@Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    String name = getArguments().getString(NAME);
    String description = getArguments().getString(DESCRIPTION);
    Log.d("Fragment", pageId + "");
    View v = inflater.inflate(R.layout.fragment_vote, container, false);
    title = (TextView) v.findViewById(R.id.titleText);
    des = (TextView) v.findViewById(R.id.desText);
    title.setText(name);
    des.setText(description);
    np = (NumberPicker) v.findViewById(R.id.numberPicker);
    np.setMaxValue(value + left);
    np.setValue(value);
    np.setOnValueChangedListener(
        new OnValueChangeListener() {

          @Override
          public void onValueChange(NumberPicker arg0, int arg1, int arg2) {
            value = arg2;
            voteActivity.valueChange();
          }
        });
    return v;
  }
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    final PersistenceManager persistenceManager = PersistenceManager.getInstance(getContext());

    View fragmentView = View.inflate(getContext(), R.layout.fragment_widget_update_interval, null);
    NumberPicker picker = (NumberPicker) fragmentView.findViewById(R.id.picker_dialog_widget_time);
    picker.setMinValue(0);
    picker.setMaxValue(GeneralHelper.WIDGET_UPDATE_HOUR_INTERVALS.length - 1);
    picker.setValue(persistenceManager.getWidgetPickerValue());
    picker.setDisplayedValues(GeneralHelper.getWidgetPickerDisplayedValues());
    picker.setOnValueChangedListener(
        new NumberPicker.OnValueChangeListener() {
          @Override
          public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            persistenceManager.setWidgetPickerValue(newVal);
            setAlarmForWidgetUpdate(
                getContext(), GeneralHelper.getMillisForWidgetDisplayedValue(newVal));
          }
        });

    return fragmentView;
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   int minimumForAmber = 0, minimumForRed = 0;
   super.onCreate(savedInstanceState);
   //        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
   //                WindowManager.LayoutParams.FLAG_FULLSCREEN);
   setContentView(R.layout.activity_advanced_speeches_timer_setting);
   setTitle("Select Time");
   final NumberPicker greenNumberPicker = (NumberPicker) findViewById(R.id.numberPicker);
   final NumberPicker amberNumberPicker = (NumberPicker) findViewById(R.id.numberPicker2);
   final NumberPicker redNumberPicker = (NumberPicker) findViewById(R.id.numberPicker3);
   numberPickerSetup(greenNumberPicker, 0);
   greenNumberPicker.setOnValueChangedListener(
       new NumberPicker.OnValueChangeListener() {
         @Override
         public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
           numberPickerSetup(amberNumberPicker, newVal);
           amberNumberPicker.setOnValueChangedListener(
               new NumberPicker.OnValueChangeListener() {
                 @Override
                 public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                   numberPickerSetup(redNumberPicker, newVal);
                 }
               });
         }
       });
 }
 public NumberPicker setupSpinner(int id, int min, int max) {
   NumberPicker mSpinner = (NumberPicker) findViewById(id);
   mSpinner.setMinValue(min);
   mSpinner.setMaxValue(max);
   mSpinner.setOnValueChangedListener(mOnChangeListener);
   mSpinner.setOnLongPressUpdateInterval(100);
   return mSpinner;
 }
  private void loadUserHeight() {
    if (null != user.getHeight()) {
      String height[] = user.getHeight().split("-");
      heightFeet = Integer.parseInt(height[0]);
      heightInch = Integer.parseInt(height[1]);
    } else {
      heightFeet = Globals.DEFAULT_HEIGHT_FEET;
      heightInch = Globals.DEFAULT_HEIGHT_INCH;
    }

    pickerHeightFeet.setMinValue(Globals.MIN_HEIGHT_FEET);
    pickerHeightFeet.setMaxValue(Globals.MAX_HEIGHT_FEET);
    pickerHeightFeet.setValue(heightFeet);
    pickerHeightFeet.setWrapSelectorWheel(false);

    pickerHeightFeet.setOnValueChangedListener(
        new NumberPicker.OnValueChangeListener() {

          @Override
          public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            isDataChanged = true;
            Log.v(
                Globals.TAG,
                "picker : " + picker + ", oldVal : " + oldVal + ", newVal : " + newVal);
          }
        });

    pickerHeightInch.setMinValue(Globals.MIN_HEIGHT_INCH);
    pickerHeightInch.setMaxValue(Globals.MAX_HEIGHT_INCH);
    pickerHeightInch.setValue(heightInch);
    pickerHeightInch.setWrapSelectorWheel(false);

    pickerHeightInch.setOnValueChangedListener(
        new NumberPicker.OnValueChangeListener() {

          @Override
          public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            isDataChanged = true;
            Log.v(
                Globals.TAG,
                "picker : " + picker + ", oldVal : " + oldVal + ", newVal : " + newVal);
          }
        });
  }
  public DateTimePicker(Context context) {
    super(context);
    /*
     *獲取系統時間
     */
    mDate = Calendar.getInstance();
    mHour = mDate.get(Calendar.HOUR_OF_DAY);
    mMinute = mDate.get(Calendar.MINUTE);
    /** 加载布局 */
    inflate(context, R.layout.datadialog, this);
    /** 初始化控件 */
    mDateSpinner = (NumberPicker) this.findViewById(R.id.np_date);
    mDateSpinner.setMinValue(0);
    mDateSpinner.setMaxValue(6);
    updateDateControl();
    mDateSpinner.setOnValueChangedListener(mOnDateChangedListener);
    mHourSpinner = (NumberPicker) this.findViewById(R.id.np_hour);
    mHourSpinner.setMaxValue(23);
    mHourSpinner.setMinValue(0);
    mHourSpinner.setValue(mHour);
    mHourSpinner.setOnValueChangedListener(mOnHourChangedListener);
    mHourSpinner.setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);

    mMinuteSpinner = (NumberPicker) this.findViewById(R.id.np_minute);
    mMinuteSpinner.setMaxValue(59);
    mMinuteSpinner.setMinValue(0);
    mMinuteSpinner.setValue(mMinute);
    mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
    mMinuteSpinner.setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
    mMinuteSpinner.setWrapSelectorWheel(true);

    FixScroller mScroller =
        new FixScroller(mDateSpinner.getContext(), new DecelerateInterpolator());
    BaseUtil.setViewPagerScroller(mDateSpinner, mScroller);

    FixScroller mScroller1 =
        new FixScroller(mHourSpinner.getContext(), new DecelerateInterpolator());
    BaseUtil.setViewPagerScroller(mHourSpinner, mScroller1);

    FixScroller mScroller2 =
        new FixScroller(mMinuteSpinner.getContext(), new DecelerateInterpolator());
    BaseUtil.setViewPagerScroller(mMinuteSpinner, mScroller2);
  }
  /** This function defines a Listener for Number Picker element */
  public void addListenerOnNumberPicker() {

    setMinutes.setOnValueChangedListener(
        new OnValueChangeListener() {

          @Override
          public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            setMinuteForAlarm = newVal;
          }
        });
  }
 @Override
 protected void showDialog(Bundle state) {
   super.showDialog(state);
   User user = ((CompassApplication) getContext().getApplicationContext()).getUser();
   mValue = user.getDailyNotifications();
   Dialog dialog = getDialog();
   NumberPicker picker = (NumberPicker) dialog.findViewById(R.id.number_picker_picker);
   picker.setOnValueChangedListener(this);
   picker.setMinValue(0);
   picker.setMaxValue(20);
   picker.setValue(mValue);
   picker.setWrapSelectorWheel(false);
 }
  public void addListenerOnNumberPickerCapacity() {

    txtNumberViewCapacity = (TextView) findViewById(R.id.numberView);
    NumberPicker numberPicker = (NumberPicker) findViewById(R.id.numberPicker);
    numberPicker.setMaxValue(MAX_VALUE);
    numberPicker.setMinValue(MIN_VALUE);
    numberPicker.setWrapSelectorWheel(true);
    numberPicker.setOnValueChangedListener(
        new NumberPicker.OnValueChangeListener() {
          @Override
          public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            txtNumberViewCapacity.setText("Capacidade: " + newVal);
            capacity = newVal;
          }
        });
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    type = SET_SELECTION;
    prev = getArguments().getInt(Constants.TOTAL_PLAYERS_KEY, 8);
    next = Integer.MAX_VALUE;

    final Dialog dialog = new Dialog(getActivity(), AlertDialog.THEME_HOLO_LIGHT);
    dialog.setTitle("Select Number of Total Players");
    dialog.setContentView(R.layout.dialog_number_picker);
    Button negative = (Button) dialog.findViewById(R.id.game_setup_dialog_negativebutton);
    Button positive = (Button) dialog.findViewById(R.id.game_setup_dialog_positivebutton);

    NumberPicker picker = (NumberPicker) dialog.findViewById(R.id.game_setup_dialog_numberpicker);

    picker.setMaxValue(10);
    picker.setMinValue(5);
    picker.setValue(prev);

    picker.setWrapSelectorWheel(false);
    picker.setOnValueChangedListener(this);
    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    negative.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            dialog.dismiss();
          }
        });

    positive.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (prev > next) type = CLEAR_SELECTION;

            if (next == Integer.MAX_VALUE) next = prev;

            getPlotListener().onEventStart(type, next);

            dialog.dismiss();
          }
        });

    return dialog;
  }
  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();
          }
        });
  }
 private void initPicker(NumberPicker picker, int currentValue) {
   picker.setMinValue(1);
   picker.setMaxValue(25);
   picker.setValue(currentValue);
   picker.setFormatter(
       new NumberPicker.Formatter() {
         @Override
         public String format(int value) {
           return String.format("第%1$d周", value);
         }
       });
   picker.setOnValueChangedListener(
       new NumberPicker.OnValueChangeListener() {
         @Override
         public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
           weekResultTv.setText(
               String.format(
                   WEEK_RESULT_FORMAT, startWeekPicker.getValue(), endWeekPicker.getValue()));
         }
       });
 }
  private void loadUserWeight() {
    weightLbs = user.getWeightLbs();
    if (weightLbs <= 0) {
      weightLbs = Globals.DEFAULT_WEIGHT_LBS;
    }

    pickerWeight.setMinValue(Globals.MIN_WEIGHT_LBS);
    pickerWeight.setMaxValue(Globals.MAX_WEIGHT_LBS);
    pickerWeight.setValue(weightLbs);
    pickerWeight.setWrapSelectorWheel(false);

    pickerWeight.setOnValueChangedListener(
        new NumberPicker.OnValueChangeListener() {

          @Override
          public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            isDataChanged = true;
            Log.v(
                Globals.TAG,
                "picker : " + picker + ", oldVal : " + oldVal + ", newVal : " + newVal);
          }
        });
  }
Exemple #14
0
  private void createDelayWithADistraction() {
    final Dialog d = new Dialog(MainActivity.this);
    d.setTitle(getResources().getString(R.string.delay_question));
    d.setContentView(R.layout.dialog_delay);
    Button setDelayButton = (Button) d.findViewById(R.id.button1);
    Button cancelDelayButton = (Button) d.findViewById(R.id.button2);
    final NumberPicker np = (NumberPicker) d.findViewById(R.id.numberPicker1);
    np.setMaxValue(45); // max value 45
    np.setMinValue(10); // min value 10
    np.setValue(prefs.getInt("delaySeconds", 20));
    np.setWrapSelectorWheel(false);
    np.setOnValueChangedListener(this);
    setDelayButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            d.dismiss();
            buttonStartTime.setVisibility(View.GONE);
            textViewShowTime.setVisibility(View.VISIBLE);
            showMinutes(false);
            mProgressBar
                .getBackground()
                .setColorFilter(Color.argb(255, 0, 230, 118), PorterDuff.Mode.SRC_IN);
            mProgressBar
                .getProgressDrawable()
                .setColorFilter(Color.argb(255, 0, 230, 118), PorterDuff.Mode.SRC_IN);
            mProgressBar.setMax(prefs.getInt("delaySeconds", 20));
            int delayInMilliseconds = (prefs.getInt("delaySeconds", 20)) * 1000;
            delayCountDown =
                new CountDownTimer(delayInMilliseconds, 500) {
                  @Override
                  public void onTick(long millisUntilFinished) {
                    long seconds = millisUntilFinished / 1000;
                    mProgressBar.setProgress((int) (millisUntilFinished / 1000));
                    textViewShowTime.setText(
                        String.format("%02d", seconds / 60)
                            + ":"
                            + String.format("%02d", seconds % 60));
                  }

                  @Override
                  public void onFinish() {
                    setTimer();
                    buttonStartTime.setVisibility(View.GONE);
                    textViewShowTime.setVisibility(View.VISIBLE);
                    startTimer();
                    // set volt buttons disabled
                    setButtonDisabled(false);
                    int volt = textViewToInt(volts);
                    increaseThread = increaseVoltToMax(volt);
                  }
                }.start();
          }
        });
    cancelDelayButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            d.dismiss(); // dismiss the dialog
            // Lets not start the timer here as the user might want to change the voltage.
          }
        });
    d.show();
  }
 private void setupPicker() {
   mPicker.setMaxValue(1000);
   mPicker.setMinValue(1);
   mPicker.setOnValueChangedListener(this);
 }
  public LunarDatePicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // initialization based on locale
    setCurrentLocale(Locale.getDefault());

    // /@M:{comment these lines
    //         TypedArray attributesArray = context.obtainStyledAttributes(attrs,
    //         R.styleable.LunarDatePicker,
    //         defStyle, 0);
    //         boolean spinnersShown =
    //         attributesArray.getBoolean(R.styleable.LunarDatePicker_spinnersShown,
    //         DEFAULT_SPINNERS_SHOWN);
    //         boolean calendarViewShown = attributesArray.getBoolean(
    //         R.styleable.LunarDatePicker_calendarViewShown,
    //         DEFAULT_CALENDAR_VIEW_SHOWN);
    //         int startYear =
    //         attributesArray.getInt(R.styleable.LunarDatePicker_startYear,
    //         DEFAULT_START_YEAR);
    //         int endYear = attributesArray.getInt(R.styleable.LunarDatePicker_endYear,
    //         DEFAULT_END_YEAR);
    //         String minDate =
    //         attributesArray.getString(R.styleable.LunarDatePicker_minDate);
    //         String maxDate =
    //         attributesArray.getString(R.styleable.LunarDatePicker_maxDate);
    //         int layoutResourceId =R.layout.date_picker;
    //         attributesArray.getResourceId(R.styleable.LunarDatePicker_layout,
    //         R.layout.date_picker);
    //         attributesArray.recycle();
    // /}

    // /M:add @{
    boolean spinnersShown = DEFAULT_SPINNERS_SHOWN;
    boolean calendarViewShown = DEFAULT_CALENDAR_VIEW_SHOWN;
    int startYear = DEFAULT_START_YEAR;
    int endYear = DEFAULT_END_YEAR;
    int layoutResourceId = R.layout.date_picker;
    // /}

    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(layoutResourceId, this, true);

    OnValueChangeListener onChangeListener =
        new OnValueChangeListener() {
          public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            updateInputState();
            mTempDate.setTimeInMillis(mCurrentDate.getTimeInMillis());
            int gregorianYear = mTempDate.get(Calendar.YEAR);
            int gregorianMonth = mTempDate.get(Calendar.MONTH) + 1;
            int gregorianDay = mTempDate.get(Calendar.DAY_OF_MONTH);
            int lunarDates[] =
                LunarUtil.calculateLunarByGregorian(gregorianYear, gregorianMonth, gregorianDay);

            // take care of wrapping of days and months to update greater
            // fields
            if (picker == mDaySpinner) {
              if (oldVal > 27 && newVal == 1) {
                mTempDate.add(Calendar.DAY_OF_MONTH, 1);
              } else if (oldVal == 1 && newVal > 27) {
                mTempDate.add(Calendar.DAY_OF_MONTH, -1);
              } else {
                mTempDate.add(Calendar.DAY_OF_MONTH, newVal - oldVal);
              }
            } else if (picker == mMonthSpinner) {
              int leapMonth = 0;
              int monthCountDays = 0;
              if (oldVal > 10 && newVal == 0) {
                leapMonth = LunarUtil.leapMonth(lunarDates[0]);
                if (leapMonth == 12) {
                  monthCountDays = LunarUtil.daysOfLeapMonthInLunarYear(lunarDates[0]);
                } else {
                  monthCountDays = LunarUtil.daysOfALunarMonth(lunarDates[0], 12);
                }
                mTempDate.add(Calendar.DAY_OF_MONTH, monthCountDays);

              } else if (oldVal == 0 && newVal > 10) {
                leapMonth = LunarUtil.leapMonth(lunarDates[0] - 1);
                if (leapMonth == 12) {
                  monthCountDays = LunarUtil.daysOfLeapMonthInLunarYear(lunarDates[0]);
                } else {
                  monthCountDays = LunarUtil.daysOfALunarMonth(lunarDates[0] - 1, 12);
                }

                mTempDate.add(Calendar.DAY_OF_MONTH, -monthCountDays);
              } else {
                leapMonth = LunarUtil.leapMonth(lunarDates[0]);
                // move to previous
                if ((newVal - oldVal) < 0) {
                  if (leapMonth == 0) {
                    monthCountDays = LunarUtil.daysOfALunarMonth(lunarDates[0], newVal + 1);
                  } else { // leap year
                    if (newVal < leapMonth) {
                      monthCountDays = LunarUtil.daysOfALunarMonth(lunarDates[0], newVal + 1);
                    } else if (newVal == leapMonth) {
                      monthCountDays = LunarUtil.daysOfLeapMonthInLunarYear(lunarDates[0]);
                    } else {
                      monthCountDays = LunarUtil.daysOfALunarMonth(lunarDates[0], newVal);
                    }
                  }
                  monthCountDays = -monthCountDays;
                } else { // move to next month
                  if (leapMonth == 0) {
                    monthCountDays = LunarUtil.daysOfALunarMonth(lunarDates[0], oldVal + 1);
                  } else { // leap year
                    if (oldVal < leapMonth) {
                      monthCountDays = LunarUtil.daysOfALunarMonth(lunarDates[0], oldVal + 1);
                    } else if (oldVal == leapMonth) {
                      monthCountDays = LunarUtil.daysOfLeapMonthInLunarYear(lunarDates[0]);
                    } else {
                      monthCountDays = LunarUtil.daysOfALunarMonth(lunarDates[0], oldVal);
                    }
                  }
                }
                mTempDate.add(Calendar.DAY_OF_MONTH, monthCountDays);
              }
            } else if (picker == mYearSpinner) {
              int orientation =
                  newVal - oldVal > 0
                      ? LunarUtil.INCREASE_A_LUANR_YEAR
                      : LunarUtil.DECREATE_A_LUANR_YEAR;
              mTempDate =
                  LunarUtil.decreaseOrIncreaseALunarYear(
                      mTempDate, lunarDates[1], lunarDates[2], orientation);
            } else {
              throw new IllegalArgumentException();
            }
            // now set the date to the adjusted one
            setDate(
                mTempDate.get(Calendar.YEAR),
                mTempDate.get(Calendar.MONTH),
                mTempDate.get(Calendar.DAY_OF_MONTH));
            updateSpinners();
            updateCalendarView();
            notifyDateChanged();
          }
        };

    mSpinners = (LinearLayout) findViewById(R.id.pickers);

    // calendar view day-picker
    mCalendarView = (CalendarView) findViewById(R.id.calendar_view);
    mCalendarView.setOnDateChangeListener(
        new CalendarView.OnDateChangeListener() {
          public void onSelectedDayChange(CalendarView view, int year, int month, int monthDay) {
            setDate(year, month, monthDay);
            updateSpinners();
            notifyDateChanged();
          }
        });

    // day
    mDaySpinner = (NumberPicker) findViewById(R.id.day);
    // /M: comment this line @{
    // mDaySpinner.setFormatter(NumberPicker.TWO_DIGIT_FORMATTER);
    // /}
    mDaySpinner.setOnLongPressUpdateInterval(100);
    mDaySpinner.setOnValueChangedListener(onChangeListener);
    // mDaySpinner has 3 child,topButton,editText,bottomButtom
    if (mDaySpinner.getChildCount() == PICKER_CHILD_COUNT) {
      // set the Middle EditText of Numberpicker read only.
      mDaySpinnerInput = (EditText) mDaySpinner.getChildAt(1);
      mDaySpinnerInput.setClickable(false);
      mDaySpinnerInput.setFocusable(false);
    } else {
      // Normally,this will always not happen.
      mDaySpinnerInput = new EditText(context);
      Log.e(TAG, "mDaySpinner.getChildCount() != 3,It isn't init ok.");
    }

    // month
    mMonthSpinner = (NumberPicker) findViewById(R.id.month);
    mMonthSpinner.setMinValue(0);
    mMonthSpinner.setMaxValue(mNumberOfMonths - 1);
    mMonthSpinner.setDisplayedValues(mShortMonths);
    mMonthSpinner.setOnLongPressUpdateInterval(200);
    mMonthSpinner.setOnValueChangedListener(onChangeListener);
    // mDaySpinner has 3 child,topButton,editText,bottomButtom
    if (mMonthSpinner.getChildCount() == PICKER_CHILD_COUNT) {
      // set the Middle EditText of Numberpicker read only.
      mMonthSpinnerInput = (EditText) mMonthSpinner.getChildAt(1);
      mMonthSpinnerInput.setClickable(false);
      mMonthSpinnerInput.setFocusable(false);
    } else {
      // Normally,this will always not happen.
      mMonthSpinnerInput = new EditText(context);
      Log.e(TAG, "mMonthSpinner.getChildCount() != 3,It isn't init ok.");
    }
    // year
    mYearSpinner = (NumberPicker) findViewById(R.id.year);
    mYearSpinner.setOnLongPressUpdateInterval(100);
    mYearSpinner.setOnValueChangedListener(onChangeListener);
    // mDaySpinner has 3 child,topButton,editText,bottomButtom
    if (mYearSpinner.getChildCount() == PICKER_CHILD_COUNT) {
      // set the Middle EditText of Numberpicker read only.
      mYearSpinnerInput = (EditText) mYearSpinner.getChildAt(1);
      mYearSpinnerInput.setClickable(false);
      mYearSpinnerInput.setFocusable(false);
    } else {
      // Normally,this will always not happen.
      mYearSpinnerInput = new EditText(context);
      Log.e(TAG, "mYearSpinner.getChildCount() != 3,It isn't init ok.");
    }

    // show only what the user required but make sure we
    // show something and the spinners have higher priority
    if (!spinnersShown && !calendarViewShown) {
      setSpinnersShown(true);
    } else {
      setSpinnersShown(spinnersShown);
      setCalendarViewShown(calendarViewShown);
    }

    // set the min date giving priority of the minDate over startYear
    mTempDate.clear();
    mTempDate.set(startYear, 0, 1);
    setMinDate(mTempDate.getTimeInMillis());

    // set the max date giving priority of the maxDate over endYear
    mTempDate.clear();
    mTempDate.set(endYear, 11, 31);
    setMaxDate(mTempDate.getTimeInMillis());

    // initialize to current date
    mCurrentDate.setTimeInMillis(System.currentTimeMillis());
    init(
        mCurrentDate.get(Calendar.YEAR),
        mCurrentDate.get(Calendar.MONTH),
        mCurrentDate.get(Calendar.DAY_OF_MONTH),
        null);

    // re-order the number spinners to match the current date format
    reorderSpinners();

    // set content descriptions
    AccessibilityManager accessibilityManager =
        (AccessibilityManager) context.getSystemService(context.ACCESSIBILITY_SERVICE);
    if (accessibilityManager.isEnabled()) {
      setContentDescriptions();
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_suspension_picker);
    SharedPreferences sp = getSharedPreferences(Utilities.SP_LOGIN, Context.MODE_PRIVATE);
    if (!sp.contains(Utilities.SP_KEY_SUSPENSION_TS)) {
      sp.edit()
          .putLong(Utilities.SP_KEY_SUSPENSION_TS, Calendar.getInstance().getTimeInMillis())
          .commit();
    }

    NumberPicker np = (NumberPicker) findViewById(R.id.suspension_picker);
    Button setPicker = (Button) findViewById(R.id.btnSuspension);
    Button backButton = (Button) findViewById(R.id.btnReturn);

    np.setMinValue(0);
    np.setMaxValue(Utilities.SUSPENSION_DISPLAY.length - 1);
    np.setDisplayedValues(Utilities.SUSPENSION_DISPLAY);

    np.setOnValueChangedListener(
        new OnValueChangeListener() {

          @Override
          public void onValueChange(NumberPicker picker, int oldValue, int newValue) {
            // TODO Auto-generated method stub
            Utilities.Log(
                TAG, "selection is " + seq + " and item is " + Utilities.SUSPENSION_DISPLAY[seq]);

            seq = newValue;
          }
        });

    setPicker.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub

            //				section_6.setText("Break Suspension");
            Utilities.getSP(SuspensionTimePicker.this, Utilities.SP_SURVEY)
                .edit()
                .putBoolean(Utilities.SP_KEY_SURVEY_SUSPENSION, true)
                .commit();

            // set suspension alarm
            AlarmManager am =
                (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);

            Intent breakIntent = new Intent(Utilities.BD_ACTION_SUSPENSION);
            breakIntent.putExtra(Utilities.SV_NAME, Utilities.SV_NAME_RANDOM); // useless
            PendingIntent breakPi =
                PendingIntent.getBroadcast(
                    getApplicationContext(), 0, breakIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
            //				getApplicationContext().sendBroadcast(breakIntent);

            am.setExact(
                AlarmManager.RTC_WAKEUP,
                Calendar.getInstance().getTimeInMillis() + (seq + 1) * interval * 1000,
                breakPi);

            // close volume
            AudioManager audiom =
                (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
            audiom.setStreamVolume(AudioManager.STREAM_MUSIC, 3, AudioManager.FLAG_PLAY_SOUND);

            // set result and finish
            setResult(1); // set text to break suspension
            finish();
          }
        });

    backButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
          }
        });
  }
  @SuppressLint("NewApi")
  @Override
  protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
    // super.onPrepareDialogBuilder(builder);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      dialog = ((Activity) ctx).getLayoutInflater().inflate(R.layout.num_picker_pref_v10, null);
      final Button plus = (Button) dialog.findViewById(R.id.dialog_num_pick_plus);
      final Button minus = (Button) dialog.findViewById(R.id.dialog_num_pick_minus);
      tx = (TextView) dialog.findViewById(R.id.dialog_num_pick_val);
      updateV10Value();
      plus.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              if (VALUE < MAX_VAL) {
                ++VALUE;
                updateV10Value();
                updateSummary();
              }
            }
          });
      minus.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              if (VALUE > MIN_VAL) {
                --VALUE;
                updateV10Value();
                updateSummary();
              }
            }
          });
    } else {
      dialog = ((Activity) ctx).getLayoutInflater().inflate(R.layout.num_picker_pref, null);
      picker = (NumberPicker) dialog.findViewById(R.id.numberPicker);
      picker.setMaxValue(MAX_VAL);
      picker.setMinValue(MIN_VAL);
      picker.setValue(VALUE);
      picker.setWrapSelectorWheel(false);
      picker.setOnValueChangedListener(
          new OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
              VALUE = newVal;
              updateSummary();
            }
          });
    }
    updateSummary();
    builder.setPositiveButton(
        android.R.string.ok,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            callChangeListener(VALUE);
          }
        });
    builder.setNegativeButton(
        android.R.string.cancel,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            // Nothing
          }
        });
    builder.setView(dialog);
  }