Loading packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt +1 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ interface ClockEvents { fun onColorPaletteChanged(resources: Resources) {} /** Call whenever the weather data should update */ fun onWeatherDataChanged(data: Weather) {} fun onWeatherDataChanged(data: WeatherData) {} } /** Methods which trigger various clock animations */ Loading packages/SystemUI/plugin/src/com/android/systemui/plugins/Weather.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/WeatherData.kt +107 −0 Original line number Diff line number Diff line package com.android.systemui.plugins import android.os.Bundle import androidx.annotation.VisibleForTesting class Weather(val conditions: WeatherStateIcon, val temperature: Int, val isCelsius: Boolean) { class WeatherData private constructor( val description: String, val state: WeatherStateIcon, val useCelsius: Boolean, val temperature: Int, ) { companion object { private const val TAG = "Weather" private const val WEATHER_STATE_ICON_KEY = "weather_state_icon_extra_key" private const val TEMPERATURE_VALUE_KEY = "temperature_value_extra_key" private const val TEMPERATURE_UNIT_KEY = "temperature_unit_extra_key" private const val INVALID_TEMPERATURE = Int.MIN_VALUE private const val TAG = "WeatherData" @VisibleForTesting const val DESCRIPTION_KEY = "description" @VisibleForTesting const val STATE_KEY = "state" @VisibleForTesting const val USE_CELSIUS_KEY = "use_celsius" @VisibleForTesting const val TEMPERATURE_KEY = "temperature" private const val INVALID_WEATHER_ICON_STATE = -1 fun fromBundle(extras: Bundle): Weather? { val icon = WeatherStateIcon.fromInt( extras.getInt(WEATHER_STATE_ICON_KEY, WeatherStateIcon.UNKNOWN_ICON.id) fun fromBundle(extras: Bundle): WeatherData? { val description = extras.getString(DESCRIPTION_KEY) val state = WeatherStateIcon.fromInt(extras.getInt(STATE_KEY, INVALID_WEATHER_ICON_STATE)) val temperature = readIntFromBundle(extras, TEMPERATURE_KEY) return if ( description == null || state == null || !extras.containsKey(USE_CELSIUS_KEY) || temperature == null ) null else WeatherData( description = description, state = state, useCelsius = extras.getBoolean(USE_CELSIUS_KEY), temperature = temperature ) if (icon == null || icon == WeatherStateIcon.UNKNOWN_ICON) { return null } val temperature = extras.getInt(TEMPERATURE_VALUE_KEY, INVALID_TEMPERATURE) if (temperature == INVALID_TEMPERATURE) { return null } return Weather(icon, temperature, extras.getBoolean(TEMPERATURE_UNIT_KEY)) private fun readIntFromBundle(extras: Bundle, key: String): Int? = try { extras.getString(key).toInt() } catch (e: Exception) { null } } Loading Loading @@ -80,6 +101,7 @@ class Weather(val conditions: WeatherStateIcon, val temperature: Int, val isCels } override fun toString(): String { return "$conditions $temperature${if (isCelsius) "C" else "F"}" val unit = if (useCelsius) "C" else "F" return "$state (\"$description\") $temperature°$unit" } } packages/SystemUI/src/com/android/keyguard/ClockEventController.kt +3 −5 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ import com.android.systemui.plugins.ClockTickRate import com.android.systemui.plugins.log.LogBuffer import com.android.systemui.plugins.log.LogLevel.DEBUG import com.android.systemui.shared.regionsampling.RegionSampler import com.android.systemui.plugins.Weather import com.android.systemui.plugins.WeatherData import com.android.systemui.statusbar.policy.BatteryController import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback import com.android.systemui.statusbar.policy.ConfigurationController Loading Loading @@ -291,12 +291,10 @@ constructor( clock?.events?.onTimeFormatChanged(DateFormat.is24HourFormat(context)) } override fun onWeatherDataChanged(data: Weather?) { if (data != null) { override fun onWeatherDataChanged(data: WeatherData) { clock?.events?.onWeatherDataChanged(data) } } } fun registerListeners(parent: View) { if (isRegistered) { Loading packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +3 −3 Original line number Diff line number Diff line Loading @@ -148,7 +148,7 @@ import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dump.DumpManager; import com.android.systemui.dump.DumpsysTableLogger; import com.android.systemui.log.SessionTracker; import com.android.systemui.plugins.Weather; import com.android.systemui.plugins.WeatherData; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.settings.UserTracker; import com.android.systemui.shared.system.TaskStackChangeListener; Loading Loading @@ -3286,12 +3286,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab /** * @param data the weather data (temp, conditions, unit) for weather clock to use */ public void sendWeatherData(Weather data) { public void sendWeatherData(WeatherData data) { mHandler.post(()-> { handleWeatherDataUpdate(data); }); } private void handleWeatherDataUpdate(Weather data) { private void handleWeatherDataUpdate(WeatherData data) { Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); Loading packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java +2 −2 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.settingslib.fuelgauge.BatteryStatus; import com.android.systemui.plugins.Weather; import com.android.systemui.plugins.WeatherData; import com.android.systemui.statusbar.KeyguardIndicationController; import java.util.TimeZone; Loading Loading @@ -61,7 +61,7 @@ public class KeyguardUpdateMonitorCallback { /** * Called when receive new weather data. */ public void onWeatherDataChanged(Weather data) { } public void onWeatherDataChanged(WeatherData data) { } /** * Called when the carrier PLMN or SPN changes. Loading Loading
packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt +1 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ interface ClockEvents { fun onColorPaletteChanged(resources: Resources) {} /** Call whenever the weather data should update */ fun onWeatherDataChanged(data: Weather) {} fun onWeatherDataChanged(data: WeatherData) {} } /** Methods which trigger various clock animations */ Loading
packages/SystemUI/plugin/src/com/android/systemui/plugins/Weather.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/WeatherData.kt +107 −0 Original line number Diff line number Diff line package com.android.systemui.plugins import android.os.Bundle import androidx.annotation.VisibleForTesting class Weather(val conditions: WeatherStateIcon, val temperature: Int, val isCelsius: Boolean) { class WeatherData private constructor( val description: String, val state: WeatherStateIcon, val useCelsius: Boolean, val temperature: Int, ) { companion object { private const val TAG = "Weather" private const val WEATHER_STATE_ICON_KEY = "weather_state_icon_extra_key" private const val TEMPERATURE_VALUE_KEY = "temperature_value_extra_key" private const val TEMPERATURE_UNIT_KEY = "temperature_unit_extra_key" private const val INVALID_TEMPERATURE = Int.MIN_VALUE private const val TAG = "WeatherData" @VisibleForTesting const val DESCRIPTION_KEY = "description" @VisibleForTesting const val STATE_KEY = "state" @VisibleForTesting const val USE_CELSIUS_KEY = "use_celsius" @VisibleForTesting const val TEMPERATURE_KEY = "temperature" private const val INVALID_WEATHER_ICON_STATE = -1 fun fromBundle(extras: Bundle): Weather? { val icon = WeatherStateIcon.fromInt( extras.getInt(WEATHER_STATE_ICON_KEY, WeatherStateIcon.UNKNOWN_ICON.id) fun fromBundle(extras: Bundle): WeatherData? { val description = extras.getString(DESCRIPTION_KEY) val state = WeatherStateIcon.fromInt(extras.getInt(STATE_KEY, INVALID_WEATHER_ICON_STATE)) val temperature = readIntFromBundle(extras, TEMPERATURE_KEY) return if ( description == null || state == null || !extras.containsKey(USE_CELSIUS_KEY) || temperature == null ) null else WeatherData( description = description, state = state, useCelsius = extras.getBoolean(USE_CELSIUS_KEY), temperature = temperature ) if (icon == null || icon == WeatherStateIcon.UNKNOWN_ICON) { return null } val temperature = extras.getInt(TEMPERATURE_VALUE_KEY, INVALID_TEMPERATURE) if (temperature == INVALID_TEMPERATURE) { return null } return Weather(icon, temperature, extras.getBoolean(TEMPERATURE_UNIT_KEY)) private fun readIntFromBundle(extras: Bundle, key: String): Int? = try { extras.getString(key).toInt() } catch (e: Exception) { null } } Loading Loading @@ -80,6 +101,7 @@ class Weather(val conditions: WeatherStateIcon, val temperature: Int, val isCels } override fun toString(): String { return "$conditions $temperature${if (isCelsius) "C" else "F"}" val unit = if (useCelsius) "C" else "F" return "$state (\"$description\") $temperature°$unit" } }
packages/SystemUI/src/com/android/keyguard/ClockEventController.kt +3 −5 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ import com.android.systemui.plugins.ClockTickRate import com.android.systemui.plugins.log.LogBuffer import com.android.systemui.plugins.log.LogLevel.DEBUG import com.android.systemui.shared.regionsampling.RegionSampler import com.android.systemui.plugins.Weather import com.android.systemui.plugins.WeatherData import com.android.systemui.statusbar.policy.BatteryController import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback import com.android.systemui.statusbar.policy.ConfigurationController Loading Loading @@ -291,12 +291,10 @@ constructor( clock?.events?.onTimeFormatChanged(DateFormat.is24HourFormat(context)) } override fun onWeatherDataChanged(data: Weather?) { if (data != null) { override fun onWeatherDataChanged(data: WeatherData) { clock?.events?.onWeatherDataChanged(data) } } } fun registerListeners(parent: View) { if (isRegistered) { Loading
packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +3 −3 Original line number Diff line number Diff line Loading @@ -148,7 +148,7 @@ import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dump.DumpManager; import com.android.systemui.dump.DumpsysTableLogger; import com.android.systemui.log.SessionTracker; import com.android.systemui.plugins.Weather; import com.android.systemui.plugins.WeatherData; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.settings.UserTracker; import com.android.systemui.shared.system.TaskStackChangeListener; Loading Loading @@ -3286,12 +3286,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab /** * @param data the weather data (temp, conditions, unit) for weather clock to use */ public void sendWeatherData(Weather data) { public void sendWeatherData(WeatherData data) { mHandler.post(()-> { handleWeatherDataUpdate(data); }); } private void handleWeatherDataUpdate(Weather data) { private void handleWeatherDataUpdate(WeatherData data) { Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); Loading
packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java +2 −2 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.settingslib.fuelgauge.BatteryStatus; import com.android.systemui.plugins.Weather; import com.android.systemui.plugins.WeatherData; import com.android.systemui.statusbar.KeyguardIndicationController; import java.util.TimeZone; Loading Loading @@ -61,7 +61,7 @@ public class KeyguardUpdateMonitorCallback { /** * Called when receive new weather data. */ public void onWeatherDataChanged(Weather data) { } public void onWeatherDataChanged(WeatherData data) { } /** * Called when the carrier PLMN or SPN changes. Loading