From 6bf8c427dfd76ff55f697bb2c2e8ba8eb659656c Mon Sep 17 00:00:00 2001 From: Candice Date: Wed, 15 May 2024 05:14:50 +0000 Subject: refactor(size preference): rename the class to WindowMagnificationFrameSizePrefs Rename the class name so it will be more clear to show that we are keeping the magnification window frame size instead of the window itself. Bug: 325567876 Test: atest WindowMagnificationFrameSizePrefsTest Flag: N/A Change-Id: Idc5641c73551ed0e2a82361c83b1574f5d24cd88 --- .../WindowMagnificationController.java | 12 ++-- .../WindowMagnificationFrameSizePrefs.java | 71 +++++++++++++++++++++ .../WindowMagnificationSizePrefs.java | 71 --------------------- .../WindowMagnificationFrameSizePrefsTest.java | 74 ++++++++++++++++++++++ .../WindowMagnificationSizePrefsTest.java | 74 ---------------------- 5 files changed, 151 insertions(+), 151 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationFrameSizePrefs.java delete mode 100644 packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSizePrefs.java create mode 100644 packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationFrameSizePrefsTest.java delete mode 100644 packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSizePrefsTest.java diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java index e66261c459c7..5458ab1196d7 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java @@ -240,7 +240,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private boolean mEditSizeEnable = false; private boolean mSettingsPanelVisibility = false; @VisibleForTesting - WindowMagnificationSizePrefs mWindowMagnificationSizePrefs; + WindowMagnificationFrameSizePrefs mWindowMagnificationFrameSizePrefs; @Nullable private final MirrorWindowControl mMirrorWindowControl; @@ -270,7 +270,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold mSysUiState = sysUiState; mScvhSupplier = scvhSupplier; mConfiguration = new Configuration(context.getResources().getConfiguration()); - mWindowMagnificationSizePrefs = new WindowMagnificationSizePrefs(mContext); + mWindowMagnificationFrameSizePrefs = new WindowMagnificationFrameSizePrefs(mContext); final Display display = mContext.getDisplay(); mDisplayId = mContext.getDisplayId(); @@ -457,7 +457,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold if (!enable) { // Keep the magnifier size when exiting edit mode - mWindowMagnificationSizePrefs.saveSizeForCurrentDensity( + mWindowMagnificationFrameSizePrefs.saveSizeForCurrentDensity( new Size(mMagnificationFrame.width(), mMagnificationFrame.height())); } } @@ -944,7 +944,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold } private void setMagnificationFrame(int width, int height, int centerX, int centerY) { - mWindowMagnificationSizePrefs.saveSizeForCurrentDensity(new Size(width, height)); + mWindowMagnificationFrameSizePrefs.saveSizeForCurrentDensity(new Size(width, height)); // Sets the initial frame area for the mirror and place it to the given center on the // display. @@ -954,11 +954,11 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold } private Size restoreMagnificationWindowFrameSizeIfPossible() { - if (!mWindowMagnificationSizePrefs.isPreferenceSavedForCurrentDensity()) { + if (!mWindowMagnificationFrameSizePrefs.isPreferenceSavedForCurrentDensity()) { return getDefaultMagnificationWindowFrameSize(); } - return mWindowMagnificationSizePrefs.getSizeForCurrentDensity(); + return mWindowMagnificationFrameSizePrefs.getSizeForCurrentDensity(); } private Size getDefaultMagnificationWindowFrameSize() { diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationFrameSizePrefs.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationFrameSizePrefs.java new file mode 100644 index 000000000000..e83e85e1af1a --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationFrameSizePrefs.java @@ -0,0 +1,71 @@ +/* + * 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.systemui.accessibility; + +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Size; + +/** + * Class to handle SharedPreference for window magnification size. + */ +final class WindowMagnificationFrameSizePrefs { + + private static final String WINDOW_MAGNIFICATION_PREFERENCES = + "window_magnification_preferences"; + Context mContext; + SharedPreferences mWindowMagnificationSizePreferences; + + WindowMagnificationFrameSizePrefs(Context context) { + mContext = context; + mWindowMagnificationSizePreferences = mContext + .getSharedPreferences(WINDOW_MAGNIFICATION_PREFERENCES, Context.MODE_PRIVATE); + } + + /** + * Uses smallest screen width DP as the key for preference. + */ + private String getKey() { + return String.valueOf( + mContext.getResources().getConfiguration().smallestScreenWidthDp); + } + + /** + * Saves the window frame size for current screen density. + */ + public void saveSizeForCurrentDensity(Size size) { + mWindowMagnificationSizePreferences.edit() + .putString(getKey(), size.toString()).apply(); + } + + /** + * Check if there is a preference saved for current screen density. + * + * @return true if there is a preference saved for current screen density, false if it is unset. + */ + public boolean isPreferenceSavedForCurrentDensity() { + return mWindowMagnificationSizePreferences.contains(getKey()); + } + + /** + * Gets the size preference for current screen density. + */ + public Size getSizeForCurrentDensity() { + return Size.parseSize(mWindowMagnificationSizePreferences.getString(getKey(), null)); + } + +} diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSizePrefs.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSizePrefs.java deleted file mode 100644 index a401f2a980c1..000000000000 --- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSizePrefs.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.systemui.accessibility; - -import android.content.Context; -import android.content.SharedPreferences; -import android.util.Size; - -/** - * Class to handle SharedPreference for window magnification size. - */ -final class WindowMagnificationSizePrefs { - - private static final String WINDOW_MAGNIFICATION_PREFERENCES = - "window_magnification_preferences"; - Context mContext; - SharedPreferences mWindowMagnificationSizePreferences; - - public WindowMagnificationSizePrefs(Context context) { - mContext = context; - mWindowMagnificationSizePreferences = mContext - .getSharedPreferences(WINDOW_MAGNIFICATION_PREFERENCES, Context.MODE_PRIVATE); - } - - /** - * Uses smallest screen width DP as the key for preference. - */ - private String getKey() { - return String.valueOf( - mContext.getResources().getConfiguration().smallestScreenWidthDp); - } - - /** - * Saves the window frame size for current screen density. - */ - public void saveSizeForCurrentDensity(Size size) { - mWindowMagnificationSizePreferences.edit() - .putString(getKey(), size.toString()).apply(); - } - - /** - * Check if there is a preference saved for current screen density. - * - * @return true if there is a preference saved for current screen density, false if it is unset. - */ - public boolean isPreferenceSavedForCurrentDensity() { - return mWindowMagnificationSizePreferences.contains(getKey()); - } - - /** - * Gets the size preference for current screen density. - */ - public Size getSizeForCurrentDensity() { - return Size.parseSize(mWindowMagnificationSizePreferences.getString(getKey(), null)); - } - -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationFrameSizePrefsTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationFrameSizePrefsTest.java new file mode 100644 index 000000000000..93c0eeaac488 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationFrameSizePrefsTest.java @@ -0,0 +1,74 @@ +/* + * 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.systemui.accessibility; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import android.testing.AndroidTestingRunner; +import android.testing.TestableLooper; +import android.util.Size; + +import androidx.test.filters.SmallTest; + +import com.android.systemui.SysuiTestCase; +import com.android.systemui.util.FakeSharedPreferences; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidTestingRunner.class) +@TestableLooper.RunWithLooper +public class WindowMagnificationFrameSizePrefsTest extends SysuiTestCase { + + WindowMagnificationFrameSizePrefs mWindowMagnificationFrameSizePrefs; + FakeSharedPreferences mSharedPreferences; + + @Before + public void setUp() { + mContext = spy(mContext); + mSharedPreferences = new FakeSharedPreferences(); + when(mContext.getSharedPreferences( + eq("window_magnification_preferences"), anyInt())) + .thenReturn(mSharedPreferences); + mWindowMagnificationFrameSizePrefs = new WindowMagnificationFrameSizePrefs(mContext); + } + + @Test + public void saveSizeForCurrentDensity_getExpectedSize() { + Size testSize = new Size(500, 500); + mWindowMagnificationFrameSizePrefs.saveSizeForCurrentDensity(testSize); + + assertThat(mWindowMagnificationFrameSizePrefs.getSizeForCurrentDensity()) + .isEqualTo(testSize); + } + + @Test + public void saveSizeForCurrentDensity_containsPreferenceForCurrentDensity() { + Size testSize = new Size(500, 500); + mWindowMagnificationFrameSizePrefs.saveSizeForCurrentDensity(testSize); + + assertThat(mWindowMagnificationFrameSizePrefs.isPreferenceSavedForCurrentDensity()) + .isTrue(); + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSizePrefsTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSizePrefsTest.java deleted file mode 100644 index 516b6658d24a..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSizePrefsTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.systemui.accessibility; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; -import android.util.Size; - -import androidx.test.filters.SmallTest; - -import com.android.systemui.SysuiTestCase; -import com.android.systemui.util.FakeSharedPreferences; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@SmallTest -@RunWith(AndroidTestingRunner.class) -@TestableLooper.RunWithLooper -public class WindowMagnificationSizePrefsTest extends SysuiTestCase { - - WindowMagnificationSizePrefs mWindowMagnificationSizePrefs; - FakeSharedPreferences mSharedPreferences; - - @Before - public void setUp() { - mContext = spy(mContext); - mSharedPreferences = new FakeSharedPreferences(); - when(mContext.getSharedPreferences( - eq("window_magnification_preferences"), anyInt())) - .thenReturn(mSharedPreferences); - mWindowMagnificationSizePrefs = new WindowMagnificationSizePrefs(mContext); - } - - @Test - public void saveSizeForCurrentDensity_getExpectedSize() { - Size testSize = new Size(500, 500); - mWindowMagnificationSizePrefs.saveSizeForCurrentDensity(testSize); - - assertThat(mWindowMagnificationSizePrefs.getSizeForCurrentDensity()) - .isEqualTo(testSize); - } - - @Test - public void saveSizeForCurrentDensity_containsPreferenceForCurrentDensity() { - Size testSize = new Size(500, 500); - mWindowMagnificationSizePrefs.saveSizeForCurrentDensity(testSize); - - assertThat(mWindowMagnificationSizePrefs.isPreferenceSavedForCurrentDensity()) - .isTrue(); - } -} -- cgit v1.2.3-59-g8ed1b