summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/LiveDisplayTile.java57
1 files changed, 43 insertions, 14 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/LiveDisplayTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/LiveDisplayTile.java
index 97d9381..24043fe 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/LiveDisplayTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/LiveDisplayTile.java
@@ -24,7 +24,10 @@ import static lineageos.hardware.LiveDisplayManager.MODE_NIGHT;
import static lineageos.hardware.LiveDisplayManager.MODE_OFF;
import static lineageos.hardware.LiveDisplayManager.MODE_OUTDOOR;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.ContentObserver;
@@ -60,10 +63,11 @@ public class LiveDisplayTile extends QSTileImpl<LiveDisplayState> {
private boolean mListening;
- private int mDayTemperature;
+ private int mDayTemperature = -1;
private final boolean mNightDisplayAvailable;
- private final boolean mOutdoorModeAvailable;
+ private boolean mOutdoorModeAvailable;
+ private boolean mReceiverRegistered;
private final LiveDisplayManager mLiveDisplay;
@@ -84,17 +88,37 @@ public class LiveDisplayTile extends QSTileImpl<LiveDisplayState> {
updateEntries();
mLiveDisplay = LiveDisplayManager.getInstance(mContext);
+ if (!updateConfig()) {
+ mContext.registerReceiver(mReceiver, new IntentFilter(
+ lineageos.content.Intent.ACTION_INITIALIZE_LIVEDISPLAY));
+ mReceiverRegistered = true;
+ }
+
+ mObserver = new LiveDisplayObserver(mHandler);
+ mObserver.startObserving();
+ }
+
+ @Override
+ protected void handleDestroy() {
+ super.handleDestroy();
+ unregisterReceiver();
+ }
+
+ private void unregisterReceiver() {
+ if (mReceiverRegistered) {
+ mContext.unregisterReceiver(mReceiver);
+ mReceiverRegistered = false;
+ }
+ }
+
+ private boolean updateConfig() {
if (mLiveDisplay.getConfig() != null) {
mOutdoorModeAvailable = mLiveDisplay.getConfig().hasFeature(MODE_OUTDOOR) &&
!mLiveDisplay.getConfig().hasFeature(FEATURE_MANAGED_OUTDOOR_MODE);
mDayTemperature = mLiveDisplay.getDayColorTemperature();
- } else {
- mOutdoorModeAvailable = false;
- mDayTemperature = -1;
+ return true;
}
-
- mObserver = new LiveDisplayObserver(mHandler);
- mObserver.startObserving();
+ return false;
}
private void updateEntries() {
@@ -107,11 +131,6 @@ public class LiveDisplayTile extends QSTileImpl<LiveDisplayState> {
}
@Override
- public boolean isAvailable() {
- return !mNightDisplayAvailable || mOutdoorModeAvailable;
- }
-
- @Override
public LiveDisplayState newTileState() {
return new LiveDisplayState();
}
@@ -141,7 +160,8 @@ public class LiveDisplayTile extends QSTileImpl<LiveDisplayState> {
state.secondaryLabel = mEntries[state.mode];
state.icon = ResourceIcon.get(mEntryIconRes[state.mode]);
state.contentDescription = mDescriptionEntries[state.mode];
- state.state = mLiveDisplay.getMode() != MODE_OFF ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
+ state.state = (mNightDisplayAvailable && !mOutdoorModeAvailable) ? Tile.STATE_UNAVAILABLE:
+ mLiveDisplay.getMode() != MODE_OFF ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
}
@Override
@@ -228,4 +248,13 @@ public class LiveDisplayTile extends QSTileImpl<LiveDisplayState> {
mContext.getContentResolver().unregisterContentObserver(this);
}
}
+
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ updateConfig();
+ refreshState();
+ unregisterReceiver();
+ }
+ };
}