Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41b93c6e authored by Peter Kalauskas's avatar Peter Kalauskas Committed by Android (Google) Code Review
Browse files

Merge "Read weather data from smartspace extras" into tm-qpr-dev

parents cc086f8d e05be49e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 */
+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
            }
    }

@@ -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"
    }
}
+3 −5
Original line number Diff line number Diff line
@@ -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
@@ -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) {
+3 −3
Original line number Diff line number Diff line
@@ -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;
@@ -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();
+2 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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