Code Monkey home page Code Monkey logo

materialseekbarpreference's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

materialseekbarpreference's Issues

Class cast exception

Getting an exception when adding this to my Preferences:
com.pavelsikun.seekbarpreference.SeekBarPreference cannot be cast to android.support.v7.preference.Preference

Cannot set defaultValue in Android 6.x?

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+'

Marshmallow issue with seekbar drag

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

Measurement unit value update

How do I make the measurement unit value update with the drag on the SeekBar? I saw no example in the sample.thanks

Getting current value from the seekbar

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?

Two seekbars, one doesn't update.

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"/>

How to Fix Error inflating class com.pavelsikun.seekbarpreference.SeekBarPreference

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?

API 11 needed?

Do you really need API level 11? I want to use it in my app, but it's API 8 :( Br, Michael

Support library conflicts

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'

Set default value

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?

defaultValue

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

Bug

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.

Negative values

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" />

Dependency upon activity android:theme setting

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?

PreferenceChangeListener not invoked

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?

Exception raised during rendering

Error text :-
Exception raised during rendering: com.pavelsikun.seekbarpreference.SeekBarPreferenceView cannot be cast to android.preference.Preference (Details) Tip: Try to refresh the layout.

screenshot_10

Xml Code :-
screenshot_11

Ability to disable EditText

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.

Why not a View ??

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. .

Create methods for programmatic use

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.

PreferenceFragment

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

Allow or support floating point values

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.

Add the ability to style title and summary

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?

Rendering does not match with other preferences on legacy api levels

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
gingerbread
On Kindle running Android 4.3.
kindle
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.

MAX and MIN AND INTERVAL BUG

I find some problem,and I think...
In com.pavelsikun.seekbarpreference PreferenceControllerDelegate

  1. preferencevalue not change;

  2. 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;

/**

  • Created by Pavel Sikun on 28.05.16.
    */

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;
}

}

dependency tag does not enable SeekBarPreference

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.

seek bar does not catch drag when used in a navigation drawer

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.

measurement unit for singular item

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:

  • app:msbp_measurementUnit="minutes"
  • app:msbp_measurementUnitSingle="minute"

1 minutes vs 1 minute

Duplicate seek bar in a RecyclerView

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);
}

Adding/removing number from input loses focus and changes keyboard

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.

  • Deleting a number (or inputting a number) in input area causes focus to be lost and keyboard to change from numeric to regular text.

Tested on Moto X Android 5.1 and Nexus 4 Android 5.0, in a new project, target SDK 22.

Особые параметры

Вот с этими параметрами слайдер начинает отбражать фигню.
<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"/>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.