wear action menu refactored and opens on double tap

This commit is contained in:
AdrianLxM 2017-02-09 00:00:54 +01:00
parent 6556ddda37
commit b8588b2c3c
10 changed files with 184 additions and 34 deletions

View file

@ -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;
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}

View file

@ -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));

View file

@ -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();

View file

@ -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;
}
}

View file

@ -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() {
}
}

View file

@ -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

View file

@ -10,7 +10,7 @@
android:layout_width="20dp"
android:src="@drawable/wl_circle"/>
<TextView
android:id="@+id/name"
android:id="@+id/actionitem"
android:gravity="center_vertical|left"
android:layout_width="wrap_content"
android:layout_marginRight="16dp"

View file

@ -66,14 +66,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/full/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/full/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/full/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/assets" type="java-test-resource" />
@ -82,6 +74,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/testFull/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />