Tweak search result for adaptive brightness

- Create a new controller for auto brightness in
auto_brightness_detail.xml.
- We only show slice version for search result.
- Change slice summary for adaptive brightness.

Test: visual
Fixes: 130651278
Change-Id: If9b71735bbb2a0ee22676d9dfedab2cf9e778493
This commit is contained in:
tmfang
2019-04-18 16:53:59 +08:00
parent f263f489e2
commit e4753a3632
7 changed files with 131 additions and 22 deletions

View File

@@ -0,0 +1,69 @@
/*
* 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.display;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import com.android.settings.testutils.shadow.SettingsShadowResources;
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;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {SettingsShadowResources.class})
public class AutoBrightnessDetailPreferenceControllerTest {
private AutoBrightnessDetailPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new AutoBrightnessDetailPreferenceController(
RuntimeEnvironment.application, "test_key");
}
@Test
public void isSliceable_returnTrue() {
mController.onPreferenceChange(null, true);
assertThat(mController.isSliceable()).isTrue();
}
@Test
public void getAvailabilityStatus_configTrueSet_shouldReturnAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_automatic_brightness_available, true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void getAvailabilityStatus_configFalseSet_shouldReturnUnsupportedOnDevice() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_automatic_brightness_available, false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
}

View File

@@ -20,6 +20,9 @@ import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import android.content.ContentResolver;
@@ -27,6 +30,7 @@ import android.content.Context;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.Before;
import org.junit.Test;
@@ -34,8 +38,10 @@ import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {SettingsShadowResources.class})
public class AutoBrightnessPreferenceControllerTest {
private static final String PREFERENCE_KEY = "auto_brightness";
@@ -115,17 +121,18 @@ public class AutoBrightnessPreferenceControllerTest {
}
@Test
public void isSliceable_correctKey_returnsTrue() {
final AutoBrightnessPreferenceController controller =
new AutoBrightnessPreferenceController(mContext,
"auto_brightness");
assertThat(controller.isSliceable()).isTrue();
public void getAvailabilityStatus_configTrueSet_shouldReturnAvailableUnsearchable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_automatic_brightness_available, true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
@Test
public void isSliceable_incorrectKey_returnsFalse() {
final AutoBrightnessPreferenceController controller =
new AutoBrightnessPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
public void getAvailabilityStatus_configFalseSet_shouldReturnUnsupportedOnDevice() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_automatic_brightness_available, false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
}