Hides the settings entry in Magnification Settings if device is not supported
If the device doesn't support magnification area, we should hide the settings entry in mangification settings Bug: 177371954 Test: atest ToggleScreenMagnificationPreferenceFragmentTest Change-Id: I41fc3177f86c6a19e3ef0d2fbe5e052d77c1cb47
This commit is contained in:
@@ -128,8 +128,15 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initSettingsPreference() {
|
protected void initSettingsPreference() {
|
||||||
|
// If the device doesn't support magnification area, it should hide the settings preference.
|
||||||
|
if (!getContext().getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_magnification_area)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mSettingsPreference = new Preference(getPrefContext());
|
mSettingsPreference = new Preference(getPrefContext());
|
||||||
mSettingsPreference.setTitle(R.string.accessibility_menu_item_settings);
|
mSettingsPreference.setTitle(R.string.accessibility_menu_item_settings);
|
||||||
|
// TODO(b/177371954): "magnification area" should be brought up to the highest level of the
|
||||||
|
// settings UI so that it appears below "shortcut" to replace "settings.
|
||||||
mSettingsPreference.setFragment(MagnificationSettingsFragment.class.getName());
|
mSettingsPreference.setFragment(MagnificationSettingsFragment.class.getName());
|
||||||
mSettingsPreference.setPersistent(false);
|
mSettingsPreference.setPersistent(false);
|
||||||
|
|
||||||
|
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -75,7 +76,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
"com.android.server.accessibility.MagnificationController";
|
"com.android.server.accessibility.MagnificationController";
|
||||||
|
|
||||||
private TestToggleScreenMagnificationPreferenceFragment mFragment;
|
private TestToggleScreenMagnificationPreferenceFragment mFragment;
|
||||||
private Context mContext = ApplicationProvider.getApplicationContext();
|
private Context mContext;
|
||||||
|
private Resources mResources;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceManager mPreferenceManager;
|
private PreferenceManager mPreferenceManager;
|
||||||
@@ -86,10 +88,14 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
public void setUpTestFragment() {
|
public void setUpTestFragment() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
mFragment = spy(new TestToggleScreenMagnificationPreferenceFragment());
|
mFragment = spy(new TestToggleScreenMagnificationPreferenceFragment());
|
||||||
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
|
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
|
||||||
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
|
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
|
||||||
when(mFragment.getContext()).thenReturn(mContext);
|
when(mFragment.getContext()).thenReturn(mContext);
|
||||||
|
mResources = spy(mContext.getResources());
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
when(mFragment.getContext().getResources()).thenReturn(mResources);
|
||||||
doReturn(null).when(mFragment).getPreferenceScreen();
|
doReturn(null).when(mFragment).getPreferenceScreen();
|
||||||
doReturn(mActivity).when(mFragment).getActivity();
|
doReturn(mActivity).when(mFragment).getActivity();
|
||||||
}
|
}
|
||||||
@@ -250,6 +256,16 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
assertThat(expectedType).isEqualTo(UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP);
|
assertThat(expectedType).isEqualTo(UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initSettingsPreference_notSupportsMagnificationArea_settingsPreferenceIsNull() {
|
||||||
|
when(mResources.getBoolean(
|
||||||
|
com.android.internal.R.bool.config_magnification_area))
|
||||||
|
.thenReturn(false);
|
||||||
|
mFragment.initSettingsPreference();
|
||||||
|
|
||||||
|
assertThat(mFragment.mSettingsPreference).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
private void putStringIntoSettings(String key, String componentName) {
|
private void putStringIntoSettings(String key, String componentName) {
|
||||||
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
|
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user