Merge "Use custom action key icon" into udc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
dbec7ba7fb
@@ -17,7 +17,9 @@
|
||||
package com.android.settings.inputmethod;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
/**
|
||||
@@ -41,4 +43,14 @@ public interface KeyboardSettingsFeatureProvider {
|
||||
* @return true if the category is added successfully.
|
||||
*/
|
||||
boolean addFirmwareUpdateCategory(Context context, PreferenceScreen screen);
|
||||
|
||||
/**
|
||||
* Get custom action key icon.
|
||||
*
|
||||
* @param context Context for accessing resources.
|
||||
*
|
||||
* @return Returns the image of the icon, or null if there is no any custom icon.
|
||||
*/
|
||||
@Nullable
|
||||
Drawable getActionKeyIcon(Context context);
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.inputmethod;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@@ -34,4 +35,9 @@ public class KeyboardSettingsFeatureProviderImpl implements KeyboardSettingsFeat
|
||||
public boolean addFirmwareUpdateCategory(Context context, PreferenceScreen screen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getActionKeyIcon(Context context) {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
@@ -39,10 +40,12 @@ import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -60,6 +63,11 @@ public class ModifierKeysPickerDialogFragment extends DialogFragment {
|
||||
private String mKeyDefaultName;
|
||||
private String mKeyFocus;
|
||||
private Activity mActivity;
|
||||
private KeyboardSettingsFeatureProvider mFeatureProvider;
|
||||
private Drawable mActionKeyDrawable;
|
||||
private TextView mLeftBracket;
|
||||
private TextView mRightBracket;
|
||||
private ImageView mActionKeyIcon;
|
||||
|
||||
private List<int[]> mRemappableKeyList =
|
||||
new ArrayList<>(Arrays.asList(
|
||||
@@ -83,6 +91,8 @@ public class ModifierKeysPickerDialogFragment extends DialogFragment {
|
||||
super.onCreateDialog(savedInstanceState);
|
||||
|
||||
mActivity = getActivity();
|
||||
FeatureFactory featureFactory = FeatureFactory.getFactory(mActivity);
|
||||
mFeatureProvider = featureFactory.getKeyboardSettingsFeatureProvider();
|
||||
InputManager inputManager = mActivity.getSystemService(InputManager.class);
|
||||
mKeyDefaultName = getArguments().getString(DEFAULT_KEY);
|
||||
mKeyFocus = getArguments().getString(SELECTION_KEY);
|
||||
@@ -97,6 +107,10 @@ public class ModifierKeysPickerDialogFragment extends DialogFragment {
|
||||
for (int i = 0; i < modifierKeys.size(); i++) {
|
||||
mRemappableKeyMap.put(modifierKeys.get(i), mRemappableKeyList.get(i));
|
||||
}
|
||||
Drawable drawable = mFeatureProvider.getActionKeyIcon(mActivity);
|
||||
if (drawable != null) {
|
||||
mActionKeyDrawable = DrawableCompat.wrap(drawable);
|
||||
}
|
||||
|
||||
View dialoglayout =
|
||||
LayoutInflater.from(mActivity).inflate(R.layout.modifier_key_picker_dialog, null);
|
||||
@@ -226,10 +240,18 @@ public class ModifierKeysPickerDialogFragment extends DialogFragment {
|
||||
checkIcon.setImageAlpha(255);
|
||||
view.setBackground(
|
||||
mActivity.getDrawable(R.drawable.modifier_key_lisetview_background));
|
||||
if (mActionKeyDrawable != null && i == 2) {
|
||||
setActionKeyIcon(view);
|
||||
setActionKeyColor(getColorOfMaterialColorPrimary());
|
||||
}
|
||||
} else {
|
||||
textView.setTextColor(getColorOfTextColorPrimary());
|
||||
checkIcon.setImageAlpha(0);
|
||||
view.setBackground(null);
|
||||
if (mActionKeyDrawable != null && i == 2) {
|
||||
setActionKeyIcon(view);
|
||||
setActionKeyColor(getColorOfTextColorPrimary());
|
||||
}
|
||||
}
|
||||
return view;
|
||||
}
|
||||
@@ -243,6 +265,21 @@ public class ModifierKeysPickerDialogFragment extends DialogFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void setActionKeyIcon(View view) {
|
||||
mLeftBracket = view.findViewById(R.id.modifier_key_left_bracket);
|
||||
mRightBracket = view.findViewById(R.id.modifier_key_right_bracket);
|
||||
mActionKeyIcon = view.findViewById(R.id.modifier_key_action_key_icon);
|
||||
mLeftBracket.setText("(");
|
||||
mRightBracket.setText(")");
|
||||
mActionKeyIcon.setImageDrawable(mActionKeyDrawable);
|
||||
}
|
||||
|
||||
private void setActionKeyColor(int color) {
|
||||
mLeftBracket.setTextColor(color);
|
||||
mRightBracket.setTextColor(color);
|
||||
DrawableCompat.setTint(mActionKeyDrawable, color);
|
||||
}
|
||||
|
||||
private int getColorOfTextColorPrimary() {
|
||||
return Utils.getColorAttrDefaultColor(mActivity, android.R.attr.textColorPrimary);
|
||||
}
|
||||
|
@@ -17,12 +17,16 @@
|
||||
package com.android.settings.inputmethod;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Pair;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
@@ -31,7 +35,9 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -53,6 +59,7 @@ public class ModifierKeysPreferenceController extends BasePreferenceController {
|
||||
private FragmentManager mFragmentManager;
|
||||
private final InputManager mIm;
|
||||
private PreferenceScreen mScreen;
|
||||
private Drawable mDrawable;
|
||||
|
||||
private final List<Integer> mRemappableKeys = new ArrayList<>(
|
||||
Arrays.asList(
|
||||
@@ -61,6 +68,14 @@ public class ModifierKeysPreferenceController extends BasePreferenceController {
|
||||
KeyEvent.KEYCODE_ALT_LEFT, KeyEvent.KEYCODE_ALT_RIGHT,
|
||||
KeyEvent.KEYCODE_CAPS_LOCK));
|
||||
|
||||
private final List<Pair<String, Integer>> mKeys = new ArrayList<>(
|
||||
Arrays.asList(
|
||||
Pair.create(KEY_PREFERENCE_CTRL, R.string.modifier_keys_ctrl),
|
||||
Pair.create(KEY_PREFERENCE_META, R.string.modifier_keys_meta),
|
||||
Pair.create(KEY_PREFERENCE_ALT, R.string.modifier_keys_alt),
|
||||
Pair.create(KEY_PREFERENCE_CAPS_LOCK, R.string.modifier_keys_caps_lock)
|
||||
));
|
||||
|
||||
private String[] mKeyNames = new String[] {
|
||||
mContext.getString(R.string.modifier_keys_ctrl),
|
||||
mContext.getString(R.string.modifier_keys_ctrl),
|
||||
@@ -74,6 +89,9 @@ public class ModifierKeysPreferenceController extends BasePreferenceController {
|
||||
super(context, key);
|
||||
mIm = context.getSystemService(InputManager.class);
|
||||
Objects.requireNonNull(mIm, "InputManager service cannot be null");
|
||||
KeyboardSettingsFeatureProvider featureProvider =
|
||||
FeatureFactory.getFactory(context).getKeyboardSettingsFeatureProvider();
|
||||
mDrawable = featureProvider.getActionKeyIcon(context);
|
||||
}
|
||||
|
||||
public void setFragment(Fragment parent) {
|
||||
@@ -91,33 +109,59 @@ public class ModifierKeysPreferenceController extends BasePreferenceController {
|
||||
}
|
||||
|
||||
private void refreshUi() {
|
||||
initDefaultKeysName();
|
||||
for (Map.Entry<Integer, Integer> entry : mIm.getModifierKeyRemapping().entrySet()) {
|
||||
int fromKey = entry.getKey();
|
||||
int toKey = entry.getValue();
|
||||
int index = mRemappableKeys.indexOf(toKey);
|
||||
|
||||
if (isCtrl(fromKey) && mRemappableKeys.contains(toKey)) {
|
||||
Preference preference = mScreen.findPreference(KEY_PREFERENCE_CTRL);
|
||||
preference.setSummary(changeSummaryColor(mKeyNames[index]));
|
||||
setSummaryColor(KEY_PREFERENCE_CTRL, index);
|
||||
}
|
||||
|
||||
if (isMeta(fromKey) && mRemappableKeys.contains(toKey)) {
|
||||
Preference preference = mScreen.findPreference(KEY_PREFERENCE_META);
|
||||
preference.setSummary(changeSummaryColor(mKeyNames[index]));
|
||||
setSummaryColor(KEY_PREFERENCE_META, index);
|
||||
}
|
||||
|
||||
if (isAlt(fromKey) && mRemappableKeys.contains(toKey)) {
|
||||
Preference preference = mScreen.findPreference(KEY_PREFERENCE_ALT);
|
||||
preference.setSummary(changeSummaryColor(mKeyNames[index]));
|
||||
setSummaryColor(KEY_PREFERENCE_ALT, index);
|
||||
}
|
||||
|
||||
if (isCapLock(fromKey) && mRemappableKeys.contains(toKey)) {
|
||||
Preference preference = mScreen.findPreference(KEY_PREFERENCE_CAPS_LOCK);
|
||||
preference.setSummary(changeSummaryColor(mKeyNames[index]));
|
||||
setSummaryColor(KEY_PREFERENCE_CAPS_LOCK, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initDefaultKeysName() {
|
||||
for (Pair<String, Integer> key : mKeys) {
|
||||
LayoutPreference layoutPreference = mScreen.findPreference(key.first);
|
||||
TextView title = layoutPreference.findViewById(R.id.title);
|
||||
TextView summary = layoutPreference.findViewById(R.id.summary);
|
||||
title.setText(key.second);
|
||||
summary.setText(R.string.modifier_keys_default_summary);
|
||||
|
||||
if (key.first.equals(KEY_PREFERENCE_META) && mDrawable != null) {
|
||||
setActionKeyIcon(layoutPreference, mDrawable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setActionKeyIcon(LayoutPreference preference, Drawable drawable) {
|
||||
TextView leftBracket = preference.findViewById(R.id.modifier_key_left_bracket);
|
||||
TextView rightBracket = preference.findViewById(R.id.modifier_key_right_bracket);
|
||||
ImageView actionKeyIcon = preference.findViewById(R.id.modifier_key_action_key_icon);
|
||||
leftBracket.setText("(");
|
||||
rightBracket.setText(")");
|
||||
actionKeyIcon.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
private void setSummaryColor(String key, int targetIndex) {
|
||||
LayoutPreference layoutPreference = mScreen.findPreference(key);
|
||||
TextView summary = layoutPreference.findViewById(R.id.summary);
|
||||
summary.setText(changeSummaryColor(mKeyNames[targetIndex]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (preference.getKey().equals(KEY_RESTORE_PREFERENCE)) {
|
||||
@@ -137,12 +181,14 @@ public class ModifierKeysPreferenceController extends BasePreferenceController {
|
||||
ModifierKeysPickerDialogFragment fragment = new ModifierKeysPickerDialogFragment();
|
||||
fragment.setTargetFragment(mParent, 0);
|
||||
Bundle bundle = new Bundle();
|
||||
TextView title = ((LayoutPreference) preference).findViewById(R.id.title);
|
||||
TextView summary = ((LayoutPreference) preference).findViewById(R.id.summary);
|
||||
bundle.putString(
|
||||
ModifierKeysPickerDialogFragment.DEFAULT_KEY,
|
||||
preference.getTitle().toString());
|
||||
title.getText().toString());
|
||||
bundle.putString(
|
||||
ModifierKeysPickerDialogFragment.SELECTION_KEY,
|
||||
preference.getSummary().toString());
|
||||
summary.getText().toString());
|
||||
fragment.setArguments(bundle);
|
||||
fragment.show(mFragmentManager, KEY_TAG);
|
||||
}
|
||||
|
Reference in New Issue
Block a user