diff --git a/wear/src/main/java/info/nightscout/androidaps/BIGChart.java b/wear/src/main/java/info/nightscout/androidaps/BIGChart.java index 637908600e..af69c8f546 100644 --- a/wear/src/main/java/info/nightscout/androidaps/BIGChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/BIGChart.java @@ -39,6 +39,7 @@ import com.ustwo.clockwise.common.WatchShape; import java.util.ArrayList; import java.util.Date; +import info.nightscout.androidaps.actions.ActionsListActivity; import lecho.lib.hellocharts.view.LineChartView; /** @@ -83,6 +84,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre private String externalStatusString = "no status"; private TextView statusView; private long chartTapTime = 0l; + private long sgvTapTime = 0l; @Override public void onCreate() { @@ -143,6 +145,8 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre @Override protected void onTapCommand(int tapType, int x, int y, long eventTime) { + int extra = mSgv!=null?(mSgv.getRight() - mSgv.getLeft())/2:0; + if (tapType == TAP_TYPE_TAP&& x >=chart.getLeft() && x <= chart.getRight()&& @@ -152,6 +156,17 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre changeChartTimeframe(); } chartTapTime = eventTime; + } else if (tapType == TAP_TYPE_TAP&& + x + extra >=mSgv.getLeft() && + x - extra <= mSgv.getRight()&& + y >= mSgv.getTop() && + y <= mSgv.getBottom()){ + if (eventTime - sgvTapTime < 800){ + Intent intent = new Intent(this, ActionsListActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + sgvTapTime = eventTime; } } diff --git a/wear/src/main/java/info/nightscout/androidaps/CircleWatchface.java b/wear/src/main/java/info/nightscout/androidaps/CircleWatchface.java index c81b6de6f1..26b8f0198e 100644 --- a/wear/src/main/java/info/nightscout/androidaps/CircleWatchface.java +++ b/wear/src/main/java/info/nightscout/androidaps/CircleWatchface.java @@ -35,6 +35,8 @@ import java.util.Date; import java.util.HashSet; import java.util.TreeSet; +import info.nightscout.androidaps.actions.ActionsListActivity; + public class CircleWatchface extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener { public final float PADDING = 20f; @@ -79,6 +81,8 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh private View myLayout; protected SharedPreferences sharedPrefs; + private TextView mSgv; + private long sgvTapTime = 0; @Override @@ -144,7 +148,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh // prepare fields TextView textView = null; - + mSgv = (TextView) myLayout.findViewById(R.id.sgvString); textView = (TextView) myLayout.findViewById(R.id.sgvString); if (sharedPrefs.getBoolean("showBG", true)) { textView.setVisibility(View.VISIBLE); @@ -700,4 +704,24 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh addArch(canvas, (float) size, offset * offsetMultiplier + 11, color, (float) (360f - size)); // Dark fill addArch(canvas, (offset + .8f) * offsetMultiplier + 11, getBackgroundColor(), 360); } + + @Override + protected void onTapCommand(int tapType, int x, int y, long eventTime) { + + int extra = mSgv!=null?(mSgv.getRight() - mSgv.getLeft())/2:0; + + if (tapType == TAP_TYPE_TAP&& + x + extra >=mSgv.getLeft() && + x - extra <= mSgv.getRight()&& + y >= mSgv.getTop() && + y <= mSgv.getBottom()){ + if (eventTime - sgvTapTime < 800){ + Intent intent = new Intent(this, ActionsListActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + sgvTapTime = eventTime; + } + } + } \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/Home.java b/wear/src/main/java/info/nightscout/androidaps/Home.java index e84098a341..45803e8b47 100644 --- a/wear/src/main/java/info/nightscout/androidaps/Home.java +++ b/wear/src/main/java/info/nightscout/androidaps/Home.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps; +import android.content.Intent; import android.graphics.Color; import android.support.v4.content.ContextCompat; import android.support.wearable.watchface.WatchFaceStyle; @@ -7,9 +8,12 @@ import android.view.LayoutInflater; import com.ustwo.clockwise.common.WatchMode; +import info.nightscout.androidaps.actions.ActionsListActivity; + public class Home extends BaseWatchFace { private long chartTapTime = 0; + private long sgvTapTime = 0; @Override public void onCreate() { @@ -22,6 +26,8 @@ public class Home extends BaseWatchFace { @Override protected void onTapCommand(int tapType, int x, int y, long eventTime) { + int extra = mSgv!=null?(mSgv.getRight() - mSgv.getLeft())/2:0; + if (tapType == TAP_TYPE_TAP&& x >=chart.getLeft() && x <= chart.getRight()&& @@ -31,6 +37,17 @@ public class Home extends BaseWatchFace { changeChartTimeframe(); } chartTapTime = eventTime; + } else if (tapType == TAP_TYPE_TAP&& + x + extra >=mSgv.getLeft() && + x - extra <= mSgv.getRight()&& + y >= mSgv.getTop() && + y <= mSgv.getBottom()){ + if (eventTime - sgvTapTime < 800){ + Intent intent = new Intent(this, ActionsListActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + sgvTapTime = eventTime; } } diff --git a/wear/src/main/java/info/nightscout/androidaps/LargeHome.java b/wear/src/main/java/info/nightscout/androidaps/LargeHome.java index 9f412702d4..1e5fedc336 100644 --- a/wear/src/main/java/info/nightscout/androidaps/LargeHome.java +++ b/wear/src/main/java/info/nightscout/androidaps/LargeHome.java @@ -1,13 +1,18 @@ package info.nightscout.androidaps; +import android.content.Intent; import android.graphics.Color; import android.support.v4.content.ContextCompat; import android.view.LayoutInflater; import com.ustwo.clockwise.common.WatchMode; +import info.nightscout.androidaps.actions.ActionsListActivity; + public class LargeHome extends BaseWatchFace { + private long sgvTapTime = 0; + @Override public void onCreate() { super.onCreate(); @@ -16,6 +21,25 @@ public class LargeHome extends BaseWatchFace { performViewSetup(); } + @Override + protected void onTapCommand(int tapType, int x, int y, long eventTime) { + + int extra = mSgv!=null?(mSgv.getRight() - mSgv.getLeft())/2:0; + + if (tapType == TAP_TYPE_TAP&& + x + extra >=mSgv.getLeft() && + x - extra <= mSgv.getRight()&& + y >= mSgv.getTop() && + y <= mSgv.getBottom()){ + if (eventTime - sgvTapTime < 800){ + Intent intent = new Intent(this, ActionsListActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + sgvTapTime = eventTime; + } + } + @Override protected void setColorDark(){ mLinearLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_mLinearLayout)); diff --git a/wear/src/main/java/info/nightscout/androidaps/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/ListenerService.java index 6e2f8e72ac..d1cb44093d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/ListenerService.java @@ -49,6 +49,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA"; private static final String ACTION_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS"; private static final String ACTION_CONFIRMATION = "com.dexdrip.stephenblack.nightwatch.CONFIRMACTION"; + private static final String ACTION_INITIATE_ACTION = "com.dexdrip.stephenblack.nightwatch.INITIATE_ACTION"; private static final String ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA"; @@ -200,8 +201,14 @@ public class ListenerService extends WearableListenerService implements GoogleAp String actionstring = intent.getStringExtra("actionstring"); sendConfirmActionstring(actionstring); - //TODO: send confirmation string to phone - } + } else if(intent != null && ACTION_INITIATE_ACTION.equals(intent.getAction())){ + googleApiConnect(); + + String actionstring = intent.getStringExtra("actionstring"); + sendInitiateActionstring(actionstring); + + } + return START_STICKY; } @@ -341,6 +348,13 @@ public class ListenerService extends WearableListenerService implements GoogleAp context.startService(intent); } + public static void initiateAction(Context context, String actionstring) { + Intent intent = new Intent(context, ListenerService.class); + intent.putExtra("actionstring", actionstring); + intent.setAction(ACTION_INITIATE_ACTION); + context.startService(intent); + } + @Override public void onConnected(Bundle bundle) { requestData(); diff --git a/wear/src/main/java/info/nightscout/androidaps/actions/ActionsDefinitions.java b/wear/src/main/java/info/nightscout/androidaps/actions/ActionsDefinitions.java new file mode 100644 index 0000000000..0b6d90c150 --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/actions/ActionsDefinitions.java @@ -0,0 +1,60 @@ +package info.nightscout.androidaps.actions; + +import android.content.Context; +import android.content.Intent; + +import info.nightscout.androidaps.ListenerService; +import info.nightscout.androidaps.NWPreferences; + +/** + * Created by adrian on 08/02/17. + */ + +final class ActionsDefinitions { + + private static final String[] ACTION_NAMES = { + "Temp Target", + "Bolus", + "Settings", + "Resend Data", + "Fillpreset 1", + "Fillpreset 2", + "Fillpreset 3", + "003"}; + + + public static void doAction(int position, Context ctx) { + + switch (position) { + case 0: + break; + case 1: + break; + case 2: + Intent intent = new Intent(ctx, NWPreferences.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + ctx.startActivity(intent); + break; + case 3: + ListenerService.requestData(ctx); + break; + case 4: + ListenerService.initiateAction(ctx, "fillpreset 1"); + break; + case 5: + ListenerService.initiateAction(ctx, "fillpreset 2"); + break; + case 6: + ListenerService.initiateAction(ctx, "fillpreset 3"); + break; + } + + } + + + public static String[] getActionNames() { + //posibility for later i18n + return ACTION_NAMES; + } + +} diff --git a/wear/src/main/java/info/nightscout/androidaps/actions/ActionsListActivity.java b/wear/src/main/java/info/nightscout/androidaps/actions/ActionsListActivity.java index 2fa629f613..f1202797d4 100644 --- a/wear/src/main/java/info/nightscout/androidaps/actions/ActionsListActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/actions/ActionsListActivity.java @@ -18,35 +18,36 @@ import info.nightscout.androidaps.R; public class ActionsListActivity extends Activity implements WearableListView.ClickListener { - // Sample dataset for the list - String[] elements = { "Temp Target", "Bolus", "Settings"}; + String[] elements = ActionsDefinitions.getActionNames(); -@Override -protected void onCreate(Bundle savedInstanceState) { + @Override + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.actions_list_activity); // Get the list component from the layout of the activity WearableListView listView = - (WearableListView) findViewById(R.id.wearable_list); + (WearableListView) findViewById(R.id.wearable_list); // Assign an adapter to the list listView.setAdapter(new Adapter(this, elements)); // Set a click listener listView.setClickListener(this); - } + } -// WearableListView click listener -@Override -public void onClick(WearableListView.ViewHolder v) { + // WearableListView click listener + @Override + public void onClick(WearableListView.ViewHolder v) { Integer tag = (Integer) v.itemView.getTag(); - // use this data to complete some action ... - } + ActionsDefinitions.doAction(tag, this); + //ActionsDefinitions.doAction(v.getAdapterPosition(), this); + finish(); + } -@Override -public void onTopEmptyRegionClick() { - } + @Override + public void onTopEmptyRegionClick() { + } private static final class Adapter extends WearableListView.Adapter { @@ -64,10 +65,11 @@ public void onTopEmptyRegionClick() { // Provide a reference to the type of views you're using public static class ItemViewHolder extends WearableListView.ViewHolder { private TextView textView; + public ItemViewHolder(View itemView) { super(itemView); // find the text view within the custom item's layout - textView = (TextView) itemView.findViewById(R.id.name); + textView = (TextView) itemView.findViewById(R.id.actionitem); } } @@ -104,8 +106,4 @@ public void onTopEmptyRegionClick() { } - - - - } \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/actions/WearableListItemLayout.java b/wear/src/main/java/info/nightscout/androidaps/actions/WearableListItemLayout.java index 28acb60fdf..bb027ba438 100644 --- a/wear/src/main/java/info/nightscout/androidaps/actions/WearableListItemLayout.java +++ b/wear/src/main/java/info/nightscout/androidaps/actions/WearableListItemLayout.java @@ -45,10 +45,8 @@ public class WearableListItemLayout extends LinearLayout @Override protected void onFinishInflate() { super.onFinishInflate(); - // These are defined in the layout file for list items - // (see next section) mCircle = (ImageView) findViewById(R.id.circle); - mName = (TextView) findViewById(R.id.name); + mName = (TextView) findViewById(R.id.actionitem); } @Override diff --git a/wear/src/main/res/layout/list_item.xml b/wear/src/main/res/layout/list_item.xml index c193f0bd2c..4ca65adaa6 100644 --- a/wear/src/main/res/layout/list_item.xml +++ b/wear/src/main/res/layout/list_item.xml @@ -10,7 +10,7 @@ android:layout_width="20dp" android:src="@drawable/wl_circle"/> - - - - - - - - @@ -82,6 +74,14 @@ + + + + + + + +