Wear: move simple ui to layout
This commit is contained in:
parent
51a88cff6c
commit
0d6a8aedf7
5 changed files with 167 additions and 93 deletions
|
@ -10,6 +10,7 @@ import android.graphics.Color;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.PowerManager;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
|
@ -25,6 +26,7 @@ import android.widget.LinearLayout;
|
|||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import com.google.android.gms.wearable.DataMap;
|
||||
|
@ -40,7 +42,6 @@ import javax.inject.Inject;
|
|||
|
||||
import dagger.android.AndroidInjection;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.complications.BaseComplicationProviderService;
|
||||
import info.nightscout.androidaps.data.ListenerService;
|
||||
import info.nightscout.androidaps.data.RawDisplayData;
|
||||
import info.nightscout.androidaps.interaction.utils.Persistence;
|
||||
|
@ -59,7 +60,6 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
|
|||
@Inject Persistence persistence;
|
||||
|
||||
public final static IntentFilter INTENT_FILTER;
|
||||
public static final long[] vibratePattern = {0, 400, 300, 400, 300, 400};
|
||||
|
||||
static {
|
||||
INTENT_FILTER = new IntentFilter();
|
||||
|
@ -70,10 +70,11 @@ 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 mSimpleSvg, mSimpleDirection, mSimpleTime;
|
||||
public ImageView mGlucoseDial, mDeltaGauge, mHourHand, mMinuteHand;
|
||||
public View mSimpleUi;
|
||||
public RelativeLayout mRelativeLayout;
|
||||
public LinearLayout mLinearLayout, mLinearLayout2, mLinearLayout3, mDate, mChartTap,
|
||||
mMainMenuTap;
|
||||
public LinearLayout mLinearLayout, mLinearLayout2, mDate, mChartTap, mMainMenuTap;
|
||||
public int ageLevel = 1;
|
||||
public int loopLevel = 1;
|
||||
public int highColor = Color.YELLOW;
|
||||
|
@ -101,6 +102,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
|
|||
protected SharedPreferences sharedPrefs;
|
||||
private LocalBroadcastManager localBroadcastManager;
|
||||
private MessageReceiver messageReceiver;
|
||||
private BroadcastReceiver batteryReceiver;
|
||||
protected boolean isCharging = false;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
@ -122,6 +125,26 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
|
|||
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
persistence.turnOff();
|
||||
|
||||
setupBatteryReceiver();
|
||||
}
|
||||
|
||||
private void setupBatteryReceiver() {
|
||||
if (sharedPrefs.getBoolean("simplify_ui_charging", false)) {
|
||||
IntentFilter intentBatteryFilter = new IntentFilter();
|
||||
intentBatteryFilter.addAction(BatteryManager.ACTION_CHARGING);
|
||||
intentBatteryFilter.addAction(BatteryManager.ACTION_DISCHARGING);
|
||||
isCharging = checkIsCharging();
|
||||
batteryReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
isCharging = checkIsCharging();
|
||||
setDataFields();
|
||||
invalidate();
|
||||
}
|
||||
};
|
||||
registerReceiver(batteryReceiver, intentBatteryFilter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -168,7 +191,6 @@ 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);
|
||||
|
@ -178,8 +200,11 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
|
|||
mChartTap = stub.findViewById(R.id.chart_zoom_tap);
|
||||
mMainMenuTap = stub.findViewById(R.id.main_menu_tap);
|
||||
chart = stub.findViewById(R.id.chart);
|
||||
mSimpleUi = stub.findViewById(R.id.simple_ui);
|
||||
mSimpleSvg = stub.findViewById(R.id.simple_sgv);
|
||||
mSimpleDirection = stub.findViewById(R.id.simple_direction);
|
||||
mSimpleTime = stub.findViewById(R.id.simple_watch_time);
|
||||
layoutSet = true;
|
||||
|
||||
setDataFields();
|
||||
setColor();
|
||||
}
|
||||
|
@ -219,6 +244,9 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
|
|||
if (sharedPrefs != null) {
|
||||
sharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
if (batteryReceiver != null) {
|
||||
unregisterReceiver(batteryReceiver);
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -258,8 +286,16 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
|
|||
}
|
||||
}
|
||||
|
||||
private boolean checkIsCharging() {
|
||||
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;
|
||||
}
|
||||
|
||||
private void checkVibrateHourly(WatchFaceTime oldTime, WatchFaceTime newTime) {
|
||||
Boolean hourlyVibratePref = sharedPrefs.getBoolean("vibrate_Hourly", false);
|
||||
boolean hourlyVibratePref = sharedPrefs.getBoolean("vibrate_Hourly", false);
|
||||
if (hourlyVibratePref && layoutSet && newTime.hasHourChanged(oldTime)) {
|
||||
Log.i("hourlyVibratePref", "true --> " + newTime.toString());
|
||||
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
|
||||
|
@ -450,6 +486,37 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
|
|||
mLoop.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
setDataFieldsSimpleUi();
|
||||
}
|
||||
|
||||
void setDataFieldsSimpleUi() {
|
||||
if (sharedPrefs.getBoolean("simplify_ui_charging", false) && isCharging) {
|
||||
mSimpleUi.setVisibility(View.VISIBLE);
|
||||
|
||||
mSimpleSvg.setText(rawData.sSgv);
|
||||
if (ageLevel() <= 0) {
|
||||
mSimpleSvg.setPaintFlags(mSimpleSvg.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
} else {
|
||||
mSimpleSvg.setPaintFlags(mSimpleSvg.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
if (rawData.sgvLevel == 1) {
|
||||
mSimpleSvg.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
|
||||
mSimpleDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
|
||||
} else if (rawData.sgvLevel == 0) {
|
||||
mSimpleSvg.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
mSimpleDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
|
||||
} else if (rawData.sgvLevel == -1) {
|
||||
mSimpleSvg.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
|
||||
mSimpleDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
|
||||
}
|
||||
|
||||
mSimpleDirection.setText(rawData.sDirection+"\uFE0E");
|
||||
|
||||
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
|
||||
mSimpleTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||
} else {
|
||||
mSimpleUi.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDateAndTime() {
|
||||
|
@ -528,7 +595,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
|
|||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
|
||||
setupBatteryReceiver();
|
||||
if ("delta_granularity".equals(key)) {
|
||||
ListenerService.requestData(this);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import androidx.core.content.ContextCompat;
|
|||
|
||||
import android.os.BatteryManager;
|
||||
import android.support.wearable.watchface.WatchFaceStyle;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -32,27 +33,9 @@ public class Home2 extends BaseWatchFace {
|
|||
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
layoutView = inflater.inflate(R.layout.activity_home_2, null);
|
||||
|
||||
IntentFilter intentBatteryFilter = new IntentFilter();
|
||||
intentBatteryFilter.addAction(BatteryManager.ACTION_CHARGING);
|
||||
intentBatteryFilter.addAction(BatteryManager.ACTION_DISCHARGING);
|
||||
registerReceiver(batteryReceiver, intentBatteryFilter);
|
||||
performViewSetup();
|
||||
}
|
||||
|
||||
private BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
setDataFields();
|
||||
invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
unregisterReceiver(batteryReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTapCommand(int tapType, int x, int y, long eventTime) {
|
||||
|
||||
|
@ -286,58 +269,4 @@ 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="0px"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_weight="@dimen/home2_primary_layout_height"
|
||||
android:layout_weight="0.27"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:textAlignment="center">
|
||||
|
@ -50,7 +50,7 @@
|
|||
android:paddingRight="5dp"
|
||||
android:text="---"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="@dimen/home2_sgv_text_size" />
|
||||
android:textSize="38sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -70,7 +70,7 @@
|
|||
android:text="--"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="@dimen/home2_direction_text_size"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
|
@ -275,7 +275,7 @@
|
|||
android:text="12:00"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="@dimen/home2_time_text_size" />
|
||||
android:textSize="30sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/date_time"
|
||||
|
@ -370,4 +370,9 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<include
|
||||
android:id="@+id/simple_ui"
|
||||
layout="@layout/simple_ui"
|
||||
android:visibility="gone" />
|
||||
|
||||
</RelativeLayout>
|
81
wear/src/main/res/layout/simple_ui.xml
Normal file
81
wear/src/main/res/layout/simple_ui.xml
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="@color/black"
|
||||
android:orientation="vertical"
|
||||
android:weightSum="100">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="50"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:textAlignment="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/simple_sgv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginBottom="-2dp"
|
||||
android:gravity="bottom|end"
|
||||
android:text="---"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="50sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:baselineAligned="false"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:textAlignment="center"
|
||||
android:weightSum="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/simple_direction"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
android:layout_marginTop="-2dp"
|
||||
android:layout_marginBottom="-5dp"
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:text="--"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="35sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="50"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/simple_watch_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal|top"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="12:00"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="35sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,8 +0,0 @@
|
|||
<?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>
|
Loading…
Reference in a new issue