Unify Tick Preference from Physic keyboard and Regional preference
- Also change icon color from colorAccentPrimaryVarient to colorAccentPrimary Bug: b/272398108 Bug: b/264476709 Test: Manual test. Change-Id: Ide602c6fb9501b832df646692ec618be8a76e7b9
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.inputmethod;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class KeyboardLayoutPreference extends Preference {
|
||||
|
||||
private ImageView mCheckIcon;
|
||||
private boolean mIsMark;
|
||||
|
||||
public KeyboardLayoutPreference(Context context, String layoutName, boolean defaultMark) {
|
||||
super(context);
|
||||
setWidgetLayoutResource(R.layout.preference_check_icon);
|
||||
setTitle(layoutName);
|
||||
mIsMark = defaultMark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
mCheckIcon = (ImageView) holder.findViewById(R.id.keyboard_check_icon);
|
||||
setCheckMark(mIsMark);
|
||||
}
|
||||
|
||||
public void setCheckMark(boolean isMark) {
|
||||
if (mCheckIcon != null) {
|
||||
mCheckIcon.setVisibility(isMark ? View.VISIBLE : View.INVISIBLE);
|
||||
mIsMark = isMark;
|
||||
}
|
||||
}
|
||||
}
|
@@ -28,6 +28,7 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.widget.TickButtonPreference;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
@@ -38,7 +39,7 @@ import java.util.Map;
|
||||
public class NewKeyboardLayoutPickerController extends BasePreferenceController implements
|
||||
InputManager.InputDeviceListener, LifecycleObserver, OnStart, OnStop {
|
||||
private final InputManager mIm;
|
||||
private final Map<KeyboardLayoutPreference, KeyboardLayout> mPreferenceMap;
|
||||
private final Map<TickButtonPreference, KeyboardLayout> mPreferenceMap;
|
||||
|
||||
private Fragment mParent;
|
||||
private int mInputDeviceId;
|
||||
@@ -102,16 +103,15 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
|
||||
if (!(preference instanceof KeyboardLayoutPreference)) {
|
||||
if (!(preference instanceof TickButtonPreference)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final KeyboardLayoutPreference pref = (KeyboardLayoutPreference) preference;
|
||||
pref.setCheckMark(true);
|
||||
final TickButtonPreference pref = (TickButtonPreference) preference;
|
||||
pref.setSelected(true);
|
||||
if (mPreviousSelection != null && !mPreviousSelection.equals(preference.getKey())) {
|
||||
KeyboardLayoutPreference preSelectedPref = mScreen.findPreference(mPreviousSelection);
|
||||
preSelectedPref.setCheckMark(false);
|
||||
TickButtonPreference preSelectedPref = mScreen.findPreference(mPreviousSelection);
|
||||
preSelectedPref.setSelected(false);
|
||||
}
|
||||
setLayout(pref);
|
||||
mPreviousSelection = preference.getKey();
|
||||
@@ -140,12 +140,13 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
||||
return;
|
||||
}
|
||||
for (KeyboardLayout layout : mKeyboardLayouts) {
|
||||
final KeyboardLayoutPreference pref;
|
||||
final TickButtonPreference pref;
|
||||
pref = new TickButtonPreference(mScreen.getContext());
|
||||
pref.setTitle(layout.getLabel());
|
||||
|
||||
if (mLayout.equals(layout.getLabel())) {
|
||||
pref = new KeyboardLayoutPreference(mScreen.getContext(), layout.getLabel(), true);
|
||||
pref.setSelected(true);
|
||||
mPreviousSelection = layout.getDescriptor();
|
||||
} else {
|
||||
pref = new KeyboardLayoutPreference(mScreen.getContext(), layout.getLabel(), false);
|
||||
}
|
||||
pref.setKey(layout.getDescriptor());
|
||||
mScreen.addPreference(pref);
|
||||
@@ -153,7 +154,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
||||
}
|
||||
}
|
||||
|
||||
private void setLayout(KeyboardLayoutPreference preference) {
|
||||
private void setLayout(TickButtonPreference preference) {
|
||||
mIm.setKeyboardLayoutForInputDevice(
|
||||
mInputDeviceIdentifier,
|
||||
mUserId,
|
||||
|
Reference in New Issue
Block a user