Wear: watchface home2 add simplyfied charging ui

This commit is contained in:
Andries Smit 2021-12-16 22:25:07 +01:00
parent 176d898d0a
commit 3a9352b825
7 changed files with 132 additions and 43 deletions

View file

@ -72,7 +72,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
public TextView mTime, mHour, mMinute, mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mAvgDelta, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mBgi, mLoop, mDay, mDayName, mMonth, isAAPSv2, mHighLight, mLowLight; public TextView mTime, mHour, mMinute, mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mAvgDelta, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mBgi, mLoop, mDay, mDayName, mMonth, isAAPSv2, mHighLight, mLowLight;
public ImageView mGlucoseDial, mDeltaGauge, mHourHand, mMinuteHand; public ImageView mGlucoseDial, mDeltaGauge, mHourHand, mMinuteHand;
public RelativeLayout mRelativeLayout; public RelativeLayout mRelativeLayout;
public LinearLayout mLinearLayout, mLinearLayout2, mDate, mChartTap, mMainMenuTap; public LinearLayout mLinearLayout, mLinearLayout2, mLinearLayout3, mDate, mChartTap,
mMainMenuTap;
public int ageLevel = 1; public int ageLevel = 1;
public int loopLevel = 1; public int loopLevel = 1;
public int highColor = Color.YELLOW; public int highColor = Color.YELLOW;
@ -167,6 +168,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
mHighLight = stub.findViewById(R.id.highLight); mHighLight = stub.findViewById(R.id.highLight);
mLowLight = stub.findViewById(R.id.lowLight); mLowLight = stub.findViewById(R.id.lowLight);
mRelativeLayout = stub.findViewById(R.id.main_layout); mRelativeLayout = stub.findViewById(R.id.main_layout);
mLinearLayout3 = stub.findViewById(R.id.primary_layout);
mLinearLayout = stub.findViewById(R.id.secondary_layout); mLinearLayout = stub.findViewById(R.id.secondary_layout);
mLinearLayout2 = stub.findViewById(R.id.tertiary_layout); mLinearLayout2 = stub.findViewById(R.id.tertiary_layout);
mGlucoseDial = stub.findViewById(R.id.glucose_dial); mGlucoseDial = stub.findViewById(R.id.glucose_dial);

View file

@ -1,11 +1,18 @@
package info.nightscout.androidaps.watchfaces; package info.nightscout.androidaps.watchfaces;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color; import android.graphics.Color;
import androidx.annotation.ColorInt; import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import android.os.BatteryManager;
import android.support.wearable.watchface.WatchFaceStyle; import android.support.wearable.watchface.WatchFaceStyle;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import com.ustwo.clockwise.common.WatchMode; import com.ustwo.clockwise.common.WatchMode;
@ -257,4 +264,59 @@ public class Home2 extends BaseWatchFace {
} }
} }
} }
@Override
public void setDataFields() {
super.setDataFields();
if (sharedPrefs.getBoolean("simplify_ui_charging", false) && isCharging()) {
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
0,
0.5f
);
mLinearLayout3.setLayoutParams(param);
mLinearLayout3.setWeightSum(0.7f);
mLinearLayout.setVisibility(View.GONE);
mLoop.setVisibility(View.INVISIBLE);
chart.setVisibility(View.GONE);
mIOB1.setVisibility(View.GONE);
mIOB2.setVisibility(View.GONE);
mCOB1.setVisibility(View.GONE);
mCOB2.setVisibility(View.GONE);
mTimestamp.setVisibility(View.GONE);
mTime.setTextSize(35);
mDirection.setTextSize(35);
mSgv.setTextSize(50);
} else {
TypedValue outValue = new TypedValue();
getResources().getValue(R.dimen.home2_primary_layout_height, outValue, true);
float layoutHeight = outValue.getFloat();
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
0,
layoutHeight
);
mLinearLayout3.setLayoutParams(param);
mLinearLayout.setVisibility(View.VISIBLE);
mLoop.setVisibility(View.VISIBLE);
chart.setVisibility(View.VISIBLE);
mIOB1.setVisibility(View.VISIBLE);
mIOB2.setVisibility(View.VISIBLE);
mCOB1.setVisibility(View.VISIBLE);
mCOB2.setVisibility(View.VISIBLE);
mTimestamp.setVisibility(View.VISIBLE);
mDirection.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.home2_direction_text_size));
mSgv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.home2_sgv_text_size));
mTime.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.home2_time_text_size));
}
}
private boolean isCharging() {
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = this.registerReceiver(null, iFilter);
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
return status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
}
} }

View file

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent" tools:context=".watchfaces.Home2" tools:deviceIds="wear_square" android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black" android:background="@color/black"
android:id="@+id/main_layout"> tools:context=".watchfaces.Home2"
tools:deviceIds="wear_square">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -13,10 +16,11 @@
android:weightSum="1"> android:weightSum="1">
<LinearLayout <LinearLayout
android:id="@+id/primary_layout"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="0px" android:layout_height="0px"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_weight="0.27" android:layout_weight="@dimen/home2_primary_layout_height"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="horizontal" android:orientation="horizontal"
android:textAlignment="center"> android:textAlignment="center">
@ -42,11 +46,11 @@
android:layout_marginBottom="-2dp" android:layout_marginBottom="-2dp"
android:gravity="bottom|right" android:gravity="bottom|right"
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="-2dp" android:paddingTop="-2dp"
android:paddingRight="5dp"
android:text="---" android:text="---"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="38sp" /> android:textSize="@dimen/home2_sgv_text_size" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -66,7 +70,7 @@
android:text="--" android:text="--"
android:textAlignment="center" android:textAlignment="center"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="22sp" android:textSize="@dimen/home2_direction_text_size"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
@ -101,8 +105,8 @@
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center" android:gravity="center"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp" android:paddingStart="2dp"
android:paddingEnd="2dp"
android:textAlignment="center"> android:textAlignment="center">
<TextView <TextView
@ -271,7 +275,7 @@
android:text="12:00" android:text="12:00"
android:textAlignment="center" android:textAlignment="center"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="26sp" /> android:textSize="@dimen/home2_time_text_size" />
<LinearLayout <LinearLayout
android:id="@+id/date_time" android:id="@+id/date_time"

View file

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent" tools:context=".watchfaces.Home2" tools:deviceIds="wear_round" android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black" android:background="@color/black"
android:id="@+id/main_layout"> tools:context=".watchfaces.Home2"
tools:deviceIds="wear_round">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -15,15 +18,15 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="0px" android:layout_height="0px"
android:orientation="vertical" android:layout_weight="0.05"
android:layout_weight="0.05"> android:orientation="vertical" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/primary_layout"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="0px" android:layout_height="0px"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_weight="0.27" android:layout_weight="@dimen/home2_primary_layout_height"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="horizontal" android:orientation="horizontal"
android:textAlignment="center"> android:textAlignment="center">
@ -49,11 +52,11 @@
android:layout_marginBottom="-2dp" android:layout_marginBottom="-2dp"
android:gravity="bottom|right" android:gravity="bottom|right"
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="-2dp" android:paddingTop="-2dp"
android:paddingRight="5dp"
android:text="---" android:text="---"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="38sp" /> android:textSize="@dimen/home2_sgv_text_size" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -74,7 +77,7 @@
android:text="--" android:text="--"
android:textAlignment="center" android:textAlignment="center"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="22sp" android:textSize="@dimen/home2_direction_text_size"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
@ -109,8 +112,8 @@
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center" android:gravity="center"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingEnd="5dp"
android:paddingStart="5dp" android:paddingStart="5dp"
android:paddingEnd="5dp"
android:textAlignment="center"> android:textAlignment="center">
<TextView <TextView
@ -279,7 +282,7 @@
android:text="12:00" android:text="12:00"
android:textAlignment="center" android:textAlignment="center"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="30sp" /> android:textSize="@dimen/home2_time_text_size" />
<LinearLayout <LinearLayout
android:id="@+id/date_time" android:id="@+id/date_time"
@ -375,9 +378,8 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="0px" android:layout_height="0px"
android:orientation="vertical" android:layout_weight="0.05"
android:layout_weight="0.05"> android:orientation="vertical" />
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="home2_primary_layout_height">0.27</dimen>
<dimen name="home2_sgv_text_size">38sp</dimen>
<dimen name="home2_direction_text_size">22sp</dimen>
<dimen name="home2_time_text_size">30sp</dimen>
</resources>

View file

@ -136,6 +136,8 @@
<string name="color_name_white">white</string> <string name="color_name_white">white</string>
<string name="color_name_black">black</string> <string name="color_name_black">black</string>
<string name="color_name_multicolor">multicolor</string> <string name="color_name_multicolor">multicolor</string>
<string name="pref_simplify_ui_charging">Simplify Charging UI</string>
<string name="pref_simplify_ui_charging_sum">Only show time and BG when charging</string>
<string name="pref_vibrate_hourly">Vibrate hourly</string> <string name="pref_vibrate_hourly">Vibrate hourly</string>

View file

@ -26,9 +26,18 @@
app:wear_iconOn="@drawable/settings_on" /> app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false"
android:key="vibrate_Hourly" android:key="vibrate_Hourly"
android:title="@string/pref_vibrate_hourly" android:title="@string/pref_vibrate_hourly"
android:defaultValue="false"
app:wear_iconOff="@drawable/settings_off" app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" /> app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
android:key="simplify_ui_charging"
android:summary="@string/pref_simplify_ui_charging_sum"
android:title="@string/pref_simplify_ui_charging"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
</PreferenceScreen> </PreferenceScreen>