Add pref for notification swipe direction
And move that and other settings under an 'advanced' category Test: robotests Fixes: 124099692 Change-Id: I89df276a8bc1cd56ce8530239ca02b2c4b43fa65
This commit is contained in:
@@ -1098,6 +1098,17 @@
|
||||
<item>zen_mode_from_none</item>
|
||||
</string-array>
|
||||
|
||||
<!--String arrays for notification swipe direction -->
|
||||
<string-array name="swipe_direction_titles">
|
||||
<item>@string/swipe_direction_rtl</item>
|
||||
<item>@string/swipe_direction_ltr</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="swipe_direction_values">
|
||||
<item>1</item>
|
||||
<item>0</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="wifi_metered_entries">
|
||||
<item>Detect automatically</item>
|
||||
<item>Treat as metered</item>
|
||||
|
@@ -7617,6 +7617,15 @@
|
||||
<!-- Configure Notifications: Title for the notification bubbles option. [CHAR LIMIT=60] -->
|
||||
<string name="notification_bubbles_title">Allow notification bubbles</string>
|
||||
|
||||
<!-- Configure notifications: title for swipe direction [CHAR LIMIT=60] -->
|
||||
<string name="swipe_direction_title">Swipe actions</string>
|
||||
|
||||
<!-- Configure notifications: value for swipe direction [CHAR LIMIT=100] -->
|
||||
<string name="swipe_direction_ltr">Swipe right to dismiss, left to show menu</string>
|
||||
|
||||
<!-- Configure notifications: value for swipe direction [CHAR LIMIT=100] -->
|
||||
<string name="swipe_direction_rtl">Swipe left to dismiss, right to show menu</string>
|
||||
|
||||
<!-- Configure Notifications: Title for the pulse notification light option. [CHAR LIMIT=30] -->
|
||||
<string name="notification_pulse_title">Blink light</string>
|
||||
|
||||
|
@@ -19,58 +19,71 @@
|
||||
android:title="@string/configure_notification_settings"
|
||||
android:key="configure_notification_settings">
|
||||
|
||||
<!-- When device is locked -->
|
||||
<com.android.settings.RestrictedListPreference
|
||||
android:key="lock_screen_notifications"
|
||||
android:title="@string/lock_screen_notifications_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:searchable="false"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:key="hide_silent_icons"
|
||||
android:title="@string/hide_silent_icons_title"
|
||||
android:summary="@string/hide_silent_icons_summary"
|
||||
settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController" />
|
||||
|
||||
<!-- Notification badging -->
|
||||
<SwitchPreference
|
||||
android:key="notification_badging"
|
||||
android:title="@string/notification_badging_title"
|
||||
settings:controller="com.android.settings.notification.BadgingNotificationPreferenceController"/>
|
||||
<PreferenceCategory
|
||||
android:key="configure_notifications_advanced"
|
||||
android:order="15"
|
||||
settings:initialExpandedChildrenCount="0">
|
||||
|
||||
<!-- Notification bubbles -->
|
||||
<SwitchPreference
|
||||
android:key="notification_bubbles"
|
||||
android:title="@string/notification_bubbles_title"
|
||||
settings:controller="com.android.settings.notification.BubbleNotificationPreferenceController"/>
|
||||
<com.android.settings.RestrictedListPreference
|
||||
android:key="swipe"
|
||||
android:title="@string/swipe_direction_title"
|
||||
android:entries="@array/swipe_direction_titles"
|
||||
android:entryValues="@array/swipe_direction_values"
|
||||
settings:controller="com.android.settings.notification.SwipeDirectionPreferenceController"/>
|
||||
|
||||
<!-- Pulse notification light -->
|
||||
<SwitchPreference
|
||||
android:key="notification_pulse"
|
||||
android:title="@string/notification_pulse_title"
|
||||
settings:controller="com.android.settings.notification.PulseNotificationPreferenceController"/>
|
||||
<!-- When device is locked -->
|
||||
<com.android.settings.RestrictedListPreference
|
||||
android:key="lock_screen_notifications"
|
||||
android:title="@string/lock_screen_notifications_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:searchable="false"/>
|
||||
|
||||
<!-- Default notification ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
android:key="notification_default_ringtone"
|
||||
android:title="@string/notification_ringtone_title"
|
||||
android:dialogTitle="@string/notification_ringtone_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:ringtoneType="notification"/>
|
||||
<!-- Notification badging -->
|
||||
<SwitchPreference
|
||||
android:key="notification_badging"
|
||||
android:title="@string/notification_badging_title"
|
||||
settings:controller="com.android.settings.notification.BadgingNotificationPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="gesture_swipe_down_fingerprint_notifications"
|
||||
android:title="@string/fingerprint_swipe_for_notifications_title"
|
||||
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings"
|
||||
settings:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController"/>
|
||||
<!-- Notification bubbles -->
|
||||
<SwitchPreference
|
||||
android:key="notification_bubbles"
|
||||
android:title="@string/notification_bubbles_title"
|
||||
settings:controller="com.android.settings.notification.BubbleNotificationPreferenceController"/>
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="zen_mode_notifications"
|
||||
android:title="@string/zen_mode_settings_title"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
android:fragment="com.android.settings.notification.ZenModeSettings"
|
||||
settings:controller="com.android.settings.notification.ZenModePreferenceController"
|
||||
settings:allowDividerAbove="false"/>
|
||||
<!-- Pulse notification light -->
|
||||
<SwitchPreference
|
||||
android:key="notification_pulse"
|
||||
android:title="@string/notification_pulse_title"
|
||||
settings:controller="com.android.settings.notification.PulseNotificationPreferenceController"/>
|
||||
|
||||
<!-- Default notification ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
android:key="notification_default_ringtone"
|
||||
android:title="@string/notification_ringtone_title"
|
||||
android:dialogTitle="@string/notification_ringtone_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:ringtoneType="notification"/>
|
||||
|
||||
<Preference
|
||||
android:key="gesture_swipe_down_fingerprint_notifications"
|
||||
android:title="@string/fingerprint_swipe_for_notifications_title"
|
||||
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings"
|
||||
settings:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController"/>
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="zen_mode_notifications"
|
||||
android:title="@string/zen_mode_settings_title"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
android:fragment="com.android.settings.notification.ZenModeSettings"
|
||||
settings:controller="com.android.settings.notification.ZenModePreferenceController"
|
||||
settings:allowDividerAbove="false"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<!-- Empty category to draw divider -->
|
||||
<PreferenceCategory
|
||||
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
public class SwipeDirectionPreferenceController extends BasePreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
public SwipeDirectionPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference pref) {
|
||||
((ListPreference) pref).setValue(String.valueOf(Settings.Secure.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.NOTIFICATION_DISMISS_RTL,
|
||||
1)));
|
||||
super.updateState(pref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.NOTIFICATION_DISMISS_RTL,
|
||||
Integer.valueOf((String) newValue));
|
||||
refreshSummary(preference);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
int value = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.NOTIFICATION_DISMISS_RTL, 1);
|
||||
String[] values = mContext.getResources().getStringArray(R.array.swipe_direction_values);
|
||||
String[] titles = mContext.getResources().getStringArray(R.array.swipe_direction_titles);
|
||||
if (values == null) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int valueAt = Integer.parseInt(values[i]);
|
||||
if (value == valueAt) {
|
||||
return titles[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import static android.provider.Settings.Secure.NOTIFICATION_DISMISS_RTL;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SwipeDirectionPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private SwipeDirectionPreferenceController mController;
|
||||
private ListPreference mPreference;
|
||||
|
||||
private static final String KEY = "swipe";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new SwipeDirectionPreferenceController(mContext, KEY);
|
||||
mPreference = new ListPreference(RuntimeEnvironment.application);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_shouldDisplay() {
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_SettingIsOn() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_DISMISS_RTL,
|
||||
1);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getValue()).isEqualTo("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_SettingIsOff() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_DISMISS_RTL,
|
||||
0);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getValue()).isEqualTo("0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_LTR() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_DISMISS_RTL, 1);
|
||||
|
||||
mController.onPreferenceChange(mPreference, "0");
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_DISMISS_RTL, 1)).isEqualTo(0);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
mContext.getResources().getStringArray(R.array.swipe_direction_titles)[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_On() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_DISMISS_RTL, 0);
|
||||
|
||||
mController.onPreferenceChange(mPreference, "1");
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_DISMISS_RTL, 0)).isEqualTo(1);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
mContext.getResources().getStringArray(R.array.swipe_direction_titles)[0]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user