Merge "New Settings preference for One Handed mode"
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class OneHandedAppTapsExitPreferenceControllerTest {
|
||||
|
||||
private static final String KEY = "gesture_app_taps_to_exit";
|
||||
|
||||
private Context mContext;
|
||||
private SwitchPreference mSwitchPreference;
|
||||
|
||||
private OneHandedAppTapsExitPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new OneHandedAppTapsExitPreferenceController(mContext, KEY);
|
||||
mSwitchPreference = new SwitchPreference(mContext);
|
||||
mSwitchPreference.setKey(KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_setBoolean_checkIsTrueOrFalse() {
|
||||
mController.setChecked(false);
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
|
||||
mController.setChecked(true);
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_enabledOneHanded_shouldAvailable() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(TogglePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_disabledOneHanded_shouldUnavailable() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(TogglePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_enableOneHanded_switchShouldEnabled() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, true);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
assertThat(mSwitchPreference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_disableOneHanded_switchShouldDisabled() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, false);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
assertThat(mSwitchPreference.isEnabled()).isFalse();
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
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;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class OneHandedEnablePreferenceControllerTest {
|
||||
|
||||
private static final String KEY = "gesture_one_handed_mode_enabled";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private OneHandedEnablePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new OneHandedEnablePreferenceController(mContext, KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_setBoolean_checkIsTrueOrFalse() {
|
||||
mController.setChecked(false);
|
||||
assertThat(OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)).isFalse();
|
||||
|
||||
mController.setChecked(true);
|
||||
assertThat(OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_byDefault_shouldAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class OneHandedSettingsTest {
|
||||
|
||||
private OneHandedSettings mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mSettings = new OneHandedSettings();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_shouldIndexResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
OneHandedSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
|
||||
RuntimeEnvironment.application, true /* enabled */);
|
||||
|
||||
assertThat(indexRes).isNotNull();
|
||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
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.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class OneHandedSettingsUtilsTest {
|
||||
|
||||
private static final int TIMEOUT_INDEX_NEVER = 0;
|
||||
private static final int TIMEOUT_INDEX_SHORT = 1;
|
||||
private static final int TIMEOUT_INDEX_MEDIUM = 2;
|
||||
private static final int TIMEOUT_INDEX_LONG = 3;
|
||||
|
||||
private Context mContext;
|
||||
private String[] mConfigTimeout;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mConfigTimeout = mContext.getResources().getStringArray(R.array.one_handed_timeout_values);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingsOneHandedModeEnabled_setEnable_shouldReturnEnabled() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ONE_HANDED_MODE_ENABLED, 0)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingsOneHandedModeEnabled_setDisable_shouldReturnDisabled() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ONE_HANDED_MODE_ENABLED, 0)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingsTapsAppToExitEnabled_setEnable_shouldReturnEnabled() {
|
||||
OneHandedSettingsUtils.setSettingsTapsAppToExit(mContext, true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.TAPS_APP_TO_EXIT, 1)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingsTapsAppToExitEnabled_setDisable_shouldReturnDisabled() {
|
||||
OneHandedSettingsUtils.setSettingsTapsAppToExit(mContext, false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.TAPS_APP_TO_EXIT, 1)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingsTimeout_setNever_shouldReturnNeverValue() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeTimeout(mContext,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.NEVER.getValue());
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ONE_HANDED_MODE_TIMEOUT,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.NEVER.getValue()))
|
||||
.isEqualTo(Integer.parseInt(mConfigTimeout[TIMEOUT_INDEX_NEVER]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingsTimeout_setShort_shouldReturnShortValue() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeTimeout(mContext,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.SHORT.getValue());
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ONE_HANDED_MODE_TIMEOUT,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.SHORT.getValue()))
|
||||
.isEqualTo(Integer.parseInt(mConfigTimeout[TIMEOUT_INDEX_SHORT]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingsTimeout_setMedium_shouldReturnMediumValue() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeTimeout(mContext,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.MEDIUM.getValue());
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ONE_HANDED_MODE_TIMEOUT,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.MEDIUM.getValue()))
|
||||
.isEqualTo(Integer.parseInt(mConfigTimeout[TIMEOUT_INDEX_MEDIUM]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSettingsTimeout_setLong_shouldReturnLongValue() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeTimeout(mContext,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.LONG.getValue());
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ONE_HANDED_MODE_TIMEOUT,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.LONG.getValue()))
|
||||
.isEqualTo(Integer.parseInt(mConfigTimeout[TIMEOUT_INDEX_LONG]));
|
||||
}
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class OneHandedTimeoutPreferenceControllerTest {
|
||||
|
||||
private static final String KEY = "one_handed_timeout_preference";
|
||||
|
||||
private Context mContext;
|
||||
private OneHandedTimeoutPreferenceController mController;
|
||||
private ListPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new OneHandedTimeoutPreferenceController(mContext, KEY);
|
||||
mPreference = new ListPreference(mContext);
|
||||
mPreference.setKey(KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_enabledOneHanded_shouldAvailable() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_disableOneHanded_shouldUnavailable() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_enableOneHanded_switchShouldEnabled() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_disableOneHanded_switchShouldDisabled() {
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, false);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_setTimeout_shouldReturnSummary() {
|
||||
final String[] timeoutTitles = mContext.getResources().getStringArray(
|
||||
R.array.one_handed_timeout_title);
|
||||
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeTimeout(mContext,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.NEVER.getValue());
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
timeoutTitles[OneHandedSettingsUtils.OneHandedTimeout.NEVER.ordinal()]);
|
||||
|
||||
OneHandedSettingsUtils.setSettingsOneHandedModeTimeout(mContext,
|
||||
OneHandedSettingsUtils.OneHandedTimeout.SHORT.getValue());
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
timeoutTitles[OneHandedSettingsUtils.OneHandedTimeout.SHORT.ordinal()]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user