FileDocCategorySizeDatePackage
EqualizerTest.javaAPI DocAndroid 5.1 API15164Thu Mar 12 22:22:30 GMT 2015com.android.effectstest

EqualizerTest

public class EqualizerTest extends android.app.Activity implements android.widget.CompoundButton.OnCheckedChangeListener

Fields Summary
private static final String
TAG
private static int
NUM_BANDS
private static int
NUM_PARAMS
private EffectParameter[]
mParameters
private android.media.audiofx.Equalizer
mEqualizer
android.widget.ToggleButton
mOnOffButton
android.widget.ToggleButton
mReleaseButton
android.widget.EditText
mSessionText
static int
sSession
EffectListner
mEffectListener
private static HashMap
sInstances
String
mSettings
private View.OnKeyListener
mSessionKeyListener
Constructors Summary
public EqualizerTest()


      
        Log.d(TAG, "contructor");
    
Methods Summary
private voiddisplayFreq(int viewId, int freq)

        TextView textView = (TextView)findViewById(viewId);
        String text = Integer.toString(freq/1000)+" Hz";
        textView.setText(text);
    
private voidgetEffect(int session)

        synchronized (sInstances) {
            if (sInstances.containsKey(session)) {
                mEqualizer = sInstances.get(session);
            } else {
                try{
                    mEqualizer = new Equalizer(0, session);
                } catch (IllegalArgumentException e) {
                    Log.e(TAG,"Equalizer effect not supported");
                } catch (UnsupportedOperationException e) {
                    Log.e(TAG,"Equalizer library not loaded");
                } catch (IllegalStateException e) {
                    Log.e(TAG,"Equalizer cannot get presets");
                } catch (RuntimeException e) {
                    Log.e(TAG,"Equalizer effect not found");
                }
                sInstances.put(session, mEqualizer);
            }
        }
        mReleaseButton.setEnabled(false);
        mOnOffButton.setEnabled(false);
        if (mEqualizer != null) {
            if (mSettings != "") {
                Log.d(TAG,"Equalizer settings: "+mSettings);
                mEqualizer.setProperties(new Equalizer.Settings(mSettings));
            }

            mEqualizer.setEnableStatusListener(mEffectListener);
            mEqualizer.setControlStatusListener(mEffectListener);
            mEqualizer.setParameterListener(mEffectListener);

            mReleaseButton.setChecked(true);
            mReleaseButton.setEnabled(true);

            mOnOffButton.setChecked(mEqualizer.getEnabled());
            mOnOffButton.setEnabled(true);
        }
    
public voidonCheckedChanged(android.widget.CompoundButton buttonView, boolean isChecked)


    // OnCheckedChangeListener
          
        if (buttonView.getId() == R.id.equalizerOnOff) {
            if (mEqualizer != null) {
                mEqualizer.setEnabled(isChecked);
                updateBands();
            }
        }
        if (buttonView.getId() == R.id.eqReleaseButton) {
            if (isChecked) {
                if (mEqualizer == null) {
                    getEffect(sSession);
                    if (mEqualizer != null) {
                        for (int i = 0 ; i < mParameters.length; i++) {
                            mParameters[i].setEffect(mEqualizer);
                            mParameters[i].setEnabled(true);
                        }
                    }
                }
            } else {
                if (mEqualizer != null) {
                    for (int i = 0 ; i < mParameters.length; i++) {
                        mParameters[i].setEnabled(false);
                    }
                    putEffect(sSession);
                }
            }
        }
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        SeekBar seekBar;
        TextView textView;

        setContentView(R.layout.equalizertest);

        mSessionText = (EditText) findViewById(R.id.sessionEdit);
        mSessionText.setOnKeyListener(mSessionKeyListener);

        mSessionText.setText(Integer.toString(sSession));

        mReleaseButton = (ToggleButton)findViewById(R.id.eqReleaseButton);
        mOnOffButton = (ToggleButton)findViewById(R.id.equalizerOnOff);

        getEffect(sSession);

        if (mEqualizer != null) {
            mReleaseButton.setOnCheckedChangeListener(this);
            mOnOffButton.setOnCheckedChangeListener(this);

            short[] bandLevelRange = mEqualizer.getBandLevelRange();
            int centerFreq;
            int []freqRange;

            // Band 1 level
            centerFreq = mEqualizer.getCenterFreq((short)0);
            freqRange = mEqualizer.getBandFreqRange((short)0);
            displayFreq(R.id.eqParam1Center, centerFreq);
            displayFreq(R.id.eqParam1Min, freqRange[0]);
            displayFreq(R.id.eqParam1Max, freqRange[1]);
            seekBar = (SeekBar)findViewById(R.id.eqParam1SeekBar);
            textView = (TextView)findViewById(R.id.eqParam1Value);
            mParameters[0] = new BandLevelParam(mEqualizer, 0, bandLevelRange[0], bandLevelRange[1], seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[0]);

            // Band 2 level
            centerFreq = mEqualizer.getCenterFreq((short)1);
            freqRange = mEqualizer.getBandFreqRange((short)1);
            displayFreq(R.id.eqParam2Center, centerFreq);
            displayFreq(R.id.eqParam2Min, freqRange[0]);
            displayFreq(R.id.eqParam2Max, freqRange[1]);
            seekBar = (SeekBar)findViewById(R.id.eqParam2SeekBar);
            textView = (TextView)findViewById(R.id.eqParam2Value);
            mParameters[1] = new BandLevelParam(mEqualizer, 1, bandLevelRange[0], bandLevelRange[1], seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[1]);

            // Band 3 level
            centerFreq = mEqualizer.getCenterFreq((short)2);
            freqRange = mEqualizer.getBandFreqRange((short)2);
            displayFreq(R.id.eqParam3Center, centerFreq);
            displayFreq(R.id.eqParam3Min, freqRange[0]);
            displayFreq(R.id.eqParam3Max, freqRange[1]);
            seekBar = (SeekBar)findViewById(R.id.eqParam3SeekBar);
            textView = (TextView)findViewById(R.id.eqParam3Value);
            mParameters[2] = new BandLevelParam(mEqualizer, 2, bandLevelRange[0], bandLevelRange[1], seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[2]);

            // Band 4 level
            centerFreq = mEqualizer.getCenterFreq((short)3);
            freqRange = mEqualizer.getBandFreqRange((short)3);
            displayFreq(R.id.eqParam4Center, centerFreq);
            displayFreq(R.id.eqParam4Min, freqRange[0]);
            displayFreq(R.id.eqParam4Max, freqRange[1]);
            seekBar = (SeekBar)findViewById(R.id.eqParam4SeekBar);
            textView = (TextView)findViewById(R.id.eqParam4Value);
            mParameters[3] = new BandLevelParam(mEqualizer, 3, bandLevelRange[0], bandLevelRange[1], seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[3]);

            // Band 5 level
            centerFreq = mEqualizer.getCenterFreq((short)4);
            freqRange = mEqualizer.getBandFreqRange((short)4);
            displayFreq(R.id.eqParam5Center, centerFreq);
            displayFreq(R.id.eqParam5Min, freqRange[0]);
            displayFreq(R.id.eqParam5Max, freqRange[1]);
            seekBar = (SeekBar)findViewById(R.id.eqParam5SeekBar);
            textView = (TextView)findViewById(R.id.eqParam5Value);
            mParameters[4] = new BandLevelParam(mEqualizer, 4, bandLevelRange[0], bandLevelRange[1], seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[4]);

            // Presets
            short numPresets = mEqualizer.getNumberOfPresets();
            seekBar = (SeekBar)findViewById(R.id.eqParam6SeekBar);
            textView = (TextView)findViewById(R.id.eqParam6Value);
            mParameters[5] = new PresetParam(mEqualizer, (short)0, (short)(numPresets-1), seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[5]);
        }
    
public voidonPause()

        super.onPause();
    
public voidonResume()

        super.onResume();
    
private voidputEffect(int session)

//        mOnOffButton.setChecked(false);
        mOnOffButton.setEnabled(false);
        synchronized (sInstances) {
            if (mEqualizer != null) {
                mSettings = mEqualizer.getProperties().toString();
                mEqualizer.release();
                Log.d(TAG,"Equalizer released, settings: "+mSettings);
                mEqualizer = null;
                sInstances.remove(session);
            }
        }
    
protected voidupdateBands()

        for (int i = 0 ; i < NUM_BANDS; i++) {
            mParameters[i].updateDisplay();
        }