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:
tom hsu
2023-03-29 21:28:25 +08:00
parent e78b3d3f7e
commit 23359bc0e9
8 changed files with 42 additions and 102 deletions

View File

@@ -0,0 +1,57 @@
/*
* 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.
* 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.widget;
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;
/** A preference with tick icon. */
public class TickButtonPreference extends Preference {
private ImageView mCheckIcon;
private boolean mIsSelected = false;
public TickButtonPreference(Context context) {
super(context);
setWidgetLayoutResource(R.layout.preference_check_icon);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
mCheckIcon = (ImageView) holder.findViewById(R.id.check_icon);
setSelected(mIsSelected);
}
/** Set icon state.*/
public void setSelected(boolean isSelected) {
if (mCheckIcon != null) {
mCheckIcon.setVisibility(isSelected ? View.VISIBLE : View.INVISIBLE);
}
mIsSelected = isSelected;
}
/** Return state of presenting icon. */
public boolean isSelected() {
return mIsSelected;
}
}