cmparts: Implement summaries for dashboard tiles
Change-Id: Ibc6ad6180b0c25fcf815eba7961176723f851fe4
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 01331f9..6cde44e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -65,6 +65,7 @@
<receiver android:name=".RefreshReceiver" android:enabled="true">
<intent-filter>
<action android:name="org.cyanogenmod.cmparts.REFRESH_PART" />
+ <action android:name="org.cyanogenmod.settings.REFRESH_SUMMARY" />
</intent-filter>
</receiver>
@@ -95,6 +96,12 @@
<meta-data
android:name="com.android.settings.icon"
android:resource="@drawable/ic_settings_privacy" />
+ <meta-data
+ android:name="org.cyanogenmod.settings.summary.receiver"
+ android:value="org.cyanogenmod.cmparts.RefreshReceiver" />
+ <meta-data
+ android:name="org.cyanogenmod.settings.summary.key"
+ android:value="privacy_settings" />
</activity-alias>
<!-- Button settings (dashboard) -->
@@ -113,6 +120,12 @@
<meta-data
android:name="com.android.settings.icon"
android:resource="@drawable/ic_settings_buttons" />
+ <meta-data
+ android:name="org.cyanogenmod.settings.summary.receiver"
+ android:value="org.cyanogenmod.cmparts.RefreshReceiver" />
+ <meta-data
+ android:name="org.cyanogenmod.settings.summary.key"
+ android:value="button_settings" />
</activity-alias>
<!-- Profiles settings (dashboard) -->
@@ -131,6 +144,12 @@
<meta-data
android:name="com.android.settings.icon"
android:resource="@drawable/ic_settings_profiles" />
+ <meta-data
+ android:name="org.cyanogenmod.settings.summary.receiver"
+ android:value="org.cyanogenmod.cmparts.RefreshReceiver" />
+ <meta-data
+ android:name="org.cyanogenmod.settings.summary.key"
+ android:value="profiles_settings" />
</activity-alias>
<!-- Status bar settings (dashboard) -->
@@ -149,6 +168,12 @@
<meta-data
android:name="com.android.settings.icon"
android:resource="@drawable/ic_settings_statusbar" />
+ <meta-data
+ android:name="org.cyanogenmod.settings.summary.receiver"
+ android:value="org.cyanogenmod.cmparts.RefreshReceiver" />
+ <meta-data
+ android:name="org.cyanogenmod.settings.summary.key"
+ android:value="status_bar_settings" />
</activity-alias>
<!-- Anonymous Statistics -->
@@ -176,7 +201,7 @@
android:enabled="true"
android:exported="false" />
- <!-- Weather settings (dashboard) -->
+ <!-- Weather settings -->
<activity-alias
android:name=".weather.WeatherServiceSettings"
android:label="@string/weather_settings_title"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7b9ec25..e29e9f3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -49,6 +49,7 @@
<string name="privacy_guard_dlg_text">When Privacy Guard is enabled, the app will not be able to access personal data such as contacts, messages or call logs.</string>
<string name="privacy_guard_dlg_system_app_text">When enabling Privacy Guard for a built-in app, the app will not be able to access or provide personal data. This may cause other apps to misbehave.</string>
<string name="privacy_guard_default_title">Enabled by default</string>
+ <string name="privacy_guard_default_summary_on">Privacy Guard is enabled</string>
<string name="privacy_guard_default_summary">Enable by default for newly-installed apps</string>
<string name="privacy_guard_manager_summary">Manage which apps have access to your personal data</string>
<string name="privacy_guard_no_user_apps">No apps are installed</string>
@@ -282,6 +283,7 @@
<string name="profile_menu_delete">Delete</string>
<string name="profile_settings_title">Profile</string>
<string name="profile_empty_list_profiles_off">To configure and use system profiles, turn profiles on.</string>
+ <string name="profile_settings_summary_off">Profiles are disabled</string>
<string name="profile_trigger_configure">Configure trigger</string>
<string name="profile_write_nfc_tag">Write to NFC tag</string>
<string name="profile_write_touch_tag">Touch tag to write</string>
diff --git a/res/xml/privacy_guard_prefs.xml b/res/xml/privacy_guard_prefs.xml
index ad91bef..5409d29 100644
--- a/res/xml/privacy_guard_prefs.xml
+++ b/res/xml/privacy_guard_prefs.xml
@@ -19,11 +19,11 @@
android:key="privacy_guard_manager"
android:title="@*cyanogenmod.platform:string/privacy_guard_manager_title">
- <SwitchPreference
+ <cyanogenmod.preference.CMSecureSettingSwitchPreference
android:key="privacy_guard_default"
android:title="@string/privacy_guard_default_title"
android:summary="@string/privacy_guard_default_summary"
- android:persistent="false" />
+ android:defaultValue="false" />
<cyanogenmod.preference.CMSecureSettingSwitchPreference
android:key="privacy_guard_notification"
diff --git a/src/org/cyanogenmod/cmparts/PartsRefresher.java b/src/org/cyanogenmod/cmparts/PartsRefresher.java
index ca0ae56..d24a1c0 100644
--- a/src/org/cyanogenmod/cmparts/PartsRefresher.java
+++ b/src/org/cyanogenmod/cmparts/PartsRefresher.java
@@ -41,6 +41,7 @@
import static org.cyanogenmod.internal.cmparts.PartsList.ACTION_PART_CHANGED;
import static org.cyanogenmod.internal.cmparts.PartsList.EXTRA_PART;
import static org.cyanogenmod.internal.cmparts.PartsList.EXTRA_PART_KEY;
+import static org.cyanogenmod.internal.cmparts.PartsList.EXTRA_PART_SUMMARY;
/**
* PartsRefresher keeps remote UI clients up to date with any changes in the
@@ -125,6 +126,7 @@
pi.setSummary(si.getSummary(mContext, key));
bundle.putString(EXTRA_PART_KEY, key);
+ bundle.putString(EXTRA_PART_SUMMARY, pi.getSummary());
bundle.putParcelable(EXTRA_PART, pi);
return true;
}
@@ -178,6 +180,7 @@
uris.add(contentUri);
if (!mRefs.contains(contentUri)) {
mResolver.registerContentObserver(contentUri, false, this);
+ listener.onRefresh(mContext, null);
}
mRefs.add(contentUri);
}
diff --git a/src/org/cyanogenmod/cmparts/PrivacySettings.java b/src/org/cyanogenmod/cmparts/PrivacySettings.java
index 8b74c93..f6be14b 100644
--- a/src/org/cyanogenmod/cmparts/PrivacySettings.java
+++ b/src/org/cyanogenmod/cmparts/PrivacySettings.java
@@ -16,8 +16,11 @@
package org.cyanogenmod.cmparts;
+import android.content.Context;
import android.os.Bundle;
+import cyanogenmod.providers.CMSettings;
+
/**
* Privacy settings
*/
@@ -29,4 +32,15 @@
addPreferencesFromResource(R.xml.privacy_settings);
}
+
+ public static final SummaryProvider SUMMARY_PROVIDER = new SummaryProvider() {
+ @Override
+ public String getSummary(Context context, String key) {
+ if (CMSettings.Secure.getInt(context.getContentResolver(),
+ CMSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) == 1) {
+ return context.getString(R.string.privacy_guard_default_summary_on);
+ }
+ return null;
+ }
+ };
}
diff --git a/src/org/cyanogenmod/cmparts/RefreshReceiver.java b/src/org/cyanogenmod/cmparts/RefreshReceiver.java
index d4ccea9..75969a0 100644
--- a/src/org/cyanogenmod/cmparts/RefreshReceiver.java
+++ b/src/org/cyanogenmod/cmparts/RefreshReceiver.java
@@ -19,24 +19,31 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-
-import org.cyanogenmod.internal.cmparts.PartsList;
+import android.util.Log;
import static org.cyanogenmod.internal.cmparts.PartsList.ACTION_REFRESH_PART;
+import static org.cyanogenmod.internal.cmparts.PartsList.EXTRA_PART_KEY;
public class RefreshReceiver extends BroadcastReceiver {
+ /* for Settings dashboard tiles */
+ private static final String ACTION_REFRESH_SUMMARY =
+ "org.cyanogenmod.settings.REFRESH_SUMMARY";
+
/**
* Receiver which handles clients requesting a summary update. A client may send
- * the REFERSH_PART action via sendOrderedBroadcast, and we will reply immediately.
+ * the REFERSH_PART or REFRESH_SUMMARY actions via sendOrderedBroadcast,
+ * and we will reply immediately.
*
* @param context
* @param intent
*/
@Override
public void onReceive(Context context, Intent intent) {
- if (ACTION_REFRESH_PART.equals(intent.getAction()) && isOrderedBroadcast()) {
- final String key = intent.getStringExtra(PartsList.EXTRA_PART_KEY);
+ Log.d("REFRESH-PARTS", intent.toString());
+ if (isOrderedBroadcast() && (ACTION_REFRESH_PART.equals(intent.getAction()) ||
+ ACTION_REFRESH_SUMMARY.equals(intent.getAction()))) {
+ final String key = intent.getStringExtra(EXTRA_PART_KEY);
if (key != null &&
PartsRefresher.get(context).updateExtras(key, getResultExtras(true))) {
setResultCode(Activity.RESULT_OK);
diff --git a/src/org/cyanogenmod/cmparts/privacyguard/PrivacyGuardPrefs.java b/src/org/cyanogenmod/cmparts/privacyguard/PrivacyGuardPrefs.java
index 0635948..2188882 100644
--- a/src/org/cyanogenmod/cmparts/privacyguard/PrivacyGuardPrefs.java
+++ b/src/org/cyanogenmod/cmparts/privacyguard/PrivacyGuardPrefs.java
@@ -18,31 +18,19 @@
package org.cyanogenmod.cmparts.privacyguard;
import android.os.Bundle;
-import android.provider.Settings;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.Preference.OnPreferenceChangeListener;
-import android.support.v14.preference.PreferenceFragment;
-import android.support.v14.preference.SwitchPreference;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ListView;
import org.cyanogenmod.cmparts.R;
-
import org.cyanogenmod.cmparts.SettingsPreferenceFragment;
import cyanogenmod.providers.CMSettings;
-public class PrivacyGuardPrefs extends SettingsPreferenceFragment implements
- OnPreferenceChangeListener {
+public class PrivacyGuardPrefs extends SettingsPreferenceFragment {
private static final String TAG = "PrivacyGuardPrefs";
- private static final String KEY_PRIVACY_GUARD_DEFAULT = "privacy_guard_default";
-
- private SwitchPreference mPrivacyGuardDefault;
-
public static PrivacyGuardPrefs newInstance() {
PrivacyGuardPrefs privacyGuardFragment = new PrivacyGuardPrefs();
return privacyGuardFragment;
@@ -51,13 +39,7 @@
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.privacy_guard_prefs);
-
- mPrivacyGuardDefault = (SwitchPreference) findPreference(KEY_PRIVACY_GUARD_DEFAULT);
- mPrivacyGuardDefault.setOnPreferenceChangeListener(this);
-
- mPrivacyGuardDefault.setChecked(CMSettings.Secure.getInt(
- getActivity().getContentResolver(),
- CMSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) == 1);
+ addTrigger(CMSettings.Secure.getUriFor(CMSettings.Secure.PRIVACY_GUARD_DEFAULT));
}
@Override
@@ -71,15 +53,4 @@
list.setPadding(0, paddingTop, 0, paddingBottom);
return view;
}
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (preference == mPrivacyGuardDefault) {
- boolean value = (Boolean) newValue;
- CMSettings.Secure.putInt(getActivity().getContentResolver(),
- CMSettings.Secure.PRIVACY_GUARD_DEFAULT, value ? 1 : 0);
- return true;
- }
- return false;
- }
}
diff --git a/src/org/cyanogenmod/cmparts/profiles/ProfilesSettings.java b/src/org/cyanogenmod/cmparts/profiles/ProfilesSettings.java
index 29ea35b..bd502d1 100644
--- a/src/org/cyanogenmod/cmparts/profiles/ProfilesSettings.java
+++ b/src/org/cyanogenmod/cmparts/profiles/ProfilesSettings.java
@@ -243,6 +243,8 @@
} else {
refreshList();
}
+
+ onRefresh(activity, null);
}
@Override
@@ -300,4 +302,20 @@
ex.printStackTrace();
}
}
+
+ public static final SummaryProvider SUMMARY_PROVIDER = new SummaryProvider() {
+ @Override
+ public String getSummary(Context context, String key) {
+ ProfileManager pm = ProfileManager.getInstance(context);
+ if (!pm.isProfilesEnabled()) {
+ return context.getString(R.string.profile_settings_summary_off);
+ }
+
+ Profile p = pm.getActiveProfile();
+ if (p != null) {
+ return p.getName();
+ }
+ return null;
+ }
+ };
}