Merge "[PK Setting] add keyboard review under keyboard selection page" into main
This commit is contained in:
@@ -20,6 +20,13 @@
|
|||||||
android:id="@+id/keyboard_layout_picker_container"
|
android:id="@+id/keyboard_layout_picker_container"
|
||||||
android:orientation="vertical">
|
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
|
<FrameLayout
|
||||||
android:id="@+id/keyboard_layout_title"
|
android:id="@+id/keyboard_layout_title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@@ -479,7 +479,10 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
|||||||
mDialogFragment.dismiss();
|
mDialogFragment.dismiss();
|
||||||
mDialogFragment = null;
|
mDialogFragment = null;
|
||||||
}
|
}
|
||||||
getListView().clearOnScrollListeners();
|
RecyclerView view = getListView();
|
||||||
|
if (view != null) {
|
||||||
|
view.clearOnScrollListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,20 @@ import com.android.settings.dashboard.DashboardFragment;
|
|||||||
public class NewKeyboardLayoutPickerContent extends DashboardFragment {
|
public class NewKeyboardLayoutPickerContent extends DashboardFragment {
|
||||||
|
|
||||||
private static final String TAG = "KeyboardLayoutPicker";
|
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
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
@@ -40,7 +54,11 @@ public class NewKeyboardLayoutPickerContent extends DashboardFragment {
|
|||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
use(NewKeyboardLayoutPickerController.class).initialize(this);
|
mNewKeyboardLayoutPickerController = use(NewKeyboardLayoutPickerController.class);
|
||||||
|
mNewKeyboardLayoutPickerController.initialize(this);
|
||||||
|
if (mControllerUpdateCallback != null) {
|
||||||
|
mControllerUpdateCallback.onControllerUpdated(mNewKeyboardLayoutPickerController);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,4 +74,8 @@ public class NewKeyboardLayoutPickerContent extends DashboardFragment {
|
|||||||
protected int getPreferenceScreenResId() {
|
protected int getPreferenceScreenResId() {
|
||||||
return R.xml.new_keyboard_layout_picker_fragment;
|
return R.xml.new_keyboard_layout_picker_fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NewKeyboardLayoutPickerController getController() {
|
||||||
|
return mNewKeyboardLayoutPickerController;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -59,6 +59,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
private String mFinalSelectedLayout;
|
private String mFinalSelectedLayout;
|
||||||
private String mLayout;
|
private String mLayout;
|
||||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
private KeyboardLayoutSelectedCallback mKeyboardLayoutSelectedCallback;
|
||||||
|
|
||||||
public NewKeyboardLayoutPickerController(Context context, String key) {
|
public NewKeyboardLayoutPickerController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
@@ -100,7 +101,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
if (!mLayout.equals(mFinalSelectedLayout)) {
|
if (mLayout != null && !mLayout.equals(mFinalSelectedLayout)) {
|
||||||
String change = "From:" + mLayout + ", to:" + mFinalSelectedLayout;
|
String change = "From:" + mLayout + ", to:" + mFinalSelectedLayout;
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(
|
||||||
mContext, SettingsEnums.ACTION_PK_LAYOUT_CHANGED, change);
|
mContext, SettingsEnums.ACTION_PK_LAYOUT_CHANGED, change);
|
||||||
@@ -121,6 +122,14 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers {@link KeyboardLayoutSelectedCallback} and get updated.
|
||||||
|
*/
|
||||||
|
public void registerKeyboardSelectedCallback(KeyboardLayoutSelectedCallback
|
||||||
|
keyboardLayoutSelectedCallback) {
|
||||||
|
this.mKeyboardLayoutSelectedCallback = keyboardLayoutSelectedCallback;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (!(preference instanceof TickButtonPreference)) {
|
if (!(preference instanceof TickButtonPreference)) {
|
||||||
@@ -128,6 +137,9 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
final TickButtonPreference pref = (TickButtonPreference) preference;
|
final TickButtonPreference pref = (TickButtonPreference) preference;
|
||||||
|
if (mKeyboardLayoutSelectedCallback != null && mPreferenceMap.containsKey(preference)) {
|
||||||
|
mKeyboardLayoutSelectedCallback.onSelected(mPreferenceMap.get(preference));
|
||||||
|
}
|
||||||
pref.setSelected(true);
|
pref.setSelected(true);
|
||||||
if (mPreviousSelection != null && !mPreviousSelection.equals(preference.getKey())) {
|
if (mPreviousSelection != null && !mPreviousSelection.equals(preference.getKey())) {
|
||||||
TickButtonPreference preSelectedPref = mScreen.findPreference(mPreviousSelection);
|
TickButtonPreference preSelectedPref = mScreen.findPreference(mPreviousSelection);
|
||||||
@@ -166,6 +178,9 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
pref.setTitle(layout.getLabel());
|
pref.setTitle(layout.getLabel());
|
||||||
|
|
||||||
if (mLayout.equals(layout.getLabel())) {
|
if (mLayout.equals(layout.getLabel())) {
|
||||||
|
if (mKeyboardLayoutSelectedCallback != null) {
|
||||||
|
mKeyboardLayoutSelectedCallback.onSelected(layout);
|
||||||
|
}
|
||||||
pref.setSelected(true);
|
pref.setSelected(true);
|
||||||
mPreviousSelection = layout.getDescriptor();
|
mPreviousSelection = layout.getDescriptor();
|
||||||
}
|
}
|
||||||
@@ -200,4 +215,11 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
}
|
}
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface KeyboardLayoutSelectedCallback {
|
||||||
|
/**
|
||||||
|
* Called when KeyboardLayout been selected.
|
||||||
|
*/
|
||||||
|
void onSelected(KeyboardLayout keyboardLayout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,35 +16,75 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
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.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
//TODO: b/316243168 - [Physical Keyboard Setting] Refactor NewKeyboardLayoutPickerFragment
|
||||||
public class NewKeyboardLayoutPickerFragment extends Fragment {
|
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
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
mInputManager = requireContext().getSystemService(InputManager.class);
|
||||||
ViewGroup fragmentView = (ViewGroup) inflater.inflate(
|
ViewGroup fragmentView = (ViewGroup) inflater.inflate(
|
||||||
R.layout.keyboard_layout_picker, container, false);
|
R.layout.keyboard_layout_picker, container, false);
|
||||||
|
mKeyboardLayoutPreview = fragmentView.findViewById(R.id.keyboard_layout_preview);
|
||||||
getActivity().getSupportFragmentManager()
|
getActivity().getSupportFragmentManager()
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(R.id.keyboard_layout_title, new NewKeyboardLayoutPickerTitle())
|
.replace(R.id.keyboard_layout_title, new NewKeyboardLayoutPickerTitle())
|
||||||
.commit();
|
.commit();
|
||||||
|
|
||||||
NewKeyboardLayoutPickerContent fragment = new NewKeyboardLayoutPickerContent();
|
NewKeyboardLayoutPickerContent fragment = new NewKeyboardLayoutPickerContent();
|
||||||
|
fragment.setControllerUpdateCallback(mControllerUpdateCallback);
|
||||||
fragment.setArguments(getArguments());
|
fragment.setArguments(getArguments());
|
||||||
getActivity().getSupportFragmentManager()
|
getActivity().getSupportFragmentManager()
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(R.id.keyboard_layouts, fragment)
|
.replace(R.id.keyboard_layouts, fragment)
|
||||||
.commit();
|
.commit();
|
||||||
|
|
||||||
return fragmentView;
|
return fragmentView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user