Android Open Source - Matrix-Mate Number Picker Preference






From Project

Back to project page Matrix-Mate.

License

The source code is released under:

MIT License

If you think the Android project Matrix-Mate 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.RSen.MatrixMate;
/*from  ww w  .  j  a v  a 2  s  . c o m*/
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;

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

  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, 0);
    mEndRange = arr.getInteger(R.styleable.numberpicker_endRange, 200);
    mDefault = arr.getInteger(R.styleable.numberpicker_defaultValue, 0);

    arr.recycle();

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

  public void onClick(DialogInterface dialog, int which) {
    switch (which) {
    case DialogInterface.BUTTON_POSITIVE:
      saveValue(mPicker.getCurrent());
      break;
    default:
      break;
    }
  }

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

  private void saveValue(int val) {
    getEditor().putInt(getKey(), val).commit();
    notifyChanged();
  }

  private int getValue() {
    return getSharedPreferences().getInt(getKey(), mDefault);
  }
}




Java Source Code List

com.RSen.MatrixMate.GmailSender.java
com.RSen.MatrixMate.JSSEProvider.java
com.RSen.MatrixMate.MainSearchLayout.java
com.RSen.MatrixMate.ManipulateActivity.java
com.RSen.MatrixMate.MatrixMateActivity.java
com.RSen.MatrixMate.NumberPickerButton.java
com.RSen.MatrixMate.NumberPickerDialog.java
com.RSen.MatrixMate.NumberPickerPreference.java
com.RSen.MatrixMate.NumberPicker.java
com.RSen.MatrixMate.ReportDialog.java
com.RSen.MatrixMate.SimpleEula.java