List of usage examples for android.widget SeekBar.OnSeekBarChangeListener SeekBar.OnSeekBarChangeListener
SeekBar.OnSeekBarChangeListener
From source file:nf.frex.android.FrexActivity.java
private void preparePropertiesDialog(final Dialog dialog) { final Registry<Fractal> fractals = Registries.fractals; int fractalTypeIndex = fractals.getIndex(view.getFractalId()); final Spinner fractalTypeSpinner = (Spinner) dialog.findViewById(R.id.fractal_type_spinner); final SeekBar iterationsSeekBar = (SeekBar) dialog.findViewById(R.id.num_iterations_seek_bar); final EditText iterationsEditText = (EditText) dialog.findViewById(R.id.num_iterations_edit_text); final CheckBox juliaModeCheckBox = (CheckBox) dialog.findViewById(R.id.julia_mode_fractal_check_box); final CheckBox decoratedFractal = (CheckBox) dialog.findViewById(R.id.decorated_fractal_check_box); final Button okButton = (Button) dialog.findViewById(R.id.ok_button); final Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button); juliaModeCheckBox.setEnabled(true);/* ww w.j av a 2 s. com*/ ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, fractals.getIds()); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); fractalTypeSpinner.setAdapter(arrayAdapter); fractalTypeSpinner.setSelection(fractalTypeIndex, true); fractalTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) { Fractal fractal = fractals.getValue(position); iterationsEditText.setText(fractal.getDefaultIterMax() + ""); boolean sameFractal = view.getFractalId().equals(fractals.getId(position)); if (!sameFractal) { juliaModeCheckBox.setChecked(false); } juliaModeCheckBox.setEnabled(sameFractal); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); iterationsEditText.setText(view.getIterMax() + "", TextView.BufferType.NORMAL); final double iterationsMin = 1; final double iterationsMax = 3; final SeekBarConfigurer iterationsSeekBarConfigurer = SeekBarConfigurer.create(iterationsSeekBar, iterationsMin, iterationsMax, true, view.getIterMax()); iterationsSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { int iterMax = iterationsSeekBarConfigurer.getValueInt(); iterationsEditText.setText(iterMax + "", TextView.BufferType.NORMAL); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); iterationsEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { try { int iterMax = Integer.parseInt(v.getText().toString()); iterationsSeekBarConfigurer.setValue(iterMax); return true; } catch (NumberFormatException e) { return false; } } }); decoratedFractal.setChecked(view.isDecoratedFractal()); juliaModeCheckBox.setChecked(view.isJuliaModeFractal()); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int iterMax; try { iterMax = Integer.parseInt(iterationsEditText.getText().toString()); } catch (NumberFormatException e) { Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show(); return; } dialog.dismiss(); String oldConfigName = view.getConfigName(); String newFractalId = fractals.getId(fractalTypeSpinner.getSelectedItemPosition()); Fractal fractal = fractals.getValue(fractalTypeSpinner.getSelectedItemPosition()); String oldFractalId = view.getFractalId(); boolean newJuliaModeFractal = juliaModeCheckBox.isChecked(); boolean oldJuliaModeFractal = view.isJuliaModeFractal(); view.setFractalId(newFractalId); view.setIterMax(iterMax); view.setDecoratedFractal(decoratedFractal.isChecked()); view.setJuliaModeFractal(newJuliaModeFractal); boolean fractalTypeChanged = !oldFractalId.equals(newFractalId); if (fractalTypeChanged) { if (oldConfigName.contains(oldFractalId.toLowerCase())) { view.setConfigName(newFractalId.toLowerCase()); } view.setRegion(fractal.getDefaultRegion()); view.setBailOut(fractal.getDefaultBailOut()); } boolean juliaModeChanged = oldJuliaModeFractal != newJuliaModeFractal; if (fractalTypeChanged || juliaModeChanged) { view.getRegionHistory().clear(); view.getRegionHistory().add(fractal.getDefaultRegion().clone()); } view.recomputeAll(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }
From source file:com.javielinux.fragments.MyActivityFragment.java
public void showSizeText() { final int minValue = 6; LayoutInflater factory = LayoutInflater.from(getActivity()); final View sizesFontView = factory.inflate(R.layout.alert_dialog_sizes_font, null); ((TextView) sizesFontView.findViewById(R.id.txt_size_titles)).setText( getString(R.string.size_title) + " (" + PreferenceUtils.getSizeTitles(getActivity()) + ")"); ((TextView) sizesFontView.findViewById(R.id.txt_size_text)) .setText(getString(R.string.size_text) + " (" + PreferenceUtils.getSizeText(getActivity()) + ")"); SeekBar sbSizeTitles = (SeekBar) sizesFontView.findViewById(R.id.sb_size_titles); sbSizeTitles.setMax(18);//from w ww . java2 s. co m sbSizeTitles.setProgress(PreferenceUtils.getSizeTitles(getActivity()) - minValue); sbSizeTitles.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { progress += minValue; PreferenceUtils.setSizeTitles(getActivity(), progress); //seekBar.setProgress(progress); ((TextView) sizesFontView.findViewById(R.id.txt_size_titles)).setText( getString(R.string.size_title) + " (" + PreferenceUtils.getSizeTitles(getActivity()) + ")"); // TODO notificar al adapter el cambio de texto //mAdapterResponseList.notifyDataSetChanged(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); SeekBar sbSizeText = (SeekBar) sizesFontView.findViewById(R.id.sb_size_text); sbSizeText.setMax(18); sbSizeText.setProgress(PreferenceUtils.getSizeText(getActivity()) - minValue); sbSizeText.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { progress += minValue; PreferenceUtils.setSizeText(getActivity(), progress); //seekBar.setProgress(progress); ((TextView) sizesFontView.findViewById(R.id.txt_size_text)).setText( getString(R.string.size_text) + " (" + PreferenceUtils.getSizeText(getActivity()) + ")"); // TODO notificar al adapter el cambio de texto //mAdapterResponseList.notifyDataSetChanged(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.font_size); builder.setView(sizesFontView); builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.create(); builder.show(); }