Refactor of BaseWatchFace.java in order to allow greater flexibility in presenting or removing data from various watch faces.
Inclusion of Home2 ("AAPSv2") watch face for round.
This commit is contained in:
parent
45a26da8b3
commit
bc485a4783
7 changed files with 370 additions and 675 deletions
|
@ -542,28 +542,16 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
|
||||
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH);
|
||||
//unique content
|
||||
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
|
||||
//Log.e("SendStatus", "timestamp is " + System.currentTimeMillis());
|
||||
dataMapRequest.getDataMap().putString("externalStatusString", status);
|
||||
//Log.e("SendStatus", "externalStatusString is " + status);
|
||||
dataMapRequest.getDataMap().putString("iobTotal", iobTotal);
|
||||
//Log.e("SendStatus", "iobTotal is " + iobTotal);
|
||||
dataMapRequest.getDataMap().putString("iobDetail", iobDetail);
|
||||
//Log.e("SendStatus", "iobDetail is " + iobDetail);
|
||||
dataMapRequest.getDataMap().putBoolean("detailedIob", mPrefs.getBoolean("wear_detailediob", false));
|
||||
//Log.e("SendStatus", "cob is " + cobString);
|
||||
dataMapRequest.getDataMap().putString("cob", cobString);
|
||||
//Log.e("SendStatus", "cob is " + cobString);
|
||||
dataMapRequest.getDataMap().putString("tempBasal", tempBasal);
|
||||
//Log.e("SendStatus", "tempBasal is " + tempBasal);
|
||||
dataMapRequest.getDataMap().putString("battery", "" + phoneBattery);
|
||||
//Log.e("SendStatus", "battery is " + phoneBattery);
|
||||
dataMapRequest.getDataMap().putString("rigBattery", rigBattery);
|
||||
//Log.e("SendStatus", "rigBattery is " + rigBattery);
|
||||
dataMapRequest.getDataMap().putString("openApsStatus", openApsStatus);
|
||||
//Log.e("SendStatus", "openApsStatus is " + openApsStatus);
|
||||
dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0);
|
||||
//Log.e("SendStatus", "batteryLevel is " + ((phoneBattery >= 30) ? 1 : 0));
|
||||
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
|
||||
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ import com.ustwo.clockwise.wearable.WatchFace;
|
|||
import com.ustwo.clockwise.common.WatchFaceTime;
|
||||
import com.ustwo.clockwise.common.WatchShape;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -43,16 +44,19 @@ import lecho.lib.hellocharts.view.LineChartView;
|
|||
|
||||
/**
|
||||
* Created by emmablack on 12/29/14.
|
||||
* Updated by andrew-warrington on 11/15/17.
|
||||
*/
|
||||
public abstract class BaseWatchFace extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public final static IntentFilter INTENT_FILTER;
|
||||
public static final long[] vibratePattern = {0,400,300,400,300,400};
|
||||
public TextView mTime, mSgv, mDirection, mTimestamp, mUploaderBattery, mDelta, mStatus;
|
||||
public TextView mTime, mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mLoop, mDay, mMonth, isAAPSv2;
|
||||
public double datetime;
|
||||
public RelativeLayout mRelativeLayout;
|
||||
public LinearLayout mLinearLayout;
|
||||
public LinearLayout mLinearLayout, mLinearLayout2, mDate;
|
||||
public long sgvLevel = 0;
|
||||
public int batteryLevel = 1;
|
||||
public int ageLevel = 1;
|
||||
public int loopLevel = 1;
|
||||
public int batteryLevel = 1;
|
||||
public int highColor = Color.YELLOW;
|
||||
public int lowColor = Color.RED;
|
||||
public int midColor = Color.WHITE;
|
||||
|
@ -60,12 +64,11 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
|||
public int basalBackgroundColor = Color.BLUE;
|
||||
public int basalCenterColor = Color.BLUE;
|
||||
public boolean lowResMode = false;
|
||||
public int pointSize = 2;
|
||||
public boolean layoutSet = false;
|
||||
public int pointSize = 2;
|
||||
public int missed_readings_alert_id = 818;
|
||||
public BgGraphBuilder bgGraphBuilder;
|
||||
public LineChartView chart;
|
||||
public double datetime;
|
||||
public ArrayList<BgWatchData> bgDataList = new ArrayList<>();
|
||||
public ArrayList<TempWatchData> tempWatchDataList = new ArrayList<>();
|
||||
public ArrayList<BasalWatchData> basalWatchDataList = new ArrayList<>();
|
||||
|
@ -74,17 +77,25 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
|||
public View layoutView;
|
||||
private final Point displaySize = new Point();
|
||||
private int specW, specH;
|
||||
|
||||
private LocalBroadcastManager localBroadcastManager;
|
||||
private MessageReceiver messageReceiver;
|
||||
|
||||
protected SharedPreferences sharedPrefs;
|
||||
private String batteryString = "--";
|
||||
private String sgvString = "--";
|
||||
private String externalStatusString = "no status";
|
||||
private String avgDelta = "";
|
||||
private String delta = "";
|
||||
|
||||
public boolean detailedIOB = false;
|
||||
public String openApsStatus = "0";
|
||||
public String externalStatusString = "no status";
|
||||
public String sSgv = "---";
|
||||
public String sDirection = "--";
|
||||
public String sUploaderBattery = "--";
|
||||
public String sRigBattery = "--";
|
||||
public String sDelta = "-";
|
||||
public String sAvgDelta = "-";
|
||||
public String sBasalRate = "-.--U/h";
|
||||
public String sIOB1 = "IOB";
|
||||
public String sIOB2 = "-.--";
|
||||
public String sCOB1 = "Carb";
|
||||
public String sCOB2 = "--g";
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
@ -121,22 +132,33 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
|||
@Override
|
||||
public void onLayoutInflated(WatchViewStub stub) {
|
||||
mTime = (TextView) stub.findViewById(R.id.watch_time);
|
||||
mDay = (TextView) stub.findViewById(R.id.day);
|
||||
mMonth = (TextView) stub.findViewById(R.id.month);
|
||||
mDate = (LinearLayout) stub.findViewById(R.id.date_time);
|
||||
mLoop = (TextView) stub.findViewById(R.id.loop);
|
||||
mSgv = (TextView) stub.findViewById(R.id.sgv);
|
||||
mDirection = (TextView) stub.findViewById(R.id.direction);
|
||||
mTimestamp = (TextView) stub.findViewById(R.id.timestamp);
|
||||
mIOB1 = (TextView) stub.findViewById(R.id.iob_text);
|
||||
mIOB2 = (TextView) stub.findViewById(R.id.iobView);
|
||||
mCOB1 = (TextView) stub.findViewById(R.id.cob_text);
|
||||
mCOB2 = (TextView) stub.findViewById(R.id.cobView);
|
||||
mStatus = (TextView) stub.findViewById(R.id.externaltstatus);
|
||||
mBasalRate = (TextView) stub.findViewById(R.id.tmpBasal);
|
||||
mUploaderBattery = (TextView) stub.findViewById(R.id.uploader_battery);
|
||||
mRigBattery = (TextView) stub.findViewById(R.id.rig_battery);
|
||||
mDelta = (TextView) stub.findViewById(R.id.delta);
|
||||
isAAPSv2 = (TextView) stub.findViewById(R.id.AAPSv2);
|
||||
mRelativeLayout = (RelativeLayout) stub.findViewById(R.id.main_layout);
|
||||
mLinearLayout = (LinearLayout) stub.findViewById(R.id.secondary_layout);
|
||||
mLinearLayout2 = (LinearLayout) stub.findViewById(R.id.tertiary_layout);
|
||||
chart = (LineChartView) stub.findViewById(R.id.chart);
|
||||
layoutSet = true;
|
||||
showAgoRawBattStatus();
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
|
||||
setDataFields();
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
ListenerService.requestData(this);
|
||||
wakeLock.acquire(50);
|
||||
}
|
||||
|
@ -164,9 +186,10 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
|||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if(localBroadcastManager != null && messageReceiver != null){
|
||||
localBroadcastManager.unregisterReceiver(messageReceiver);}
|
||||
if (sharedPrefs != null){
|
||||
if (localBroadcastManager != null && messageReceiver != null) {
|
||||
localBroadcastManager.unregisterReceiver(messageReceiver);
|
||||
}
|
||||
if (sharedPrefs != null) {
|
||||
sharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
super.onDestroy();
|
||||
|
@ -181,7 +204,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
|||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if(layoutSet) {
|
||||
if (layoutSet) {
|
||||
this.mRelativeLayout.draw(canvas);
|
||||
Log.d("onDraw", "draw");
|
||||
}
|
||||
|
@ -191,15 +214,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
|||
protected void onTimeChanged(WatchFaceTime oldTime, WatchFaceTime newTime) {
|
||||
if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) {
|
||||
wakeLock.acquire(50);
|
||||
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
|
||||
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||
showAgoRawBattStatus();
|
||||
|
||||
if(ageLevel()<=0) {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
} else {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
setDataFields();
|
||||
|
||||
missedReadingAlert();
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
|
@ -212,108 +228,228 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
|||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
//data
|
||||
Bundle bundle = intent.getBundleExtra("data");
|
||||
if (layoutSet && bundle != null) {
|
||||
DataMap dataMap = DataMap.fromBundle(bundle);
|
||||
wakeLock.acquire(50);
|
||||
sgvLevel = dataMap.getLong("sgvLevel");
|
||||
batteryLevel = dataMap.getInt("batteryLevel");
|
||||
datetime = dataMap.getDouble("timestamp");
|
||||
sgvString = dataMap.getString("sgvString");
|
||||
batteryString = dataMap.getString("battery");
|
||||
mSgv.setText(dataMap.getString("sgvString"));
|
||||
|
||||
if(ageLevel()<=0) {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
} else {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
|
||||
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
|
||||
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||
|
||||
mDirection.setText(dataMap.getString("slopeArrow"));
|
||||
avgDelta = dataMap.getString("avgDelta");
|
||||
delta = dataMap.getString("delta");
|
||||
|
||||
|
||||
showAgoRawBattStatus();
|
||||
|
||||
|
||||
sSgv = dataMap.getString("sgvString");
|
||||
sDirection = dataMap.getString("slopeArrow");
|
||||
sDelta = dataMap.getString("delta");
|
||||
sAvgDelta = dataMap.getString("avgDelta");
|
||||
if (chart != null) {
|
||||
addToWatchSet(dataMap);
|
||||
setupCharts();
|
||||
}
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
invalidate();
|
||||
setColor();
|
||||
}
|
||||
//status
|
||||
|
||||
bundle = intent.getBundleExtra("status");
|
||||
if (layoutSet && bundle != null) {
|
||||
DataMap dataMap = DataMap.fromBundle(bundle);
|
||||
wakeLock.acquire(50);
|
||||
sBasalRate = dataMap.getString("tempBasal");
|
||||
sUploaderBattery = dataMap.getString("battery");
|
||||
sRigBattery = dataMap.getString("rigBattery");
|
||||
detailedIOB = dataMap.getBoolean("detailedIob");
|
||||
sIOB1 = dataMap.getString("iobTotal");
|
||||
sIOB2 = dataMap.getString("iobDetail");
|
||||
sCOB1 = "Carb";
|
||||
sCOB2 = dataMap.getString("cob");
|
||||
externalStatusString = dataMap.getString("externalStatusString");
|
||||
|
||||
showAgoRawBattStatus();
|
||||
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
invalidate();
|
||||
setColor();
|
||||
openApsStatus = dataMap.getString("openApsStatus");
|
||||
batteryLevel = dataMap.getInt("batteryLevel");
|
||||
}
|
||||
//basals and temps
|
||||
|
||||
setDataFields();
|
||||
|
||||
bundle = intent.getBundleExtra("basals");
|
||||
if (layoutSet && bundle != null) {
|
||||
DataMap dataMap = DataMap.fromBundle(bundle);
|
||||
wakeLock.acquire(500);
|
||||
|
||||
loadBasalsAndTemps(dataMap);
|
||||
}
|
||||
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
invalidate();
|
||||
setColor();
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
invalidate();
|
||||
setColor();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDataFields() {
|
||||
|
||||
setDateAndTime();
|
||||
|
||||
if (mSgv != null) {
|
||||
if (sharedPrefs.getBoolean("showBG", true)) {
|
||||
mSgv.setText(sSgv);
|
||||
mSgv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
//leave the textview there but invisible, as a height holder for the empty space above the white line
|
||||
mSgv.setVisibility(View.INVISIBLE);
|
||||
mSgv.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
strikeThroughSgvIfNeeded();
|
||||
|
||||
if (mDirection != null) {
|
||||
if (sharedPrefs.getBoolean("show_direction", true)) {
|
||||
mDirection.setText(sDirection);
|
||||
mDirection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mDirection.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mDelta != null) {
|
||||
if (sharedPrefs.getBoolean("showDelta", true)) {
|
||||
mDelta.setText(sDelta);
|
||||
mDelta.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mDelta.setVisibility(View.GONE);
|
||||
}
|
||||
if (sharedPrefs.getBoolean("showAvgDelta", true)) {
|
||||
mDelta.append(" " + sAvgDelta);
|
||||
}
|
||||
}
|
||||
|
||||
if (mCOB1 != null && mCOB2 != null) {
|
||||
mCOB2.setText(sCOB2);
|
||||
if (sharedPrefs.getBoolean("show_cob", true)) {
|
||||
mCOB1.setVisibility(View.VISIBLE);
|
||||
mCOB2.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mCOB1.setVisibility(View.GONE);
|
||||
mCOB2.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mIOB1 != null && mIOB2 != null) {
|
||||
if (sharedPrefs.getBoolean("show_iob", true)) {
|
||||
mIOB1.setVisibility(View.VISIBLE);
|
||||
mIOB2.setVisibility(View.VISIBLE);
|
||||
if (detailedIOB) {
|
||||
mIOB1.setTextSize(14);
|
||||
mIOB2.setTextSize(10);
|
||||
mIOB1.setText("IOB " + sIOB1);
|
||||
mIOB2.setText(sIOB2);
|
||||
} else {
|
||||
mIOB1.setTextSize(10);
|
||||
mIOB2.setTextSize(14);
|
||||
mIOB1.setText("IOB");
|
||||
mIOB2.setText(sIOB1);
|
||||
}
|
||||
} else {
|
||||
mIOB1.setVisibility(View.GONE);
|
||||
mIOB2.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mTimestamp != null) {
|
||||
if (sharedPrefs.getBoolean("showAgo", true)) {
|
||||
if (isAAPSv2 != null) {
|
||||
mTimestamp.setText(readingAge(true));
|
||||
} else {
|
||||
if (sharedPrefs.getBoolean("showExternalStatus", true)) {
|
||||
mTimestamp.setText(readingAge(true));
|
||||
} else {
|
||||
mTimestamp.setText(readingAge(false));
|
||||
}
|
||||
}
|
||||
mTimestamp.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mTimestamp.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mUploaderBattery != null) {
|
||||
if (sharedPrefs.getBoolean("show_uploader_battery", true)) {
|
||||
if (isAAPSv2 != null) {
|
||||
mUploaderBattery.setText(sUploaderBattery + "%");
|
||||
mUploaderBattery.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
if (sharedPrefs.getBoolean("showExternalStatus", true)) {
|
||||
mUploaderBattery.setText("U: " + sUploaderBattery + "%");
|
||||
} else {
|
||||
mUploaderBattery.setText("Uploader: " + sUploaderBattery + "%");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mUploaderBattery.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mRigBattery != null) {
|
||||
if (sharedPrefs.getBoolean("show_rig_battery", false)) {
|
||||
mRigBattery.setText(sRigBattery);
|
||||
mRigBattery.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mRigBattery.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mBasalRate != null) {
|
||||
if (sharedPrefs.getBoolean("show_temp_basal", true)) {
|
||||
mBasalRate.setText(sBasalRate);
|
||||
mBasalRate.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mBasalRate.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mStatus != null) {
|
||||
if (sharedPrefs.getBoolean("showExternalStatus", true)) {
|
||||
mStatus.setText(externalStatusString);
|
||||
mStatus.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mStatus.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mLoop != null) {
|
||||
if (sharedPrefs.getBoolean("showExternalStatus", true)) {
|
||||
mLoop.setVisibility(View.VISIBLE);
|
||||
if (openApsStatus != null && openApsStatus != "") {
|
||||
mLoop.setText(openApsStatus + "'");
|
||||
if (Integer.valueOf(openApsStatus) > 14) {
|
||||
loopLevel = 0;
|
||||
if (getCurrentWatchMode() == WatchMode.INTERACTIVE) {
|
||||
mLoop.setBackgroundResource(R.drawable.loop_red_25);
|
||||
}
|
||||
} else {
|
||||
loopLevel = 1;
|
||||
if (getCurrentWatchMode() == WatchMode.INTERACTIVE) {
|
||||
mLoop.setBackgroundResource(R.drawable.loop_green_25);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mLoop.setText("-'");
|
||||
}
|
||||
} else {
|
||||
mLoop.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showAgoRawBattStatus() {
|
||||
public void setDateAndTime() {
|
||||
|
||||
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
|
||||
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||
|
||||
boolean showAvgDelta = sharedPrefs.getBoolean("showAvgDelta", true);
|
||||
mDelta.setText(delta);
|
||||
if(showAvgDelta){
|
||||
mDelta.append(" " + avgDelta);
|
||||
}
|
||||
|
||||
|
||||
if( mTimestamp == null || mUploaderBattery == null|| mStatus == null){
|
||||
return;
|
||||
}
|
||||
|
||||
boolean showStatus = sharedPrefs.getBoolean("showExternalStatus", true);
|
||||
|
||||
if(showStatus){
|
||||
//use short forms
|
||||
mTimestamp.setText(readingAge(true));
|
||||
mUploaderBattery.setText("U: " + batteryString + "%");
|
||||
} else {
|
||||
mTimestamp.setText(readingAge(false));
|
||||
mUploaderBattery.setText("Uploader: " + batteryString + "%");
|
||||
}
|
||||
|
||||
|
||||
if (showStatus) {
|
||||
mStatus.setVisibility(View.VISIBLE);
|
||||
mStatus.setText("S: " + externalStatusString);
|
||||
} else {
|
||||
mStatus.setVisibility(View.GONE);
|
||||
if (mDate != null && mDay != null && mMonth != null) {
|
||||
if (sharedPrefs.getBoolean("show_date", false)) {
|
||||
Date today = new Date();
|
||||
SimpleDateFormat sdfDay = new SimpleDateFormat("dd");
|
||||
SimpleDateFormat sdfMonth = new SimpleDateFormat("MMM");
|
||||
mDay.setText(sdfDay.format(today));
|
||||
mMonth.setText(sdfMonth.format(today));
|
||||
mDate.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mDate.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -327,6 +463,18 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
|||
}
|
||||
}
|
||||
|
||||
public void strikeThroughSgvIfNeeded() {
|
||||
if (mSgv !=null) {
|
||||
if (sharedPrefs.getBoolean("showBG", true)) {
|
||||
if (ageLevel() <= 0) {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
} else {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onWatchModeChanged(WatchMode watchMode) {
|
||||
|
||||
if(lowResMode ^ isLowRes(watchMode)){ //if there was a change in lowResMode
|
||||
|
@ -344,20 +492,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
|
|||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){
|
||||
setColor();
|
||||
|
||||
if(layoutSet){
|
||||
showAgoRawBattStatus();
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
setDataFields();
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
protected abstract void setColorDark();
|
||||
protected abstract void setColorDark();
|
||||
protected abstract void setColorBright();
|
||||
protected abstract void setColorLowRes();
|
||||
|
||||
|
||||
public void missedReadingAlert() {
|
||||
int minutes_since = (int) Math.floor(timeSince()/(1000*60));
|
||||
if(minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) {
|
||||
|
|
|
@ -1,504 +0,0 @@
|
|||
package info.nightscout.androidaps.watchfaces;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.wearable.view.WatchViewStub;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
import com.ustwo.clockwise.common.WatchMode;
|
||||
import com.ustwo.clockwise.wearable.WatchFace;
|
||||
import com.ustwo.clockwise.common.WatchFaceTime;
|
||||
import com.ustwo.clockwise.common.WatchShape;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.data.BasalWatchData;
|
||||
import info.nightscout.androidaps.data.BgWatchData;
|
||||
import info.nightscout.androidaps.data.ListenerService;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.TempWatchData;
|
||||
import lecho.lib.hellocharts.view.LineChartView;
|
||||
|
||||
/**
|
||||
* Created by emmablack on 12/29/14.
|
||||
* Updated by andrew-warrington on 11/04/17.
|
||||
*/
|
||||
public abstract class BaseWatchFace2 extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public final static IntentFilter INTENT_FILTER;
|
||||
public static final long[] vibratePattern = {0,400,300,400,300,400};
|
||||
public TextView mTime, mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mStatus, mIOB1, mIOB2, mCOB, mLoop, mDay, mMonth;
|
||||
public RelativeLayout mRelativeLayout;
|
||||
public LinearLayout mLinearLayout, mLinearLayout2, mDate;
|
||||
public long sgvLevel = 0;
|
||||
public int batteryLevel = 1;
|
||||
public int ageLevel = 1;
|
||||
public int loopLevel = 1;
|
||||
public int highColor = Color.YELLOW;
|
||||
public int lowColor = Color.RED;
|
||||
public int midColor = Color.WHITE;
|
||||
public int gridColor = Color.WHITE;
|
||||
public int basalBackgroundColor = Color.BLUE;
|
||||
public int basalCenterColor = Color.BLUE;
|
||||
public boolean lowResMode = false;
|
||||
public int pointSize = 2;
|
||||
public boolean layoutSet = false;
|
||||
//public int missed_readings_alert_id = 818;
|
||||
public BgGraphBuilder bgGraphBuilder;
|
||||
public LineChartView chart;
|
||||
public double datetime;
|
||||
public ArrayList<BgWatchData> bgDataList = new ArrayList<>();
|
||||
public ArrayList<TempWatchData> tempWatchDataList = new ArrayList<>();
|
||||
public ArrayList<BasalWatchData> basalWatchDataList = new ArrayList<>();
|
||||
public PowerManager.WakeLock wakeLock;
|
||||
// related endTime manual layout
|
||||
public View layoutView;
|
||||
private final Point displaySize = new Point();
|
||||
private int specW, specH;
|
||||
|
||||
private LocalBroadcastManager localBroadcastManager;
|
||||
private MessageReceiver messageReceiver;
|
||||
|
||||
protected SharedPreferences sharedPrefs;
|
||||
private String openApsStatus = "--";
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
|
||||
.getDefaultDisplay();
|
||||
display.getSize(displaySize);
|
||||
wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Clock");
|
||||
|
||||
specW = View.MeasureSpec.makeMeasureSpec(displaySize.x,
|
||||
View.MeasureSpec.EXACTLY);
|
||||
specH = View.MeasureSpec.makeMeasureSpec(displaySize.y,
|
||||
View.MeasureSpec.EXACTLY);
|
||||
sharedPrefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(this);
|
||||
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(WatchShape shape, Rect screenBounds, WindowInsets screenInsets) {
|
||||
super.onLayout(shape, screenBounds, screenInsets);
|
||||
layoutView.onApplyWindowInsets(screenInsets);
|
||||
}
|
||||
|
||||
public void performViewSetup() {
|
||||
final WatchViewStub stub = (WatchViewStub) layoutView.findViewById(R.id.watch_view_stub);
|
||||
IntentFilter messageFilter = new IntentFilter(Intent.ACTION_SEND);
|
||||
|
||||
messageReceiver = new MessageReceiver();
|
||||
localBroadcastManager = LocalBroadcastManager.getInstance(this);
|
||||
localBroadcastManager.registerReceiver(messageReceiver, messageFilter);
|
||||
|
||||
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
|
||||
@Override
|
||||
public void onLayoutInflated(WatchViewStub stub) {
|
||||
mTime = (TextView) stub.findViewById(R.id.watch_time);
|
||||
mDay = (TextView) stub.findViewById(R.id.day);
|
||||
mMonth = (TextView) stub.findViewById(R.id.month);
|
||||
mLoop = (TextView) stub.findViewById(R.id.loop);
|
||||
mSgv = (TextView) stub.findViewById(R.id.sgv);
|
||||
mDirection = (TextView) stub.findViewById(R.id.direction);
|
||||
mTimestamp = (TextView) stub.findViewById(R.id.timestamp);
|
||||
mIOB1 = (TextView) stub.findViewById(R.id.iob_text);
|
||||
mIOB2 = (TextView) stub.findViewById(R.id.iobView);
|
||||
mCOB = (TextView) stub.findViewById(R.id.cobView);
|
||||
mStatus = (TextView) stub.findViewById(R.id.tmpBasal);
|
||||
mUploaderBattery = (TextView) stub.findViewById(R.id.uploader_battery);
|
||||
mRigBattery = (TextView) stub.findViewById(R.id.rig_battery);
|
||||
mDelta = (TextView) stub.findViewById(R.id.delta);
|
||||
mRelativeLayout = (RelativeLayout) stub.findViewById(R.id.main_layout);
|
||||
mLinearLayout = (LinearLayout) stub.findViewById(R.id.secondary_layout);
|
||||
mLinearLayout2 = (LinearLayout) stub.findViewById(R.id.tertiary_layout);
|
||||
mDate = (LinearLayout) stub.findViewById(R.id.date_time);
|
||||
chart = (LineChartView) stub.findViewById(R.id.chart);
|
||||
layoutSet = true;
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
}
|
||||
});
|
||||
ListenerService.requestData(this);
|
||||
wakeLock.acquire(50);
|
||||
}
|
||||
|
||||
public int ageLevel() {
|
||||
if(timeSince() <= (1000 * 60 * 12)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public double timeSince() {
|
||||
return System.currentTimeMillis() - datetime;
|
||||
}
|
||||
|
||||
public String readingAge(boolean shortString) {
|
||||
if (datetime == 0) { return shortString?"--'":"-- Minute ago"; }
|
||||
int minutesAgo = (int) Math.floor(timeSince()/(1000*60));
|
||||
if (minutesAgo == 1) {
|
||||
return minutesAgo + (shortString?"'":" Minute ago");
|
||||
}
|
||||
return minutesAgo + (shortString?"'":" Minutes ago");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if(localBroadcastManager != null && messageReceiver != null){
|
||||
localBroadcastManager.unregisterReceiver(messageReceiver);}
|
||||
if (sharedPrefs != null){
|
||||
sharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
static {
|
||||
INTENT_FILTER = new IntentFilter();
|
||||
INTENT_FILTER.addAction(Intent.ACTION_TIME_TICK);
|
||||
INTENT_FILTER.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
INTENT_FILTER.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if(layoutSet) {
|
||||
this.mRelativeLayout.draw(canvas);
|
||||
Log.d("onDraw", "draw");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTimeChanged(WatchFaceTime oldTime, WatchFaceTime newTime) {
|
||||
if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) {
|
||||
wakeLock.acquire(50);
|
||||
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace2.this);
|
||||
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||
mTimestamp.setText(readingAge(true));
|
||||
|
||||
if (sharedPrefs.getBoolean("show_date", false)) {
|
||||
Date today = new Date();
|
||||
SimpleDateFormat sdfDay = new SimpleDateFormat("dd");
|
||||
SimpleDateFormat sdfMonth = new SimpleDateFormat("MMM");
|
||||
mDay.setText(sdfDay.format(today));
|
||||
mMonth.setText(sdfMonth.format(today));
|
||||
mDate.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
//mDay.setText("");
|
||||
//mMonth.setText("");
|
||||
mDate.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(ageLevel()<=0) {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
} else {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
|
||||
missedReadingAlert();
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
|
||||
public class MessageReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
//data
|
||||
Bundle bundle = intent.getBundleExtra("data");
|
||||
if (layoutSet && bundle != null) {
|
||||
DataMap dataMap = DataMap.fromBundle(bundle);
|
||||
wakeLock.acquire(50);
|
||||
sgvLevel = dataMap.getLong("sgvLevel");
|
||||
datetime = dataMap.getDouble("timestamp");
|
||||
mSgv.setText(dataMap.getString("sgvString"));
|
||||
|
||||
if(ageLevel()<=0) {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
} else {
|
||||
mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
|
||||
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace2.this);
|
||||
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||
|
||||
mDirection.setText(dataMap.getString("slopeArrow"));
|
||||
String avgDelta = dataMap.getString("avgDelta");
|
||||
String delta = dataMap.getString("delta");
|
||||
|
||||
if (sharedPrefs.getBoolean("showDelta", true)) {
|
||||
mDelta.setText(delta);
|
||||
mDelta.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mDelta.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
boolean showAvgDelta = sharedPrefs.getBoolean("showAvgDelta", true);
|
||||
if(showAvgDelta){
|
||||
mDelta.append(" " + avgDelta);
|
||||
}
|
||||
|
||||
if (chart != null) {
|
||||
addToWatchSet(dataMap);
|
||||
setupCharts();
|
||||
}
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
invalidate();
|
||||
setColor();
|
||||
}
|
||||
|
||||
//status
|
||||
bundle = intent.getBundleExtra("status");
|
||||
if (layoutSet && bundle != null) {
|
||||
DataMap dataMap = DataMap.fromBundle(bundle);
|
||||
wakeLock.acquire(50);
|
||||
///externalStatusString = dataMap.getString("externalStatusString");
|
||||
batteryLevel = dataMap.getInt("batteryLevel");
|
||||
openApsStatus = dataMap.getString("openApsStatus");
|
||||
mCOB.setText(dataMap.getString("cob"));
|
||||
|
||||
if (dataMap.getBoolean("detailedIob")) {
|
||||
mIOB1.setTextSize(14);
|
||||
mIOB2.setTextSize(10);
|
||||
mIOB1.setText("IOB " + dataMap.getString("iobTotal"));
|
||||
mIOB2.setText(dataMap.getString("iobDetail"));
|
||||
} else {
|
||||
mIOB1.setTextSize(10);
|
||||
mIOB2.setTextSize(14);
|
||||
mIOB1.setText("IOB");
|
||||
mIOB2.setText(dataMap.getString("iobTotal"));
|
||||
}
|
||||
|
||||
|
||||
//use Config.APS to determine mode?
|
||||
if (sharedPrefs.getBoolean("show_uploader_battery", true)) {
|
||||
mUploaderBattery.setText(dataMap.getString("battery") + "%");
|
||||
mUploaderBattery.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mUploaderBattery.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (sharedPrefs.getBoolean("show_rig_battery", false)) {
|
||||
mRigBattery.setText(dataMap.getString("rigBattery"));
|
||||
mRigBattery.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mRigBattery.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (mTimestamp != null) {
|
||||
if (sharedPrefs.getBoolean("showAgo", true)) {
|
||||
mTimestamp.setText(readingAge(true));
|
||||
mTimestamp.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mTimestamp.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mStatus != null) {
|
||||
mStatus.setVisibility(View.VISIBLE);
|
||||
mStatus.setText("" + dataMap.getString("tempBasal"));
|
||||
}
|
||||
|
||||
if (mLoop != null) {
|
||||
if (sharedPrefs.getBoolean("showExternalStatus", true)) {
|
||||
mLoop.setVisibility(View.VISIBLE);
|
||||
String loopTime = dataMap.getString("openApsStatus");
|
||||
if (loopTime != null && loopTime != "") {
|
||||
mLoop.setText(loopTime + "'");
|
||||
if (Integer.valueOf(loopTime) > 14) {
|
||||
loopLevel = 0;
|
||||
mLoop.setBackgroundResource(R.drawable.loop_red_25);
|
||||
} else {
|
||||
loopLevel = 1;
|
||||
mLoop.setBackgroundResource(R.drawable.loop_green_25);
|
||||
}
|
||||
} else {
|
||||
mLoop.setText("-'");
|
||||
}
|
||||
} else {
|
||||
//mLoop.setText("");
|
||||
//mLoop.setBackgroundResource(R.drawable.empty);
|
||||
mLoop.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
invalidate();
|
||||
setColor();
|
||||
}
|
||||
|
||||
|
||||
//basals and temps
|
||||
bundle = intent.getBundleExtra("basals");
|
||||
if (layoutSet && bundle != null) {
|
||||
DataMap dataMap = DataMap.fromBundle(bundle);
|
||||
wakeLock.acquire(500);
|
||||
|
||||
loadBasalsAndTemps(dataMap);
|
||||
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
invalidate();
|
||||
setColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor() {
|
||||
if(lowResMode){
|
||||
setColorLowRes();
|
||||
} else if (sharedPrefs.getBoolean("dark", true)) {
|
||||
setColorDark();
|
||||
} else {
|
||||
setColorBright();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onWatchModeChanged(WatchMode watchMode) {
|
||||
|
||||
if(lowResMode ^ isLowRes(watchMode)){ //if there was a change in lowResMode
|
||||
lowResMode = isLowRes(watchMode);
|
||||
setColor();
|
||||
} else if (! sharedPrefs.getBoolean("dark", true)){
|
||||
//in bright mode: different colours if active:
|
||||
setColor();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLowRes(WatchMode watchMode) {
|
||||
return (watchMode == WatchMode.LOW_BIT) || (watchMode == WatchMode.LOW_BIT_BURN_IN) || (watchMode == WatchMode.LOW_BIT_BURN_IN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){
|
||||
setColor();
|
||||
if(layoutSet){
|
||||
mRelativeLayout.measure(specW, specH);
|
||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||
mRelativeLayout.getMeasuredHeight());
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
protected abstract void setColorDark();
|
||||
protected abstract void setColorBright();
|
||||
protected abstract void setColorLowRes();
|
||||
|
||||
|
||||
public void missedReadingAlert() {
|
||||
int minutes_since = (int) Math.floor(timeSince()/(1000*60));
|
||||
if(minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) {
|
||||
ListenerService.requestData(this); // attempt endTime recover missing data
|
||||
}
|
||||
}
|
||||
|
||||
public void addToWatchSet(DataMap dataMap) {
|
||||
|
||||
ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
|
||||
if (entries != null) {
|
||||
bgDataList = new ArrayList<BgWatchData>();
|
||||
for (DataMap entry : entries) {
|
||||
double sgv = entry.getDouble("sgvDouble");
|
||||
double high = entry.getDouble("high");
|
||||
double low = entry.getDouble("low");
|
||||
double timestamp = entry.getDouble("timestamp");
|
||||
bgDataList.add(new BgWatchData(sgv, high, low, timestamp));
|
||||
}
|
||||
} else {
|
||||
double sgv = dataMap.getDouble("sgvDouble");
|
||||
double high = dataMap.getDouble("high");
|
||||
double low = dataMap.getDouble("low");
|
||||
double timestamp = dataMap.getDouble("timestamp");
|
||||
|
||||
final int size = bgDataList.size();
|
||||
if (size > 0) {
|
||||
if (bgDataList.get(size - 1).timestamp == timestamp)
|
||||
return; // Ignore duplicates.
|
||||
}
|
||||
|
||||
bgDataList.add(new BgWatchData(sgv, high, low, timestamp));
|
||||
}
|
||||
|
||||
for (int i = 0; i < bgDataList.size(); i++) {
|
||||
if (bgDataList.get(i).timestamp < (System.currentTimeMillis() - (1000 * 60 * 60 * 5))) {
|
||||
bgDataList.remove(i); //Get rid of anything more than 5 hours old
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setupCharts() {
|
||||
if(bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things
|
||||
int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3"));
|
||||
if (lowResMode) {
|
||||
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, basalWatchDataList, pointSize, midColor, gridColor, basalBackgroundColor, basalCenterColor, timeframe);
|
||||
} else {
|
||||
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, basalWatchDataList, pointSize, highColor, lowColor, midColor, gridColor, basalBackgroundColor, basalCenterColor, timeframe);
|
||||
}
|
||||
|
||||
chart.setLineChartData(bgGraphBuilder.lineData());
|
||||
chart.setViewportCalculationEnabled(true);
|
||||
chart.setMaximumViewport(chart.getMaximumViewport());
|
||||
} else {
|
||||
ListenerService.requestData(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadBasalsAndTemps(DataMap dataMap) {
|
||||
ArrayList<DataMap> temps = dataMap.getDataMapArrayList("temps");
|
||||
if (temps != null) {
|
||||
tempWatchDataList = new ArrayList<>();
|
||||
for (DataMap temp : temps) {
|
||||
TempWatchData twd = new TempWatchData();
|
||||
twd.startTime = temp.getLong("starttime");
|
||||
twd.startBasal = temp.getDouble("startBasal");
|
||||
twd.endTime = temp.getLong("endtime");
|
||||
twd.endBasal = temp.getDouble("endbasal");
|
||||
twd.amount = temp.getDouble("amount");
|
||||
tempWatchDataList.add(twd);
|
||||
}
|
||||
}
|
||||
ArrayList<DataMap> basals = dataMap.getDataMapArrayList("basals");
|
||||
if (basals != null) {
|
||||
basalWatchDataList = new ArrayList<>();
|
||||
for (DataMap basal : basals) {
|
||||
BasalWatchData bwd = new BasalWatchData();
|
||||
bwd.startTime = basal.getLong("starttime");
|
||||
bwd.endTime = basal.getLong("endtime");
|
||||
bwd.amount = basal.getDouble("amount");
|
||||
basalWatchDataList.add(bwd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ import com.ustwo.clockwise.common.WatchMode;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity;
|
||||
|
||||
public class Home2 extends BaseWatchFace2 {
|
||||
public class Home2 extends BaseWatchFace {
|
||||
|
||||
private long chartTapTime = 0;
|
||||
private long sgvTapTime = 0;
|
||||
|
@ -63,22 +63,27 @@ public class Home2 extends BaseWatchFace2 {
|
|||
return new WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build();
|
||||
}
|
||||
|
||||
|
||||
protected void setColorDark() {
|
||||
mLinearLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_statusView));
|
||||
mTime.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_mTime));
|
||||
mLinearLayout2.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_background));
|
||||
mRelativeLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_background));
|
||||
mTime.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mIOB1.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mIOB2.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mCOB1.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mCOB2.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mDay.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mMonth.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mLoop.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
|
||||
if (sgvLevel == 1) {
|
||||
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
|
||||
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
|
||||
mDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
|
||||
} else if (sgvLevel == 0) {
|
||||
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
} else if (sgvLevel == -1) {
|
||||
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
|
||||
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
|
||||
mDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
|
||||
}
|
||||
|
||||
|
@ -93,6 +98,9 @@ public class Home2 extends BaseWatchFace2 {
|
|||
} else {
|
||||
mUploaderBattery.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_uploaderBatteryEmpty));
|
||||
}
|
||||
mRigBattery.setTextColor(Color.BLACK);
|
||||
mDelta.setTextColor(Color.BLACK);
|
||||
mBasalRate.setTextColor(Color.BLACK);
|
||||
|
||||
if (loopLevel == 1) {
|
||||
mLoop.setBackgroundResource(R.drawable.loop_green_25);
|
||||
|
@ -100,8 +108,6 @@ public class Home2 extends BaseWatchFace2 {
|
|||
mLoop.setBackgroundResource(R.drawable.loop_red_25);
|
||||
}
|
||||
|
||||
mStatus.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_mStatus_home));
|
||||
|
||||
if (chart != null) {
|
||||
highColor = ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor);
|
||||
lowColor = ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor);
|
||||
|
@ -115,13 +121,25 @@ public class Home2 extends BaseWatchFace2 {
|
|||
}
|
||||
|
||||
protected void setColorLowRes() {
|
||||
mTime.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_mTime));
|
||||
mLoop.setBackgroundResource(R.drawable.loop_grey_25);
|
||||
mLinearLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_statusView));
|
||||
mLinearLayout2.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_background));
|
||||
mRelativeLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_background));
|
||||
mLoop.setBackgroundResource(R.drawable.loop_grey_25);
|
||||
mLoop.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
// mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_Timestamp));
|
||||
mDelta.setTextColor(Color.BLACK);
|
||||
mRigBattery.setTextColor(Color.BLACK);
|
||||
mUploaderBattery.setTextColor(Color.BLACK);
|
||||
mBasalRate.setTextColor(Color.BLACK);
|
||||
mIOB1.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mIOB2.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mCOB1.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mCOB2.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mDay.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mMonth.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mTime.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_mTime));
|
||||
if (chart != null) {
|
||||
highColor = ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor);
|
||||
lowColor = ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor);
|
||||
|
@ -132,44 +150,55 @@ public class Home2 extends BaseWatchFace2 {
|
|||
pointSize = 2;
|
||||
setupCharts();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void setColorBright() {
|
||||
|
||||
if (getCurrentWatchMode() == WatchMode.INTERACTIVE) {
|
||||
mLinearLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.light_stripe_background));
|
||||
mLinearLayout2.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.light_background));
|
||||
mRelativeLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.light_background));
|
||||
mTime.setTextColor(Color.BLACK);
|
||||
mIOB1.setTextColor(Color.BLACK);
|
||||
mIOB2.setTextColor(Color.BLACK);
|
||||
mCOB1.setTextColor(Color.BLACK);
|
||||
mCOB2.setTextColor(Color.BLACK);
|
||||
mDay.setTextColor(Color.BLACK);
|
||||
mMonth.setTextColor(Color.BLACK);
|
||||
mLoop.setTextColor(Color.BLACK);
|
||||
|
||||
if (sgvLevel == 1) {
|
||||
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_highColor));
|
||||
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_highColor));
|
||||
mDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_highColor));
|
||||
} else if (sgvLevel == 0) {
|
||||
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_midColor));
|
||||
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_midColor));
|
||||
mDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_midColor));
|
||||
} else if (sgvLevel == -1) {
|
||||
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_lowColor));
|
||||
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_lowColor));
|
||||
mDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_lowColor));
|
||||
}
|
||||
|
||||
if (ageLevel == 1) {
|
||||
mTimestamp.setTextColor(Color.WHITE);
|
||||
mTimestamp.setTextColor(Color.BLACK);
|
||||
} else {
|
||||
mTimestamp.setTextColor(Color.RED);
|
||||
}
|
||||
|
||||
if (batteryLevel == 1) {
|
||||
mUploaderBattery.setTextColor(Color.WHITE);
|
||||
mUploaderBattery.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
} else {
|
||||
mUploaderBattery.setTextColor(Color.RED);
|
||||
}
|
||||
mRigBattery.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mBasalRate.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
|
||||
mStatus.setTextColor(Color.WHITE);
|
||||
if (loopLevel == 1) {
|
||||
mLoop.setBackgroundResource(R.drawable.loop_green_25);
|
||||
} else {
|
||||
mLoop.setBackgroundResource(R.drawable.loop_red_25);
|
||||
}
|
||||
|
||||
mTime.setTextColor(Color.BLACK);
|
||||
if (chart != null) {
|
||||
highColor = ContextCompat.getColor(getApplicationContext(), R.color.light_highColor);
|
||||
lowColor = ContextCompat.getColor(getApplicationContext(), R.color.light_lowColor);
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
|
@ -138,7 +138,8 @@
|
|||
android:textAlignment="center"
|
||||
android:textColor="#000000"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tmpBasal"
|
||||
|
@ -151,6 +152,13 @@
|
|||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/AAPSv2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -18,13 +18,35 @@
|
|||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="1"
|
||||
android:entries="@array/input_design"
|
||||
android:entryValues="@array/input_design_values"
|
||||
android:key="input_design"
|
||||
android:summary="Input Design"
|
||||
android:title="Input Design" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="show_date"
|
||||
android:title="Show Date"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="show_iob"
|
||||
android:title="Show IOB"
|
||||
android:summary="Show insulin on board."
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="show_cob"
|
||||
android:title="Show COB"
|
||||
android:summary="Show carb on board."
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="show_temp_basal"
|
||||
android:title="Show Temp Basal"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
|
@ -40,13 +62,6 @@
|
|||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="show_date"
|
||||
android:title="Show Date"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="showExternalStatus"
|
||||
|
@ -54,14 +69,6 @@
|
|||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="highlight_basals"
|
||||
android:summary="Better visible basal rate and temp basals"
|
||||
android:title="Highlight Basals"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="showDelta"
|
||||
|
@ -86,6 +93,22 @@
|
|||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="showBG"
|
||||
android:summary="Show BG. (Circle WF)"
|
||||
android:title="Show BG"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="show_direction"
|
||||
android:summary="Show direction arrow"
|
||||
android:title="Show Direction Arrow"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="dark"
|
||||
|
@ -94,6 +117,14 @@
|
|||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="highlight_basals"
|
||||
android:summary="Better visible basal rate and temp basals"
|
||||
android:title="Highlight Basals"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on"/>
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="3"
|
||||
android:entries="@array/chart_timeframe"
|
||||
|
@ -102,13 +133,13 @@
|
|||
android:summary="Chart Timeframe"
|
||||
android:title="Chart Timeframe" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="showBG"
|
||||
android:summary="Show BG. (Circle WF)"
|
||||
android:title="Show BG"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on"/>
|
||||
<ListPreference
|
||||
android:defaultValue="1"
|
||||
android:entries="@array/input_design"
|
||||
android:entryValues="@array/input_design_values"
|
||||
android:key="input_design"
|
||||
android:summary="Input Design"
|
||||
android:title="Input Design" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
|
|
Loading…
Reference in a new issue