Loading res/layout/keyboard_layout_picker.xml +7 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,13 @@ android:id="@+id/keyboard_layout_picker_container" android:orientation="vertical"> <ImageView android:id="@+id/keyboard_layout_preview" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitCenter"/> <FrameLayout android:id="@+id/keyboard_layout_title" android:layout_width="match_parent" Loading src/com/android/settings/SettingsPreferenceFragment.java +4 −1 Original line number Diff line number Diff line Loading @@ -479,7 +479,10 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF mDialogFragment.dismiss(); mDialogFragment = null; } getListView().clearOnScrollListeners(); RecyclerView view = getListView(); if (view != null) { view.clearOnScrollListeners(); } } super.onDetach(); } Loading src/com/android/settings/inputmethod/NewKeyboardLayoutPickerContent.java +23 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,20 @@ import com.android.settings.dashboard.DashboardFragment; public class NewKeyboardLayoutPickerContent extends DashboardFragment { private static final String TAG = "KeyboardLayoutPicker"; private NewKeyboardLayoutPickerController mNewKeyboardLayoutPickerController; private ControllerUpdateCallback mControllerUpdateCallback; public interface ControllerUpdateCallback { /** * Called when mNewKeyBoardLayoutPickerController been initialized. */ void onControllerUpdated(NewKeyboardLayoutPickerController newKeyboardLayoutPickerController); } public void setControllerUpdateCallback(ControllerUpdateCallback controllerUpdateCallback) { this.mControllerUpdateCallback = controllerUpdateCallback; } @Override public void onAttach(Context context) { Loading @@ -40,7 +54,11 @@ public class NewKeyboardLayoutPickerContent extends DashboardFragment { getActivity().finish(); return; } use(NewKeyboardLayoutPickerController.class).initialize(this); mNewKeyboardLayoutPickerController = use(NewKeyboardLayoutPickerController.class); mNewKeyboardLayoutPickerController.initialize(this); if (mControllerUpdateCallback != null) { mControllerUpdateCallback.onControllerUpdated(mNewKeyboardLayoutPickerController); } } @Override Loading @@ -56,4 +74,8 @@ public class NewKeyboardLayoutPickerContent extends DashboardFragment { protected int getPreferenceScreenResId() { return R.xml.new_keyboard_layout_picker_fragment; } public NewKeyboardLayoutPickerController getController() { return mNewKeyboardLayoutPickerController; } } src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java +23 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController private String mFinalSelectedLayout; private String mLayout; private MetricsFeatureProvider mMetricsFeatureProvider; private KeyboardLayoutSelectedCallback mKeyboardLayoutSelectedCallback; public NewKeyboardLayoutPickerController(Context context, String key) { super(context, key); Loading Loading @@ -100,7 +101,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController @Override public void onStop() { if (!mLayout.equals(mFinalSelectedLayout)) { if (mLayout != null && !mLayout.equals(mFinalSelectedLayout)) { String change = "From:" + mLayout + ", to:" + mFinalSelectedLayout; mMetricsFeatureProvider.action( mContext, SettingsEnums.ACTION_PK_LAYOUT_CHANGED, change); Loading @@ -121,6 +122,14 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController return AVAILABLE; } /** * Registers {@link KeyboardLayoutSelectedCallback} and get updated. */ public void registerKeyboardSelectedCallback(KeyboardLayoutSelectedCallback keyboardLayoutSelectedCallback) { this.mKeyboardLayoutSelectedCallback = keyboardLayoutSelectedCallback; } @Override public boolean handlePreferenceTreeClick(Preference preference) { if (!(preference instanceof TickButtonPreference)) { Loading @@ -128,6 +137,9 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController } final TickButtonPreference pref = (TickButtonPreference) preference; if (mKeyboardLayoutSelectedCallback != null && mPreferenceMap.containsKey(preference)) { mKeyboardLayoutSelectedCallback.onSelected(mPreferenceMap.get(preference)); } pref.setSelected(true); if (mPreviousSelection != null && !mPreviousSelection.equals(preference.getKey())) { TickButtonPreference preSelectedPref = mScreen.findPreference(mPreviousSelection); Loading Loading @@ -166,6 +178,9 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController pref.setTitle(layout.getLabel()); if (mLayout.equals(layout.getLabel())) { if (mKeyboardLayoutSelectedCallback != null) { mKeyboardLayoutSelectedCallback.onSelected(layout); } pref.setSelected(true); mPreviousSelection = layout.getDescriptor(); } Loading Loading @@ -200,4 +215,11 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController } return label; } public interface KeyboardLayoutSelectedCallback { /** * Called when KeyboardLayout been selected. */ void onSelected(KeyboardLayout keyboardLayout); } } src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java +42 −2 Original line number Diff line number Diff line Loading @@ -16,35 +16,75 @@ package com.android.settings.inputmethod; import static android.view.View.GONE; import static android.view.View.VISIBLE; import android.graphics.drawable.Drawable; import android.hardware.input.InputManager; import android.hardware.input.KeyboardLayout; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import androidx.fragment.app.Fragment; import com.android.settings.R; //TODO: b/316243168 - [Physical Keyboard Setting] Refactor NewKeyboardLayoutPickerFragment public class NewKeyboardLayoutPickerFragment extends Fragment { private static final int DEFAULT_KEYBOARD_PREVIEW_WIDTH = 1630; private static final int DEFAULT_KEYBOARD_PREVIEW_HEIGHT = 540; private ImageView mKeyboardLayoutPreview; private InputManager mInputManager; private final NewKeyboardLayoutPickerController.KeyboardLayoutSelectedCallback mKeyboardLayoutSelectedCallback = new NewKeyboardLayoutPickerController.KeyboardLayoutSelectedCallback() { @Override public void onSelected(KeyboardLayout keyboardLayout) { if (mInputManager != null && mKeyboardLayoutPreview != null) { Drawable previewDrawable = mInputManager.getKeyboardLayoutPreview( keyboardLayout, DEFAULT_KEYBOARD_PREVIEW_WIDTH, DEFAULT_KEYBOARD_PREVIEW_HEIGHT); mKeyboardLayoutPreview.setVisibility( previewDrawable == null ? GONE : VISIBLE); if (previewDrawable != null) { mKeyboardLayoutPreview.setImageDrawable(previewDrawable); } } } }; private final NewKeyboardLayoutPickerContent.ControllerUpdateCallback mControllerUpdateCallback = newKeyboardLayoutPickerController -> { if (newKeyboardLayoutPickerController != null) { newKeyboardLayoutPickerController.registerKeyboardSelectedCallback( mKeyboardLayoutSelectedCallback); } }; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mInputManager = requireContext().getSystemService(InputManager.class); ViewGroup fragmentView = (ViewGroup) inflater.inflate( R.layout.keyboard_layout_picker, container, false); mKeyboardLayoutPreview = fragmentView.findViewById(R.id.keyboard_layout_preview); getActivity().getSupportFragmentManager() .beginTransaction() .replace(R.id.keyboard_layout_title, new NewKeyboardLayoutPickerTitle()) .commit(); NewKeyboardLayoutPickerContent fragment = new NewKeyboardLayoutPickerContent(); fragment.setControllerUpdateCallback(mControllerUpdateCallback); fragment.setArguments(getArguments()); getActivity().getSupportFragmentManager() .beginTransaction() .replace(R.id.keyboard_layouts, fragment) .commit(); return fragmentView; } } Loading
res/layout/keyboard_layout_picker.xml +7 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,13 @@ android:id="@+id/keyboard_layout_picker_container" android:orientation="vertical"> <ImageView android:id="@+id/keyboard_layout_preview" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitCenter"/> <FrameLayout android:id="@+id/keyboard_layout_title" android:layout_width="match_parent" Loading
src/com/android/settings/SettingsPreferenceFragment.java +4 −1 Original line number Diff line number Diff line Loading @@ -479,7 +479,10 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF mDialogFragment.dismiss(); mDialogFragment = null; } getListView().clearOnScrollListeners(); RecyclerView view = getListView(); if (view != null) { view.clearOnScrollListeners(); } } super.onDetach(); } Loading
src/com/android/settings/inputmethod/NewKeyboardLayoutPickerContent.java +23 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,20 @@ import com.android.settings.dashboard.DashboardFragment; public class NewKeyboardLayoutPickerContent extends DashboardFragment { private static final String TAG = "KeyboardLayoutPicker"; private NewKeyboardLayoutPickerController mNewKeyboardLayoutPickerController; private ControllerUpdateCallback mControllerUpdateCallback; public interface ControllerUpdateCallback { /** * Called when mNewKeyBoardLayoutPickerController been initialized. */ void onControllerUpdated(NewKeyboardLayoutPickerController newKeyboardLayoutPickerController); } public void setControllerUpdateCallback(ControllerUpdateCallback controllerUpdateCallback) { this.mControllerUpdateCallback = controllerUpdateCallback; } @Override public void onAttach(Context context) { Loading @@ -40,7 +54,11 @@ public class NewKeyboardLayoutPickerContent extends DashboardFragment { getActivity().finish(); return; } use(NewKeyboardLayoutPickerController.class).initialize(this); mNewKeyboardLayoutPickerController = use(NewKeyboardLayoutPickerController.class); mNewKeyboardLayoutPickerController.initialize(this); if (mControllerUpdateCallback != null) { mControllerUpdateCallback.onControllerUpdated(mNewKeyboardLayoutPickerController); } } @Override Loading @@ -56,4 +74,8 @@ public class NewKeyboardLayoutPickerContent extends DashboardFragment { protected int getPreferenceScreenResId() { return R.xml.new_keyboard_layout_picker_fragment; } public NewKeyboardLayoutPickerController getController() { return mNewKeyboardLayoutPickerController; } }
src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java +23 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController private String mFinalSelectedLayout; private String mLayout; private MetricsFeatureProvider mMetricsFeatureProvider; private KeyboardLayoutSelectedCallback mKeyboardLayoutSelectedCallback; public NewKeyboardLayoutPickerController(Context context, String key) { super(context, key); Loading Loading @@ -100,7 +101,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController @Override public void onStop() { if (!mLayout.equals(mFinalSelectedLayout)) { if (mLayout != null && !mLayout.equals(mFinalSelectedLayout)) { String change = "From:" + mLayout + ", to:" + mFinalSelectedLayout; mMetricsFeatureProvider.action( mContext, SettingsEnums.ACTION_PK_LAYOUT_CHANGED, change); Loading @@ -121,6 +122,14 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController return AVAILABLE; } /** * Registers {@link KeyboardLayoutSelectedCallback} and get updated. */ public void registerKeyboardSelectedCallback(KeyboardLayoutSelectedCallback keyboardLayoutSelectedCallback) { this.mKeyboardLayoutSelectedCallback = keyboardLayoutSelectedCallback; } @Override public boolean handlePreferenceTreeClick(Preference preference) { if (!(preference instanceof TickButtonPreference)) { Loading @@ -128,6 +137,9 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController } final TickButtonPreference pref = (TickButtonPreference) preference; if (mKeyboardLayoutSelectedCallback != null && mPreferenceMap.containsKey(preference)) { mKeyboardLayoutSelectedCallback.onSelected(mPreferenceMap.get(preference)); } pref.setSelected(true); if (mPreviousSelection != null && !mPreviousSelection.equals(preference.getKey())) { TickButtonPreference preSelectedPref = mScreen.findPreference(mPreviousSelection); Loading Loading @@ -166,6 +178,9 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController pref.setTitle(layout.getLabel()); if (mLayout.equals(layout.getLabel())) { if (mKeyboardLayoutSelectedCallback != null) { mKeyboardLayoutSelectedCallback.onSelected(layout); } pref.setSelected(true); mPreviousSelection = layout.getDescriptor(); } Loading Loading @@ -200,4 +215,11 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController } return label; } public interface KeyboardLayoutSelectedCallback { /** * Called when KeyboardLayout been selected. */ void onSelected(KeyboardLayout keyboardLayout); } }
src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java +42 −2 Original line number Diff line number Diff line Loading @@ -16,35 +16,75 @@ package com.android.settings.inputmethod; import static android.view.View.GONE; import static android.view.View.VISIBLE; import android.graphics.drawable.Drawable; import android.hardware.input.InputManager; import android.hardware.input.KeyboardLayout; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import androidx.fragment.app.Fragment; import com.android.settings.R; //TODO: b/316243168 - [Physical Keyboard Setting] Refactor NewKeyboardLayoutPickerFragment public class NewKeyboardLayoutPickerFragment extends Fragment { private static final int DEFAULT_KEYBOARD_PREVIEW_WIDTH = 1630; private static final int DEFAULT_KEYBOARD_PREVIEW_HEIGHT = 540; private ImageView mKeyboardLayoutPreview; private InputManager mInputManager; private final NewKeyboardLayoutPickerController.KeyboardLayoutSelectedCallback mKeyboardLayoutSelectedCallback = new NewKeyboardLayoutPickerController.KeyboardLayoutSelectedCallback() { @Override public void onSelected(KeyboardLayout keyboardLayout) { if (mInputManager != null && mKeyboardLayoutPreview != null) { Drawable previewDrawable = mInputManager.getKeyboardLayoutPreview( keyboardLayout, DEFAULT_KEYBOARD_PREVIEW_WIDTH, DEFAULT_KEYBOARD_PREVIEW_HEIGHT); mKeyboardLayoutPreview.setVisibility( previewDrawable == null ? GONE : VISIBLE); if (previewDrawable != null) { mKeyboardLayoutPreview.setImageDrawable(previewDrawable); } } } }; private final NewKeyboardLayoutPickerContent.ControllerUpdateCallback mControllerUpdateCallback = newKeyboardLayoutPickerController -> { if (newKeyboardLayoutPickerController != null) { newKeyboardLayoutPickerController.registerKeyboardSelectedCallback( mKeyboardLayoutSelectedCallback); } }; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mInputManager = requireContext().getSystemService(InputManager.class); ViewGroup fragmentView = (ViewGroup) inflater.inflate( R.layout.keyboard_layout_picker, container, false); mKeyboardLayoutPreview = fragmentView.findViewById(R.id.keyboard_layout_preview); getActivity().getSupportFragmentManager() .beginTransaction() .replace(R.id.keyboard_layout_title, new NewKeyboardLayoutPickerTitle()) .commit(); NewKeyboardLayoutPickerContent fragment = new NewKeyboardLayoutPickerContent(); fragment.setControllerUpdateCallback(mControllerUpdateCallback); fragment.setArguments(getArguments()); getActivity().getSupportFragmentManager() .beginTransaction() .replace(R.id.keyboard_layouts, fragment) .commit(); return fragmentView; } }