Search in sources :

Example 1 with SizableSeekBar

use of com.simplecity.amp_library.ui.views.SizableSeekBar in project Shuttle by timusus.

the class EqualizerActivity method onCreate.

@SuppressLint("InlinedApi")
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onCreate(Bundle savedInstanceState) {
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    ThemeUtils.setTheme(this);
    if (!ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        mTintManager = new SystemBarTintManager(this);
    }
    if (!ShuttleUtils.hasKitKat()) {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }
    if (SettingsManager.getInstance().canTintNavBar()) {
        getWindow().setNavigationBarColor(ColorUtils.getPrimaryColorDark(this));
    }
    super.onCreate(savedInstanceState);
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    setContentView(R.layout.activity_equalizer);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ThemeUtils.themeActionBar(this);
    ThemeUtils.themeStatusBar(this, mTintManager);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle(getResources().getString(R.string.equalizer));
    try {
        //Query available effects
        final AudioEffect.Descriptor[] effects = AudioEffect.queryEffects();
        //Determine available/supported effects
        if (effects != null && effects.length != 0) {
            for (final AudioEffect.Descriptor effect : effects) {
                //Equalizer
                if (effect.type.equals(UUID.fromString(EFFECT_TYPE_EQUALIZER))) {
                    mEqualizerSupported = true;
                } else if (effect.type.equals(UUID.fromString(EFFECT_TYPE_BASS_BOOST))) {
                    mBassBoostSupported = true;
                } else if (effect.type.equals(UUID.fromString(EFFECT_TYPE_VIRTUALIZER))) {
                    mVirtualizerSupported = true;
                }
            }
        }
    } catch (NoClassDefFoundError ignored) {
    //The user doesn't have the AudioEffect/AudioEffect.Descriptor class. How sad.
    }
    mSpinner = (Spinner) findViewById(R.id.eqSpinner);
    mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mEqPreset = position;
            equalizerSetPreset(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    setupPresets();
    if (mSpinnerAdapter != null && mSpinnerAdapter.getCount() > mEqPreset) {
        mSpinner.setSelection(mEqPreset);
    }
    //Initialize the equalizer elements
    View eqContainer = findViewById(R.id.eqContainer);
    mNumberEqualizerBands = Integer.parseInt(mPrefs.getString("equalizer.number_of_bands", "5"));
    final int[] centerFreqs = getCenterFreqs();
    final int[] bandLevelRange = getBandLevelRange();
    for (int band = 0; band < mNumberEqualizerBands; band++) {
        //Unit conversion from mHz to Hz and use k prefix if necessary to display
        float centerFreqHz = centerFreqs[band] / 1000;
        String unitPrefix = "";
        if (centerFreqHz >= 1000) {
            centerFreqHz = centerFreqHz / 1000;
            unitPrefix = "k";
        }
        (eqContainer.findViewById(eqViewElementIds[band][0])).setVisibility(View.VISIBLE);
        (eqContainer.findViewById(eqViewTextElementIds[band][0])).setVisibility(View.VISIBLE);
        (eqContainer.findViewById(eqViewElementIds[band][1])).setVisibility(View.VISIBLE);
        (eqContainer.findViewById(eqViewTextElementIds[band][1])).setVisibility(View.VISIBLE);
        ((TextView) eqContainer.findViewById(eqViewElementIds[band][0])).setText(format("%.0f ", centerFreqHz) + unitPrefix + "Hz");
        mEqualizerSeekBar[band] = (SizableSeekBar) eqContainer.findViewById(eqViewElementIds[band][1]);
        ThemeUtils.themeSeekBar(this, mEqualizerSeekBar[band]);
        mEqualizerSeekBar[band].setMax((bandLevelRange[1] / 100) - (bandLevelRange[0] / 100));
        mEqualizerSeekBar[band].setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                if (fromUser) {
                    //Determine which band changed
                    int seekbarId = seekBar.getId();
                    int band = 0;
                    for (int i = 0; i < eqViewElementIds.length; i++) {
                        if (eqViewElementIds[i][1] == seekbarId) {
                            band = i;
                        }
                    }
                    if (mEqPreset != mEqCustomPresetPosition) {
                        equalizerCopyToCustom();
                        if (mSpinnerAdapter != null && mSpinnerAdapter.getCount() > mEqCustomPresetPosition) {
                            mSpinner.setSelection(mEqCustomPresetPosition);
                        }
                    } else {
                        int level = getBandLevelRange()[0] + (progress * 100);
                        equalizerBandUpdate(band, level);
                    }
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
            }
        });
    }
    // Set the SeekBar listener.
    if (mBassBoostSupported) {
        final SizableSeekBar seekbar = (SizableSeekBar) findViewById(R.id.bb_strength);
        ThemeUtils.themeSeekBar(this, seekbar);
        seekbar.setMax(OpenSLESConstants.BASSBOOST_MAX_STRENGTH - OpenSLESConstants.BASSBOOST_MIN_STRENGTH);
        seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                // set parameter and state
                if (fromUser) {
                    mPrefs.edit().putBoolean("audiofx.bass.enable", true).apply();
                    mPrefs.edit().putString("audiofx.bass.strength", String.valueOf(progress)).apply();
                    mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
                }
            }

            // If slider pos was 0 when starting re-enable effect
            @Override
            public void onStartTrackingTouch(final SeekBar seekBar) {
                if (seekBar.getProgress() == 0) {
                    mPrefs.edit().putBoolean("audiofx.bass.enable", true).apply();
                    mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
                }
            }

            // If slider pos = 0 when stopping disable effect
            @Override
            public void onStopTrackingTouch(final SeekBar seekBar) {
                if (seekBar.getProgress() == 0) {
                    // disable
                    mPrefs.edit().putBoolean("audiofx.bass.enable", false).apply();
                    mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
                }
            }
        });
    }
    // Set the SeekBar listener.
    if (mVirtualizerSupported) {
        final SizableSeekBar seekbar = (SizableSeekBar) findViewById(R.id.virtualizer_strength);
        ThemeUtils.themeSeekBar(this, seekbar);
        seekbar.setMax(OpenSLESConstants.VIRTUALIZER_MAX_STRENGTH - OpenSLESConstants.VIRTUALIZER_MIN_STRENGTH);
        seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                // set parameter and state
                if (fromUser) {
                    mPrefs.edit().putBoolean("audiofx.virtualizer.enable", true).apply();
                    mPrefs.edit().putString("audiofx.virtualizer.strength", String.valueOf(progress)).apply();
                    mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
                }
            }

            // If slider pos was 0 when starting re-enable effect
            @Override
            public void onStartTrackingTouch(final SeekBar seekBar) {
                if (seekBar.getProgress() == 0) {
                    mPrefs.edit().putBoolean("audiofx.virtualizer.enable", true).apply();
                    mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
                }
            }

            // If slider pos = 0 when stopping disable effect
            @Override
            public void onStopTrackingTouch(final SeekBar seekBar) {
                if (seekBar.getProgress() == 0) {
                    // disable
                    mPrefs.edit().putBoolean("audiofx.virtualizer.enable", false).apply();
                    mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
                }
            }
        });
    }
}
Also used : SizableSeekBar(com.simplecity.amp_library.ui.views.SizableSeekBar) SeekBar(android.widget.SeekBar) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) SizableSeekBar(com.simplecity.amp_library.ui.views.SizableSeekBar) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) AudioEffect(android.media.audiofx.AudioEffect) SuppressLint(android.annotation.SuppressLint) TargetApi(android.annotation.TargetApi)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 AudioEffect (android.media.audiofx.AudioEffect)1 ActionBar (android.support.v7.app.ActionBar)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 SystemBarTintManager (com.readystatesoftware.systembartint.SystemBarTintManager)1 SizableSeekBar (com.simplecity.amp_library.ui.views.SizableSeekBar)1