Java Code Examples for android.widget.NumberPicker#setDisplayedValues()

The following examples show how to use android.widget.NumberPicker#setDisplayedValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnoozeActivity.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 2
Source File: SnoozeActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 3
Source File: SnoozeActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 4
Source File: NumericDayPopup.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public void doContentSection() {
    int maxDaysToShow = 7;

    String[] days = new String[maxDaysToShow];

    //1-7 day(s) picker
    for (int dayNumber = 1; dayNumber < maxDaysToShow+1 ; dayNumber++) {
        int arrayNumber = dayNumber-1;
        if(dayNumber>1) days[arrayNumber] = (dayNumber)+" Days";
        else days[arrayNumber] = (dayNumber)+" Day";
    }
    picker = (NumberPicker) contentView.findViewById(R.id.floating_day_number_picker);
    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    picker.setMinValue(0);
    picker.setMaxValue(maxDaysToShow - 1);
    picker.setDisplayedValues(days);
}
 
Example 5
Source File: FormatPickerDialog.java    From Android-Webcam with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    setCancelable(false);

    numberPicker = (NumberPicker) getDialog().findViewById(R.id.number_picker);
    numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    numberPicker.setDisplayedValues(values);
    numberPicker.setMinValue(getMinimumValue());
    numberPicker.setMaxValue(getMaximumValue());
    numberPicker.setValue(getInitialValue());
    numberPicker.setWrapSelectorWheel(false);
    numberPicker.setOnValueChangedListener(new OnValueChangeListener() {
        @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            currentIndex = newVal;
        }
    });
}
 
Example 6
Source File: TimezonePickerPopup.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override public void doContentSection() {
    timezones = getTimezones();
    picker = (NumberPicker) contentView.findViewById(R.id.floating_day_number_picker);
    picker.setVisibility(View.GONE);
    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    picker.setMinValue(0);

    String[] displayedValues = new String[timezones.size()];
    for (int i = 0; i < timezones.size(); i++) {
        displayedValues[i] = timezones.get(i).getName();
    }

    picker.setMaxValue(displayedValues.length - 1);
    picker.setDisplayedValues(displayedValues);
    picker.setValue(getIndexOfCurrentZoneOrDefault(0));
    picker.setVisibility(View.VISIBLE);

    Bundle args = getArguments();
    if (args == null) {
        forceNotification = false;
    } else {
        forceNotification = args.getBoolean(FORCE_NOTIFICATION, false);
    }
}
 
Example 7
Source File: WeeklyIntervalPopup.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public void doContentSection() {
    Calendar current = Calendar.getInstance();
    int maxDaysToShow = 7;

    String[] days = new String[maxDaysToShow];

    for (int i = 0; i < maxDaysToShow; i++) {
        if (i > 1) {
            days[i] = headerDateFormat.format(current.getTime());
        }
        else {
            days[i] = i == 0 ? getString(R.string.today) : getString(R.string.tomorrow);
        }
        current.add(Calendar.DAY_OF_MONTH, 1);
    }

    picker = (NumberPicker) contentView.findViewById(R.id.floating_day_number_picker);
    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    picker.setMinValue(0);
    picker.setMaxValue(maxDaysToShow - 1);
    picker.setDisplayedValues(days);
}
 
Example 8
Source File: SnoozeActivity.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 9
Source File: Dialogs.java    From Aegis with GNU General Public License v3.0 6 votes vote down vote up
public static void showBackupVersionsPickerDialog(Activity activity, NumberInputListener listener) {
    final int max = 30;
    String[] numbers = new String[max / 5];
    for (int i = 0; i < numbers.length; i++) {
        numbers[i] = Integer.toString(i * 5 + 5);
    }

    View view = activity.getLayoutInflater().inflate(R.layout.dialog_number_picker, null);
    NumberPicker numberPicker = view.findViewById(R.id.numberPicker);
    numberPicker.setDisplayedValues(numbers);
    numberPicker.setMaxValue(numbers.length - 1);
    numberPicker.setMinValue(0);
    numberPicker.setValue(new Preferences(activity.getApplicationContext()).getBackupsVersionCount() / 5 - 1);
    numberPicker.setWrapSelectorWheel(false);

    AlertDialog dialog = new AlertDialog.Builder(activity)
            .setTitle(R.string.set_number)
            .setView(view)
            .setPositiveButton(android.R.string.ok, (dialog1, which) ->
                    listener.onNumberInputResult(numberPicker.getValue()))
            .create();

    showSecureDialog(dialog);
}
 
Example 10
Source File: SnoozeActivity.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
static void SetSnoozePickerValues(NumberPicker picker, boolean above, int default_snooze) {
    String[] values=new String[snoozeValues.length];
    for(int i=0;i<values.length;i++){
        values[i]=getNameFromTime(snoozeValues[i]);
    }

    picker.setMaxValue(values.length -1);
    picker.setMinValue(0);
    picker.setDisplayedValues(values);
    picker.setWrapSelectorWheel(false);
    if(default_snooze != 0) {
        picker.setValue(getSnoozeLocatoin(default_snooze));
    } else {
        picker.setValue(getSnoozeLocatoin(getDefaultSnooze(above)));
    }
}
 
Example 11
Source File: DurationPicker.java    From SightRemote with GNU General Public License v3.0 5 votes vote down vote up
public DurationPicker(NumberPicker digit1, NumberPicker digit2) {
    this.digit1 = digit1;
    this.digit2 = digit2;

    digit1.setMinValue(0);
    digit1.setMaxValue(24);
    digit2.setMinValue(0);
    digit2.setMaxValue(3);
    digit2.setDisplayedValues(new String[] {"0", "15", "30", "45"});

    digit1.setOnValueChangedListener(this);
    digit2.setOnValueChangedListener(this);
}
 
Example 12
Source File: PreferenceNagTimePicker.java    From recurrence with GNU General Public License v3.0 5 votes vote down vote up
protected void setUpMinutePicker(View view) {
    minutePicker = (NumberPicker) view.findViewById(R.id.picker1);
    minutePicker.setMaxValue(MAX_VALUE);
    minutePicker.setMinValue(MIN_VALUE);
    minutePicker.setValue(sharedPreferences.getInt("nagMinutes", getContext().getResources().getInteger(R.integer.default_nag_minutes)));

    String[] minuteValues = new String[61];
    for (int i = 0; i < minuteValues.length; i++) {
        minuteValues[i] = String.format(getContext().getResources().getQuantityString(R.plurals.time_minute, i), i);
    }
    minutePicker.setDisplayedValues(minuteValues);
}
 
Example 13
Source File: PreferenceNagTimePicker.java    From recurrence with GNU General Public License v3.0 5 votes vote down vote up
protected void setUpSecondPicker(View view) {
    secondPicker = (NumberPicker) view.findViewById(R.id.picker2);
    secondPicker.setMaxValue(MAX_VALUE);
    secondPicker.setMinValue(MIN_VALUE);
    secondPicker.setValue(sharedPreferences.getInt("nagSeconds", getContext().getResources().getInteger(R.integer.default_nag_seconds)));

    String[] secondValues = new String[61];
    for (int i = 0; i < secondValues.length; i++) {
        secondValues[i] = String.format(getContext().getResources().getQuantityString(R.plurals.time_second, i), i);
    }
    secondPicker.setDisplayedValues(secondValues);
}
 
Example 14
Source File: OddDaysPopup.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public void doContentSection() {
    Calendar current = Calendar.getInstance();
    String[] days = new String[7];
    int j=0;
    int i=0;
    do {
        if ( (current.get(Calendar.DAY_OF_MONTH) & 1) == 0 ) {
            i++;
        } else {
            if (i > 1) {
                days[j] = headerDateFormat.format(current.getTime());
            }
            else {
                days[j] = i == 0 ? getString(R.string.today) : getString(R.string.tomorrow);
            }
            j++;
            i++;
        }
        current.add(Calendar.DAY_OF_MONTH, 1);
    } while(i<14);

    picker = (NumberPicker) contentView.findViewById(R.id.floating_day_number_picker);
    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    picker.setMinValue(0);
    picker.setMaxValue(6);
    picker.setDisplayedValues(days);
}
 
Example 15
Source File: DayPickerPopup.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public void doContentSection() {
    Calendar current = Calendar.getInstance();
    int DEFAULT_MAX_DAYS_TO_SHOW = 14;
    int maxDaysToShow = getNonNullArguments().getInt(MAX_DAYS, DEFAULT_MAX_DAYS_TO_SHOW);
    int dayAddOrSubtract = getNonNullArguments().getBoolean(DAYS_GOING_BACKWARDS, true) ? -1 : 1;
    String yesterdayTomorrowText = getString(getNonNullArguments().getBoolean(DAYS_GOING_BACKWARDS, true) ? R.string.yesterday : R.string.tomorrow);

    String[] days = new String[maxDaysToShow];

    for (int i = 0; i < maxDaysToShow; i++) {
        if (i > 1) {
            days[i] = headerDateFormat.format(current.getTime());
        }
        else {
            days[i] = i == 0 ? getString(R.string.today) : yesterdayTomorrowText;
        }
        current.add(Calendar.DAY_OF_MONTH, dayAddOrSubtract);
    }

    picker = (NumberPicker) contentView.findViewById(R.id.floating_day_number_picker);
    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    picker.setMinValue(0);
    picker.setMaxValue(maxDaysToShow - 1);
    picker.setDisplayedValues(days);

    View divider = contentView.findViewById(R.id.picker_title_divider);
    if (divider != null) {
        divider.setVisibility(View.VISIBLE);
    }
}
 
Example 16
Source File: EvenDaysPopup.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public void doContentSection() {
    Calendar current = Calendar.getInstance();
    String[] days = new String[7];
    int j=0;
    int i=0;
    do {
        if ( (current.get(Calendar.DAY_OF_MONTH) & 1) == 0 ) {
            if (i > 1) {
                days[j] = headerDateFormat.format(current.getTime());
            }
            else {
                days[j] = i == 0 ? getString(R.string.today) : getString(R.string.tomorrow);
            }
            j++;
            i++;
        } else {
            i++;
        }
        current.add(Calendar.DAY_OF_MONTH, 1);
    } while(i<14);

    picker = (NumberPicker) contentView.findViewById(R.id.floating_day_number_picker);
    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    picker.setMinValue(0);
    picker.setMaxValue(6);
    picker.setDisplayedValues(days);
}
 
Example 17
Source File: IrrigationZoneDurationFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public void doContentSection() {
    String deviceAddress = getArguments().getString(MODEL_ADDR, "");

    ModelSource<DeviceModel> m = DeviceModelProvider.instance().getModel(deviceAddress);
    m.addModelListener(Listeners.runOnUiThread(new Listener<ModelEvent>() {
        public void onEvent(ModelEvent e) {
            if (e instanceof ModelAddedEvent) {
                // model is loaded
            }
        }
    }));
    m.load();

    if (m.get() != null) {
        deviceModel = m.get();
    }

    capabilityUtils = new CapabilityUtils(deviceModel);

    getZoneNames();

    stationPicker = (NumberPicker) contentView.findViewById(R.id.station_picker);
    stationPicker.setMinValue(1);
    stationPicker.setValue(1);
    stationPicker.setMaxValue(zoneNameArr.length);
    for(int i = 0; i < zoneNameArr.length; i++){
        zoneNameArrTrunk[i]=StringUtils.abbreviate(zoneNameArr[i],20);
    }
    stationPicker.setDisplayedValues(zoneNameArrTrunk);

    updateTimeSelector();

    zoneSelection = (Version1TextView) contentView.findViewById(R.id.zone_selected);
    durationSelection = (Version1TextView) contentView.findViewById(R.id.duration_selected);
}
 
Example 18
Source File: PersianDatePicker.java    From PersianDatePicker with Apache License 2.0 4 votes vote down vote up
public PersianDatePicker(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);

      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

      View view = inflater.inflate(R.layout.sl_persian_date_picker, this);
      yearNumberPicker = (NumberPicker) view.findViewById(R.id.yearNumberPicker);
      monthNumberPicker = (NumberPicker) view.findViewById(R.id.monthNumberPicker);
      dayNumberPicker = (NumberPicker) view.findViewById(R.id.dayNumberPicker);
      descriptionTextView = (TextView) view.findViewById(R.id.descriptionTextView);

      TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersianDatePicker, 0, 0);

      /*
       * Set timezone
       */
      PersianCalendar pCalendar;
      timezone = a.getString(R.styleable.PersianDatePicker_timezone);
      if( timezone == null || timezone.isEmpty()) {
          pCalendar = new PersianCalendar();
      } else {
          pCalendar = new PersianCalendar(TimeZone.getTimeZone(timezone));
      }

      yearRange = a.getInteger(R.styleable.PersianDatePicker_yearRange, 10);

/*
       * Initializing yearNumberPicker min and max values If minYear and
 * maxYear attributes are not set, use (current year - 10) as min and
 * (current year + 10) as max.
 */
      minYear = a.getInt(R.styleable.PersianDatePicker_minYear, pCalendar.getPersianYear() - yearRange);
      maxYear = a.getInt(R.styleable.PersianDatePicker_maxYear, pCalendar.getPersianYear() + yearRange);
      yearNumberPicker.setMinValue(minYear);
      yearNumberPicker.setMaxValue(maxYear);

      int selectedYear = a.getInt(R.styleable.PersianDatePicker_selectedYear, pCalendar.getPersianYear());
      if (selectedYear > maxYear || selectedYear < minYear) {
          throw new IllegalArgumentException(String.format("Selected year (%d) must be between minYear(%d) and maxYear(%d)", selectedYear, minYear, maxYear));
      }
      yearNumberPicker.setValue(selectedYear);
      yearNumberPicker.setOnValueChangedListener(dateChangeListener);

/*
       * initializng monthNumberPicker
 */
      boolean displayMonthNames = a.getBoolean(R.styleable.PersianDatePicker_displayMonthNames, false);
      monthNumberPicker.setMinValue(1);
      monthNumberPicker.setMaxValue(12);
      if (displayMonthNames) {
          monthNumberPicker.setDisplayedValues(PersianCalendarConstants.persianMonthNames);
      }
      int selectedMonth = a.getInteger(R.styleable.PersianDatePicker_selectedMonth, pCalendar.getPersianMonth());
      if (selectedMonth < 1 || selectedMonth > 12) {
          throw new IllegalArgumentException(String.format("Selected month (%d) must be between 1 and 12", selectedMonth));
      }
      monthNumberPicker.setValue(selectedMonth);
      monthNumberPicker.setOnValueChangedListener(dateChangeListener);



/*
       * initializiing dayNumberPicker
 */
      dayNumberPicker.setMinValue(1);
      dayNumberPicker.setMaxValue(31);
      int selectedDay = a.getInteger(R.styleable.PersianDatePicker_selectedDay, pCalendar.getPersianDay());
      if (selectedDay > 31 || selectedDay < 1) {
          throw new IllegalArgumentException(String.format("Selected day (%d) must be between 1 and 31", selectedDay));
      }
      if (selectedMonth > 6 && selectedMonth < 12 && selectedDay == 31) {
          selectedDay = 30;
      } else {
          boolean isLeapYear = PersianCalendarUtils.isPersianLeapYear(selectedYear);
          if (isLeapYear && selectedDay == 31) {
              selectedDay = 30;
          } else if (selectedDay > 29) {
              selectedDay = 29;
          }
      }
      dayNumberPicker.setValue(selectedDay);
      dayNumberPicker.setOnValueChangedListener(dateChangeListener);

/*
 * displayDescription
 */
      displayDescription = a.getBoolean(R.styleable.PersianDatePicker_displayDescription, false);
      if (displayDescription) {
          descriptionTextView.setVisibility(View.VISIBLE);
          descriptionTextView.setText(getDisplayPersianDate().getPersianLongDate());
      }

      a.recycle();
  }
 
Example 19
Source File: IrrigationZoneDurationFragment.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
private void updateTimeSelector() {
    String deviceAddress = getArguments().getString(MODEL_ADDR, "");

    ModelSource<DeviceModel> m = DeviceModelProvider.instance().getModel(deviceAddress);
    m.addModelListener(Listeners.runOnUiThread(new Listener<ModelEvent>() {
        public void onEvent(ModelEvent e) {
            if (e instanceof ModelAddedEvent) {
                // model is loaded
            }
        }
    }));
    m.load();

    if (m.get() != null) {
        deviceModel = m.get();
    }

    Bundle args = getArguments();
    if (args == null) {
        return; // Nothing to show...
    }

    try {
        bundleStrings = (ArrayList<StringPair>) args.getSerializable(SELECTIONS);
        if (bundleStrings == null) {
            return; // Again, nothing to show.
        }
    }
    catch (Exception ex) {
        logger.error("Could not deserialize SELECTIONS", ex);
        return;
    }

    String selectedValue = args.getString(SELECTED);
    int selectedIndex = -1;
    int bundleSize = bundleStrings.size();
    String[] pickerValues = new String[bundleSize];
    for (int i = 0; i < bundleSize; i++) {
        pickerValues[i] = bundleStrings.get(i).getValue();
        if (bundleStrings.get(i).getKey().equals(selectedValue)) {
            selectedIndex = i;
        }
    }

    String abstractText = args.getString(ABSTRACT);
    if (!TextUtils.isEmpty(abstractText)) {
        TextView view = (TextView) contentView.findViewById(R.id.day_number_picker_abstract);
        if (view != null) {
            view.setText(abstractText);
            view.setVisibility(View.VISIBLE);
        }
    }

    boolean showDivider = args.getBoolean(DIVIDER, false);
    View divider = contentView.findViewById(R.id.picker_title_divider);
    if (showDivider) {
        if (divider != null) {
            divider.setVisibility(View.VISIBLE);
        }
    }
    else {
        if (divider != null) {
            divider.setVisibility(View.GONE);
        }
    }

    picker = (NumberPicker) contentView.findViewById(R.id.floating_day_number_picker);
    picker.setMinValue(0);
    picker.setMaxValue(bundleSize - 1);
    picker.setDisplayedValues(pickerValues);
    picker.setValue(selectedIndex != -1 ? selectedIndex : 0);
}
 
Example 20
Source File: HoursMinutePickerFragment.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
@Override
public void doContentSection() {
    String deviceAddress = getArguments().getString(MODEL_ADDR, "");

    ModelSource<DeviceModel> m = DeviceModelProvider.instance().getModel(deviceAddress);
    m.addModelListener(Listeners.runOnUiThread(new Listener<ModelEvent>() {
        public void onEvent(ModelEvent e) {
            if (e instanceof ModelAddedEvent) {
                // model is loaded
            }
        }
    }));
    m.load();

    if (m.get() != null) {
        deviceModel = m.get();
    }

    Bundle args = getArguments();
    if (args == null) {
        return; // Nothing to show...
    }

    try {
        bundleStrings = (ArrayList<StringPair>) args.getSerializable(SELECTIONS);
        if (bundleStrings == null) {
            return; // Again, nothing to show.
        }
    }
    catch (Exception ex) {
        logger.error("Could not deserialize SELECTIONS", ex);
        return;
    }

    String selectedValue = args.getString(SELECTED);
    int selectedIndex = -1;
    int bundleSize = bundleStrings.size();
    String[] pickerValues = new String[bundleSize];
    for (int i = 0; i < bundleSize; i++) {
        pickerValues[i] = bundleStrings.get(i).getValue();
        if (bundleStrings.get(i).getKey().equals(selectedValue)) {
            selectedIndex = i;
        }
    }

    String abstractText = args.getString(ABSTRACT);
    if (!TextUtils.isEmpty(abstractText)) {
        TextView view = (TextView) contentView.findViewById(R.id.day_number_picker_abstract);
        if (view != null) {
            view.setText(abstractText);
            view.setVisibility(View.VISIBLE);
        }
    }

    picker = (NumberPicker) contentView.findViewById(R.id.floating_day_number_picker);
    picker.setMinValue(0);
    picker.setMaxValue(bundleSize - 1);
    picker.setDisplayedValues(pickerValues);
    picker.setValue(selectedIndex != -1 ? selectedIndex : 0);
}