Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27dd2230 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Migrate to CompoundButton" into main

parents 2260edba c4a3a50d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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;
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -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.
+5 −7
Original line number Diff line number Diff line
@@ -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);
+3 −3
Original line number Diff line number Diff line
@@ -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);

+4 −7
Original line number Diff line number Diff line
@@ -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);
Loading