Search in sources :

Example 21 with NumberPicker

use of android.widget.NumberPicker in project butter-android by butterproject.

the class NumberPickerDialogFragment method onCreateDialog.

@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();
    }
    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, (dialog, which) -> {
        mOnResultListener.onNewValue(numberPicker.getValue() + (minValue < 0 ? minValue : 0));
        dialog.dismiss();
    }).setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
    return builder.create();
}
Also used : AlertDialog(android.app.AlertDialog) AlertDialog(android.app.AlertDialog) List(java.util.List) Bundle(android.os.Bundle) Dialog(android.app.Dialog) DialogFragment(android.support.v4.app.DialogFragment) R(butter.droid.base.R) ViewGroup(android.view.ViewGroup) NumberPicker(android.widget.NumberPicker) ArrayList(java.util.ArrayList) NumberPicker(android.widget.NumberPicker) ArrayList(java.util.ArrayList)

Example 22 with NumberPicker

use of android.widget.NumberPicker in project Gadgetbridge by Freeyourgadget.

the class ConfigActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_qhybrid_settings);
    findViewById(R.id.buttonOverwriteButtons).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS));
        }
    });
    prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE);
    timeOffsetView = findViewById(R.id.qhybridTimeOffset);
    timeOffsetView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int timeOffset = prefs.getInt("QHYBRID_TIME_OFFSET", 0);
            LinearLayout layout2 = new LinearLayout(ConfigActivity.this);
            layout2.setOrientation(LinearLayout.HORIZONTAL);
            final NumberPicker hourPicker = new NumberPicker(ConfigActivity.this);
            hourPicker.setMinValue(0);
            hourPicker.setMaxValue(23);
            hourPicker.setValue(timeOffset / 60);
            final NumberPicker minPicker = new NumberPicker(ConfigActivity.this);
            minPicker.setMinValue(0);
            minPicker.setMaxValue(59);
            minPicker.setValue(timeOffset % 60);
            layout2.addView(hourPicker);
            TextView tw = new TextView(ConfigActivity.this);
            tw.setText(":");
            layout2.addView(tw);
            layout2.addView(minPicker);
            layout2.setGravity(Gravity.CENTER);
            new AlertDialog.Builder(ConfigActivity.this).setTitle(getString(R.string.qhybrid_offset_time_by)).setView(layout2).setPositiveButton("ok", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    prefs.edit().putInt("QHYBRID_TIME_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply();
                    updateTimeOffset();
                    LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE));
                    GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO);
                }
            }).setNegativeButton("cancel", null).show();
        }
    });
    updateTimeOffset();
    timezoneOffsetView = findViewById(R.id.timezoneOffset);
    timezoneOffsetView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int timeOffset = prefs.getInt("QHYBRID_TIMEZONE_OFFSET", 0);
            LinearLayout layout2 = new LinearLayout(ConfigActivity.this);
            layout2.setOrientation(LinearLayout.HORIZONTAL);
            final NumberPicker hourPicker = new NumberPicker(ConfigActivity.this);
            hourPicker.setMinValue(0);
            hourPicker.setMaxValue(23);
            hourPicker.setValue(timeOffset / 60);
            final NumberPicker minPicker = new NumberPicker(ConfigActivity.this);
            minPicker.setMinValue(0);
            minPicker.setMaxValue(59);
            minPicker.setValue(timeOffset % 60);
            layout2.addView(hourPicker);
            TextView tw = new TextView(ConfigActivity.this);
            tw.setText(":");
            layout2.addView(tw);
            layout2.addView(minPicker);
            layout2.setGravity(Gravity.CENTER);
            new AlertDialog.Builder(ConfigActivity.this).setTitle(getString(R.string.qhybrid_offset_timezone)).setView(layout2).setPositiveButton("ok", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    prefs.edit().putInt("QHYBRID_TIMEZONE_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply();
                    updateTimezoneOffset();
                    LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_TIMEZONE));
                    GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO);
                }
            }).setNegativeButton("cancel", null).show();
        }
    });
    updateTimezoneOffset();
    setTitle(R.string.preferences_qhybrid_settings);
    ListView appList = findViewById(R.id.qhybrid_appList);
    try {
        helper = new PackageConfigHelper(getApplicationContext());
        list = helper.getNotificationConfigurations();
    } catch (Exception e) {
        GB.toast("error getting configurations", Toast.LENGTH_SHORT, GB.ERROR, e);
        list = new ArrayList<>();
    }
    // null is added to indicate the plus button added handled in PackageAdapter#getView
    list.add(null);
    appList.setAdapter(adapter = new PackageAdapter(this, R.layout.qhybrid_package_settings_item, list));
    appList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(final AdapterView<?> adapterView, View view, final int i, long l) {
            PopupMenu menu = new PopupMenu(ConfigActivity.this, view);
            menu.getMenu().add(0, 0, 0, "edit");
            menu.getMenu().add(0, 1, 1, "delete");
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    switch(menuItem.getItemId()) {
                        case 0:
                            {
                                TimePicker picker = new TimePicker(ConfigActivity.this, (NotificationConfiguration) adapterView.getItemAtPosition(i));
                                picker.finishListener = new TimePicker.OnFinishListener() {

                                    @Override
                                    public void onFinish(boolean success, NotificationConfiguration config) {
                                        setControl(false, null);
                                        if (success) {
                                            try {
                                                helper.saveNotificationConfiguration(config);
                                                LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
                                            } catch (Exception e) {
                                                GB.toast("error saving notification", Toast.LENGTH_SHORT, GB.ERROR, e);
                                            }
                                            refreshList();
                                        }
                                    }
                                };
                                picker.handsListener = new TimePicker.OnHandsSetListener() {

                                    @Override
                                    public void onHandsSet(NotificationConfiguration config) {
                                        setHands(config);
                                    }
                                };
                                picker.vibrationListener = new TimePicker.OnVibrationSetListener() {

                                    @Override
                                    public void onVibrationSet(NotificationConfiguration config) {
                                        vibrate(config);
                                    }
                                };
                                setControl(true, picker.getSettings());
                                break;
                            }
                        case 1:
                            {
                                try {
                                    helper.deleteNotificationConfiguration((NotificationConfiguration) adapterView.getItemAtPosition(i));
                                    LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
                                } catch (Exception e) {
                                    GB.toast("error deleting setting", Toast.LENGTH_SHORT, GB.ERROR, e);
                                }
                                refreshList();
                                break;
                            }
                    }
                    return true;
                }
            });
            menu.show();
            return true;
        }
    });
    appList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Intent notificationIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION);
            notificationIntent.putExtra("CONFIG", (NotificationConfiguration) adapterView.getItemAtPosition(i));
            LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(notificationIntent);
        }
    });
    SeekBar vibeBar = findViewById(R.id.vibrationStrengthBar);
    vibeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        int start;

        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            start = seekBar.getProgress();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            int progress;
            if ((progress = seekBar.getProgress()) == start)
                return;
            String[] values = { "25", "50", "100" };
            device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_VIBRATION_STRENGTH, values[progress]));
            Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
            intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_VIBRATION_STRENGTH);
            LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
        }
    });
    device = GBApplication.app().getDeviceManager().getSelectedDevice();
    if (device == null || device.getType() != DeviceType.FOSSILQHYBRID || device.getFirmwareVersion().charAt(2) != '0') {
        setSettingsError(getString(R.string.watch_not_connected));
    } else {
        updateSettings();
    }
}
Also used : GenericItem(nodomain.freeyourgadget.gadgetbridge.model.GenericItem) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) ListView(android.widget.ListView) TextView(android.widget.TextView) NumberPicker(android.widget.NumberPicker) SeekBar(android.widget.SeekBar) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) JSONException(org.json.JSONException) Paint(android.graphics.Paint) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout) PopupMenu(android.widget.PopupMenu)

Example 23 with NumberPicker

use of android.widget.NumberPicker in project material-calendarview by prolificinteractive.

the class DynamicSettersActivity method onTileWidthHeightClicked.

@OnClick(R.id.button_set_width_height)
void onTileWidthHeightClicked() {
    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    final NumberPicker pickerWidth = new NumberPicker(this);
    pickerWidth.setMinValue(24);
    pickerWidth.setMaxValue(64);
    pickerWidth.setWrapSelectorWheel(false);
    pickerWidth.setValue(currentTileWidth);
    final NumberPicker pickerHeight = new NumberPicker(this);
    pickerHeight.setMinValue(24);
    pickerHeight.setMaxValue(64);
    pickerHeight.setWrapSelectorWheel(false);
    pickerHeight.setValue(currentTileHeight);
    layout.addView(pickerWidth);
    layout.addView(pickerHeight);
    new AlertDialog.Builder(this).setView(layout).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(@NonNull DialogInterface dialog, int which) {
            currentTileWidth = pickerWidth.getValue();
            currentTileHeight = pickerHeight.getValue();
            widget.setTileSize(-1);
            widget.setTileWidthDp(currentTileWidth);
            widget.setTileHeightDp(currentTileHeight);
        }
    }).show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) NumberPicker(android.widget.NumberPicker) DialogInterface(android.content.DialogInterface) NonNull(android.support.annotation.NonNull) LinearLayout(android.widget.LinearLayout) OnClick(butterknife.OnClick)

Example 24 with NumberPicker

use of android.widget.NumberPicker in project material-calendarview by prolificinteractive.

the class DynamicSettersActivity method onTileSizeClicked.

@OnClick(R.id.button_set_tile_size)
void onTileSizeClicked() {
    final NumberPicker view = new NumberPicker(this);
    view.setMinValue(24);
    view.setMaxValue(64);
    view.setWrapSelectorWheel(false);
    view.setValue(currentTileSize);
    new AlertDialog.Builder(this).setView(view).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(@NonNull DialogInterface dialog, int which) {
            currentTileSize = view.getValue();
            widget.setTileSizeDp(currentTileSize);
        }
    }).show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) NumberPicker(android.widget.NumberPicker) DialogInterface(android.content.DialogInterface) NonNull(android.support.annotation.NonNull) OnClick(butterknife.OnClick)

Example 25 with NumberPicker

use of android.widget.NumberPicker in project orgzly-android by orgzly.

the class EspressoUtils method setNumber.

public static ViewAction setNumber(final int num) {
    return new ViewAction() {

        @Override
        public void perform(UiController uiController, View view) {
            NumberPicker np = (NumberPicker) view;
            np.setValue(num);
        }

        @Override
        public String getDescription() {
            return "Set the passed number into the NumberPicker";
        }

        @Override
        public Matcher<View> getConstraints() {
            return ViewMatchers.isAssignableFrom(NumberPicker.class);
        }
    };
}
Also used : NumberPicker(android.widget.NumberPicker) ViewAction(androidx.test.espresso.ViewAction) UiController(androidx.test.espresso.UiController) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Espresso.onView(androidx.test.espresso.Espresso.onView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Aggregations

NumberPicker (android.widget.NumberPicker)32 View (android.view.View)19 TextView (android.widget.TextView)14 DialogInterface (android.content.DialogInterface)12 Dialog (android.app.Dialog)10 Button (android.widget.Button)10 AlertDialog (android.app.AlertDialog)8 LayoutInflater (android.view.LayoutInflater)6 Paint (android.graphics.Paint)5 NonNull (android.support.annotation.NonNull)5 AlertDialog (android.support.v7.app.AlertDialog)5 CompoundButton (android.widget.CompoundButton)5 FrameLayout (android.widget.FrameLayout)5 OnClick (butterknife.OnClick)5 TimePickerDialog (android.app.TimePickerDialog)4 ListView (android.widget.ListView)4 Activity (android.app.Activity)3 Intent (android.content.Intent)3 ImageView (android.widget.ImageView)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3