Merge pull request #1163 from MilosKozak/wear-confirm
For testing: Wear confirm dialog
This commit is contained in:
commit
7d4eec6c99
6 changed files with 228 additions and 41 deletions
|
@ -30,7 +30,7 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
applicationId "info.nightscout.androidaps"
|
||||
minSdkVersion 21
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 23
|
||||
versionCode 1
|
||||
versionName "1.0.2"
|
||||
|
@ -67,6 +67,7 @@ dependencies {
|
|||
implementation "com.google.android.support:wearable:${wearableVersion}"
|
||||
implementation "com.google.android.gms:play-services-wearable:7.3.0"
|
||||
implementation(name:"ustwo-clockwise-debug", ext:"aar")
|
||||
implementation "com.android.support:support-v4:23.0.1"
|
||||
implementation "com.android.support:support-v4:27.0.1"
|
||||
implementation 'com.android.support:wear:27.0.1'
|
||||
implementation "me.denley.wearpreferenceactivity:wearpreferenceactivity:0.5.0"
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -204,6 +206,11 @@
|
|||
android:name=".interaction.actions.CPPActivity"
|
||||
android:label="CPP">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".interaction.actions.AcceptActivity"
|
||||
android:launchMode="singleInstance"
|
||||
android:label="ACCEPT">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".interaction.actions.FillActivity"
|
||||
android:label="Fill">
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import info.nightscout.androidaps.interaction.AAPSPreferences;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interaction.actions.AcceptActivity;
|
||||
import info.nightscout.androidaps.interaction.actions.CPPActivity;
|
||||
import info.nightscout.androidaps.interaction.utils.SafeParse;
|
||||
|
||||
|
@ -345,45 +346,14 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
|
||||
private void showConfirmationDialog(String title, String message, String actionstring) {
|
||||
|
||||
if(confirmThread != null){
|
||||
confirmThread.invalidate();
|
||||
}
|
||||
|
||||
Intent actionIntent = new Intent(this, ListenerService.class);
|
||||
actionIntent.setAction(ACTION_CONFIRMATION);
|
||||
actionIntent.putExtra("actionstring", actionstring);
|
||||
PendingIntent actionPendingIntent = PendingIntent.getService(this, 0, actionIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_UPDATE_CURRENT);;
|
||||
|
||||
long[] vibratePattern = new long[]{0, 100, 50, 100, 50};
|
||||
|
||||
NotificationCompat.Builder notificationBuilder =
|
||||
new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_icon)
|
||||
.setContentTitle(title)
|
||||
.setContentText(message)
|
||||
.setContentIntent(actionPendingIntent)
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setVibrate(vibratePattern)
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
|
||||
.extend(new NotificationCompat.WearableExtender())
|
||||
.addAction(R.drawable.ic_confirm, title, actionPendingIntent);
|
||||
|
||||
NotificationManagerCompat notificationManager =
|
||||
NotificationManagerCompat.from(this);
|
||||
|
||||
notificationManager.notify(CONFIRM_NOTIF_ID, notificationBuilder.build());
|
||||
|
||||
// keep the confirmation dialog open for one minute.
|
||||
scheduleDismissConfirm(60);
|
||||
|
||||
}
|
||||
|
||||
private void scheduleDismissConfirm(final int seconds) {
|
||||
if(confirmThread != null){
|
||||
confirmThread.invalidate();
|
||||
}
|
||||
confirmThread = new DismissThread(CONFIRM_NOTIF_ID, seconds);
|
||||
confirmThread.start();
|
||||
Intent intent = new Intent(this, AcceptActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Bundle params = new Bundle();
|
||||
params.putString("title", title);
|
||||
params.putString("message", message);
|
||||
params.putString("actionstring", actionstring);
|
||||
intent.putExtras(params);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void scheduleDismissBolusprogress(final int seconds) {
|
||||
|
@ -436,6 +406,13 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
context.startService(intent);
|
||||
}
|
||||
|
||||
public static void confirmAction(Context context, String actionstring) {
|
||||
Intent intent = new Intent(context, ListenerService.class);
|
||||
intent.putExtra("actionstring", actionstring);
|
||||
intent.setAction(ACTION_CONFIRMATION);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(Bundle bundle) {
|
||||
requestData();
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
package info.nightscout.androidaps.interaction.actions;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.os.Vibrator;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.support.wearable.view.DotsPageIndicator;
|
||||
import android.support.wearable.view.GridPagerAdapter;
|
||||
import android.support.wearable.view.GridViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.ListenerService;
|
||||
|
||||
/**
|
||||
* Created by adrian on 09/02/17.
|
||||
*/
|
||||
|
||||
|
||||
public class AcceptActivity extends ViewSelectorActivity {
|
||||
|
||||
|
||||
String title = "";
|
||||
String message = "";
|
||||
String actionstring = "";
|
||||
private DismissThread dismissThread;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
this.dismissThread = new DismissThread();
|
||||
dismissThread.start();
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
title = extras.getString("title", "");
|
||||
message = extras.getString("message", "");
|
||||
actionstring = extras.getString("actionstring", "");
|
||||
|
||||
if ("".equals(message) || "".equals(actionstring) ){
|
||||
finish(); return;
|
||||
}
|
||||
|
||||
setContentView(R.layout.grid_layout);
|
||||
final Resources res = getResources();
|
||||
final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
|
||||
|
||||
pager.setAdapter(new MyGridViewPagerAdapter());
|
||||
DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
|
||||
dotsPageIndicator.setPager(pager);
|
||||
|
||||
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
long[] vibratePattern = new long[]{0, 100, 50, 100, 50};
|
||||
v.vibrate(vibratePattern, -1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
private class MyGridViewPagerAdapter extends GridPagerAdapter {
|
||||
@Override
|
||||
public int getColumnCount(int arg0) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int row, int col) {
|
||||
|
||||
if(col == 0){
|
||||
final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_confirm_text, container, false);
|
||||
final TextView headingView = (TextView) view.findViewById(R.id.title);
|
||||
headingView.setText(title);
|
||||
final TextView textView = (TextView) view.findViewById(R.id.message);
|
||||
textView.setText(message);
|
||||
container.addView(view);
|
||||
return view;
|
||||
} else {
|
||||
final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false);
|
||||
final ImageView confirmbutton = (ImageView) view.findViewById(R.id.confirmbutton);
|
||||
confirmbutton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ListenerService.confirmAction(AcceptActivity.this, actionstring);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
container.addView(view);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int row, int col, Object view) {
|
||||
// Handle this to get the data before the view is destroyed?
|
||||
// Object should still be kept by this, just setup for reinit?
|
||||
container.removeView((View)view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view==object;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onDestroy(){
|
||||
super.onDestroy();
|
||||
if(dismissThread != null){
|
||||
dismissThread.invalidate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class DismissThread extends Thread{
|
||||
private boolean valid = true;
|
||||
|
||||
public synchronized void invalidate(){
|
||||
valid = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SystemClock.sleep(60 * 1000);
|
||||
synchronized (this) {
|
||||
if(valid) {
|
||||
AcceptActivity.this.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
if(dismissThread != null) dismissThread.invalidate();
|
||||
Bundle extras = intent.getExtras();
|
||||
Intent msgIntent = new Intent(this, AcceptActivity.class);
|
||||
msgIntent.putExtras(extras);
|
||||
startActivity(msgIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import java.util.Vector;
|
|||
|
||||
import info.nightscout.androidaps.data.ListenerService;
|
||||
import info.nightscout.androidaps.interaction.AAPSPreferences;
|
||||
import info.nightscout.androidaps.interaction.actions.AcceptActivity;
|
||||
import info.nightscout.androidaps.interaction.actions.BolusActivity;
|
||||
import info.nightscout.androidaps.interaction.actions.ECarbActivity;
|
||||
import info.nightscout.androidaps.interaction.actions.TempTargetActivity;
|
||||
|
|
40
wear/src/main/res/layout/action_confirm_text.xml
Normal file
40
wear/src/main/res/layout/action_confirm_text.xml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<android.support.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="15dp">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="5dp"
|
||||
app:boxedEdges="all">
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="title"
|
||||
android:textAppearance="@style/TextAppearance.Wearable.Medium"
|
||||
android:textColor="@color/white" />
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="message"
|
||||
android:textAppearance="@style/TextAppearance.Wearable.Small"
|
||||
android:textColor="@color/white" />
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
||||
</FrameLayout>
|
||||
</android.support.wear.widget.BoxInsetLayout>
|
Loading…
Reference in a new issue