Search in sources :

Example 21 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project AntennaPod by AntennaPod.

the class MediaplayerActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (controller == null) {
        return false;
    }
    Playable media = controller.getMedia();
    if (item.getItemId() == android.R.id.home) {
        Intent intent = new Intent(MediaplayerActivity.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return true;
    } else {
        if (media != null) {
            switch(item.getItemId()) {
                case R.id.add_to_favorites_item:
                    if (media instanceof FeedMedia) {
                        FeedItem feedItem = ((FeedMedia) media).getItem();
                        if (feedItem != null) {
                            DBWriter.addFavoriteItem(feedItem);
                            isFavorite = true;
                            invalidateOptionsMenu();
                            Toast.makeText(this, R.string.added_to_favorites, Toast.LENGTH_SHORT).show();
                        }
                    }
                    break;
                case R.id.remove_from_favorites_item:
                    if (media instanceof FeedMedia) {
                        FeedItem feedItem = ((FeedMedia) media).getItem();
                        if (feedItem != null) {
                            DBWriter.removeFavoriteItem(feedItem);
                            isFavorite = false;
                            invalidateOptionsMenu();
                            Toast.makeText(this, R.string.removed_from_favorites, Toast.LENGTH_SHORT).show();
                        }
                    }
                    break;
                case R.id.disable_sleeptimer_item:
                    if (controller.serviceAvailable()) {
                        MaterialDialog.Builder stDialog = new MaterialDialog.Builder(this);
                        stDialog.title(R.string.sleep_timer_label);
                        stDialog.content(getString(R.string.time_left_label) + Converter.getDurationStringLong((int) controller.getSleepTimerTimeLeft()));
                        stDialog.positiveText(R.string.disable_sleeptimer_label);
                        stDialog.negativeText(R.string.cancel_label);
                        stDialog.onPositive((dialog, which) -> {
                            dialog.dismiss();
                            controller.disableSleepTimer();
                        });
                        stDialog.onNegative((dialog, which) -> dialog.dismiss());
                        stDialog.build().show();
                    }
                    break;
                case R.id.set_sleeptimer_item:
                    if (controller.serviceAvailable()) {
                        SleepTimerDialog td = new SleepTimerDialog(this) {

                            @Override
                            public void onTimerSet(long millis, boolean shakeToReset, boolean vibrate) {
                                controller.setSleepTimer(millis, shakeToReset, vibrate);
                            }
                        };
                        td.createNewDialog().show();
                    }
                    break;
                case R.id.audio_controls:
                    MaterialDialog dialog = new MaterialDialog.Builder(this).title(R.string.audio_controls).customView(R.layout.audio_controls, true).neutralText(R.string.close_label).onNeutral((dialog1, which) -> {
                        final SeekBar left = (SeekBar) dialog1.findViewById(R.id.volume_left);
                        final SeekBar right = (SeekBar) dialog1.findViewById(R.id.volume_right);
                        UserPreferences.setVolume(left.getProgress(), right.getProgress());
                    }).show();
                    final SeekBar barPlaybackSpeed = (SeekBar) dialog.findViewById(R.id.playback_speed);
                    final Button butDecSpeed = (Button) dialog.findViewById(R.id.butDecSpeed);
                    butDecSpeed.setOnClickListener(v -> {
                        if (controller != null && controller.canSetPlaybackSpeed()) {
                            barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() - 2);
                        } else {
                            VariableSpeedDialog.showGetPluginDialog(this);
                        }
                    });
                    final Button butIncSpeed = (Button) dialog.findViewById(R.id.butIncSpeed);
                    butIncSpeed.setOnClickListener(v -> {
                        if (controller != null && controller.canSetPlaybackSpeed()) {
                            barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() + 2);
                        } else {
                            VariableSpeedDialog.showGetPluginDialog(this);
                        }
                    });
                    final TextView txtvPlaybackSpeed = (TextView) dialog.findViewById(R.id.txtvPlaybackSpeed);
                    float currentSpeed = 1.0f;
                    try {
                        currentSpeed = Float.parseFloat(UserPreferences.getPlaybackSpeed());
                    } catch (NumberFormatException e) {
                        Log.e(TAG, Log.getStackTraceString(e));
                        UserPreferences.setPlaybackSpeed(String.valueOf(currentSpeed));
                    }
                    txtvPlaybackSpeed.setText(String.format("%.2fx", currentSpeed));
                    barPlaybackSpeed.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                            if (controller != null && controller.canSetPlaybackSpeed()) {
                                float playbackSpeed = (progress + 10) / 20.0f;
                                controller.setPlaybackSpeed(playbackSpeed);
                                String speedPref = String.format(Locale.US, "%.2f", playbackSpeed);
                                UserPreferences.setPlaybackSpeed(speedPref);
                                String speedStr = String.format("%.2fx", playbackSpeed);
                                txtvPlaybackSpeed.setText(speedStr);
                            } else if (fromUser) {
                                float speed = Float.valueOf(UserPreferences.getPlaybackSpeed());
                                barPlaybackSpeed.post(() -> barPlaybackSpeed.setProgress((int) (20 * speed) - 10));
                            }
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {
                            if (controller != null && !controller.canSetPlaybackSpeed()) {
                                VariableSpeedDialog.showGetPluginDialog(MediaplayerActivity.this);
                            }
                        }

                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {
                        }
                    });
                    barPlaybackSpeed.setProgress((int) (20 * currentSpeed) - 10);
                    final SeekBar barLeftVolume = (SeekBar) dialog.findViewById(R.id.volume_left);
                    barLeftVolume.setProgress(UserPreferences.getLeftVolumePercentage());
                    final SeekBar barRightVolume = (SeekBar) dialog.findViewById(R.id.volume_right);
                    barRightVolume.setProgress(UserPreferences.getRightVolumePercentage());
                    final CheckBox stereoToMono = (CheckBox) dialog.findViewById(R.id.stereo_to_mono);
                    stereoToMono.setChecked(UserPreferences.stereoToMono());
                    if (controller != null && !controller.canDownmix()) {
                        stereoToMono.setEnabled(false);
                        String sonicOnly = getString(R.string.sonic_only);
                        stereoToMono.setText(stereoToMono.getText() + " [" + sonicOnly + "]");
                    }
                    barLeftVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                            controller.setVolume(Converter.getVolumeFromPercentage(progress), Converter.getVolumeFromPercentage(barRightVolume.getProgress()));
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {
                        }

                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {
                        }
                    });
                    barRightVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                            controller.setVolume(Converter.getVolumeFromPercentage(barLeftVolume.getProgress()), Converter.getVolumeFromPercentage(progress));
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {
                        }

                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {
                        }
                    });
                    stereoToMono.setOnCheckedChangeListener((buttonView, isChecked) -> {
                        UserPreferences.stereoToMono(isChecked);
                        if (controller != null) {
                            controller.setDownmix(isChecked);
                        }
                    });
                    break;
                case R.id.visit_website_item:
                    Uri uri = Uri.parse(media.getWebsiteLink());
                    startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    break;
                case R.id.support_item:
                    if (media instanceof FeedMedia) {
                        DBTasks.flattrItemIfLoggedIn(this, ((FeedMedia) media).getItem());
                    }
                    break;
                case R.id.share_link_item:
                    if (media instanceof FeedMedia) {
                        ShareUtils.shareFeedItemLink(this, ((FeedMedia) media).getItem());
                    }
                    break;
                case R.id.share_download_url_item:
                    if (media instanceof FeedMedia) {
                        ShareUtils.shareFeedItemDownloadLink(this, ((FeedMedia) media).getItem());
                    }
                    break;
                case R.id.share_link_with_position_item:
                    if (media instanceof FeedMedia) {
                        ShareUtils.shareFeedItemLink(this, ((FeedMedia) media).getItem(), true);
                    }
                    break;
                case R.id.share_download_url_with_position_item:
                    if (media instanceof FeedMedia) {
                        ShareUtils.shareFeedItemDownloadLink(this, ((FeedMedia) media).getItem(), true);
                    }
                    break;
                default:
                    return false;
            }
            return true;
        } else {
            return false;
        }
    }
}
Also used : Converter(de.danoeh.antennapod.core.util.Converter) PlaybackController(de.danoeh.antennapod.core.util.playback.PlaybackController) ImageButton(android.widget.ImageButton) Bundle(android.os.Bundle) SleepTimerDialog(de.danoeh.antennapod.dialog.SleepTimerDialog) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) PixelFormat(android.graphics.PixelFormat) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) Observable(rx.Observable) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) SeekBar(android.widget.SeekBar) CheckBox(android.widget.CheckBox) MenuInflater(android.view.MenuInflater) Locale(java.util.Locale) ShareUtils(de.danoeh.antennapod.core.util.ShareUtils) Toast(android.widget.Toast) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Button(android.widget.Button) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Playable(de.danoeh.antennapod.core.util.playback.Playable) Build(android.os.Build) TargetApi(android.annotation.TargetApi) Log(android.util.Log) MediaPlayerError(de.danoeh.antennapod.core.util.playback.MediaPlayerError) PlaybackService(de.danoeh.antennapod.core.service.playback.PlaybackService) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) R(de.danoeh.antennapod.R) VariableSpeedDialog(de.danoeh.antennapod.dialog.VariableSpeedDialog) Color(android.graphics.Color) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FontAwesomeIcons(com.joanzapata.iconify.fonts.FontAwesomeIcons) IconDrawable(com.joanzapata.iconify.IconDrawable) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) Flavors(de.danoeh.antennapod.core.util.Flavors) DBReader(de.danoeh.antennapod.core.storage.DBReader) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DBTasks(de.danoeh.antennapod.core.storage.DBTasks) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SeekBar(android.widget.SeekBar) Intent(android.content.Intent) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) Uri(android.net.Uri) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ImageButton(android.widget.ImageButton) Button(android.widget.Button) CheckBox(android.widget.CheckBox) SleepTimerDialog(de.danoeh.antennapod.dialog.SleepTimerDialog) TextView(android.widget.TextView)

Example 22 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project Lightning-Browser by anthonycr.

the class ReadingActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.invert_item:
            mPreferences.setInvertColors(!mInvert);
            Intent read = new Intent(this, ReadingActivity.class);
            read.putExtra(Constants.LOAD_READING_URL, mUrl);
            startActivity(read);
            finish();
            break;
        case R.id.text_size_item:
            View view = LayoutInflater.from(this).inflate(R.layout.dialog_seek_bar, null);
            final SeekBar bar = (SeekBar) view.findViewById(R.id.text_size_seekbar);
            bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar view, int size, boolean user) {
                    mBody.setTextSize(getTextSize(size));
                }

                @Override
                public void onStartTrackingTouch(SeekBar arg0) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar arg0) {
                }
            });
            bar.setMax(5);
            bar.setProgress(mTextSize);
            AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(view).setTitle(R.string.size).setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int arg1) {
                    mTextSize = bar.getProgress();
                    mBody.setTextSize(getTextSize(mTextSize));
                    mPreferences.setReadingTextSize(bar.getProgress());
                }
            });
            Dialog dialog = builder.show();
            BrowserDialog.setDialogSize(this, dialog);
            break;
        default:
            finish();
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) SeekBar(android.widget.SeekBar) DialogInterface(android.content.DialogInterface) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) ProgressDialog(android.app.ProgressDialog) AlertDialog(android.support.v7.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener) Intent(android.content.Intent) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView)

Example 23 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project Osmand by osmandapp.

the class OsmandMonitoringPlugin method createIntervalChooseLayout.

public static LinearLayout createIntervalChooseLayout(final Context uiCtx, final String patternMsg, final int[] seconds, final int[] minutes, final ValueHolder<Boolean> choice, final ValueHolder<Integer> v, final boolean showTrackSelection, DisplayMetrics dm) {
    LinearLayout ll = new LinearLayout(uiCtx);
    final int dp24 = AndroidUtils.dpToPx(uiCtx, 24f);
    final int dp8 = AndroidUtils.dpToPx(uiCtx, 8f);
    final TextView tv = new TextView(uiCtx);
    tv.setPadding(dp24, dp8 * 2, dp24, dp8);
    tv.setText(String.format(patternMsg, uiCtx.getString(R.string.int_continuosly)));
    SeekBar sp = new SeekBar(uiCtx);
    sp.setPadding(dp24 + dp8, dp8, dp24 + dp8, dp8);
    final int secondsLength = seconds.length;
    final int minutesLength = minutes.length;
    sp.setMax(secondsLength + minutesLength - 1);
    sp.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            String s;
            if (progress == 0) {
                s = uiCtx.getString(R.string.int_continuosly);
                v.value = 0;
            } else {
                if (progress < secondsLength) {
                    s = seconds[progress] + " " + uiCtx.getString(R.string.int_seconds);
                    v.value = seconds[progress] * 1000;
                } else {
                    s = minutes[progress - secondsLength] + " " + uiCtx.getString(R.string.int_min);
                    v.value = minutes[progress - secondsLength] * 60 * 1000;
                }
            }
            tv.setText(String.format(patternMsg, s));
        }
    });
    for (int i = 0; i < secondsLength + minutesLength - 1; i++) {
        if (i < secondsLength) {
            if (v.value <= seconds[i] * 1000) {
                sp.setProgress(i);
                break;
            }
        } else {
            if (v.value <= minutes[i - secondsLength] * 1000 * 60) {
                sp.setProgress(i);
                break;
            }
        }
    }
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(tv);
    ll.addView(sp);
    if (choice != null) {
        final CheckBox cb = new CheckBox(uiCtx);
        cb.setText(R.string.shared_string_remember_my_choice);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        lp.setMargins(dp24, dp8, dp24, 0);
        cb.setLayoutParams(lp);
        cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                choice.value = isChecked;
            }
        });
        ll.addView(cb);
    }
    if (showTrackSelection) {
        final OsmandApplication app = (OsmandApplication) uiCtx.getApplicationContext();
        boolean light = app.getSettings().isLightContent();
        View divider = new View(uiCtx);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(uiCtx, 1f));
        lp.setMargins(0, dp8 * 2, 0, 0);
        divider.setLayoutParams(lp);
        divider.setBackgroundColor(uiCtx.getResources().getColor(light ? R.color.dashboard_divider_light : R.color.dashboard_divider_dark));
        ll.addView(divider);
        final CheckBox cb = new CheckBox(uiCtx);
        cb.setText(R.string.shared_string_show_on_map);
        lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        lp.setMargins(dp24, dp8 * 2, dp24, 0);
        cb.setLayoutParams(lp);
        cb.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null);
        cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), isChecked, false);
            }
        });
        ll.addView(cb);
    }
    return ll;
}
Also used : LayoutParams(android.widget.LinearLayout.LayoutParams) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SeekBar(android.widget.SeekBar) OsmandApplication(net.osmand.plus.OsmandApplication) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) TextView(android.widget.TextView) LayoutParams(android.widget.LinearLayout.LayoutParams) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton)

Example 24 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project android_packages_apps_Snap by LineageOS.

the class TinyPlanetFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getDialog().setCanceledOnTouchOutside(true);
    View view = inflater.inflate(R.layout.tinyplanet_editor, container, false);
    mPreview = (TinyPlanetPreview) view.findViewById(R.id.preview);
    mPreview.setPreviewSizeChangeListener(this);
    // Zoom slider setup.
    SeekBar zoomSlider = (SeekBar) view.findViewById(R.id.zoomSlider);
    zoomSlider.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        // Do nothing.
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        // Do nothing.
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            onZoomChange(progress);
        }
    });
    // Rotation slider setup.
    SeekBar angleSlider = (SeekBar) view.findViewById(R.id.angleSlider);
    angleSlider.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        // Do nothing.
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        // Do nothing.
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            onAngleChange(progress);
        }
    });
    Button createButton = (Button) view.findViewById(R.id.creatTinyPlanetButton);
    createButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onCreateTinyPlanet();
        }
    });
    mOriginalTitle = getArguments().getString(ARGUMENT_TITLE);
    mSourceImageUri = Uri.parse(getArguments().getString(ARGUMENT_URI));
    mSourceBitmap = createPaddedSourceImage(mSourceImageUri, true);
    if (mSourceBitmap == null) {
        Log.e(TAG, "Could not decode source image.");
        dismiss();
    }
    return view;
}
Also used : SeekBar(android.widget.SeekBar) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) View(android.view.View) Point(android.graphics.Point)

Example 25 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project android_packages_apps_Snap by LineageOS.

the class DrawAutoHDR method UpdateManualFocusSettings.

private void UpdateManualFocusSettings() {
    // dismiss all popups first, because we need to show edit dialog
    mUI.collapseCameraControls();
    final AlertDialog.Builder alert = new AlertDialog.Builder(mActivity);
    LinearLayout linear = new LinearLayout(mActivity);
    linear.setOrientation(1);
    alert.setTitle("Manual Focus Settings");
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    final TextView focusPositionText = new TextView(mActivity);
    String scaleMode = mActivity.getString(R.string.pref_camera_manual_focus_value_scale_mode);
    String diopterMode = mActivity.getString(R.string.pref_camera_manual_focus_value_diopter_mode);
    String manualFocusMode = mPreferences.getString(CameraSettings.KEY_MANUAL_FOCUS, mActivity.getString(R.string.pref_camera_manual_focus_default));
    Log.v(TAG, "manualFocusMode selected = " + manualFocusMode);
    if (manualFocusMode.equals(scaleMode)) {
        final SeekBar focusbar = new SeekBar(mActivity);
        final int minFocusPos = mParameters.getInt(CameraSettings.KEY_MIN_FOCUS_SCALE);
        final int maxFocusPos = mParameters.getInt(CameraSettings.KEY_MAX_FOCUS_SCALE);
        // update mparameters to fetch latest focus position
        mParameters = mCameraDevice.getParameters();
        int CurFocusPos = minFocusPos;
        try {
            CurFocusPos = mParameters.getInt(CameraSettings.KEY_MANUAL_FOCUS_SCALE);
        } catch (NumberFormatException e) {
        // Do nothing
        }
        focusbar.setProgress(CurFocusPos);
        focusPositionText.setText("Current focus position is " + CurFocusPos);
        alert.setMessage("Enter focus position in the range of " + minFocusPos + " to " + maxFocusPos);
        focusbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                focusPositionText.setText("Current focus position is " + progress);
            }
        });
        linear.addView(focusbar);
        linear.addView(focusPositionText);
        alert.setView(linear);
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
                int focusPos = focusbar.getProgress();
                Log.v(TAG, "Setting focus position : " + focusPos);
                mManual3AEnabled |= MANUAL_FOCUS;
                mParameters.setFocusMode(ParametersWrapper.FOCUS_MODE_MANUAL_POSITION);
                // 2 for scale mode
                mParameters.set(CameraSettings.KEY_MANUAL_FOCUS_TYPE, 2);
                mParameters.set(CameraSettings.KEY_MANUAL_FOCUS_POSITION, focusPos);
                updateCommonManual3ASettings();
                onSharedPreferenceChanged();
            }
        });
        alert.show();
    } else if (manualFocusMode.equals(diopterMode)) {
        String minFocusStr = mParameters.get(CameraSettings.KEY_MIN_FOCUS_DIOPTER);
        String maxFocusStr = mParameters.get(CameraSettings.KEY_MAX_FOCUS_DIOPTER);
        final double minFocusPos = Double.parseDouble(minFocusStr);
        final double maxFocusPos = Double.parseDouble(maxFocusStr);
        final EditText input = new EditText(mActivity);
        int floatType = InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER;
        input.setInputType(floatType);
        alert.setMessage("Enter focus position in the range of " + minFocusPos + " to " + maxFocusPos);
        // update mparameters to fetch latest focus position
        mParameters = mCameraDevice.getParameters();
        final String CurFocusPos = mParameters.get(CameraSettings.KEY_MANUAL_FOCUS_DIOPTER);
        focusPositionText.setText("Current focus position is " + (CurFocusPos != null ? CurFocusPos : minFocusStr));
        linear.addView(input);
        linear.addView(focusPositionText);
        alert.setView(linear);
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
                double focuspos = 0;
                String focusStr = input.getText().toString();
                if (focusStr.length() > 0) {
                    try {
                        focuspos = Double.parseDouble(focusStr);
                    } catch (NumberFormatException e) {
                        Log.w(TAG, "Input foucspos " + focuspos + " is invalid");
                        focuspos = maxFocusPos + 1f;
                    }
                } else {
                    RotateTextToast.makeText(mActivity, "Invalid focus position", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (focuspos >= minFocusPos && focuspos <= maxFocusPos) {
                    Log.v(TAG, "Setting focus position : " + focusStr);
                    mManual3AEnabled |= MANUAL_FOCUS;
                    mParameters.setFocusMode(ParametersWrapper.FOCUS_MODE_MANUAL_POSITION);
                    // focus type 3 is diopter mode
                    mParameters.set(CameraSettings.KEY_MANUAL_FOCUS_TYPE, 3);
                    mParameters.set(CameraSettings.KEY_MANUAL_FOCUS_POSITION, focusStr);
                    updateCommonManual3ASettings();
                    onSharedPreferenceChanged();
                } else {
                    RotateTextToast.makeText(mActivity, "Invalid focus position", Toast.LENGTH_SHORT).show();
                }
            }
        });
        alert.show();
    } else {
        mManual3AEnabled &= ~MANUAL_FOCUS;
        mParameters.setFocusMode(mFocusManager.getFocusMode(false));
        mUI.overrideSettings(CameraSettings.KEY_FOCUS_MODE, null);
        updateCommonManual3ASettings();
        onSharedPreferenceChanged();
    }
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) DialogInterface(android.content.DialogInterface) NumberFormatException(java.lang.NumberFormatException) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) Paint(android.graphics.Paint) Point(android.graphics.Point) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

OnSeekBarChangeListener (android.widget.SeekBar.OnSeekBarChangeListener)34 SeekBar (android.widget.SeekBar)33 View (android.view.View)24 TextView (android.widget.TextView)18 OnClickListener (android.view.View.OnClickListener)13 Intent (android.content.Intent)9 CompoundButton (android.widget.CompoundButton)9 ImageView (android.widget.ImageView)8 AdapterView (android.widget.AdapterView)7 Button (android.widget.Button)6 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)6 SuppressLint (android.annotation.SuppressLint)5 Paint (android.graphics.Paint)5 LayoutInflater (android.view.LayoutInflater)5 DialogInterface (android.content.DialogInterface)4 CheckBox (android.widget.CheckBox)4 AlertDialog (android.app.AlertDialog)3 Dialog (android.app.Dialog)3 ProgressDialog (android.app.ProgressDialog)3 Point (android.graphics.Point)3