Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchface changes iob #112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NightWatch.iml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Wed Dec 27 01:32:14 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
2 changes: 1 addition & 1 deletion mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {

android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
buildToolsVersion '26.0.2'

defaultConfig {
applicationId "com.dexdrip.stephenblack.nightwatch"
Expand Down
171 changes: 83 additions & 88 deletions mobile/mobile.iml

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions mobile/src/main/java/com/dexdrip/stephenblack/nightwatch/Bg.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public class Bg extends Model {
@Column(name = "raw")
public double raw; //Calibrated raw value

@Expose
@Column(name = "iob")
public String iob;


public String unitized_string() {
double value = sgv_double();
DecimalFormat df = new DecimalFormat("#");
Expand All @@ -92,15 +97,15 @@ public String unitized_string(SharedPreferences aPrefs) {
return unitized_string();
}

public String unitizedDeltaString() {
public String unitizedDeltaString() { // fixing delta values for nightwidget and watchface while 640G & mmol in use.
DecimalFormat df = new DecimalFormat("#");
df.setMaximumFractionDigits(1);
String delta_sign = "";
if (bgdelta > 0.1) { delta_sign = "+"; }
if(doMgdl()) {
return delta_sign + df.format(unitized(bgdelta)) + " mg/dl";
if(!doMgdl()) {
return delta_sign + df.format(bgdelta) + " mmol";
} else {
return delta_sign + df.format(unitized(bgdelta)) + " mmol";
return delta_sign + df.format(mgdlConvert(bgdelta)) + " mg/dl";
}
}
public String unitizedDeltaStringNoUnit() {
Expand Down Expand Up @@ -138,6 +143,8 @@ public double mmolConvert(double mgdl) {
return mgdl * Constants.MGDL_TO_MMOLL;
}

public double mgdlConvert (double mmol) { return mmol * Constants.MMOLL_TO_MGDL; }


public boolean doMgdl() {
String unit = prefs.getString("units", "mgdl");
Expand All @@ -154,6 +161,7 @@ public int battery_int() {

public String slopeArrow() {
String arrow = "--";
if(direction == null) return arrow;
if (direction.compareTo("DoubleDown") == 0) {
arrow = "\u21ca";
} else if (direction.compareTo("SingleDown") == 0) {
Expand All @@ -174,7 +182,7 @@ public String slopeArrow() {

public String readingAge() {
int minutesAgo = (int) Math.floor(timeSince()/(1000*60));
if (minutesAgo == 1) {
if (minutesAgo <= 1) {
return minutesAgo + " Minute ago";
}
return minutesAgo + " Minutes ago";
Expand All @@ -200,6 +208,7 @@ public DataMap dataMap(SharedPreferences sPrefs) {
dataMap.putDouble("sgvDouble", sgv_double());
dataMap.putDouble("high", inMgdl(highMark));
dataMap.putDouble("low", inMgdl(lowMark));
dataMap.putString("iob",iob);
dataMap.putString("rawString", threeRaw((prefs.getString("units", "mgdl").equals("mgdl"))));
return dataMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,19 @@ public String unitizedDeltaString(double value) {
df.setMaximumFractionDigits(1);
String delta_sign = "";
if (value > 0.1) { delta_sign = "+"; }
if(doMgdl) {
return delta_sign + df.format(unitized(value)) + " mg/dl";
if(!doMgdl) {
return delta_sign + df.format(value) + " mmol";
} else {
return delta_sign + df.format(unitized(value)) + " mmol";
return delta_sign + df.format(mgdlConvert(value)) + " mg/dl";
}
}

public double mmolConvert(double mgdl) {
return mgdl * Constants.MGDL_TO_MMOLL;
}

public double mgdlConvert (double mmol) { return mmol * Constants.MMOLL_TO_MGDL; }

static public boolean isXLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
Expand Down Expand Up @@ -364,7 +366,7 @@ public String unitizedDeltaString(boolean showUnit, boolean highGranularity) {
} else {

if(highGranularity){
df.setMaximumFractionDigits(2);
df.setMaximumFractionDigits(1); // 1 set as max fraction digits when mmol in use
} else {
df.setMaximumFractionDigits(1);
}
Expand Down
5 changes: 3 additions & 2 deletions wear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
buildToolsVersion '26.0.2'

defaultConfig {
applicationId "com.dexdrip.stephenblack.nightwatch"
Expand All @@ -23,6 +23,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.ustwo.android:clockwise-wearable:1.0.2'
compile 'com.google.android.support:wearable:1.1.0'
provided 'com.google.android.wearable:wearable:2.0.1'
compile 'com.google.android.support:wearable:2.0.1'
compile 'com.google.android.gms:play-services-wearable:7.3.0'
}
22 changes: 18 additions & 4 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,27 @@
</service>

<service
android:name=".LargeHome"
android:name=".LargeHome"
android:allowEmbedded="true"
android:label="NightWatch(Large)"
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_dark" />
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
</intent-filter>
</service>

<service
android:name=".HomeSpecial"
android:allowEmbedded="true"
android:label="NightWatch(Large)"
android:label="NightWatch IOB Special"
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_dark" />
android:resource="@xml/watch_face"/>
<meta-data android:name="com.google.android.wearable.watchface.preview" android:resource="@drawable/watchface_iob" />
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public double timeSince() {
public String readingAge(boolean shortString) {
if (datetime == 0) { return shortString?"--'":"-- Minute ago"; }
int minutesAgo = (int) Math.floor(timeSince()/(1000*60));
if (minutesAgo == 1) {
if (minutesAgo <= 1) {
return minutesAgo + (shortString?"'":" Minute ago");
}
return minutesAgo + (shortString?"'":" Minutes ago");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
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, mRaw;
public TextView mTime, mSgv, mDirection, mTimestamp, mUploaderBattery, mDelta, mRaw, miob;
public RelativeLayout mRelativeLayout;
public LinearLayout mLinearLayout;
public long sgvLevel = 0;
Expand Down Expand Up @@ -72,6 +72,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
private String rawString = "000 | 000 | 000";
private String batteryString = "--";
private String sgvString = "--";
private String iobString = "--";

@Override
public void onCreate() {
Expand Down Expand Up @@ -114,6 +115,7 @@ public void onLayoutInflated(WatchViewStub stub) {
mRaw = (TextView) stub.findViewById(R.id.raw);
mUploaderBattery = (TextView) stub.findViewById(R.id.uploader_battery);
mDelta = (TextView) stub.findViewById(R.id.delta);
miob = (TextView) stub.findViewById(R.id.iob);
mRelativeLayout = (RelativeLayout) stub.findViewById(R.id.main_layout);
mLinearLayout = (LinearLayout) stub.findViewById(R.id.secondary_layout);
chart = (LineChartView) stub.findViewById(R.id.chart);
Expand Down Expand Up @@ -143,7 +145,7 @@ public double timeSince() {
public String readingAge(boolean shortString) {
if (datetime == 0) { return shortString?"--'":"-- Minute ago"; }
int minutesAgo = (int) Math.floor(timeSince()/(1000*60));
if (minutesAgo == 1) {
if (minutesAgo <= 1) {
return minutesAgo + (shortString?"'":" Minute ago");
}
return minutesAgo + (shortString?"'":" Minutes ago");
Expand Down Expand Up @@ -207,6 +209,7 @@ public void onReceive(Context context, Intent intent) {
rawString = dataMap.getString("rawString");
sgvString = dataMap.getString("sgvString");
batteryString = dataMap.getString("battery");
iobString = dataMap.getString("iob");
mSgv.setText(dataMap.getString("sgvString"));

if(ageLevel()<=0) {
Expand All @@ -222,6 +225,9 @@ public void onReceive(Context context, Intent intent) {

mDirection.setText(dataMap.getString("slopeArrow"));
mDelta.setText(dataMap.getString("delta"));
if (miob != null) {
miob.setText("IOB: " + iobString + "u");
}

if (chart != null) {
addToWatchSet(dataMap);
Expand All @@ -231,6 +237,8 @@ public void onReceive(Context context, Intent intent) {
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
mRelativeLayout.getMeasuredHeight());
invalidate();


} else {
Log.d("ERROR: ", "DATA IS NOT YET SET");
}
Expand All @@ -240,7 +248,7 @@ public void onReceive(Context context, Intent intent) {

private void showAgoRawBatt() {

if(mRaw == null || mTimestamp == null || mUploaderBattery == null){
if(mRaw == null || mTimestamp == null || mUploaderBattery == null ){
return;
}

Expand All @@ -251,6 +259,7 @@ private void showAgoRawBatt() {
mRaw.setText("R: " + rawString);
mTimestamp.setText(readingAge(true));
mUploaderBattery.setText("U: " + batteryString + "%");

} else {
mRaw.setVisibility(View.GONE);
mTimestamp.setText(readingAge(false));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.dexdrip.stephenblack.nightwatch;

/**
* Created by Janne on 18.2.2018.
*/

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;

import com.ustwo.clockwise.WatchMode;

public class HomeSpecial extends BaseWatchFace {

@Override
public void onCreate() {
super.onCreate();
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutView = inflater.inflate(R.layout.activity_home_special, null);
performViewSetup();
}


@Override
protected void setColorDark(){
mTime.setTextColor(Color.WHITE);
mRelativeLayout.setBackgroundColor(Color.BLACK);
mLinearLayout.setBackgroundColor(Color.WHITE);
if (sgvLevel == 1) {
mSgv.setTextColor(Color.YELLOW);
mDirection.setTextColor(Color.YELLOW);
mDelta.setTextColor(Color.YELLOW);
miob.setTextColor(Color.YELLOW);
} else if (sgvLevel == 0) {
mSgv.setTextColor(Color.WHITE);
mDirection.setTextColor(Color.WHITE);
mDelta.setTextColor(Color.WHITE);
miob.setTextColor(Color.WHITE);
} else if (sgvLevel == -1) {
mSgv.setTextColor(Color.RED);
mDirection.setTextColor(Color.RED);
mDelta.setTextColor(Color.RED);
miob.setTextColor(Color.RED);
}
if (ageLevel == 1) {
mTimestamp.setTextColor(Color.BLACK);
} else {
mTimestamp.setTextColor(Color.RED);
}

if (batteryLevel == 1) {
mUploaderBattery.setTextColor(Color.BLACK);
} else {
mUploaderBattery.setTextColor(Color.RED);
}

mRaw.setTextColor(Color.WHITE);
}



@Override
protected void setColorBright() {
if (getCurrentWatchMode() == WatchMode.INTERACTIVE) {
mRelativeLayout.setBackgroundColor(Color.WHITE);
mLinearLayout.setBackgroundColor(Color.BLACK);
if (sgvLevel == 1) {
mSgv.setTextColor(Color.YELLOW);
mDirection.setTextColor(Color.YELLOW);
mDelta.setTextColor(Color.YELLOW);
miob.setTextColor(Color.YELLOW);
} else if (sgvLevel == 0) {
mSgv.setTextColor(Color.BLACK);
mDirection.setTextColor(Color.BLACK);
mDelta.setTextColor(Color.BLACK);
miob.setTextColor(Color.BLACK);
} else if (sgvLevel == -1) {
mSgv.setTextColor(Color.RED);
mDirection.setTextColor(Color.RED);
mDelta.setTextColor(Color.RED);
miob.setTextColor(Color.RED);
}

if (ageLevel == 1) {
mTimestamp.setTextColor(Color.WHITE);
} else {
mTimestamp.setTextColor(Color.RED);
}

if (batteryLevel == 1) {
mUploaderBattery.setTextColor(Color.WHITE);
} else {
mUploaderBattery.setTextColor(Color.RED);
}
mRaw.setTextColor(Color.BLACK);
mTime.setTextColor(Color.BLACK);
} else {
mRelativeLayout.setBackgroundColor(Color.BLACK);
mLinearLayout.setBackgroundColor(Color.LTGRAY);
if (sgvLevel == 1) {
mSgv.setTextColor(Color.YELLOW);
mDirection.setTextColor(Color.YELLOW);
mDelta.setTextColor(Color.YELLOW);
miob.setTextColor(Color.YELLOW);
} else if (sgvLevel == 0) {
mSgv.setTextColor(Color.WHITE);
mDirection.setTextColor(Color.WHITE);
mDelta.setTextColor(Color.WHITE);
miob.setTextColor(Color.BLACK);
} else if (sgvLevel == -1) {
mSgv.setTextColor(Color.RED);
mDirection.setTextColor(Color.RED);
mDelta.setTextColor(Color.RED);
miob.setTextColor(Color.RED);
}

mUploaderBattery.setTextColor(Color.BLACK);
mTimestamp.setTextColor(Color.BLACK);
mRaw.setTextColor(Color.BLACK);
mTime.setTextColor(Color.WHITE);
miob.setTextColor(Color.BLACK);
}
}
}

Loading