OSDN Git Service

Clean up DND slice in search.
authorFan Zhang <zhfan@google.com>
Fri, 12 Apr 2019 22:31:25 +0000 (15:31 -0700)
committerFan Zhang <zhfan@google.com>
Fri, 12 Apr 2019 23:11:31 +0000 (16:11 -0700)
- Remove the controller in SoundSettings, just use the common one.
- Update a bunch of IDs so ZenModeSliceBuilder maps to the toggle
  button in zen_mode_settings.xml

This is needed so the slice intent (left target when shown in search)
is the same as what we index from search side. Previously the search
indexer is finding zen_mode from sound page but the slice itself is
reporting a deep link into zenModeSettings page.

Fixes: 130437726
Test: robotest

Change-Id: Ic41d2d93afa1f748e3282e23010199a0fa078645

res/xml/sound_settings.xml
res/xml/zen_mode_settings.xml
src/com/android/settings/notification/ZenModeButtonPreferenceController.java
src/com/android/settings/notification/ZenModeSettings.java
src/com/android/settings/notification/ZenModeSliceBuilder.java
src/com/android/settings/notification/ZenModeSoundSettingsPreferenceController.java [deleted file]
src/com/android/settings/slices/CustomSliceRegistry.java
tests/robotests/src/com/android/settings/notification/ZenModeSoundSettingsPreferenceControllerTest.java [deleted file]

index e610df2..d99cc00 100644 (file)
         settings:useAdminDisabledSummary="true"
         settings:keywords="@string/keywords_sounds_and_notifications_interruptions"
         settings:allowDividerAbove="true"
-        settings:controller="com.android.settings.notification.ZenModeSoundSettingsPreferenceController"/>
+        settings:controller="com.android.settings.notification.ZenModePreferenceController"/>
 
     <Preference
         android:key="gesture_prevent_ringing_sound"
index 832150a..320a37c 100644 (file)
@@ -20,7 +20,7 @@
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:key="zen_mode_settings"
     android:title="@string/zen_mode_settings_title"
-    settings:keywords="@string/keywords_zen_mode_settings">
+    settings:searchable="false">
 
     <PreferenceCategory
         android:key="zen_mode_settings_category_behavior"
 
     <!-- Turn on DND button -->
     <com.android.settingslib.widget.LayoutPreference
-        android:key="zen_mode_settings_button_container"
+        android:key="zen_mode_toggle"
+        android:title="@string/zen_mode_settings_title"
         android:selectable="false"
         android:layout="@layout/zen_mode_settings_button"
         settings:allowDividerAbove="true"
-        settings:allowDividerBelow="true"/>
+        settings:allowDividerBelow="true"
+        settings:keywords="@string/keywords_zen_mode_settings"/>
 
     <!-- Footer that shows if user is put into alarms only or total silence mode by an app -->
     <com.android.settingslib.widget.FooterPreference/>
index 4829a28..3a9bcb7 100644 (file)
@@ -33,11 +33,12 @@ import com.android.settingslib.widget.LayoutPreference;
 public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController
         implements PreferenceControllerMixin {
 
+    public static final String KEY = "zen_mode_toggle";
+
     private static final String TAG = "EnableZenModeButton";
-    protected static final String KEY = "zen_mode_settings_button_container";
+    private final FragmentManager mFragment;
     private Button mZenButtonOn;
     private Button mZenButtonOff;
-    private FragmentManager mFragment;
 
     public ZenModeButtonPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
             fragment) {
@@ -60,13 +61,13 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference
         super.updateState(preference);
 
         if (null == mZenButtonOn) {
-            mZenButtonOn = (Button) ((LayoutPreference) preference)
+            mZenButtonOn = ((LayoutPreference) preference)
                     .findViewById(R.id.zen_mode_settings_turn_on_button);
             updateZenButtonOnClickListener();
         }
 
         if (null == mZenButtonOff) {
-            mZenButtonOff = (Button) ((LayoutPreference) preference)
+            mZenButtonOff = ((LayoutPreference) preference)
                     .findViewById(R.id.zen_mode_settings_turn_off_button);
             mZenButtonOff.setOnClickListener(v -> {
                 mMetricsFeatureProvider.action(mContext,
index 9360a33..f35c649 100644 (file)
@@ -328,7 +328,6 @@ public class ZenModeSettings extends ZenModeSettingsBase {
                 public List<String> getNonIndexableKeys(Context context) {
                     List<String> keys = super.getNonIndexableKeys(context);
                     keys.add(ZenModeDurationPreferenceController.KEY);
-                    keys.add(ZenModeButtonPreferenceController.KEY);
                     return keys;
                 }
 
index e8b181a..9e88cea 100644 (file)
@@ -18,8 +18,6 @@ package com.android.settings.notification;
 
 import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
 
-import static com.android.settings.notification.ZenModeSoundSettingsPreferenceController.ZEN_MODE_KEY;
-
 import android.annotation.ColorInt;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
@@ -47,6 +45,8 @@ public class ZenModeSliceBuilder {
 
     private static final String TAG = "ZenModeSliceBuilder";
 
+    private static final String ZEN_MODE_SLICE_KEY = ZenModeButtonPreferenceController.KEY;
+
     /**
      * Action notifying a change on the Zen Mode Slice.
      */
@@ -78,7 +78,8 @@ public class ZenModeSliceBuilder {
         final PendingIntent primaryAction = getPrimaryAction(context);
         final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction,
                 (IconCompat) null /* icon */, ListBuilder.ICON_IMAGE, title);
-        final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction, null /* actionTitle */,
+        final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction,
+                null /* actionTitle */,
                 isZenModeEnabled);
 
         return new ListBuilder(context, CustomSliceRegistry.ZEN_MODE_SLICE_URI,
@@ -110,10 +111,10 @@ public class ZenModeSliceBuilder {
     }
 
     public static Intent getIntent(Context context) {
-        final Uri contentUri = new Uri.Builder().appendPath(ZEN_MODE_KEY).build();
+        final Uri contentUri = new Uri.Builder().appendPath(ZEN_MODE_SLICE_KEY).build();
         final String screenTitle = context.getText(R.string.zen_mode_settings_title).toString();
         return SliceBuilderUtils.buildSearchResultPageIntent(context,
-                ZenModeSettings.class.getName(), ZEN_MODE_KEY, screenTitle,
+                ZenModeSettings.class.getName(), ZEN_MODE_SLICE_KEY, screenTitle,
                 SettingsEnums.NOTIFICATION_ZEN_MODE)
                 .setClassName(context.getPackageName(), SubSettings.class.getName())
                 .setData(contentUri);
diff --git a/src/com/android/settings/notification/ZenModeSoundSettingsPreferenceController.java b/src/com/android/settings/notification/ZenModeSoundSettingsPreferenceController.java
deleted file mode 100644 (file)
index 842c49d..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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;
-
-public class ZenModeSoundSettingsPreferenceController extends ZenModePreferenceController {
-
-    public static final String ZEN_MODE_KEY = "zen_mode";
-
-    public ZenModeSoundSettingsPreferenceController(Context context, String key) {
-        super(context, key);
-    }
-
-    @Override
-    public int getAvailabilityStatus() {
-        return AVAILABLE;
-    }
-}
index e400815..dc3324b 100644 (file)
@@ -19,8 +19,6 @@ package com.android.settings.slices;
 import static android.provider.SettingsSlicesContract.KEY_LOCATION;
 import static android.provider.SettingsSlicesContract.KEY_WIFI;
 
-import static com.android.settings.notification.ZenModeSoundSettingsPreferenceController.ZEN_MODE_KEY;
-
 import android.content.ContentResolver;
 import android.net.Uri;
 import android.provider.SettingsSlicesContract;
@@ -43,6 +41,7 @@ import com.android.settings.location.LocationSlice;
 import com.android.settings.media.MediaOutputIndicatorSlice;
 import com.android.settings.media.MediaOutputSlice;
 import com.android.settings.network.telephony.MobileDataSlice;
+import com.android.settings.notification.ZenModeButtonPreferenceController;
 import com.android.settings.wifi.calling.WifiCallingSliceHelper;
 import com.android.settings.wifi.slice.ContextualWifiSlice;
 import com.android.settings.wifi.slice.WifiSlice;
@@ -298,7 +297,7 @@ public class CustomSliceRegistry {
             .scheme(ContentResolver.SCHEME_CONTENT)
             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
-            .appendPath(ZEN_MODE_KEY)
+            .appendPath(ZenModeButtonPreferenceController.KEY)
             .build();
 
     /**
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSoundSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSoundSettingsPreferenceControllerTest.java
deleted file mode 100644 (file)
index a08a4d7..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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 com.android.settings.core.BasePreferenceController.AVAILABLE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(RobolectricTestRunner.class)
-public class ZenModeSoundSettingsPreferenceControllerTest {
-
-    private Context mContext;
-    private ZenModeSoundSettingsPreferenceController mController;
-    private static final String KEY_ZEN_MODE = "zen_mode";
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        mContext = RuntimeEnvironment.application;
-        mController = new ZenModeSoundSettingsPreferenceController(mContext, KEY_ZEN_MODE);
-    }
-
-    @Test
-    public void getAvailabilityStatus_available() {
-        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
-    }
-}