Revert "Apply SettingsLib SeekBarPreference to Settings"
Revert submission 13422386-seekbar-sc-dev Reason for revert: build broken in SettingsGoogle Reverted Changes: I0c2d0d5fb:Apply SettingsLib SeekBarPreference to SettingsGoo... I1844bb3b0:Apply SettingsLib SeekBarPreference to a11y vibrat... Ia3e4adec8:Apply SettingsLib SeekBarPreference to a11y vibrat... Iadee57e9d:Apply SettingsLib SeekBarPreference to a11y vibrat... I219878716:Apply SettingsLib SeekBarPreference to Settings I959f5672c:Create SettingsLibSeekBarPreference I92545a69c:Apply SettingsLib SeekBarPreference to a11y vibrat... Change-Id: Ie6c3b0dc072e044796abdb33fca305f9f9d47c4d Bug: 176818438
This commit is contained in:
committed by
Giuliano Procida
parent
d6b5bbb5cb
commit
cdff5c6ceb
89
src/com/android/settings/widget/DefaultIndicatorSeekBar.java
Normal file
89
src/com/android/settings/widget/DefaultIndicatorSeekBar.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
public class DefaultIndicatorSeekBar extends SeekBar {
|
||||
|
||||
private int mDefaultProgress = -1;
|
||||
|
||||
public DefaultIndicatorSeekBar(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public DefaultIndicatorSeekBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public DefaultIndicatorSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public DefaultIndicatorSeekBar(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
/**
|
||||
* N.B. Only draws the default indicator tick mark, NOT equally spaced tick marks.
|
||||
*/
|
||||
@Override
|
||||
protected void drawTickMarks(Canvas canvas) {
|
||||
if (isEnabled() && mDefaultProgress <= getMax() && mDefaultProgress >= getMin()) {
|
||||
final Drawable defaultIndicator = getTickMark();
|
||||
|
||||
// Adjust the drawable's bounds to center it at the point where it's drawn.
|
||||
final int w = defaultIndicator.getIntrinsicWidth();
|
||||
final int h = defaultIndicator.getIntrinsicHeight();
|
||||
final int halfW = w >= 0 ? w / 2 : 1;
|
||||
final int halfH = h >= 0 ? h / 2 : 1;
|
||||
defaultIndicator.setBounds(-halfW, -halfH, halfW, halfH);
|
||||
|
||||
// This mimics the computation of the thumb position, to get the true "default."
|
||||
final int availableWidth = getWidth() - mPaddingLeft - mPaddingRight;
|
||||
final int range = getMax() - getMin();
|
||||
final float scale = range > 0f ? mDefaultProgress / (float) range : 0f;
|
||||
final int offset = (int) ((scale * availableWidth) + 0.5f);
|
||||
final int indicatorPosition = isLayoutRtl() && getMirrorForRtl()
|
||||
? availableWidth - offset + mPaddingRight : offset + mPaddingLeft;
|
||||
|
||||
final int saveCount = canvas.save();
|
||||
canvas.translate(indicatorPosition, getHeight() / 2);
|
||||
defaultIndicator.draw(canvas);
|
||||
canvas.restoreToCount(saveCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* N.B. This sets the default *unadjusted* progress, i.e. in the SeekBar's [0 - max] terms.
|
||||
*/
|
||||
public void setDefaultProgress(int defaultProgress) {
|
||||
if (mDefaultProgress != defaultProgress) {
|
||||
mDefaultProgress = defaultProgress;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public int getDefaultProgress() {
|
||||
return mDefaultProgress;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.res.TypedArrayUtils;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/** A slider preference with left and right labels **/
|
||||
public class LabeledSeekBarPreference extends SeekBarPreference {
|
||||
|
||||
private final int mTextStartId;
|
||||
private final int mTextEndId;
|
||||
private final int mTickMarkId;
|
||||
private OnPreferenceChangeListener mStopListener;
|
||||
|
||||
public LabeledSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
setLayoutResource(R.layout.preference_labeled_slider);
|
||||
|
||||
final TypedArray styledAttrs = context.obtainStyledAttributes(attrs,
|
||||
R.styleable.LabeledSeekBarPreference);
|
||||
mTextStartId = styledAttrs.getResourceId(
|
||||
R.styleable.LabeledSeekBarPreference_textStart,
|
||||
R.string.summary_placeholder);
|
||||
mTextEndId = styledAttrs.getResourceId(
|
||||
R.styleable.LabeledSeekBarPreference_textEnd,
|
||||
R.string.summary_placeholder);
|
||||
mTickMarkId = styledAttrs.getResourceId(
|
||||
R.styleable.LabeledSeekBarPreference_tickMark, /* defValue= */ 0);
|
||||
styledAttrs.recycle();
|
||||
}
|
||||
|
||||
public LabeledSeekBarPreference(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, TypedArrayUtils.getAttr(context,
|
||||
androidx.preference.R.attr.seekBarPreferenceStyle,
|
||||
com.android.internal.R.attr.seekBarPreferenceStyle), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
final TextView startText = (TextView) holder.findViewById(android.R.id.text1);
|
||||
final TextView endText = (TextView) holder.findViewById(android.R.id.text2);
|
||||
startText.setText(mTextStartId);
|
||||
endText.setText(mTextEndId);
|
||||
|
||||
if (mTickMarkId != 0) {
|
||||
final Drawable tickMark = getContext().getDrawable(mTickMarkId);
|
||||
final SeekBar seekBar = (SeekBar) holder.findViewById(
|
||||
com.android.internal.R.id.seekbar);
|
||||
seekBar.setTickMark(tickMark);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnPreferenceChangeStopListener(OnPreferenceChangeListener listener) {
|
||||
mStopListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
super.onStopTrackingTouch(seekBar);
|
||||
|
||||
if (mStopListener != null) {
|
||||
mStopListener.onPreferenceChange(this, seekBar.getProgress());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.Restrictable;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedPreferenceHelper;
|
||||
import com.android.settingslib.widget.AppPreference;
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.android.settingslib.widget.AppPreference;
|
||||
* {@link com.android.settingslib.RestrictedPreferenceHelper}.
|
||||
* Used to show policy transparency on {@link AppPreference}.
|
||||
*/
|
||||
public class RestrictedAppPreference extends AppPreference implements Restrictable {
|
||||
public class RestrictedAppPreference extends AppPreference {
|
||||
private RestrictedPreferenceHelper mHelper;
|
||||
private String userRestriction;
|
||||
|
||||
@@ -85,14 +85,14 @@ public class RestrictedAppPreference extends AppPreference implements Restrictab
|
||||
super.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestrictedPreferenceHelper getHelper() {
|
||||
return mHelper;
|
||||
public void setDisabledByAdmin(RestrictedLockUtils.EnforcedAdmin admin) {
|
||||
if (mHelper.setDisabledByAdmin(admin)) {
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyPreferenceChanged() {
|
||||
notifyChanged();
|
||||
public boolean isDisabledByAdmin() {
|
||||
return mHelper.isDisabledByAdmin();
|
||||
}
|
||||
|
||||
public void useAdminDisabledSummary(boolean useSummary) {
|
||||
@@ -111,4 +111,12 @@ public class RestrictedAppPreference extends AppPreference implements Restrictab
|
||||
}
|
||||
mHelper.checkRestrictionAndSetDisabled(userRestriction, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
public void checkRestrictionAndSetDisabled(String userRestriction) {
|
||||
mHelper.checkRestrictionAndSetDisabled(userRestriction, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
public void checkRestrictionAndSetDisabled(String userRestriction, int userId) {
|
||||
mHelper.checkRestrictionAndSetDisabled(userRestriction, userId);
|
||||
}
|
||||
}
|
||||
|
||||
436
src/com/android/settings/widget/SeekBarPreference.java
Normal file
436
src/com/android/settings/widget/SeekBarPreference.java
Normal file
@@ -0,0 +1,436 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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 static android.view.HapticFeedbackConstants.CLOCK_TICK;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
|
||||
import androidx.core.content.res.TypedArrayUtils;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
/**
|
||||
* Based on android.preference.SeekBarPreference, but uses support preference as base.
|
||||
*/
|
||||
public class SeekBarPreference extends RestrictedPreference
|
||||
implements OnSeekBarChangeListener, View.OnKeyListener {
|
||||
|
||||
public static final int HAPTIC_FEEDBACK_MODE_NONE = 0;
|
||||
public static final int HAPTIC_FEEDBACK_MODE_ON_TICKS = 1;
|
||||
public static final int HAPTIC_FEEDBACK_MODE_ON_ENDS = 2;
|
||||
|
||||
private int mProgress;
|
||||
private int mMax;
|
||||
private int mMin;
|
||||
private boolean mTrackingTouch;
|
||||
|
||||
private boolean mContinuousUpdates;
|
||||
private int mHapticFeedbackMode = HAPTIC_FEEDBACK_MODE_NONE;
|
||||
private int mDefaultProgress = -1;
|
||||
|
||||
private SeekBar mSeekBar;
|
||||
private boolean mShouldBlink;
|
||||
private int mAccessibilityRangeInfoType = AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT;
|
||||
private CharSequence mSeekBarContentDescription;
|
||||
private CharSequence mSeekBarStateDescription;
|
||||
|
||||
public SeekBarPreference(
|
||||
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(
|
||||
attrs, com.android.internal.R.styleable.ProgressBar, defStyleAttr, defStyleRes);
|
||||
setMax(a.getInt(com.android.internal.R.styleable.ProgressBar_max, mMax));
|
||||
setMin(a.getInt(com.android.internal.R.styleable.ProgressBar_min, mMin));
|
||||
a.recycle();
|
||||
|
||||
a = context.obtainStyledAttributes(attrs,
|
||||
com.android.internal.R.styleable.SeekBarPreference, defStyleAttr, defStyleRes);
|
||||
final int layoutResId = a.getResourceId(
|
||||
com.android.internal.R.styleable.SeekBarPreference_layout,
|
||||
com.android.internal.R.layout.preference_widget_seekbar);
|
||||
a.recycle();
|
||||
|
||||
a = context.obtainStyledAttributes(
|
||||
attrs, com.android.internal.R.styleable.Preference, defStyleAttr, defStyleRes);
|
||||
final boolean isSelectable = a.getBoolean(
|
||||
com.android.settings.R.styleable.Preference_android_selectable, false);
|
||||
setSelectable(isSelectable);
|
||||
a.recycle();
|
||||
|
||||
setLayoutResource(layoutResId);
|
||||
}
|
||||
|
||||
public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
this(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
public SeekBarPreference(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, TypedArrayUtils.getAttr(context,
|
||||
androidx.preference.R.attr.seekBarPreferenceStyle,
|
||||
com.android.internal.R.attr.seekBarPreferenceStyle));
|
||||
}
|
||||
|
||||
public SeekBarPreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public void setShouldBlink(boolean shouldBlink) {
|
||||
mShouldBlink = shouldBlink;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelectable() {
|
||||
if(isDisabledByAdmin()) {
|
||||
return true;
|
||||
} else {
|
||||
return super.isSelectable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
view.itemView.setOnKeyListener(this);
|
||||
mSeekBar = (SeekBar) view.findViewById(
|
||||
com.android.internal.R.id.seekbar);
|
||||
mSeekBar.setOnSeekBarChangeListener(this);
|
||||
mSeekBar.setMax(mMax);
|
||||
mSeekBar.setMin(mMin);
|
||||
mSeekBar.setProgress(mProgress);
|
||||
mSeekBar.setEnabled(isEnabled());
|
||||
final CharSequence title = getTitle();
|
||||
if (!TextUtils.isEmpty(mSeekBarContentDescription)) {
|
||||
mSeekBar.setContentDescription(mSeekBarContentDescription);
|
||||
} else if (!TextUtils.isEmpty(title)) {
|
||||
mSeekBar.setContentDescription(title);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mSeekBarStateDescription)) {
|
||||
mSeekBar.setStateDescription(mSeekBarStateDescription);
|
||||
}
|
||||
if (mSeekBar instanceof DefaultIndicatorSeekBar) {
|
||||
((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
|
||||
}
|
||||
if (mShouldBlink) {
|
||||
View v = view.itemView;
|
||||
v.post(() -> {
|
||||
if (v.getBackground() != null) {
|
||||
final int centerX = v.getWidth() / 2;
|
||||
final int centerY = v.getHeight() / 2;
|
||||
v.getBackground().setHotspot(centerX, centerY);
|
||||
}
|
||||
v.setPressed(true);
|
||||
v.setPressed(false);
|
||||
mShouldBlink = false;
|
||||
});
|
||||
}
|
||||
mSeekBar.setAccessibilityDelegate(new View.AccessibilityDelegate() {
|
||||
@Override
|
||||
public void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfo info) {
|
||||
super.onInitializeAccessibilityNodeInfo(view, info);
|
||||
// Update the range info with the correct type
|
||||
AccessibilityNodeInfo.RangeInfo rangeInfo = info.getRangeInfo();
|
||||
if (rangeInfo != null) {
|
||||
info.setRangeInfo(AccessibilityNodeInfo.RangeInfo.obtain(
|
||||
mAccessibilityRangeInfoType, rangeInfo.getMin(),
|
||||
rangeInfo.getMax(), rangeInfo.getCurrent()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
|
||||
setProgress(restoreValue ? getPersistedInt(mProgress)
|
||||
: (Integer) defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||
return a.getInt(index, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (event.getAction() != KeyEvent.ACTION_DOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SeekBar seekBar = (SeekBar) v.findViewById(com.android.internal.R.id.seekbar);
|
||||
if (seekBar == null) {
|
||||
return false;
|
||||
}
|
||||
return seekBar.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
public void setMax(int max) {
|
||||
if (max != mMax) {
|
||||
mMax = max;
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMin(int min) {
|
||||
if (min != mMin) {
|
||||
mMin = min;
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return mMax;
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return mMin;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
setProgress(progress, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the progress point to draw a single tick mark representing a default value.
|
||||
*/
|
||||
public void setDefaultProgress(int defaultProgress) {
|
||||
if (mDefaultProgress != defaultProgress) {
|
||||
mDefaultProgress = defaultProgress;
|
||||
if (mSeekBar instanceof DefaultIndicatorSeekBar) {
|
||||
((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When {@code continuousUpdates} is true, update the persisted setting immediately as the thumb
|
||||
* is dragged along the SeekBar. Otherwise, only update the value of the setting when the thumb
|
||||
* is dropped.
|
||||
*/
|
||||
public void setContinuousUpdates(boolean continuousUpdates) {
|
||||
mContinuousUpdates = continuousUpdates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the haptic feedback mode. HAPTIC_FEEDBACK_MODE_ON_TICKS means to perform haptic feedback
|
||||
* as the SeekBar's progress is updated; HAPTIC_FEEDBACK_MODE_ON_ENDS means to perform haptic
|
||||
* feedback as the SeekBar's progress value is equal to the min/max value.
|
||||
*
|
||||
* @param hapticFeedbackMode the haptic feedback mode.
|
||||
*/
|
||||
public void setHapticFeedbackMode(int hapticFeedbackMode) {
|
||||
mHapticFeedbackMode = hapticFeedbackMode;
|
||||
}
|
||||
|
||||
private void setProgress(int progress, boolean notifyChanged) {
|
||||
if (progress > mMax) {
|
||||
progress = mMax;
|
||||
}
|
||||
if (progress < mMin) {
|
||||
progress = mMin;
|
||||
}
|
||||
if (progress != mProgress) {
|
||||
mProgress = progress;
|
||||
persistInt(progress);
|
||||
if (notifyChanged) {
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return mProgress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the seekBar's progress value if callChangeListener
|
||||
* returns true, otherwise set the seekBar's progress to the stored value
|
||||
*/
|
||||
void syncProgress(SeekBar seekBar) {
|
||||
int progress = seekBar.getProgress();
|
||||
if (progress != mProgress) {
|
||||
if (callChangeListener(progress)) {
|
||||
setProgress(progress, false);
|
||||
switch (mHapticFeedbackMode) {
|
||||
case HAPTIC_FEEDBACK_MODE_ON_TICKS:
|
||||
seekBar.performHapticFeedback(CLOCK_TICK);
|
||||
break;
|
||||
case HAPTIC_FEEDBACK_MODE_ON_ENDS:
|
||||
if (progress == mMax || progress == mMin) {
|
||||
seekBar.performHapticFeedback(CLOCK_TICK);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
seekBar.setProgress(mProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (fromUser && (mContinuousUpdates || !mTrackingTouch)) {
|
||||
syncProgress(seekBar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
mTrackingTouch = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
mTrackingTouch = false;
|
||||
if (seekBar.getProgress() != mProgress) {
|
||||
syncProgress(seekBar);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the type of range this seek bar represents.
|
||||
*
|
||||
* @param rangeInfoType The type of range to be shared with accessibility
|
||||
*
|
||||
* @see android.view.accessibility.AccessibilityNodeInfo.RangeInfo
|
||||
*/
|
||||
public void setAccessibilityRangeInfoType(int rangeInfoType) {
|
||||
mAccessibilityRangeInfoType = rangeInfoType;
|
||||
}
|
||||
|
||||
public void setSeekBarContentDescription(CharSequence contentDescription) {
|
||||
mSeekBarContentDescription = contentDescription;
|
||||
if (mSeekBar != null) {
|
||||
mSeekBar.setContentDescription(contentDescription);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the state description for this seek bar represents.
|
||||
*
|
||||
* @param stateDescription the state description of seek bar
|
||||
*/
|
||||
public void setSeekBarStateDescription(CharSequence stateDescription) {
|
||||
mSeekBarStateDescription = stateDescription;
|
||||
if (mSeekBar != null) {
|
||||
mSeekBar.setStateDescription(stateDescription);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
/*
|
||||
* Suppose a client uses this preference type without persisting. We
|
||||
* must save the instance state so it is able to, for example, survive
|
||||
* orientation changes.
|
||||
*/
|
||||
|
||||
final Parcelable superState = super.onSaveInstanceState();
|
||||
if (isPersistent()) {
|
||||
// No need to save instance state since it's persistent
|
||||
return superState;
|
||||
}
|
||||
|
||||
// Save the instance state
|
||||
final SavedState myState = new SavedState(superState);
|
||||
myState.progress = mProgress;
|
||||
myState.max = mMax;
|
||||
myState.min = mMin;
|
||||
return myState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if (!state.getClass().equals(SavedState.class)) {
|
||||
// Didn't save state for us in onSaveInstanceState
|
||||
super.onRestoreInstanceState(state);
|
||||
return;
|
||||
}
|
||||
|
||||
// Restore the instance state
|
||||
SavedState myState = (SavedState) state;
|
||||
super.onRestoreInstanceState(myState.getSuperState());
|
||||
mProgress = myState.progress;
|
||||
mMax = myState.max;
|
||||
mMin = myState.min;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* SavedState, a subclass of {@link BaseSavedState}, will store the state
|
||||
* of MyPreference, a subclass of Preference.
|
||||
* <p>
|
||||
* It is important to always call through to super methods.
|
||||
*/
|
||||
private static class SavedState extends BaseSavedState {
|
||||
int progress;
|
||||
int max;
|
||||
int min;
|
||||
|
||||
public SavedState(Parcel source) {
|
||||
super(source);
|
||||
|
||||
// Restore the click counter
|
||||
progress = source.readInt();
|
||||
max = source.readInt();
|
||||
min = source.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
|
||||
// Save the click counter
|
||||
dest.writeInt(progress);
|
||||
dest.writeInt(max);
|
||||
dest.writeInt(min);
|
||||
}
|
||||
|
||||
public SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static final Parcelable.Creator<SavedState> CREATOR =
|
||||
new Parcelable.Creator<SavedState>() {
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user