cpp watch openactivity

This commit is contained in:
AdrianLxM 2017-07-09 18:35:20 +02:00
parent 39ee68e62a
commit 85d028abff
6 changed files with 184 additions and 2 deletions

View file

@ -358,4 +358,11 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
return sb.toString();
}
public int getPercentage() {
return percentage;
}
public int getTimeshift() {
return timeshift;
}
}

View file

@ -24,6 +24,7 @@ import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@ -225,7 +226,24 @@ public class ActionStringHandler {
lastBolusWizard = bolusWizard;
} else return;
} else if("opencpp".equals(act[0])){
//TODO ADRIAN open cpp
Object activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getSpecificPlugin(CircadianPercentageProfilePlugin.class);
if(cpp == null || activeProfile==null || cpp != activeProfile){
rTitle = "STATUS";
rAction = "statusmessage";
rMessage = "CPP not activated";
} else {
// read CPP values
rTitle = "opencpp";
rMessage = "opencpp";
rAction = "opencpp" + " " + cpp.getPercentage() + " " + cpp.getTimeshift();
}
}else return;
// send result
WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation(rTitle, rMessage, rAction);

View file

@ -140,6 +140,10 @@
android:name=".interaction.actions.BolusActivity"
android:label="Bolus">
</activity>
<activity
android:name=".interaction.actions.CPPActivity"
android:label="CPP">
</activity>
<activity
android:name=".interaction.actions.FillActivity"
android:label="Fill">

View file

@ -26,6 +26,8 @@ import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.interaction.AAPSPreferences;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interaction.actions.CPPActivity;
import info.nightscout.androidaps.interaction.utils.SafeParse;
/**
* Created by emmablack on 12/26/14.
@ -252,7 +254,21 @@ public class ListenerService extends WearableListenerService implements GoogleAp
String title = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("title");
String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message");
String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring");
showConfirmationDialog(title, message, actionstring);
if("opencpp".equals(title) && actionstring.startsWith("opencpp")){
String[] act = actionstring.split("\\s+");
Intent intent = new Intent(this, CPPActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//TODO adrian: parse actionstring and add parameters
Bundle params = new Bundle();
params.putInt("percentage", SafeParse.stringToInt(act[1]));
params.putInt("timeshift", SafeParse.stringToInt(act[2]));
intent.putExtras(params);
startActivity(intent);
} else {
showConfirmationDialog(title, message, actionstring);
}
}else if (path.equals(NEW_STATUS_PATH)) {
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Intent messageIntent = new Intent();

View file

@ -0,0 +1,133 @@
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 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 CPPActivity extends ViewSelectorActivity {
PlusMinusEditText editPercentage;
PlusMinusEditText editTimeshift;
int percentage = -1;
int timeshift = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
percentage = extras.getInt("percentage", -1);
timeshift = extras.getInt("timeshift", -1);
if (percentage ==-1 || timeshift ==-1){
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 3;
}
@Override
public int getRowCount() {
return 1;
}
@Override
public Object instantiateItem(ViewGroup container, int row, int col) {
if(col == 0){
final View view = getInflatedPlusMinusView(container);
double def = timeshift;
if (editTimeshift != null){
def = SafeParse.stringToDouble(editTimeshift.editText.getText().toString());
}
editTimeshift = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 24d, 1d, new DecimalFormat("0"), false);
setLabelToPlusMinusView(view, "timeshift");
container.addView(view);
return view;
} else if(col == 1){
final View view = getInflatedPlusMinusView(container);
double def = percentage;
if (editPercentage != null){
def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
}
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50d, 150d, 1d, new DecimalFormat("0"), false);
setLabelToPlusMinusView(view, "percentage");
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) {
//check if it can happen that the fagment is never created that hold data?
// (you have to swipe past them anyways - but still)
String actionstring = "cppset " +SafeParse.stringToInt(editTimeshift.editText.getText().toString())
+ " " + SafeParse.stringToInt(editPercentage.editText.getText().toString());
ListenerService.initiateAction(CPPActivity.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;
}
}
}

View file

@ -15,6 +15,7 @@ public class StatusMenuActivity extends MenuListActivity {
"Pump",
"Loop",
"Targets",
"CPP",
"OAPS Result"};
}
@ -33,6 +34,9 @@ public class StatusMenuActivity extends MenuListActivity {
ListenerService.initiateAction(this, "status targets");
break;
case 3:
ListenerService.initiateAction(this, "opencpp");
break;
case 4:
ListenerService.initiateAction(this, "status oapsresult");
break;
}