• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

Revisioncf97b6b32a6edafd6c88f4b1ef8c443118eb5e5e (tree)
Zeit2016-10-09 19:47:07
AutorLuis Vidal <lvidal@cyng...>
CommiterSteve Kondik

Log Message

Add Weather Content Provider [5/5]

Use the Weather Content Provider in the cmsdk to pull the
weather data.

However, SystemUI will rely on LockClock to force weather
updates via the new Weather Service, which in turn will
send a broadcast when new weather data is available.

Change-Id: I3c65ea5f4cc297a7944fcdef33f496cdf2d68d0a

SystemUI: Expose weather text colors

Weather text colors in the expanded status bar are hardcoded to
white. Expose these via cm_colors so that themes can color them
however they'd like.

A martini. Shaken, not stirred.

Change-Id: I5e5a738c8b97f556562114a66d102fcb924a0493

SystemUI: Update cached weather data when temperature unit changes

Register an observer to keep track of the temperature unit
selected in settings to update the cached data accordingly

TICKET: CYNGNOS-2694

Change-Id: I92adec20835bcd6d6476d793564300611bcba4a1

Ändern Zusammenfassung

Diff

--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -165,9 +165,6 @@
165165 <!-- the ability to rename notifications posted by other apps -->
166166 <uses-permission android:name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME" />
167167
168- <!-- Weather -->
169- <uses-permission android:name="com.cyanogenmod.lockclock.permission.READ_WEATHER" />
170-
171168 <!-- manage cmsettings -->
172169 <uses-permission android:name="cyanogenmod.permission.WRITE_SETTINGS" />
173170 <uses-permission android:name="cyanogenmod.permission.WRITE_SECURE_SETTINGS" />
--- a/packages/SystemUI/AndroidManifest_cm.xml
+++ b/packages/SystemUI/AndroidManifest_cm.xml
@@ -26,6 +26,9 @@
2626 <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
2727 <uses-permission android:name="android.permission.RECORD_AUDIO" />
2828
29+ <!-- Weather Provider -->
30+ <uses-permission android:name="cyanogenmod.permission.READ_WEATHER" />
31+
2932 <application>
3033
3134 <activity-alias
--- a/packages/SystemUI/res/layout/status_bar_expanded_header.xml
+++ b/packages/SystemUI/res/layout/status_bar_expanded_header.xml
@@ -183,7 +183,7 @@
183183 android:layout_height="wrap_content"
184184 android:paddingEnd="16dp"
185185 android:gravity="right"
186- android:textColor="#ffffff"
186+ android:textColor="@color/status_bar_temperature_text_color"
187187 android:textSize="@dimen/weather_text_size"
188188 android:importantForAccessibility="noHideDescendants"/>
189189 <TextView
@@ -192,7 +192,7 @@
192192 android:layout_height="wrap_content"
193193 android:paddingEnd="16dp"
194194 android:gravity="right"
195- android:textColor="#ffffff"
195+ android:textColor="@color/status_bar_temperature_location_text_color"
196196 android:textSize="@dimen/weather_text_size"
197197 android:importantForAccessibility="noHideDescendants"/>
198198 </LinearLayout>
--- /dev/null
+++ b/packages/SystemUI/res/values/cm_colors.xml
@@ -0,0 +1,23 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!--
3+ Copyright (C) 2016 The CyanogenMod Project
4+
5+ Licensed under the Apache License, Version 2.0 (the "License");
6+ you may not use this file except in compliance with the License.
7+ You may obtain a copy of the License at
8+
9+ http://www.apache.org/licenses/LICENSE-2.0
10+
11+ Unless required by applicable law or agreed to in writing, software
12+ distributed under the License is distributed on an "AS IS" BASIS,
13+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ See the License for the specific language governing permissions and
15+ limitations under the License.
16+-->
17+<resources>
18+
19+ <!-- Expanded Status Bar Weather Text Colors -->
20+ <color name="status_bar_temperature_text_color">#FFFFFFFF</color>
21+ <color name="status_bar_temperature_location_text_color">#FFFFFFFF</color>
22+
23+</resources>
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
@@ -16,34 +16,22 @@
1616
1717 package com.android.systemui.statusbar.phone;
1818
19-import android.app.ActivityManager;
20-import android.app.ActivityManagerNative;
2119 import android.app.AlarmManager;
22-import android.app.IUserSwitchObserver;
2320 import android.app.PendingIntent;
2421 import android.content.ContentUris;
25-import android.content.ContentResolver;
2622 import android.content.Context;
2723 import android.content.Intent;
2824 import android.content.res.Configuration;
2925 import android.content.res.Resources;
30-import android.database.ContentObserver;
3126 import android.graphics.Outline;
3227 import android.graphics.Rect;
3328 import android.graphics.drawable.Animatable;
3429 import android.graphics.drawable.Drawable;
3530 import android.graphics.drawable.RippleDrawable;
3631 import android.net.Uri;
37-import android.os.Handler;
38-import android.os.IRemoteCallback;
39-import android.os.RemoteException;
40-import android.os.UserHandle;
4132 import android.provider.AlarmClock;
4233 import android.provider.CalendarContract;
43-import android.provider.Settings;
44-import android.net.Uri;
4534 import android.util.AttributeSet;
46-import android.util.Log;
4735 import android.util.MathUtils;
4836 import android.util.TypedValue;
4937 import android.view.View;
@@ -55,11 +43,11 @@ import android.widget.RelativeLayout;
5543 import android.widget.Switch;
5644 import android.widget.TextView;
5745 import android.widget.Toast;
46+
5847 import com.android.keyguard.KeyguardStatusView;
5948 import com.android.systemui.BatteryMeterView;
6049 import com.android.systemui.FontSizeUtils;
6150 import com.android.systemui.R;
62-import com.android.systemui.cm.UserContentObserver;
6351 import com.android.systemui.qs.QSPanel;
6452 import com.android.systemui.qs.QSPanel.Callback;
6553 import com.android.systemui.qs.QSTile;
@@ -75,13 +63,14 @@ import com.android.systemui.tuner.TunerService;
7563 import java.text.NumberFormat;
7664
7765 import cyanogenmod.providers.CMSettings;
66+import cyanogenmod.weather.util.WeatherUtils;
7867
7968 /**
8069 * The view to manage the header area in the expanded status bar.
8170 */
8271 public class StatusBarHeaderView extends BaseStatusBarHeader implements View.OnClickListener,
8372 BatteryController.BatteryStateChangeCallback, NextAlarmController.NextAlarmChangeCallback,
84- EmergencyListener, WeatherController.Callback {
73+ EmergencyListener, WeatherController.Callback, TunerService.Tunable {
8574
8675 private boolean mExpanded;
8776 private boolean mListening;
@@ -152,7 +141,6 @@ public class StatusBarHeaderView extends BaseStatusBarHeader implements View.OnC
152141 private float mCurrentT;
153142 private boolean mShowingDetail;
154143 private boolean mDetailTransitioning;
155- private SettingsObserver mSettingsObserver;
156144 private boolean mShowWeather;
157145
158146 private boolean mAllowExpand = true;
@@ -195,7 +183,6 @@ public class StatusBarHeaderView extends BaseStatusBarHeader implements View.OnC
195183 mWeatherContainer.setOnClickListener(this);
196184 mWeatherLine1 = (TextView) findViewById(R.id.weather_line_1);
197185 mWeatherLine2 = (TextView) findViewById(R.id.weather_line_2);
198- mSettingsObserver = new SettingsObserver(new Handler());
199186 loadDimens();
200187 updateVisibilities();
201188 updateClockScale();
@@ -419,7 +406,8 @@ public class StatusBarHeaderView extends BaseStatusBarHeader implements View.OnC
419406
420407 private void updateListeners() {
421408 if (mListening) {
422- mSettingsObserver.observe();
409+ TunerService.get(getContext()).addTunable(this,
410+ "cmsystem:" + CMSettings.System.STATUS_BAR_SHOW_WEATHER);
423411 mBatteryController.addStateChangedCallback(this);
424412 mNextAlarmController.addStateChangedCallback(this);
425413 mWeatherController.addCallback(this);
@@ -427,7 +415,7 @@ public class StatusBarHeaderView extends BaseStatusBarHeader implements View.OnC
427415 mBatteryController.removeStateChangedCallback(this);
428416 mNextAlarmController.removeStateChangedCallback(this);
429417 mWeatherController.removeCallback(this);
430- mSettingsObserver.unobserve();
418+ TunerService.get(getContext()).removeTunable(this);
431419 }
432420 }
433421
@@ -479,12 +467,12 @@ public class StatusBarHeaderView extends BaseStatusBarHeader implements View.OnC
479467
480468 @Override
481469 public void onWeatherChanged(WeatherController.WeatherInfo info) {
482- if (info.temp == null || info.condition == null) {
470+ if (Double.isNaN(info.temp) || info.condition == null) {
483471 mWeatherLine1.setText(null);
484472 } else {
485473 mWeatherLine1.setText(mContext.getString(
486474 R.string.status_bar_expanded_header_weather_format,
487- info.temp,
475+ WeatherUtils.formatTemperature(info.temp, info.tempUnit),
488476 info.condition));
489477 }
490478 mWeatherLine2.setText(info.city);
@@ -930,35 +918,10 @@ public class StatusBarHeaderView extends BaseStatusBarHeader implements View.OnC
930918 }
931919 };
932920
933- class SettingsObserver extends UserContentObserver {
934- SettingsObserver(Handler handler) {
935- super(handler);
936- }
937-
938- @Override
939- protected void observe() {
940- super.observe();
941-
942- ContentResolver resolver = mContext.getContentResolver();
943- resolver.registerContentObserver(CMSettings.System.getUriFor(
944- CMSettings.System.STATUS_BAR_SHOW_WEATHER), false, this, UserHandle.USER_ALL);
945- update();
946- }
947-
948- @Override
949- protected void unobserve() {
950- super.unobserve();
951-
952- ContentResolver resolver = mContext.getContentResolver();
953- resolver.unregisterContentObserver(this);
954- }
955-
956- @Override
957- public void update() {
958-
959- ContentResolver resolver = mContext.getContentResolver();
960- mShowWeather = CMSettings.System.getInt(
961- resolver, CMSettings.System.STATUS_BAR_SHOW_WEATHER, 1) == 1;
921+ @Override
922+ public void onTuningChanged(String key, String newValue) {
923+ if (key.endsWith(CMSettings.System.STATUS_BAR_SHOW_WEATHER)) {
924+ mShowWeather = newValue == null || "1".equals(newValue);
962925 updateVisibilities();
963926 }
964927 }
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherController.java
@@ -25,8 +25,9 @@ public interface WeatherController {
2525 void onWeatherChanged(WeatherInfo temp);
2626 }
2727 public static class WeatherInfo {
28- public String temp = null;
28+ public double temp = Double.NaN;
2929 public String city = null;
3030 public String condition = null;
31+ public int tempUnit;
3132 }
3233 }
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherControllerImpl.java
@@ -16,43 +16,49 @@
1616
1717 package com.android.systemui.statusbar.policy;
1818
19-import android.content.BroadcastReceiver;
2019 import android.content.ComponentName;
21-import android.content.ContentResolver;
2220 import android.content.Context;
2321 import android.content.Intent;
24-import android.content.IntentFilter;
2522 import android.database.ContentObserver;
2623 import android.database.Cursor;
2724 import android.net.Uri;
2825 import android.os.Handler;
29-import android.provider.Settings;
3026 import android.util.Log;
27+import cyanogenmod.providers.CMSettings;
28+import cyanogenmod.providers.WeatherContract;
29+import cyanogenmod.weather.CMWeatherManager;
30+import cyanogenmod.weather.util.WeatherUtils;
3131
3232 import java.util.ArrayList;
3333
34+import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_CITY;
35+import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_CONDITION;
36+import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_TEMPERATURE;
37+import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_TEMPERATURE_UNIT;
38+import static cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit.CELSIUS;
39+import static cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit.FAHRENHEIT;
40+
3441 public class WeatherControllerImpl implements WeatherController {
3542
3643 private static final String TAG = WeatherController.class.getSimpleName();
3744 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
45+ private WeatherContentObserver mWeatherContentObserver;
46+ private Handler mHandler;
47+ private int mWeatherUnit;
48+ private Uri mWeatherTempetarureUri;
3849
3950 public static final ComponentName COMPONENT_WEATHER_FORECAST = new ComponentName(
4051 "com.cyanogenmod.lockclock", "com.cyanogenmod.lockclock.weather.ForecastActivity");
41- public static final String ACTION_UPDATE_FINISHED
42- = "com.cyanogenmod.lockclock.action.WEATHER_UPDATE_FINISHED";
43- public static final String EXTRA_UPDATE_CANCELLED = "update_cancelled";
4452 public static final String ACTION_FORCE_WEATHER_UPDATE
4553 = "com.cyanogenmod.lockclock.action.FORCE_WEATHER_UPDATE";
46- public static final Uri CURRENT_WEATHER_URI
47- = Uri.parse("content://com.cyanogenmod.lockclock.weather.provider/weather/current");
48- public static final String[] WEATHER_PROJECTION = new String[]{
49- "temperature",
50- "city",
51- "condition"
54+ private static final String[] WEATHER_PROJECTION = new String[]{
55+ CURRENT_TEMPERATURE,
56+ CURRENT_TEMPERATURE_UNIT,
57+ CURRENT_CITY,
58+ CURRENT_CONDITION
5259 };
5360
5461 private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
55- private final Receiver mReceiver = new Receiver();
5662 private final Context mContext;
5763
5864 private WeatherInfo mCachedInfo = new WeatherInfo();
@@ -60,10 +66,16 @@ public class WeatherControllerImpl implements WeatherController {
6066 public WeatherControllerImpl(Context context) {
6167 mContext = context;
6268 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
69+ mHandler = new Handler();
70+ mWeatherContentObserver = new WeatherContentObserver(mHandler);
71+ mWeatherTempetarureUri
72+ = CMSettings.Global.getUriFor(CMSettings.Global.WEATHER_TEMPERATURE_UNIT);
73+ mContext.getContentResolver().registerContentObserver(
74+ WeatherContract.WeatherColumns.CURRENT_WEATHER_URI,true, mWeatherContentObserver);
75+ mContext.getContentResolver().registerContentObserver(mWeatherTempetarureUri, true,
76+ mWeatherContentObserver);
77+ queryWeatherTempUnit();
6378 queryWeather();
64- final IntentFilter filter = new IntentFilter();
65- filter.addAction(ACTION_UPDATE_FINISHED);
66- mContext.registerReceiver(mReceiver, filter);
6779 }
6880
6981 public void addCallback(Callback callback) {
@@ -85,17 +97,29 @@ public class WeatherControllerImpl implements WeatherController {
8597 }
8698
8799 private void queryWeather() {
88- Cursor c = mContext.getContentResolver().query(CURRENT_WEATHER_URI, WEATHER_PROJECTION,
100+ Cursor c = mContext.getContentResolver().query(
101+ WeatherContract.WeatherColumns.CURRENT_WEATHER_URI, WEATHER_PROJECTION,
89102 null, null, null);
90103 if (c == null) {
91104 if(DEBUG) Log.e(TAG, "cursor was null for temperature, forcing weather update");
105+ //LockClock keeps track of the user settings (temp unit, search by geo location/city)
106+ //so we delegate the responsibility of handling a weather update to LockClock
92107 mContext.sendBroadcast(new Intent(ACTION_FORCE_WEATHER_UPDATE));
93108 } else {
94109 try {
95110 c.moveToFirst();
96- mCachedInfo.temp = c.getString(0);
97- mCachedInfo.city = c.getString(1);
98- mCachedInfo.condition = c.getString(2);
111+ double temp = c.getDouble(0);
112+ int reportedUnit = c.getInt(1);
113+ if (reportedUnit == CELSIUS && mWeatherUnit == FAHRENHEIT) {
114+ temp = WeatherUtils.celsiusToFahrenheit(temp);
115+ } else if (reportedUnit == FAHRENHEIT && mWeatherUnit == CELSIUS) {
116+ temp = WeatherUtils.fahrenheitToCelsius(temp);
117+ }
118+
119+ mCachedInfo.temp = temp;
120+ mCachedInfo.tempUnit = mWeatherUnit;
121+ mCachedInfo.city = c.getString(2);
122+ mCachedInfo.condition = c.getString(3);
99123 } finally {
100124 c.close();
101125 }
@@ -108,19 +132,53 @@ public class WeatherControllerImpl implements WeatherController {
108132 }
109133 }
110134
111- private final class Receiver extends BroadcastReceiver {
135+ private class WeatherContentObserver extends ContentObserver {
136+
137+ public WeatherContentObserver(Handler handler) {
138+ super(handler);
139+ }
140+
112141 @Override
113- public void onReceive(Context context, Intent intent) {
114- if (DEBUG) Log.d(TAG, "onReceive " + intent.getAction());
115- if (intent.hasExtra(EXTRA_UPDATE_CANCELLED)) {
116- if (intent.getBooleanExtra(EXTRA_UPDATE_CANCELLED, false)) {
117- // no update
118- return;
142+ public void onChange(boolean selfChange, Uri uri) {
143+ if (uri != null) {
144+ if (uri.compareTo(WeatherContract.WeatherColumns.CURRENT_WEATHER_URI) == 0) {
145+ queryWeather();
146+ fireCallback();
147+ } else if (uri.compareTo(mWeatherTempetarureUri) == 0) {
148+ queryWeatherTempUnit();
149+ fixCachedWeatherInfo();
150+ fireCallback();
151+ } else {
152+ super.onChange(selfChange, uri);
119153 }
120154 }
121- queryWeather();
122- fireCallback();
155+ }
156+
157+ @Override
158+ public void onChange(boolean selfChange) {
159+ onChange(selfChange, null);
123160 }
124161 }
125162
163+ private void queryWeatherTempUnit() {
164+ try {
165+ mWeatherUnit = CMSettings.Global.getInt(mContext.getContentResolver(),
166+ CMSettings.Global.WEATHER_TEMPERATURE_UNIT);
167+ } catch (CMSettings.CMSettingNotFoundException e) {
168+ //CMSettingsProvider should have taken care of setting a default value for this setting
169+ //so how is that we ended up here?? We need to set a valid temp unit anyway to keep
170+ //this going
171+ mWeatherUnit = WeatherContract.WeatherColumns.TempUnit.CELSIUS;
172+ }
173+ }
174+
175+ private void fixCachedWeatherInfo() {
176+ if (mCachedInfo.tempUnit == CELSIUS && mWeatherUnit == FAHRENHEIT) {
177+ mCachedInfo.temp = WeatherUtils.celsiusToFahrenheit(mCachedInfo.temp);
178+ mCachedInfo.tempUnit = FAHRENHEIT;
179+ } else if (mCachedInfo.tempUnit == FAHRENHEIT && mWeatherUnit == CELSIUS) {
180+ mCachedInfo.temp = WeatherUtils.fahrenheitToCelsius(mCachedInfo.temp);
181+ mCachedInfo.tempUnit = CELSIUS;
182+ }
183+ }
126184 }