Merge "Add pref for notification swipe direction"
This commit is contained in:
committed by
Android (Google) Code Review
commit
8febd82f34
@@ -1098,6 +1098,17 @@
|
|||||||
<item>zen_mode_from_none</item>
|
<item>zen_mode_from_none</item>
|
||||||
</string-array>
|
</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">
|
<string-array name="wifi_metered_entries">
|
||||||
<item>Detect automatically</item>
|
<item>Detect automatically</item>
|
||||||
<item>Treat as metered</item>
|
<item>Treat as metered</item>
|
||||||
|
@@ -7634,6 +7634,15 @@
|
|||||||
<!-- Configure Notifications: Title for the notification bubbles option. [CHAR LIMIT=60] -->
|
<!-- Configure Notifications: Title for the notification bubbles option. [CHAR LIMIT=60] -->
|
||||||
<string name="notification_bubbles_title">Allow notification bubbles</string>
|
<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] -->
|
<!-- Configure Notifications: Title for the pulse notification light option. [CHAR LIMIT=30] -->
|
||||||
<string name="notification_pulse_title">Blink light</string>
|
<string name="notification_pulse_title">Blink light</string>
|
||||||
|
|
||||||
|
@@ -19,58 +19,71 @@
|
|||||||
android:title="@string/configure_notification_settings"
|
android:title="@string/configure_notification_settings"
|
||||||
android:key="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
|
<SwitchPreference
|
||||||
android:key="hide_silent_icons"
|
android:key="hide_silent_icons"
|
||||||
android:title="@string/hide_silent_icons_title"
|
android:title="@string/hide_silent_icons_title"
|
||||||
android:summary="@string/hide_silent_icons_summary"
|
android:summary="@string/hide_silent_icons_summary"
|
||||||
settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController" />
|
settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController" />
|
||||||
|
|
||||||
<!-- Notification badging -->
|
<PreferenceCategory
|
||||||
<SwitchPreference
|
android:key="configure_notifications_advanced"
|
||||||
android:key="notification_badging"
|
android:order="15"
|
||||||
android:title="@string/notification_badging_title"
|
settings:initialExpandedChildrenCount="0">
|
||||||
settings:controller="com.android.settings.notification.BadgingNotificationPreferenceController"/>
|
|
||||||
|
|
||||||
<!-- Notification bubbles -->
|
<com.android.settings.RestrictedListPreference
|
||||||
<SwitchPreference
|
android:key="swipe"
|
||||||
android:key="notification_bubbles"
|
android:title="@string/swipe_direction_title"
|
||||||
android:title="@string/notification_bubbles_title"
|
android:entries="@array/swipe_direction_titles"
|
||||||
settings:controller="com.android.settings.notification.BubbleNotificationPreferenceController"/>
|
android:entryValues="@array/swipe_direction_values"
|
||||||
|
settings:controller="com.android.settings.notification.SwipeDirectionPreferenceController"/>
|
||||||
|
|
||||||
<!-- Pulse notification light -->
|
<!-- When device is locked -->
|
||||||
<SwitchPreference
|
<com.android.settings.RestrictedListPreference
|
||||||
android:key="notification_pulse"
|
android:key="lock_screen_notifications"
|
||||||
android:title="@string/notification_pulse_title"
|
android:title="@string/lock_screen_notifications_title"
|
||||||
settings:controller="com.android.settings.notification.PulseNotificationPreferenceController"/>
|
android:summary="@string/summary_placeholder"
|
||||||
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<!-- Default notification ringtone -->
|
<!-- Notification badging -->
|
||||||
<com.android.settings.DefaultRingtonePreference
|
<SwitchPreference
|
||||||
android:key="notification_default_ringtone"
|
android:key="notification_badging"
|
||||||
android:title="@string/notification_ringtone_title"
|
android:title="@string/notification_badging_title"
|
||||||
android:dialogTitle="@string/notification_ringtone_title"
|
settings:controller="com.android.settings.notification.BadgingNotificationPreferenceController"/>
|
||||||
android:summary="@string/summary_placeholder"
|
|
||||||
android:ringtoneType="notification"/>
|
|
||||||
|
|
||||||
<Preference
|
<!-- Notification bubbles -->
|
||||||
android:key="gesture_swipe_down_fingerprint_notifications"
|
<SwitchPreference
|
||||||
android:title="@string/fingerprint_swipe_for_notifications_title"
|
android:key="notification_bubbles"
|
||||||
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings"
|
android:title="@string/notification_bubbles_title"
|
||||||
settings:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController"/>
|
settings:controller="com.android.settings.notification.BubbleNotificationPreferenceController"/>
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<!-- Pulse notification light -->
|
||||||
android:key="zen_mode_notifications"
|
<SwitchPreference
|
||||||
android:title="@string/zen_mode_settings_title"
|
android:key="notification_pulse"
|
||||||
settings:useAdminDisabledSummary="true"
|
android:title="@string/notification_pulse_title"
|
||||||
android:fragment="com.android.settings.notification.ZenModeSettings"
|
settings:controller="com.android.settings.notification.PulseNotificationPreferenceController"/>
|
||||||
settings:controller="com.android.settings.notification.ZenModePreferenceController"
|
|
||||||
settings:allowDividerAbove="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"/>
|
||||||
|
|
||||||
|
<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 -->
|
<!-- Empty category to draw divider -->
|
||||||
<PreferenceCategory
|
<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