Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72a7f8a7 authored by Nikita Dubrovsky's avatar Nikita Dubrovsky Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cursor-control-flags"

* changes:
  Allow setting defaults for DeviceConfig flags plumbed via settings
  Use DeviceConfig flags for cursor drag and insertion handle gestures
parents 00306fce 9e139179
Loading
Loading
Loading
Loading
+40 −23
Original line number Diff line number Diff line
@@ -152,9 +152,6 @@ public class Editor {
    private static final String TAG = "Editor";
    private static final boolean DEBUG_UNDO = false;

    // Specifies whether to allow starting a cursor drag by dragging anywhere over the text.
    @VisibleForTesting
    public static boolean FLAG_ENABLE_CURSOR_DRAG = true;
    // Specifies whether to use the magnifier when pressing the insertion or selection handles.
    private static final boolean FLAG_USE_MAGNIFIER = true;

@@ -388,9 +385,8 @@ public class Editor {

    private final SuggestionHelper mSuggestionHelper = new SuggestionHelper();

    // Specifies whether the cursor control feature set is enabled.
    // This can only be true if the text view is editable.
    private boolean mCursorControlEnabled;
    private boolean mFlagCursorDragFromAnywhereEnabled;
    private boolean mFlagInsertionHandleGesturesEnabled;

    // Specifies whether the new magnifier (with fish-eye effect) is enabled.
    private final boolean mNewMagnifierEnabled;
@@ -416,26 +412,43 @@ public class Editor {
        mHapticTextHandleEnabled = mTextView.getContext().getResources().getBoolean(
                com.android.internal.R.bool.config_enableHapticTextHandle);

        mCursorControlEnabled = AppGlobals.getIntCoreSetting(
                WidgetFlags.KEY_ENABLE_CURSOR_CONTROL , 0) != 0;
        mFlagCursorDragFromAnywhereEnabled = AppGlobals.getIntCoreSetting(
                WidgetFlags.KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE,
                WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE_DEFAULT ? 1 : 0) != 0;
        mFlagInsertionHandleGesturesEnabled = AppGlobals.getIntCoreSetting(
                WidgetFlags.KEY_ENABLE_INSERTION_HANDLE_GESTURES,
                WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES_DEFAULT ? 1 : 0) != 0;
        mNewMagnifierEnabled = AppGlobals.getIntCoreSetting(
                WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, 0) != 0;
                WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER,
                WidgetFlags.ENABLE_NEW_MAGNIFIER_DEFAULT ? 1 : 0) != 0;
        if (TextView.DEBUG_CURSOR) {
            logCursor("Editor", "Cursor control is %s.",
                    mCursorControlEnabled ? "enabled" : "disabled");
            logCursor("Editor", "Cursor drag from anywhere is %s.",
                    mFlagCursorDragFromAnywhereEnabled ? "enabled" : "disabled");
            logCursor("Editor", "Insertion handle gestures is %s.",
                    mFlagInsertionHandleGesturesEnabled ? "enabled" : "disabled");
            logCursor("Editor", "New magnifier is %s.",
                    mNewMagnifierEnabled ? "enabled" : "disabled");
        }
    }

    @VisibleForTesting
    public void setCursorControlEnabled(boolean enabled) {
        mCursorControlEnabled = enabled;
    public boolean getFlagCursorDragFromAnywhereEnabled() {
        return mFlagCursorDragFromAnywhereEnabled;
    }

    @VisibleForTesting
    public void setFlagCursorDragFromAnywhereEnabled(boolean enabled) {
        mFlagCursorDragFromAnywhereEnabled = enabled;
    }

    @VisibleForTesting
    public boolean getFlagInsertionHandleGesturesEnabled() {
        return mFlagInsertionHandleGesturesEnabled;
    }

    @VisibleForTesting
    public boolean getCursorControlEnabled() {
        return mCursorControlEnabled;
    public void setFlagInsertionHandleGesturesEnabled(boolean enabled) {
        mFlagInsertionHandleGesturesEnabled = enabled;
    }

    // Lazy creates the magnifier animator.
@@ -455,9 +468,11 @@ public class Editor {
        final Magnifier.Builder params = new Magnifier.Builder(mTextView);

        float zoom = AppGlobals.getFloatCoreSetting(
                WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, 1.5f);
                WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR,
                WidgetFlags.MAGNIFIER_ZOOM_FACTOR_DEFAULT);
        float aspectRatio = AppGlobals.getFloatCoreSetting(
                WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, 5.5f);
                WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO,
                WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT);
        // Avoid invalid/unsupported values.
        if (zoom < 1.2f || zoom > 1.8f) {
            zoom = 1.5f;
@@ -5291,11 +5306,13 @@ public class Editor {

            int deltaHeight = 0;
            int opacity = 255;
            if (mCursorControlEnabled) {
            if (mFlagInsertionHandleGesturesEnabled) {
                deltaHeight = AppGlobals.getIntCoreSetting(
                        WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, 25);
                        WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT,
                        WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT_DEFAULT);
                opacity = AppGlobals.getIntCoreSetting(
                        WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, 50);
                        WidgetFlags.KEY_INSERTION_HANDLE_OPACITY,
                        WidgetFlags.INSERTION_HANDLE_OPACITY_DEFAULT);
                // Avoid invalid/unsupported values.
                if (deltaHeight < -25 || deltaHeight > 50) {
                    deltaHeight = 25;
@@ -5361,7 +5378,7 @@ public class Editor {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            if (mCursorControlEnabled) {
            if (mFlagInsertionHandleGesturesEnabled) {
                final int height = Math.max(
                        getPreferredHeight() + mDeltaHeight, mDrawable.getIntrinsicHeight());
                setMeasuredDimension(getPreferredWidth(), height);
@@ -5372,7 +5389,7 @@ public class Editor {

        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            if (mCursorControlEnabled && FLAG_ENABLE_CURSOR_DRAG) {
            if (mFlagInsertionHandleGesturesEnabled && mFlagCursorDragFromAnywhereEnabled) {
                // Should only enable touch through when cursor drag is enabled.
                // Otherwise the insertion handle view cannot be moved.
                return touchThrough(ev);
@@ -6063,7 +6080,7 @@ public class Editor {
                    }
                    if (mIsDraggingCursor) {
                        performCursorDrag(event);
                    } else if (FLAG_ENABLE_CURSOR_DRAG
                    } else if (mFlagCursorDragFromAnywhereEnabled
                                && mTextView.getLayout() != null
                                && mTextView.isFocused()
                                && mTouchState.isMovedEnoughForDrag()
+56 −11
Original line number Diff line number Diff line
@@ -17,27 +17,49 @@
package android.widget;

/**
 * Keeps the flags related to the Widget namespace in {@link DeviceConfig}.
 * Flags in the {@link android.provider.DeviceConfig#NAMESPACE_WIDGET "widget" namespace}.
 *
 * @hide
 */
public final class WidgetFlags {

    /**
     * Whether the cursor control feature set is enabled.
     * TODO: Makes this flag key visible to webview/chrome.
     * Whether starting a cursor drag from anywhere in the text should be enabled.
     */
    public static final String ENABLE_CURSOR_CONTROL =
            "CursorControlFeature__enable_cursor_control";
    public static final String ENABLE_CURSOR_DRAG_FROM_ANYWHERE =
            "CursorControlFeature__enable_cursor_drag_from_anywhere";

    /**
     * The key name used in app core settings for enable cursor control.
     * The key used in app core settings for the flag {@link #ENABLE_CURSOR_DRAG_FROM_ANYWHERE}.
     */
    public static final String KEY_ENABLE_CURSOR_CONTROL = "widget__enable_cursor_control";
    public static final String KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE =
            "widget__enable_cursor_drag_from_anywhere";

    /**
     * Default value for the flag {@link #ENABLE_CURSOR_DRAG_FROM_ANYWHERE}.
     */
    public static final boolean ENABLE_CURSOR_DRAG_FROM_ANYWHERE_DEFAULT = true;

    /**
     * Whether additional gestures should be enabled for the insertion cursor handle (e.g.
     * long-press or double-tap on the handle to trigger selection).
     */
    public static final String ENABLE_INSERTION_HANDLE_GESTURES =
            "CursorControlFeature__enable_insertion_handle_gestures";

    /**
     * The key used in app core settings for the flag {@link #ENABLE_INSERTION_HANDLE_GESTURES}.
     */
    public static final String KEY_ENABLE_INSERTION_HANDLE_GESTURES =
            "widget__enable_insertion_handle_gestures";

    /**
     * Default value for the flag {@link #ENABLE_INSERTION_HANDLE_GESTURES}.
     */
    public static final boolean ENABLE_INSERTION_HANDLE_GESTURES_DEFAULT = false;

    /**
     * The flag of delta height applies to the insertion handle when cursor control flag is enabled.
     * The default value is 25.
     */
    public static final String INSERTION_HANDLE_DELTA_HEIGHT =
            "CursorControlFeature__insertion_handle_delta_height";
@@ -48,9 +70,14 @@ public final class WidgetFlags {
    public static final String KEY_INSERTION_HANDLE_DELTA_HEIGHT =
            "widget__insertion_handle_delta_height";

    /**
     * Default value for the flag {@link #INSERTION_HANDLE_DELTA_HEIGHT}.
     */
    public static final int INSERTION_HANDLE_DELTA_HEIGHT_DEFAULT = 25;

    /**
     * The flag of opacity applies to the insertion handle when cursor control flag is enabled.
     * The opacity value is in the range of {0..100}. The default value is 50.
     * The opacity value is in the range of {0..100}.
     */
    public static final String INSERTION_HANDLE_OPACITY =
            "CursorControlFeature__insertion_handle_opacity";
@@ -61,6 +88,11 @@ public final class WidgetFlags {
    public static final String KEY_INSERTION_HANDLE_OPACITY =
            "widget__insertion_handle_opacity";

    /**
     * Default value for the flag {@link #INSERTION_HANDLE_OPACITY}.
     */
    public static final int INSERTION_HANDLE_OPACITY_DEFAULT = 50;

    /**
     * The flag of enabling the new magnifier.
     */
@@ -71,9 +103,13 @@ public final class WidgetFlags {
     */
    public static final String KEY_ENABLE_NEW_MAGNIFIER = "widget__enable_new_magnifier";

    /**
     * Default value for the flag {@link #ENABLE_NEW_MAGNIFIER}.
     */
    public static final boolean ENABLE_NEW_MAGNIFIER_DEFAULT = false;

    /**
     * The flag of zoom factor applies to the new magnifier.
     * The default value is 1.5f.
     */
    public static final String MAGNIFIER_ZOOM_FACTOR =
            "CursorControlFeature__magnifier_zoom_factor";
@@ -83,9 +119,13 @@ public final class WidgetFlags {
     */
    public static final String KEY_MAGNIFIER_ZOOM_FACTOR = "widget__magnifier_zoom_factor";

    /**
     * Default value for the flag {@link #MAGNIFIER_ZOOM_FACTOR}.
     */
    public static final float MAGNIFIER_ZOOM_FACTOR_DEFAULT = 1.5f;

    /**
     * The flag of aspect ratio (width/height) applies to the new magnifier.
     * The default value is 5.5f.
     */
    public static final String MAGNIFIER_ASPECT_RATIO =
            "CursorControlFeature__magnifier_aspect_ratio";
@@ -95,6 +135,11 @@ public final class WidgetFlags {
     */
    public static final String KEY_MAGNIFIER_ASPECT_RATIO = "widget__magnifier_aspect_ratio";

    /**
     * Default value for the flag {@link #MAGNIFIER_ASPECT_RATIO}.
     */
    public static final float MAGNIFIER_ASPECT_RATIO_DEFAULT = 5.5f;

    private WidgetFlags() {
    }
}
+0 −9
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import com.android.frameworks.coretests.R;

import com.google.common.base.Strings;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -69,7 +68,6 @@ public class EditorCursorDragTest {
    public ActivityTestRule<TextViewActivity> mActivityRule = new ActivityTestRule<>(
            TextViewActivity.class);

    private boolean mOriginalFlagValue;
    private Instrumentation mInstrumentation;
    private Activity mActivity;

@@ -77,13 +75,6 @@ public class EditorCursorDragTest {
    public void before() throws Throwable {
        mInstrumentation = InstrumentationRegistry.getInstrumentation();
        mActivity = mActivityRule.getActivity();
        mOriginalFlagValue = Editor.FLAG_ENABLE_CURSOR_DRAG;
        Editor.FLAG_ENABLE_CURSOR_DRAG = true;
    }

    @After
    public void after() throws Throwable {
        Editor.FLAG_ENABLE_CURSOR_DRAG = mOriginalFlagValue;
    }

    @Test
+15 −43
Original line number Diff line number Diff line
@@ -31,8 +31,8 @@ import static android.widget.espresso.TextViewActions.doubleTapAndDragHandle;
import static android.widget.espresso.TextViewActions.doubleTapAndDragOnText;
import static android.widget.espresso.TextViewActions.doubleTapHandle;
import static android.widget.espresso.TextViewActions.dragHandle;
import static android.widget.espresso.TextViewActions.longPressAndDragOnText;
import static android.widget.espresso.TextViewActions.longPressAndDragHandle;
import static android.widget.espresso.TextViewActions.longPressAndDragOnText;
import static android.widget.espresso.TextViewActions.longPressHandle;
import static android.widget.espresso.TextViewActions.longPressOnTextAtIndex;
import static android.widget.espresso.TextViewAssertions.doesNotHaveStyledText;
@@ -514,29 +514,26 @@ public class TextViewActivityTest {
        onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f")));
    }

    @Test
    public void testInsertionHandle_touchThrough() {
    private void enableFlagsForInsertionHandleGestures() {
        final TextView textView = mActivity.findViewById(R.id.textview);
        boolean cursorControlEnabled = textView.getEditorForTesting().getCursorControlEnabled();
        boolean cursorDragEnabled = Editor.FLAG_ENABLE_CURSOR_DRAG;
        textView.getEditorForTesting().setCursorControlEnabled(true);
        Editor.FLAG_ENABLE_CURSOR_DRAG = true;
        final Editor editor = textView.getEditorForTesting();
        editor.setFlagCursorDragFromAnywhereEnabled(true);
        editor.setFlagInsertionHandleGesturesEnabled(true);
        // Note: We don't need to reset these flags explicitly at the end of each test, because a
        // fresh TextView and Editor will be created for each test.
    }

    @Test
    public void testInsertionHandle_touchThrough() {
        enableFlagsForInsertionHandleGestures();
        testInsertionHandle();
        testInsertionHandle_multiLine();

        textView.getEditorForTesting().setCursorControlEnabled(cursorControlEnabled);
        Editor.FLAG_ENABLE_CURSOR_DRAG = cursorDragEnabled;
    }

    @Test
    public void testInsertionHandle_longPressToSelect() {
        // This test only makes sense when Cursor Control flag is enabled.
        enableFlagsForInsertionHandleGestures();
        final TextView textView = mActivity.findViewById(R.id.textview);
        boolean cursorControlEnabled = textView.getEditorForTesting().getCursorControlEnabled();
        boolean cursorDragEnabled = Editor.FLAG_ENABLE_CURSOR_DRAG;
        textView.getEditorForTesting().setCursorControlEnabled(true);
        Editor.FLAG_ENABLE_CURSOR_DRAG = true;

        final String text = "hello the world";
        onView(withId(R.id.textview)).perform(replaceText(text));
@@ -546,20 +543,12 @@ public class TextViewActivityTest {

        onHandleView(com.android.internal.R.id.insertion_handle).perform(longPressHandle(textView));
        onView(withId(R.id.textview)).check(hasSelection("world"));

        textView.getEditorForTesting().setCursorControlEnabled(cursorControlEnabled);
        Editor.FLAG_ENABLE_CURSOR_DRAG = cursorDragEnabled;
    }

    @Test
    public void testInsertionHandle_longPressAndDragToSelect() {
        // This test only makes sense when Cursor Control flag is enabled.
        enableFlagsForInsertionHandleGestures();
        final TextView textView = mActivity.findViewById(R.id.textview);
        boolean cursorControlEnabled = textView.getEditorForTesting().getCursorControlEnabled();
        boolean cursorDragEnabled = Editor.FLAG_ENABLE_CURSOR_DRAG;
        textView.getEditorForTesting().setCursorControlEnabled(true);
        Editor.FLAG_ENABLE_CURSOR_DRAG = true;

        final String text = "hello the world";
        onView(withId(R.id.textview)).perform(replaceText(text));

@@ -569,19 +558,12 @@ public class TextViewActivityTest {
        onHandleView(com.android.internal.R.id.insertion_handle)
                .perform(longPressAndDragHandle(textView, Handle.INSERTION, text.indexOf('t')));
        onView(withId(R.id.textview)).check(hasSelection("the world"));

        textView.getEditorForTesting().setCursorControlEnabled(cursorControlEnabled);
        Editor.FLAG_ENABLE_CURSOR_DRAG = cursorDragEnabled;
    }

    @Test
    public void testInsertionHandle_doubleTapToSelect() {
        // This test only makes sense when Cursor Control flag is enabled.
        enableFlagsForInsertionHandleGestures();
        final TextView textView = mActivity.findViewById(R.id.textview);
        boolean cursorControlEnabled = textView.getEditorForTesting().getCursorControlEnabled();
        boolean cursorDragEnabled = Editor.FLAG_ENABLE_CURSOR_DRAG;
        textView.getEditorForTesting().setCursorControlEnabled(true);
        Editor.FLAG_ENABLE_CURSOR_DRAG = true;

        final String text = "hello the world";
        onView(withId(R.id.textview)).perform(replaceText(text));
@@ -591,19 +573,12 @@ public class TextViewActivityTest {

        onHandleView(com.android.internal.R.id.insertion_handle).perform(doubleTapHandle(textView));
        onView(withId(R.id.textview)).check(hasSelection("world"));

        textView.getEditorForTesting().setCursorControlEnabled(cursorControlEnabled);
        Editor.FLAG_ENABLE_CURSOR_DRAG = cursorDragEnabled;
    }

    @Test
    public void testInsertionHandle_doubleTapAndDragToSelect() {
        // This test only makes sense when Cursor Control flag is enabled.
        enableFlagsForInsertionHandleGestures();
        final TextView textView = mActivity.findViewById(R.id.textview);
        boolean cursorControlEnabled = textView.getEditorForTesting().getCursorControlEnabled();
        boolean cursorDragEnabled = Editor.FLAG_ENABLE_CURSOR_DRAG;
        textView.getEditorForTesting().setCursorControlEnabled(true);
        Editor.FLAG_ENABLE_CURSOR_DRAG = true;

        final String text = "hello the world";
        onView(withId(R.id.textview)).perform(replaceText(text));
@@ -614,9 +589,6 @@ public class TextViewActivityTest {
        onHandleView(com.android.internal.R.id.insertion_handle)
                .perform(doubleTapAndDragHandle(textView, Handle.INSERTION, text.indexOf('t')));
        onView(withId(R.id.textview)).check(hasSelection("the world"));

        textView.getEditorForTesting().setCursorControlEnabled(cursorControlEnabled);
        Editor.FLAG_ENABLE_CURSOR_DRAG = cursorDragEnabled;
    }

    @Test
+44 −22
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.am;

import android.annotation.NonNull;
import android.app.ActivityThread;
import android.content.Context;
import android.database.ContentObserver;
@@ -32,6 +33,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Helper class for watching a set of core settings which the framework
@@ -42,16 +44,20 @@ import java.util.Map;
final class CoreSettingsObserver extends ContentObserver {
    private static final String LOG_TAG = CoreSettingsObserver.class.getSimpleName();

    private static class DeviceConfigEntry {
    private static class DeviceConfigEntry<T> {
        String namespace;
        String flag;
        String coreSettingKey;
        Class<?> type;
        DeviceConfigEntry(String namespace, String flag, String coreSettingKey, Class<?> type) {
        Class<T> type;
        T defaultValue;

        DeviceConfigEntry(String namespace, String flag, String coreSettingKey, Class<T> type,
                @NonNull T defaultValue) {
            this.namespace = namespace;
            this.flag = flag;
            this.coreSettingKey = coreSettingKey;
            this.type = type;
            this.defaultValue = Objects.requireNonNull(defaultValue);
        }
    }

@@ -105,24 +111,34 @@ final class CoreSettingsObserver extends ContentObserver {
        sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, String.class);
        // add other global settings here...

        sDeviceConfigEntries.add(new DeviceConfigEntry(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_CURSOR_CONTROL,
                WidgetFlags.KEY_ENABLE_CURSOR_CONTROL, boolean.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
        sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE,
                WidgetFlags.KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE, boolean.class,
                WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES,
                WidgetFlags.KEY_ENABLE_INSERTION_HANDLE_GESTURES, boolean.class,
                WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT,
                WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, int.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, int.class,
                WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_OPACITY,
                WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, int.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, int.class,
                WidgetFlags.INSERTION_HANDLE_OPACITY_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_NEW_MAGNIFIER,
                WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, boolean.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, boolean.class,
                WidgetFlags.ENABLE_NEW_MAGNIFIER_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Float>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ZOOM_FACTOR,
                WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, float.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, float.class,
                WidgetFlags.MAGNIFIER_ZOOM_FACTOR_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Float>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO,
                WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class));
                WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class,
                WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT));
        // add other device configs here...
    }

@@ -216,23 +232,29 @@ final class CoreSettingsObserver extends ContentObserver {
        }
    }

    @SuppressWarnings("unchecked")
    private void populateSettingsFromDeviceConfig() {
        for (DeviceConfigEntry entry : sDeviceConfigEntries) {
        for (DeviceConfigEntry<?> entry : sDeviceConfigEntries) {
            if (entry.type == String.class) {
                String defaultValue = ((DeviceConfigEntry<String>) entry).defaultValue;
                mCoreSettings.putString(entry.coreSettingKey,
                        DeviceConfig.getString(entry.namespace, entry.flag, ""));
                        DeviceConfig.getString(entry.namespace, entry.flag, defaultValue));
            } else if (entry.type == int.class) {
                int defaultValue = ((DeviceConfigEntry<Integer>) entry).defaultValue;
                mCoreSettings.putInt(entry.coreSettingKey,
                        DeviceConfig.getInt(entry.namespace, entry.flag, 0));
                        DeviceConfig.getInt(entry.namespace, entry.flag, defaultValue));
            } else if (entry.type == float.class) {
                float defaultValue = ((DeviceConfigEntry<Float>) entry).defaultValue;
                mCoreSettings.putFloat(entry.coreSettingKey,
                        DeviceConfig.getFloat(entry.namespace, entry.flag, 0));
                        DeviceConfig.getFloat(entry.namespace, entry.flag, defaultValue));
            } else if (entry.type == long.class) {
                long defaultValue = ((DeviceConfigEntry<Long>) entry).defaultValue;
                mCoreSettings.putLong(entry.coreSettingKey,
                        DeviceConfig.getLong(entry.namespace, entry.flag, 0));
                        DeviceConfig.getLong(entry.namespace, entry.flag, defaultValue));
            } else if (entry.type == boolean.class) {
                boolean defaultValue = ((DeviceConfigEntry<Boolean>) entry).defaultValue;
                mCoreSettings.putInt(entry.coreSettingKey,
                        DeviceConfig.getBoolean(entry.namespace, entry.flag, false) ? 1 : 0);
                        DeviceConfig.getBoolean(entry.namespace, entry.flag, defaultValue) ? 1 : 0);
            }
        }
    }