Android Open Source - graph-android Number Picker Preference






From Project

Back to project page graph-android.

License

The source code is released under:

GNU General Public License

If you think the Android project graph-android 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 com.michaelnovakjr.numberpicker;
/*from  ww w . ja  v  a  2s  .c  o m*/
import lorian.graph.android.GraphActivity;
import lorian.graph.android.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;


public class NumberPickerPreference extends DialogPreference {
    private NumberPicker mPicker;
    private int mStartRange;
    private int mEndRange;
    private int mCurrentVal;

    public NumberPickerPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        if (attrs == null) {
            return;
        }
        
        TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.numberpicker);
        mStartRange = arr.getInteger(R.styleable.numberpicker_startRange, Integer.MIN_VALUE);
        mEndRange = arr.getInteger(R.styleable.numberpicker_endRange, Integer.MAX_VALUE);
        mCurrentVal = PreferenceManager.getDefaultSharedPreferences(context).getInt(getKey(), arr.getInteger(R.styleable.numberpicker_defaultValue, 0)); 
        //arr.getInteger(R.styleable.numberpicker_defaultValue, 0);
       
        arr.recycle();
        
        this.setSummary((CharSequence) String.valueOf(mCurrentVal)); 
        setDialogLayoutResource(R.layout.pref_number_picker);
    }

    public NumberPickerPreference(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.dialogPreferenceStyle);
    }

    public NumberPickerPreference(Context context) {
        this(context, null);
    }

    @Override
    protected void onBindDialogView(View view) {
        super.onBindDialogView(view);
        mPicker = (NumberPicker) view.findViewById(R.id.pref_num_picker);
        mPicker.setRange(mStartRange, mEndRange);
        mPicker.setCurrent(mCurrentVal);
    }

    @Override
    protected void onDialogClosed(boolean positiveResult) {
        super.onDialogClosed(positiveResult);

        final int origValue = getValue();
        final int curValue = mPicker.getCurrent();

        if (positiveResult && (curValue != origValue)) {
            if (callChangeListener(curValue)) {
                saveValue(curValue);
            }
        }
    }

    public void setRange(int start, int end) {
        mPicker.setRange(start, end);
    }

    private boolean saveValue(int val) {
      this.mCurrentVal = val;
      this.setSummary((CharSequence) String.valueOf(mCurrentVal));    
        return persistInt(val);
    }

    private int getValue() {
      return mCurrentVal;
        //return getSharedPreferences().getInt(getKey(), mCurrentVal);
 

    }
  
    public void notifyValueChanged(int newValue)
    {
      saveValue(newValue);
    }
    
  
    
}




Java Source Code List

com.michaelnovakjr.numberpicker.NumberPickerButton.java
com.michaelnovakjr.numberpicker.NumberPickerDialog.java
com.michaelnovakjr.numberpicker.NumberPickerPreference.java
com.michaelnovakjr.numberpicker.NumberPicker.java
lorian.graph.WindowSettings.java
lorian.graph.android.FunctionDataArray.java
lorian.graph.android.GraphActivity.java
lorian.graph.android.InputActivity.java
lorian.graph.android.Util.java
lorian.graph.android.WindowSettingsActivity.java
lorian.graph.android.opengl.Color.java
lorian.graph.android.opengl.GraphRenderer.java
lorian.graph.android.opengl.GraphSurfaceView.java
lorian.graph.function.Calculate.java
lorian.graph.function.Factor.java
lorian.graph.function.Function.java
lorian.graph.function.MathChars.java
lorian.graph.function.MathFunctions.java
lorian.graph.function.PointXY.java
lorian.graph.function.Term.java
lorian.graph.function.Util.java
lorian.graph.function.Variable.java
yuku.ambilwarna.AmbilWarnaDialog.java
yuku.ambilwarna.AmbilWarnaKotak.java