summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2016-03-10 16:15:14 -0800
committerDanesh M <daneshm90@gmail.com>2016-03-14 13:21:24 -0800
commitf5994c831f908019f29187a616af1d1a407c78a8 (patch)
tree2e87fed36d82e30efdd39520e5c862c0d21f9d36 /packages/SystemUI
parent6b5c6f33523facb3baef64f335c5439df6d58544 (diff)
downloadframeworks_base-f5994c831f908019f29187a616af1d1a407c78a8.zip
frameworks_base-f5994c831f908019f29187a616af1d1a407c78a8.tar.gz
frameworks_base-f5994c831f908019f29187a616af1d1a407c78a8.tar.bz2
Prompt permission dialog for status bar weather
CYNGNOS-2222 Change-Id: I435b1badbc5949cb0bc76050a67e212d519c466a
Diffstat (limited to 'packages/SystemUI')
-rw-r--r--packages/SystemUI/res/layout/qs_settings.xml3
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSBooleanSettingRow.java15
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSSettings.java65
3 files changed, 79 insertions, 4 deletions
diff --git a/packages/SystemUI/res/layout/qs_settings.xml b/packages/SystemUI/res/layout/qs_settings.xml
index b7c8d60..bd7cbec 100644
--- a/packages/SystemUI/res/layout/qs_settings.xml
+++ b/packages/SystemUI/res/layout/qs_settings.xml
@@ -37,10 +37,11 @@
<!-- show weather -->
<com.android.systemui.qs.QSBooleanSettingRow
+ android:id="@+id/show_weather"
style="@style/SettingRow"
android:key="status_bar_show_weather"
android:title="@string/quick_settings_title_show_weather"
- systemui:defaultValue="1"
+ systemui:defaultValue="0"
systemui:table="cm_system"/>
<!-- brightness slider -->
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSBooleanSettingRow.java b/packages/SystemUI/src/com/android/systemui/qs/QSBooleanSettingRow.java
index d2d13ae..50845da 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSBooleanSettingRow.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSBooleanSettingRow.java
@@ -49,6 +49,7 @@ public class QSBooleanSettingRow extends LinearLayout implements View.OnClickLis
private TextView mText;
private Switch mSwitch;
private int mDefaultValue;
+ private CompoundButton.OnCheckedChangeListener mOnCheckedChangeListener;
public QSBooleanSettingRow(Context context) {
this(context, null);
@@ -99,6 +100,9 @@ public class QSBooleanSettingRow extends LinearLayout implements View.OnClickLis
+ "buttonView = [" + buttonView + "], isChecked = [" + isChecked
+ "] and table: " + mWhichTable + ", and key: " + mKey);
applyChange(isChecked);
+ if (mOnCheckedChangeListener != null) {
+ mOnCheckedChangeListener.onCheckedChanged(buttonView, isChecked);
+ }
}
});
}
@@ -106,6 +110,13 @@ public class QSBooleanSettingRow extends LinearLayout implements View.OnClickLis
a.recycle();
}
+ public void setChecked(boolean checked) {
+ if (mSwitch.isChecked() == checked) {
+ return;
+ }
+ mSwitch.setChecked(checked);
+ }
+
private void applyChange(boolean value) {
ContentResolver cr = getContext().getContentResolver();
switch (mWhichTable) {
@@ -160,4 +171,8 @@ public class QSBooleanSettingRow extends LinearLayout implements View.OnClickLis
public void onClick(View v) {
mSwitch.setChecked(!mSwitch.isChecked());
}
+
+ public void setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener l) {
+ mOnCheckedChangeListener = l;
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSettings.java b/packages/SystemUI/src/com/android/systemui/qs/QSSettings.java
index 7766ca4..0a2b937 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSSettings.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSSettings.java
@@ -15,15 +15,22 @@
*/
package com.android.systemui.qs;
+import android.Manifest;
import android.annotation.Nullable;
+import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.os.ResultReceiver;
import android.util.AttributeSet;
-import android.util.Log;
-import android.view.MotionEvent;
import android.view.View;
-import android.widget.LinearLayout;
+import android.widget.CompoundButton;
import android.widget.ScrollView;
import com.android.systemui.R;
@@ -32,9 +39,16 @@ import com.android.systemui.statusbar.phone.SystemUIDialog;
public class QSSettings extends ScrollView {
+ private static final String RESULT_RECEIVER_EXTRA = "result_receiver";
+ private static final String LOCK_CLOCK_PACKAGENAME = "com.cyanogenmod.lockclock";
+ private static final String LOCK_CLOCK_PERM_CLASS = LOCK_CLOCK_PACKAGENAME
+ + ".weather.PermissionRequestActivity";
+
private QSTileHost mHost;
private boolean mAdapterEditingState;
+ private QSBooleanSettingRow mShowWeather;
+ private ResultReceiver mResultReceiver;
public QSSettings(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
@@ -51,6 +65,51 @@ public class QSSettings extends ScrollView {
initiateTileReset();
}
});
+
+ mShowWeather = (QSBooleanSettingRow) findViewById(R.id.show_weather);
+ mShowWeather.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (isChecked) {
+ PackageManager packageManager = getContext().getPackageManager();
+ if (packageManager.checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION,
+ LOCK_CLOCK_PACKAGENAME) != PackageManager.PERMISSION_GRANTED) {
+ mShowWeather.setChecked(false);
+ requestPermission();
+ mHost.collapsePanels();
+ }
+ }
+ }
+ });
+ }
+
+ public Parcelable getResultReceiverForSending() {
+ if (mResultReceiver == null) {
+ mResultReceiver = new ResultReceiver(new Handler()) {
+ @Override
+ protected void onReceiveResult(int resultCode, Bundle resultData) {
+ super.onReceiveResult(resultCode, resultData);
+ if (resultCode == Activity.RESULT_OK) {
+ mShowWeather.setChecked(true);
+ }
+ mResultReceiver = null;
+ }
+ };
+ }
+ Parcel parcel = Parcel.obtain();
+ mResultReceiver.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ ResultReceiver receiverForSending = ResultReceiver.CREATOR.createFromParcel(parcel);
+ parcel.recycle();
+ return receiverForSending;
+ }
+
+ private void requestPermission() {
+ Intent i = new Intent();
+ i.setClassName(LOCK_CLOCK_PACKAGENAME, LOCK_CLOCK_PERM_CLASS);
+ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ i.putExtra(RESULT_RECEIVER_EXTRA, getResultReceiverForSending());
+ getContext().startActivity(i);
}
private void initiateTileReset() {