diff --git a/res/drawable/ic_check_24dp.xml b/res/drawable/ic_check_24dp.xml
index 5801e701e0a..52389013d32 100644
--- a/res/drawable/ic_check_24dp.xml
+++ b/res/drawable/ic_check_24dp.xml
@@ -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">
diff --git a/res/layout/preference_check_icon.xml b/res/layout/preference_check_icon.xml
index 5652ac65997..1b759fcc045 100644
--- a/res/layout/preference_check_icon.xml
+++ b/res/layout/preference_check_icon.xml
@@ -15,7 +15,7 @@
-->
mPreferenceMap;
+ private final Map 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,
diff --git a/src/com/android/settings/regionalpreferences/NumberingSystemItemController.java b/src/com/android/settings/regionalpreferences/NumberingSystemItemController.java
index 8e2d735ce08..8b851b86eb0 100644
--- a/src/com/android/settings/regionalpreferences/NumberingSystemItemController.java
+++ b/src/com/android/settings/regionalpreferences/NumberingSystemItemController.java
@@ -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);
}
}
diff --git a/src/com/android/settings/regionalpreferences/RegionalPreferencesFragment.java b/src/com/android/settings/regionalpreferences/RegionalPreferencesFragment.java
index 03bc8ac5d57..ea9b7b39073 100644
--- a/src/com/android/settings/regionalpreferences/RegionalPreferencesFragment.java
+++ b/src/com/android/settings/regionalpreferences/RegionalPreferencesFragment.java
@@ -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);
diff --git a/src/com/android/settings/regionalpreferences/TickButtonPreference.java b/src/com/android/settings/regionalpreferences/TickButtonPreference.java
deleted file mode 100644
index c01521f548d..00000000000
--- a/src/com/android/settings/regionalpreferences/TickButtonPreference.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/src/com/android/settings/inputmethod/KeyboardLayoutPreference.java b/src/com/android/settings/widget/TickButtonPreference.java
similarity index 61%
rename from src/com/android/settings/inputmethod/KeyboardLayoutPreference.java
rename to src/com/android/settings/widget/TickButtonPreference.java
index f9f858b6bc8..c55da2c1077 100644
--- a/src/com/android/settings/inputmethod/KeyboardLayoutPreference.java
+++ b/src/com/android/settings/widget/TickButtonPreference.java
@@ -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;
}
}
diff --git a/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemItemControllerTest.java b/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemItemControllerTest.java
index 5ec33db8095..708987efc7d 100644
--- a/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemItemControllerTest.java
+++ b/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemItemControllerTest.java
@@ -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;