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

The following examples show how to use android.widget.NumberPicker#setOnValueChangedListener() . 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: AlarmOffsetDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
protected void initViews( final Context context, View dialogContent )
{
    pickerDirection = (NumberPicker) dialogContent.findViewById(R.id.alarmOption_offset_direction);
    pickerDirection.setMinValue(0);
    pickerDirection.setMaxValue(1);
    pickerDirection.setDisplayedValues( new String[] {context.getString(R.string.offset_button_before), context.getString(R.string.offset_button_after)} );
    pickerDirection.setOnValueChangedListener(onOffsetChanged);

    pickerOffsetMinutes = (NumberPicker) dialogContent.findViewById(R.id.alarmOption_offset_minute);
    pickerOffsetMinutes.setMinValue(0);
    pickerOffsetMinutes.setMaxValue(minuteStrings.length-1);
    pickerOffsetMinutes.setDisplayedValues(minuteStrings);
    pickerOffsetMinutes.setOnValueChangedListener(onOffsetChanged);

    pickerOffsetHours = (NumberPicker) dialogContent.findViewById(R.id.alarmOption_offset_hour);
    pickerOffsetHours.setMinValue(0);
    pickerOffsetHours.setMaxValue(hourStrings.length-1);
    pickerOffsetHours.setDisplayedValues(hourStrings);
    pickerOffsetHours.setOnValueChangedListener(onOffsetChanged);

    pickerOffsetDays = (NumberPicker) dialogContent.findViewById(R.id.alarmOption_offset_day);
    pickerOffsetDays.setMinValue(0);
    pickerOffsetDays.setMaxValue(dayStrings.length-1);
    pickerOffsetDays.setDisplayedValues(dayStrings);
    pickerOffsetDays.setOnValueChangedListener(onOffsetChanged);
}
 
Example 2
Source File: MainActivity.java    From CompoundViews with Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example 3
Source File: AgeElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected View createView(Context c) {
    LayoutInflater inflater = ((Activity) c).getLayoutInflater();
    LinearLayout v = (LinearLayout) inflater.inflate(R.layout.widget_element_age, null);
    mWidget = (NumberPicker) v.findViewById(R.id.answer);
    mWidget.setMaxValue(120);
    mWidget.setMinValue(0);
    mWidget.setValue((int) age);
    mWidget.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            setAge(newVal);
        }
    });
    /*
    et = new EditText(c);
    et.setText(String.valueOf(age));
    et.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    et.setKeyListener(new DigitsKeyListener());
    */
    //return encapsulateQuestion(c, et);
    return encapsulateQuestion(c, v);
}
 
Example 4
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 5
Source File: BolusAmountPicker.java    From SightRemote with GNU General Public License v3.0 5 votes vote down vote up
public BolusAmountPicker(NumberPicker digit1, NumberPicker digit2, NumberPicker digit3, NumberPicker digit4) {
    this.digit1 = digit1;
    this.digit2 = digit2;
    this.digit3 = digit3;
    this.digit4 = digit4;
    digit1.setOnValueChangedListener(this);
    digit2.setOnValueChangedListener(this);
    digit3.setOnValueChangedListener(this);
    digit4.setOnValueChangedListener(this);
}
 
Example 6
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 7
Source File: TimeSleepActivity.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
void init() {
    custom = true;
    View v = findViewById(R.id.time_sleep_pickers);
    v.setVisibility(View.VISIBLE);

    tHour = (TextView) findViewById(R.id.time_sleep_custom_num_left_t);
    tMinute = (TextView) findViewById(R.id.time_sleep_custom_num_right_t);
    minute = (NumberPicker) findViewById(R.id.time_sleep_custom_num_right);
    hour = (NumberPicker) findViewById(R.id.time_sleep_custom_num_left);
    minute.setOnValueChangedListener(this);
    hour.setOnValueChangedListener(this);

    initTheme();
    initPickersData();
}
 
Example 8
Source File: NumberPickerPreferenceFragment.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
protected View onCreateDialogView(final Context context) {
	if (DEBUG) Log.v(TAG, "onCreateDialogView:");
	final NumberPicker picker = new NumberPicker(context);
	picker.setOnValueChangedListener(mOnValueChangeListener);
	picker.setMinValue(mMinValue);
	picker.setMaxValue(mMaxValue);
	picker.setValue(mValue);
	changed = false;
	return picker;
}
 
Example 9
Source File: NumberPickerPreferenceFragmentCompat.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
protected View onCreateDialogView(final Context context) {
	if (DEBUG) Log.v(TAG, "onCreateDialogView:");
	final NumberPicker picker = new NumberPicker(context);
	picker.setOnValueChangedListener(mOnValueChangeListener);
	picker.setMinValue(mMinValue);
	picker.setMaxValue(mMaxValue);
	picker.setValue(mValue);
	changed = false;
	return picker;
}
 
Example 10
Source File: MainActivity.java    From ScrollingPagerIndicator with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    int screenWidth = getScreenWidth();

    // Setup ViewPager with indicator
    ViewPager pager = findViewById(R.id.pager);
    DemoPagerAdapter pagerAdapter = new DemoPagerAdapter(8);
    pager.setAdapter(pagerAdapter);

    ScrollingPagerIndicator pagerIndicator = findViewById(R.id.pager_indicator);
    pagerIndicator.attachToPager(pager);

    // Setup ViewPager2 with indicator
    ViewPager2 pager2 = findViewById(R.id.pager2);
    DemoRecyclerViewAdapter pagerAdapter2 = new DemoRecyclerViewAdapter(8, ViewGroup.LayoutParams.MATCH_PARENT);
    pager2.setAdapter(pagerAdapter2);

    ScrollingPagerIndicator pagerIndicator2 = findViewById(R.id.pager_indicator2);
    pagerIndicator2.attachToPager(pager2);

    // Setup RecyclerView with indicator
    // One page will occupy 1/3 of screen width
    RecyclerView recyclerView = findViewById(R.id.recycler);
    recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    DemoRecyclerViewAdapter recyclerAdapter = new DemoRecyclerViewAdapter(8, screenWidth / 3);
    recyclerView.setAdapter(recyclerAdapter);

    recyclerView.setPadding(screenWidth / 3, 0, screenWidth / 3, 0);

    ScrollingPagerIndicator recyclerIndicator = findViewById(R.id.recycler_indicator);
    // Consider page in the middle current
    recyclerIndicator.attachToRecyclerView(recyclerView);

    SnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(recyclerView);

    // Some controls
    NumberPicker pageCountPicker = findViewById(R.id.page_number_picker);
    pageCountPicker.setMaxValue(99);
    pageCountPicker.setMinValue(0);
    pageCountPicker.setValue(pagerAdapter.getCount());

    NumberPicker visibleDotCountPicker = findViewById(R.id.visible_dot_number_picker);
    visibleDotCountPicker.setMinValue(3);
    visibleDotCountPicker.setMaxValue(11);
    visibleDotCountPicker.setValue(pagerIndicator.getVisibleDotCount());

    visibleDotCountPicker.setOnValueChangedListener((picker, oldVal, newVal) -> {
        if (newVal % 2 == 0) {
            Toast.makeText(this, "Visible dot count must be odd number", Toast.LENGTH_SHORT).show();
            return;
        }
        pagerIndicator.setVisibleDotCount(newVal);
        recyclerIndicator.setVisibleDotCount(newVal);
    });

    pageCountPicker.setOnValueChangedListener((picker, oldVal, newVal) -> {
        if (pager.getCurrentItem() >= newVal - 1) {
            pager.setCurrentItem(newVal - 1, false);
        }
        pagerAdapter.setCount(newVal);
        recyclerAdapter.setCount(newVal);
    });
}
 
Example 11
Source File: DynamicGridSizeFragment.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
private void showNumberPicker() {
    mDialog = new Dialog(getActivity());
    mDialog.setTitle(getResources().getString(
            R.string.preferences_interface_homescreen_custom));
    mDialog.setContentView(R.layout.custom_grid_size_dialog);

    NumberPicker nPRows = (NumberPicker) mDialog.findViewById(R.id.custom_rows);
    NumberPicker nPColumns = (NumberPicker) mDialog.findViewById(R.id.custom_columns);

    InvariantDeviceProfile grid = getInvariantDeviceProfile();
    int rows = grid.numRowsBase;
    int columns = grid.numColumnsBase;

    nPRows.setMinValue(Math.max(MIN_DYNAMIC_GRID_ROWS, rows - InvariantDeviceProfile.GRID_SIZE_MIN));
    nPRows.setMaxValue(rows + InvariantDeviceProfile.GRID_SIZE_MAX);
    nPRows.setValue(mCustomGridRows);
    nPRows.setWrapSelectorWheel(false);
    nPRows.setOnValueChangedListener(this);
    nPRows.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    nPColumns.setMinValue(Math.max(MIN_DYNAMIC_GRID_COLUMNS,
            columns - InvariantDeviceProfile.GRID_SIZE_MIN));
    nPColumns.setMaxValue(columns + InvariantDeviceProfile.GRID_SIZE_MAX);
    nPColumns.setValue(mCustomGridColumns);
    nPColumns.setWrapSelectorWheel(false);
    nPColumns.setOnValueChangedListener(this);
    nPColumns.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    Button button = (Button) mDialog.findViewById(R.id.dialog_confirm_button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mDialog != null) {
                mDialog.dismiss();
            }
        }
    });

    mDialog.setOnDismissListener(this);
    mDialog.show();
}
 
Example 12
Source File: PersianDatePicker.java    From Smartlab with Apache License 2.0 4 votes vote down vote up
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();
		}
	});
}
 
Example 13
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();
  }