List of usage examples for android.widget NumberPicker setMaxValue
public void setMaxValue(int maxValue)
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);/*from w w w . ja v a 2 s. c o m*/ picker.setMaxValue(10); 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: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);/*from ww w. j av a2s .c om*/ 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: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);/*w ww .j a v a 2s . 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:edu.pdx.its.portal.routelandia.DatePickUp.java
/** * change the minute interval to quarter* * @param timePicker : timepicker obk in the view *//*from ww w . j ava 2 s . c om*/ @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: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); numberPicker.setMinValue(80);//www. j a va 2 s .c o m 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.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. *//*from ww w . j a v a2s . co m*/ 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(); } }
From source file:com.metinkale.prayerapp.vakit.PrefsView.java
@Override public void onClick(View v) { Object o = getValue();//from www. ja v a 2 s . com 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);//from w w w.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: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 .ja va2 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: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);//w w w . j av a 2 s . c om 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; }