Loading packages/SystemUI/src/com/android/systemui/accessibility/DisplayIdIndexSupplier.java +23 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,20 @@ abstract class DisplayIdIndexSupplier<T> { return instance; } /** * Gets the object by the element index. * * <p> If the index is bigger than the array size, an {@link ArrayIndexOutOfBoundsException} is * thrown for apps targeting {@link android.os.Build.VERSION_CODES#Q} and later </p> * * @param index the element index * @return T * @see SparseArray#valueAt(int) */ public T valueAt(int index) { return mSparseArray.valueAt(index); } @NonNull protected abstract T createInstance(Display display); Loading @@ -78,4 +92,13 @@ abstract class DisplayIdIndexSupplier<T> { public void clear() { mSparseArray.clear(); } /** * Gets the element size. * * @return size of all elements */ public int getSize() { return mSparseArray.size(); } } packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java +10 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.accessibility; import android.annotation.NonNull; import android.content.Context; import android.content.pm.ActivityInfo; import android.graphics.PixelFormat; import android.provider.Settings; import android.view.Gravity; Loading Loading @@ -102,6 +103,14 @@ class MagnificationModeSwitch { .start(); } void onConfigurationChanged(int configDiff) { if ((configDiff & ActivityInfo.CONFIG_DENSITY) == 0) { return; } applyResourcesValues(); mImageView.setImageResource(getIconResId(mMagnificationMode)); } private void toggleMagnificationMode() { final int newMode = mMagnificationMode ^ Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL; Loading packages/SystemUI/src/com/android/systemui/accessibility/ModeSwitchesController.java +18 −4 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ import javax.inject.Singleton; @Singleton public class ModeSwitchesController { private final SwitchSupplier mSwitchSupplier; private final DisplayIdIndexSupplier<MagnificationModeSwitch> mSwitchSupplier; public ModeSwitchesController(Context context) { mSwitchSupplier = new SwitchSupplier(context, Loading @@ -44,7 +44,7 @@ public class ModeSwitchesController { } @VisibleForTesting ModeSwitchesController(SwitchSupplier switchSupplier) { ModeSwitchesController(DisplayIdIndexSupplier<MagnificationModeSwitch> switchSupplier) { mSwitchSupplier = switchSupplier; } Loading Loading @@ -81,8 +81,22 @@ public class ModeSwitchesController { magnificationModeSwitch.removeButton(); } @VisibleForTesting static class SwitchSupplier extends DisplayIdIndexSupplier<MagnificationModeSwitch> { /** * Called when the configuration has changed, and it updates magnification button UI. * * @param configDiff a bit mask of the differences between the configurations */ @MainThread void onConfigurationChanged(int configDiff) { for (int i = 0; i < mSwitchSupplier.getSize(); i++) { final MagnificationModeSwitch magnificationModeSwitch = mSwitchSupplier.valueAt(i); if (magnificationModeSwitch != null) { magnificationModeSwitch.onConfigurationChanged(configDiff); } } } private static class SwitchSupplier extends DisplayIdIndexSupplier<MagnificationModeSwitch> { private final Context mContext; Loading packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnification.java +3 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,9 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall if (mWindowMagnificationController != null) { mWindowMagnificationController.onConfigurationChanged(configDiff); } if (mModeSwitchesController != null) { mModeSwitchesController.onConfigurationChanged(configDiff); } } @Override Loading packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.ActivityInfo; import android.provider.Settings; import android.testing.AndroidTestingRunner; import android.view.View; Loading Loading @@ -61,6 +62,7 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { @Mock private ViewPropertyAnimator mViewPropertyAnimator; private MagnificationModeSwitch mMagnificationModeSwitch; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); Loading Loading @@ -110,6 +112,15 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { verify(mWindowManager).removeView(mMockImageView); } @Test public void onConfigurationChanged_setImageResource() { mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN); mMagnificationModeSwitch.onConfigurationChanged(ActivityInfo.CONFIG_DENSITY); verify(mMockImageView, times(2)).setImageResource( getIconResId(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN)); } @Test public void performClick_fullscreenMode_removeViewAndChangeSettingsValue() { ArgumentCaptor<View.OnClickListener> captor = ArgumentCaptor.forClass( Loading Loading
packages/SystemUI/src/com/android/systemui/accessibility/DisplayIdIndexSupplier.java +23 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,20 @@ abstract class DisplayIdIndexSupplier<T> { return instance; } /** * Gets the object by the element index. * * <p> If the index is bigger than the array size, an {@link ArrayIndexOutOfBoundsException} is * thrown for apps targeting {@link android.os.Build.VERSION_CODES#Q} and later </p> * * @param index the element index * @return T * @see SparseArray#valueAt(int) */ public T valueAt(int index) { return mSparseArray.valueAt(index); } @NonNull protected abstract T createInstance(Display display); Loading @@ -78,4 +92,13 @@ abstract class DisplayIdIndexSupplier<T> { public void clear() { mSparseArray.clear(); } /** * Gets the element size. * * @return size of all elements */ public int getSize() { return mSparseArray.size(); } }
packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java +10 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.accessibility; import android.annotation.NonNull; import android.content.Context; import android.content.pm.ActivityInfo; import android.graphics.PixelFormat; import android.provider.Settings; import android.view.Gravity; Loading Loading @@ -102,6 +103,14 @@ class MagnificationModeSwitch { .start(); } void onConfigurationChanged(int configDiff) { if ((configDiff & ActivityInfo.CONFIG_DENSITY) == 0) { return; } applyResourcesValues(); mImageView.setImageResource(getIconResId(mMagnificationMode)); } private void toggleMagnificationMode() { final int newMode = mMagnificationMode ^ Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL; Loading
packages/SystemUI/src/com/android/systemui/accessibility/ModeSwitchesController.java +18 −4 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ import javax.inject.Singleton; @Singleton public class ModeSwitchesController { private final SwitchSupplier mSwitchSupplier; private final DisplayIdIndexSupplier<MagnificationModeSwitch> mSwitchSupplier; public ModeSwitchesController(Context context) { mSwitchSupplier = new SwitchSupplier(context, Loading @@ -44,7 +44,7 @@ public class ModeSwitchesController { } @VisibleForTesting ModeSwitchesController(SwitchSupplier switchSupplier) { ModeSwitchesController(DisplayIdIndexSupplier<MagnificationModeSwitch> switchSupplier) { mSwitchSupplier = switchSupplier; } Loading Loading @@ -81,8 +81,22 @@ public class ModeSwitchesController { magnificationModeSwitch.removeButton(); } @VisibleForTesting static class SwitchSupplier extends DisplayIdIndexSupplier<MagnificationModeSwitch> { /** * Called when the configuration has changed, and it updates magnification button UI. * * @param configDiff a bit mask of the differences between the configurations */ @MainThread void onConfigurationChanged(int configDiff) { for (int i = 0; i < mSwitchSupplier.getSize(); i++) { final MagnificationModeSwitch magnificationModeSwitch = mSwitchSupplier.valueAt(i); if (magnificationModeSwitch != null) { magnificationModeSwitch.onConfigurationChanged(configDiff); } } } private static class SwitchSupplier extends DisplayIdIndexSupplier<MagnificationModeSwitch> { private final Context mContext; Loading
packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnification.java +3 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,9 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall if (mWindowMagnificationController != null) { mWindowMagnificationController.onConfigurationChanged(configDiff); } if (mModeSwitchesController != null) { mModeSwitchesController.onConfigurationChanged(configDiff); } } @Override Loading
packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.ActivityInfo; import android.provider.Settings; import android.testing.AndroidTestingRunner; import android.view.View; Loading Loading @@ -61,6 +62,7 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { @Mock private ViewPropertyAnimator mViewPropertyAnimator; private MagnificationModeSwitch mMagnificationModeSwitch; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); Loading Loading @@ -110,6 +112,15 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { verify(mWindowManager).removeView(mMockImageView); } @Test public void onConfigurationChanged_setImageResource() { mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN); mMagnificationModeSwitch.onConfigurationChanged(ActivityInfo.CONFIG_DENSITY); verify(mMockImageView, times(2)).setImageResource( getIconResId(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN)); } @Test public void performClick_fullscreenMode_removeViewAndChangeSettingsValue() { ArgumentCaptor<View.OnClickListener> captor = ArgumentCaptor.forClass( Loading