@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(getArguments().getString("title")); LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.dialog_minutes, null, false); ButterKnife.bind(this, view); numberPicker.setMinValue(0); numberPicker.setMaxValue(300); numberPicker.setValue(getArguments().getInt("minutes")); builder.setView(view); builder.setPositiveButton( getArguments().getString("positiveBtn"), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { numberPicker.clearFocus(); int minutes = numberPicker.getValue(); callback.onDialogMinutesPositiveClick(getArguments().getInt("dialogId"), minutes); } }); Dialog dialog = builder.create(); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); return dialog; }
@Override public void onDialogClosed(boolean positiveResult) { if (positiveResult) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); sharedPreferences .edit() .putString("col_count", widthPicker.getValue() + "") .putString("row_count", heightPicker.getValue() + "") .commit(); } }
@Override public View onCreateDialogView() { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View preference = inflater.inflate(R.layout.preference_grid_size, null); widthPicker = (NumberPicker) preference.findViewById(R.id.width_picker); heightPicker = (NumberPicker) preference.findViewById(R.id.height_picker); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); widthPicker.setMaxValue(12); widthPicker.setMinValue(2); widthPicker.setValue( Integer.parseInt( sharedPrefs.getString( "col_count", getContext().getResources().getInteger(R.integer.default_col_count) + ""))); widthPicker.setWrapSelectorWheel(false); heightPicker.setMaxValue(12); heightPicker.setMinValue(3); heightPicker.setValue( Integer.parseInt( sharedPrefs.getString( "row_count", getContext().getResources().getInteger(R.integer.default_row_count) + ""))); heightPicker.setWrapSelectorWheel(false); return preference; }
@Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { if (hero.getPurse() != null) { PurseUnit unit = (PurseUnit) picker.getTag(); if (unit != null) { hero.getPurse().setCoins(unit, newVal); } } }