mrbimc / materialseekbarpreference Goto Github PK
View Code? Open in Web Editor NEWThe best yet Implemetation of SeekBarPreference. Works on API-v7 and up.
The best yet Implemetation of SeekBarPreference. Works on API-v7 and up.
Getting an exception when adding this to my Preferences:
com.pavelsikun.seekbarpreference.SeekBarPreference cannot be cast to android.support.v7.preference.Preference
Вот с этими параметрами слайдер начинает отбражать фигню.
<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="your_pref_key"
android:title="Задержка"
android:summary="Процент времени от максимального"
android:enabled="true"
android:defaultValue="50"
sample:msbp_minValue="50"
sample:msbp_maxValue="280"
sample:msbp_interval="5"
sample:msbp_measurementUnit="%"
sample:msbp_dialogEnabled="false"/>
I find some problem,and I think...
In com.pavelsikun.seekbarpreference PreferenceControllerDelegate
preferencevalue not change;
INTERVAL bug
a lot...
is My com.pavelsikun.seekbarpreference PreferenceControllerDelegate:
package com.pavelsikun.seekbarpreference;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
/**
class PreferenceControllerDelegate implements SeekBar.OnSeekBarChangeListener, View.OnClickListener {
private final String TAG = getClass().getSimpleName();
private static final int DEFAULT_CURRENT_VALUE = 50;
private static final int DEFAULT_MIN_VALUE = 0;
private static final int DEFAULT_MAX_VALUE = 100;
private static final int DEFAULT_INTERVAL = 1;
private static final boolean DEFAULT_DIALOG_ENABLED = true;
private static final boolean DEFAULT_IS_ENABLED = true;
private static final int DEFAULT_DIALOG_STYLE = R.style.MSB_Dialog_Default;
private int maxValue;
private int minValue;
private int interval;
private int currentValue;
private String measurementUnit;
private boolean dialogEnabled;
private int dialogStyle;
private TextView valueView;
private SeekBar seekBarView;
private TextView measurementView;
private LinearLayout valueHolderView;
private FrameLayout bottomLineView;
//view stuff
private TextView titleView, summaryView;
private String title;
private String summary;
private boolean isEnabled;
//controller stuff
private boolean isView = false;
private Context context;
private ViewStateListener viewStateListener;
private PersistValueListener persistValueListener;
private ChangeValueListener changeValueListener;
interface ViewStateListener {
boolean isEnabled();
void setEnabled(boolean enabled);
}
PreferenceControllerDelegate(Context context, Boolean isView) {
this.context = context;
this.isView = isView;
}
void setPersistValueListener(PersistValueListener persistValueListener) {
this.persistValueListener = persistValueListener;
}
void setViewStateListener(ViewStateListener viewStateListener) {
this.viewStateListener = viewStateListener;
}
void setChangeValueListener(ChangeValueListener changeValueListener) {
this.changeValueListener = changeValueListener;
}
void loadValuesFromXml(AttributeSet attrs) {
if (attrs == null) {
currentValue = DEFAULT_CURRENT_VALUE;
minValue = DEFAULT_MIN_VALUE;
maxValue = DEFAULT_MAX_VALUE;
interval = DEFAULT_INTERVAL;
dialogEnabled = DEFAULT_DIALOG_ENABLED;
isEnabled = DEFAULT_IS_ENABLED;
} else {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekBarPreference);
try {
minValue = a.getInt(R.styleable.SeekBarPreference_msbp_minValue, DEFAULT_MIN_VALUE);
interval = a.getInt(R.styleable.SeekBarPreference_msbp_interval, DEFAULT_INTERVAL);
maxValue = a.getInt(R.styleable.SeekBarPreference_msbp_maxValue, DEFAULT_MAX_VALUE);
dialogEnabled = a.getBoolean(R.styleable.SeekBarPreference_msbp_dialogEnabled, DEFAULT_DIALOG_ENABLED);
measurementUnit = a.getString(R.styleable.SeekBarPreference_msbp_measurementUnit);
currentValue = attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "defaultValue", DEFAULT_CURRENT_VALUE);
// TODO make it work:
// dialogStyle = a.getInt(R.styleable.SeekBarPreference_msbp_interval, DEFAULT_DIALOG_STYLE);
dialogStyle = DEFAULT_DIALOG_STYLE;
if (isView) {
title = a.getString(R.styleable.SeekBarPreference_msbp_view_title);
summary = a.getString(R.styleable.SeekBarPreference_msbp_view_summary);
currentValue = a.getInt(R.styleable.SeekBarPreference_msbp_view_defaultValue, DEFAULT_CURRENT_VALUE);
isEnabled = a.getBoolean(R.styleable.SeekBarPreference_msbp_view_enabled, DEFAULT_IS_ENABLED);
}
} finally {
a.recycle();
}
}
}
void onBind(View view) {
if (isView) {
titleView = (TextView) view.findViewById(android.R.id.title);
summaryView = (TextView) view.findViewById(android.R.id.summary);
titleView.setText(title);
summaryView.setText(summary);
}
view.setClickable(false);
seekBarView = (SeekBar) view.findViewById(R.id.seekbar);
measurementView = (TextView) view.findViewById(R.id.measurement_unit);
valueView = (TextView) view.findViewById(R.id.seekbar_value);
setMaxValue(maxValue);
seekBarView.setOnSeekBarChangeListener(this);
measurementView.setText(measurementUnit);
setCurrentValue(currentValue);
// valueView.setText(String.valueOf(currentValue));
bottomLineView = (FrameLayout) view.findViewById(R.id.bottom_line);
valueHolderView = (LinearLayout) view.findViewById(R.id.value_holder);
setDialogEnabled(dialogEnabled);
setEnabled(isEnabled(), true);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int newValue = minValue + (progress * interval);
setCurrentValue(newValue);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
setCurrentValue(currentValue);
}
@Override
public void onClick(final View v) {
new CustomValueDialog(context, dialogStyle, minValue, maxValue, currentValue)
.setPersistValueListener(new PersistValueListener() {
@Override
public boolean persistInt(int value) {
setCurrentValue(value);
return true;
}
})
.show();
}
String getTitle() {
return title;
}
void setTitle(String title) {
this.title = title;
if (titleView != null) {
titleView.setText(title);
}
}
String getSummary() {
return summary;
}
void setSummary(String summary) {
this.summary = summary;
if (seekBarView != null) {
summaryView.setText(summary);
}
}
boolean isEnabled() {
if (!isView && viewStateListener != null) {
return viewStateListener.isEnabled();
} else return isEnabled;
}
void setEnabled(boolean enabled, boolean viewsOnly) {
Log.d(TAG, "setEnabled = " + enabled);
isEnabled = enabled;
if (viewStateListener != null && !viewsOnly) {
viewStateListener.setEnabled(enabled);
}
if (seekBarView != null) { //theoretically might not always work
Log.d(TAG, "view is disabled!");
seekBarView.setEnabled(enabled);
valueView.setEnabled(enabled);
valueHolderView.setClickable(enabled);
valueHolderView.setEnabled(enabled);
measurementView.setEnabled(enabled);
bottomLineView.setEnabled(enabled);
if (isView) {
titleView.setEnabled(enabled);
summaryView.setEnabled(enabled);
}
}
}
void setEnabled(boolean enabled) {
setEnabled(enabled, false);
}
int getMaxValue() {
return maxValue;
}
void setMaxValue(int maxValue) {
this.maxValue = maxValue;
if (seekBarView != null) {
// if (minValue <= 0 && maxValue >= 0) {
// seekBarView.setMax(maxValue - minValue);
// }
// else {
seekBarView.setMax((maxValue - minValue) / interval);
// }
setBarProgress(currentValue - minValue);
}
}
private void setBarProgress(int value) {
seekBarView.setProgress(value / interval);
}
int getMinValue() {
return minValue;
}
public void setMinValue(int minValue) {
this.minValue = minValue;
setMaxValue(maxValue);
}
int getInterval() {
return interval;
}
void setInterval(int interval) {
this.interval = interval;
}
int getCurrentValue() {
return currentValue;
}
void setCurrentValue(int value) {
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
if (changeValueListener != null) {
if (!changeValueListener.onChange(value)) {
return;
}
}
currentValue = value;
if (seekBarView != null) {
seekBarView.setOnSeekBarChangeListener(null);
setBarProgress(currentValue - minValue);
seekBarView.setOnSeekBarChangeListener(this);
valueView.setText(String.valueOf(currentValue));
}
if (persistValueListener != null) {
persistValueListener.persistInt(value);
}
}
String getMeasurementUnit() {
return measurementUnit;
}
void setMeasurementUnit(String measurementUnit) {
this.measurementUnit = measurementUnit;
if (measurementView != null) {
measurementView.setText(measurementUnit);
}
}
boolean isDialogEnabled() {
return dialogEnabled;
}
void setDialogEnabled(boolean dialogEnabled) {
this.dialogEnabled = dialogEnabled;
if (valueHolderView != null && bottomLineView != null) {
valueHolderView.setOnClickListener(dialogEnabled ? this : null);
valueHolderView.setClickable(dialogEnabled);
bottomLineView.setVisibility(dialogEnabled ? View.VISIBLE : View.INVISIBLE);
}
}
void setDialogStyle(int dialogStyle) {
this.dialogStyle = dialogStyle;
}
}
Hi there.
I'm on 0.12, not the latest , but I wanted to report that dragging the seekbar doesn't seem to be working for me on marshmallow. Same code runs fine on lollipop.
Thanks for the help,
N
Default Value does not works. Lib version 2.3.0+
Tested on 25 sdk level.
I can't seem to it using android:icon or app:icon attribute in preference xml.
my preference.xml
>
<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="your_pref_key"
android:title="Sensibility"
android:enabled="false"
android:defaultValue="5000"
sample:msbp_minValue="100"
sample:msbp_maxValue="60"
sample:msbp_interval="200"
sample:msbp_measurementUnit="G"/>
<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="your_pref_key"
android:title="Number Of Shake"
android:summary="Some summary"
android:enabled="false"
android:defaultValue="5000"
sample:msbp_minValue="100"
sample:msbp_maxValue="10000"
sample:msbp_interval="200"/>
Fragment
public class SettingsFragment extends PreferenceFragmentCompat {
SeekBar sensibility;
TextView sensibility_label;
SeekBar shakeTime;
TextView shakeTime_label;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.settings);
}
}
gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.makeramen:roundedimageview:2.2.0'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:preference-v7:23.0.1'
compile 'com.android.support:preference-v14:23.0.1'
compile 'com.pavelsikun:material-seekbar-preference:0.11'
}
How can I solve this problem?
just wondering since there's been no activity in a while..
This ability should be forbid or may be controlled by option.
And there is always focus on EditText
I'm trying to set my SeekBarPreference default value, but I don't know how to do that. In a ListPreference, for example, I can do something like this:
ListPreference lp= (ListPreference) findPreference("list_preference");
if(lp.getValue() == null) {
lp.setValue("2");
}
How to do that in a SeekBarPreference?
Hi, how can I remove the dialog header image?
I mean this one: https://raw.githubusercontent.com/MrBIMC/MaterialSeekBarPreference/master/ART/screen_3.jpg
Thanks!
Hi, I have 2 seekbars but only the second one updates when I use the slider. The first one allows me to move the slider but doesn't update the value. Here is my xml for the preferences layout.
>
<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="distance_from_target"
android:title="Distance from pin"
android:summary="Distance from location to start playing"
android:enabled="true"
android:defaultValue="10"
sample:msbp_minValue="10"
sample:msbp_maxValue="100"
sample:msbp_interval="10"
sample:msbp_measurementUnit="meters"
sample:msbp_dialogEnabled="false"/>
<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="poll_time"
android:title="Update GPS every"
android:summary="How often the GPS location is updated."
android:enabled="true"
android:defaultValue="20"
sample:msbp_minValue="20"
sample:msbp_maxValue="120"
sample:msbp_interval="10"
sample:msbp_measurementUnit="seconds"
sample:msbp_dialogEnabled="false"/>
Do you really need API level 11? I want to use it in my app, but it's API 8 :( Br, Michael
I have notice some code changes in recent update that you have delete some code with discreteSeekBar
. So it there any plan to integrate with it?
In some cases it would be useful to support floating point numbers as values, not just ints.
Implementation idea: to keep it simple, perhaps just a 'factor' attribute, which would be applied when displaying in edit field and when reading from edit field and then just a couple overloaded methods to read/write float value.
Hello. When I try to put negative values to min/max, the seekbar goes to zero (but the value in summary is ok). Here is my config
<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="power"
android:title="@string/power"
android:summary="@string/power_exp"
android:defaultValue="-20"
materialdesign:minValue="-80"
materialdesign:maxValue="-30"
materialdesign:interval="1"
materialdesign:measurementUnit="@string/dbm" />
I followed your instructions as regards setting the seekbar in my app and got it referenced nicely. My issue is that I can't get the value set by the seekbar from sharedpreference in an activity. Your "how-to" only shows how to setup the Preference XML file, what about using that set value in an activity?
I am displaying SeekBarPreferenceCompat together with other preferences using com.android.support:preference-v14:25.3.1. While all looks good on newer devices, the seekbar preference looks different from the rest on older devices, for example:
On Gingerbread
On Kindle running Android 4.3.
With this patch from https://github.com/mtotschnig/MaterialSeekBarPreference/tree/improvement/align-with-layout-specific-to-each-level I am able to fix the issue. This works for me, since I am only using SeekBarPreferenceCompat, but it would break if you are also using SeekBarPreference or SeekBarPreferenceView directly.
I'm using both this library and SeekBar
https://github.com/neild001/SeekArc
and there is an issue with attribute "enabled" already being defined, which result in me not being able to use both libraries. a simple name changed with the prefix would fix it.
There seems to be a strong dependency upon the setting of android:theme in the manifest file. Without specifying this attribute a strange XML parse error results. Can a suggestion, or requirement, for this attribute be provided?
There is a bug when there are two PreferenceCompat in settings, but must be far apart, when you scroll are synchronized with the same value.
I solved by moving 'persistInt' in 'onStopTrackingTouch'.
Greetings.
When the parent view is relatively small the seek bar is set to fill the whole view and the value cannot be seen.
Hi again,
I'm on 0.12 and using this on a PreferenceFragment .. defaultValue doesn't seem to be working as the seekbar seems to be set to max when defaults should be applied.
<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="drops"
android:title="Drops"
android:summary="@string/pref_drops"
android:enabled="true"
android:defaultValue="20"
sample:msbp_minValue="1"
sample:msbp_maxValue="40"
sample:msbp_interval="1"
sample:msbp_measurementUnit="drops">
</com.pavelsikun.seekbarpreference.SeekBarPreference>
thanks for your help!
N
This library has helped me a lot in implementing a pretty common preference pattern. I do have a small request, however. Can you please add the ability to disable EditText, i.e. can we just use it as a label that just changes when you drag the seekbar.
Thanks.
You did a great job ! why not a view ...But It would be better if we can able to add a view to existing layout. .
Adding android:dependency="id_of_checkbox" should allow the SeekBarPreference to be enabled and disabled. Instead the SeekBarPreference is disabled and not enabled automatically until the Preference fragment is closed and reopened.
I define SeekBarPreference like this:
<com.pavelsikun.seekbarpreference.SeekBarPreference
android:key="sizeOfCircle"
android:title="x"
android:summary="x"
android:defaultValue="30"
android:enabled="true"
app:msbp_maxValue="100"
app:msbp_minValue="1"
app:msbp_interval="1"
/>
However, I found the default value is always 50.
I am using compile 'com.pavelsikun:material-seekbar-preference:0.12.1+'
Hello.
Please externalize message for:
customValueView.setHint("Wrong Input!");
Thank you.
When using Android Studio 2.3, I get this error :
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 25.1.1, 23.4.0.
I want to use the latest support library, could you update yours ?
I use this in my gradle file : compile 'com.pavelsikun:material-seekbar-preference:2.3.0'
Thanks for sharing and open sourcing this widget! If I get time I'll see if I can also contribute some improvements. But, for now, as I review this, I'm going to point out some bugs for other devs and contributors to see.
Tested on Moto X Android 5.1 and Nexus 4 Android 5.0, in a new project, target SDK 22.
Version 2.2 was properly sending the Preference.OnPreferenceChangeListener callback, but in 2.3 it no longer fires.
It would be great if your lib supports float numbers.
e.g. in https://github.com/yahoo/android-range-seek-bar it made through generic
Hi there,
I was wondering if you have tested this in a preferenceFragment, as my implementation doesn't seem to save the preferences at all.
thanks for your help,
N
I have been doing some experiments with theming my Preferences, and I noticed that I can set the textAppearanceListItem and textAppearanceListItemSecondary to change the text style for most Preferences, but the MaterialSeekBarPreference does not.
Could you add the style attributes to the Title and Summary TextViews so that it matches the surrounding items?
This is an enhancement request, for Java method equivalents for the XML attributes. It'll take awhile for me to get time for it, so I'm leaving it open for anybody now.
My use case: Lately-ish, I've been minimizing XML use, and mostly only using XML as "content holders" for various configurations with all the content being added programmatically. Also, it allows for easier A/B testing by changing values dynamically over network rather than recompiling in different static values.
I have a recycler view which has SeekBarPreferenceView in its rows and after a row is recycled another SeekBar appears on the view.
Could this code be issues in the SeekBarPreferenceView on lines 45-50? Why is the seek bar view inflated and added in the onAttachedToWindow()
method?
@OverRide
protected void onAttachedToWindow() {
super.onAttachedToWindow();
View view = inflate(getContext(), R.layout.seekbar_view_layout, this);
controllerDelegate.onBind(view);
}
Any one please suggest me why default value is not working, it is always getting 50% as default value.
It would be nice to have one extra attribute to specify the singular form of the measurement unit.
When the value becomes "1", the new attribute will be used instead.
For example:
1 minutes vs 1 minute
How do I make the measurement unit value update with the drag on the SeekBar? I saw no example in the sample.thanks
Is this not supposed to change the slider thumb to whatever value in the parameter?
I have a design which uses the seek bar preference in a navigation drawer, when the seekbar is dragged to the left the touch is not caught and instead the drawer is closed. I have a fix which grabs the parent and calls requestDisallowInterceptTouchEvent with true when action down is seen. It is then set to false when action up event is called.
Tried registering a change listener with mSeekBar.setOnPreferenceChangeListener
. But the listener is never called. So there's no way for me to know what is happening when the preference changed (or potentially to reject certain values).
Does SeekBarPreference
need to call callChangeListener
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.