From 2d49be1162d0f5f916753a1b6baee68a5bea70fd Mon Sep 17 00:00:00 2001 From: link_max Date: Thu, 15 Mar 2018 10:31:46 +0800 Subject: [PATCH] [ota] add ota view manager to manage ota view --- .../com/stockholm/common/IntentExtraKey.java | 4 +- .../stockholm/common/ota/OtaViewManager.java | 46 +++++++++++++++++++ .../common/view/ReleaseBaseActivity.java | 8 ++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lib/src/main/java/com/stockholm/common/ota/OtaViewManager.java diff --git a/lib/src/main/java/com/stockholm/common/IntentExtraKey.java b/lib/src/main/java/com/stockholm/common/IntentExtraKey.java index 60e5465..b8ae330 100644 --- a/lib/src/main/java/com/stockholm/common/IntentExtraKey.java +++ b/lib/src/main/java/com/stockholm/common/IntentExtraKey.java @@ -16,6 +16,8 @@ public final class IntentExtraKey { public static final String ACTION_CLEAR_NIGHT_MODE = "com.stockholm.ACTION_CLEAR_NIGHT_MODE"; public static final String ACTION_KILL_PROCESS = "com.stockholm.ACTION_KILL_PROCESS"; public static final String ACTION_PAUSE_SOUND = "com.stockholm.ACTION_PAUSE_SOUND"; + public static final String ACTION_SHOW_OTA_VIEW = "com.stockholm.ACTION_SHOW_OTA_VIEW"; + public static final String ACTION_CLEAR_OTA_VIEW = "com.stockholm.ACTION_CLEAR_OTA_VIEW"; public static final String ACTION_BIND_SUCCESS = "com.stockholm.action.BIND_SUCCESS"; @@ -26,7 +28,7 @@ public final class IntentExtraKey { //weather public static final String ACTION_GET_WEATHER = "com.stockholm.ACTION_GET_WEATHER"; public static final String ACTION_RESPONSE_WEATHER = "com.stockholm.ACTION_RESPONSE_WEATHER"; - public static final String KEY_WEATHER_TEMPERATURE = "key_weather_temperature"; + public static final String KEY_WEATHER_TEMPERATURE = "key_weather_temperature"; public static final String KEY_WEATHER_DESCRIPTION = "key_weather_description"; public static final String KEY_WEATHER_TYPE = "key_weather_type"; diff --git a/lib/src/main/java/com/stockholm/common/ota/OtaViewManager.java b/lib/src/main/java/com/stockholm/common/ota/OtaViewManager.java new file mode 100644 index 0000000..1a3b3e2 --- /dev/null +++ b/lib/src/main/java/com/stockholm/common/ota/OtaViewManager.java @@ -0,0 +1,46 @@ +package com.stockholm.common.ota; + + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; + +import com.stockholm.common.IntentExtraKey; + +public class OtaViewManager { + + private Context context; + private boolean showing = false; + private OtaViewReceiver otaViewReceiver; + + public OtaViewManager(Context context) { + this.context = context; + } + + public void registerOtaViewReceiver() { + otaViewReceiver = new OtaViewReceiver(); + context.registerReceiver(otaViewReceiver, new IntentFilter(IntentExtraKey.ACTION_SHOW_OTA_VIEW)); + context.registerReceiver(otaViewReceiver, new IntentFilter(IntentExtraKey.ACTION_CLEAR_OTA_VIEW)); + } + + public void unregisterOtaViewReceiver() { + context.unregisterReceiver(otaViewReceiver); + } + + public boolean isShowing() { + return showing; + } + + private class OtaViewReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals(IntentExtraKey.ACTION_SHOW_OTA_VIEW)) { + showing = true; + } else if (action.equals(IntentExtraKey.ACTION_CLEAR_OTA_VIEW)) { + showing = false; + } + } + } +} diff --git a/lib/src/main/java/com/stockholm/common/view/ReleaseBaseActivity.java b/lib/src/main/java/com/stockholm/common/view/ReleaseBaseActivity.java index 849e83d..c8f9251 100644 --- a/lib/src/main/java/com/stockholm/common/view/ReleaseBaseActivity.java +++ b/lib/src/main/java/com/stockholm/common/view/ReleaseBaseActivity.java @@ -20,6 +20,7 @@ import com.stockholm.common.develop.DeveloperDialog; import com.stockholm.common.nightmode.NightModeStateManager; import com.stockholm.common.notification.NotificationStateManager; +import com.stockholm.common.ota.OtaViewManager; import com.stockholm.common.toast.VolumeToastHelper; import com.stockholm.common.utils.StockholmLogger; import com.stockholm.common.utils.WeakHandler; @@ -53,6 +54,7 @@ public void handleMessage(Message msg) { private ReleaseSystemKeyEventHandler systemKeyEventHandler; private NightModeStateManager nightModeStateManager; private NotificationStateManager notificationStateManager; + private OtaViewManager otaViewManager; private DeveloperDialog developerDialog; private boolean hasKeyDown = false; @@ -70,6 +72,7 @@ protected void onCreate(Bundle savedInstanceState) { initSystemKeyHandler(); nightModeStateManager = new NightModeStateManager(this); notificationStateManager = new NotificationStateManager(this); + otaViewManager = new OtaViewManager(this); initCountdown(); registerReceiver(); lazyLoad(); @@ -191,6 +194,7 @@ protected void registerReceiver() { nightModeStateManager.registerNightModeReceiver(); notificationStateManager.registerNightModeReceiver(); + otaViewManager.registerOtaViewReceiver(); } protected void unregisterReceiver() { @@ -199,6 +203,7 @@ protected void unregisterReceiver() { unregisterReceiver(pauseSoundReceiver); nightModeStateManager.unregisterNightModeReceiver(); notificationStateManager.unregisterNightModeReceiver(); + otaViewManager.unregisterOtaViewReceiver(); } protected void showProgressDialog() { @@ -252,6 +257,9 @@ protected void enterMainView() { @Override public boolean onAllKeyEvent(KeyEvent event) { + if (otaViewManager.isShowing()) { + return true; + } sendBroadcast(new Intent(IntentExtraKey.ACTION_DISMISS_AUTO_DISPLAY)); if (nightModeStateManager.isShowing()) { sendBroadcast(new Intent(IntentExtraKey.ACTION_ANY_KEY_PRESSED));