Example usage for android.widget SeekBar setOnSeekBarChangeListener

List of usage examples for android.widget SeekBar setOnSeekBarChangeListener

Introduction

In this page you can find the example usage for android.widget SeekBar setOnSeekBarChangeListener.

Prototype

public void setOnSeekBarChangeListener(OnSeekBarChangeListener l) 

Source Link

Document

Sets a listener to receive notifications of changes to the SeekBar's progress level.

Usage

From source file:org.mdc.chess.SeekBarPreference.java

@Override
protected View onCreateView(ViewGroup parent) {
    TextView name = new TextView(getContext());
    name.setText(getTitle());/*from  ww w .  jav  a 2s .  c o  m*/
    //name.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
    TextViewCompat.setTextAppearance(name, android.R.style.TextAppearance_Large);
    name.setGravity(Gravity.START);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.START;
    lp.weight = 1.0f;
    name.setLayoutParams(lp);

    currValBox = new TextView(getContext());
    currValBox.setTextSize(12);
    currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
    currValBox.setPadding(2, 5, 0, 0);
    currValBox.setText(valToString());
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER;
    currValBox.setLayoutParams(lp);

    LinearLayout row1 = new LinearLayout(getContext());
    row1.setOrientation(LinearLayout.HORIZONTAL);
    row1.addView(name);
    row1.addView(currValBox);

    final SeekBar bar = new SeekBar(getContext());
    bar.setMax(maxValue);
    bar.setProgress(currVal);
    bar.setOnSeekBarChangeListener(this);
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.END;
    bar.setLayoutParams(lp);

    CharSequence summaryCharSeq = getSummary();
    boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0);
    TextView summary = null;
    if (haveSummary) {
        summary = new TextView(getContext());
        summary.setText(getSummary());
        //            summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
        summary.setGravity(Gravity.START);
        lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.START;
        lp.weight = 1.0f;
        summary.setLayoutParams(lp);
    }

    LinearLayout layout = new LinearLayout(getContext());
    layout.setPadding(25, 5, 25, 5);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(row1);
    layout.addView(bar);
    if (summary != null) {
        layout.addView(summary);
    }
    layout.setId(android.R.id.widget_frame);

    currValBox.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
            final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
            builder.setView(content);
            String title = "";
            String key = getKey();
            if (key.equals("strength")) {
                title = getContext().getString(R.string.edit_strength);
            } else if (key.equals("bookRandom")) {
                title = getContext().getString(R.string.edit_randomization);
            }
            builder.setTitle(title);
            final EditText valueView = (EditText) content.findViewById(R.id.selpercentage_number);
            valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", "."));
            final Runnable selectValue = new Runnable() {
                public void run() {
                    try {
                        String txt = valueView.getText().toString();
                        int value = (int) (Double.parseDouble(txt) * 10 + 0.5);
                        if (value < 0)
                            value = 0;
                        if (value > maxValue)
                            value = maxValue;
                        onProgressChanged(bar, value, false);
                    } catch (NumberFormatException ignored) {

                    }
                }
            };
            valueView.setOnKeyListener(new OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        selectValue.run();
                        return true;
                    }
                    return false;
                }
            });
            builder.setPositiveButton("Ok", new Dialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    selectValue.run();
                }
            });
            builder.setNegativeButton("Cancel", null);

            builder.create().show();
        }
    });

    return layout;
}

From source file:org.secuso.privacyfriendlypasswordgenerator.dialogs.AddMetaDataDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = getActivity().getLayoutInflater();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    rootView = inflater.inflate(R.layout.dialog_add_metadata, null);

    versionVisible = false;//  w  w w .ja va2  s .  c o m

    builder.setView(rootView);
    builder.setIcon(R.mipmap.ic_drawer);
    builder.setTitle(getActivity().getString(R.string.add_metadata_heading));

    database = MetaDataSQLiteHelper.getInstance(getActivity());

    //Seekbar
    SeekBar seekBarLength = (SeekBar) rootView.findViewById(R.id.seekBarLength);
    final TextView textViewLengthDisplayFinal = (TextView) rootView.findViewById(R.id.textViewLengthDisplay);
    seekBarLength.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            textViewLengthDisplayFinal.setText(Integer.toString(progress + 4));
        }

        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    ImageButton versionInfoImageButton = (ImageButton) rootView.findViewById(R.id.versionInfoImageButton);
    versionInfoImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder infoBbuilder = new AlertDialog.Builder(getActivity());
            infoBbuilder.setTitle(getString(R.string.dialog_version_title));
            infoBbuilder.setMessage(R.string.dialog_version);
            infoBbuilder.show();
        }

    });

    Button versionButton = (Button) rootView.findViewById(R.id.versionButton);
    versionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LinearLayout versionDataLayout = (LinearLayout) rootView.findViewById(R.id.versionDataLayout);
            TextView versionTextView = (TextView) rootView.findViewById(R.id.versionButton);
            if (!versionVisible) {
                versionDataLayout.setVisibility(View.VISIBLE);
                versionTextView.setText(getString(R.string.change_version_opened));
                versionTextView.setTextColor(Color.BLACK);
                versionVisible = true;
            } else {
                versionDataLayout.setVisibility(View.GONE);
                versionTextView.setText(getString(R.string.change_version_closed));
                versionTextView.setTextColor(Color.parseColor("#d3d3d3"));
                versionVisible = false;
            }

        }

    });

    EditText iterations = (EditText) rootView.findViewById(R.id.EditTextIteration);
    iterations.setText("1");

    builder.setPositiveButton(getActivity().getString(R.string.add), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

            addMetaData();

        }
    });

    builder.setNegativeButton(getActivity().getString(R.string.cancel), null);

    return builder.create();
}

From source file:org.phillyopen.mytracks.cyclephilly.UserInfoActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.userprefs);/*  w  w w .  j a  va 2 s  .c  o  m*/
    //Firebase Init
    Firebase.setAndroidContext(this);

    // Don't pop up the soft keyboard until user clicks!
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    SeekBar sb = (SeekBar) findViewById(R.id.SeekCycleFreq);
    sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            TextView tv = (TextView) findViewById(R.id.TextFreq);
            tv.setText(freqDesc[arg1 / 100]);
        }
    });

    Button btn = (Button) findViewById(R.id.saveButton);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(UserInfoActivity.this, MainInput.class);
            startActivity(intent);
            finish();
        }

    });

    SharedPreferences settings = getSharedPreferences("PREFS", 0);
    Map<String, ?> prefs = settings.getAll();
    for (Entry<String, ?> p : prefs.entrySet()) {
        int key = Integer.parseInt(p.getKey());
        // CharSequence value = (CharSequence) p.getValue();

        switch (key) {
        case PREF_AGE:
            ((Spinner) findViewById(R.id.ageSpinner)).setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_ETHNICITY:
            ((Spinner) findViewById(R.id.ethnicitySpinner)).setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_INCOME:
            ((Spinner) findViewById(R.id.incomeSpinner)).setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_RIDERTYPE:
            ((Spinner) findViewById(R.id.ridertypeSpinner)).setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_RIDERHISTORY:
            ((Spinner) findViewById(R.id.riderhistorySpinner))
                    .setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_ZIPHOME:
            ((EditText) findViewById(R.id.TextZipHome)).setText((CharSequence) p.getValue());
            break;
        case PREF_ZIPWORK:
            ((EditText) findViewById(R.id.TextZipWork)).setText((CharSequence) p.getValue());
            break;
        case PREF_ZIPSCHOOL:
            ((EditText) findViewById(R.id.TextZipSchool)).setText((CharSequence) p.getValue());
            break;
        case PREF_EMAIL:
            ((EditText) findViewById(R.id.TextEmail)).setText((CharSequence) p.getValue());
            break;
        case PREF_CYCLEFREQ:
            ((SeekBar) findViewById(R.id.SeekCycleFreq)).setProgress(((Integer) p.getValue()).intValue());
            break;
        case PREF_GENDER:
            int x = ((Integer) p.getValue()).intValue();
            if (x == 2) {
                ((RadioButton) findViewById(R.id.ButtonMale)).setChecked(true);
            } else if (x == 1) {
                ((RadioButton) findViewById(R.id.ButtonFemale)).setChecked(true);
            }
            break;
        }
    }
}

From source file:com.andryr.musicplayer.activities.EqualizerActivity.java

private void initBassBoost() {
    SeekBar bassBoost = (SeekBar) findViewById(R.id.bassboost_slider);
    bassBoost.setMax(AudioEffects.BASSBOOST_MAX_STRENGTH);
    bassBoost.setProgress(AudioEffects.getBassBoostStrength());
    bassBoost.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override//from ww  w  . j  av a 2 s.co m
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                AudioEffects.setBassBoostStrength((short) seekBar.getProgress());
            }

        }
    });
}

From source file:com.precisionag.waterplane.MainActivity.java

private void configSeekbar(final Field field, final GroundOverlay overlay) {
    SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
    seekBar.setMax(255);//  ww w. j  a  v  a2s . c om
    seekBar.setProgress(seekBar.getMax() / 2);
    seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            updateColors(field);
            updateMarkers();
        }
    });
}

From source file:ar.rulosoft.custompref.SeekBarCustomPreference.java

@Override
public void onBindViewHolder(final PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);

    holder.itemView.setClickable(false);

    SeekBar seekBar = (SeekBar) holder.findViewById(R.id.seekbar);
    seekBar.setOnSeekBarChangeListener(this);
    seekBar.setMax(mPreferredMax - mPreferredMin);
    seekBar.setProgress(mProgress - mPreferredMin);
    seekBar.setEnabled(isEnabled());/*www  .j a  v  a2s.  co  m*/

    mKeyProgressIncrement = seekBar.getKeyProgressIncrement();
    holder.itemView.setOnKeyListener(this);

    TextView info = (TextView) holder.findViewById(android.R.id.summary);
    if (info != null) {
        mInfoViews.put(info, this);
        bindInfo(info);
        mKeys.put(getKey(), this);
    }
}

From source file:com.mylovemhz.simplay.MediaControlFragment.java

private void configureButtons(PlaybackStateCompat state) {
    if (state == null) {
        return;/*from  w w w .  ja v a2  s  .  c om*/
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_STOPPED:
        albumImage.setImageResource(R.drawable.ic_album);
        artistText.setText("");
        titleText.setText("");
        seekBar.setProgress(0);
        seekBar.setMax(1);
    case PlaybackStateCompat.STATE_PAUSED:
        handler.removeCallbacks(seekTickRunnable);
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_PLAYING:
        handler.post(seekTickRunnable);
        break;
    case PlaybackStateCompat.STATE_ERROR:
        Log.e(TAG, "error playbackstate: " + state.getErrorMessage());
        Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
        break;
    }

    if (enablePlay) {
        playPauseButton.setImageResource(playDrawableResource);
    } else {
        playPauseButton.setImageResource(pauseDrawableResource);
    }
    playPauseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (getPlaybackState() != PlaybackStateCompat.STATE_PLAYING) {
                mediaController.getTransportControls().play();
            } else {
                mediaController.getTransportControls().pause();
            }
        }
    });
    previousButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mediaController.getTransportControls().skipToPrevious();
        }
    });
    nextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mediaController.getTransportControls().skipToNext();
        }
    });
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                mediaController.getTransportControls().seekTo(progress);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}

From source file:org.secuso.privacyfriendlypasswordgenerator.dialogs.UpdateMetadataDialog.java

/**
 * Displays old metadata and lets user add new metadata
 *//*from w w w  .j  av a  2s .c o m*/
public void setUpData() {
    EditText domain = (EditText) rootView.findViewById(R.id.editTextDomainUpdate);
    EditText username = (EditText) rootView.findViewById(R.id.editTextUsernameUpdate);
    TextView oldVersion = (TextView) rootView.findViewById(R.id.textViewIteration);
    EditText newVersion = (EditText) rootView.findViewById(R.id.EditTextIteration);

    CheckBox checkBoxSpecialCharacterUpdate = (CheckBox) rootView
            .findViewById(R.id.checkBoxSpecialCharacterUpdate);
    CheckBox checkBoxLettersLowUpdate = (CheckBox) rootView.findViewById(R.id.checkBoxLettersLowUpdate);
    CheckBox checkBoxLettersUpUpdate = (CheckBox) rootView.findViewById(R.id.checkBoxLettersUpUpdate);
    CheckBox checkBoxNumbersUpdate = (CheckBox) rootView.findViewById(R.id.checkBoxNumbersUpdate);

    setCheckBox(checkBoxSpecialCharacterUpdate, metaData.getHAS_SYMBOLS());
    setCheckBox(checkBoxLettersLowUpdate, metaData.getHAS_LETTERS_LOW());
    setCheckBox(checkBoxLettersUpUpdate, metaData.getHAS_LETTERS_UP());
    setCheckBox(checkBoxNumbersUpdate, metaData.getHAS_NUMBERS());

    domain.setText(metaData.getDOMAIN());
    username.setText(metaData.getUSERNAME());

    oldVersion.setText(getString(R.string.old_version, String.valueOf(metaData.getITERATION())));
    newVersion.setText(String.valueOf(metaData.getITERATION() + 1));

    TextView textViewLengthDisplayUpdate = (TextView) rootView.findViewById(R.id.textViewLengthDisplayUpdate);
    textViewLengthDisplayUpdate.setText(Integer.toString(metaData.getLENGTH()));

    final TextView finalTextViewLengthDisplayUpdate = textViewLengthDisplayUpdate;

    SeekBar seekBarLength = (SeekBar) rootView.findViewById(R.id.seekBarLengthUpdate);
    seekBarLength.setProgress(metaData.getLENGTH() - 4);

    seekBarLength.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            finalTextViewLengthDisplayUpdate.setText(Integer.toString(progress + 4));
        }

        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

}

From source file:net.simno.klingar.ui.PlayerController.java

@NonNull
@Override//from   www. jav a2 s  .c o m
protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
    View view = super.onCreateView(inflater, container);

    toolbarOwner.setConfig(ToolbarOwner.Config.builder().background(false).backNavigation(true)
            .titleAlpha(TITLE_GONE).build());

    setHasOptionsMenu(true);

    queueRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    queueRecyclerView.setHasFixedSize(true);
    queueRecyclerView.addItemDecoration(new DividerItemDecoration(itemDivider));

    queueRecyclerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    if (isQueueVisible) {
        queueRecyclerView.animate().alpha(1).setDuration(0).withLayer();
        background.setImageAlpha(0);
    } else {
        queueRecyclerView.animate().alpha(0).setDuration(0).withLayer();
        background.setImageAlpha(255);
    }

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            elapsedTime.setText(DateUtils.formatElapsedTime(progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            isSeeking = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            musicController.seekTo(seekBar.getProgress() * 1000);
            isSeeking = false;
        }
    });

    return view;
}

From source file:org.jsampler.android.view.classic.MainFrame.java

private void uninstallListeners() {
    CC.preferences().removePropertyChangeListener(MAXIMUM_MASTER_VOLUME, getHandler());
    CC.getSamplerModel().removeSamplerListener(getHandler());
    CC.preferences().removePropertyChangeListener(VOL_MEASUREMENT_UNIT_DECIBEL, getHandler());

    ImageButton btn = (ImageButton) view.findViewById(R.id.classic_main_flip_back);
    btn.setOnClickListener(null);/*from   www.  j a  v  a 2  s  .c om*/

    btn = (ImageButton) view.findViewById(R.id.classic_main_flip_forward);
    btn.setOnClickListener(null);

    SeekBar sliderVolume = (SeekBar) view.findViewById(R.id.main_slider_volume);
    sliderVolume.setOnSeekBarChangeListener(null);
}