2017-02-09 20:54:41 +01:00
|
|
|
package info.nightscout.androidaps.watchfaces;
|
2016-11-17 15:17:02 +01:00
|
|
|
|
|
|
|
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;
|
2019-05-16 13:57:37 +02:00
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
2016-11-17 15:17:02 +01:00
|
|
|
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;
|
2017-12-10 03:29:14 +01:00
|
|
|
import android.widget.ImageView;
|
2016-11-17 15:17:02 +01:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import com.google.android.gms.wearable.DataMap;
|
2016-11-27 06:12:20 +01:00
|
|
|
import com.ustwo.clockwise.common.WatchMode;
|
2016-11-25 21:29:46 +01:00
|
|
|
import com.ustwo.clockwise.wearable.WatchFace;
|
|
|
|
import com.ustwo.clockwise.common.WatchFaceTime;
|
|
|
|
import com.ustwo.clockwise.common.WatchShape;
|
2016-11-17 15:17:02 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
import java.text.SimpleDateFormat;
|
2016-11-17 15:17:02 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
|
2017-02-09 20:54:41 +01:00
|
|
|
import info.nightscout.androidaps.data.BasalWatchData;
|
|
|
|
import info.nightscout.androidaps.data.BgWatchData;
|
2018-03-11 21:18:03 +01:00
|
|
|
import info.nightscout.androidaps.data.BolusWatchData;
|
2017-02-09 20:54:41 +01:00
|
|
|
import info.nightscout.androidaps.data.ListenerService;
|
|
|
|
import info.nightscout.androidaps.R;
|
|
|
|
import info.nightscout.androidaps.data.TempWatchData;
|
2016-11-17 15:17:02 +01:00
|
|
|
import lecho.lib.hellocharts.view.LineChartView;
|
|
|
|
|
|
|
|
/**
|
2016-11-22 17:23:46 +01:00
|
|
|
* Created by emmablack on 12/29/14.
|
2018-01-02 00:30:20 +01:00
|
|
|
* Updated by andrew-warrington on 02-Jan-2018.
|
2016-11-17 15:17:02 +01:00
|
|
|
*/
|
2018-01-02 00:30:20 +01:00
|
|
|
|
2016-11-17 15:17:02 +01:00
|
|
|
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};
|
2017-11-28 09:24:52 +01:00
|
|
|
public TextView mTime, mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mAvgDelta, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mBgi, mLoop, mDay, mMonth, isAAPSv2, mHighLight, mLowLight;
|
2017-12-10 21:39:21 +01:00
|
|
|
public ImageView mGlucoseDial, mDeltaGauge, mHourHand, mMinuteHand;
|
2017-12-04 18:40:13 +01:00
|
|
|
public long datetime;
|
2016-11-17 15:17:02 +01:00
|
|
|
public RelativeLayout mRelativeLayout;
|
2018-01-03 15:24:06 +01:00
|
|
|
public LinearLayout mLinearLayout, mLinearLayout2, mDate, mChartTap, mMainMenuTap;
|
2016-11-17 15:17:02 +01:00
|
|
|
public long sgvLevel = 0;
|
|
|
|
public int ageLevel = 1;
|
2017-11-15 23:07:44 +01:00
|
|
|
public int loopLevel = 1;
|
|
|
|
public int batteryLevel = 1;
|
2016-11-17 15:17:02 +01:00
|
|
|
public int highColor = Color.YELLOW;
|
|
|
|
public int lowColor = Color.RED;
|
|
|
|
public int midColor = Color.WHITE;
|
2016-11-27 03:48:03 +01:00
|
|
|
public int gridColor = Color.WHITE;
|
2016-11-27 04:14:46 +01:00
|
|
|
public int basalBackgroundColor = Color.BLUE;
|
|
|
|
public int basalCenterColor = Color.BLUE;
|
2018-02-21 01:56:06 +01:00
|
|
|
public int bolusColor = Color.MAGENTA;
|
2016-11-27 06:12:20 +01:00
|
|
|
public boolean lowResMode = false;
|
2016-11-17 15:17:02 +01:00
|
|
|
public boolean layoutSet = false;
|
2017-11-22 22:46:43 +01:00
|
|
|
public boolean bIsRound = false;
|
2017-11-15 23:07:44 +01:00
|
|
|
public int pointSize = 2;
|
2016-11-17 15:17:02 +01:00
|
|
|
public BgGraphBuilder bgGraphBuilder;
|
|
|
|
public LineChartView chart;
|
|
|
|
public ArrayList<BgWatchData> bgDataList = new ArrayList<>();
|
2016-11-20 03:26:01 +01:00
|
|
|
public ArrayList<TempWatchData> tempWatchDataList = new ArrayList<>();
|
|
|
|
public ArrayList<BasalWatchData> basalWatchDataList = new ArrayList<>();
|
2018-03-11 21:18:03 +01:00
|
|
|
public ArrayList<BolusWatchData> bolusWatchDataList = new ArrayList<>();
|
2018-02-21 14:23:52 +01:00
|
|
|
public ArrayList<BgWatchData> predictionList = new ArrayList<>();
|
2018-03-11 21:18:03 +01:00
|
|
|
|
2016-11-17 15:17:02 +01:00
|
|
|
public PowerManager.WakeLock wakeLock;
|
2016-11-18 01:01:42 +01:00
|
|
|
// related endTime manual layout
|
2016-11-17 15:17:02 +01:00
|
|
|
public View layoutView;
|
2017-11-19 22:14:28 +01:00
|
|
|
public final Point displaySize = new Point();
|
|
|
|
public int specW, specH;
|
2016-11-17 15:17:02 +01:00
|
|
|
private LocalBroadcastManager localBroadcastManager;
|
|
|
|
private MessageReceiver messageReceiver;
|
|
|
|
|
|
|
|
protected SharedPreferences sharedPrefs;
|
2016-11-22 04:07:47 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
public boolean detailedIOB = false;
|
2017-11-28 09:24:52 +01:00
|
|
|
public boolean showBGI = false;
|
2018-01-02 00:30:20 +01:00
|
|
|
public boolean forceSquareCanvas = false; //set to true by the Steampunk watch face.
|
2017-12-04 18:40:13 +01:00
|
|
|
public long openApsStatus;
|
2017-11-15 23:07:44 +01:00
|
|
|
public String externalStatusString = "no status";
|
|
|
|
public String sSgv = "---";
|
|
|
|
public String sDirection = "--";
|
|
|
|
public String sUploaderBattery = "--";
|
|
|
|
public String sRigBattery = "--";
|
2017-11-28 09:24:52 +01:00
|
|
|
public String sDelta = "--";
|
|
|
|
public String sAvgDelta = "--";
|
2017-11-15 23:07:44 +01:00
|
|
|
public String sBasalRate = "-.--U/h";
|
|
|
|
public String sIOB1 = "IOB";
|
|
|
|
public String sIOB2 = "-.--";
|
|
|
|
public String sCOB1 = "Carb";
|
|
|
|
public String sCOB2 = "--g";
|
2017-11-28 09:24:52 +01:00
|
|
|
public String sBgi = "--";
|
2017-12-10 21:39:21 +01:00
|
|
|
public String sMinute = "0";
|
|
|
|
public String sHour = "0";
|
2017-12-12 23:17:25 +01:00
|
|
|
public String sUnits = "-";
|
2016-11-17 15:17:02 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
2018-01-02 00:30:20 +01:00
|
|
|
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
2016-11-17 15:17:02 +01:00
|
|
|
display.getSize(displaySize);
|
2019-04-08 16:48:19 +02:00
|
|
|
wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:BaseWatchFace");
|
2016-11-17 15:17:02 +01:00
|
|
|
|
2018-01-02 00:30:20 +01:00
|
|
|
specW = View.MeasureSpec.makeMeasureSpec(displaySize.x, View.MeasureSpec.EXACTLY);
|
|
|
|
if (forceSquareCanvas) {
|
|
|
|
specH = specW;
|
|
|
|
} else {
|
|
|
|
specH = View.MeasureSpec.makeMeasureSpec(displaySize.y, View.MeasureSpec.EXACTLY);
|
|
|
|
}
|
|
|
|
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2016-11-17 15:17:02 +01:00
|
|
|
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(WatchShape shape, Rect screenBounds, WindowInsets screenInsets) {
|
|
|
|
super.onLayout(shape, screenBounds, screenInsets);
|
|
|
|
layoutView.onApplyWindowInsets(screenInsets);
|
2017-11-22 22:46:43 +01:00
|
|
|
bIsRound = screenInsets.isRound();
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-11-15 23:07:44 +01:00
|
|
|
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);
|
2016-11-17 15:17:02 +01:00
|
|
|
mSgv = (TextView) stub.findViewById(R.id.sgv);
|
|
|
|
mDirection = (TextView) stub.findViewById(R.id.direction);
|
|
|
|
mTimestamp = (TextView) stub.findViewById(R.id.timestamp);
|
2017-11-15 23:07:44 +01:00
|
|
|
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);
|
2017-11-28 09:24:52 +01:00
|
|
|
mBgi = (TextView) stub.findViewById(R.id.bgiView);
|
2016-11-17 15:17:02 +01:00
|
|
|
mStatus = (TextView) stub.findViewById(R.id.externaltstatus);
|
2017-11-15 23:07:44 +01:00
|
|
|
mBasalRate = (TextView) stub.findViewById(R.id.tmpBasal);
|
2016-11-17 15:17:02 +01:00
|
|
|
mUploaderBattery = (TextView) stub.findViewById(R.id.uploader_battery);
|
2017-11-15 23:07:44 +01:00
|
|
|
mRigBattery = (TextView) stub.findViewById(R.id.rig_battery);
|
2016-11-17 15:17:02 +01:00
|
|
|
mDelta = (TextView) stub.findViewById(R.id.delta);
|
2017-11-28 09:24:52 +01:00
|
|
|
mAvgDelta = (TextView) stub.findViewById(R.id.avgdelta);
|
2017-11-15 23:07:44 +01:00
|
|
|
isAAPSv2 = (TextView) stub.findViewById(R.id.AAPSv2);
|
2017-11-19 22:14:28 +01:00
|
|
|
mHighLight = (TextView) stub.findViewById(R.id.highLight);
|
|
|
|
mLowLight = (TextView) stub.findViewById(R.id.lowLight);
|
2016-11-17 15:17:02 +01:00
|
|
|
mRelativeLayout = (RelativeLayout) stub.findViewById(R.id.main_layout);
|
|
|
|
mLinearLayout = (LinearLayout) stub.findViewById(R.id.secondary_layout);
|
2017-11-15 23:07:44 +01:00
|
|
|
mLinearLayout2 = (LinearLayout) stub.findViewById(R.id.tertiary_layout);
|
2017-12-10 03:29:14 +01:00
|
|
|
mGlucoseDial = (ImageView) stub.findViewById(R.id.glucose_dial);
|
2017-12-10 21:39:21 +01:00
|
|
|
mDeltaGauge = (ImageView) stub.findViewById(R.id.delta_pointer);
|
|
|
|
mHourHand = (ImageView) stub.findViewById(R.id.hour_hand);
|
|
|
|
mMinuteHand = (ImageView) stub.findViewById(R.id.minute_hand);
|
2018-01-03 15:24:06 +01:00
|
|
|
mChartTap = (LinearLayout) stub.findViewById(R.id.chart_zoom_tap);
|
|
|
|
mMainMenuTap = (LinearLayout) stub.findViewById(R.id.main_menu_tap);
|
2016-11-17 15:17:02 +01:00
|
|
|
chart = (LineChartView) stub.findViewById(R.id.chart);
|
|
|
|
layoutSet = true;
|
2017-11-15 23:07:44 +01:00
|
|
|
|
|
|
|
setDataFields();
|
2017-12-10 03:29:14 +01:00
|
|
|
setColor();
|
2017-11-15 23:07:44 +01:00
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
2017-11-15 23:07:44 +01:00
|
|
|
);
|
2016-11-17 15:17:02 +01:00
|
|
|
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() {
|
2017-11-15 23:07:44 +01:00
|
|
|
if (localBroadcastManager != null && messageReceiver != null) {
|
|
|
|
localBroadcastManager.unregisterReceiver(messageReceiver);
|
|
|
|
}
|
|
|
|
if (sharedPrefs != null) {
|
2016-11-17 15:17:02 +01:00
|
|
|
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) {
|
2017-11-15 23:07:44 +01:00
|
|
|
if (layoutSet) {
|
2017-12-04 20:08:57 +01:00
|
|
|
setupCharts();
|
2018-01-02 00:30:20 +01:00
|
|
|
|
|
|
|
mRelativeLayout.measure(specW, specH);
|
|
|
|
if (forceSquareCanvas) {
|
|
|
|
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.x); //force a square for Steampunk watch face.
|
|
|
|
} else {
|
|
|
|
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y);
|
|
|
|
}
|
|
|
|
mRelativeLayout.draw(canvas);
|
2016-11-17 15:17:02 +01:00
|
|
|
Log.d("onDraw", "draw");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onTimeChanged(WatchFaceTime oldTime, WatchFaceTime newTime) {
|
|
|
|
if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) {
|
|
|
|
wakeLock.acquire(50);
|
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
setDataFields();
|
2017-12-10 03:29:14 +01:00
|
|
|
setColor();
|
2016-11-17 15:17:02 +01:00
|
|
|
missedReadingAlert();
|
2017-11-28 09:24:52 +01:00
|
|
|
|
2016-11-17 15:17:02 +01:00
|
|
|
mRelativeLayout.measure(specW, specH);
|
2018-01-02 00:30:20 +01:00
|
|
|
if (forceSquareCanvas) {
|
|
|
|
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.x); //force a square for Steampunk watch face.
|
|
|
|
} else {
|
|
|
|
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y);
|
|
|
|
}
|
|
|
|
invalidate();
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class MessageReceiver extends BroadcastReceiver {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
|
|
|
Bundle bundle = intent.getBundleExtra("data");
|
|
|
|
if (layoutSet && bundle != null) {
|
|
|
|
DataMap dataMap = DataMap.fromBundle(bundle);
|
|
|
|
wakeLock.acquire(50);
|
|
|
|
sgvLevel = dataMap.getLong("sgvLevel");
|
2017-12-04 18:40:13 +01:00
|
|
|
datetime = dataMap.getLong("timestamp");
|
2017-11-15 23:07:44 +01:00
|
|
|
sSgv = dataMap.getString("sgvString");
|
|
|
|
sDirection = dataMap.getString("slopeArrow");
|
|
|
|
sDelta = dataMap.getString("delta");
|
|
|
|
sAvgDelta = dataMap.getString("avgDelta");
|
2017-12-12 23:17:25 +01:00
|
|
|
sUnits = dataMap.getString("glucoseUnits");
|
2016-11-17 15:17:02 +01:00
|
|
|
if (chart != null) {
|
|
|
|
addToWatchSet(dataMap);
|
|
|
|
setupCharts();
|
|
|
|
}
|
|
|
|
}
|
2017-11-15 23:07:44 +01:00
|
|
|
|
2016-11-17 15:17:02 +01:00
|
|
|
bundle = intent.getBundleExtra("status");
|
|
|
|
if (layoutSet && bundle != null) {
|
|
|
|
DataMap dataMap = DataMap.fromBundle(bundle);
|
|
|
|
wakeLock.acquire(50);
|
2017-12-18 21:58:02 +01:00
|
|
|
sBasalRate = dataMap.getString("currentBasal");
|
2017-11-15 23:07:44 +01:00
|
|
|
sUploaderBattery = dataMap.getString("battery");
|
|
|
|
sRigBattery = dataMap.getString("rigBattery");
|
|
|
|
detailedIOB = dataMap.getBoolean("detailedIob");
|
2017-11-28 09:24:52 +01:00
|
|
|
sIOB1 = dataMap.getString("iobSum") + "U";
|
2017-11-15 23:07:44 +01:00
|
|
|
sIOB2 = dataMap.getString("iobDetail");
|
|
|
|
sCOB1 = "Carb";
|
|
|
|
sCOB2 = dataMap.getString("cob");
|
2017-11-28 09:24:52 +01:00
|
|
|
sBgi = dataMap.getString("bgi");
|
|
|
|
showBGI = dataMap.getBoolean("showBgi");
|
2016-11-17 15:17:02 +01:00
|
|
|
externalStatusString = dataMap.getString("externalStatusString");
|
2017-11-15 23:07:44 +01:00
|
|
|
batteryLevel = dataMap.getInt("batteryLevel");
|
2017-12-04 18:40:13 +01:00
|
|
|
openApsStatus = dataMap.getLong("openApsStatus");
|
2017-11-15 23:07:44 +01:00
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
setDataFields();
|
2017-12-10 03:29:14 +01:00
|
|
|
setColor();
|
2016-11-17 15:17:02 +01:00
|
|
|
|
2016-11-20 03:26:01 +01:00
|
|
|
bundle = intent.getBundleExtra("basals");
|
|
|
|
if (layoutSet && bundle != null) {
|
|
|
|
DataMap dataMap = DataMap.fromBundle(bundle);
|
|
|
|
wakeLock.acquire(500);
|
|
|
|
loadBasalsAndTemps(dataMap);
|
|
|
|
}
|
2017-11-15 23:07:44 +01:00
|
|
|
|
|
|
|
mRelativeLayout.measure(specW, specH);
|
2018-01-02 00:30:20 +01:00
|
|
|
if (forceSquareCanvas) {
|
|
|
|
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.x); //force a square for Steampunk watch face.
|
|
|
|
} else {
|
|
|
|
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y);
|
|
|
|
}
|
2017-11-15 23:07:44 +01:00
|
|
|
invalidate();
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
public void setDataFields() {
|
2016-11-17 15:17:02 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
setDateAndTime();
|
2016-11-22 04:07:47 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
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("");
|
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
strikeThroughSgvIfNeeded();
|
2016-11-22 04:07:47 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
if (mDirection != null) {
|
|
|
|
if (sharedPrefs.getBoolean("show_direction", true)) {
|
|
|
|
mDirection.setText(sDirection);
|
|
|
|
mDirection.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mDirection.setVisibility(View.GONE);
|
|
|
|
}
|
2016-11-22 04:07:47 +01:00
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
if (mDelta != null) {
|
|
|
|
if (sharedPrefs.getBoolean("showDelta", true)) {
|
|
|
|
mDelta.setText(sDelta);
|
|
|
|
mDelta.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mDelta.setVisibility(View.GONE);
|
|
|
|
}
|
2017-11-28 09:24:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mAvgDelta != null) {
|
2017-11-15 23:07:44 +01:00
|
|
|
if (sharedPrefs.getBoolean("showAvgDelta", true)) {
|
2017-11-28 09:24:52 +01:00
|
|
|
mAvgDelta.setText(sAvgDelta);
|
|
|
|
mAvgDelta.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mAvgDelta.setVisibility(View.GONE);
|
2017-11-15 23:07:44 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
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);
|
|
|
|
}
|
2017-11-19 22:14:28 +01:00
|
|
|
//deal with cases where there is only the value shown for COB, and not the label
|
|
|
|
} else if (mCOB2 != null) {
|
|
|
|
mCOB2.setText(sCOB2);
|
|
|
|
if (sharedPrefs.getBoolean("show_cob", true)) {
|
|
|
|
mCOB2.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mCOB2.setVisibility(View.GONE);
|
|
|
|
}
|
2017-11-15 23:07:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mIOB1 != null && mIOB2 != null) {
|
|
|
|
if (sharedPrefs.getBoolean("show_iob", true)) {
|
|
|
|
mIOB1.setVisibility(View.VISIBLE);
|
|
|
|
mIOB2.setVisibility(View.VISIBLE);
|
|
|
|
if (detailedIOB) {
|
2017-11-22 22:46:43 +01:00
|
|
|
mIOB1.setText(sIOB1);
|
2017-11-15 23:07:44 +01:00
|
|
|
mIOB2.setText(sIOB2);
|
|
|
|
} else {
|
|
|
|
mIOB1.setText("IOB");
|
|
|
|
mIOB2.setText(sIOB1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mIOB1.setVisibility(View.GONE);
|
|
|
|
mIOB2.setVisibility(View.GONE);
|
|
|
|
}
|
2017-11-19 22:14:28 +01:00
|
|
|
//deal with cases where there is only the value shown for IOB, and not the label
|
|
|
|
} else if (mIOB2 != null) {
|
|
|
|
if (sharedPrefs.getBoolean("show_iob", true)) {
|
|
|
|
mIOB2.setVisibility(View.VISIBLE);
|
|
|
|
if (detailedIOB) {
|
|
|
|
mIOB2.setText(sIOB2);
|
|
|
|
} else {
|
|
|
|
mIOB2.setText(sIOB1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mIOB2.setText("");
|
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-28 09:24:52 +01:00
|
|
|
if (mBgi != null) {
|
|
|
|
if (showBGI) {
|
|
|
|
mBgi.setText(sBgi);
|
|
|
|
mBgi.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mBgi.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
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);
|
2017-12-04 18:40:13 +01:00
|
|
|
if (openApsStatus != -1) {
|
2017-12-03 18:53:52 +01:00
|
|
|
int mins = (int) ((System.currentTimeMillis() - openApsStatus) / 1000 / 60);
|
|
|
|
mLoop.setText(mins + "'");
|
|
|
|
if (mins > 14) {
|
2017-11-15 23:07:44 +01:00
|
|
|
loopLevel = 0;
|
2017-12-03 18:53:52 +01:00
|
|
|
mLoop.setBackgroundResource(R.drawable.loop_red_25);
|
2017-11-15 23:07:44 +01:00
|
|
|
} else {
|
|
|
|
loopLevel = 1;
|
2017-12-03 18:53:52 +01:00
|
|
|
mLoop.setBackgroundResource(R.drawable.loop_green_25);
|
2017-11-15 23:07:44 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mLoop.setText("-'");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mLoop.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDateAndTime() {
|
|
|
|
|
|
|
|
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
|
2017-12-09 14:23:43 +01:00
|
|
|
if (mTime != null) {
|
|
|
|
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
|
|
|
}
|
2017-11-15 23:07:44 +01:00
|
|
|
|
2017-12-10 21:39:21 +01:00
|
|
|
Date now = new Date();
|
|
|
|
SimpleDateFormat sdfHour = new SimpleDateFormat("HH");
|
|
|
|
SimpleDateFormat sdfMinute = new SimpleDateFormat("mm");
|
|
|
|
sHour = sdfHour.format(now);
|
|
|
|
sMinute = sdfMinute.format(now);
|
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
if (mDate != null && mDay != null && mMonth != null) {
|
|
|
|
if (sharedPrefs.getBoolean("show_date", false)) {
|
|
|
|
SimpleDateFormat sdfDay = new SimpleDateFormat("dd");
|
|
|
|
SimpleDateFormat sdfMonth = new SimpleDateFormat("MMM");
|
2017-12-10 21:39:21 +01:00
|
|
|
mDay.setText(sdfDay.format(now));
|
|
|
|
mMonth.setText(sdfMonth.format(now));
|
2017-11-15 23:07:44 +01:00
|
|
|
mDate.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mDate.setVisibility(View.GONE);
|
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setColor() {
|
2016-11-27 06:12:20 +01:00
|
|
|
if(lowResMode){
|
|
|
|
setColorLowRes();
|
|
|
|
} else if (sharedPrefs.getBoolean("dark", true)) {
|
2016-11-17 15:17:02 +01:00
|
|
|
setColorDark();
|
|
|
|
} else {
|
|
|
|
setColorBright();
|
|
|
|
}
|
2016-11-27 06:12:20 +01:00
|
|
|
}
|
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 06:12:20 +01:00
|
|
|
protected void onWatchModeChanged(WatchMode watchMode) {
|
2016-11-17 15:17:02 +01:00
|
|
|
|
2016-11-27 06:12:20 +01:00
|
|
|
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();
|
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
|
2016-11-27 06:12:20 +01:00
|
|
|
private boolean isLowRes(WatchMode watchMode) {
|
2017-11-22 22:46:43 +01:00
|
|
|
return (watchMode == WatchMode.LOW_BIT) || (watchMode == WatchMode.LOW_BIT_BURN_IN); // || (watchMode == WatchMode.LOW_BIT_BURN_IN);
|
2016-11-27 06:12:20 +01:00
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){
|
2017-11-15 23:07:44 +01:00
|
|
|
|
2018-01-04 12:22:08 +01:00
|
|
|
if("delta_granularity".equals(key)){
|
|
|
|
ListenerService.requestData(this);
|
|
|
|
}
|
|
|
|
|
2016-11-17 15:17:02 +01:00
|
|
|
if(layoutSet){
|
2017-11-15 23:07:44 +01:00
|
|
|
setDataFields();
|
2017-12-17 23:07:44 +01:00
|
|
|
setColor();
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
2017-11-28 09:24:52 +01:00
|
|
|
invalidate();
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
2017-11-28 09:24:52 +01:00
|
|
|
|
2017-11-15 23:07:44 +01:00
|
|
|
protected abstract void setColorDark();
|
2016-11-17 15:17:02 +01:00
|
|
|
protected abstract void setColorBright();
|
2016-11-27 06:12:20 +01:00
|
|
|
protected abstract void setColorLowRes();
|
2016-11-17 15:17:02 +01:00
|
|
|
|
|
|
|
public void missedReadingAlert() {
|
|
|
|
int minutes_since = (int) Math.floor(timeSince()/(1000*60));
|
|
|
|
if(minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) {
|
2016-11-18 01:01:42 +01:00
|
|
|
ListenerService.requestData(this); // attempt endTime recover missing data
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addToWatchSet(DataMap dataMap) {
|
|
|
|
|
|
|
|
ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
|
|
|
|
if (entries != null) {
|
2016-11-27 06:12:20 +01:00
|
|
|
bgDataList = new ArrayList<BgWatchData>();
|
2016-11-17 15:17:02 +01:00
|
|
|
for (DataMap entry : entries) {
|
|
|
|
double sgv = entry.getDouble("sgvDouble");
|
|
|
|
double high = entry.getDouble("high");
|
|
|
|
double low = entry.getDouble("low");
|
2017-12-04 18:40:13 +01:00
|
|
|
long timestamp = entry.getLong("timestamp");
|
2018-05-02 00:51:59 +02:00
|
|
|
int color = entry.getInt("color", 0);
|
|
|
|
bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color));
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
double sgv = dataMap.getDouble("sgvDouble");
|
|
|
|
double high = dataMap.getDouble("high");
|
|
|
|
double low = dataMap.getDouble("low");
|
2017-12-04 18:40:13 +01:00
|
|
|
long timestamp = dataMap.getLong("timestamp");
|
2018-05-02 00:51:59 +02:00
|
|
|
int color = dataMap.getInt("color", 0);
|
2016-11-17 15:17:02 +01:00
|
|
|
|
|
|
|
final int size = bgDataList.size();
|
|
|
|
if (size > 0) {
|
|
|
|
if (bgDataList.get(size - 1).timestamp == timestamp)
|
|
|
|
return; // Ignore duplicates.
|
|
|
|
}
|
|
|
|
|
2018-05-02 00:51:59 +02:00
|
|
|
bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color));
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < bgDataList.size(); i++) {
|
2017-06-15 23:12:12 +02:00
|
|
|
if (bgDataList.get(i).timestamp < (System.currentTimeMillis() - (1000 * 60 * 60 * 5))) {
|
2016-11-17 15:17:02 +01:00
|
|
|
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
|
2016-11-20 02:31:15 +01:00
|
|
|
int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3"));
|
2016-11-27 06:12:20 +01:00
|
|
|
if (lowResMode) {
|
2018-03-11 21:18:03 +01:00
|
|
|
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, predictionList, tempWatchDataList, basalWatchDataList, bolusWatchDataList, pointSize, midColor, gridColor, basalBackgroundColor, basalCenterColor, bolusColor, Color.GREEN, timeframe);
|
2016-11-17 15:17:02 +01:00
|
|
|
} else {
|
2018-03-11 21:18:03 +01:00
|
|
|
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList,predictionList, tempWatchDataList, basalWatchDataList, bolusWatchDataList, pointSize, highColor, lowColor, midColor, gridColor, basalBackgroundColor, basalCenterColor, bolusColor, Color.GREEN, timeframe);
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
chart.setLineChartData(bgGraphBuilder.lineData());
|
|
|
|
chart.setViewportCalculationEnabled(true);
|
|
|
|
chart.setMaximumViewport(chart.getMaximumViewport());
|
|
|
|
}
|
|
|
|
}
|
2016-11-20 03:26:01 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 21:18:03 +01:00
|
|
|
ArrayList<DataMap> boluses = dataMap.getDataMapArrayList("boluses");
|
|
|
|
if (boluses != null) {
|
|
|
|
bolusWatchDataList = new ArrayList<>();
|
|
|
|
for (DataMap bolus : boluses) {
|
|
|
|
BolusWatchData bwd = new BolusWatchData();
|
|
|
|
bwd.date = bolus.getLong("date");
|
|
|
|
bwd.bolus = bolus.getDouble("bolus");
|
|
|
|
bwd.carbs = bolus.getDouble("carbs");
|
|
|
|
bwd.isSMB = bolus.getBoolean("isSMB");
|
|
|
|
bwd.isValid = bolus.getBoolean("isValid");
|
|
|
|
bolusWatchDataList.add(bwd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ArrayList<DataMap> predictions = dataMap.getDataMapArrayList("predictions");
|
|
|
|
if (boluses != null) {
|
|
|
|
predictionList = new ArrayList<>();
|
|
|
|
for (DataMap prediction : predictions) {
|
|
|
|
BgWatchData bwd = new BgWatchData();
|
|
|
|
bwd.timestamp = prediction.getLong("timestamp");
|
|
|
|
bwd.sgv = prediction.getDouble("sgv");
|
2018-05-02 00:51:59 +02:00
|
|
|
bwd.color = prediction.getInt("color");
|
2018-03-11 21:18:03 +01:00
|
|
|
predictionList.add(bwd);
|
|
|
|
}
|
|
|
|
}
|
2016-11-20 03:26:01 +01:00
|
|
|
}
|
2016-11-17 15:17:02 +01:00
|
|
|
}
|