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

Commit 31bc2f92 authored by Gilles Debunne's avatar Gilles Debunne Committed by Android (Google) Code Review
Browse files

Merge "Add SwitchPreference"

parents 760145e3 be0a4535
Loading
Loading
Loading
Loading
+1 −11
Original line number Diff line number Diff line
@@ -14255,20 +14255,10 @@ package android.os.storage {
package android.preference {
  public class CheckBoxPreference extends android.preference.Preference {
    public class CheckBoxPreference extends android.preference.TwoStatePreference {
    ctor public CheckBoxPreference(android.content.Context, android.util.AttributeSet, int);
    ctor public CheckBoxPreference(android.content.Context, android.util.AttributeSet);
    ctor public CheckBoxPreference(android.content.Context);
    method public boolean getDisableDependentsState();
    method public java.lang.CharSequence getSummaryOff();
    method public java.lang.CharSequence getSummaryOn();
    method public boolean isChecked();
    method public void setChecked(boolean);
    method public void setDisableDependentsState(boolean);
    method public void setSummaryOff(java.lang.CharSequence);
    method public void setSummaryOff(int);
    method public void setSummaryOn(java.lang.CharSequence);
    method public void setSummaryOn(int);
  }
  public abstract class DialogPreference extends android.preference.Preference implements android.content.DialogInterface.OnClickListener android.content.DialogInterface.OnDismissListener android.preference.PreferenceManager.OnActivityDestroyListener {
+58 −37
Original line number Diff line number Diff line
@@ -181,9 +181,9 @@ package android {
  public static final class R.attr {
    ctor public R.attr();
    field public static final int absListViewStyle = 16842858; // 0x101006a
    field public static final int accessibilityEventTypes = 16843647; // 0x101037f
    field public static final int accessibilityFeedbackType = 16843649; // 0x1010381
    field public static final int accessibilityFlags = 16843651; // 0x1010383
    field public static final int accessibilityEventTypes = 16843650; // 0x1010382
    field public static final int accessibilityFeedbackType = 16843652; // 0x1010384
    field public static final int accessibilityFlags = 16843654; // 0x1010386
    field public static final int accountPreferences = 16843423; // 0x101029f
    field public static final int accountType = 16843407; // 0x101028f
    field public static final int action = 16842797; // 0x101002d
@@ -203,7 +203,7 @@ package android {
    field public static final int actionModeCopyDrawable = 16843538; // 0x1010312
    field public static final int actionModeCutDrawable = 16843537; // 0x1010311
    field public static final int actionModePasteDrawable = 16843539; // 0x1010313
    field public static final int actionModeSelectAllDrawable = 16843645; // 0x101037d
    field public static final int actionModeSelectAllDrawable = 16843648; // 0x1010380
    field public static final int actionOverflowButtonStyle = 16843510; // 0x10102f6
    field public static final int actionViewClass = 16843516; // 0x10102fc
    field public static final int activatedBackgroundIndicator = 16843517; // 0x10102fd
@@ -275,7 +275,7 @@ package android {
    field public static final int cacheColorHint = 16843009; // 0x1010101
    field public static final int calendarViewShown = 16843596; // 0x101034c
    field public static final int calendarViewStyle = 16843613; // 0x101035d
    field public static final int canRetrieveWindowContent = 16843652; // 0x1010384
    field public static final int canRetrieveWindowContent = 16843655; // 0x1010387
    field public static final int candidatesTextStyleSpans = 16843312; // 0x1010230
    field public static final deprecated int capitalize = 16843113; // 0x1010169
    field public static final int centerBright = 16842956; // 0x10100cc
@@ -308,9 +308,9 @@ package android {
    field public static final int colorBackgroundCacheHint = 16843435; // 0x10102ab
    field public static final int colorForeground = 16842800; // 0x1010030
    field public static final int colorForegroundInverse = 16843270; // 0x1010206
    field public static final int columnCount = 16843636; // 0x1010374
    field public static final int columnCount = 16843639; // 0x1010377
    field public static final int columnDelay = 16843215; // 0x10101cf
    field public static final int columnOrderPreserved = 16843637; // 0x1010375
    field public static final int columnOrderPreserved = 16843640; // 0x1010378
    field public static final int columnWidth = 16843031; // 0x1010117
    field public static final int compatibleWidthLimitDp = 16843621; // 0x1010365
    field public static final int completionHint = 16843122; // 0x1010172
@@ -455,7 +455,7 @@ package android {
    field public static final int fromXScale = 16843202; // 0x10101c2
    field public static final int fromYDelta = 16843208; // 0x10101c8
    field public static final int fromYScale = 16843204; // 0x10101c4
    field public static final int fullBackupAgent = 16843632; // 0x1010370
    field public static final int fullBackupAgent = 16843635; // 0x1010373
    field public static final int fullBright = 16842954; // 0x10100ca
    field public static final int fullDark = 16842950; // 0x10100c6
    field public static final int functionalTest = 16842787; // 0x1010023
@@ -533,7 +533,7 @@ package android {
    field public static final int installLocation = 16843447; // 0x10102b7
    field public static final int interpolator = 16843073; // 0x1010141
    field public static final int isAlwaysSyncable = 16843571; // 0x1010333
    field public static final int isAuxiliary = 16843646; // 0x101037e
    field public static final int isAuxiliary = 16843649; // 0x1010381
    field public static final int isDefault = 16843297; // 0x1010221
    field public static final int isIndicator = 16843079; // 0x1010147
    field public static final int isModifier = 16843334; // 0x1010246
@@ -570,7 +570,7 @@ package android {
    field public static final int layerType = 16843604; // 0x1010354
    field public static final int layout = 16842994; // 0x10100f2
    field public static final int layoutAnimation = 16842988; // 0x10100ec
    field public static final int layoutDirection = 16843631; // 0x101036f
    field public static final int layoutDirection = 16843634; // 0x1010372
    field public static final int layout_above = 16843140; // 0x1010184
    field public static final int layout_alignBaseline = 16843142; // 0x1010186
    field public static final int layout_alignBottom = 16843146; // 0x101018a
@@ -587,8 +587,8 @@ package android {
    field public static final int layout_centerInParent = 16843151; // 0x101018f
    field public static final int layout_centerVertical = 16843153; // 0x1010191
    field public static final int layout_column = 16843084; // 0x101014c
    field public static final int layout_columnSpan = 16843643; // 0x101037b
    field public static final int layout_columnWeight = 16843644; // 0x101037c
    field public static final int layout_columnSpan = 16843646; // 0x101037e
    field public static final int layout_columnWeight = 16843647; // 0x101037f
    field public static final int layout_gravity = 16842931; // 0x10100b3
    field public static final int layout_height = 16842997; // 0x10100f5
    field public static final int layout_margin = 16842998; // 0x10100f6
@@ -596,9 +596,9 @@ package android {
    field public static final int layout_marginLeft = 16842999; // 0x10100f7
    field public static final int layout_marginRight = 16843001; // 0x10100f9
    field public static final int layout_marginTop = 16843000; // 0x10100f8
    field public static final int layout_row = 16843640; // 0x1010378
    field public static final int layout_rowSpan = 16843641; // 0x1010379
    field public static final int layout_rowWeight = 16843642; // 0x101037a
    field public static final int layout_row = 16843643; // 0x101037b
    field public static final int layout_rowSpan = 16843644; // 0x101037c
    field public static final int layout_rowWeight = 16843645; // 0x101037d
    field public static final int layout_scale = 16843155; // 0x1010193
    field public static final int layout_span = 16843085; // 0x101014d
    field public static final int layout_toLeftOf = 16843138; // 0x1010182
@@ -628,7 +628,7 @@ package android {
    field public static final int loopViews = 16843527; // 0x1010307
    field public static final int manageSpaceActivity = 16842756; // 0x1010004
    field public static final int mapViewStyle = 16842890; // 0x101008a
    field public static final int marginsIncludedInAlignment = 16843639; // 0x1010377
    field public static final int marginsIncludedInAlignment = 16843642; // 0x101037a
    field public static final int marqueeRepeatLimit = 16843293; // 0x101021d
    field public static final int max = 16843062; // 0x1010136
    field public static final int maxDate = 16843584; // 0x1010340
@@ -665,7 +665,7 @@ package android {
    field public static final int nextFocusUp = 16842979; // 0x10100e3
    field public static final int noHistory = 16843309; // 0x101022d
    field public static final int normalScreens = 16843397; // 0x1010285
    field public static final int notificationTimeout = 16843650; // 0x1010382
    field public static final int notificationTimeout = 16843653; // 0x1010385
    field public static final int numColumns = 16843032; // 0x1010118
    field public static final int numStars = 16843076; // 0x1010144
    field public static final deprecated int numeric = 16843109; // 0x1010165
@@ -682,7 +682,7 @@ package android {
    field public static final int overScrollFooter = 16843459; // 0x10102c3
    field public static final int overScrollHeader = 16843458; // 0x10102c2
    field public static final int overScrollMode = 16843457; // 0x10102c1
    field public static final int packageNames = 16843648; // 0x1010380
    field public static final int packageNames = 16843651; // 0x1010383
    field public static final int padding = 16842965; // 0x10100d5
    field public static final int paddingBottom = 16842969; // 0x10100d9
    field public static final int paddingLeft = 16842966; // 0x10100d6
@@ -772,11 +772,11 @@ package android {
    field public static final int rotation = 16843558; // 0x1010326
    field public static final int rotationX = 16843559; // 0x1010327
    field public static final int rotationY = 16843560; // 0x1010328
    field public static final int rowCount = 16843634; // 0x1010372
    field public static final int rowCount = 16843637; // 0x1010375
    field public static final int rowDelay = 16843216; // 0x10101d0
    field public static final int rowEdgeFlags = 16843329; // 0x1010241
    field public static final int rowHeight = 16843058; // 0x1010132
    field public static final int rowOrderPreserved = 16843635; // 0x1010373
    field public static final int rowOrderPreserved = 16843638; // 0x1010376
    field public static final int saveEnabled = 16842983; // 0x10100e7
    field public static final int scaleGravity = 16843262; // 0x10101fe
    field public static final int scaleHeight = 16843261; // 0x10101fd
@@ -889,12 +889,15 @@ package android {
    field public static final int subtitleTextStyle = 16843513; // 0x10102f9
    field public static final int suggestActionMsg = 16843228; // 0x10101dc
    field public static final int suggestActionMsgColumn = 16843229; // 0x10101dd
    field public static final int suggestionsEnabled = 16843633; // 0x1010371
    field public static final int suggestionsEnabled = 16843636; // 0x1010374
    field public static final int summary = 16843241; // 0x10101e9
    field public static final int summaryColumn = 16843426; // 0x10102a2
    field public static final int summaryOff = 16843248; // 0x10101f0
    field public static final int summaryOn = 16843247; // 0x10101ef
    field public static final int supportsUploading = 16843419; // 0x101029b
    field public static final int switchPreferenceStyle = 16843629; // 0x101036d
    field public static final int switchTextOff = 16843628; // 0x101036c
    field public static final int switchTextOn = 16843627; // 0x101036b
    field public static final int syncable = 16842777; // 0x1010019
    field public static final int tabStripEnabled = 16843453; // 0x10102bd
    field public static final int tabStripLeft = 16843451; // 0x10102bb
@@ -957,9 +960,9 @@ package android {
    field public static final int textEditPasteWindowLayout = 16843540; // 0x1010314
    field public static final int textEditSideNoPasteWindowLayout = 16843615; // 0x101035f
    field public static final int textEditSidePasteWindowLayout = 16843614; // 0x101035e
    field public static final int textEditSuggestionItemLayout = 16843630; // 0x101036e
    field public static final int textEditSuggestionsBottomWindowLayout = 16843628; // 0x101036c
    field public static final int textEditSuggestionsTopWindowLayout = 16843629; // 0x101036d
    field public static final int textEditSuggestionItemLayout = 16843633; // 0x1010371
    field public static final int textEditSuggestionsBottomWindowLayout = 16843631; // 0x101036f
    field public static final int textEditSuggestionsTopWindowLayout = 16843632; // 0x1010370
    field public static final int textFilterEnabled = 16843007; // 0x10100ff
    field public static final int textIsSelectable = 16843542; // 0x1010316
    field public static final int textOff = 16843045; // 0x1010125
@@ -971,7 +974,7 @@ package android {
    field public static final int textSelectHandleWindowStyle = 16843464; // 0x10102c8
    field public static final int textSize = 16842901; // 0x1010095
    field public static final int textStyle = 16842903; // 0x1010097
    field public static final int textSuggestionsWindowStyle = 16843627; // 0x101036b
    field public static final int textSuggestionsWindowStyle = 16843630; // 0x101036e
    field public static final int textViewStyle = 16842884; // 0x1010084
    field public static final int theme = 16842752; // 0x1010000
    field public static final int thickness = 16843360; // 0x1010260
@@ -1007,7 +1010,7 @@ package android {
    field public static final int unfocusedMonthDateColor = 16843588; // 0x1010344
    field public static final int unselectedAlpha = 16843278; // 0x101020e
    field public static final int updatePeriodMillis = 16843344; // 0x1010250
    field public static final int useDefaultMargins = 16843638; // 0x1010376
    field public static final int useDefaultMargins = 16843641; // 0x1010379
    field public static final int useIntrinsicSizeAsMinimum = 16843536; // 0x1010310
    field public static final int useLevel = 16843167; // 0x101019f
    field public static final int userVisible = 16843409; // 0x1010291
@@ -14433,20 +14436,10 @@ package android.os.storage {
package android.preference {
  public class CheckBoxPreference extends android.preference.Preference {
  public class CheckBoxPreference extends android.preference.TwoStatePreference {
    ctor public CheckBoxPreference(android.content.Context, android.util.AttributeSet, int);
    ctor public CheckBoxPreference(android.content.Context, android.util.AttributeSet);
    ctor public CheckBoxPreference(android.content.Context);
    method public boolean getDisableDependentsState();
    method public java.lang.CharSequence getSummaryOff();
    method public java.lang.CharSequence getSummaryOn();
    method public boolean isChecked();
    method public void setChecked(boolean);
    method public void setDisableDependentsState(boolean);
    method public void setSummaryOff(java.lang.CharSequence);
    method public void setSummaryOff(int);
    method public void setSummaryOn(java.lang.CharSequence);
    method public void setSummaryOn(int);
  }
  public abstract class DialogPreference extends android.preference.Preference implements android.content.DialogInterface.OnClickListener android.content.DialogInterface.OnDismissListener android.preference.PreferenceManager.OnActivityDestroyListener {
@@ -14774,6 +14767,34 @@ package android.preference {
    method public void setShowSilent(boolean);
  }
  public class SwitchPreference extends android.preference.TwoStatePreference {
    ctor public SwitchPreference(android.content.Context, android.util.AttributeSet, int);
    ctor public SwitchPreference(android.content.Context, android.util.AttributeSet);
    ctor public SwitchPreference(android.content.Context);
    method public java.lang.CharSequence getSwitchTextOff();
    method public java.lang.CharSequence getSwitchTextOn();
    method public void setSwitchTextOff(java.lang.CharSequence);
    method public void setSwitchTextOff(int);
    method public void setSwitchTextOn(java.lang.CharSequence);
    method public void setSwitchTextOn(int);
  }
  public abstract class TwoStatePreference extends android.preference.Preference {
    ctor public TwoStatePreference(android.content.Context, android.util.AttributeSet, int);
    ctor public TwoStatePreference(android.content.Context, android.util.AttributeSet);
    ctor public TwoStatePreference(android.content.Context);
    method public boolean getDisableDependentsState();
    method public java.lang.CharSequence getSummaryOff();
    method public java.lang.CharSequence getSummaryOn();
    method public boolean isChecked();
    method public void setChecked(boolean);
    method public void setDisableDependentsState(boolean);
    method public void setSummaryOff(java.lang.CharSequence);
    method public void setSummaryOff(int);
    method public void setSummaryOn(java.lang.CharSequence);
    method public void setSummaryOn(int);
  }
}
package android.provider {
+7 −266

File changed.

Preview size limit exceeded, changes collapsed.

+180 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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 android.preference;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.CompoundButton;
import android.widget.Switch;

/**
 * A {@link Preference} that provides a two-state toggleable option.
 * <p>
 * This preference will store a boolean into the SharedPreferences.
 *
 * @attr ref android.R.styleable#SwitchPreference_summaryOff
 * @attr ref android.R.styleable#SwitchPreference_summaryOn
 * @attr ref android.R.styleable#SwitchPreference_switchTextOff
 * @attr ref android.R.styleable#SwitchPreference_switchTextOn
 * @attr ref android.R.styleable#SwitchPreference_disableDependentsState
 */
public class SwitchPreference extends TwoStatePreference {
    // Switch text for on and off states
    private CharSequence mSwitchOn;
    private CharSequence mSwitchOff;
    private final Listener mListener = new Listener();

    private class Listener implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
        @Override
        public void onClick(View v) {
            SwitchPreference.this.onClick();
        }

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SwitchPreference.this.setChecked(isChecked);
        }
    }

    /**
     * Construct a new SwitchPreference with the given style options.
     *
     * @param context The Context that will style this preference
     * @param attrs Style attributes that differ from the default
     * @param defStyle Theme attribute defining the default style options
     */
    public SwitchPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        TypedArray a = context.obtainStyledAttributes(attrs,
                com.android.internal.R.styleable.SwitchPreference, defStyle, 0);
        setSummaryOn(a.getString(com.android.internal.R.styleable.SwitchPreference_summaryOn));
        setSummaryOff(a.getString(com.android.internal.R.styleable.SwitchPreference_summaryOff));
        setSwitchTextOn(a.getString(
                com.android.internal.R.styleable.SwitchPreference_switchTextOn));
        setSwitchTextOff(a.getString(
                com.android.internal.R.styleable.SwitchPreference_switchTextOff));
        setDisableDependentsState(a.getBoolean(
                com.android.internal.R.styleable.SwitchPreference_disableDependentsState, false));
        a.recycle();
    }

    /**
     * Construct a new SwitchPreference with the given style options.
     *
     * @param context The Context that will style this preference
     * @param attrs Style attributes that differ from the default
     */
    public SwitchPreference(Context context, AttributeSet attrs) {
        this(context, attrs, com.android.internal.R.attr.switchPreferenceStyle);
    }

    /**
     * Construct a new SwitchPreference with default style options.
     *
     * @param context The Context that will style this preference
     */
    public SwitchPreference(Context context) {
        this(context, null);
    }

    @Override
    protected void onBindView(View view) {
        super.onBindView(view);

        View checkableView = view.findViewById(com.android.internal.R.id.switchWidget);
        if (checkableView != null && checkableView instanceof Checkable) {
            ((Checkable) checkableView).setChecked(mChecked);

            sendAccessibilityEventForView(checkableView);

            if (checkableView instanceof Switch) {
                final Switch switchView = (Switch) checkableView;
                switchView.setTextOn(mSwitchOn);
                switchView.setTextOff(mSwitchOff);
                switchView.setOnCheckedChangeListener(mListener);
            }

            if (checkableView.hasFocusable()) {
                // This is a focusable list item. Attach a click handler to toggle the button
                // for the rest of the item.
                view.setOnClickListener(mListener);
            }
        }

        syncSummaryView(view);
    }

    /**
     * Set the text displayed on the switch widget in the on state.
     * This should be a very short string; one word if possible.
     *
     * @param onText Text to display in the on state
     */
    public void setSwitchTextOn(CharSequence onText) {
        mSwitchOn = onText;
        notifyChanged();
    }

    /**
     * Set the text displayed on the switch widget in the off state.
     * This should be a very short string; one word if possible.
     *
     * @param offText Text to display in the off state
     */
    public void setSwitchTextOff(CharSequence offText) {
        mSwitchOff = offText;
        notifyChanged();
    }

    /**
     * Set the text displayed on the switch widget in the on state.
     * This should be a very short string; one word if possible.
     *
     * @param resId The text as a string resource ID
     */
    public void setSwitchTextOn(int resId) {
        setSwitchTextOn(getContext().getString(resId));
    }

    /**
     * Set the text displayed on the switch widget in the off state.
     * This should be a very short string; one word if possible.
     *
     * @param resId The text as a string resource ID
     */
    public void setSwitchTextOff(int resId) {
        setSwitchTextOff(getContext().getString(resId));
    }

    /**
     * @return The text that will be displayed on the switch widget in the on state
     */
    public CharSequence getSwitchTextOn() {
        return mSwitchOn;
    }

    /**
     * @return The text that will be displayed on the switch widget in the off state
     */
    public CharSequence getSwitchTextOff() {
        return mSwitchOff;
    }
}
+309 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading