From aad2b94c8ee78ebd52ec020860618eaff9161160 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 27 Jun 2018 08:04:57 +0200 Subject: [PATCH] first confirm activity --- wear/build.gradle | 5 +- wear/src/main/AndroidManifest.xml | 4 + .../androidaps/data/ListenerService.java | 7 ++ .../interaction/actions/AcceptActivity.java | 111 ++++++++++++++++++ .../interaction/menus/MainMenuActivity.java | 13 +- .../main/res/layout/action_confirm_text.xml | 27 +++++ 6 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java create mode 100644 wear/src/main/res/layout/action_confirm_text.xml diff --git a/wear/build.gradle b/wear/build.gradle index 584b9a769e..63858c7285 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -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" } diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index 01423985d0..b37a93507d 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -204,6 +204,10 @@ android:name=".interaction.actions.CPPActivity" android:label="CPP"> + + diff --git a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java index a827890733..fc25ab6341 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -436,6 +436,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(); diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java new file mode 100644 index 0000000000..c4b0436cc1 --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java @@ -0,0 +1,111 @@ +package info.nightscout.androidaps.interaction.actions; + + +import android.content.res.Resources; +import android.os.Bundle; +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 java.text.DecimalFormat; + +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.ListenerService; +import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; +import info.nightscout.androidaps.interaction.utils.SafeParse; + +/** + * Created by adrian on 09/02/17. + */ + + +public class AcceptActivity extends ViewSelectorActivity { + + + String text = ""; + String actionstring = ""; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Bundle extras = getIntent().getExtras(); + text = extras.getString("text", ""); + actionstring = extras.getString("actionstring", ""); + + if ("".equals(text) || "".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); + } + + + @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 textView = (TextView) view.findViewById(R.id.confirmtext); + textView.setText(text); + 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; + } + + + } +} \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java index fb8bb61e20..490ed77c08 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java @@ -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; @@ -34,7 +35,7 @@ public class MainMenuActivity extends MenuListActivity { protected String[] getElements() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - if(!sharedPreferences.getBoolean("wearcontrol", false)){ + if(false && !sharedPreferences.getBoolean("wearcontrol", false)){ return new String[] { "Settings", "Re-Sync"}; @@ -84,9 +85,17 @@ public class MainMenuActivity extends MenuListActivity { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); } else if ("Prime/Fill".equals(action)) { - intent = new Intent(this, FillMenuActivity.class); + /*intent = new Intent(this, FillMenuActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); + */ + intent = new Intent(this, AcceptActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + Bundle params = new Bundle(); + params.putString("text", "dies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\n"); + params.putString("actionstring", "blablubb"); + intent.putExtras(params); + startActivity(intent); } else if ("eCarb".equals(action)) { intent = new Intent(this, ECarbActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/wear/src/main/res/layout/action_confirm_text.xml b/wear/src/main/res/layout/action_confirm_text.xml new file mode 100644 index 0000000000..23472260bd --- /dev/null +++ b/wear/src/main/res/layout/action_confirm_text.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + \ No newline at end of file