From 2457784e6a38a2342f12e50f0a3b7a6f0ceaaf84 Mon Sep 17 00:00:00 2001 From: Kevin Lee Date: Mon, 8 Dec 2014 01:11:29 -0600 Subject: [PATCH] Only display battery when root option is enabled --- .../com/nightscout/android/MainActivity.java | 32 +++++++++++++------ .../android/preferences/PreferenceKeys.java | 1 + app/src/main/res/layout/activity_main.xml | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/nightscout/android/MainActivity.java b/app/src/main/java/com/nightscout/android/MainActivity.java index 1ddc0c57..b0e63a2b 100644 --- a/app/src/main/java/com/nightscout/android/MainActivity.java +++ b/app/src/main/java/com/nightscout/android/MainActivity.java @@ -3,12 +3,7 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; +import android.content.*; import android.hardware.usb.UsbManager; import android.os.Bundle; import android.os.Handler; @@ -23,19 +18,18 @@ import android.webkit.WebView; import android.widget.ImageView; import android.widget.TextView; - import com.google.android.gms.analytics.GoogleAnalytics; import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.Tracker; import com.nightscout.android.dexcom.SyncingService; import com.nightscout.android.preferences.AndroidPreferences; +import com.nightscout.android.preferences.PreferenceKeys; import com.nightscout.android.settings.SettingsActivity; import com.nightscout.core.dexcom.Constants; import com.nightscout.core.dexcom.SpecialValue; import com.nightscout.core.dexcom.TrendArrow; import com.nightscout.core.dexcom.Utils; import com.nightscout.core.preferences.NightscoutPreferences; - import org.acra.ACRA; import org.acra.ACRAConfiguration; import org.acra.ACRAConfigurationException; @@ -212,7 +206,7 @@ protected void onResume() { // Set and deal with mmol/L<->mg/dL conversions SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); - Log.d(TAG,"display_options_units: "+prefs.getString("display_options_units", "0")); + Log.d(TAG, "display_options_units: " + prefs.getString("display_options_units", "0")); currentUnits = prefs.getString("display_options_units", "0").equals("0") ? 1 : Constants.MG_DL_TO_MMOL_L; int sgv = (Integer) mTextSGV.getTag(R.string.display_sgv); @@ -224,6 +218,10 @@ protected void onResume() { mWebView.loadUrl("javascript:updateUnits(" + Boolean.toString(currentUnits == Constants.MG_DL_TO_MMOL_L) + ")"); mHandler.post(updateTimeAgo); + // FIXME: (klee) need to find a better way to do this. Too many things are hooking in here. + if (statusBarIcons != null) { + statusBarIcons.checkForRootOptionChanged(); + } } private String getSGVStringByUnit(int sgv, TrendArrow trend){ @@ -454,22 +452,36 @@ public class StatusBarIcons { private ImageView mImageViewUpload; private ImageView mImageViewTimeIndicator; private ImageView mImageRcvrBattery; + private TextView mRcvrBatteryLabel; private boolean usbActive; private boolean uploadActive; private boolean displayTimeSync; private int batteryLevel; - StatusBarIcons(){ + StatusBarIcons() { mImageViewUSB = (ImageView) findViewById(R.id.imageViewUSB); mImageViewUpload = (ImageView) findViewById(R.id.imageViewUploadStatus); mImageViewTimeIndicator = (ImageView) findViewById(R.id.imageViewTimeIndicator); mImageRcvrBattery = (ImageView) findViewById(R.id.imageViewRcvrBattery); mImageRcvrBattery.setImageResource(R.drawable.battery); + mRcvrBatteryLabel = (TextView) findViewById(R.id.rcvrBatteryLabel); setDefaults(); } + public void checkForRootOptionChanged() { + if (!PreferenceManager.getDefaultSharedPreferences( + getApplicationContext()).getBoolean(PreferenceKeys.ROOT_ENABLED, false)) { + mImageRcvrBattery.setVisibility(View.GONE); + mRcvrBatteryLabel.setVisibility(View.GONE); + } else { + mImageRcvrBattery.setVisibility(View.VISIBLE); + mRcvrBatteryLabel.setVisibility(View.VISIBLE); + } + } + + public void setDefaults() { setUSB(false); setUpload(false); diff --git a/app/src/main/java/com/nightscout/android/preferences/PreferenceKeys.java b/app/src/main/java/com/nightscout/android/preferences/PreferenceKeys.java index d60d0fbb..ac47a889 100644 --- a/app/src/main/java/com/nightscout/android/preferences/PreferenceKeys.java +++ b/app/src/main/java/com/nightscout/android/preferences/PreferenceKeys.java @@ -11,4 +11,5 @@ public final class PreferenceKeys { public static final String MONGO_COLLECTION = "cloud_storage_mongodb_collection"; public static final String MONGO_DEVICE_STATUS_COLLECTION = "cloud_storage_mongodb_device_status_collection"; + public static final String ROOT_ENABLED = "root_support_enabled"; } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8f8014c6..2cb93956 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -126,6 +126,7 @@