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:
@@ -18,7 +18,7 @@
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?androidprv:attr/colorAccentPrimaryVariant">
|
||||
android:tint="?androidprv:attr/colorAccent">
|
||||
<path
|
||||
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"
|
||||
android:fillColor="@android:color/white"/>
|
||||
|
@@ -15,7 +15,7 @@
|
||||
-->
|
||||
<ImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/keyboard_check_icon"
|
||||
android:id="@+id/check_icon"
|
||||
android:src="@drawable/ic_check_24dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@@ -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,
|
||||
|
@@ -34,6 +34,7 @@ import com.android.internal.app.LocaleStore;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.widget.TickButtonPreference;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -138,7 +139,7 @@ public class NumberingSystemItemController extends BasePreferenceController {
|
||||
String key = supportedLocale.getUnicodeLocaleType(
|
||||
ExtensionTypes.NUMBERING_SYSTEM);
|
||||
pref.setKey(key == null ? RegionalPreferencesDataUtils.DEFAULT_VALUE : key);
|
||||
pref.setTickEnable(isSameNumberingSystem(targetLocale, supportedLocale));
|
||||
pref.setSelected(isSameNumberingSystem(targetLocale, supportedLocale));
|
||||
screen.addPreference(pref);
|
||||
}
|
||||
}
|
||||
@@ -162,7 +163,7 @@ public class NumberingSystemItemController extends BasePreferenceController {
|
||||
TickButtonPreference pref = (TickButtonPreference) mPreferenceScreen.getPreference(i);
|
||||
Log.i(TAG, "[onPreferenceClick] key is " + pref.getKey());
|
||||
if (pref.getKey().equals(preference.getKey())) {
|
||||
pref.setTickEnable(true);
|
||||
pref.setSelected(true);
|
||||
Locale updatedLocale =
|
||||
saveNumberingSystemToLocale(
|
||||
Locale.forLanguageTag(mSelectedLanguage), pref.getKey());
|
||||
@@ -176,7 +177,7 @@ public class NumberingSystemItemController extends BasePreferenceController {
|
||||
mParentFragment.setArguments(bundle);
|
||||
continue;
|
||||
}
|
||||
pref.setTickEnable(false);
|
||||
pref.setSelected(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -29,6 +29,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.widget.TickButtonPreference;
|
||||
|
||||
/** A fragment to include each kind of regional preferences. */
|
||||
public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
|
||||
@@ -63,7 +64,7 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
|
||||
TickButtonPreference pref = (TickButtonPreference) mPreferenceScreen.getPreference(i);
|
||||
Log.i(TAG, "[onPreferenceClick] key is " + pref.getKey());
|
||||
if (pref.getKey().equals(preference.getKey())) {
|
||||
pref.setTickEnable(true);
|
||||
pref.setSelected(true);
|
||||
RegionalPreferencesDataUtils.savePreference(
|
||||
getPrefContext(),
|
||||
mType,
|
||||
@@ -72,7 +73,7 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
|
||||
? null : preference.getKey());
|
||||
continue;
|
||||
}
|
||||
pref.setTickEnable(false);
|
||||
pref.setSelected(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -115,7 +116,7 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
|
||||
String value = RegionalPreferencesDataUtils.getDefaultUnicodeExtensionData(
|
||||
getPrefContext(), mType);
|
||||
pref.setKey(item);
|
||||
pref.setTickEnable(!value.isEmpty() && item.equals(value));
|
||||
pref.setSelected(!value.isEmpty() && item.equals(value));
|
||||
mPreferenceScreen.addPreference(pref);
|
||||
}
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
@@ -1,69 +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.regionalpreferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.TwoTargetPreference;
|
||||
|
||||
/** A preference with tick button */
|
||||
public class TickButtonPreference extends TwoTargetPreference {
|
||||
private static final String TAG = TickButtonPreference.class.getSimpleName();
|
||||
private boolean mIsTickEnabled;
|
||||
private View mWidgetFrame;
|
||||
private View mDivider;
|
||||
|
||||
public TickButtonPreference(Context context) {
|
||||
super(context, null);
|
||||
}
|
||||
|
||||
/** Set this preference to be selected. */
|
||||
public void setTickEnable(boolean isEnable) {
|
||||
mIsTickEnabled = isEnable;
|
||||
if (mWidgetFrame != null) {
|
||||
mWidgetFrame.setVisibility(isEnable ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/** Check if this preference is selected. */
|
||||
public boolean isTickEnabled() {
|
||||
return mIsTickEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
mDivider = holder.findViewById(R.id.two_target_divider);
|
||||
mWidgetFrame = holder.findViewById(android.R.id.widget_frame);
|
||||
if (mDivider != null) {
|
||||
mDivider.setVisibility(View.GONE);
|
||||
}
|
||||
if (mWidgetFrame != null) {
|
||||
mWidgetFrame.setVisibility(mIsTickEnabled ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
super.getSecondTargetResId();
|
||||
return R.layout.preference_widget_tick;
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* Copyright (C) 2023 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.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.inputmethod;
|
||||
package com.android.settings.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
@@ -25,29 +25,33 @@ import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class KeyboardLayoutPreference extends Preference {
|
||||
|
||||
/** A preference with tick icon. */
|
||||
public class TickButtonPreference extends Preference {
|
||||
private ImageView mCheckIcon;
|
||||
private boolean mIsMark;
|
||||
private boolean mIsSelected = false;
|
||||
|
||||
public KeyboardLayoutPreference(Context context, String layoutName, boolean defaultMark) {
|
||||
public TickButtonPreference(Context context) {
|
||||
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);
|
||||
mCheckIcon = (ImageView) holder.findViewById(R.id.check_icon);
|
||||
setSelected(mIsSelected);
|
||||
}
|
||||
|
||||
public void setCheckMark(boolean isMark) {
|
||||
/** Set icon state.*/
|
||||
public void setSelected(boolean isSelected) {
|
||||
if (mCheckIcon != null) {
|
||||
mCheckIcon.setVisibility(isMark ? View.VISIBLE : View.INVISIBLE);
|
||||
mIsMark = isMark;
|
||||
mCheckIcon.setVisibility(isSelected ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
mIsSelected = isSelected;
|
||||
}
|
||||
|
||||
/** Return state of presenting icon. */
|
||||
public boolean isSelected() {
|
||||
return mIsSelected;
|
||||
}
|
||||
}
|
@@ -33,6 +33,8 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.widget.TickButtonPreference;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
Reference in New Issue
Block a user