Java 类android.widget.NumberPicker.OnValueChangeListener 实例源码

项目:AndroidMaterialPreferences    文件:DigitPickerPreference.java   
/**
 * Creates and returns a listener, which allows to observe the {@link NumberPicker} widgets,
 * which are used by the preference.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnValueChangeListener}
 */
private OnValueChangeListener createNumberPickerListener() {
    return new OnValueChangeListener() {

        @Override
        public void onValueChange(final android.widget.NumberPicker picker, final int oldValue,
                                  final int newValue) {
            int value = 0;

            for (int i = 0; i < numberPickers.length; i++) {
                int exponent = numberPickers.length - i - 1;
                value += numberPickers[i].getValue() * Math.pow(NUMERIC_SYTEM, exponent);
            }

            currentNumber = value;
        }

    };
}
项目:CompoundViews    文件:MainActivity.java   
@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mFriendCountPicker = (NumberPicker) findViewById(R.id.friend_count);
    mFriendNameView = (FriendNameView) findViewById(R.id.friend_names);
    mCountFriendsButton = (Button) findViewById(R.id.count_friends_button);

    mFriendCountPicker.setMaxValue(10);
    mFriendCountPicker.setOnValueChangedListener(new OnValueChangeListener() {
        @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            mFriendNameView.setFriendCount(newVal);
        }
    });

    mCountFriendsButton.setOnClickListener(new OnClickListener() {
        @Override public void onClick(View v) {
            List<String> names = mFriendNameView.getFriendNames();
            Intent i = new Intent(MainActivity.this, FriendCountActivity.class);
            i.putStringArrayListExtra("names", new ArrayList<String>(names));
            startActivity(i);
        }
    });
}
项目:Gizwits-SmartBuld_Android    文件:GosEditDeviceDelayActivity.java   
private void initEvent() {
        tvSave.setOnClickListener(this);
        tvSave.setClickable(false);
        tvBack.setOnClickListener(this);
//      mPick.setMaxValue(59);
        mPick.setMaxValue(60);
        mPick.setMinValue(1);
        mPick.setOnLongPressUpdateInterval(100);
        mPick.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
        setNumberPickerDividerColor(mPick);

        if (countDownMinute == 0) {
            mPick.setValue(1);
            tvSave.setClickable(true);
            tvSave.setTextColor(getResources().getColor(R.color.text_blue));
        } else {
            mPick.setValue(countDownMinute);
        }

        mPick.setOnValueChangedListener(new OnValueChangeListener() {

            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                tvSave.setClickable(true);
                tvSave.setTextColor(getResources().getColor(R.color.text_blue));
            }
        });
    }
项目:AndroidMaterialPreferences    文件:NumberPickerPreference.java   
/**
 * Creates and returns a listener, which allows to observe the {@link NumberPicker}, which is
 * used by the preference.
 *
 * @return The listener, which has been created, as an {@link OnValueChangeListener}
 */
private OnValueChangeListener createNumberPickerListener() {
    return new OnValueChangeListener() {

        @Override
        public void onValueChange(final android.widget.NumberPicker numberPicker,
                                  final int oldValue, final int newValue) {
            numberPicker.setValue(newValue);
            currentIndex = getMinNumber() + newValue * getStepSize();
        }

    };
}
项目:SlideDateTimePicker    文件:TimeFragment.java   
/**
 * Workaround for bug in Android TimePicker where the onTimeChanged() callback
 * is not invoked when the user toggles between AM/PM. But we need to be able
 * to detect this in order to dynamically update the tab title properly when
 * the user toggles between AM/PM.
 *
 * Registered as Issue 18982:
 *
 * https://code.google.com/p/android/issues/detail?id=18982
 */
private void fixTimePickerBug18982()
{
    View amPmView = ((ViewGroup) mTimePicker.getChildAt(0)).getChildAt(3);

    if (amPmView instanceof NumberPicker)
    {
        ((NumberPicker) amPmView).setOnValueChangedListener(new OnValueChangeListener() {

            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal)
            {
                if (picker.getValue() == 1)  // PM
                {
                    if (mTimePicker.getCurrentHour() < 12)
                        mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() + 12);
                }
                else  // AM
                {
                    if (mTimePicker.getCurrentHour() >= 12)
                        mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() - 12);
                }

                mCallback.onTimeChanged(
                    mTimePicker.getCurrentHour(),
                    mTimePicker.getCurrentMinute());
            }
        });
    }
}
项目:SlideDayTimePicker    文件:TimeFragment.java   
/**
 * Workaround for bug in Android TimePicker where the onTimeChanged() callback
 * is not invoked when the user toggles between AM/PM. But we need to be able
 * to detect this in order to dynamically update the tab title properly when
 * the user toggles between AM/PM.
 *
 * Registered as Issue 18982:
 *
 * https://code.google.com/p/android/issues/detail?id=18982
 */
private void fixTimePickerBug18982()
{
    View amPmView = ((ViewGroup) mTimePicker.getChildAt(0)).getChildAt(3);

    if (amPmView instanceof NumberPicker)
    {
        ((NumberPicker) amPmView).setOnValueChangedListener(new OnValueChangeListener() {

            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal)
            {
                if (picker.getValue() == 1)  // PM
                {
                    if (mTimePicker.getCurrentHour() < 12)
                        mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() + 12);
                }
                else  // AM
                {
                    if (mTimePicker.getCurrentHour() >= 12)
                        mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() - 12);
                }

                mCallback.onTimeChanged(
                    mTimePicker.getCurrentHour(),
                    mTimePicker.getCurrentMinute());
            }
        });
    }
}
项目:nexus-camera    文件:CountdownTimerPopup.java   
public void initialize(ListPreference timer, ListPreference beep) {
    mTimer = timer;
    mBeep = beep;
    // Set title.
    mTitle.setText(mTimer.getTitle());

    // Duration
    CharSequence[] entries = mTimer.getEntryValues();
    mDurations = new String[entries.length];
    Locale locale = getResources().getConfiguration().locale;
    mDurations[0] = getResources().getString(R.string.setting_off); // Off
    for (int i = 1; i < entries.length; i++)
        mDurations[i] =  String.format(locale, "%d", Integer.parseInt(entries[i].toString()));
    int durationCount = mDurations.length;
    mNumberSpinner = (NumberPicker) findViewById(R.id.duration);
    mNumberSpinner.setMinValue(0);
    mNumberSpinner.setMaxValue(durationCount - 1);
    mNumberSpinner.setDisplayedValues(mDurations);
    mNumberSpinner.setWrapSelectorWheel(false);
    mNumberSpinner.setOnValueChangedListener(new OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldValue, int newValue) {
            setTimeSelectionEnabled(newValue != 0);
        }
    });
    mConfirmButton = (Button) findViewById(R.id.timer_set_button);
    mPickerTitle = findViewById(R.id.set_time_interval_title);

    // Disable focus on the spinners to prevent keyboard from coming up
    mNumberSpinner.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    mConfirmButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            updateInputState();
        }
    });
    mTimerSound = (CheckBox) findViewById(R.id.sound_check_box);
    mSoundTitle = findViewById(R.id.beep_title);
}
项目:SlideDateTimePicker-master    文件:TimeFragment.java   
/**
 * Workaround for bug in Android TimePicker where the onTimeChanged() callback
 * is not invoked when the user toggles between AM/PM. But we need to be able
 * to detect this in order to dynamically update the tab title properly when
 * the user toggles between AM/PM.
 *
 * Registered as Issue 18982:
 *
 * https://code.google.com/p/android/issues/detail?id=18982
 */
private void fixTimePickerBug18982()
{
    View amPmView = ((ViewGroup) mTimePicker.getChildAt(0)).getChildAt(3);

    if (amPmView instanceof NumberPicker)
    {
        ((NumberPicker) amPmView).setOnValueChangedListener(new OnValueChangeListener() {

            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal)
            {
                if (picker.getValue() == 1)  // PM
                {
                    if (mTimePicker.getCurrentHour() < 12)
                        mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() + 12);
                }
                else  // AM
                {
                    if (mTimePicker.getCurrentHour() >= 12)
                        mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() - 12);
                }

                mCallback.onTimeChanged(
                    mTimePicker.getCurrentHour(),
                    mTimePicker.getCurrentMinute());
            }
        });
    }
}
项目:BatteryAlarm    文件:NumberPickerFragment.java   
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    mCurNumber = getArguments().getInt(CUR_NUMBER);
    mMaxNumber = getArguments().getInt(MAX_NUMBER);
    mMinNumber = getArguments().getInt(MIN_NUMBER);

    View v = getActivity().getLayoutInflater().inflate(
            R.layout.dialog_number, null);

    NumberPicker numberPicker = (NumberPicker) v
            .findViewById(R.id.dialog_number_numberPicker);
    numberPicker.setMinValue(mMinNumber);
    numberPicker.setMaxValue(mMaxNumber);
    numberPicker.setValue(mCurNumber);
    numberPicker.setOnValueChangedListener(new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker picker, int oldVal,
                int newVal) {
            mCurNumber = picker.getValue();
            getArguments().putInt(CUR_NUMBER, mCurNumber);

        }
    });

    return new AlertDialog.Builder(getActivity())
            .setView(v)
            .setTitle(R.string.string_set_new_critical_level)
            .setPositiveButton(android.R.string.ok,
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            sendResult();

                        }
                    }).create();
}
项目:SlideDayTimePicker    文件:DayFragment.java   
/**
 * Create and return the user interface view for this fragment.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    int initialDay = getArguments().getInt("initialDay");
    boolean isCustomDaysArraySpecified = getArguments().getBoolean("isCustomDaysArraySpecified");

    String[] daysArray;
    if (isCustomDaysArraySpecified)
    {
        daysArray = getArguments().getStringArray("customDaysArray");
    }
    else
    {
        daysArray = getResources().getStringArray(R.array.days_array);
    }

    // Unless we inflate using a cloned inflater with a Holo theme,
    // on Lollipop devices the TimePicker will be the new-style
    // radial TimePicker, which is not what we want. So we will
    // clone the inflater that we're given but with our specified
    // theme, then inflate the layout with this new inflater.
    int theme = getArguments().getInt("theme");

    Context contextThemeWrapper = new ContextThemeWrapper(
            getActivity(),
            theme == SlideDayTimePicker.HOLO_DARK ?
                    android.R.style.Theme_Holo : android.R.style.Theme_Holo_Light);

    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

    View v = localInflater.inflate(R.layout.fragment_day, container, false);

    CustomNumberPicker dayPicker = (CustomNumberPicker) v.findViewById(R.id.dayPicker);
    // remove blinking cursor from NumberPicker
    enableNumberPickerEditing(dayPicker, false);
    // block keyboard popping up on touch
    dayPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    dayPicker.setMinValue(0);
    dayPicker.setMaxValue(daysArray.length - 1);
    dayPicker.setDisplayedValues(daysArray);
    dayPicker.setValue(initialDay);
    dayPicker.setOnValueChangedListener(new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal)
        {
            mCallback.onDayChanged(newVal);
        }
    });

    return v;
}
项目:Smartlab    文件:PersianDatePicker.java   
public PersianDatePicker(final Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View root = inflater.inflate(R.layout.pdp, this);
    yearNumberPicker = (NumberPicker) root
            .findViewById(R.id.yearNumberPicker);
    monthNumberPicker = (NumberPicker) root
            .findViewById(R.id.monthNumberPicker);
    dayNumberPicker = (NumberPicker) root
            .findViewById(R.id.dayNumberPicker);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersianDatePicker, 0, 0);
    int year = 1393,month=6,day=19;

    year = a.getInteger(R.styleable.PersianDatePicker_year, 1393);
    month = a.getInteger(R.styleable.PersianDatePicker_month, 6);
    day = a.getInteger(R.styleable.PersianDatePicker_day, 19);

    a.recycle();

    yearNumberPicker.setMinValue(1380);
    yearNumberPicker.setMaxValue(1400);
    yearNumberPicker.setValue(year);

    monthNumberPicker.setMinValue(1);
    monthNumberPicker.setMaxValue(12);
    monthNumberPicker.setValue(month);

    dayNumberPicker.setMaxValue(31);
    dayNumberPicker.setMinValue(1);
    dayNumberPicker.setValue(day);

    yearNumberPicker.setOnValueChangedListener(new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker np, int oldValue, int newValue) {
            Toast.makeText(context, "Year changed:" + oldValue + " -> " + newValue, Toast.LENGTH_LONG).show();
        }
    });
}
项目:SimpleStrengthLog    文件:LogActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_log);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
       boolean keepScreenOnSetting = settings.getBoolean("screenOn", true);

       if(keepScreenOnSetting) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        Log.i("SETTINGS", "Keeping screen on, per request");
       } else {
        Log.i("SETTINGS", "Not keeping screen on");
       }

       this.metric = settings.getBoolean("metricUnits", false);
       this.weightScale = metric ? 1 : 5;

    currentLogs = new ArrayList<LogEntry>();
    previousLogs = new ArrayList<LogEntry>();

    currentExercise = (Exercise) getIntent().getExtras().getSerializable("exercise");

    TextView weightPickerLabel = (TextView) findViewById(R.id.weightPickerLabel);
    weightPickerLabel.setText(getResources().getString( metric ? R.string.weightPickerLabelMetric : R.string.weightPickerLabelImperial));

    NumberPicker weightPicker = (NumberPicker) findViewById(R.id.weightPicker);
    weightPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    String[] displayedValues = new String[NUM_WEIGHT_VALUES];
    //String weightUnits = metric ? "kg" : "lbs";
    // Populate the array
    for (int i = 0; i < NUM_WEIGHT_VALUES; i++) 
        displayedValues[i] = String.valueOf(weightScale * (i + 1));

    weightPicker.setMinValue(0);
    weightPicker.setMaxValue(displayedValues.length - 1);
    weightPicker.setDisplayedValues(displayedValues);
    weightPicker.setWrapSelectorWheel(false);

    NumberPicker repsPicker = (NumberPicker) findViewById(R.id.repsPicker);
    repsPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    String[] displayedReps = new String[NUM_REP_VALUES];
    // Populate the array
    for (int i = 0; i < NUM_REP_VALUES; i++)
        displayedReps[i] = (i + 1)+"";

    repsPicker.setMinValue(0);
    repsPicker.setMaxValue(displayedReps.length - 1);
    repsPicker.setDisplayedValues(displayedReps);
    repsPicker.setWrapSelectorWheel(false);

    OnValueChangeListener onValueChangeListener = new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker arg0, int arg1, int arg2) {
            showCurrentLogs();
        }

    };
    weightPicker.setOnValueChangedListener(onValueChangeListener);
    repsPicker.setOnValueChangedListener(onValueChangeListener);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ActionBar ab = getActionBar();
        ab.setTitle(currentExercise.name);
        if(currentExercise.muscles != null && currentExercise.muscles.length > 0) {
            ab.setSubtitle(Util.join(currentExercise.muscles, ", ", null));
        }
    }

    File dir = Util.getLogStorageDir(getApplicationContext());

    findViewById(R.id.buttonBar).setVisibility(View.INVISIBLE);
    findViewById(R.id.currentLogsLayout).setVisibility(View.INVISIBLE);
    findViewById(R.id.previousLogsLayout).setVisibility(View.INVISIBLE);
    findViewById(R.id.logLoadProgress).setVisibility(View.VISIBLE);

    new LoadLogData(this, currentExercise, dir).execute();
}
项目:android-chromium-view    文件:TwoFieldDatePicker.java   
public TwoFieldDatePicker(Context context, long minValue, long maxValue) {
    super(context, null, android.R.attr.datePickerStyle);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.two_field_date_picker, this, true);

    OnValueChangeListener onChangeListener = new OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            int year = getYear();
            int positionInYear = getPositionInYear();
            // take care of wrapping of days and months to update greater fields
            if (picker == mPositionInYearSpinner) {
                positionInYear = newVal;
                if (oldVal == picker.getMaxValue() && newVal == picker.getMinValue()) {
                    year += 1;
                } else if (oldVal == picker.getMinValue() && newVal == picker.getMaxValue()) {
                    year -=1;
                }
            } else if (picker == mYearSpinner) {
                year = newVal;
             } else {
                throw new IllegalArgumentException();
            }

            // now set the date to the adjusted one
            setCurrentDate(year, positionInYear);
            updateSpinners();
            notifyDateChanged();
        }
    };

    mCurrentDate = Calendar.getInstance();
    if (minValue >= maxValue) {
        mMinDate = Calendar.getInstance();
        mMinDate.set(0, 0, 1);
        mMaxDate = Calendar.getInstance();
        mMaxDate.set(9999, 0, 1);
    } else {
        mMinDate = createDateFromValue(minValue);
        mMaxDate = createDateFromValue(maxValue);
    }

    // month
    mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_year);
    mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
    mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);

    // year
    mYearSpinner = (NumberPicker) findViewById(R.id.year);
    mYearSpinner.setOnLongPressUpdateInterval(100);
    mYearSpinner.setOnValueChangedListener(onChangeListener);
}
项目:SimpleCardioLog    文件:LogActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_log);
    // Show the Up button in the action bar.
    getActionBar().setDisplayHomeAsUpEnabled(true);
    ActionBar ab = getActionBar();

    // Application State Setup
    currentExercise = (Exercise) getIntent().getExtras().getSerializable("exercise");
    logs = new HashMap<LocalDate, List<LogEntry>>();

    ab.setTitle(currentExercise.name);

    if (savedInstanceState != null && savedInstanceState.containsKey("ManuallySelectedCals")) {
        manuallySelectedCals = savedInstanceState.getBoolean("ManuallySelectedCals");
    } else {
        manuallySelectedCals = false;
    }

    NumberPicker minutesPicker = (NumberPicker) findViewById(R.id.minutesPicker);
    setPickerRange(minutesPicker, 1, MINUTES_MAX, 1, BigDecimal.ONE);
    minutesPicker.setOnValueChangedListener(this);

    if (currentExercise.isUnitless()) {
        findViewById(R.id.unitSelection).setVisibility(View.GONE);
        minutesPicker.setOnScrollListener(this);
    } else {
        findViewById(R.id.unitSelection).setVisibility(View.VISIBLE);

        TextView unitTextView = (TextView) findViewById(R.id.unitTextView);
        unitTextView.setText(currentExercise.units);

        NumberPicker unitPicker = (NumberPicker) findViewById(R.id.unitPicker);
        BigDecimal increment = new BigDecimal(currentExercise.precision);
        setPickerRange(unitPicker, 1, UNIT_MAX, 1, increment);
        unitPicker.setOnValueChangedListener(this);
        unitPicker.setOnScrollListener(this);
    }

    NumberPicker caloriesPicker = (NumberPicker) findViewById(R.id.caloriesPicker);
    setPickerRange(caloriesPicker, 1, CALORIE_MAX, 1, CALORIE_INCREMENT);
    caloriesPicker.setOnValueChangedListener(new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker arg0, int arg1, int arg2) {
            manuallySelectedCals = true;
            showCurrentLogs();
        }

    });

    findViewById(R.id.saveButton).setOnClickListener(this);
    findViewById(R.id.undoButton).setOnClickListener(this);

    findViewById(R.id.buttonBar).setVisibility(View.INVISIBLE);
    findViewById(R.id.logsScroll).setVisibility(View.INVISIBLE);
    findViewById(R.id.logLoadProgress).setVisibility(View.VISIBLE);

    new LoadLogData(this, currentExercise, Util.getLogStorageDir(getApplicationContext()), MAX_REGRESSION_POINTS).execute();
}
项目:android-chromium    文件:TwoFieldDatePicker.java   
public TwoFieldDatePicker(Context context, long minValue, long maxValue) {
    super(context, null, android.R.attr.datePickerStyle);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.two_field_date_picker, this, true);

    OnValueChangeListener onChangeListener = new OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            int year = getYear();
            int positionInYear = getPositionInYear();
            // take care of wrapping of days and months to update greater fields
            if (picker == mPositionInYearSpinner) {
                positionInYear = newVal;
                if (oldVal == picker.getMaxValue() && newVal == picker.getMinValue()) {
                    year += 1;
                    positionInYear = getMinPositionInYear(year);
                } else if (oldVal == picker.getMinValue() && newVal == picker.getMaxValue()) {
                    year -=1;
                    positionInYear = getMaxPositionInYear(year);
                }
            } else if (picker == mYearSpinner) {
                year = newVal;
             } else {
                throw new IllegalArgumentException();
            }

            // now set the date to the adjusted one
            setCurrentDate(year, positionInYear);
            updateSpinners();
            notifyDateChanged();
        }
    };

    mCurrentDate = Calendar.getInstance();
    if (minValue >= maxValue) {
        mMinDate = Calendar.getInstance();
        mMinDate.set(0, 0, 1);
        mMaxDate = Calendar.getInstance();
        mMaxDate.set(9999, 0, 1);
    } else {
        mMinDate = createDateFromValue(minValue);
        mMaxDate = createDateFromValue(maxValue);
    }

    // month
    mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_year);
    mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
    mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);

    // year
    mYearSpinner = (NumberPicker) findViewById(R.id.year);
    mYearSpinner.setOnLongPressUpdateInterval(100);
    mYearSpinner.setOnValueChangedListener(onChangeListener);
}
项目:chromium_webview    文件:TwoFieldDatePicker.java   
public TwoFieldDatePicker(Context context, double minValue, double maxValue) {
    super(context, null, android.R.attr.datePickerStyle);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.two_field_date_picker, this, true);

    OnValueChangeListener onChangeListener = new OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            int year = getYear();
            int positionInYear = getPositionInYear();
            // take care of wrapping of days and months to update greater fields
            if (picker == mPositionInYearSpinner) {
                positionInYear = newVal;
                if (oldVal == picker.getMaxValue() && newVal == picker.getMinValue()) {
                    year += 1;
                    positionInYear = getMinPositionInYear(year);
                } else if (oldVal == picker.getMinValue() && newVal == picker.getMaxValue()) {
                    year -= 1;
                    positionInYear = getMaxPositionInYear(year);
                }
            } else if (picker == mYearSpinner) {
                year = newVal;
            } else {
                throw new IllegalArgumentException();
            }

            // now set the date to the adjusted one
            setCurrentDate(year, positionInYear);
            updateSpinners();
            notifyDateChanged();
        }
    };

    mCurrentDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    if (minValue >= maxValue) {
        mMinDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        mMinDate.set(0, 0, 1);
        mMaxDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        mMaxDate.set(9999, 0, 1);
    } else {
        mMinDate = getDateForValue(minValue);
        mMaxDate = getDateForValue(maxValue);
    }

    // month
    mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_year);
    mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
    mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);

    // year
    mYearSpinner = (NumberPicker) findViewById(R.id.year);
    mYearSpinner.setOnLongPressUpdateInterval(100);
    mYearSpinner.setOnValueChangedListener(onChangeListener);
}
项目:cordova-android-chromium    文件:TwoFieldDatePicker.java   
public TwoFieldDatePicker(Context context, long minValue, long maxValue) {
    super(context, null, android.R.attr.datePickerStyle);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.two_field_date_picker, this, true);

    OnValueChangeListener onChangeListener = new OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            int year = getYear();
            int positionInYear = getPositionInYear();
            // take care of wrapping of days and months to update greater fields
            if (picker == mPositionInYearSpinner) {
                positionInYear = newVal;
                if (oldVal == picker.getMaxValue() && newVal == picker.getMinValue()) {
                    year += 1;
                    positionInYear = getMinPositionInYear(year);
                } else if (oldVal == picker.getMinValue() && newVal == picker.getMaxValue()) {
                    year -=1;
                    positionInYear = getMaxPositionInYear(year);
                }
            } else if (picker == mYearSpinner) {
                year = newVal;
             } else {
                throw new IllegalArgumentException();
            }

            // now set the date to the adjusted one
            setCurrentDate(year, positionInYear);
            updateSpinners();
            notifyDateChanged();
        }
    };

    mCurrentDate = Calendar.getInstance();
    if (minValue >= maxValue) {
        mMinDate = Calendar.getInstance();
        mMinDate.set(0, 0, 1);
        mMaxDate = Calendar.getInstance();
        mMaxDate.set(9999, 0, 1);
    } else {
        mMinDate = createDateFromValue(minValue);
        mMaxDate = createDateFromValue(maxValue);
    }

    // month
    mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_year);
    mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
    mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);

    // year
    mYearSpinner = (NumberPicker) findViewById(R.id.year);
    mYearSpinner.setOnLongPressUpdateInterval(100);
    mYearSpinner.setOnValueChangedListener(onChangeListener);
}