consp1racy / android-support-preference

Android Preferences according to Material design specs
Apache License 2.0
331 stars 49 forks source link

Request: SeekBarDialogPreference.setInfo(...) + realtime listener support #27

Open anggrayudi opened 8 years ago

anggrayudi commented 8 years ago

Hi @consp1racy, I want to introduce you a new attribute for SeekBarPreference. I have edited below picture from your screenshot. Look at the preferences. Each of them had a unit. For Media preference, the unit is % (percent), and for Vibration the unit is ms (milliseconds) which means the device will be vibrated for 200ms. I hope you can add this feature by adding the following attribute to the preference:

<SeekBarPreference
    android:key="vibrate_duration"
    app:asp_preferenceUnit="ms"
    ... />

Also, once user seek the bar, the value will be updated automatically.

unit pref


I have the second request for you, i.e. by adding app:asp_dialogContent="Some explanation." attribute to SeekBarDialogPreference. Adding this attribute makes a big difference between SeekBarPreference and SeekBarDialogPreference. Let's say that you have a SeekBarDialogPreference without any explanation about it. If that's so, why don't you just use SeekBarPreference which already had no explanation but a title? You can see the edited screenshot below:

<SeekBarDialogPreference
    android:key="custom_volume"
    app:asp_dialogContent="This is an explanation."
    ... />

dialog explanation pref

And the last request is, I want you to add setMin(int min) method and app:asp_min to this preference. We can define the minimum value for the SeekBar. For example:

<SeekBarPreference
    android:max="500"
    app:asp_min="20"
    app:asp_preferenceUnit="ms"
    ... />

The SeekBar had range value between 20 to 500 with unit in milliseconds.


Thanks in advance. I hope you accept this idea.

JoseGD commented 8 years ago

Don't know what decision @consp1racy will take, but for now you can do that setting a value via setSummary(), at least for SeekBarPreference. Not the same result but very similar

consp1racy commented 8 years ago

Hello @anggrayudi ,

app:asp_min is a good idea, I'll do that for both seek bar preferences.

The unit thing... I think it would be better as app:asp_info similar to Notification.contentInfo. It would handle an arbitrary text and you could hook a seek bar listener to the preference and put value + " ms" to it on change. It makes sense for SeekBarPreference. For SeekBarDialogPreference just use setSummary. It shouldn't be a problem design-wise since you'll probably be using just one type of seek bar preference.

android:dialogMessage is used, well, for dialog message, unfortunately it's ignored in SeekBarDialogPreference because we're using a custom layout. But it's possible to add it. I'm going to put it above the seek bar, similar to EditTextPreference.

@JoseGD I'd use setSummary just for SeekBarDialogPreference. setSummary in SeekBarPreference is used for the greyed title instead of regular setTitle - at least in the sample.

Thank you both for ideas, this is totally doable.

consp1racy commented 8 years ago

Everything discussed above should be implemented in latest commit. If you pull the sample app you can test it if it fits your needs. Changes include:

I'm going to try to figure out if the "info" text view could be included in SeekBarDialogPreference as well. If you find any issues let me know. I'd like to release next version within a week.

anggrayudi commented 8 years ago

@consp1racy, I think the best design for SeekBarDialogPreference is look like this:

seekbardialogpreference

The dialog must use Material Dialogs specifications as explained by Google.

consp1racy commented 8 years ago

The original was taken straight from AOSP 5.0 so you can't get more Material than that since MD specs are silent about seek bars. In the next version the android:dialogMessage attribute will be honored and the SeekBarDialogPreference dialog will look like this:

image

SeekBarPreference just like SeekBarDialogPreference will understand app:asp_min attribute and in combination with app:asp_info attribute could produce following results:

image image

If you need anything special on top of what SeekBarDialogPreference offers feel free to subclass XpSeekBarPreferenceDialogFragment and tailor it to your own needs. You can open your new dialog fragment instead by implementing PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback in your activity like so:

@Override
public boolean onPreferenceDisplayDialog(PreferenceFragmentCompat preferenceFragmentCompat, Preference preference) {
    final String key = preference.getKey();
    DialogFragment f;
    if (preference instanceof SeekBarDialogPreference) {
        f = MySeekBarPreferenceDialogFragment.newInstance(key);
    } else {
        return false;
    }

    f.setTargetFragment(preferenceFragmentCompat, 0);
    f.show(this.getSupportFragmentManager(), key);
    return true;
}
anggrayudi commented 8 years ago

@consp1racy, that's a pretty dialog. But, where's the asp_info and the current value for the SeekBar? Just like SeekBarPreference, you had better to put them on the dialog to make users know the current SeekBar's value or position.

consp1racy commented 8 years ago

@anggrayudi Damn right it's a pretty dialog, that was the goal. :D

Connecting OnSeekBarChangeListener to potential SeekBarDialogPreference.setInfo(...) has proven to be difficult since the preference object has no link to its dialog.

Two options come to mind: 1) Subclass XpSeekBarPreferenceDialog and setup everything inside it just as you want - mentioned in my previous comment. 2) Make a subscreen where you can use a Preference with a title and summary do describe the screen and then as many SeekBarPreferences as you want with subtitle and info.

consp1racy commented 8 years ago

Looks like seek bar preferences will have to have a asp_unit attribute. Otherwise TalkBack will report "0-100%" when working with seek bars.

anggrayudi commented 8 years ago

@consp1racy, when you will release the next version of this library with some fixes? I hope you can release it ASAP. Thanks

consp1racy commented 8 years ago

@anggrayudi What's "some fixes", please, be specific. The library is stable as I see it now.

I currently have no clear direction how to alter SeekBarDialogPreference and SeekBarPreference works as intended.

If you need anything else feel free to make your own preference classes. My package should be extensible enough.

anggrayudi commented 8 years ago

@consp1racy, I mean, fixes for SeekBarDialogPreference and SeekBarPreference.

consp1racy commented 8 years ago

I don't want to repeat myself, but

@anggrayudi What's "some fixes", please, be specific.

They're working as intended as far as I can see. If you need anything else I gave you suggestions for alternative solutions and

If you need anything else feel free to make your own preference classes. My package should be extensible enough.

What more do you want?

I will not be implementing https://github.com/consp1racy/android-support-preference/issues/27#issuecomment-211017526. It looks very specialized and you can do it yourself in your app.

Potential TODOs on SeekBarDialogPreference are these: