Merge "Migrate to CompoundButton" into main

This commit is contained in:
Chaohui Wang
2023-10-25 10:48:16 +00:00
committed by Android (Google) Code Review
9 changed files with 24 additions and 36 deletions

View File

@@ -52,13 +52,13 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.CompoundButton;
import android.widget.ExpandableListView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -456,10 +456,10 @@ public class TrustedCredentialsFragment extends ObservableFragment
return "Group" + getUserIdByGroup(groupPosition);
}
private class ViewHolder {
private static class ViewHolder {
private TextView mSubjectPrimaryView;
private TextView mSubjectSecondaryView;
private Switch mSwitch;
private CompoundButton mSwitch;
}
}

View File

@@ -21,8 +21,8 @@ import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
@@ -88,7 +88,7 @@ public class ShortcutPreference extends Preference {
mSettingsEditable ? outValue.resourceId : /* Remove background */ 0);
}
Switch switchWidget =
CompoundButton switchWidget =
holder.itemView.findViewById(com.android.settingslib.R.id.switchWidget);
if (switchWidget != null) {
// Consumes move events to ignore drag actions.

View File

@@ -29,9 +29,9 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
import androidx.fragment.app.ListFragment;
@@ -244,14 +244,12 @@ public class AppOpsCategory extends ListFragment implements
public static class AppListAdapter extends BaseAdapter {
private final Resources mResources;
private final LayoutInflater mInflater;
private final AppOpsState mState;
List<AppOpEntry> mList;
public AppListAdapter(Context context, AppOpsState state) {
public AppListAdapter(Context context) {
mResources = context.getResources();
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mState = state;
}
public void setData(List<AppOpEntry> data) {
@@ -294,7 +292,7 @@ public class AppOpsCategory extends ListFragment implements
((TextView) view.findViewById(R.id.op_name)).setText(
item.getTimeText(mResources, false));
view.findViewById(R.id.op_time).setVisibility(View.GONE);
((Switch) view.findViewById(R.id.op_switch)).setChecked(
((CompoundButton) view.findViewById(R.id.op_switch)).setChecked(
item.getPrimaryOpMode() == AppOpsManager.MODE_ALLOWED);
return view;
@@ -318,7 +316,7 @@ public class AppOpsCategory extends ListFragment implements
setHasOptionsMenu(true);
// Create an empty adapter we will use to display the loaded data.
mAdapter = new AppListAdapter(getActivity(), mState);
mAdapter = new AppListAdapter(getActivity());
setListAdapter(mAdapter);
// Start out with a progress indicator.
@@ -332,7 +330,7 @@ public class AppOpsCategory extends ListFragment implements
AppOpEntry entry = mAdapter.getItem(position);
if (entry != null) {
// We treat this as tapping on the check box, toggling the app op state.
Switch sw = v.findViewById(R.id.op_switch);
CompoundButton sw = v.findViewById(R.id.op_switch);
boolean checked = !sw.isChecked();
sw.setChecked(checked);
AppOpsManager.OpEntry op = entry.getOpEntry(0);

View File

@@ -47,7 +47,7 @@ import android.service.autofill.AutofillServiceInfo;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Switch;
import android.widget.CompoundButton;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
@@ -969,7 +969,7 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
}
// Stores a reference to the switch view.
private @Nullable Switch mSwitch;
private @Nullable CompoundButton mSwitch;
// Switch text for on and off states
private @NonNull boolean mChecked = false;
@@ -1022,7 +1022,7 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
// Setup the switch.
View checkableView =
view.itemView.findViewById(com.android.settingslib.R.id.switchWidget);
if (checkableView instanceof Switch switchView) {
if (checkableView instanceof CompoundButton switchView) {
switchView.setChecked(mChecked);
switchView.setOnClickListener(mListener);

View File

@@ -31,9 +31,9 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.StringRes;
@@ -67,7 +67,7 @@ public class ApplicationViewHolder extends RecyclerView.ViewHolder {
@VisibleForTesting
final ViewGroup mWidgetContainer;
@VisibleForTesting
final Switch mSwitch;
final CompoundButton mSwitch;
final ImageView mAddIcon;
final ProgressBar mProgressBar;
@@ -173,10 +173,6 @@ public class ApplicationViewHolder extends RecyclerView.ViewHolder {
mAppName.setContentDescription(contentDescription);
}
void setIcon(int drawableRes) {
mAppIcon.setImageResource(drawableRes);
}
void setIcon(Drawable icon) {
if (icon == null) {
return;
@@ -219,7 +215,8 @@ public class ApplicationViewHolder extends RecyclerView.ViewHolder {
}
}
void updateSwitch(Switch.OnCheckedChangeListener listener, boolean enabled, boolean checked) {
void updateSwitch(CompoundButton.OnCheckedChangeListener listener, boolean enabled,
boolean checked) {
if (mSwitch != null && mWidgetContainer != null) {
mWidgetContainer.setFocusable(false);
mWidgetContainer.setClickable(false);

View File

@@ -22,7 +22,6 @@ import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import com.android.settings.R;
@@ -32,7 +31,7 @@ import com.android.settings.R;
*/
public class FaceEnrollAccessibilityToggle extends LinearLayout {
private Switch mSwitch;
private final CompoundButton mSwitch;
public FaceEnrollAccessibilityToggle(Context context) {
this(context, null /* attrs */);
@@ -76,7 +75,7 @@ public class FaceEnrollAccessibilityToggle extends LinearLayout {
mSwitch.setOnCheckedChangeListener(listener);
}
public Switch getSwitch() {
public CompoundButton getSwitch() {
return mSwitch;
}
}

View File

@@ -32,8 +32,8 @@ import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
@@ -342,8 +342,8 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
TextView pairingViewCaption = (TextView) view.findViewById(R.id.pairing_caption);
TextView pairingViewContent = (TextView) view.findViewById(R.id.pairing_subhead);
TextView messagePairing = (TextView) view.findViewById(R.id.pairing_code_message);
Switch contactSharing = (Switch) view.findViewById(
R.id.phonebook_sharing_message_confirm_pin);
CompoundButton contactSharing =
view.findViewById(R.id.phonebook_sharing_message_confirm_pin);
view.findViewById(R.id.phonebook_sharing).setVisibility(
mPairingController.isContactSharingVisible() ? View.VISIBLE : View.GONE);
mPairingController.setContactSharingState();

View File

@@ -35,7 +35,6 @@ import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
@@ -45,7 +44,7 @@ import com.android.settings.R;
public class TareHomePage extends Activity {
private static final String TAG = "TareHomePage";
private Switch mOnSwitch;
private CompoundButton mOnSwitch;
private Button mRevButton;
private TextView mAlarmManagerView;
private TextView mJobSchedulerView;

View File

@@ -45,7 +45,6 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import androidx.preference.ListPreference;
import androidx.preference.MultiSelectListPreference;
@@ -175,10 +174,6 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
panelOpen = open;
}
List<Preference> getChildren() {
return mChildren;
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
@@ -197,7 +192,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
ViewGroup widget = (ViewGroup) view.findViewById(android.R.id.widget_frame);
widget.setEnabled(!isImmutable());
if (widget.getChildCount() > 0) {
final Switch toggle = (Switch) widget.getChildAt(0);
final CompoundButton toggle = (CompoundButton) widget.getChildAt(0);
toggle.setEnabled(!isImmutable());
toggle.setTag(this);
toggle.setClickable(true);