Merge "Integrate UI with APIs for trackpad settgins."

This commit is contained in:
Daniel Huang
2023-01-12 05:33:48 +00:00
committed by Android (Google) Code Review
16 changed files with 1001 additions and 8 deletions

View File

@@ -24,39 +24,45 @@
android:title="@string/trackpad_go_back_title"
android:summary="@string/trackpad_go_back_summary"
android:icon="@drawable/ic_trackpad_gesture_back"
android:order="10"/>
android:order="10"
settings:controller="com.android.settings.inputmethod.TrackpadGoBackPreferenceController"/>
<SwitchPreference
android:key="gesture_go_home"
android:title="@string/trackpad_go_home_title"
android:summary="@string/trackpad_go_home_summary"
android:icon="@drawable/ic_trackpad_gesture_home"
android:order="20"/>
android:order="20"
settings:controller="com.android.settings.inputmethod.TrackpadGoHomePreferenceController"/>
<SwitchPreference
android:key="gesture_recent_apps"
android:title="@string/trackpad_recent_apps_title"
android:summary="@string/trackpad_recent_apps_summary"
android:icon="@drawable/ic_trackpad_gesture_recent_apps"
android:order="30"/>
android:order="30"
settings:controller="com.android.settings.inputmethod.TrackpadRecentAppsPreferenceController"/>
<SwitchPreference
android:key="gesture_notifications"
android:title="@string/trackpad_notifications_title"
android:summary="@string/trackpad_notifications_summary"
android:icon="@drawable/ic_trackpad_gesture_notifications"
android:order="40"/>
android:order="40"
settings:controller="com.android.settings.inputmethod.TrackpadNotificationsPreferenceController"/>
<SwitchPreference
android:key="gesture_switch_apps"
android:title="@string/trackpad_switch_apps_title"
android:summary="@string/trackpad_switch_apps_summary"
android:icon="@drawable/ic_trackpad_gesture_switch_apps"
android:order="50"/>
android:order="50"
settings:controller="com.android.settings.inputmethod.TrackpadSwitchAppsPreferenceController"/>
<com.android.settingslib.widget.ButtonPreference
android:key="trackpad_touch_gesture_developer_mode"
android:title="@string/trackpad_touch_gesture"
android:icon="@drawable/ic_trackpad_touch_gestures_inverse"
android:order="100"
settings:controller="com.android.settings.inputmethod.TouchGesturesButtonPreferenceController"/>
</PreferenceScreen>

View File

@@ -32,6 +32,7 @@
android:key="trackpad_tap_to_click"
android:title="@string/trackpad_tap_to_click"
android:icon="@drawable/ic_trackpad_tap_to_click"
settings:controller="com.android.settings.inputmethod.TrackpadTapToClickPreferenceController"
android:order="10"/>
<SwitchPreference
@@ -39,6 +40,7 @@
android:title="@string/trackpad_reverse_scrolling_title"
android:summary="@string/trackpad_reverse_scrolling_summary"
android:icon="@drawable/ic_trackpad_reverse_scrolling"
settings:controller="com.android.settings.inputmethod.TrackpadReverseScrollingPreferenceController"
android:order="20"/>
<SwitchPreference
@@ -46,6 +48,7 @@
android:title="@string/trackpad_bottom_right_tap_title"
android:summary="@string/trackpad_bottom_right_tap_summary"
android:icon="@drawable/ic_trackpad_reverse_scrolling"
settings:controller="com.android.settings.inputmethod.TrackpadBottomPreferenceController"
android:order="30"/>
<com.android.settings.widget.SeekBarPreference
@@ -54,9 +57,7 @@
android:icon="@drawable/ic_trackpad_pointer_speed"
android:order="40"
android:selectable="false"
android:max="100"
android:min="0"
android:defaultValue="50"/>
settings:controller="com.android.settings.inputmethod.TrackpadPointerSpeedPreferenceController"/>
<com.android.settingslib.widget.ButtonPreference
android:key="trackpad_touch_gesture"

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2023 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.inputmethod;
import android.content.Context;
import android.hardware.input.InputManager;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class TrackpadBottomPreferenceController extends TogglePreferenceController {
private InputManager mIm;
public TrackpadBottomPreferenceController(Context context, String key) {
super(context, key);
mIm = context.getSystemService(InputManager.class);
}
@Override
public boolean isChecked() {
return mIm.useTouchpadRightClickZone(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
mIm.setTouchpadRightClickZone(mContext, isChecked);
return true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 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.inputmethod;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class TrackpadGoBackPreferenceController extends TogglePreferenceController {
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_BACK_ENABLED;
public TrackpadGoBackPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1) != 0;
}
@Override
public boolean setChecked(boolean isChecked) {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, isChecked ? 1 : 0);
return true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 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.inputmethod;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class TrackpadGoHomePreferenceController extends TogglePreferenceController {
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_HOME_ENABLED;
public TrackpadGoHomePreferenceController(Context context, String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1) != 0;
}
@Override
public boolean setChecked(boolean isChecked) {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, isChecked ? 1 : 0);
return true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 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.inputmethod;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class TrackpadNotificationsPreferenceController extends TogglePreferenceController {
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_NOTIFICATION_ENABLED;
public TrackpadNotificationsPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1) != 0;
}
@Override
public boolean setChecked(boolean isChecked) {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, isChecked ? 1 : 0);
return true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (C) 2023 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.inputmethod;
import android.content.Context;
import android.hardware.input.InputManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.SliderPreferenceController;
import com.android.settings.widget.SeekBarPreference;
public class TrackpadPointerSpeedPreferenceController extends SliderPreferenceController {
private InputManager mIm;
private SeekBarPreference mPreference;
public TrackpadPointerSpeedPreferenceController(Context context, String key) {
super(context, key);
mIm = context.getSystemService(InputManager.class);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
mPreference.setMax(getMax());
mPreference.setMin(getMin());
mPreference.setProgress(getSliderPosition());
updateState(mPreference);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public boolean setSliderPosition(int position) {
if (position < getMin() || position > getMax()) {
return false;
}
mIm.setTouchpadPointerSpeed(mContext, position);
return true;
}
@Override
public int getSliderPosition() {
return mIm.getTouchpadPointerSpeed(mContext);
}
@Override
public int getMin() {
return InputManager.MIN_POINTER_SPEED;
}
@Override
public int getMax() {
return InputManager.MAX_POINTER_SPEED;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 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.inputmethod;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class TrackpadRecentAppsPreferenceController extends TogglePreferenceController {
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_OVERVIEW_ENABLED;
public TrackpadRecentAppsPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1) != 0;
}
@Override
public boolean setChecked(boolean isChecked) {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, isChecked ? 1 : 0);
return true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2023 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.inputmethod;
import android.content.Context;
import android.hardware.input.InputManager;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class TrackpadReverseScrollingPreferenceController extends TogglePreferenceController {
private InputManager mIm;
public TrackpadReverseScrollingPreferenceController(Context context, String key) {
super(context, key);
mIm = context.getSystemService(InputManager.class);
}
@Override
public boolean isChecked() {
return mIm.useTouchpadNaturalScrolling(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
mIm.setTouchpadNaturalScrolling(mContext, isChecked);
return true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 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.inputmethod;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class TrackpadSwitchAppsPreferenceController extends TogglePreferenceController {
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_QUICK_SWITCH_ENABLED;
public TrackpadSwitchAppsPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1) != 0;
}
@Override
public boolean setChecked(boolean isChecked) {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, isChecked ? 1 : 0);
return true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2023 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.inputmethod;
import android.content.Context;
import android.hardware.input.InputManager;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class TrackpadTapToClickPreferenceController extends TogglePreferenceController {
private InputManager mIm;
public TrackpadTapToClickPreferenceController(Context context, String key) {
super(context, key);
mIm = context.getSystemService(InputManager.class);
}
@Override
public boolean isChecked() {
return mIm.useTouchpadTapToClick(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
mIm.setTouchpadTapToClick(mContext, isChecked);
return true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2023 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.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
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;
/** Tests for {@link TrackpadGoBackPreferenceController} */
@RunWith(RobolectricTestRunner.class)
public class TrackpadGoBackPreferenceControllerTest {
private static final String PREFERENCE_KEY = "gesture_go_back";
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_BACK_ENABLED;
private Context mContext;
private TrackpadGoBackPreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new TrackpadGoBackPreferenceController(mContext, PREFERENCE_KEY);
}
@Test
public void getAvailabilityStatus_expected() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getSliceHighlightMenuRes_expected() {
assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system);
}
@Test
public void setChecked_true_shouldReturn1() {
mController.setChecked(true);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(1);
}
@Test
public void setChecked_false_shouldReturn0() {
mController.setChecked(false);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(0);
}
@Test
public void isChecked_providerPutInt1_returnTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 1);
boolean result = mController.isChecked();
assertThat(result).isTrue();
}
@Test
public void isChecked_providerPutInt0_returnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 0);
boolean result = mController.isChecked();
assertThat(result).isFalse();
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2023 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.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
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;
/** Tests for {@link TrackpadGoHomePreferenceController} */
@RunWith(RobolectricTestRunner.class)
public class TrackpadGoHomePreferenceControllerTest {
private static final String PREFERENCE_KEY = "gesture_go_home";
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_HOME_ENABLED;
private Context mContext;
private TrackpadGoHomePreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new TrackpadGoHomePreferenceController(mContext, PREFERENCE_KEY);
}
@Test
public void getAvailabilityStatus_expected() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getSliceHighlightMenuRes_expected() {
assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system);
}
@Test
public void setChecked_true_shouldReturn1() {
mController.setChecked(true);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(1);
}
@Test
public void setChecked_false_shouldReturn0() {
mController.setChecked(false);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(0);
}
@Test
public void isChecked_providerPutInt1_returnTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 1);
boolean result = mController.isChecked();
assertThat(result).isTrue();
}
@Test
public void isChecked_providerPutInt0_returnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 0);
boolean result = mController.isChecked();
assertThat(result).isFalse();
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2023 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.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
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;
/** Tests for {@link TrackpadNotificationsPreferenceController} */
@RunWith(RobolectricTestRunner.class)
public class TrackpadNotificationsPreferenceControllerTest {
private static final String PREFERENCE_KEY = "gesture_notifications";
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_NOTIFICATION_ENABLED;
private Context mContext;
private TrackpadNotificationsPreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new TrackpadNotificationsPreferenceController(mContext, PREFERENCE_KEY);
}
@Test
public void getAvailabilityStatus_expected() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getSliceHighlightMenuRes_expected() {
assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system);
}
@Test
public void setChecked_true_shouldReturn1() {
mController.setChecked(true);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(1);
}
@Test
public void setChecked_false_shouldReturn0() {
mController.setChecked(false);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(0);
}
@Test
public void isChecked_providerPutInt1_returnTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 1);
boolean result = mController.isChecked();
assertThat(result).isTrue();
}
@Test
public void isChecked_providerPutInt0_returnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 0);
boolean result = mController.isChecked();
assertThat(result).isFalse();
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2023 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.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
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;
/** Tests for {@link TrackpadRecentAppsPreferenceController} */
@RunWith(RobolectricTestRunner.class)
public class TrackpadRecentAppsPreferenceControllerTest {
private static final String PREFERENCE_KEY = "gesture_recent_apps";
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_OVERVIEW_ENABLED;
private Context mContext;
private TrackpadRecentAppsPreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new TrackpadRecentAppsPreferenceController(mContext, PREFERENCE_KEY);
}
@Test
public void getAvailabilityStatus_expected() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getSliceHighlightMenuRes_expected() {
assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system);
}
@Test
public void setChecked_true_shouldReturn1() {
mController.setChecked(true);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(1);
}
@Test
public void setChecked_false_shouldReturn0() {
mController.setChecked(false);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(0);
}
@Test
public void isChecked_providerPutInt1_returnTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 1);
boolean result = mController.isChecked();
assertThat(result).isTrue();
}
@Test
public void isChecked_providerPutInt0_returnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 0);
boolean result = mController.isChecked();
assertThat(result).isFalse();
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2023 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.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
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;
/** Tests for {@link TrackpadSwitchAppsPreferenceController} */
@RunWith(RobolectricTestRunner.class)
public class TrackpadSwitchAppsPreferenceControllerTest {
private static final String PREFERENCE_KEY = "gesture_switch_apps";
private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_QUICK_SWITCH_ENABLED;
private Context mContext;
private TrackpadSwitchAppsPreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new TrackpadSwitchAppsPreferenceController(mContext, PREFERENCE_KEY);
}
@Test
public void getAvailabilityStatus_expected() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getSliceHighlightMenuRes_expected() {
assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system);
}
@Test
public void setChecked_true_shouldReturn1() {
mController.setChecked(true);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(1);
}
@Test
public void setChecked_false_shouldReturn0() {
mController.setChecked(false);
int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1);
assertThat(result).isEqualTo(0);
}
@Test
public void isChecked_providerPutInt1_returnTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 1);
boolean result = mController.isChecked();
assertThat(result).isTrue();
}
@Test
public void isChecked_providerPutInt0_returnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 0);
boolean result = mController.isChecked();
assertThat(result).isFalse();
}
}