Show current value as summary for dialog preferences

This commit is contained in:
Christopher Eby 2011-11-05 13:33:50 -05:00
parent be06557594
commit 16d8f56764
7 changed files with 132 additions and 83 deletions

View File

@ -82,21 +82,20 @@ THE SOFTWARE.
<!-- Preferences -->
<plurals name="seconds">
<item quantity="one">01 sekund</item>
<item quantity="other">%02d sekunder</item>
<item quantity="one">1 sekund</item>
<item quantity="other">%d sekunder</item>
</plurals>
<plurals name="minutes">
<item quantity="one">01 minutt</item>
<item quantity="other">%02d minutter</item>
<item quantity="one">1 minutt</item>
<item quantity="other">%d minutter</item>
</plurals>
<plurals name="hours">
<item quantity="one">01 time</item>
<item quantity="other">%02d timer</item>
<item quantity="one">1 time</item>
<item quantity="other">%d timer</item>
</plurals>
<string name="pref_output">Lydutgang</string>
<string name="volume_title">Volum</string>
<string name="volume_summary">Musill volum</string>
<string name="media_button_title">Bruk Hodetelefon Knapper</string>
<string name="media_button_summary">Ett tapp for spille / pause. Dobbeltapp for neste.</string>
<string name="headset_only_title">Kun Ekstern Lydutgang</string>
@ -108,23 +107,16 @@ THE SOFTWARE.
<string name="pref_notifications">Varsler</string>
<string name="notification_mode_title">Varselmodus</string>
<string name="notification_mode_summary">Når skal varsler vises</string>
<string name="notification_action_title">Varsel Handling</string>
<string name="notification_action_summary">Hva skjer når varselet er trykket</string>
<string name="notification_invert_color_title">Inverter Varsling Farge</string>
<string name="notification_invert_color_summary">Bruk hvit tekst i stedet for svart tekst</string>
<string name="pref_playback_view">Avspill Visning</string>
<string name="display_mode_title">Visningsmodus</string>
<string name="display_mode_summary">Utseendet og plasseringen av låten bilde og info.</string>
<string name="swipe_up_action_title">Sveip Opp Handling</string>
<string name="swipe_up_action_summary">Hva skjer når en sveip opp gest er utført</string>
<string name="swipe_down_action_title">Sveip Ned Handling</string>
<string name="swipe_down_action_summary">Hva skjer når en sveip ned gest er utført</string>
<string name="cover_press_action_title">Cover Tapp Handling</string>
<string name="cover_press_action_summary">Hva skjer når coveret er tappet på</string>
<string name="cover_longpress_action_title">Lang Cover Trykk Handling</string>
<string name="cover_longpress_action_summary">Hva skjer når coveret er lenge trykket på</string>
<string name="disable_cover_art_title">Deaktiver Cover bilde</string>
<string name="disable_cover_art_summary">Ikke vis cover bilde noen steder i programmet</string>
@ -134,13 +126,11 @@ THE SOFTWARE.
<string name="controls_in_selector_title">Medieknapper i Bibliotek</string>
<string name="controls_in_selector_summary">Vis låten som spilles og mediekontrollene i biblioteket</string>
<string name="default_action_title">Standard Handling</string>
<string name="default_action_summary">Hva skjer når et element blir tappet på</string>
<string name="pref_misc">Diverse Egenskaper</string>
<string name="use_idle_timeout_title">Aktiver Tomgang</string>
<string name="use_idle_timeout_summary">Når aktiv, blir avspillingen stoppet etter en gitt periode med inaktivitet</string>
<string name="idle_timeout_title">Tomgang</string>
<string name="idle_timeout_summary">Mengde tid som må passere før det blir tomgang</string>
<string name="double_tap_title">Dobbeltapp Widget</string>
<string name="double_tap_summary">Dobbeltapping på 1x1 widget vil åpne spilleren. Forvent en 400ms forsinkelse før widgeten reagerer på handlingen.</string>
<string name="scrobble_title">Bruk ScrobbleDroid API</string>

View File

@ -86,24 +86,23 @@ THE SOFTWARE.
<!-- Preferences -->
<plurals name="seconds">
<item quantity="one">01 sekunda</item>
<item quantity="few">%02d sekundy</item>
<item quantity="other">%02d sekúnd</item>
<item quantity="one">1 sekunda</item>
<item quantity="few">%d sekundy</item>
<item quantity="other">%d sekúnd</item>
</plurals>
<plurals name="minutes">
<item quantity="one">01 minúta</item>
<item quantity="few">%02d minúty</item>
<item quantity="other">%02d minút</item>
<item quantity="one">1 minúta</item>
<item quantity="few">%d minúty</item>
<item quantity="other">%d minút</item>
</plurals>
<plurals name="hours">
<item quantity="one">01 hodina</item>
<item quantity="few">%02d hodiny</item>
<item quantity="other">%02d hodín</item>
<item quantity="one">1 hodina</item>
<item quantity="few">%d hodiny</item>
<item quantity="other">%d hodín</item>
</plurals>
<string name="pref_output">Zvukový výstup</string>
<string name="volume_title">Hlasitosť</string>
<string name="volume_summary">Hlasitosť hudby</string>
<string name="media_button_title">Použiť ovládanie náhlavnej súpravy</string>
<string name="media_button_summary">Jedným stlačením prehrať/pozastaviť. Dvojitým stlačením nasledujúca.</string>
<string name="headset_only_title">Iba externý výstup</string>
@ -115,23 +114,16 @@ THE SOFTWARE.
<string name="pref_notifications">Upozornenia</string>
<string name="notification_mode_title">Režim upozornení</string>
<string name="notification_mode_summary">Kedy zobraziť upozornenie.</string>
<string name="notification_action_title">Akcia upozornenia</string>
<string name="notification_action_summary">Čo spraviť keď je na upozornenie ťuknuté.</string>
<string name="notification_invert_color_title">Invertovať farbu oznámenia</string>
<string name="notification_invert_color_summary">Použije biely text namiesto čierneho.</string>
<string name="pref_playback_view">Zobrazenie prehrávania</string>
<string name="display_mode_title">Režim zobrazenia</string>
<string name="display_mode_summary">Vzhľad a pozícia grafiky skladby a informácií.</string>
<string name="swipe_up_action_title">Akcia prejedním prstu nahor</string>
<string name="swipe_up_action_summary">Čo spraviť, keď prejdete prstom nahor.</string>
<string name="swipe_down_action_title">Prejdením prstom nadol</string>
<string name="swipe_down_action_summary">Čo spraviť keď prejdete prstom nadol.</string>
<string name="cover_press_action_title">Akcia pri ťuknutí na obal</string>
<string name="cover_press_action_summary">Čo spraviť, keď ťuknete na obal albumu.</string>
<string name="cover_longpress_action_title">Akcia pri podržaní na obale</string>
<string name="cover_longpress_action_summary">Čo spraviť, keď ťuknete a podržíte na obal albumu.</string>
<string name="disable_cover_art_title">Vypnúť obal albumu</string>
<string name="disable_cover_art_summary">Nebude zobrazovať obal albumu nikde v aplikácii.</string>
@ -141,13 +133,11 @@ THE SOFTWARE.
<string name="controls_in_selector_title">Ovládanie v knižnici</string>
<string name="controls_in_selector_summary">V knižnici zobrazí aktuálne prehrávanú skladbu a ovládanie prehrávania.</string>
<string name="default_action_title">Predvolená akcia</string>
<string name="default_action_summary">Čo spraviť, keď ťuknete na položku.</string>
<string name="pref_misc">Ostatné funkcie</string>
<string name="use_idle_timeout_title">Povoliť časový limit nečinnosti</string>
<string name="use_idle_timeout_summary">Keď je povolené, prehrávanie sa zastaví po danom čase nečinnosti.</string>
<string name="idle_timeout_title">Časový limit nečinnosti</string>
<string name="idle_timeout_summary">Čas, ktorý musí ubehnúť pred prejdením do nečinnosti.</string>
<string name="double_tap_title">Dvojité ťuknutie na miniaplikáciu</string>
<string name="double_tap_summary">Dvojité ťuknutie na 1×1 miniaplikáciu otvorí prehrávač. Vytvorí oneskorenie 0,4 sekúnd pred tým, ako miniaplikácia reaguje na akciu.</string>
<string name="scrobble_title">Použiť ScrobbleDroid API</string>

View File

@ -109,21 +109,20 @@ THE SOFTWARE.
<!-- Preferences -->
<plurals name="seconds">
<item quantity="one">01 second</item>
<item quantity="other">%02d seconds</item>
<item quantity="one">1 second</item>
<item quantity="other">%d seconds</item>
</plurals>
<plurals name="minutes">
<item quantity="one">01 minute</item>
<item quantity="other">%02d minutes</item>
<item quantity="one">1 minute</item>
<item quantity="other">%d minutes</item>
</plurals>
<plurals name="hours">
<item quantity="one">01 hour</item>
<item quantity="other">%02d hours</item>
<item quantity="one">1 hour</item>
<item quantity="other">%d hours</item>
</plurals>
<string name="pref_output">Audio Output</string>
<string name="volume_title">Volume</string>
<string name="volume_summary">Music volume</string>
<string name="media_button_title">Use Headset Controls</string>
<string name="media_button_summary">Single click for play/pause. Double click for next.</string>
<string name="headset_only_title">External Output Only</string>
@ -135,23 +134,16 @@ THE SOFTWARE.
<string name="pref_notifications">Notifications</string>
<string name="notification_mode_title">Notification Mode</string>
<string name="notification_mode_summary">When to show the notification</string>
<string name="notification_action_title">Notification Action</string>
<string name="notification_action_summary">What to do when the notification is pressed</string>
<string name="notification_invert_color_title">Invert Notification Color</string>
<string name="notification_invert_color_summary">Use white text instead of black text</string>
<string name="pref_playback_view">Playback View</string>
<string name="display_mode_title">Display Mode</string>
<string name="display_mode_summary">The appearance and position of the song art and info.</string>
<string name="swipe_up_action_title">Swipe Up Action</string>
<string name="swipe_up_action_summary">What to do when a swipe up gesture is performed</string>
<string name="swipe_down_action_title">Swipe Down Action</string>
<string name="swipe_down_action_summary">What to do when a swipe down gesture is performed</string>
<string name="cover_press_action_title">Cover Tap Action</string>
<string name="cover_press_action_summary">What to do when the cover is tapped</string>
<string name="cover_longpress_action_title">Cover Long Press Action</string>
<string name="cover_longpress_action_summary">What to do when the cover is long-pressed</string>
<string name="disable_cover_art_title">Disable Cover Art</string>
<string name="disable_cover_art_summary">Do not show cover art anywhere in the application</string>
@ -161,7 +153,6 @@ THE SOFTWARE.
<string name="controls_in_selector_title">Controls in Library</string>
<string name="controls_in_selector_summary">Show the currently playing song and media controls in the library view</string>
<string name="default_action_title">Default Action</string>
<string name="default_action_summary">What to do when an item is tapped</string>
<string name="pref_misc">Miscellaneous Features</string>
<string name="disable_lockscreen_title">Disable Lockscreen</string>
@ -169,7 +160,6 @@ THE SOFTWARE.
<string name="use_idle_timeout_title">Enable Idle Timeout</string>
<string name="use_idle_timeout_summary">When active, playback will be stopped after the given period of inactivity</string>
<string name="idle_timeout_title">Idle Timeout</string>
<string name="idle_timeout_summary">The amount of time that must pass before becoming idle</string>
<string name="double_tap_title">Double Tap Widget</string>
<string name="double_tap_summary">Double-tapping the 1x1 widget will open the player. Incurs a 400ms delay before the widget responds to actions.</string>
<string name="scrobble_title">Use ScrobbleDroid API</string>

View File

@ -26,8 +26,7 @@ THE SOFTWARE.
<PreferenceCategory android:title="@string/pref_output">
<org.kreed.vanilla.VolumePreference
android:key="volume"
android:title="@string/volume_title"
android:summary="@string/volume_summary" />
android:title="@string/volume_title" />
<CheckBoxPreference
android:key="media_button"
android:title="@string/media_button_title"
@ -50,17 +49,15 @@ THE SOFTWARE.
android:defaultValue="false" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_notifications">
<ListPreference
<org.kreed.vanilla.ListPreferenceSummary
android:key="notification_mode"
android:title="@string/notification_mode_title"
android:summary="@string/notification_mode_summary"
android:entries="@array/notification_mode_entries"
android:entryValues="@array/entry_values"
android:defaultValue="1" />
<ListPreference
<org.kreed.vanilla.ListPreferenceSummary
android:key="notification_action"
android:title="@string/notification_action_title"
android:summary="@string/notification_action_summary"
android:entries="@array/notification_action_entries"
android:entryValues="@array/entry_values"
android:defaultValue="0" />
@ -71,38 +68,33 @@ THE SOFTWARE.
android:defaultValue="false" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_playback_view">
<ListPreference
<org.kreed.vanilla.ListPreferenceSummary
android:key="display_mode"
android:title="@string/display_mode_title"
android:summary="@string/display_mode_summary"
android:entries="@array/display_mode_entries"
android:entryValues="@array/entry_values"
android:defaultValue="2" />
<ListPreference
<org.kreed.vanilla.ListPreferenceSummary
android:key="swipe_up_action"
android:title="@string/swipe_up_action_title"
android:summary="@string/swipe_up_action_summary"
android:entries="@array/swipe_action_entries"
android:entryValues="@array/swipe_action_values"
android:defaultValue="Nothing" />
<ListPreference
<org.kreed.vanilla.ListPreferenceSummary
android:key="swipe_down_action"
android:title="@string/swipe_down_action_title"
android:summary="@string/swipe_down_action_summary"
android:entries="@array/swipe_action_entries"
android:entryValues="@array/swipe_action_values"
android:defaultValue="Nothing" />
<ListPreference
<org.kreed.vanilla.ListPreferenceSummary
android:key="cover_press_action"
android:title="@string/cover_press_action_title"
android:summary="@string/cover_press_action_summary"
android:entries="@array/swipe_action_entries"
android:entryValues="@array/swipe_action_values"
android:defaultValue="ToggleControls" />
<ListPreference
<org.kreed.vanilla.ListPreferenceSummary
android:key="cover_longpress_action"
android:title="@string/cover_longpress_action_title"
android:summary="@string/cover_longpress_action_summary"
android:entries="@array/swipe_action_entries"
android:entryValues="@array/swipe_action_values"
android:defaultValue="PlayPause" />
@ -123,10 +115,9 @@ THE SOFTWARE.
android:title="@string/controls_in_selector_title"
android:summary="@string/controls_in_selector_summary"
android:defaultValue="false" />
<ListPreference
<org.kreed.vanilla.ListPreferenceSummary
android:key="default_action_int"
android:title="@string/default_action_title"
android:summary="@string/default_action_summary"
android:entries="@array/default_action_entries"
android:entryValues="@array/entry_values"
android:defaultValue="0" />
@ -145,7 +136,6 @@ THE SOFTWARE.
<org.kreed.vanilla.IdlePreference
android:key="idle_timeout"
android:title="@string/idle_timeout_title"
android:summary="@string/idle_timeout_summary"
android:dependency="use_idle_timeout" />
<CheckBoxPreference
android:key="double_tap"

View File

@ -40,6 +40,7 @@ import android.widget.TextView;
* (6 hours). The values range on an approximately exponential scale.
*/
public class IdlePreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
private static final int DEFAULT_VALUE = 3600;
private static final int MIN = 60;
private static final int MAX = 21600;
@ -58,13 +59,19 @@ public class IdlePreference extends DialogPreference implements SeekBar.OnSeekBa
super(context, attrs);
}
@Override
public CharSequence getSummary()
{
return formatTime(getPersistedInt(DEFAULT_VALUE));
}
@Override
protected void onPrepareDialogBuilder(Builder builder)
{
Context context = getContext();
ViewGroup.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mValue = getPersistedInt(3600);
mValue = getPersistedInt(DEFAULT_VALUE);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
@ -89,12 +96,14 @@ public class IdlePreference extends DialogPreference implements SeekBar.OnSeekBa
}
/**
* Update the text view with the current value.
* Format seconds into a human-readable time description.
*
* @param value The time, in seconds.
* @return A human-readable string, such as "1 hour, 21 minutes"
*/
private void updateText()
private String formatTime(int value)
{
Resources res = getContext().getResources();
int value = mValue;
StringBuilder text = new StringBuilder();
if (value >= 3600) {
int hours = value / 3600;
@ -109,16 +118,27 @@ public class IdlePreference extends DialogPreference implements SeekBar.OnSeekBa
int seconds = value - minutes * 60;
text.append(res.getQuantityString(R.plurals.seconds, seconds, seconds));
}
mValueText.setText(text.toString());
return text.toString();
}
/**
* Update the text view with the current value.
*/
private void updateText()
{
mValueText.setText(formatTime(mValue));
}
@Override
protected void onDialogClosed(boolean positiveResult)
{
if (positiveResult && shouldPersist())
if (positiveResult && shouldPersist()) {
persistInt(mValue);
notifyChanged();
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
// Approximate an exponential curve with x^4. Produces a value from MIN-MAX.
@ -131,10 +151,12 @@ public class IdlePreference extends DialogPreference implements SeekBar.OnSeekBa
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2011 Christopher Eby <kreed@kreed.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.kreed.vanilla;
import android.content.Context;
import android.preference.ListPreference;
import android.util.AttributeSet;
/**
* Overrides ListPreference to show the selected value as the summary.
*
* (ListPreference should supposedly be able to do this itself if %s is in the
* summary, but as far as I can tell that behavior is broken.)
*/
public class ListPreferenceSummary extends ListPreference {
public ListPreferenceSummary(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
public CharSequence getSummary()
{
return getEntry();
}
@Override
protected void onDialogClosed(boolean positiveResult)
{
super.onDialogClosed(positiveResult);
notifyChanged();
}
}

View File

@ -37,11 +37,19 @@ import android.widget.SeekBar;
* roughly exponential scale.
*/
public class VolumePreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
private static final float DEFAULT_VALUE = 1.0f;
public VolumePreference(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
public CharSequence getSummary()
{
return String.format("%.0f%%", Math.pow(getPersistedFloat(DEFAULT_VALUE), 0.33f) * 100);
}
@Override
protected void onPrepareDialogBuilder(Builder builder)
{
@ -53,27 +61,33 @@ public class VolumePreference extends DialogPreference implements SeekBar.OnSeek
SeekBar seekBar = new SeekBar(getContext());
seekBar.setPadding(20, 20, 20, 20);
seekBar.setLayoutParams(params);
seekBar.setMax(1000);
seekBar.setProgress((int)(Math.pow(getPersistedFloat(1.0f), 0.25f) * 1000));
seekBar.setMax(100);
seekBar.setProgress((int)(Math.pow(getPersistedFloat(DEFAULT_VALUE), 0.33f) * 100));
seekBar.setOnSeekBarChangeListener(this);
builder.setView(seekBar);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
// Approximate an exponential curve with x^4. Produces a value from 0.0 - 1.0.
// Approximate an exponential curve with x^3. Produces a value from 0.0 - 1.0.
if (fromUser && shouldPersist()) {
float value = seekBar.getProgress() / 1000.0f;
value *= value;
value *= value;
persistFloat(value);
persistFloat((float)Math.pow(seekBar.getProgress() / 100.0f, 3));
}
}
@Override
protected void onDialogClosed(boolean positiveResult)
{
notifyChanged();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}