Merge "Update magnification button UI when the device configuration is changed"
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -112,7 +121,7 @@ class MagnificationModeSwitch {
|
||||
}
|
||||
|
||||
private static ImageView createView(Context context) {
|
||||
ImageView imageView = new ImageView(context);
|
||||
ImageView imageView = new ImageView(context);
|
||||
imageView.setClickable(true);
|
||||
imageView.setFocusable(true);
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
|
||||
@@ -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,
|
||||
@@ -44,7 +44,7 @@ public class ModeSwitchesController {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ModeSwitchesController(SwitchSupplier switchSupplier) {
|
||||
ModeSwitchesController(DisplayIdIndexSupplier<MagnificationModeSwitch> switchSupplier) {
|
||||
mSwitchSupplier = switchSupplier;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -84,6 +84,9 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall
|
||||
if (mWindowMagnificationController != null) {
|
||||
mWindowMagnificationController.onConfigurationChanged(configDiff);
|
||||
}
|
||||
if (mModeSwitchesController != null) {
|
||||
mModeSwitchesController.onConfigurationChanged(configDiff);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
@@ -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(
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package com.android.systemui.accessibility;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.provider.Settings;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.view.Display;
|
||||
@@ -39,8 +39,7 @@ import org.mockito.MockitoAnnotations;
|
||||
/** Tests the ModeSwitchesController. */
|
||||
public class ModeSwitchesControllerTest extends SysuiTestCase {
|
||||
|
||||
@Mock
|
||||
private ModeSwitchesController.SwitchSupplier mSupplier;
|
||||
private FakeSwitchSupplier mSupplier;
|
||||
@Mock
|
||||
private MagnificationModeSwitch mModeSwitch;
|
||||
private ModeSwitchesController mModeSwitchesController;
|
||||
@@ -49,7 +48,7 @@ public class ModeSwitchesControllerTest extends SysuiTestCase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mSupplier.get(anyInt())).thenReturn(mModeSwitch);
|
||||
mSupplier = new FakeSwitchSupplier(mContext.getSystemService(DisplayManager.class));
|
||||
mModeSwitchesController = new ModeSwitchesController(mSupplier);
|
||||
}
|
||||
|
||||
@@ -70,4 +69,25 @@ public class ModeSwitchesControllerTest extends SysuiTestCase {
|
||||
|
||||
verify(mModeSwitch).removeButton();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testControllerOnConfigurationChanged_notifyShowingButton() {
|
||||
mModeSwitchesController.showButton(Display.DEFAULT_DISPLAY,
|
||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
mModeSwitchesController.onConfigurationChanged(ActivityInfo.CONFIG_DENSITY);
|
||||
|
||||
verify(mModeSwitch).onConfigurationChanged(ActivityInfo.CONFIG_DENSITY);
|
||||
}
|
||||
|
||||
private class FakeSwitchSupplier extends DisplayIdIndexSupplier<MagnificationModeSwitch> {
|
||||
|
||||
FakeSwitchSupplier(DisplayManager displayManager) {
|
||||
super(displayManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MagnificationModeSwitch createInstance(Display display) {
|
||||
return mModeSwitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
package com.android.systemui.accessibility;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Rect;
|
||||
import android.os.RemoteException;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
@@ -96,4 +98,13 @@ public class WindowMagnificationTest extends SysuiTestCase {
|
||||
verify(connectionCallback).onWindowMagnifierBoundsChanged(Display.DEFAULT_DISPLAY,
|
||||
testBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onConfigurationChanged_updateModeSwitches() {
|
||||
final Configuration config = new Configuration();
|
||||
config.densityDpi = Configuration.DENSITY_DPI_ANY;
|
||||
mWindowMagnification.onConfigurationChanged(config);
|
||||
|
||||
verify(mModeSwitchesController).onConfigurationChanged(anyInt());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user