Merge pull request #273 from AdrianLxM/nighttime-watchface
nighttime watchface
This commit is contained in:
commit
1c35daf403
7 changed files with 768 additions and 0 deletions
|
@ -27,6 +27,7 @@ android {
|
||||||
resValue "string", "label_xdrip", "AAPS"
|
resValue "string", "label_xdrip", "AAPS"
|
||||||
resValue "string", "label_xdrip_large", "AAPS(Large)"
|
resValue "string", "label_xdrip_large", "AAPS(Large)"
|
||||||
resValue "string", "label_xdrip_big_chart", "AAPS(BigChart)"
|
resValue "string", "label_xdrip_big_chart", "AAPS(BigChart)"
|
||||||
|
resValue "string", "label_xdrip_no_chart", "AAPS(NoChart)"
|
||||||
resValue "string", "label_xdrip_circle", "AAPS(Circle)"
|
resValue "string", "label_xdrip_circle", "AAPS(Circle)"
|
||||||
resValue "string", "label_xdrip_activity", "AAPS Prefs."
|
resValue "string", "label_xdrip_activity", "AAPS Prefs."
|
||||||
resValue "string", "app_settings", "AAPS Settings"
|
resValue "string", "app_settings", "AAPS Settings"
|
||||||
|
@ -39,6 +40,7 @@ android {
|
||||||
resValue "string", "label_xdrip", "AAPS"
|
resValue "string", "label_xdrip", "AAPS"
|
||||||
resValue "string", "label_xdrip_large", "AAPS(Large)"
|
resValue "string", "label_xdrip_large", "AAPS(Large)"
|
||||||
resValue "string", "label_xdrip_big_chart", "AAPS(BigChart)"
|
resValue "string", "label_xdrip_big_chart", "AAPS(BigChart)"
|
||||||
|
resValue "string", "label_xdrip_no_chart", "AAPS(NoChart)"
|
||||||
resValue "string", "label_xdrip_circle", "AAPS(Circle)"
|
resValue "string", "label_xdrip_circle", "AAPS(Circle)"
|
||||||
resValue "string", "label_xdrip_activity", "AAPS Prefs."
|
resValue "string", "label_xdrip_activity", "AAPS Prefs."
|
||||||
resValue "string", "app_settings", "AAPS Settings"
|
resValue "string", "app_settings", "AAPS Settings"
|
||||||
|
|
|
@ -34,6 +34,24 @@
|
||||||
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
|
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
<service
|
||||||
|
android:name=".watchfaces.NOChart"
|
||||||
|
android:allowEmbedded="true"
|
||||||
|
android:label="@string/label_xdrip_no_chart"
|
||||||
|
android:permission="android.permission.BIND_WALLPAPER">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.service.wallpaper"
|
||||||
|
android:resource="@xml/watch_face" />
|
||||||
|
<meta-data
|
||||||
|
android:name="com.google.android.wearable.watchface.preview"
|
||||||
|
android:resource="@drawable/watchface_nochart" />
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.service.wallpaper.WallpaperService" />
|
||||||
|
|
||||||
|
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
<service
|
<service
|
||||||
android:name=".watchfaces.Home"
|
android:name=".watchfaces.Home"
|
||||||
android:allowEmbedded="true"
|
android:allowEmbedded="true"
|
||||||
|
|
|
@ -0,0 +1,520 @@
|
||||||
|
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.LinearGradient;
|
||||||
|
import android.graphics.Matrix;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Point;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.Shader;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
import android.support.wearable.view.WatchViewStub;
|
||||||
|
import android.support.wearable.watchface.WatchFaceStyle;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Display;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.WindowInsets;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.google.android.gms.wearable.DataMap;
|
||||||
|
import com.ustwo.clockwise.common.WatchFaceTime;
|
||||||
|
import com.ustwo.clockwise.common.WatchMode;
|
||||||
|
import com.ustwo.clockwise.common.WatchShape;
|
||||||
|
import com.ustwo.clockwise.wearable.WatchFace;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.BasalWatchData;
|
||||||
|
import info.nightscout.androidaps.data.BgWatchData;
|
||||||
|
import info.nightscout.androidaps.data.ListenerService;
|
||||||
|
import info.nightscout.androidaps.data.TempWatchData;
|
||||||
|
import info.nightscout.androidaps.interaction.menus.MainMenuActivity;
|
||||||
|
import lecho.lib.hellocharts.view.LineChartView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adrianLxM.
|
||||||
|
*/
|
||||||
|
public class NOChart extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
public final static IntentFilter INTENT_FILTER;
|
||||||
|
public TextView mTime, mSgv, mTimestamp, mDelta, mAvgDelta;
|
||||||
|
public RelativeLayout mRelativeLayout;
|
||||||
|
public long sgvLevel = 0;
|
||||||
|
public int batteryLevel = 1;
|
||||||
|
public int ageLevel = 1;
|
||||||
|
public boolean lowResMode = false;
|
||||||
|
public boolean layoutSet = false;
|
||||||
|
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;
|
||||||
|
public View layoutView;
|
||||||
|
private final Point displaySize = new Point();
|
||||||
|
private int specW, specH;
|
||||||
|
private int animationAngle = 0;
|
||||||
|
private boolean isAnimated = false;
|
||||||
|
|
||||||
|
private LocalBroadcastManager localBroadcastManager;
|
||||||
|
private MessageReceiver messageReceiver;
|
||||||
|
|
||||||
|
protected SharedPreferences sharedPrefs;
|
||||||
|
private String sgvString = "--";
|
||||||
|
private String externalStatusString = "no status";
|
||||||
|
private TextView statusView;
|
||||||
|
private long sgvTapTime = 0l;
|
||||||
|
|
||||||
|
@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);
|
||||||
|
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
layoutView = inflater.inflate(R.layout.activity_nochart, null);
|
||||||
|
performViewSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
mSgv = (TextView) stub.findViewById(R.id.sgv);
|
||||||
|
mTimestamp = (TextView) stub.findViewById(R.id.timestamp);
|
||||||
|
mDelta = (TextView) stub.findViewById(R.id.delta);
|
||||||
|
mAvgDelta = (TextView) stub.findViewById(R.id.avgdelta);
|
||||||
|
mRelativeLayout = (RelativeLayout) stub.findViewById(R.id.main_layout);
|
||||||
|
statusView = (TextView) stub.findViewById(R.id.aps_status);
|
||||||
|
layoutSet = true;
|
||||||
|
showAgeAndStatus();
|
||||||
|
mRelativeLayout.measure(specW, specH);
|
||||||
|
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||||
|
mRelativeLayout.getMeasuredHeight());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ListenerService.requestData(this);
|
||||||
|
wakeLock.acquire(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onTapCommand(int tapType, int x, int y, long eventTime) {
|
||||||
|
|
||||||
|
int extra = mSgv!=null?(mSgv.getRight() - mSgv.getLeft())/2:0;
|
||||||
|
|
||||||
|
if (tapType == TAP_TYPE_TAP&&
|
||||||
|
x + extra >=mSgv.getLeft() &&
|
||||||
|
x - extra <= mSgv.getRight()&&
|
||||||
|
y >= mSgv.getTop() &&
|
||||||
|
y <= mSgv.getBottom()){
|
||||||
|
if (eventTime - sgvTapTime < 800){
|
||||||
|
Intent intent = new Intent(this, MainMenuActivity.class);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
sgvTapTime = eventTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
protected WatchFaceStyle getWatchFaceStyle(){
|
||||||
|
return new WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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(NOChart.this);
|
||||||
|
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||||
|
showAgeAndStatus();
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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");
|
||||||
|
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(NOChart.this);
|
||||||
|
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||||
|
|
||||||
|
showAgeAndStatus();
|
||||||
|
|
||||||
|
String delta = dataMap.getString("delta");
|
||||||
|
|
||||||
|
if (delta.endsWith(" mg/dl")) {
|
||||||
|
mDelta.setText(delta.substring(0, delta.length() - 6));
|
||||||
|
} else if (delta.endsWith(" mmol/l")||delta.endsWith(" mmol")) {
|
||||||
|
mDelta.setText(delta.substring(0, delta.length() - 5));
|
||||||
|
} else {
|
||||||
|
mDelta.setText(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String avgDelta = dataMap.getString("avgDelta");
|
||||||
|
|
||||||
|
if (delta.endsWith(" mg/dl")) {
|
||||||
|
mAvgDelta.setText(avgDelta.substring(0, avgDelta.length() - 6));
|
||||||
|
} else if (avgDelta.endsWith(" mmol/l")||avgDelta.endsWith(" mmol")) {
|
||||||
|
mAvgDelta.setText(avgDelta.substring(0, avgDelta.length() - 5));
|
||||||
|
} else {
|
||||||
|
mAvgDelta.setText(avgDelta);
|
||||||
|
}
|
||||||
|
|
||||||
|
mRelativeLayout.measure(specW, specH);
|
||||||
|
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||||
|
mRelativeLayout.getMeasuredHeight());
|
||||||
|
invalidate();
|
||||||
|
setColor();
|
||||||
|
|
||||||
|
//start animation?
|
||||||
|
// dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
|
||||||
|
if (!lowResMode && (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (sgvString.equals("100") || sgvString.equals("5.5") || sgvString.equals("5,5")))) {
|
||||||
|
startAnimation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//status
|
||||||
|
bundle = intent.getBundleExtra("status");
|
||||||
|
if (layoutSet && bundle != null) {
|
||||||
|
DataMap dataMap = DataMap.fromBundle(bundle);
|
||||||
|
wakeLock.acquire(50);
|
||||||
|
externalStatusString = dataMap.getString("externalStatusString");
|
||||||
|
|
||||||
|
showAgeAndStatus();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showAgeAndStatus() {
|
||||||
|
|
||||||
|
if( mTimestamp != null){
|
||||||
|
mTimestamp.setText(readingAge(true));
|
||||||
|
}
|
||||||
|
boolean showAvgDelta = sharedPrefs.getBoolean("showAvgDelta", true);
|
||||||
|
|
||||||
|
if(showAvgDelta){
|
||||||
|
mAvgDelta.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
mAvgDelta.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
statusView.setText(externalStatusString);
|
||||||
|
statusView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor() {
|
||||||
|
if(lowResMode){
|
||||||
|
setColorLowRes();
|
||||||
|
} else if (sharedPrefs.getBoolean("dark", true)) {
|
||||||
|
setColorDark();
|
||||||
|
} else {
|
||||||
|
setColorBright();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){
|
||||||
|
setColor();
|
||||||
|
if(layoutSet){
|
||||||
|
showAgeAndStatus();
|
||||||
|
mRelativeLayout.measure(specW, specH);
|
||||||
|
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||||
|
mRelativeLayout.getMeasuredHeight());
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateRainbow() {
|
||||||
|
animationAngle = (animationAngle + 1) % 360;
|
||||||
|
//Animation matrix:
|
||||||
|
int[] rainbow = {Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE
|
||||||
|
, Color.CYAN};
|
||||||
|
Shader shader = new LinearGradient(0, 0, 0, 20, rainbow,
|
||||||
|
null, Shader.TileMode.MIRROR);
|
||||||
|
Matrix matrix = new Matrix();
|
||||||
|
matrix.setRotate(animationAngle);
|
||||||
|
shader.setLocalMatrix(matrix);
|
||||||
|
mSgv.getPaint().setShader(shader);
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void setIsAnimated(boolean isAnimated) {
|
||||||
|
this.isAnimated = isAnimated;
|
||||||
|
}
|
||||||
|
|
||||||
|
void startAnimation() {
|
||||||
|
Log.d("CircleWatchface", "start startAnimation");
|
||||||
|
|
||||||
|
Thread animator = new Thread() {
|
||||||
|
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
setIsAnimated(true);
|
||||||
|
for (int i = 0; i <= 8 * 1000 / 40; i++) {
|
||||||
|
updateRainbow();
|
||||||
|
try {
|
||||||
|
Thread.sleep(40);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mSgv.getPaint().setShader(null);
|
||||||
|
setIsAnimated(false);
|
||||||
|
invalidate();
|
||||||
|
setColor();
|
||||||
|
|
||||||
|
System.gc();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
animator.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setColorLowRes() {
|
||||||
|
mTime.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_mTime));
|
||||||
|
statusView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_statusView));
|
||||||
|
mRelativeLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_background));
|
||||||
|
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||||
|
mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||||
|
mAvgDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||||
|
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_Timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setColorDark() {
|
||||||
|
mTime.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_mTime));
|
||||||
|
statusView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_statusView));
|
||||||
|
mRelativeLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_background));
|
||||||
|
if (sgvLevel == 1) {
|
||||||
|
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
|
||||||
|
mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
|
||||||
|
mAvgDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
|
||||||
|
} else if (sgvLevel == 0) {
|
||||||
|
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||||
|
mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||||
|
mAvgDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||||
|
} else if (sgvLevel == -1) {
|
||||||
|
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
|
||||||
|
mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
|
||||||
|
mAvgDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ageLevel == 1) {
|
||||||
|
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_Timestamp));
|
||||||
|
} else {
|
||||||
|
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_TimestampOld));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void setColorBright() {
|
||||||
|
|
||||||
|
if (getCurrentWatchMode() == WatchMode.INTERACTIVE) {
|
||||||
|
mTime.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_bigchart_time));
|
||||||
|
statusView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_bigchart_status));
|
||||||
|
mRelativeLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.light_background));
|
||||||
|
if (sgvLevel == 1) {
|
||||||
|
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_highColor));
|
||||||
|
mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_highColor));
|
||||||
|
mAvgDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_highColor));
|
||||||
|
} else if (sgvLevel == 0) {
|
||||||
|
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_midColor));
|
||||||
|
mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_midColor));
|
||||||
|
mAvgDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_midColor));
|
||||||
|
} else if (sgvLevel == -1) {
|
||||||
|
mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_lowColor));
|
||||||
|
mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_lowColor));
|
||||||
|
mAvgDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_lowColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ageLevel == 1) {
|
||||||
|
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_mTimestamp1));
|
||||||
|
} else {
|
||||||
|
mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.light_mTimestamp));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setColorDark();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
wear/src/main/res/drawable/watchface_nochart.png
Executable file
BIN
wear/src/main/res/drawable/watchface_nochart.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
12
wear/src/main/res/layout/activity_nochart.xml
Normal file
12
wear/src/main/res/layout/activity_nochart.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.wearable.view.WatchViewStub
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/watch_view_stub"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:rectLayout="@layout/rect_activity_nochart"
|
||||||
|
app:roundLayout="@layout/round_activity_nochart"
|
||||||
|
tools:context=".watchfaces.Home"
|
||||||
|
tools:deviceIds="wear"/>
|
108
wear/src/main/res/layout/rect_activity_nochart.xml
Normal file
108
wear/src/main/res/layout/rect_activity_nochart.xml
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" tools:context=".watchfaces.Home" tools:deviceIds="wear_square"
|
||||||
|
android:background="@color/black"
|
||||||
|
android:id="@+id/main_layout">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:gravity="center_horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="-5dp"
|
||||||
|
android:gravity="center_horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/delta"
|
||||||
|
android:textSize="40sp"
|
||||||
|
android:text="---"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:gravity="center_horizontal|bottom"
|
||||||
|
android:layout_marginRight="5dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/sgv"
|
||||||
|
android:textSize="55sp"
|
||||||
|
android:text="---"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/avgdelta"
|
||||||
|
android:textSize="40sp"
|
||||||
|
android:text="---"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:gravity="center_horizontal|bottom"
|
||||||
|
android:layout_marginLeft="5dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/aps_status"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:text="E xU/h IOB: x (x+x)"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/chart"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:gravity="center_horizontal|bottom">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/watch_time"
|
||||||
|
android:textSize="47sp"
|
||||||
|
android:text="12:00"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:layout_marginRight="6dp"
|
||||||
|
android:layout_gravity="center_horizontal" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timestamp"
|
||||||
|
android:textSize="35sp"
|
||||||
|
android:text="-- '"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
108
wear/src/main/res/layout/round_activity_nochart.xml
Normal file
108
wear/src/main/res/layout/round_activity_nochart.xml
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" tools:context=".watchfaces.Home" tools:deviceIds="wear_square"
|
||||||
|
android:background="@color/black"
|
||||||
|
android:id="@+id/main_layout">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:gravity="center_horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="-5dp"
|
||||||
|
android:gravity="center_horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/delta"
|
||||||
|
android:textSize="40sp"
|
||||||
|
android:text="---"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:gravity="center_horizontal|bottom"
|
||||||
|
android:layout_marginRight="5dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/sgv"
|
||||||
|
android:textSize="55sp"
|
||||||
|
android:text="---"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/avgdelta"
|
||||||
|
android:textSize="40sp"
|
||||||
|
android:text="---"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:gravity="center_horizontal|bottom"
|
||||||
|
android:layout_marginLeft="5dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/aps_status"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:text="E xU/h IOB: x (x+x)"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/chart"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:gravity="center_horizontal|bottom">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/watch_time"
|
||||||
|
android:textSize="47sp"
|
||||||
|
android:text="12:00"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:layout_marginRight="6dp"
|
||||||
|
android:layout_gravity="center_horizontal" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timestamp"
|
||||||
|
android:textSize="35sp"
|
||||||
|
android:text="-- '"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
Loading…
Reference in a new issue