Merge "Refactor GestureNavigationSeekBarPreference"
This commit is contained in:
committed by
Android (Google) Code Review
commit
8b2594393b
@@ -62,7 +62,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="start|top"
|
android:layout_gravity="start|top"
|
||||||
android:gravity="start"
|
android:gravity="start"
|
||||||
android:text="@string/low_label"
|
|
||||||
android:layout_weight="1"/>
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -72,7 +71,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end|top"
|
android:layout_gravity="end|top"
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:text="@string/high_label"
|
|
||||||
android:layout_weight="1"/>
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@@ -159,6 +159,12 @@
|
|||||||
<attr name="textOff" format="reference" />
|
<attr name="textOff" format="reference" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
<!-- For LabeledSeekBarPreference -->
|
||||||
|
<declare-styleable name="LabeledSeekBarPreference">
|
||||||
|
<attr name="textStart" format="reference" />
|
||||||
|
<attr name="textEnd" format="reference" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="TintDrawable">
|
<declare-styleable name="TintDrawable">
|
||||||
<attr name="android:tint" />
|
<attr name="android:tint" />
|
||||||
<attr name="android:drawable" />
|
<attr name="android:drawable" />
|
||||||
|
@@ -28,17 +28,21 @@
|
|||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/back_sensitivity_dialog_title">
|
android:title="@string/back_sensitivity_dialog_title">
|
||||||
|
|
||||||
<com.android.settings.gestures.GestureNavigationSeekBarPreference
|
<com.android.settings.widget.LabeledSeekBarPreference
|
||||||
android:key="gesture_left_back_sensitivity"
|
android:key="gesture_left_back_sensitivity"
|
||||||
android:title="@string/left_edge"
|
android:title="@string/left_edge"
|
||||||
android:max="3"
|
android:max="3"
|
||||||
android:selectable="true"/>
|
android:selectable="true"
|
||||||
|
settings:textStart="@string/low_label"
|
||||||
|
settings:textEnd="@string/high_label"/>
|
||||||
|
|
||||||
<com.android.settings.gestures.GestureNavigationSeekBarPreference
|
<com.android.settings.widget.LabeledSeekBarPreference
|
||||||
android:key="gesture_right_back_sensitivity"
|
android:key="gesture_right_back_sensitivity"
|
||||||
android:title="@string/right_edge"
|
android:title="@string/right_edge"
|
||||||
android:max="3"
|
android:max="3"
|
||||||
android:selectable="true"/>
|
android:selectable="true"
|
||||||
|
settings:textStart="@string/low_label"
|
||||||
|
settings:textEnd="@string/high_label"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<com.android.settingslib.widget.FooterPreference
|
<com.android.settingslib.widget.FooterPreference
|
||||||
|
@@ -25,6 +25,7 @@ import android.view.WindowManager;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,7 +109,7 @@ public class GestureNavigationSettingsFragment extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initSeekBarPreference(final String key) {
|
private void initSeekBarPreference(final String key) {
|
||||||
final GestureNavigationSeekBarPreference pref = getPreferenceScreen().findPreference(key);
|
final LabeledSeekBarPreference pref = getPreferenceScreen().findPreference(key);
|
||||||
pref.setContinuousUpdates(true);
|
pref.setContinuousUpdates(true);
|
||||||
|
|
||||||
final String settingsKey = key == LEFT_EDGE_SEEKBAR_KEY
|
final String settingsKey = key == LEFT_EDGE_SEEKBAR_KEY
|
||||||
|
@@ -14,35 +14,59 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.gestures;
|
package com.android.settings.widget;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.core.content.res.TypedArrayUtils;
|
import androidx.core.content.res.TypedArrayUtils;
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.SeekBarPreference;
|
|
||||||
|
|
||||||
/** A slider preference that is used to set the back gesture's sensitivity **/
|
/** A slider preference with left and right labels **/
|
||||||
public class GestureNavigationSeekBarPreference extends SeekBarPreference {
|
public class LabeledSeekBarPreference extends SeekBarPreference {
|
||||||
|
|
||||||
|
private final int mTextStartId;
|
||||||
|
private final int mTextEndId;
|
||||||
private OnPreferenceChangeListener mStopListener;
|
private OnPreferenceChangeListener mStopListener;
|
||||||
|
|
||||||
public GestureNavigationSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
public LabeledSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||||
int defStyleRes) {
|
int defStyleRes) {
|
||||||
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
setLayoutResource(R.layout.preference_gesture_navigation_slider);
|
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);
|
||||||
|
styledAttrs.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GestureNavigationSeekBarPreference(Context context, AttributeSet attrs) {
|
public LabeledSeekBarPreference(Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, TypedArrayUtils.getAttr(context,
|
this(context, attrs, TypedArrayUtils.getAttr(context,
|
||||||
androidx.preference.R.attr.seekBarPreferenceStyle,
|
androidx.preference.R.attr.seekBarPreferenceStyle,
|
||||||
com.android.internal.R.attr.seekBarPreferenceStyle), 0);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
public void setOnPreferenceChangeStopListener(OnPreferenceChangeListener listener) {
|
public void setOnPreferenceChangeStopListener(OnPreferenceChangeListener listener) {
|
||||||
mStopListener = listener;
|
mStopListener = listener;
|
||||||
}
|
}
|
@@ -27,6 +27,8 @@ import android.widget.SeekBar;
|
|||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -36,11 +38,11 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class GestureNavigationSeekBarPreferenceTest {
|
public class LabeledSeekBarPreferenceTest {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SeekBar mSeekBar;
|
private SeekBar mSeekBar;
|
||||||
private GestureNavigationSeekBarPreference mSeekBarPreference;
|
private LabeledSeekBarPreference mSeekBarPreference;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Preference.OnPreferenceChangeListener mListener;
|
private Preference.OnPreferenceChangeListener mListener;
|
||||||
@@ -50,7 +52,7 @@ public class GestureNavigationSeekBarPreferenceTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mSeekBarPreference = new GestureNavigationSeekBarPreference(mContext, null);
|
mSeekBarPreference = new LabeledSeekBarPreference(mContext, null);
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
final View view =
|
final View view =
|
||||||
inflater.inflate(mSeekBarPreference.getLayoutResource(),
|
inflater.inflate(mSeekBarPreference.getLayoutResource(),
|
Reference in New Issue
Block a user