From 8ed20eaecef3e0ec3b05531e9db4b4d9dda0a862 Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Tue, 4 Jan 2022 11:51:23 +0100 Subject: [PATCH 1/2] wear: add watchface digtal support 12h clock --- .../androidaps/watchfaces/BaseWatchFace.java | 25 +++++++++++- .../res/layout/rect_activity_digitalstyle.xml | 38 +++++++++++++------ .../layout/round_activity_digitalstyle.xml | 37 ++++++++++++------ 3 files changed, 75 insertions(+), 25 deletions(-) diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java index 55549af656..0500786802 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java @@ -69,7 +69,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc } public final Point displaySize = new Point(); - 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, mTimePeriod, mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mAvgDelta, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mBgi, mLoop, mDay, mDayName, mMonth, isAAPSv2, mHighLight, mLowLight; public TextView mSimpleSvg, mSimpleDirection, mSimpleTime; public ImageView mGlucoseDial, mDeltaGauge, mHourHand, mMinuteHand; public View mSimpleUi; @@ -166,6 +166,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc mTime = stub.findViewById(R.id.watch_time); mHour = stub.findViewById(R.id.hour); mMinute = stub.findViewById(R.id.minute); + mTimePeriod = stub.findViewById(R.id.timePeriod); mDay = stub.findViewById(R.id.day); mDayName = stub.findViewById(R.id.dayname); mMonth = stub.findViewById(R.id.month); @@ -517,6 +518,11 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc } } + @Override + protected void on24HourFormatChanged(boolean is24HourFormat) { + setDateAndTime(); + } + public void setDateAndTime() { final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this); @@ -525,8 +531,13 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc } Date now = new Date(); - SimpleDateFormat sdfHour = new SimpleDateFormat("HH"); + SimpleDateFormat sdfHour; SimpleDateFormat sdfMinute = new SimpleDateFormat("mm"); + if (DateFormat.is24HourFormat(this)) { + sdfHour = new SimpleDateFormat("HH"); + } else { + sdfHour = new SimpleDateFormat("hh"); + } sHour = sdfHour.format(now); sMinute = sdfMinute.format(now); @@ -535,6 +546,16 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc mMinute.setText(sMinute); } + if(mTimePeriod != null) { + if (!DateFormat.is24HourFormat(this)) { + mTimePeriod.setVisibility(View.VISIBLE); + SimpleDateFormat sdfPeriod = new SimpleDateFormat("a"); + mTimePeriod.setText(sdfPeriod.format(now).toUpperCase()); + } else { + mTimePeriod.setVisibility(View.GONE); + } + } + if (mDate != null && mDay != null && mMonth != null) { if (sharedPrefs.getBoolean("show_date", false)) { if (mDayName != null) { diff --git a/wear/src/main/res/layout/rect_activity_digitalstyle.xml b/wear/src/main/res/layout/rect_activity_digitalstyle.xml index 57a03fc718..86c79196fc 100644 --- a/wear/src/main/res/layout/rect_activity_digitalstyle.xml +++ b/wear/src/main/res/layout/rect_activity_digitalstyle.xml @@ -9,7 +9,6 @@ tools:context=".watchfaces.DigitalStyle" tools:deviceIds="wear_square"> - - + android:orientation="horizontal"> + android:layout_marginTop="-5dp"> + + + + + + + - @@ -549,7 +565,6 @@ android:visibility="gone" /> - - - \ No newline at end of file + diff --git a/wear/src/main/res/layout/round_activity_digitalstyle.xml b/wear/src/main/res/layout/round_activity_digitalstyle.xml index 8eedf2ceff..193d727ca4 100644 --- a/wear/src/main/res/layout/round_activity_digitalstyle.xml +++ b/wear/src/main/res/layout/round_activity_digitalstyle.xml @@ -9,7 +9,6 @@ tools:context=".watchfaces.DigitalStyle" tools:deviceIds="wear_round"> - - + android:orientation="horizontal"> + android:layout_marginTop="-5dp"> + + + + + + - @@ -549,8 +564,8 @@ android:id="@+id/simple_ui" layout="@layout/simple_ui" android:visibility="gone" /> - + - \ No newline at end of file + From ff3036a91b9c3ff8ab47a24d0c8296470e2bc934 Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Tue, 4 Jan 2022 15:56:01 +0100 Subject: [PATCH 2/2] Wear: fix import error api 25 --- .../main/java/info/nightscout/androidaps/di/ServicesModule.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/wear/src/main/java/info/nightscout/androidaps/di/ServicesModule.kt b/wear/src/main/java/info/nightscout/androidaps/di/ServicesModule.kt index 889c193536..358d9250d0 100644 --- a/wear/src/main/java/info/nightscout/androidaps/di/ServicesModule.kt +++ b/wear/src/main/java/info/nightscout/androidaps/di/ServicesModule.kt @@ -1,6 +1,5 @@ package info.nightscout.androidaps.di -import android.net.wifi.hotspot2.pps.HomeSp import dagger.Module import dagger.android.ContributesAndroidInjector import info.nightscout.androidaps.complications.BaseComplicationProviderService @@ -24,7 +23,6 @@ abstract class ServicesModule { @ContributesAndroidInjector abstract fun contributesBaseWatchFace(): BaseWatchFace @ContributesAndroidInjector abstract fun contributesHome(): Home @ContributesAndroidInjector abstract fun contributesHome2(): Home2 - @ContributesAndroidInjector abstract fun contributesHomeSp(): HomeSp @ContributesAndroidInjector abstract fun contributesLargeHome(): LargeHome @ContributesAndroidInjector abstract fun contributesSteampunk(): Steampunk @ContributesAndroidInjector abstract fun contributesDigitalStyle(): DigitalStyle