List of usage examples for android.widget NumberPicker setDisplayedValues
public void setDisplayedValues(String[] displayedValues)
From source file:org.odk.collect.android.fragments.dialogs.NumberPickerDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.number_picker_dialog, null); final NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.number_picker); numberPicker.setMaxValue(((String[]) getArguments().getSerializable(DISPLAYED_VALUES)).length - 1); numberPicker.setMinValue(0);//from ww w.ja va 2s.c o m numberPicker.setWrapSelectorWheel(false); numberPicker.setDisplayedValues((String[]) getArguments().getSerializable(DISPLAYED_VALUES)); numberPicker.setValue(((String[]) getArguments().getSerializable(DISPLAYED_VALUES)).length - 1 - getArguments().getInt(PROGRESS)); return new AlertDialog.Builder(getActivity()).setTitle("Number Picker").setView(view) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { listener.onNumberPickerValueSelected(getArguments().getInt(WIDGET_ID), numberPicker.getValue()); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).create(); }
From source file:com.crcrch.chromatictuner.app.NotePickerFragment.java
@NonNull @Override/* w ww. ja v a 2 s . co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext()); View dialogContent = LayoutInflater.from(dialogBuilder.getContext()).inflate(R.layout.fragment_note_picker, null); final NumberPicker notePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_note); notePicker.setMinValue(0); notePicker.setMaxValue(MiscMusic.CHROMATIC_SCALE.length - 1); notePicker.setDisplayedValues(MiscMusic.CHROMATIC_SCALE); notePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final NumberPicker octavePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_octave); octavePicker.setMinValue(0); octavePicker.setMaxValue(MAX_OCTAVE); octavePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); octavePicker.setWrapSelectorWheel(false); final TextView frequencyView = (TextView) dialogContent.findViewById(R.id.frequency); notePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { frequencyView.setText(selectFrequency(newVal, octavePicker.getValue())); } }); octavePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { frequencyView.setText(selectFrequency(notePicker.getValue(), newVal)); } }); double frequencyToDisplay; if (savedInstanceState == null) { frequencyToDisplay = initialFrequency; } else { frequencyToDisplay = savedInstanceState.getDouble(STATE_FREQUENCY); } frequencyView.setText(selectFrequency(frequencyToDisplay)); int note = getNoteForFrequency(frequencyToDisplay); octavePicker.setValue(getOctaveForNote(note)); octavePicker.invalidate(); notePicker.setValue(getNoteIndexForNote(note)); notePicker.invalidate(); return dialogBuilder.setTitle(R.string.dialog_title_note_picker).setView(dialogContent) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { listener.onFrequencySelected(frequency); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, null).create(); }
From source file:com.jaguarlandrover.hvacdemo.MainActivity.java
private void configurePicker(NumberPicker picker) { picker.setMinValue(15);//from w ww . j a v a2 s .c o m picker.setMaxValue(29); picker.setWrapSelectorWheel(false); picker.setDisplayedValues(new String[] { "LO", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "HI" }); picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); picker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { /* USER INTERFACE CALLBACK */ @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { Log.d(TAG, Util.getMethodName()); HVACManager.invokeService(getServiceIdentifiersFromViewId(picker.getId()), Integer.toString(newVal)); } }); }
From source file:com.sean.takeastand.ui.MainActivity.java
private void showPauseSettingsDialog() { LayoutInflater inflater = getLayoutInflater(); AlertDialog.Builder builder = new AlertDialog.Builder(this); View dialogView = inflater.inflate(R.layout.dialog_pause, null); TextView title = new TextView(this); title.setPadding(50, 50, 50, 50);//from w w w .j a v a 2 s. co m title.setTextSize(22); title.setTextColor(getResources().getColor(android.R.color.holo_blue_light)); title.setText(getResources().getString(R.string.select_pause_type)); builder.setCustomTitle(title); String[] valueSet = new String[pauseTimes.length]; for (int i = 0; i < pauseTimes.length; i++) { valueSet[i] = Integer.toString(pauseTimes[i]); } builder.setView(dialogView); final NumberPicker npPause = (NumberPicker) dialogView.findViewById(R.id.pauseNumberPicker); npPause.setDisplayedValues(valueSet); npPause.setMinValue(0); npPause.setMaxValue(valueSet.length - 1); npPause.setWrapSelectorWheel(false); int initialValue = Utils.getDefaultPauseAmount(this); for (int i = 0; i < pauseTimes.length; i++) { if (initialValue == pauseTimes[i]) { initialValue = i; } } npPause.setValue(initialValue); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { //getValue returns the index number, so need to do some math to correct correct //actual value setDefaultPauseAmount(pauseTimes[npPause.getValue()]); int currentStatus = Utils.getImageStatus(MainActivity.this); if (currentStatus == Constants.NON_SCHEDULE_ALARM_RUNNING || currentStatus == Constants.NON_SCHEDULE_STOOD_UP || currentStatus == Constants.NON_SCHEDULE_TIME_TO_STAND) { pauseUnscheduled(); } else { pauseSchedule(); sendAnalyticsEvent("Paused"); } dialogInterface.dismiss(); } }); builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { mPausePlay.setIcon(getResources().getDrawable(R.drawable.ic_action_pause)); } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); }
From source file:org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java
private void drawEventBufferWidgets() { LinearLayout bufferBox = (LinearLayout) rootView.findViewById(R.id.advanced_settings_buffer_box); bufferBox.setOnClickListener(new View.OnClickListener() { @Override// w w w . j av a 2 s . c o m public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(context, R.style.Dialog)); builder.setTitle("Buffer Minutes"); final NumberPicker number = new NumberPicker(context); String[] nums = new String[32]; for (int i = 0; i < nums.length; i++) { nums[i] = Integer.toString(i); } number.setMinValue(1); number.setMaxValue(nums.length - 1); number.setWrapSelectorWheel(false); number.setDisplayedValues(nums); number.setValue(prefs.getBufferMinutes() + 1); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefs.setBufferMinutes(number.getValue() - 1); drawEventBufferWidgets(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing } }); builder.setView(number); AlertDialog dialog = builder.show(); } }); // the event buffer button TextView bufferTV = (TextView) rootView.findViewById(R.id.bufferMinutesDescription); String bufferText = getResources().getString(R.string.advanced_settings_section_intervals_buffer_duration); bufferTV.setText(String.format(bufferText, prefs.getBufferMinutes())); }
From source file:edu.pdx.its.portal.routelandia.DatePickUp.java
/** * change the minute interval to quarter* * @param timePicker : timepicker obk in the view *///from ww w. ja v a2s. co m @SuppressLint("NewApi") private void setTimePickerInterval(TimePicker timePicker) { try { Class<?> classForid = Class.forName("com.android.internal.R$id"); Field field = classForid.getField("minute"); NumberPicker minutePicker = (NumberPicker) timePicker.findViewById(field.getInt(null)); minutePicker.setMinValue(0); minutePicker.setMaxValue(7); ArrayList<String> displayedValues = new ArrayList<>(); for (int i = 0; i < 60; i += TIME_PICKER_INTERVAL) { displayedValues.add(String.format("%02d", i)); } for (int i = 0; i < 60; i += TIME_PICKER_INTERVAL) { displayedValues.add(String.format("%02d", i)); } minutePicker.setDisplayedValues(displayedValues.toArray(new String[0])); } catch (Exception e) { e.printStackTrace(); } }
From source file:butter.droid.base.fragments.dialog.NumberPickerDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (getArguments() == null || !getArguments().containsKey(MAX_VALUE) || !getArguments().containsKey(MIN_VALUE) || !getArguments().containsKey(TITLE) || mOnResultListener == null) { return builder.create(); }//from w w w . j a va 2s . c o m final NumberPicker numberPicker = new NumberPicker(getActivity()); numberPicker.setLayoutParams(new NumberPicker.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); numberPicker.setWrapSelectorWheel(false); final int minValue = getArguments().getInt(MIN_VALUE); final int maxValue = getArguments().getInt(MAX_VALUE); final int currentValue = getArguments().getInt(DEFAULT_VALUE, (int) Math.floor((numberPicker.getMaxValue() - numberPicker.getMinValue()) / 2)); List<String> displayValues = new ArrayList<>(); for (int i = minValue; i < maxValue + 1; i++) { displayValues.add(Integer.toString(i)); } numberPicker.setDisplayedValues(displayValues.toArray(new String[displayValues.size()])); if (minValue < 0) { numberPicker.setMinValue(0); numberPicker.setMaxValue(maxValue + Math.abs(minValue)); numberPicker.setValue(currentValue + Math.abs(minValue)); } else { numberPicker.setMinValue(minValue); numberPicker.setMaxValue(maxValue); numberPicker.setValue(currentValue); } if (getArguments().containsKey(FOCUSABLE) && !getArguments().getBoolean(FOCUSABLE)) numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); builder.setView(numberPicker).setTitle(getArguments().getString(TITLE)) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mOnResultListener.onNewValue(numberPicker.getValue() + (minValue < 0 ? minValue : 0)); dialog.dismiss(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); return builder.create(); }
From source file:org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java
private void drawQuickSilenceWidget() { LinearLayout quicksilenceBox = (LinearLayout) rootView .findViewById(R.id.advanced_settings_quicksilence_box); quicksilenceBox.setOnClickListener(new View.OnClickListener() { @Override/*w w w . j a v a 2 s. c o m*/ public void onClick(View v) { LayoutInflater inflater = LayoutInflater.from(v.getContext()); View dialogView = inflater.inflate(R.layout.dialog_quicksilent, null); final AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(context, R.style.Dialog)); builder.setTitle(R.string.notification_quicksilence_title); builder.setView(dialogView); final NumberPicker hourP = (NumberPicker) dialogView.findViewById(R.id.hourPicker); final NumberPicker minP = (NumberPicker) dialogView.findViewById(R.id.minutePicker); String[] hours = new String[25]; String[] minutes = new String[59]; for (int i = 0; i < hours.length; i++) { hours[i] = Integer.toString(i); } int i = 0; while (i < minutes.length) { minutes[i] = Integer.toString(++i); } hourP.setMinValue(1); hourP.setMaxValue(hours.length - 1); hourP.setWrapSelectorWheel(false); hourP.setDisplayedValues(hours); hourP.setValue(prefs.getQuickSilenceHours() + 1); minP.setMinValue(1); minP.setMaxValue(minutes.length - 1); minP.setWrapSelectorWheel(false); minP.setDisplayedValues(minutes); minP.setValue(prefs.getQuicksilenceMinutes()); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { prefs.setQuickSilenceHours(hourP.getValue() - 1); prefs.setQuicksilenceMinutes(minP.getValue()); drawQuickSilenceWidget(); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //do nothing } }); AlertDialog dialog = builder.show(); } }); //the quick silence button TextView quickTV = (TextView) rootView.findViewById(R.id.quickSilenceDescription); String quicksilenceText = getResources() .getString(R.string.advanced_settings_section_interval_quicksilence_duration); String hrs = ""; if (prefs.getQuickSilenceHours() > 0) { hrs = String.valueOf(prefs.getQuickSilenceHours()) + " " + getString(R.string.hours_lower) + " "; } quickTV.setText(String.format(quicksilenceText, hrs, prefs.getQuicksilenceMinutes())); }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
public void TimeLapseDialog() { if (isRecording) return;// ww w.j a v a 2 s. co m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext()); interval = Integer.valueOf(prefs.getString("timelapseInterval", "0")); measurementVal = Integer.valueOf(prefs.getString("timelapseMeasurementVal", "0")); // show time lapse settings timeLapseDialog = new TimeLapseDialog(ApplicationScreen.instance); timeLapseDialog.setContentView(R.layout.plugin_capture_video_timelapse_dialog); final NumberPicker np = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker1); np.setMaxValue(16); np.setMinValue(0); np.setValue(interval); np.setDisplayedValues(stringInterval); np.setWrapSelectorWheel(false); np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final NumberPicker np2 = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker2); np2.setMaxValue(2); np2.setMinValue(0); np2.setValue(measurementVal); np2.setWrapSelectorWheel(false); np2.setDisplayedValues(stringMeasurement); np2.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final Switch sw = (Switch) timeLapseDialog.findViewById(R.id.timelapse_switcher); // disable/enable controls in dialog sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!sw.isChecked()) { swChecked = false; } else { swChecked = true; } } }); np2.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int scrollState) { sw.setChecked(true); } }); np.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int scrollState) { sw.setChecked(true); } }); // disable control in dialog by default if (!swChecked) { sw.setChecked(false); } else { sw.setChecked(true); } timeLapseDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (swChecked) { measurementVal = np2.getValue(); interval = np.getValue(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ApplicationScreen.getMainContext()); Editor editor = prefs.edit(); editor.putString("timelapseMeasurementVal", String.valueOf(measurementVal)); editor.putString("timelapseInterval", String.valueOf(interval)); editor.commit(); timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources() .getDrawable(R.drawable.plugin_capture_video_timelapse_active)); ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START); } else { timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources() .getDrawable(R.drawable.plugin_capture_video_timelapse_inactive)); ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START); } } }); timeLapseDialog.show(); }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public Object showNativePicker(final int type, final Component source, final Object currentValue, final Object data) { if (getActivity() == null) { return null; }/*w w w.j a va2 s .c o m*/ final boolean[] canceled = new boolean[1]; final boolean[] dismissed = new boolean[1]; if (editInProgress()) { stopEditing(true); } if (type == Display.PICKER_TYPE_TIME) { class TimePick implements TimePickerDialog.OnTimeSetListener, TimePickerDialog.OnCancelListener, Runnable { int result = ((Integer) currentValue).intValue(); public void onTimeSet(TimePicker tp, int hour, int minute) { result = hour * 60 + minute; dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } @Override public void onCancel(DialogInterface di) { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final TimePick pickInstance = new TimePick(); getActivity().runOnUiThread(new Runnable() { public void run() { int hour = ((Integer) currentValue).intValue() / 60; int minute = ((Integer) currentValue).intValue() % 60; TimePickerDialog tp = new TimePickerDialog(getActivity(), pickInstance, hour, minute, true) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); //DateFormat.is24HourFormat(activity)); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } return new Integer(pickInstance.result); } if (type == Display.PICKER_TYPE_DATE) { final java.util.Calendar cl = java.util.Calendar.getInstance(); if (currentValue != null) { cl.setTime((Date) currentValue); } class DatePick implements DatePickerDialog.OnDateSetListener, DatePickerDialog.OnCancelListener, Runnable { Date result = (Date) currentValue; public void onDateSet(DatePicker dp, int year, int month, int day) { java.util.Calendar c = java.util.Calendar.getInstance(); c.set(java.util.Calendar.YEAR, year); c.set(java.util.Calendar.MONTH, month); c.set(java.util.Calendar.DAY_OF_MONTH, day); result = c.getTime(); dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void onCancel(DialogInterface di) { result = null; dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final DatePick pickInstance = new DatePick(); getActivity().runOnUiThread(new Runnable() { public void run() { DatePickerDialog tp = new DatePickerDialog(getActivity(), pickInstance, cl.get(java.util.Calendar.YEAR), cl.get(java.util.Calendar.MONTH), cl.get(java.util.Calendar.DAY_OF_MONTH)) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); return pickInstance.result; } if (type == Display.PICKER_TYPE_STRINGS) { final String[] values = (String[]) data; class StringPick implements Runnable, NumberPicker.OnValueChangeListener { int result = -1; StringPick() { } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void cancel() { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } public void ok() { canceled[0] = false; dismissed[0] = true; synchronized (this) { notify(); } } @Override public void onValueChange(NumberPicker np, int oldVal, int newVal) { result = newVal; } } final StringPick pickInstance = new StringPick(); for (int iter = 0; iter < values.length; iter++) { if (values[iter].equals(currentValue)) { pickInstance.result = iter; break; } } if (pickInstance.result == -1 && values.length > 0) { // The picker will default to showing the first element anyways // If we don't set the result to 0, then the user has to first // scroll to a different number, then back to the first option // to pick the first option. pickInstance.result = 0; } getActivity().runOnUiThread(new Runnable() { public void run() { NumberPicker picker = new NumberPicker(getActivity()); if (source.getClientProperty("showKeyboard") == null) { picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); } picker.setMinValue(0); picker.setMaxValue(values.length - 1); picker.setDisplayedValues(values); picker.setOnValueChangedListener(pickInstance); if (pickInstance.result > -1) { picker.setValue(pickInstance.result); } RelativeLayout linearLayout = new RelativeLayout(getActivity()); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50); RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL); linearLayout.setLayoutParams(params); linearLayout.addView(picker, numPicerParams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setView(linearLayout); alertDialogBuilder.setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { pickInstance.ok(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); pickInstance.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } if (pickInstance.result < 0) { return null; } return values[pickInstance.result]; } return null; }