Skip to content

Commit

Permalink
[ota] add ota view manager to manage ota view
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxJCheung committed Mar 15, 2018
1 parent f7f61cd commit 2d49be1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/src/main/java/com/stockholm/common/IntentExtraKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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";

Expand Down
46 changes: 46 additions & 0 deletions lib/src/main/java/com/stockholm/common/ota/OtaViewManager.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -191,6 +194,7 @@ protected void registerReceiver() {

nightModeStateManager.registerNightModeReceiver();
notificationStateManager.registerNightModeReceiver();
otaViewManager.registerOtaViewReceiver();
}

protected void unregisterReceiver() {
Expand All @@ -199,6 +203,7 @@ protected void unregisterReceiver() {
unregisterReceiver(pauseSoundReceiver);
nightModeStateManager.unregisterNightModeReceiver();
notificationStateManager.unregisterNightModeReceiver();
otaViewManager.unregisterOtaViewReceiver();
}

protected void showProgressDialog() {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 2d49be1

Please sign in to comment.