List of usage examples for android.widget NumberPicker setValue
public void setValue(int value)
From source file:cz.maresmar.sfm.view.menu.MenuDetailsFragment.java
private void showPickerDialog(@StringRes int title, int min, int max, int value, IntConsumer newValueConsumer) { // Prepare number picker NumberPicker picker = new NumberPicker(getContext()); picker.setMinValue(min);//from w w w. j av a 2 s .co m picker.setMaxValue(max); picker.setValue(value); picker.setWrapSelectorWheel(false); FrameLayout layout = new FrameLayout(getContext()); layout.addView(picker, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER)); // Show alert new AlertDialog.Builder(getContext()).setTitle(title).setMessage(R.string.menu_detail_pick_new_value) .setView(layout).setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { // do something with picker.getValue() newValueConsumer.accept(picker.getValue()); }).setNegativeButton(android.R.string.cancel, null).show(); }
From source file:com.metinkale.prayerapp.vakit.PrefsView.java
@Override public void onClick(View v) { Object o = getValue();/* ww w .j a v a2s. c o m*/ if ((mPref == Pref.Sound) || (mPref == Pref.Dua) || (mPref == Pref.Sela)) { new SoundChooser().showExpanded(((Activity) getContext()).getFragmentManager(), new Callback() { @Override public String getCurrent() { return (String) getValue(); } @Override public void setCurrent(String current) { setValue(current); } @Override public Vakit getVakit() { return mVakit; } @Override public List<Sound> getSounds() { if (mPref == Pref.Sound) { return Sounds.getSounds(mVakit); } else if (mPref == Pref.Dua) { return Sounds.getSounds("dua", "extra"); } else if (mPref == Pref.Sela) { return Sounds.getSounds("sela", "extra"); } return Sounds.getSounds(mVakit); } }); } else if (mPref == Pref.SabahTime) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); LayoutInflater inflater = LayoutInflater.from(getContext()); View view = inflater.inflate(R.layout.sabahtime_dialog, null); final NumberPicker np = (NumberPicker) view.findViewById(R.id.number_picker); final RadioGroup rg = (RadioGroup) view.findViewById(R.id.rg); int val = (Integer) getValue(); np.setMinValue(0); np.setMaxValue(300); np.setValue(Math.abs(val)); rg.check((val < 0) ? R.id.afterImsak : R.id.beforeGunes); builder.setView(view).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { setValue(np.getValue() * ((rg.getCheckedRadioButtonId() == R.id.beforeGunes) ? 1 : -1)); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); builder.show(); } else if (mPref == Pref.Vibration2) { int i = (Integer) o; i++; if ((i < -1) || (i > 1)) { i = -1; } setValue(i); performHapticFeedback(HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); } else if (o instanceof Boolean) { setValue(!(Boolean) o); performHapticFeedback(HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); } else if (o instanceof Integer) { int titleId = 0; switch (mPref) { case Silenter: PermissionUtils.get(getContext()).needNotificationPolicy((Activity) getContext()); titleId = R.string.silenterDuration; break; case Time: titleId = R.string.time; break; default: break; } NumberPickerDialog npd = new NumberPickerDialog(getContext(), new OnNumberSetListener() { @Override public void onNumberSet(int dialogId, int number) { setValue(number); } }, (Integer) o, 0, 300, titleId, 0, 0); npd.show(); } }
From source file:io.github.data4all.activity.MapViewActivity.java
private void bodyheightdialog() { PreferenceManager.setDefaultValues(this, R.xml.settings, false); this.prefs = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences userPrefs = getSharedPreferences("UserPrefs", 0); firstUse = userPrefs.getBoolean("firstUse", true); if (firstUse) { RelativeLayout linearLayout = new RelativeLayout(this); final NumberPicker numberPicker = new NumberPicker(this); numberPicker.setMaxValue(250);/*from w w w . j a v a2 s . c om*/ numberPicker.setMinValue(80); numberPicker.setValue(180); 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(numberPicker, numPicerParams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(R.string.pref_bodyheight_dialog_title); alertDialogBuilder.setMessage(R.string.pref_bodyheight_dialog_message); alertDialogBuilder.setView(linearLayout); alertDialogBuilder.setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Log.d(TAG, "set bodyheight to: " + numberPicker.getValue()); prefs.edit().putString("PREF_BODY_HEIGHT", String.valueOf(numberPicker.getValue())) .commit(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); // set firstUse to false so this dialog is not shown again. ever. userPrefs.edit().putBoolean("firstUse", false).commit(); firstUse = false; } }
From source file:com.retroteam.studio.retrostudio.MeasureEditor.java
/** * Show the user the octave changer prompt. *///from w w w. j av a 2 s.c om private void octavePrompt() { AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); final View tempo_picker = inflater.inflate(R.layout.octave_picker, null); final NumberPicker np = (NumberPicker) tempo_picker.findViewById(R.id.octavePickerField); np.setMaxValue(8); np.setMinValue(0); np.setValue(noteSUB); builder.setTitle("Set Measure Octave").setView(tempo_picker) .setPositiveButton(R.string.set, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { int sub = np.getValue(); noteSUB = sub; } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // do nothing } }); AlertDialog dialog = builder.create(); dialog.show(); }
From source file:kr.wdream.storyshop.AndroidUtilities.java
public static AlertDialog.Builder buildTTLAlert(final Context context, final TLRPC.EncryptedChat encryptedChat) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(LocaleController.getString("MessageLifetime", R.string.MessageLifetime)); final NumberPicker numberPicker = new NumberPicker(context); numberPicker.setMinValue(0);/*from w w w .j av a2s . c o m*/ numberPicker.setMaxValue(20); if (encryptedChat.ttl > 0 && encryptedChat.ttl < 16) { numberPicker.setValue(encryptedChat.ttl); } else if (encryptedChat.ttl == 30) { numberPicker.setValue(16); } else if (encryptedChat.ttl == 60) { numberPicker.setValue(17); } else if (encryptedChat.ttl == 60 * 60) { numberPicker.setValue(18); } else if (encryptedChat.ttl == 60 * 60 * 24) { numberPicker.setValue(19); } else if (encryptedChat.ttl == 60 * 60 * 24 * 7) { numberPicker.setValue(20); } else if (encryptedChat.ttl == 0) { numberPicker.setValue(0); } numberPicker.setFormatter(new NumberPicker.Formatter() { @Override public String format(int value) { if (value == 0) { return LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever); } else if (value >= 1 && value < 16) { return AndroidUtilities.formatTTLString(value); } else if (value == 16) { return AndroidUtilities.formatTTLString(30); } else if (value == 17) { return AndroidUtilities.formatTTLString(60); } else if (value == 18) { return AndroidUtilities.formatTTLString(60 * 60); } else if (value == 19) { return AndroidUtilities.formatTTLString(60 * 60 * 24); } else if (value == 20) { return AndroidUtilities.formatTTLString(60 * 60 * 24 * 7); } return ""; } }); builder.setView(numberPicker); builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int oldValue = encryptedChat.ttl; which = numberPicker.getValue(); if (which >= 0 && which < 16) { encryptedChat.ttl = which; } else if (which == 16) { encryptedChat.ttl = 30; } else if (which == 17) { encryptedChat.ttl = 60; } else if (which == 18) { encryptedChat.ttl = 60 * 60; } else if (which == 19) { encryptedChat.ttl = 60 * 60 * 24; } else if (which == 20) { encryptedChat.ttl = 60 * 60 * 24 * 7; } if (oldValue != encryptedChat.ttl) { SecretChatHelper.getInstance().sendTTLMessage(encryptedChat, null); MessagesStorage.getInstance().updateEncryptedChatTTL(encryptedChat); } } }); return builder; }
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//from w ww . ja v a 2s . 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:com.untie.daywal.activity.MainActivity.java
private void showDayPicker() { Calendar calender = Calendar.getInstance(); pickedYear = calender.get(Calendar.YEAR); pickedMonth = calender.get(Calendar.MONTH) + 1; final Dialog dayPickerDialog = new Dialog(this); dayPickerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dayPickerDialog.setContentView(R.layout.dialog); Button okBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_ok); Button cancelBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_cancel); dialog_year_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_year_title); dialog_month_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_month_title); final NumberPicker yearPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.yearPicker); final NumberPicker monthPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.monthPicker); dialog_year_title.setText(String.valueOf(pickedYear) + ""); dialog_month_title.setText(String.valueOf(pickedMonth) + ""); yearPicker.setMinValue(pickedYear - 100); yearPicker.setMaxValue(pickedYear + 40); yearPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); // setDividerColor(yearPicker, android.R.color.white ); yearPicker.setWrapSelectorWheel(false); yearPicker.setValue(pickedYear); yearPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override/* www . ja v a2 s . c o m*/ public void onValueChange(NumberPicker picker, int oldVal, int newVal) { dialog_year_title.setText(String.valueOf(newVal) + ""); } }); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); // setDividerColor(monthPicker, android.R.color.white); //monthPicker.setWrapSelectorWheel(false); monthPicker.setValue(pickedMonth); monthPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { dialog_month_title.setText(String.valueOf(newVal) + ""); } }); okBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //TODO : ?? yearPicker.getValue() monthPicker.getValue() //Toast.makeText(MainActivity.this, String.valueOf(yearPicker.getValue())+"/"+monthPicker.getValue(), Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MainActivity.this, MainActivity.class); intent.putExtra("year", yearPicker.getValue()); intent.putExtra("month", monthPicker.getValue()); intent.putExtra("order", 1); dayPickerDialog.dismiss(); startActivity(intent); overridePendingTransition(0, 0); } }); cancelBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dayPickerDialog.dismiss(); } }); dayPickerDialog.show(); }
From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java
/** * Screen to select the number of questions in the test *//* w w w.j a v a2s .c om*/ private void selectNumQuestions() { screenStep = ScreenStep.NUM_QUESTIONS; setLayout(R.layout.tests_num_questions); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { android.widget.NumberPicker numberPicker = (android.widget.NumberPicker) findViewById( R.id.testNumQuestionsNumberPicker); numberPicker.setMaxValue(test.getMax()); numberPicker.setMinValue(test.getMin()); numberPicker.setValue(test.getDef()); numberPicker.setVisibility(View.VISIBLE); } else { es.ugr.swad.swadroid.gui.widget.NumberPicker numberPickerOld = (es.ugr.swad.swadroid.gui.widget.NumberPicker) findViewById( R.id.testNumQuestionsNumberPickerOld); numberPickerOld.setRange(test.getMin(), test.getMax()); numberPickerOld.setCurrent(test.getDef()); numberPickerOld.setVisibility(View.VISIBLE); } }
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);/* ww w . ja v a 2s.c o 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: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 www .java2s . 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(); }