List of usage examples for android.widget NumberPicker setMinValue
public void setMinValue(int minValue)
From source file:org.sufficientlysecure.keychain.ui.SafeSlingerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.safe_slinger_activity); mMasterKeyId = getIntent().getLongExtra(EXTRA_MASTER_KEY_ID, 0); // NOTE: there are two versions of this layout, for API >= 11 and one for < 11 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { NumberPicker picker = (NumberPicker) findViewById(R.id.safe_slinger_picker); picker.setMinValue(2); picker.setMaxValue(10);//w ww .j a va 2 s . c o m picker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { mSelectedNumber = newVal; } }); } else { Spinner spinner = (Spinner) findViewById(R.id.safe_slinger_spinner); List<String> list = new ArrayList<String>(); list.add("2"); list.add("3"); list.add("4"); list.add("5"); list.add("6"); list.add("7"); list.add("8"); list.add("9"); list.add("10"); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mSelectedNumber = position + 2; } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } ImageView buttonIcon = (ImageView) findViewById(R.id.safe_slinger_button_image); buttonIcon.setColorFilter(getResources().getColor(R.color.tertiary_text_light), PorterDuff.Mode.SRC_IN); View button = findViewById(R.id.safe_slinger_button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startExchange(mMasterKeyId, mSelectedNumber); } }); }
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); picker.setMaxValue(max);/* w w w . j ava 2 s .co m*/ 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:edu.pdx.its.portal.routelandia.DatePickUp.java
/** * change the minute interval to quarter* * @param timePicker : timepicker obk in the view *//*from w w w. j a va 2 s . 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:de.anycook.einkaufszettel.activities.AddIngredientsActivity.java
public void onNumberPickerClick(View view) { final EditText personsEditText = (EditText) view; int numPersons = Integer.parseInt(personsEditText.getText().toString()); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setMessage(R.string.for_x_people); View alertDialogContent = LayoutInflater.from(alertDialogBuilder.getContext()) .inflate(R.layout.number_picker_dialog, this.ingredientListView, false); final NumberPicker numberPicker = (NumberPicker) alertDialogContent .findViewById(R.id.number_picker_dialog_numberpicker); numberPicker.setMaxValue(MAX_PERSONS); numberPicker.setValue(numPersons);//w w w . jav a 2s.c o m numberPicker.setMinValue(MIN_PERSONS); alertDialogBuilder.setView(alertDialogContent); alertDialogBuilder.setPositiveButton(R.string.set, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String personsString = Integer.toString(numberPicker.getValue()); personsEditText.setText(personsString); if (personsString.length() == 0) { return; } int numPersons = Integer.parseInt(personsEditText.getText().toString()); ((IngredientRowAdapter) ingredientListView.getAdapter()).setCurrentPersons(numPersons); } }); alertDialogBuilder.setNegativeButton(R.string.cancel, null); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }
From source file:com.metinkale.prayerapp.vakit.PrefsView.java
@Override public void onClick(View v) { Object o = getValue();/* ww w. ja v a 2 s. c om*/ 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:com.jaguarlandrover.hvacdemo.MainActivity.java
private void configurePicker(NumberPicker picker) { picker.setMinValue(15); picker.setMaxValue(29);// w ww . j a v a2 s . c om 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: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 w w. jav 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: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 ww w.ja v a 2s . c o m*/ 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.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);//from w ww. j a v a2 s . c o m yearPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override 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:com.example.google.playservices.placepicker.PlacePickerFragment.java
@Override public void onCardClick(int cardActionId, String cardTag) { if (cardActionId == ACTION_PICK_PLACE) { // BEGIN_INCLUDE(intent) /* Use the PlacePicker Builder to construct an Intent. Note: This sample demonstrates a basic use case. The PlacePicker Builder supports additional properties such as search bounds. */// ww w . j a v a 2s. c om try { PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder(); Intent intent = intentBuilder.build(getActivity()); // Start the Intent by requesting a result, identified by a request code. startActivityForResult(intent, REQUEST_PLACE_PICKER); // Hide the pick option in the UI to prevent users from starting the picker // multiple times. showPickAction(false); } catch (GooglePlayServicesRepairableException e) { GooglePlayServicesUtil.getErrorDialog(e.getConnectionStatusCode(), getActivity(), 0); } catch (GooglePlayServicesNotAvailableException e) { Toast.makeText(getActivity(), "Google Play Services is not available.", Toast.LENGTH_LONG).show(); } // END_INCLUDE(intent) } else if (cardActionId == ACTION_REPORT_WAIT) { final Dialog dialog = new Dialog(this.getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.report); final NumberPicker np = (NumberPicker) dialog.findViewById(R.id.numpicker); np.setMaxValue(120); np.setMinValue(0); // Report Button dialogButtonReport = (Button) dialog.findViewById(R.id.dialogButtonReport); dialogButtonReport.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { HttpPost httppost = new HttpPost("http://powergrid.xyz/quickq/restaurantpost.php"); httppost.setHeader("Content-type", "application/x-www-form-urlencoded"); List<NameValuePair> nameValuePairs = new ArrayList<>(2); // TODO nameValuePairs.add(new BasicNameValuePair("placeid", globalplace.getId())); nameValuePairs.add(new BasicNameValuePair("waittime", String.valueOf(np.getValue()))); try { httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } powergridServerReportTime task = new powergridServerReportTime(); task.execute(httppost); dialog.dismiss(); } }); // Cancel Button dialogButtonCancel = (Button) dialog.findViewById(R.id.dialogButtonCancel); // If button is clicked, close the custom dialog dialogButtonCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } }