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 ImageView mGlucoseDial, mDeltaGauge, mHourHand, mMinuteHand;
public RelativeLayout mRelativeLayout;
public LinearLayout mLinearLayout, mLinearLayout2, mDate, mChartTap, mMainMenuTap;
public LinearLayout mLinearLayout, mLinearLayout2, mLinearLayout3, mDate, mChartTap,
mMainMenuTap;
public int ageLevel = 1;
public int loopLevel = 1;
public int highColor = Color.YELLOW;
@ -167,6 +168,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
mHighLight = stub.findViewById(R.id.highLight);
mLowLight = stub.findViewById(R.id.lowLight);
mRelativeLayout = stub.findViewById(R.id.main_layout);
mLinearLayout3 = stub.findViewById(R.id.primary_layout);
mLinearLayout = stub.findViewById(R.id.secondary_layout);
mLinearLayout2 = stub.findViewById(R.id.tertiary_layout);
mGlucoseDial = stub.findViewById(R.id.glucose_dial);

View file

@ -1,11 +1,18 @@
package info.nightscout.androidaps.watchfaces;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;
import android.os.BatteryManager;
import android.support.wearable.watchface.WatchFaceStyle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import com.ustwo.clockwise.common.WatchMode;
@ -28,23 +35,23 @@ public class Home2 extends BaseWatchFace {
@Override
protected void onTapCommand(int tapType, int x, int y, long eventTime) {
int extra = mSgv!=null?(mSgv.getRight() - mSgv.getLeft())/2:0;
int extra = mSgv != null ? (mSgv.getRight() - mSgv.getLeft()) / 2 : 0;
if (tapType == TAP_TYPE_TAP&&
x >=chart.getLeft() &&
x <= chart.getRight()&&
if (tapType == TAP_TYPE_TAP &&
x >= chart.getLeft() &&
x <= chart.getRight() &&
y >= chart.getTop() &&
y <= chart.getBottom()){
if (eventTime - chartTapTime < 800){
y <= chart.getBottom()) {
if (eventTime - chartTapTime < 800) {
changeChartTimeframe();
}
chartTapTime = eventTime;
} else if (tapType == TAP_TYPE_TAP&&
x + extra >=mSgv.getLeft() &&
x - extra <= mSgv.getRight()&&
} else if (tapType == TAP_TYPE_TAP &&
x + extra >= mSgv.getLeft() &&
x - extra <= mSgv.getRight() &&
y >= mSgv.getTop() &&
y <= mSgv.getBottom()){
if (eventTime - sgvTapTime < 800){
y <= mSgv.getBottom()) {
if (eventTime - sgvTapTime < 800) {
Intent intent = new Intent(this, MainMenuActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
@ -55,12 +62,12 @@ public class Home2 extends BaseWatchFace {
private void changeChartTimeframe() {
int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3"));
timeframe = (timeframe%5) + 1;
timeframe = (timeframe % 5) + 1;
sharedPrefs.edit().putString("chart_timeframe", "" + timeframe).apply();
}
@Override
protected WatchFaceStyle getWatchFaceStyle(){
protected WatchFaceStyle getWatchFaceStyle() {
return new WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build();
}
@ -176,7 +183,7 @@ public class Home2 extends BaseWatchFace {
if (getCurrentWatchMode() == WatchMode.INTERACTIVE) {
@ColorInt final int dividerTxtColor = dividerMatchesBg ? Color.BLACK :
@ColorInt final int dividerTxtColor = dividerMatchesBg ? Color.BLACK :
ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor);
@ColorInt final int dividerBgColor = ContextCompat.getColor(getApplicationContext(),
dividerMatchesBg ? R.color.light_background : R.color.light_stripe_background);
@ -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"?>
<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.Home2" tools:deviceIds="wear_square"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:id="@+id/main_layout">
tools:context=".watchfaces.Home2"
tools:deviceIds="wear_square">
<LinearLayout
android:layout_width="match_parent"
@ -13,10 +16,11 @@
android:weightSum="1">
<LinearLayout
android:id="@+id/primary_layout"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_gravity="center_horizontal"
android:layout_weight="0.27"
android:layout_weight="@dimen/home2_primary_layout_height"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:textAlignment="center">
@ -42,11 +46,11 @@
android:layout_marginBottom="-2dp"
android:gravity="bottom|right"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="-2dp"
android:paddingRight="5dp"
android:text="---"
android:textColor="#FFFFFF"
android:textSize="38sp" />
android:textSize="@dimen/home2_sgv_text_size" />
<LinearLayout
android:layout_width="wrap_content"
@ -66,7 +70,7 @@
android:text="--"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="22sp"
android:textSize="@dimen/home2_direction_text_size"
android:textStyle="bold" />
<TextView
@ -101,8 +105,8 @@
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:textAlignment="center">
<TextView
@ -271,7 +275,7 @@
android:text="12:00"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="26sp" />
android:textSize="@dimen/home2_time_text_size" />
<LinearLayout
android:id="@+id/date_time"

View file

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

View file

@ -8,7 +8,7 @@
android:summary="Dark theme"
android:title="@string/pref_dark"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on"/>
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
@ -16,7 +16,7 @@
android:summary="Status bar divider background matches watchface background"
android:title="@string/pref_matching_divider"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on"/>
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
@ -26,9 +26,18 @@
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
android:key="vibrate_Hourly"
android:title="@string/pref_vibrate_hourly"
android:defaultValue="false"
app:wear_iconOff="@drawable/settings_off"
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>