Android Open Source - speedofsound Speed Slider Preference






From Project

Back to project page speedofsound.

License

The source code is released under:

GNU General Public License

If you think the Android project speedofsound listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.codechunk.speedofsound.util;
//  w ww.  j av a 2  s  . co m
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;

/**
 * A preference that is displayed as a seek bar.
 *
 * Customized for speed ranges; localized to the currently-selected units
 * when the user opens it. minValue/maxValue should be in m/s.
 */
public class SpeedSliderPreference extends SliderPreference {
  public SpeedSliderPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  protected int localMin;
  protected int localMax;

  /**
   * Set up the preference display.
   */
  @Override
  protected View onCreateDialogView() {
    // grabbing the saved value before calling superclass;
    // when the seekbar is set up there the value will be clamped to
    // unlocalized min/max which would give us the wrong value
    int val = getPersistedInt(-1);

    super.onCreateDialogView();

    // grab the units currently in use
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String units = prefs.getString("speed_units", "");
    this.units = " " + units;

    // adjust the maximum value for the correct units; maxValue is in m/s
    this.localMax = (int) SpeedConversions.localizedSpeed(units, this.maxValue);
    this.localMin = (int) SpeedConversions.localizedSpeed(units, this.minValue);
    this.seekBar.setMax(this.localMax);
    this.seekBar.setProgress(val - this.localMin);

    // restore the value and redraw
    this.value = val;
    this.updateDisplay();

    return this.view;
  }

  public void onProgressChanged(SeekBar seekBar, int value, boolean fromTouch) {
    this.value = value + this.localMin;
    this.updateDisplay();
  }


}




Java Source Code List

net.codechunk.speedofsound.LocaleActivity.java
net.codechunk.speedofsound.MapperActivity.java
net.codechunk.speedofsound.PreferencesActivity.java
net.codechunk.speedofsound.SongTracker.java
net.codechunk.speedofsound.SpeedActivity.java
net.codechunk.speedofsound.players.AndroidMusicPlayer.java
net.codechunk.speedofsound.players.BasePlayer.java
net.codechunk.speedofsound.players.HTCPlayer.java
net.codechunk.speedofsound.players.LastFmAPIPlayer.java
net.codechunk.speedofsound.players.SLSAPIPlayer.java
net.codechunk.speedofsound.players.SamsungPlayer.java
net.codechunk.speedofsound.players.WinampPlayer.java
net.codechunk.speedofsound.service.SoundServiceManager.java
net.codechunk.speedofsound.service.SoundService.java
net.codechunk.speedofsound.service.VolumeConversion.java
net.codechunk.speedofsound.service.VolumeThread.java
net.codechunk.speedofsound.util.AppPreferences.java
net.codechunk.speedofsound.util.AverageSpeed.java
net.codechunk.speedofsound.util.ColorCreator.java
net.codechunk.speedofsound.util.SliderPreference.java
net.codechunk.speedofsound.util.SongInfo.java
net.codechunk.speedofsound.util.SpeedConversions.java
net.codechunk.speedofsound.util.SpeedSliderPreference.java