Allow importance to be reset.
Change-Id: Ib2c2289631dfe4eb2aa09baf84d401eb2000c0d9
This commit is contained in:
@@ -23,35 +23,11 @@
|
|||||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:clickable="false"
|
android:clickable="false"
|
||||||
android:focusable="false"
|
android:focusable="false" >
|
||||||
android:paddingTop="8dip"
|
|
||||||
android:paddingBottom="8dip">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@android:id/title"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:ellipsize="marquee"
|
|
||||||
android:fadingEdge="horizontal" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@android:id/summary"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignStart="@android:id/title"
|
|
||||||
android:textAlignment="viewStart"
|
|
||||||
android:textAppearance="@android:style/TextAppearance.Material.Body1"
|
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
|
||||||
android:maxLines="10"
|
|
||||||
android:minLines="2" />
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" >
|
||||||
android:layout_marginTop="6dp">
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/low_importance"
|
android:id="@+id/low_importance"
|
||||||
@@ -82,5 +58,4 @@
|
|||||||
android:tint="@color/importance_icon_tint" />
|
android:tint="@color/importance_icon_tint" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -5839,6 +5839,9 @@
|
|||||||
<!-- [CHAR LIMIT=100] Notification importance slider title -->
|
<!-- [CHAR LIMIT=100] Notification importance slider title -->
|
||||||
<string name="notification_importance_title">Importance</string>
|
<string name="notification_importance_title">Importance</string>
|
||||||
|
|
||||||
|
<!-- [CHAR LIMIT=100] Notification Importance slider: unset importance level description -->
|
||||||
|
<string name="notification_importance_none">Not set</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=100] Notification Importance slider: blocked importance level description -->
|
<!-- [CHAR LIMIT=100] Notification Importance slider: blocked importance level description -->
|
||||||
<string name="notification_importance_blocked">Blocked: Never show these notifications</string>
|
<string name="notification_importance_blocked">Blocked: Never show these notifications</string>
|
||||||
|
|
||||||
@@ -5854,6 +5857,9 @@
|
|||||||
<!-- [CHAR LIMIT=100] Notification Importance slider: max importance level description -->
|
<!-- [CHAR LIMIT=100] Notification Importance slider: max importance level description -->
|
||||||
<string name="notification_importance_max">Urgent: Peek onto the screen and make sound</string>
|
<string name="notification_importance_max">Urgent: Peek onto the screen and make sound</string>
|
||||||
|
|
||||||
|
<!-- [CHAR LIMIT=60] Notification importance reset button -->
|
||||||
|
<string name="importance_reset">Reset</string>
|
||||||
|
|
||||||
<!-- Default Apps > Default notification assistant -->
|
<!-- Default Apps > Default notification assistant -->
|
||||||
<string name="default_notification_assistant">Notification assistant</string>
|
<string name="default_notification_assistant">Notification assistant</string>
|
||||||
|
|
||||||
|
@@ -22,6 +22,47 @@
|
|||||||
<Preference
|
<Preference
|
||||||
android:key="app_settings"
|
android:key="app_settings"
|
||||||
android:title="@string/app_notification_preferences"
|
android:title="@string/app_notification_preferences"
|
||||||
android:persistent="false" />
|
android:order="1" />
|
||||||
|
|
||||||
|
<!-- Apps without topics -->
|
||||||
|
<!-- Importance -->
|
||||||
|
<Preference
|
||||||
|
android:key="importance_title"
|
||||||
|
android:title="@string/notification_importance_title"
|
||||||
|
android:order="2" />
|
||||||
|
<com.android.settings.notification.ImportanceSeekBarPreference
|
||||||
|
android:key="importance"
|
||||||
|
android:order="3"/>
|
||||||
|
|
||||||
|
<com.android.settings.applications.LayoutPreference
|
||||||
|
android:key="importance_reset_button"
|
||||||
|
android:layout="@layout/two_buttons_panel"
|
||||||
|
android:order="4" />
|
||||||
|
|
||||||
|
<!-- Sensitive -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="sensitive"
|
||||||
|
android:title="@string/app_notification_sensitive_title"
|
||||||
|
android:summary="@string/app_notification_sensitive_summary"
|
||||||
|
android:order="5" />
|
||||||
|
|
||||||
|
<!-- Bypass DND -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="bypass_dnd"
|
||||||
|
android:title="@string/app_notification_override_dnd_title"
|
||||||
|
android:summary="@string/app_notification_override_dnd_summary"
|
||||||
|
android:order="6" />
|
||||||
|
|
||||||
|
<!-- Apps with topics -->
|
||||||
|
<!-- Block -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="block"
|
||||||
|
android:title="@string/app_notification_block_title"
|
||||||
|
android:summary="@string/app_notification_block_summary"
|
||||||
|
android:order="7" />
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="categories"
|
||||||
|
android:title="@string/notification_topic_categories"
|
||||||
|
android:order="8" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -19,26 +19,31 @@
|
|||||||
android:key="topic_notification_settings">
|
android:key="topic_notification_settings">
|
||||||
|
|
||||||
<!-- Importance -->
|
<!-- Importance -->
|
||||||
|
<Preference
|
||||||
|
android:key="importance_title"
|
||||||
|
android:title="@string/notification_importance_title"
|
||||||
|
android:order="1" />
|
||||||
<com.android.settings.notification.ImportanceSeekBarPreference
|
<com.android.settings.notification.ImportanceSeekBarPreference
|
||||||
android:key="importance"
|
android:key="importance"
|
||||||
android:title="@string/notification_importance_title"
|
android:order="2" />
|
||||||
android:order="1"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<!-- Bypass DND -->
|
<com.android.settings.applications.LayoutPreference
|
||||||
<SwitchPreference
|
android:key="importance_reset_button"
|
||||||
android:key="bypass_dnd"
|
android:order="3"
|
||||||
android:title="@string/app_notification_override_dnd_title"
|
android:layout="@layout/two_buttons_panel" />
|
||||||
android:summary="@string/app_notification_override_dnd_summary"
|
|
||||||
android:order="2"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<!-- Sensitive -->
|
<!-- Sensitive -->
|
||||||
<SwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:key="sensitive"
|
android:key="sensitive"
|
||||||
android:title="@string/app_notification_sensitive_title"
|
android:title="@string/app_notification_sensitive_title"
|
||||||
android:summary="@string/app_notification_sensitive_summary"
|
android:summary="@string/app_notification_sensitive_summary"
|
||||||
android:order="4"
|
android:order="4" />
|
||||||
android:persistent="false" />
|
|
||||||
|
<!-- Bypass DND -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="bypass_dnd"
|
||||||
|
android:title="@string/app_notification_override_dnd_title"
|
||||||
|
android:summary="@string/app_notification_override_dnd_summary"
|
||||||
|
android:order="5" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -22,8 +22,7 @@ import android.content.pm.ActivityInfo;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService.Ranking;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
||||||
@@ -37,6 +36,7 @@ import com.android.settings.AppHeader;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.applications.AppInfoBase;
|
import com.android.settings.applications.AppInfoBase;
|
||||||
|
import com.android.settings.applications.LayoutPreference;
|
||||||
import com.android.settings.notification.NotificationBackend.AppRow;
|
import com.android.settings.notification.NotificationBackend.AppRow;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
@@ -79,7 +79,16 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.app_notification_settings);
|
addPreferencesFromResource(R.xml.app_notification_settings);
|
||||||
getPreferenceScreen().setOrderingAsAdded(true);
|
mCategories = (PreferenceCategory) findPreference(KEY_CATEGORIES);
|
||||||
|
mBlock = (RestrictedSwitchPreference) findPreference(KEY_BLOCK);
|
||||||
|
mImportance = (ImportanceSeekBarPreference) findPreference(KEY_IMPORTANCE);
|
||||||
|
mImportanceReset = (LayoutPreference) findPreference(KEY_IMPORTANCE_RESET);
|
||||||
|
mImportanceTitle = findPreference(KEY_IMPORTANCE_TITLE);
|
||||||
|
mPriority =
|
||||||
|
(RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BYPASS_DND);
|
||||||
|
mSensitive =
|
||||||
|
(RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_SENSITIVE);
|
||||||
|
|
||||||
mAppRow = mBackend.loadAppRow(mPm, mPkgInfo);
|
mAppRow = mBackend.loadAppRow(mPm, mPkgInfo);
|
||||||
|
|
||||||
// load settings intent
|
// load settings intent
|
||||||
@@ -90,16 +99,13 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
// Add topics
|
// Add topics
|
||||||
List<Notification.Topic> topics = mBackend.getTopics(mPkg, mUid);
|
List<Notification.Topic> topics = mBackend.getTopics(mPkg, mUid);
|
||||||
if (topics.size() <= 1) {
|
if (topics.size() <= 1) {
|
||||||
setupImportancePref(mAppRow, null, mAppRow.appImportance);
|
removeAppPrefs();
|
||||||
setupPriorityPref(null, mAppRow.appBypassDnd);
|
setupImportancePrefs(mAppRow.systemApp, mAppRow.appImportance);
|
||||||
setupSensitivePref(null, mAppRow.appSensitive);
|
setupPriorityPref(mAppRow.appBypassDnd);
|
||||||
|
setupSensitivePref(mAppRow.appSensitive);
|
||||||
} else {
|
} else {
|
||||||
|
removeTopicPrefs();
|
||||||
setupBlockSwitch();
|
setupBlockSwitch();
|
||||||
mCategories = new PreferenceCategory(getPrefContext());
|
|
||||||
mCategories.setKey(KEY_CATEGORIES);
|
|
||||||
mCategories.setTitle(R.string.notification_topic_categories);
|
|
||||||
mCategories.setOrderingAsAdded(true);
|
|
||||||
getPreferenceScreen().addPreference(mCategories);
|
|
||||||
for (Notification.Topic topic : topics) {
|
for (Notification.Topic topic : topics) {
|
||||||
RestrictedPreference topicPreference = new RestrictedPreference(getPrefContext());
|
RestrictedPreference topicPreference = new RestrictedPreference(getPrefContext());
|
||||||
topicPreference.setDisabledByAdmin(
|
topicPreference.setDisabledByAdmin(
|
||||||
@@ -138,22 +144,28 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateDependents(int progress) {
|
protected void updateDependents(int progress) {
|
||||||
updateDependents(progress == NotificationListenerService.Ranking.IMPORTANCE_NONE);
|
updateDependents(progress == Ranking.IMPORTANCE_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeTopicPrefs() {
|
||||||
|
setVisible(mImportance, false);
|
||||||
|
setVisible(mImportanceReset, false);
|
||||||
|
setVisible(mImportanceTitle, false);
|
||||||
|
setVisible(mPriority, false);
|
||||||
|
setVisible(mSensitive, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeAppPrefs() {
|
||||||
|
setVisible(mBlock, false);
|
||||||
|
setVisible(mCategories, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDependents(boolean banned) {
|
private void updateDependents(boolean banned) {
|
||||||
if (mBlock != null) {
|
mBlock.setEnabled(!mAppRow.systemApp);
|
||||||
mBlock.setEnabled(!mAppRow.systemApp);
|
mCategories.setEnabled(!banned);
|
||||||
mBlock.setDisabledByAdmin(
|
|
||||||
RestrictedLockUtils.checkIfApplicationIsSuspended(mContext, mPkg, mUserId));
|
|
||||||
}
|
|
||||||
if (mCategories != null) {
|
|
||||||
setVisible(mCategories, !banned);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupBlockSwitch() {
|
private void setupBlockSwitch() {
|
||||||
mBlock = new RestrictedSwitchPreference(getPrefContext());
|
|
||||||
mBlock.setDisabledByAdmin(
|
mBlock.setDisabledByAdmin(
|
||||||
RestrictedLockUtils.checkIfApplicationIsSuspended(mContext, mPkg, mUserId));
|
RestrictedLockUtils.checkIfApplicationIsSuspended(mContext, mPkg, mUserId));
|
||||||
mBlock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
mBlock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
@@ -170,10 +182,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mBlock.setKey(KEY_BLOCK);
|
|
||||||
mBlock.setTitle(R.string.app_notification_block_title);
|
|
||||||
mBlock.setSummary(R.string.app_notification_block_summary);
|
|
||||||
getPreferenceScreen().addPreference(mBlock);
|
|
||||||
mBlock.setChecked(mAppRow.banned);
|
mBlock.setChecked(mAppRow.banned);
|
||||||
updateDependents(mAppRow.banned);
|
updateDependents(mAppRow.banned);
|
||||||
}
|
}
|
||||||
|
@@ -20,12 +20,10 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SeekBarPreference;
|
import com.android.settings.SeekBarPreference;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.service.notification.NotificationListenerService;
|
|
||||||
import android.support.v7.preference.PreferenceViewHolder;
|
import android.support.v7.preference.PreferenceViewHolder;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A slider preference that controls notification importance.
|
* A slider preference that controls notification importance.
|
||||||
@@ -35,8 +33,6 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
|||||||
private static final String TAG = "ImportanceSeekBarPref";
|
private static final String TAG = "ImportanceSeekBarPref";
|
||||||
|
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
private TextView mSummaryTextView;
|
|
||||||
private String mSummary;
|
|
||||||
private int mMinProgress;
|
private int mMinProgress;
|
||||||
private boolean mSystemApp;
|
private boolean mSystemApp;
|
||||||
|
|
||||||
@@ -64,6 +60,7 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
|||||||
|
|
||||||
public void setMinimumProgress(int minProgress) {
|
public void setMinimumProgress(int minProgress) {
|
||||||
mMinProgress = minProgress;
|
mMinProgress = minProgress;
|
||||||
|
notifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSystemApp(boolean systemApp) {
|
public void setSystemApp(boolean systemApp) {
|
||||||
@@ -74,17 +71,12 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||||
super.onBindViewHolder(view);
|
super.onBindViewHolder(view);
|
||||||
mSummaryTextView = (TextView) view.findViewById(com.android.internal.R.id.summary);
|
|
||||||
if (mSystemApp) {
|
if (mSystemApp) {
|
||||||
((ImageView) view.findViewById(R.id.low_importance)).getDrawable().setTint(
|
((ImageView) view.findViewById(R.id.low_importance)).getDrawable().setTint(
|
||||||
getContext().getColor(R.color.importance_disabled_tint));
|
getContext().getColor(R.color.importance_disabled_tint));
|
||||||
}
|
}
|
||||||
}
|
view.setDividerAllowedAbove(false);
|
||||||
|
view.setDividerAllowedBelow(false);
|
||||||
@Override
|
|
||||||
public void setProgress(int progress) {
|
|
||||||
mSummary = getProgressSummary(progress);
|
|
||||||
super.setProgress(progress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -94,37 +86,11 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
|||||||
seekBar.setProgress(mMinProgress);
|
seekBar.setProgress(mMinProgress);
|
||||||
progress = mMinProgress;
|
progress = mMinProgress;
|
||||||
}
|
}
|
||||||
mSummary = getProgressSummary(progress);
|
|
||||||
if (mSummaryTextView != null) {
|
|
||||||
mSummaryTextView.setText(mSummary);
|
|
||||||
}
|
|
||||||
if (fromTouch) {
|
if (fromTouch) {
|
||||||
mCallback.onImportanceChanged(progress);
|
mCallback.onImportanceChanged(progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getSummary() {
|
|
||||||
return mSummary;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getProgressSummary(int progress) {
|
|
||||||
switch (progress) {
|
|
||||||
case NotificationListenerService.Ranking.IMPORTANCE_NONE:
|
|
||||||
return getContext().getString(R.string.notification_importance_blocked);
|
|
||||||
case NotificationListenerService.Ranking.IMPORTANCE_LOW:
|
|
||||||
return getContext().getString(R.string.notification_importance_low);
|
|
||||||
case NotificationListenerService.Ranking.IMPORTANCE_DEFAULT:
|
|
||||||
return getContext().getString(R.string.notification_importance_default);
|
|
||||||
case NotificationListenerService.Ranking.IMPORTANCE_HIGH:
|
|
||||||
return getContext().getString(R.string.notification_importance_high);
|
|
||||||
case NotificationListenerService.Ranking.IMPORTANCE_MAX:
|
|
||||||
return getContext().getString(R.string.notification_importance_max);
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
void onImportanceChanged(int progress);
|
void onImportanceChanged(int progress);
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@ import com.android.settings.SettingsPreferenceFragment;
|
|||||||
import com.android.settings.applications.AppInfoBase;
|
import com.android.settings.applications.AppInfoBase;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
import com.android.settings.applications.LayoutPreference;
|
||||||
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -32,10 +33,11 @@ import android.os.Bundle;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.notification.NotificationListenerService.Ranking;
|
import android.service.notification.NotificationListenerService.Ranking;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
@@ -45,10 +47,13 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
|
||||||
protected static final String ARG_PACKAGE_INFO = "arg_info";
|
protected static final String ARG_PACKAGE_INFO = "arg_info";
|
||||||
|
protected static final String ARG_TOPIC = "arg_topic";
|
||||||
|
|
||||||
protected static final String KEY_BYPASS_DND = "bypass_dnd";
|
protected static final String KEY_BYPASS_DND = "bypass_dnd";
|
||||||
protected static final String KEY_SENSITIVE = "sensitive";
|
protected static final String KEY_SENSITIVE = "sensitive";
|
||||||
protected static final String KEY_IMPORTANCE = "importance";
|
protected static final String KEY_IMPORTANCE = "importance";
|
||||||
|
protected static final String KEY_IMPORTANCE_TITLE = "importance_title";
|
||||||
|
protected static final String KEY_IMPORTANCE_RESET = "importance_reset_button";
|
||||||
|
|
||||||
protected PackageManager mPm;
|
protected PackageManager mPm;
|
||||||
protected final NotificationBackend mBackend = new NotificationBackend();
|
protected final NotificationBackend mBackend = new NotificationBackend();
|
||||||
@@ -58,7 +63,10 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
protected int mUserId;
|
protected int mUserId;
|
||||||
protected String mPkg;
|
protected String mPkg;
|
||||||
protected PackageInfo mPkgInfo;
|
protected PackageInfo mPkgInfo;
|
||||||
|
protected Notification.Topic mTopic;
|
||||||
protected ImportanceSeekBarPreference mImportance;
|
protected ImportanceSeekBarPreference mImportance;
|
||||||
|
protected Preference mImportanceTitle;
|
||||||
|
protected LayoutPreference mImportanceReset;
|
||||||
protected RestrictedSwitchPreference mPriority;
|
protected RestrictedSwitchPreference mPriority;
|
||||||
protected RestrictedSwitchPreference mSensitive;
|
protected RestrictedSwitchPreference mSensitive;
|
||||||
|
|
||||||
@@ -114,6 +122,10 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
toastAndFinish();
|
toastAndFinish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Will be null for app wide settings.
|
||||||
|
mTopic = args != null && args.containsKey(ARG_TOPIC)
|
||||||
|
? (Notification.Topic) args.getParcelable(ARG_TOPIC) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -137,70 +149,89 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupImportancePref(final NotificationBackend.AppRow appRow,
|
protected void setupImportancePrefs(boolean isSystemApp, int importance) {
|
||||||
final Notification.Topic topic, int importance) {
|
mImportance.setDisabledByAdmin(
|
||||||
if (mImportance == null) {
|
RestrictedLockUtils.checkIfApplicationIsSuspended(mContext, mPkg, mUserId));
|
||||||
mImportance = new ImportanceSeekBarPreference(getPrefContext());
|
if (importance == Ranking.IMPORTANCE_UNSPECIFIED) {
|
||||||
mImportance.setDisabledByAdmin(
|
mImportance.setVisible(false);
|
||||||
RestrictedLockUtils.checkIfApplicationIsSuspended(mContext, mPkg, mUserId));
|
mImportanceReset.setVisible(false);
|
||||||
mImportance.setTitle(R.string.notification_importance_title);
|
mImportanceTitle.setOnPreferenceClickListener(showEditableImportance);
|
||||||
mImportance.setKey(KEY_IMPORTANCE);
|
} else {
|
||||||
getPreferenceScreen().addPreference(mImportance);
|
mImportanceTitle.setOnPreferenceClickListener(null);
|
||||||
}
|
}
|
||||||
mImportance.setSystemApp(appRow.systemApp);
|
|
||||||
|
mImportanceTitle.setSummary(getProgressSummary(importance));
|
||||||
|
mImportance.setSystemApp(isSystemApp);
|
||||||
mImportance.setMinimumProgress(
|
mImportance.setMinimumProgress(
|
||||||
appRow.systemApp ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_NONE);
|
isSystemApp ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_NONE);
|
||||||
mImportance.setMax(Ranking.IMPORTANCE_MAX);
|
mImportance.setMax(Ranking.IMPORTANCE_MAX);
|
||||||
// TODO: stop defaulting to 'normal' in the UI when there are mocks for this scenario.
|
|
||||||
importance = importance == Ranking.IMPORTANCE_UNSPECIFIED
|
|
||||||
? Ranking.IMPORTANCE_DEFAULT
|
|
||||||
: importance;
|
|
||||||
mImportance.setProgress(importance);
|
mImportance.setProgress(importance);
|
||||||
mImportance.setCallback(new ImportanceSeekBarPreference.Callback() {
|
mImportance.setCallback(new ImportanceSeekBarPreference.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onImportanceChanged(int progress) {
|
public void onImportanceChanged(int progress) {
|
||||||
mBackend.setImportance(appRow.pkg, appRow.uid, topic, progress);
|
mBackend.setImportance(mPkg, mUid, mTopic, progress);
|
||||||
|
mImportanceTitle.setSummary(getProgressSummary(progress));
|
||||||
updateDependents(progress);
|
updateDependents(progress);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Button button = (Button) mImportanceReset.findViewById(R.id.left_button);
|
||||||
|
button.setText(R.string.importance_reset);
|
||||||
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
mBackend.setImportance(mPkg, mUid, mTopic, Ranking.IMPORTANCE_UNSPECIFIED);
|
||||||
|
mImportanceReset.setVisible(false);
|
||||||
|
mImportance.setVisible(false);
|
||||||
|
mImportanceTitle.setOnPreferenceClickListener(showEditableImportance);
|
||||||
|
mImportanceTitle.setSummary(getProgressSummary(Ranking.IMPORTANCE_UNSPECIFIED));
|
||||||
|
updateDependents(Ranking.IMPORTANCE_UNSPECIFIED);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mImportanceReset.findViewById(R.id.right_button).setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupPriorityPref(final Notification.Topic topic, boolean priority) {
|
private String getProgressSummary(int progress) {
|
||||||
if (mPriority == null) {
|
switch (progress) {
|
||||||
mPriority = new RestrictedSwitchPreference(getPrefContext());
|
case Ranking.IMPORTANCE_NONE:
|
||||||
mPriority.setDisabledByAdmin(
|
return mContext.getString(R.string.notification_importance_blocked);
|
||||||
RestrictedLockUtils.checkIfApplicationIsSuspended(mContext, mPkg, mUserId));
|
case Ranking.IMPORTANCE_LOW:
|
||||||
mPriority.setTitle(R.string.app_notification_override_dnd_title);
|
return mContext.getString(R.string.notification_importance_low);
|
||||||
mPriority.setSummary(R.string.app_notification_override_dnd_summary);
|
case Ranking.IMPORTANCE_DEFAULT:
|
||||||
mPriority.setKey(KEY_BYPASS_DND);
|
return mContext.getString(R.string.notification_importance_default);
|
||||||
getPreferenceScreen().addPreference(mPriority);
|
case Ranking.IMPORTANCE_HIGH:
|
||||||
|
return mContext.getString(R.string.notification_importance_high);
|
||||||
|
case Ranking.IMPORTANCE_MAX:
|
||||||
|
return mContext.getString(R.string.notification_importance_max);
|
||||||
|
case Ranking.IMPORTANCE_UNSPECIFIED:
|
||||||
|
return mContext.getString(R.string.notification_importance_none);
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupPriorityPref(boolean priority) {
|
||||||
|
mPriority.setDisabledByAdmin(
|
||||||
|
RestrictedLockUtils.checkIfApplicationIsSuspended(mContext, mPkg, mUserId));
|
||||||
mPriority.setChecked(priority);
|
mPriority.setChecked(priority);
|
||||||
mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean bypassZenMode = (Boolean) newValue;
|
final boolean bypassZenMode = (Boolean) newValue;
|
||||||
return mBackend.setBypassZenMode(mPkgInfo.packageName, mUid, topic, bypassZenMode);
|
return mBackend.setBypassZenMode(mPkgInfo.packageName, mUid, mTopic, bypassZenMode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupSensitivePref(final Notification.Topic topic, boolean sensitive) {
|
protected void setupSensitivePref(boolean sensitive) {
|
||||||
if (mSensitive == null) {
|
mSensitive.setDisabledByAdmin(
|
||||||
mSensitive = new RestrictedSwitchPreference(getPrefContext());
|
RestrictedLockUtils.checkIfApplicationIsSuspended(mContext, mPkg, mUserId));
|
||||||
mSensitive.setDisabledByAdmin(
|
|
||||||
RestrictedLockUtils.checkIfApplicationIsSuspended(mContext, mPkg, mUserId));
|
|
||||||
mSensitive.setTitle(R.string.app_notification_sensitive_title);
|
|
||||||
mSensitive.setSummary(R.string.app_notification_sensitive_summary);
|
|
||||||
mSensitive.setKey(KEY_SENSITIVE);
|
|
||||||
getPreferenceScreen().addPreference(mSensitive);
|
|
||||||
}
|
|
||||||
mSensitive.setChecked(sensitive);
|
mSensitive.setChecked(sensitive);
|
||||||
mSensitive.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
mSensitive.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean sensitive = (Boolean) newValue;
|
final boolean sensitive = (Boolean) newValue;
|
||||||
return mBackend.setSensitive(mPkgInfo.packageName, mUid, topic, sensitive);
|
return mBackend.setSensitive(mPkgInfo.packageName, mUid, mTopic, sensitive);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -239,4 +270,18 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Preference.OnPreferenceClickListener showEditableImportance =
|
||||||
|
new Preference.OnPreferenceClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
mBackend.setImportance(mPkg, mUid, mTopic, Ranking.IMPORTANCE_DEFAULT);
|
||||||
|
mImportance.setProgress(Ranking.IMPORTANCE_DEFAULT);
|
||||||
|
mImportanceTitle.setSummary(getProgressSummary(Ranking.IMPORTANCE_DEFAULT));
|
||||||
|
mImportance.setVisible(true);
|
||||||
|
mImportanceReset.setVisible(true);
|
||||||
|
mImportanceTitle.setOnPreferenceClickListener(null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@@ -20,34 +20,19 @@ import com.android.internal.logging.MetricsProto.MetricsEvent;
|
|||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.AppHeader;
|
import com.android.settings.AppHeader;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.applications.LayoutPreference;
|
||||||
import com.android.settings.applications.AppInfoBase;
|
|
||||||
import com.android.settings.notification.NotificationBackend.TopicRow;
|
import com.android.settings.notification.NotificationBackend.TopicRow;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
import android.app.Notification;
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.notification.NotificationListenerService;
|
|
||||||
import android.service.notification.NotificationListenerService.Ranking;
|
import android.service.notification.NotificationListenerService.Ranking;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
/** These settings are per topic, so should not be returned in global search results. */
|
/** These settings are per topic, so should not be returned in global search results. */
|
||||||
public class TopicNotificationSettings extends NotificationSettingsBase {
|
public class TopicNotificationSettings extends NotificationSettingsBase {
|
||||||
private static final String TAG = "TopicNotiSettings";
|
private static final String TAG = "TopicNotiSettings";
|
||||||
|
|
||||||
protected static final String ARG_TOPIC = "arg_topic";
|
|
||||||
|
|
||||||
private TopicRow mTopicRow;
|
private TopicRow mTopicRow;
|
||||||
private boolean mDndVisualEffectsSuppressed;
|
private boolean mDndVisualEffectsSuppressed;
|
||||||
|
|
||||||
@@ -72,25 +57,23 @@ public class TopicNotificationSettings extends NotificationSettingsBase {
|
|||||||
NotificationManager.from(mContext).getNotificationPolicy();
|
NotificationManager.from(mContext).getNotificationPolicy();
|
||||||
mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
|
mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
|
||||||
|
|
||||||
Bundle args = getArguments();
|
if (mTopic == null) {
|
||||||
final Notification.Topic topic = args != null && args.containsKey(ARG_TOPIC)
|
|
||||||
? (Notification.Topic) args.getParcelable(ARG_TOPIC) : null;
|
|
||||||
if (topic == null) {
|
|
||||||
toastAndFinish();
|
toastAndFinish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.topic_notification_settings);
|
addPreferencesFromResource(R.xml.topic_notification_settings);
|
||||||
mTopicRow = mBackend.loadTopicRow(mPm, mPkgInfo, topic);
|
mTopicRow = mBackend.loadTopicRow(mPm, mPkgInfo, mTopic);
|
||||||
|
|
||||||
mImportance = (ImportanceSeekBarPreference) findPreference(KEY_IMPORTANCE);
|
mImportance = (ImportanceSeekBarPreference) findPreference(KEY_IMPORTANCE);
|
||||||
setupImportancePref(mTopicRow, mTopicRow.topic, mTopicRow.importance);
|
mImportanceReset = (LayoutPreference) findPreference(KEY_IMPORTANCE_RESET);
|
||||||
|
mImportanceTitle = findPreference(KEY_IMPORTANCE_TITLE);
|
||||||
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
||||||
setupPriorityPref(mTopicRow.topic, mTopicRow.priority);
|
|
||||||
|
|
||||||
mSensitive = (RestrictedSwitchPreference) findPreference(KEY_SENSITIVE);
|
mSensitive = (RestrictedSwitchPreference) findPreference(KEY_SENSITIVE);
|
||||||
setupSensitivePref(mTopicRow.topic, mTopicRow.sensitive);
|
|
||||||
|
setupImportancePrefs(mTopicRow.systemApp, mTopicRow.importance);
|
||||||
|
setupPriorityPref(mTopicRow.priority);
|
||||||
|
setupSensitivePref(mTopicRow.sensitive);
|
||||||
|
|
||||||
updateDependents(mTopicRow.importance);
|
updateDependents(mTopicRow.importance);
|
||||||
}
|
}
|
||||||
@@ -102,13 +85,19 @@ public class TopicNotificationSettings extends NotificationSettingsBase {
|
|||||||
final boolean lockscreenNotificationsEnabled = getLockscreenNotificationsEnabled();
|
final boolean lockscreenNotificationsEnabled = getLockscreenNotificationsEnabled();
|
||||||
final boolean allowPrivate = getLockscreenAllowPrivateNotifications();
|
final boolean allowPrivate = getLockscreenAllowPrivateNotifications();
|
||||||
|
|
||||||
|
setVisible(mPriority, checkCanBeVisible(Ranking.IMPORTANCE_DEFAULT, importance)
|
||||||
setVisible(mPriority, importance > NotificationListenerService.Ranking.IMPORTANCE_DEFAULT
|
|
||||||
&& !mDndVisualEffectsSuppressed);
|
&& !mDndVisualEffectsSuppressed);
|
||||||
setVisible(mSensitive, (importance > NotificationListenerService.Ranking.IMPORTANCE_LOW)
|
setVisible(mSensitive, checkCanBeVisible(Ranking.IMPORTANCE_LOW, importance)
|
||||||
&& lockscreenSecure && lockscreenNotificationsEnabled && allowPrivate);
|
&& lockscreenSecure && lockscreenNotificationsEnabled && allowPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean checkCanBeVisible(int minImportanceVisible, int importance) {
|
||||||
|
if (importance == Ranking.IMPORTANCE_UNSPECIFIED) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return importance > minImportanceVisible;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean getLockscreenNotificationsEnabled() {
|
private boolean getLockscreenNotificationsEnabled() {
|
||||||
return Settings.Secure.getInt(getContentResolver(),
|
return Settings.Secure.getInt(getContentResolver(),
|
||||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
|
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
|
||||||
|
Reference in New Issue
Block a user