Example usage for android.widget SeekBar setMax

List of usage examples for android.widget SeekBar setMax

Introduction

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

Prototype

@Override
    public synchronized void setMax(int max) 

Source Link

Usage

From source file:org.musicmod.android.dialog.EqualizerDialog.java

private void setupEqualizerFxAndUI(int audioSessionId) {

    // Create the Equalizer object (an AudioEffect subclass) and attach it
    // to our media player, with a default priority (0).
    mEqualizer = new EqualizerWrapper(0, audioSessionId);
    if (mEqualizer == null) {
        finish();/*from  w w  w. j a v  a 2s  .c  o m*/
        return;
    }
    mEqualizer.setEnabled(false);

    short bands = mEqualizer.getNumberOfBands();

    final short minEQLevel = mEqualizer.getBandLevelRange()[0];
    final short maxEQLevel = mEqualizer.getBandLevelRange()[1];

    mLinearLayout.removeAllViews();

    for (short i = 0; i < bands; i++) {
        final short band = i;

        TextView freqTextView = new TextView(this);
        freqTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        freqTextView.setGravity(Gravity.CENTER_HORIZONTAL);

        if (mEqualizer.getCenterFreq(band) / 1000 < 1000) {
            freqTextView.setText((mEqualizer.getCenterFreq(band) / 1000) + " Hz");
        } else {
            freqTextView.setText(((float) mEqualizer.getCenterFreq(band) / 1000 / 1000) + " KHz");
        }

        mLinearLayout.addView(freqTextView);

        LinearLayout row = new LinearLayout(this);
        row.setOrientation(LinearLayout.HORIZONTAL);

        TextView minDbTextView = new TextView(this);
        minDbTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        minDbTextView.setText((minEQLevel / 100) + " dB");

        TextView maxDbTextView = new TextView(this);
        maxDbTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        maxDbTextView.setText((maxEQLevel / 100) + " dB");

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.weight = 1;
        SeekBar bar = new SeekBar(this);
        bar.setLayoutParams(layoutParams);
        bar.setMax(maxEQLevel - minEQLevel);
        bar.setProgress(mPrefs.getEqualizerSetting(band, (short) ((maxEQLevel + minEQLevel) / 2)) - minEQLevel);
        mEqualizer.setBandLevel(band,
                mPrefs.getEqualizerSetting(band, (short) ((maxEQLevel + minEQLevel) / 2)));

        bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                mEqualizer.setBandLevel(band, (short) (minEQLevel + progress));
                mPrefs.setEqualizerSetting(band, (short) (minEQLevel + progress));
                reloadEqualizer();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        row.addView(minDbTextView);
        row.addView(bar);
        row.addView(maxDbTextView);

        mLinearLayout.addView(row);
    }
}

From source file:com.saulcintero.moveon.fragments.Summary2.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContext = getActivity().getApplicationContext();

    prefs = PreferenceManager.getDefaultSharedPreferences(mContext);

    LinearLayout fragmentView = (LinearLayout) inflater.inflate(R.layout.summary2, container, false);
    summary2ListView = (ListView) fragmentView.findViewById(R.id.summary2_list_splitlaps);
    summary2ListView.setSelector(android.R.color.transparent);
    label1 = (TextView) fragmentView.findViewById(R.id.summary2_item_one);
    label2 = (TextView) fragmentView.findViewById(R.id.summary2_label_one);

    isMetric = FunctionUtils.checkIfUnitsAreMetric(mContext);

    unit = (isMetric ? 1000 : 1609);// w ww .  j a  v a 2s . c o  m

    label1.setText((isMetric ? getString(R.string.long_unit1_detail_1).toUpperCase(Locale.getDefault())
            : getString(R.string.long_unit2_detail_1).toUpperCase(Locale.getDefault())) + ".");
    label2.setText("1 " + (isMetric ? getString(R.string.long_unit1_detail_1).toUpperCase(Locale.getDefault())
            : getString(R.string.long_unit2_detail_1).toUpperCase(Locale.getDefault())) + ".");

    seekBar = (SeekBar) fragmentView.findViewById(R.id.summary2_slider);
    seekBar.setMax(49);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            splitData(progress * unit);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progr, boolean fromUser) {
            progress = progr + 1;

            label2.setText(String.valueOf(progress) + " "
                    + (isMetric ? getString(R.string.long_unit1_detail_1).toUpperCase(Locale.getDefault())
                            : getString(R.string.long_unit2_detail_1).toUpperCase(Locale.getDefault()))
                    + ".");
        }
    });

    return fragmentView;
}

From source file:org.ciasaboark.tacere.activity.SettingsActivity.java

private void drawAlarmWidgets() {
    TextView alarmTV = (TextView) findViewById(id.settings_alarmText);
    if (prefs.getIsServiceActivated()) {
        alarmTV.setTextColor(getResources().getColor(R.color.textcolor));
    } else {// ww w.j  a v  a 2s. c  o  m
        alarmTV.setTextColor(getResources().getColor(R.color.textColorDisabled));
    }

    //the alarm volumes toggle
    Switch alarmSwitch = (Switch) findViewById(id.adjustAlarmCheckBox);
    alarmSwitch.setChecked(prefs.getAdjustAlarm());
    alarmSwitch.setEnabled(prefs.getIsServiceActivated());
    findViewById(id.settings_alarmBox).setEnabled(prefs.getIsServiceActivated());

    //the alarm volumes slider
    SeekBar alarmSB = (SeekBar) findViewById(id.alarmSeekBar);
    alarmSB.setMax(VolumesManager.getMaxAlarmVolume());
    alarmSB.setProgress(prefs.getCurAlarmVolume());
    if (prefs.getAdjustAlarm() && prefs.getIsServiceActivated()) {
        this.animateRevealView(alarmSB);
        alarmSB.setEnabled(true);
    } else {
        alarmSB.setEnabled(false);
        this.animateHideView(alarmSB);
    }
    alarmSB.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            prefs.setCurAlarmVolume(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            //required stub
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            //required stub
        }
    });
}

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());//from   w  w w.j a  va2 s  . c  o  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:org.dpadgett.timer.WorldClockFragment.java

private void newClockDialog(final int position) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(context.getString(R.string.world_clock_select_timezone));
    final Map<String, String> timezoneNameToId = new HashMap<String, String>();
    final Set<Integer> timezones = new TreeSet<Integer>();
    final Map<Integer, List<String>> offsetToName = new HashMap<Integer, List<String>>();
    final long currentTime = System.currentTimeMillis();

    for (final String timezone : TimeZone.getAvailableIDs()) {
        final TimeZone tz = TimeZone.getTimeZone(timezone);
        final boolean isDaylight = tz.useDaylightTime();
        final String timezoneName = tz.getDisplayName(isDaylight, TimeZone.LONG, Locale.getDefault());
        if (timezoneNameToId.containsKey(timezoneName)) {
            continue;
        }//from   w  w w. j a  va  2s  . c  o m
        final int millisOffset = tz.getOffset(currentTime);
        timezones.add(millisOffset);
        if (!offsetToName.containsKey(millisOffset)) {
            offsetToName.put(millisOffset, new ArrayList<String>());
        }
        offsetToName.get(millisOffset).add(timezoneName);
        timezoneNameToId.put(timezoneName, timezone);
    }
    for (final List<String> names : offsetToName.values()) {
        Collections.sort(names);
    }
    if (position > -1) {
        builder.setPositiveButton(context.getString(R.string.world_clock_button_remove),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        clockList.remove(position);
                        clocksListAdapter.notifyDataSetChanged();

                        final SharedPreferences.Editor prefs = context
                                .getSharedPreferences("WorldClocks", Context.MODE_PRIVATE).edit();
                        prefs.putInt("numClocks", clockList.size());
                        int idx;
                        for (idx = position; idx < clockList.size(); idx++) {
                            prefs.putString("clock" + idx, clockList.get(idx));
                        }
                        prefs.remove("clock" + idx);
                        prefs.commit();
                    }
                });
    }
    final LinearLayout tzView = (LinearLayout) LayoutInflater.from(context)
            .inflate(R.layout.timezone_picker_dialog, (ViewGroup) finder.findViewById(R.id.layout_root));

    final List<String> initialItems = new ArrayList<String>();
    initialItems.add(context.getString(R.string.world_clock_timezone_gmt));
    initialItems.add(context.getString(R.string.world_clock_timezone_utc));
    final ArrayAdapter<String> adapter = ArrayAdapter.newArrayAdapter(context,
            R.layout.timezone_dialog_list_item, initialItems);
    final ListView timezoneList = (ListView) tzView.findViewById(R.id.timezoneList);
    timezoneList.setAdapter(adapter);

    final TextView sliderView = (TextView) tzView.findViewById(R.id.timezoneLabel);

    final SeekBar timezoneSeeker = (SeekBar) tzView.findViewById(R.id.timezoneSeeker);
    final List<Integer> timezonesList = new ArrayList<Integer>(timezones);
    timezoneSeeker.setMax(timezonesList.size() - 1);
    if (position > -1) {
        final int offset = TimeZone.getTimeZone(clockList.get(position)).getOffset(currentTime);
        timezoneSeeker.setProgress(timezonesList.indexOf(offset));
    } else {
        timezoneSeeker.setProgress(timezonesList.indexOf(0));
    }
    timezoneSeeker.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        // initialize the timezoneSeeker
        {
            onProgressChanged(timezoneSeeker, timezoneSeeker.getProgress(), false);
        }

        @Override
        public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
            adapter.clear();
            adapter.addAll(offsetToName.get(timezonesList.get(progress)));
            final int millisOffset = timezonesList.get(progress);
            String offset = String.format("%02d:%02d", Math.abs(millisOffset / 1000 / 60 / 60),
                    Math.abs(millisOffset / 1000 / 60) % 60);
            if (millisOffset / 1000 / 60 / 60 < 0) {
                offset = "-" + offset;
            } else {
                offset = "+" + offset;
            }
            sliderView.setText(context.getString(R.string.world_clock_timezone_label) + offset);
        }

        @Override
        public void onStartTrackingTouch(final SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(final SeekBar seekBar) {
        }
    });
    builder.setView(tzView);
    final AlertDialog alert = builder.create();

    timezoneList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int selectedPosition,
                final long id) {
            final String timezoneName = adapter.getItem(selectedPosition);
            final String timezone = timezoneNameToId.get(timezoneName);
            addNewClock(timezone, position);
            alert.dismiss();
        }
    });

    alert.show();
}

From source file:com.brewcrewfoo.performance.fragments.BatteryInfo.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.battery_info, root, false);

    mbattery_percent = (TextView) view.findViewById(R.id.batt_percent);
    mbattery_volt = (TextView) view.findViewById(R.id.batt_volt);
    mbattery_status = (TextView) view.findViewById(R.id.batt_status);
    mBattIcon = (ImageView) view.findViewById(R.id.batt_icon);

    if (new File(BAT_VOLT_PATH).exists()) {
        int volt = Integer.parseInt(Helpers.readOneLine(BAT_VOLT_PATH));
        if (volt > 5000)
            volt = (int) Math.round(volt / 1000.0);// in microvolts
        mbattery_volt.setText(volt + " mV");
        mBattIcon.setVisibility(ImageView.GONE);
        mbattery_volt.setVisibility(TextView.VISIBLE);
        mbattery_volt.setOnClickListener(new View.OnClickListener() {
            @Override/*w w w .  j  a v  a 2  s . co  m*/
            public void onClick(View view) {
                Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null)
                    startActivity(powerUsageIntent);
            }
        });
        mbattery_volt.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                mBattIcon.setVisibility(ImageView.VISIBLE);
                mbattery_volt.setVisibility(TextView.GONE);
                return true;
            }
        });
    } else {
        mBattIcon.setVisibility(ImageView.VISIBLE);
        mbattery_volt.setVisibility(TextView.GONE);
        mBattIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                    startActivity(powerUsageIntent);
                } catch (Exception e) {
                }
            }
        });
    }

    SeekBar mBlxSlider = (SeekBar) view.findViewById(R.id.blx_slider);
    if (new File(BLX_PATH).exists()) {
        no_settings = false;
        mBlxSlider.setMax(100);

        mBlxVal = (TextView) view.findViewById(R.id.blx_val);
        mBlxVal.setText(getString(R.string.blx_title) + " " + Helpers.readOneLine(BLX_PATH) + "%");

        mBlxSlider.setProgress(Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
        mBlxSlider.setOnSeekBarChangeListener(this);
        Switch mSetOnBoot = (Switch) view.findViewById(R.id.blx_sob);
        mSetOnBoot.setChecked(mPreferences.getBoolean(BLX_SOB, false));
        mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                final SharedPreferences.Editor editor = mPreferences.edit();
                editor.putBoolean(BLX_SOB, checked);
                if (checked) {
                    editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
                }
                editor.commit();
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.blx_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    mFastChargePath = Helpers.fastcharge_path();
    if (mFastChargePath != null) {
        no_settings = false;
        mFastchargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob);
        mFastchargeOnBoot.setChecked(
                mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.readOneLine(mFastChargePath).equals("1")));
        mFastchargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply();
                final NotificationManager nm = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                if (checked) {
                    new CMDProcessor().su.runWaitFor("busybox echo 1 > " + mFastChargePath);
                    Notification n = new Notification.Builder(context)
                            .setContentTitle(context.getText(R.string.app_name))
                            .setContentText(context.getText(R.string.fast_charge_notification_title))
                            .setTicker(context.getText(R.string.fast_charge_notification_title))
                            .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis())
                            .getNotification();
                    //n.flags = Notification.FLAG_NO_CLEAR;
                    nm.notify(1337, n);
                } else {
                    new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath);
                    nm.cancel(1337);
                }
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.fastcharge_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    if (no_settings) {
        LinearLayout ns = (LinearLayout) view.findViewById(R.id.no_settings);
        ns.setVisibility(LinearLayout.VISIBLE);
    }

    return view;
}

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

private void installListeners() {
    SeekBar sliderVolume = (SeekBar) view.findViewById(R.id.main_slider_volume);
    int i = CC.preferences().getIntProperty(MAXIMUM_MASTER_VOLUME);
    sliderVolume.setMax(i);
    CC.preferences().addPropertyChangeListener(MAXIMUM_MASTER_VOLUME, getHandler());

    sliderVolume.setOnSeekBarChangeListener(getHandler());

    CC.getSamplerModel().addSamplerListener(getHandler());

    CC.preferences().addPropertyChangeListener(VOL_MEASUREMENT_UNIT_DECIBEL, getHandler());

    ImageButton btn = (ImageButton) view.findViewById(R.id.classic_main_flip_back);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            panesFlipper.setInAnimation(AHF.inFromLeftAnimation());
            panesFlipper.setOutAnimation(AHF.outToRightAnimation());
            panesFlipper.showPrevious();
            updateMainTitle();//from  w w w .  j a v  a  2s.  c o m
        }
    });

    btn = (ImageButton) view.findViewById(R.id.classic_main_flip_forward);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            panesFlipper.setInAnimation(AHF.inFromRightAnimation());
            panesFlipper.setOutAnimation(AHF.outToLeftAnimation());
            panesFlipper.showNext();
            updateMainTitle();
        }
    });
}

From source file:com.racoon.ampdroid.views.CurrentPlaylistView.java

public void updateSongData() {
    mHandler = new Handler();
    mRunnable = new Runnable() {
        @Override//  w w  w  . ja v  a  2s.c om
        public void run() {
            Log.d("bugs", "Thread luft noch");
            final MainActivity main = (MainActivity) getActivity();
            if (main != null && main.getService() != null) {
                if (main.getService().isPlaying()) {
                    controller.setPlayingNow(main.getService().getCurrentSong());
                    songTitle.setText(main.getService().getCurrentSong().toString());
                    String artist = "Unknown";
                    if (controller.getPlayingNow().getArtist() != null) {
                        artist = controller.getPlayingNow().getArtist().toString();
                    }
                    songArtist.setText(artist);
                    togglePlayButton.setBackground(getResources().getDrawable(R.drawable.ic_action_pause));
                    int songDuration = main.getService().getMediaPlayer().getDuration() / 1000;
                    duration.setText(
                            String.format("%02d:%02d", (songDuration % 3600) / 60, (songDuration % 60)));
                    songDuration = main.getService().getMediaPlayer().getCurrentPosition() / 1000;
                    currentDuration.setText(
                            String.format("%02d:%02d", (songDuration % 3600) / 60, (songDuration % 60)));
                    int mCurrentPosition = main.getService().getMediaPlayer().getCurrentPosition();
                    seekBar.setMax(main.getService().getMediaPlayer().getDuration());
                    seekBar.setProgress(mCurrentPosition);
                    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {
                            main.getService().getMediaPlayer().seekTo(seekBar.getProgress());
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {

                        }

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                        }
                    });
                    mHandler.postDelayed(this, 1000);
                } else {
                    updateAttempts++;
                    Log.d("bugs", "attempt " + String.valueOf(updateAttempts));
                    if (updateAttempts >= 3) {
                        Log.d("bugs", "thread pause");
                        pauseView();
                        mHandler.removeCallbacks(mRunnable);
                    }
                }
            } else {
                Log.d("bugs", "service ist nicht vorhanden");
                cleanView();
                mHandler.removeCallbacks(mRunnable);
            }

        }
    };
    mHandler.post(mRunnable);
}

From source file:com.jaguarlandrover.hvacdemo.MainActivity.java

private void configureSeekBar(SeekBar seekBar) {
    seekBar.setMax(MAX_FAN_SPEED);
    seekBar.setOnSeekBarChangeListener(mFanSpeedSeekBarListener = new SeekBar.OnSeekBarChangeListener() {
        /* USER INTERFACE CALLBACK */
        @Override//ww w .  java2  s . c om
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            Log.d(TAG, Util.getMethodName());

            if (fromUser) {
                HVACManager.invokeService(getServiceIdentifiersFromViewId(seekBar.getId()),
                        Integer.toString(progress));

                if (progress == 0) {
                    setAirflowDirectionButtons(0);
                    HVACManager.invokeService(HVACServiceIdentifier.AIRFLOW_DIRECTION.value(),
                            Integer.toString(0));
                }
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}

From source file:mx.klozz.xperience.tweaker.fragments.Advanced.java

public void openDialog(String title, final int min, final int max, final Preference pref, final String path,
        final String key) {
    Resources res = context.getResources();
    String cancel = res.getString(R.string.cancel);
    String ok = res.getString(R.string.ok);
    final EditText settingText;
    LayoutInflater factory = LayoutInflater.from(context);
    final View alphaDialog = factory.inflate(R.layout.seekbar_dialog, null);

    final SeekBar seekbar = (SeekBar) alphaDialog.findViewById(R.id.seek_bar);
    seekbar.setMax(max - min);

    int currentProgress = min;
    if (key.equals("pref_viber")) {
        currentProgress = Integer.parseInt(Helpers.LeerUnaLinea(path));
    } else {//from   w  w w.  ja va2 s.co  m
        currentProgress = Integer.parseInt(vib.get_val(path));
    }
    if (currentProgress > max)
        currentProgress = max - min;
    else if (currentProgress < min)
        currentProgress = 0;
    else
        currentProgress = currentProgress - min;

    seekbar.setProgress(currentProgress);

    settingText = (EditText) alphaDialog.findViewById(R.id.setting_text);
    settingText.setText(Integer.toString(currentProgress + min));

    settingText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                int val = Integer.parseInt(settingText.getText().toString()) - min;
                seekbar.setProgress(val);
                return true;
            }
            return false;
        }
    });

    settingText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                int val = Integer.parseInt(s.toString());
                if (val > max) {
                    s.replace(0, s.length(), Integer.toString(max));
                    val = max;
                }
                seekbar.setProgress(val - min);
            } catch (NumberFormatException ex) {
            }
        }
    });

    OnSeekBarChangeListener seekBarChangeListener = new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
            final int mSeekbarProgress = seekbar.getProgress();
            if (fromUser) {
                settingText.setText(Integer.toString(mSeekbarProgress + min));
            }
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekbar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekbar) {
        }
    };
    seekbar.setOnSeekBarChangeListener(seekBarChangeListener);

    new AlertDialog.Builder(context).setTitle(title).setView(alphaDialog)
            .setNegativeButton(cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // nothing
                }
            }).setPositiveButton(ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int val = min;
                    if (!settingText.getText().toString().equals(""))
                        val = Integer.parseInt(settingText.getText().toString());
                    if (val < min)
                        val = min;
                    seekbar.setProgress(val - min);
                    int newProgress = seekbar.getProgress() + min;
                    new CMDProcessor().su
                            .runWaitFor("busybox echo " + Integer.toString(newProgress) + " > " + path);
                    String v;
                    if (key.equals("pref_viber")) {
                        v = vib.get_val(path);
                        Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                        vb.vibrate(1000);
                    } else {
                        v = Helpers.LeerUnaLinea(path);
                    }
                    final SharedPreferences.Editor editor = mPreferences.edit();
                    editor.putInt(key, Integer.parseInt(v)).commit();
                    pref.setSummary(v);

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