Search in sources :

Example 1 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project UltimateAndroid by cymcsg.

the class CropperSample method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.cropper_activity);
    // Sets fonts for all
    Typeface mFont = Typeface.createFromAsset(getAssets(), "Roboto-Thin.ttf");
    ViewGroup root = (ViewGroup) findViewById(R.id.mylayout);
    setFont(root, mFont);
    // Initialize components of the app
    final CropImageView cropImageView = (CropImageView) findViewById(R.id.CropImageView);
    final SeekBar aspectRatioXSeek = (SeekBar) findViewById(R.id.aspectRatioXSeek);
    final SeekBar aspectRatioYSeek = (SeekBar) findViewById(R.id.aspectRatioYSeek);
    final ToggleButton fixedAspectRatioToggle = (ToggleButton) findViewById(R.id.fixedAspectRatioToggle);
    Spinner showGuidelinesSpin = (Spinner) findViewById(R.id.showGuidelinesSpin);
    // Sets sliders to be disabled until fixedAspectRatio is set
    aspectRatioXSeek.setEnabled(false);
    aspectRatioYSeek.setEnabled(false);
    // Set initial spinner value
    showGuidelinesSpin.setSelection(ON_TOUCH);
    //Sets the rotate button
    final Button rotateButton = (Button) findViewById(R.id.Button_rotate);
    rotateButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            cropImageView.rotateImage(ROTATE_NINETY_DEGREES);
        }
    });
    // Sets fixedAspectRatio
    fixedAspectRatioToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            cropImageView.setFixedAspectRatio(isChecked);
            if (isChecked) {
                aspectRatioXSeek.setEnabled(true);
                aspectRatioYSeek.setEnabled(true);
            } else {
                aspectRatioXSeek.setEnabled(false);
                aspectRatioYSeek.setEnabled(false);
            }
        }
    });
    // Sets initial aspect ratio to 10/10, for demonstration purposes
    cropImageView.setAspectRatio(DEFAULT_ASPECT_RATIO_VALUES, DEFAULT_ASPECT_RATIO_VALUES);
    // Sets aspectRatioX
    final TextView aspectRatioX = (TextView) findViewById(R.id.aspectRatioX);
    aspectRatioXSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar aspectRatioXSeek, int progress, boolean fromUser) {
            try {
                mAspectRatioX = progress;
                cropImageView.setAspectRatio(progress, mAspectRatioY);
                aspectRatioX.setText(" " + progress);
            } catch (IllegalArgumentException e) {
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    // Sets aspectRatioY
    final TextView aspectRatioY = (TextView) findViewById(R.id.aspectRatioY);
    aspectRatioYSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar aspectRatioYSeek, int progress, boolean fromUser) {
            try {
                mAspectRatioY = progress;
                cropImageView.setAspectRatio(mAspectRatioX, progress);
                aspectRatioY.setText(" " + progress);
            } catch (IllegalArgumentException e) {
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    // Sets up the Spinner
    showGuidelinesSpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            cropImageView.setGuidelines(i);
        }

        public void onNothingSelected(AdapterView<?> adapterView) {
            return;
        }
    });
    final Button cropButton = (Button) findViewById(R.id.Button_crop);
    cropButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            croppedImage = cropImageView.getCroppedImage();
            ImageView croppedImageView = (ImageView) findViewById(R.id.croppedImageView);
            croppedImageView.setImageBitmap(croppedImage);
        }
    });
}
Also used : ToggleButton(android.widget.ToggleButton) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SeekBar(android.widget.SeekBar) Typeface(android.graphics.Typeface) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) ImageView(android.widget.ImageView) CropImageView(com.marshalchen.common.uimodule.cropperimage.CropImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) CropImageView(com.marshalchen.common.uimodule.cropperimage.CropImageView) CropImageView(com.marshalchen.common.uimodule.cropperimage.CropImageView) CompoundButton(android.widget.CompoundButton)

Example 2 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project Shuttle by timusus.

the class VideoCastControllerActivity method loadAndSetupViews.

private void loadAndSetupViews() {
    mPauseDrawable = getResources().getDrawable(R.drawable.ic_pause_circle_white_80dp);
    mPlayDrawable = getResources().getDrawable(R.drawable.ic_play_circle_white_80dp);
    mStopDrawable = getResources().getDrawable(R.drawable.ic_stop_circle_white_80dp);
    mPageView = findViewById(R.id.pageview);
    mPlayPause = (ImageButton) findViewById(R.id.play_pause_toggle);
    mLiveText = (TextView) findViewById(R.id.live_text);
    mStart = (TextView) findViewById(R.id.start_text);
    mEnd = (TextView) findViewById(R.id.end_text);
    mSeekbar = (SeekBar) findViewById(R.id.seekbar);
    mLine2 = (TextView) findViewById(R.id.textview2);
    mLoading = (ProgressBar) findViewById(R.id.progressbar1);
    mControllers = findViewById(R.id.controllers);
    mClosedCaptionIcon = (ImageButton) findViewById(R.id.cc);
    mSkipNext = (ImageButton) findViewById(R.id.next);
    mSkipPrevious = (ImageButton) findViewById(R.id.previous);
    mPlaybackControls = findViewById(R.id.playback_controls);
    ((MiniController) findViewById(R.id.miniController1)).setCurrentVisibility(false);
    setClosedCaptionState(CC_DISABLED);
    mPlayPause.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                mListener.onPlayPauseClicked(v);
            } catch (TransientNetworkDisconnectionException e) {
                LOGE(TAG, "Failed to toggle playback due to temporary network issue", e);
                Utils.showToast(VideoCastControllerActivity.this, R.string.ccl_failed_no_connection_trans);
            } catch (NoConnectionException e) {
                LOGE(TAG, "Failed to toggle playback due to network issues", e);
                Utils.showToast(VideoCastControllerActivity.this, R.string.ccl_failed_no_connection);
            } catch (Exception e) {
                LOGE(TAG, "Failed to toggle playback due to other issues", e);
                Utils.showToast(VideoCastControllerActivity.this, R.string.ccl_failed_perform_action);
            }
        }
    });
    mSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            try {
                if (mListener != null) {
                    mListener.onStopTrackingTouch(seekBar);
                }
            } catch (Exception e) {
                LOGE(TAG, "Failed to complete seek", e);
                finish();
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            try {
                if (mListener != null) {
                    mListener.onStartTrackingTouch(seekBar);
                }
            } catch (Exception e) {
                LOGE(TAG, "Failed to start seek", e);
                finish();
            }
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mStart.setText(Utils.formatMillis(progress));
            try {
                if (mListener != null) {
                    mListener.onProgressChanged(seekBar, progress, fromUser);
                }
            } catch (Exception e) {
                LOGE(TAG, "Failed to set the progress result", e);
            }
        }
    });
    mClosedCaptionIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                showTracksChooserDialog();
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "Failed to get the media", e);
            }
        }
    });
    mSkipNext.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                mListener.onSkipNextClicked(v);
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "Failed to move to the next item in the queue", e);
            }
        }
    });
    mSkipPrevious.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                mListener.onSkipPreviousClicked(v);
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "Failed to move to the previous item in the queue", e);
            }
        }
    });
}
Also used : SeekBar(android.widget.SeekBar) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) MiniController(com.google.android.libraries.cast.companionlibrary.widgets.MiniController) OnClickListener(android.view.View.OnClickListener) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)

Example 3 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project JamsMusicPlayer by psaravan.

the class SettingsActivity____ method onCreate.

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    //Context.
    mContext = this;
    mSettingsActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    //Initialize SharedPreferences.
    sharedPreferences = this.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);
    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        this.setTheme(R.style.AppThemeNoActionBar);
    } else {
        this.setTheme(R.style.AppThemeNoActionBarLight);
    }
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    preferenceManager = this.getPreferenceManager();
    //Retrieve the preferences based on their unique keys.
    upgradePreference = preferenceManager.findPreference("preference_key_upgrade");
    appThemePreference = preferenceManager.findPreference("preference_key_app_theme");
    playerColorSchemePreference = preferenceManager.findPreference("preference_key_player_color_scheme");
    trackChangeAnimationPreference = preferenceManager.findPreference("preference_key_track_change_animation");
    defaultScreenPreference = preferenceManager.findPreference("preference_key_startup_screen");
    artistsLayoutPreference = preferenceManager.findPreference("preference_key_artists_layout");
    albumArtistsLayoutPreference = preferenceManager.findPreference("preference_key_album_artists_layout");
    albumsLayoutPreference = preferenceManager.findPreference("preference_key_albums_layout");
    lockscreenControlsPreference = preferenceManager.findPreference("preference_key_lockscreen_controls");
    albumArtStylePreference = preferenceManager.findPreference("preference_key_album_art_style");
    albumArtSourcesPreference = preferenceManager.findPreference("preference_key_album_art_sources");
    albumArtScanDownloadPreference = preferenceManager.findPreference("preference_key_scan_download_album_art");
    chooseGooglePlayMusicAccountPreference = preferenceManager.findPreference("preference_key_google_play_music_account");
    getPinnedSongsPreference = preferenceManager.findPreference("preference_key_get_pinned_songs");
    defaultFolderPreference = preferenceManager.findPreference("preference_key_default_folder");
    addMusicLibraryPreference = preferenceManager.findPreference("preference_key_add_music_library");
    editMusicLibraryPreference = preferenceManager.findPreference("preference_key_edit_music_library");
    deleteMusicLibraryPreference = preferenceManager.findPreference("preference_key_delete_music_library");
    selectFoldersPreference = preferenceManager.findPreference("preference_key_select_folders");
    rescanFoldersPreference = preferenceManager.findPreference("preference_key_rescan_folders");
    scanFrequencyPreference = preferenceManager.findPreference("preference_key_scan_frequency");
    blacklistManagerPreference = preferenceManager.findPreference("preference_key_blacklist_manager");
    unblacklistAllPreference = preferenceManager.findPreference("preference_key_unblacklist_all");
    scrobblingPreference = preferenceManager.findPreference("preference_key_scrobbling");
    headphonesUnplugActionPreference = preferenceManager.findPreference("preference_key_headphones_unplug_action");
    crossfadeTracksPreference = preferenceManager.findPreference("preference_key_crossfade_tracks");
    crossfadeTracksDurationPreference = preferenceManager.findPreference("preference_key_crossfade_tracks_duration");
    equalizerPreference = preferenceManager.findPreference("preference_key_equalizer_toggle");
    licensesPreference = preferenceManager.findPreference("preference_key_licenses");
    contactUsPreference = preferenceManager.findPreference("preference_key_contact_us");
    //Set the preference icons.
    upgradePreference.setIcon(UIElementsHelper.getIcon(mContext, "checkmark"));
    appThemePreference.setIcon(UIElementsHelper.getIcon(mContext, "color_palette"));
    playerColorSchemePreference.setIcon(UIElementsHelper.getIcon(mContext, "color_palette_play"));
    trackChangeAnimationPreference.setIcon(UIElementsHelper.getIcon(mContext, "customize_screens"));
    defaultScreenPreference.setIcon(UIElementsHelper.getIcon(mContext, "default_screen"));
    artistsLayoutPreference.setIcon(UIElementsHelper.getIcon(mContext, "mic"));
    albumArtistsLayoutPreference.setIcon(UIElementsHelper.getIcon(mContext, "album_artists"));
    albumsLayoutPreference.setIcon(UIElementsHelper.getIcon(mContext, "albums"));
    lockscreenControlsPreference.setIcon(UIElementsHelper.getIcon(mContext, "lockscreen_controls"));
    getPinnedSongsPreference.setIcon(UIElementsHelper.getIcon(mContext, "pin_settings"));
    chooseGooglePlayMusicAccountPreference.setIcon(UIElementsHelper.getIcon(mContext, "accounts"));
    addMusicLibraryPreference.setIcon(UIElementsHelper.getIcon(mContext, "add_new_library"));
    editMusicLibraryPreference.setIcon(UIElementsHelper.getIcon(mContext, "edit_library"));
    deleteMusicLibraryPreference.setIcon(UIElementsHelper.getIcon(mContext, "delete_library"));
    albumArtStylePreference.setIcon(UIElementsHelper.getIcon(mContext, "cover_art_icon"));
    albumArtSourcesPreference.setIcon(UIElementsHelper.getIcon(mContext, "album_art_source"));
    albumArtScanDownloadPreference.setIcon(UIElementsHelper.getIcon(mContext, "auto_cover_fetch"));
    defaultFolderPreference.setIcon(UIElementsHelper.getIcon(mContext, "folders_settings"));
    selectFoldersPreference.setIcon(UIElementsHelper.getIcon(mContext, "folders_settings"));
    rescanFoldersPreference.setIcon(UIElementsHelper.getIcon(mContext, "rescan"));
    scanFrequencyPreference.setIcon(UIElementsHelper.getIcon(mContext, "scan_frequency"));
    blacklistManagerPreference.setIcon(UIElementsHelper.getIcon(mContext, "manage_blacklists"));
    unblacklistAllPreference.setIcon(UIElementsHelper.getIcon(mContext, "unblacklist_all"));
    scrobblingPreference.setIcon(UIElementsHelper.getIcon(mContext, "scrobbling"));
    headphonesUnplugActionPreference.setIcon(UIElementsHelper.getIcon(mContext, "headphones"));
    crossfadeTracksPreference.setIcon(UIElementsHelper.getIcon(mContext, "crossfade_tracks"));
    crossfadeTracksDurationPreference.setIcon(UIElementsHelper.getIcon(mContext, "crossfade_tracks_duration"));
    equalizerPreference.setIcon(UIElementsHelper.getIcon(mContext, "equalizer_settings"));
    licensesPreference.setIcon(UIElementsHelper.getIcon(mContext, "licenses"));
    contactUsPreference.setIcon(UIElementsHelper.getIcon(mContext, "contact_us"));
    if (sharedPreferences.getBoolean("TRIAL", true) == false) {
        PreferenceScreen screen = getPreferenceScreen();
        PreferenceCategory upgradePrefCategory = (PreferenceCategory) preferenceManager.findPreference("upgrade_pref_category");
        screen.removePreference(upgradePrefCategory);
    }
    upgradePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            //initInAppBilling();
            Intent intent = new Intent(mContext, com.jams.music.player.LauncherActivity.LauncherActivity.class);
            intent.putExtra("UPGRADE", true);
            startActivity(intent);
            finish();
            return false;
        }
    });
    //Set click listeners on each preference.
    appThemePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 0);
            startActivity(intent);
            return false;
        }
    });
    playerColorSchemePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 1);
            startActivity(intent);
            return false;
        }
    });
    trackChangeAnimationPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            int selectedIndex = sharedPreferences.getInt("TRACK_CHANGE_ANIMATION", 0);
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(R.string.track_change_animation);
            View layoutView = mSettingsActivity.getLayoutInflater().inflate(R.layout.generic_message_listview_dialog_layout, null);
            TextView message = (TextView) layoutView.findViewById(R.id.generic_message);
            ListView listView = (ListView) layoutView.findViewById(R.id.generic_listview);
            message.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
            message.setPaintFlags(message.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
            message.setText(R.string.track_change_animation_info);
            String[] values = { mSettingsActivity.getResources().getString(R.string.slide_away), mSettingsActivity.getResources().getString(R.string.zoom_out_and_slide_away), mSettingsActivity.getResources().getString(R.string.depth_transformer) };
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(mSettingsActivity, android.R.layout.simple_list_item_single_choice, android.R.id.text1, values);
            listView.setAdapter(adapter);
            listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            listView.setItemChecked(selectedIndex, true);
            listView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int which, long arg3) {
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                    sharedPreferences.edit().putInt("TRACK_CHANGE_ANIMATION", which).commit();
                    mTrackChangeAnimationDialog.dismiss();
                }
            });
            builder.setView(layoutView);
            mTrackChangeAnimationDialog = builder.create();
            mTrackChangeAnimationDialog.show();
            return false;
        }
    });
    defaultScreenPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            //Get the current preference.
            int currentPreference = sharedPreferences.getInt("STARTUP_SCREEN", 0);
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            //builder.setTitle(R.string.startup_screen);
            builder.setSingleChoiceItems(R.array.startup_screen_items, currentPreference, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    sharedPreferences.edit().putInt("STARTUP_SCREEN", which).commit();
                    dialog.dismiss();
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                }
            });
            builder.create().show();
            return false;
        }
    });
    artistsLayoutPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            //Get the current preference.
            int currentPreference = sharedPreferences.getInt("ARTISTS_LAYOUT_PREF", 0);
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(R.string.artists_layout);
            builder.setSingleChoiceItems(R.array.layout_preference_items, currentPreference, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    sharedPreferences.edit().putInt("ARTISTS_LAYOUT_PREF", which).commit();
                    dialog.dismiss();
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                }
            });
            builder.create().show();
            return false;
        }
    });
    albumArtistsLayoutPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            //Get the current preference.
            int currentPreference = sharedPreferences.getInt("ALBUM_ARTISTS_LAYOUT_PREF", 0);
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(R.string.album_artists_layout);
            builder.setSingleChoiceItems(R.array.layout_preference_items, currentPreference, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    sharedPreferences.edit().putInt("ALBUM_ARTISTS_LAYOUT_PREF", which).commit();
                    dialog.dismiss();
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                }
            });
            builder.create().show();
            return false;
        }
    });
    albumsLayoutPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            //Get the current preference.
            int currentPreference = sharedPreferences.getInt("ALBUMS_LAYOUT_PREF", 0);
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(R.string.albums_layout);
            builder.setSingleChoiceItems(R.array.layout_preference_items, currentPreference, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    sharedPreferences.edit().putInt("ALBUMS_LAYOUT_PREF", which).commit();
                    dialog.dismiss();
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                }
            });
            builder.create().show();
            return false;
        }
    });
    lockscreenControlsPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            //Get the current preference.
            int currentPreference = sharedPreferences.getInt(Common.SHOW_LOCKSCREEN_CONTROLS, 0);
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            //builder.setTitle(R.string.lockscreen_controls);
            builder.setSingleChoiceItems(R.array.enable_disable, currentPreference, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    sharedPreferences.edit().putInt(Common.SHOW_LOCKSCREEN_CONTROLS, which).commit();
                    dialog.dismiss();
                    //Enable/disable the lockscreen controls for this session.
                    try {
                        if (which == 0) {
                            Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                            if (sharedPreferences.getBoolean("SERVICE_RUNNING", false) == true) {
                                mApp.getService().initRemoteControlClient();
                                mApp.getService().updateRemoteControlClients(mApp.getService().getCurrentSong());
                            }
                        } else if (which == 1) {
                            if (sharedPreferences.getBoolean("SERVICE_RUNNING", false) == true) {
                                Toast.makeText(mContext, R.string.lockscreen_controls_disabled_next_run, Toast.LENGTH_LONG).show();
                            } else {
                                Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            builder.create().show();
            return false;
        }
    });
    defaultFolderPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(R.string.default_folder_for_folders_view);
            builder.setMessage(R.string.default_folder_for_folders_view_info);
            builder.setPositiveButton(R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.create().show();
            return false;
        }
    });
    chooseGooglePlayMusicAccountPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            final AccountManager accountManager = AccountManager.get(mContext);
            final Account[] accounts = accountManager.getAccounts();
            final int size = accounts.length;
            final String[] accountNames = new String[size + 1];
            accountNames[0] = "Don't use Google Play Music";
            //Create a new array with a list of all account names on the device.
            for (int i = 0; i < accounts.length; i++) {
                accountNames[i + 1] = accounts[i].name;
            }
            //Get the current account name (if it exists) and get the index of the account name.
            String currentAccountName = sharedPreferences.getString("GOOGLE_PLAY_MUSIC_ACCOUNT", "");
            int accountIndex = -1;
            if (!currentAccountName.isEmpty()) {
                for (int i = 0; i < accounts.length; i++) {
                    if (currentAccountName.equals(accountNames[i + 1])) {
                        accountIndex = i + 1;
                    }
                }
            } else {
                accountIndex = 0;
            }
            //Display a list of all accounts that are currently on the device.
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(R.string.select_google_account);
            builder.setSingleChoiceItems(accountNames, accountIndex, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int position) {
                    if (position != 0) {
                        //Start the sign-in process.
                        Toast.makeText(mContext, R.string.signing_in_dot_dot_dot, Toast.LENGTH_SHORT).show();
                        sharedPreferences.edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", accountNames[position]).commit();
                        AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext.getApplicationContext(), mSettingsActivity, false, accountNames[position]);
                        task.execute();
                    } else {
                        Toast.makeText(mContext, R.string.google_play_music_disabled, Toast.LENGTH_SHORT).show();
                        sharedPreferences.edit().putBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false).commit();
                        sharedPreferences.edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", "").commit();
                        //Restart the app.
                        final Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
                        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        finish();
                        startActivity(i);
                    }
                    dialog.dismiss();
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();
            return false;
        }
    });
    getPinnedSongsPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            mApp.queueSongsToPin(true, false, null);
            return false;
        }
    });
    addMusicLibraryPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 13);
            startActivity(intent);
            return false;
        }
    });
    editMusicLibraryPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 14);
            intent.putExtra("OPERATION", "EDIT");
            startActivity(intent);
            return false;
        }
    });
    deleteMusicLibraryPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 14);
            intent.putExtra("OPERATION", "DELETE");
            startActivity(intent);
            return false;
        }
    });
    albumArtStylePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 3);
            startActivity(intent);
            return false;
        }
    });
    albumArtSourcesPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 4);
            startActivity(intent);
            return false;
        }
    });
    albumArtScanDownloadPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            //Start the service that will download album art.
            mContext.startService(new Intent(mContext, AutoFetchAlbumArtService.class));
            return false;
        }
    });
    selectFoldersPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 5);
            startActivity(intent);
            return false;
        }
    });
    rescanFoldersPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            //Seting the "REBUILD_LIBRARY" flag to true will force MainActivity to rescan the folders.
            sharedPreferences.edit().putBoolean("REBUILD_LIBRARY", true).commit();
            //Restart the app.
            final Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            finish();
            startActivity(i);
            return false;
        }
    });
    scanFrequencyPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 7);
            startActivity(intent);
            return false;
        }
    });
    blacklistManagerPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            /*				Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
				intent.putExtra("INDEX", 8);
				startActivity(intent);*/
            /*String[] blacklistManagerChoices = { mContext.getResources().getString(R.string.manage_blacklisted_artists),
						 							 mContext.getResources().getString(R.string.manage_blacklisted_albums), 
						 							 mContext.getResources().getString(R.string.manage_blacklisted_songs), 
						 							 mContext.getResources().getString(R.string.manage_blacklisted_playlists) };
				
				AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

		        //Set the dialog title.
		        builder.setTitle(R.string.blacklist_manager);
		        builder.setItems(blacklistManagerChoices, new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						Bundle bundle = new Bundle();
						
						if (which==0) {
							bundle.putString("MANAGER_TYPE", "ARTISTS");
						} else if (which==1) {
							bundle.putString("MANAGER_TYPE", "ALBUMS");
						} else if (which==2) {
							bundle.putString("MANAGER_TYPE", "SONGS");
						} else if (which==3) {
							bundle.putString("MANAGER_TYPE", "PLAYLISTS");
						}
						
						dialog.dismiss();
						Intent intent = new Intent(mContext, BlacklistManagerActivity.class);
						intent.putExtras(bundle);
						startActivity(intent);
						
					}
		        	
		        });
		        
		        builder.create().show();*/
            Intent intent = new Intent(mContext, BlacklistManagerActivity.class);
            startActivity(intent);
            return false;
        }
    });
    unblacklistAllPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            AsyncUnblacklistAllSongsTask task = new AsyncUnblacklistAllSongsTask();
            task.execute();
            return false;
        }
    });
    /*    	bluetoothControlsPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

			@Override
			public boolean onPreferenceClick(Preference arg0) {
				// TODO Auto-generated method stub
				return false;
			}
    		
    	});
    	
    	headphonesUnplugActionPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

			@Override
			public boolean onPreferenceClick(Preference arg0) {
				// TODO Auto-generated method stub
				return false;
			}
    		
    	});*/
    scrobblingPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            int currentSelection = 0;
            if (sharedPreferences.getInt("SCROBBLING", 0) == 0) {
                currentSelection = 0;
            } else if (sharedPreferences.getInt("SCROBBLING", 0) == 1) {
                currentSelection = 1;
            } else if (sharedPreferences.getInt("SCROBBLING", 0) == 2) {
                currentSelection = 2;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(R.string.scrobbling);
            builder.setSingleChoiceItems(R.array.scrobbling_options, currentSelection, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                    sharedPreferences.edit().putInt("SCROBBLING", which).commit();
                }
            });
            builder.create().show();
            return false;
        }
    });
    headphonesUnplugActionPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            //Get the current selection.
            int currentSelection;
            if (sharedPreferences.getString("UNPLUG_ACTION", "DO_NOTHING").equals("DO_NOTHING")) {
                currentSelection = 0;
            } else {
                currentSelection = 1;
            }
            String[] unplugActionsArray = mContext.getResources().getStringArray(R.array.headphones_unplug_actions);
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(R.string.headphones_unplug_action);
            builder.setSingleChoiceItems(unplugActionsArray, currentSelection, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                    if (which == 0) {
                        sharedPreferences.edit().putString("UNPLUG_ACTION", "DO_NOTHING").commit();
                        if (sharedPreferences.getBoolean("SERVICE_RUNNING", false) == true) {
                            mApp.getService().unregisterReceiver(mApp.getService().getHeadsetPlugReceiver());
                        }
                    } else {
                        sharedPreferences.edit().putString("UNPLUG_ACTION", "PAUSE_MUSIC_PLAYBACK").commit();
                        if (sharedPreferences.getBoolean("SERVICE_RUNNING", false) == true) {
                            mApp.getService().registerHeadsetPlugReceiver();
                        }
                    }
                }
            });
            builder.create().show();
            return false;
        }
    });
    crossfadeTracksPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            int currentSelection;
            if (sharedPreferences.getBoolean(Common.CROSSFADE_ENABLED, false) == true) {
                currentSelection = 0;
            } else {
                currentSelection = 1;
            }
            String[] enableDisableArray = mContext.getResources().getStringArray(R.array.enable_disable);
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(R.string.crossfade_tracks);
            builder.setSingleChoiceItems(enableDisableArray, currentSelection, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                    if (which == 0) {
                        sharedPreferences.edit().putBoolean(Common.CROSSFADE_ENABLED, true).commit();
                        //Enable crossfade for the current queue.
                        if (mApp.isServiceRunning() && mApp.getService().getHandler() != null) {
                            mApp.getService().getHandler().post(mApp.getService().startCrossFadeRunnable);
                        }
                    } else {
                        sharedPreferences.edit().putBoolean(Common.CROSSFADE_ENABLED, false).commit();
                        //Disable crossfade for the current queue.
                        if (mApp.isServiceRunning() && mApp.getService().getHandler() != null) {
                            mApp.getService().getHandler().removeCallbacks(mApp.getService().startCrossFadeRunnable);
                            mApp.getService().getHandler().removeCallbacks(mApp.getService().crossFadeRunnable);
                        }
                    }
                }
            });
            builder.create().show();
            return false;
        }
    });
    crossfadeTracksDurationPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            AlertDialog.Builder builder = new AlertDialog.Builder(mSettingsActivity);
            builder.setTitle(R.string.crossfade_duration);
            RelativeLayout dialogView = (RelativeLayout) mSettingsActivity.getLayoutInflater().inflate(R.layout.dialog_crossfade_duration, null);
            final TextView durationText = (TextView) dialogView.findViewById(R.id.crossfade_duration_text);
            final SeekBar durationSeekBar = (SeekBar) dialogView.findViewById(R.id.crossfade_duration_seekbar);
            int currentSeekBarDuration = sharedPreferences.getInt(Common.CROSSFADE_DURATION, 5);
            durationSeekBar.setMax(14);
            durationSeekBar.setProgress(currentSeekBarDuration);
            durationText.setText(currentSeekBarDuration + " secs");
            durationSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    sharedPreferences.edit().putInt(Common.CROSSFADE_DURATION, (progress + 1)).commit();
                    durationText.setText((progress + 1) + " secs");
                }

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

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
                }
            });
            builder.setView(dialogView);
            builder.setPositiveButton(R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int arg1) {
                    dialog.dismiss();
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                }
            });
            builder.create().show();
            return false;
        }
    });
    equalizerPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            boolean currentSetting = sharedPreferences.getBoolean("EQUALIZER_ENABLED", true);
            int intCurrentSetting = -1;
            if (currentSetting == true)
                intCurrentSetting = 0;
            else
                intCurrentSetting = 1;
            AlertDialog.Builder builder = new AlertDialog.Builder(mSettingsActivity);
            builder.setTitle(R.string.equalizer);
            builder.setSingleChoiceItems(R.array.enable_disable, intCurrentSetting, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    boolean isEnabled;
                    if (which == 0)
                        isEnabled = true;
                    else
                        isEnabled = false;
                    sharedPreferences.edit().putBoolean("EQUALIZER_ENABLED", isEnabled).commit();
                    Toast.makeText(mContext, R.string.changes_saved, Toast.LENGTH_SHORT).show();
                    if (Build.PRODUCT.contains("HTC") && which == 0) {
                        showHTCEqualizerIssueDialog();
                    }
                    if (sharedPreferences.getBoolean("SERVICE_RUNNING", false) == true && which == 0) {
                        mApp.getService().initAudioFX();
                    } else if (sharedPreferences.getBoolean("SERVICE_RUNNING", false) == true && which == 1) {
                        try {
                            mApp.getService().getEqualizerHelper().releaseEQObjects();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    dialog.dismiss();
                }

                private void showHTCEqualizerIssueDialog() {
                    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                    builder.setTitle(R.string.htc_devices);
                    builder.setMessage(R.string.htc_devices_equalizer_issue);
                    builder.setPositiveButton(R.string.ok, new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
                    builder.create().show();
                }
            });
            builder.create().show();
            return false;
        }
    });
    licensesPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(mContext, PreferenceDialogLauncherActivity.class);
            intent.putExtra("INDEX", 12);
            startActivity(intent);
            return false;
        }
    });
    contactUsPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "jamsmusicplayer@gmail.com", null));
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Jams Music Player Support");
            startActivity(Intent.createChooser(emailIntent, "Send email"));
            return false;
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) PreferenceScreen(android.preference.PreferenceScreen) DialogInterface(android.content.DialogInterface) AsyncGoogleMusicAuthenticationTask(com.jams.music.player.AsyncTasks.AsyncGoogleMusicAuthenticationTask) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) ListView(android.widget.ListView) TextView(android.widget.TextView) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SeekBar(android.widget.SeekBar) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) Paint(android.graphics.Paint) BlacklistManagerActivity(com.jams.music.player.BlacklistManagerActivity.BlacklistManagerActivity) PreferenceCategory(android.preference.PreferenceCategory) Preference(android.preference.Preference) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.content.DialogInterface.OnClickListener) AdapterView(android.widget.AdapterView) AccountManager(android.accounts.AccountManager) ArrayAdapter(android.widget.ArrayAdapter)

Example 4 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project OpenCamera by ageback.

the class MainActivity method setManualWBSeekbar.

public void setManualWBSeekbar() {
    if (MyDebug.LOG)
        Log.d(TAG, "setManualWBSeekbar");
    if (preview.getSupportedWhiteBalances() != null && preview.supportsWhiteBalanceTemperature()) {
        if (MyDebug.LOG)
            Log.d(TAG, "set up manual white balance");
        SeekBar white_balance_seek_bar = ((SeekBar) findViewById(R.id.white_balance_seekbar));
        // clear an existing listener - don't want to call the listener when setting up the progress bar to match the existing state
        white_balance_seek_bar.setOnSeekBarChangeListener(null);
        final int minimum_temperature = preview.getMinimumWhiteBalanceTemperature();
        final int maximum_temperature = preview.getMaximumWhiteBalanceTemperature();
        // white balance should use linear scaling
        white_balance_seek_bar.setMax(maximum_temperature - minimum_temperature);
        white_balance_seek_bar.setProgress(preview.getCameraController().getWhiteBalanceTemperature() - minimum_temperature);
        white_balance_seek_bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (MyDebug.LOG)
                    Log.d(TAG, "white balance seekbar onProgressChanged: " + progress);
                int temperature = minimum_temperature + progress;
                preview.setWhiteBalanceTemperature(temperature);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
    }
}
Also used : SeekBar(android.widget.SeekBar) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) SuppressLint(android.annotation.SuppressLint)

Example 5 with OnSeekBarChangeListener

use of android.widget.SeekBar.OnSeekBarChangeListener in project OpenCamera by ageback.

the class MainActivity method cameraSetup.

void cameraSetup() {
    long debug_time = 0;
    if (MyDebug.LOG) {
        Log.d(TAG, "cameraSetup");
        debug_time = System.currentTimeMillis();
    }
    if (this.supportsForceVideo4K() && preview.usingCamera2API()) {
        if (MyDebug.LOG)
            Log.d(TAG, "using Camera2 API, so can disable the force 4K option");
        this.disableForceVideo4K();
    }
    if (this.supportsForceVideo4K() && preview.getVideoQualityHander().getSupportedVideoSizes() != null) {
        for (CameraController.Size size : preview.getVideoQualityHander().getSupportedVideoSizes()) {
            if (size.width >= 3840 && size.height >= 2160) {
                if (MyDebug.LOG)
                    Log.d(TAG, "camera natively supports 4K, so can disable the force option");
                this.disableForceVideo4K();
            }
        }
    }
    if (MyDebug.LOG)
        Log.d(TAG, "cameraSetup: time after handling Force 4K option: " + (System.currentTimeMillis() - debug_time));
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    {
        if (MyDebug.LOG)
            Log.d(TAG, "set up zoom");
        if (MyDebug.LOG)
            Log.d(TAG, "has_zoom? " + preview.supportsZoom());
        ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoom);
        SeekBar zoomSeekBar = (SeekBar) findViewById(R.id.zoom_seekbar);
        if (preview.supportsZoom()) {
            if (sharedPreferences.getBoolean(PreferenceKeys.ShowZoomControlsPreferenceKey, false)) {
                zoomControls.setIsZoomInEnabled(true);
                zoomControls.setIsZoomOutEnabled(true);
                zoomControls.setZoomSpeed(20);
                zoomControls.setOnZoomInClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                        zoomIn();
                    }
                });
                zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                        zoomOut();
                    }
                });
                if (!mainUI.inImmersiveMode()) {
                    zoomControls.setVisibility(View.VISIBLE);
                }
            } else {
                zoomControls.setVisibility(View.GONE);
            }
            // clear an existing listener - don't want to call the listener when setting up the progress bar to match the existing state
            zoomSeekBar.setOnSeekBarChangeListener(null);
            zoomSeekBar.setMax(preview.getMaxZoom());
            zoomSeekBar.setProgress(preview.getMaxZoom() - preview.getCameraController().getZoom());
            zoomSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "zoom onProgressChanged: " + progress);
                    // note we zoom even if !fromUser, as various other UI controls (multitouch, volume key zoom, -/+ zoomcontrol)
                    // indirectly set zoom via this method, from setting the zoom slider
                    preview.zoomTo(preview.getMaxZoom() - progress);
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
            if (sharedPreferences.getBoolean(PreferenceKeys.ShowZoomSliderControlsPreferenceKey, true)) {
                if (!mainUI.inImmersiveMode()) {
                    zoomSeekBar.setVisibility(View.VISIBLE);
                }
            } else {
                // should be INVISIBLE not GONE, as the focus_seekbar is aligned to be left to this
                zoomSeekBar.setVisibility(View.INVISIBLE);
            }
        } else {
            zoomControls.setVisibility(View.GONE);
            zoomSeekBar.setVisibility(View.GONE);
        }
        if (MyDebug.LOG)
            Log.d(TAG, "cameraSetup: time after setting up zoom: " + (System.currentTimeMillis() - debug_time));
        View takePhotoButton = findViewById(R.id.take_photo);
        if (sharedPreferences.getBoolean(PreferenceKeys.ShowTakePhotoPreferenceKey, true)) {
            if (!mainUI.inImmersiveMode()) {
                takePhotoButton.setVisibility(View.VISIBLE);
            }
        } else {
            takePhotoButton.setVisibility(View.INVISIBLE);
        }
    }
    {
        if (MyDebug.LOG)
            Log.d(TAG, "set up manual focus");
        SeekBar focusSeekBar = (SeekBar) findViewById(R.id.focus_seekbar);
        // clear an existing listener - don't want to call the listener when setting up the progress bar to match the existing state
        focusSeekBar.setOnSeekBarChangeListener(null);
        setProgressSeekbarScaled(focusSeekBar, 0.0, preview.getMinimumFocusDistance(), preview.getCameraController().getFocusDistance());
        focusSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                double frac = progress / (double) manual_n;
                double scaling = MainActivity.seekbarScaling(frac);
                float focus_distance = (float) (scaling * preview.getMinimumFocusDistance());
                preview.setFocusDistance(focus_distance);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        final int visibility = preview.getCurrentFocusValue() != null && this.getPreview().getCurrentFocusValue().equals("focus_mode_manual2") ? View.VISIBLE : View.GONE;
        focusSeekBar.setVisibility(visibility);
    }
    if (MyDebug.LOG)
        Log.d(TAG, "cameraSetup: time after setting up manual focus: " + (System.currentTimeMillis() - debug_time));
    {
        if (preview.supportsISORange()) {
            if (MyDebug.LOG)
                Log.d(TAG, "set up iso");
            SeekBar iso_seek_bar = ((SeekBar) findViewById(R.id.iso_seekbar));
            // clear an existing listener - don't want to call the listener when setting up the progress bar to match the existing state
            iso_seek_bar.setOnSeekBarChangeListener(null);
            setProgressSeekbarExponential(iso_seek_bar, preview.getMinimumISO(), preview.getMaximumISO(), preview.getCameraController().getISO());
            iso_seek_bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "iso seekbar onProgressChanged: " + progress);
                    double frac = progress / (double) manual_n;
                    if (MyDebug.LOG)
                        Log.d(TAG, "exposure_time frac: " + frac);
                    /*double scaling = MainActivity.seekbarScaling(frac);
						if( MyDebug.LOG )
							Log.d(TAG, "exposure_time scaling: " + scaling);
						int min_iso = preview.getMinimumISO();
						int max_iso = preview.getMaximumISO();
						int iso = min_iso + (int)(scaling * (max_iso - min_iso));*/
                    int min_iso = preview.getMinimumISO();
                    int max_iso = preview.getMaximumISO();
                    int iso = (int) exponentialScaling(frac, min_iso, max_iso);
                    preview.setISO(iso);
                    mainUI.updateSelectedISOButton();
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
            if (preview.supportsExposureTime()) {
                if (MyDebug.LOG)
                    Log.d(TAG, "set up exposure time");
                SeekBar exposure_time_seek_bar = ((SeekBar) findViewById(R.id.exposure_time_seekbar));
                // clear an existing listener - don't want to call the listener when setting up the progress bar to match the existing state
                exposure_time_seek_bar.setOnSeekBarChangeListener(null);
                setProgressSeekbarExponential(exposure_time_seek_bar, preview.getMinimumExposureTime(), preview.getMaximumExposureTime(), preview.getCameraController().getExposureTime());
                exposure_time_seek_bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        if (MyDebug.LOG)
                            Log.d(TAG, "exposure_time seekbar onProgressChanged: " + progress);
                        double frac = progress / (double) manual_n;
                        if (MyDebug.LOG)
                            Log.d(TAG, "exposure_time frac: " + frac);
                        // long exposure_time = min_exposure_time + (long)(frac * (max_exposure_time - min_exposure_time));
                        // double exposure_time_r = min_exposure_time_r + (frac * (max_exposure_time_r - min_exposure_time_r));
                        // long exposure_time = (long)(1.0 / exposure_time_r);
                        // we use the formula: [100^(percent/100) - 1]/99.0 rather than a simple linear scaling
                        /*double scaling = MainActivity.seekbarScaling(frac);
							if( MyDebug.LOG )
								Log.d(TAG, "exposure_time scaling: " + scaling);
							long min_exposure_time = preview.getMinimumExposureTime();
							long max_exposure_time = preview.getMaximumExposureTime();
							long exposure_time = min_exposure_time + (long)(scaling * (max_exposure_time - min_exposure_time));*/
                        long min_exposure_time = preview.getMinimumExposureTime();
                        long max_exposure_time = preview.getMaximumExposureTime();
                        long exposure_time = exponentialScaling(frac, min_exposure_time, max_exposure_time);
                        preview.setExposureTime(exposure_time);
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }
                });
            }
        }
    }
    setManualWBSeekbar();
    if (MyDebug.LOG)
        Log.d(TAG, "cameraSetup: time after setting up iso: " + (System.currentTimeMillis() - debug_time));
    {
        if (preview.supportsExposures()) {
            if (MyDebug.LOG)
                Log.d(TAG, "set up exposure compensation");
            final int min_exposure = preview.getMinimumExposure();
            SeekBar exposure_seek_bar = ((SeekBar) findViewById(R.id.exposure_seekbar));
            // clear an existing listener - don't want to call the listener when setting up the progress bar to match the existing state
            exposure_seek_bar.setOnSeekBarChangeListener(null);
            exposure_seek_bar.setMax(preview.getMaximumExposure() - min_exposure);
            exposure_seek_bar.setProgress(preview.getCurrentExposure() - min_exposure);
            exposure_seek_bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "exposure seekbar onProgressChanged: " + progress);
                    preview.setExposure(min_exposure + progress);
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
            ZoomControls seek_bar_zoom = (ZoomControls) findViewById(R.id.exposure_seekbar_zoom);
            seek_bar_zoom.setOnZoomInClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    changeExposure(1);
                }
            });
            seek_bar_zoom.setOnZoomOutClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    changeExposure(-1);
                }
            });
        }
    }
    if (MyDebug.LOG)
        Log.d(TAG, "cameraSetup: time after setting up exposure: " + (System.currentTimeMillis() - debug_time));
    View exposureButton = findViewById(R.id.exposure);
    exposureButton.setVisibility(supportsExposureButton() && !mainUI.inImmersiveMode() ? View.VISIBLE : View.GONE);
    ImageButton exposureLockButton = (ImageButton) findViewById(R.id.exposure_lock);
    exposureLockButton.setVisibility(preview.supportsExposureLock() && !mainUI.inImmersiveMode() ? View.VISIBLE : View.GONE);
    if (preview.supportsExposureLock()) {
        exposureLockButton.setImageResource(preview.isExposureLocked() ? R.drawable.exposure_locked : R.drawable.exposure_unlocked);
    }
    if (MyDebug.LOG)
        Log.d(TAG, "cameraSetup: time after setting exposure lock button: " + (System.currentTimeMillis() - debug_time));
    // needed so that the icon is set right even if no flash mode is set when starting up camera (e.g., switching to front camera with no flash)
    mainUI.setPopupIcon();
    if (MyDebug.LOG)
        Log.d(TAG, "cameraSetup: time after setting popup icon: " + (System.currentTimeMillis() - debug_time));
    mainUI.setTakePhotoIcon();
    mainUI.setSwitchCameraContentDescription();
    if (MyDebug.LOG)
        Log.d(TAG, "cameraSetup: time after setting take photo icon: " + (System.currentTimeMillis() - debug_time));
    if (!block_startup_toast) {
        this.showPhotoVideoToast(false);
    }
    block_startup_toast = false;
    if (MyDebug.LOG)
        Log.d(TAG, "cameraSetup: total time for cameraSetup: " + (System.currentTimeMillis() - debug_time));
}
Also used : ZoomControls(android.widget.ZoomControls) SeekBar(android.widget.SeekBar) CameraController(net.sourceforge.opencamera.CameraController.CameraController) SharedPreferences(android.content.SharedPreferences) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) View(android.view.View) SuppressLint(android.annotation.SuppressLint) ImageButton(android.widget.ImageButton)

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