FileDocCategorySizeDatePackage
PresetReverbTest.javaAPI DocAndroid 5.1 API10619Thu Mar 12 22:22:30 GMT 2015com.android.effectstest

PresetReverbTest

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

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


      
        Log.d(TAG, "contructor");
    
Methods Summary
private voidgetEffect(int session)

        synchronized (sInstances) {
            if (sInstances.containsKey(session)) {
                mPresetReverb = sInstances.get(session);
            } else {
                try{
                    mPresetReverb = new PresetReverb(0, session);
                } catch (IllegalArgumentException e) {
                    Log.e(TAG,"PresetReverb effect not supported");
                } catch (UnsupportedOperationException e) {
                    Log.e(TAG,"PresetReverb library not loaded");
                } catch (RuntimeException e) {
                    Log.e(TAG,"PresetReverb effect not found");
                }
                sInstances.put(session, mPresetReverb);
            }
        }
        mReleaseButton.setEnabled(false);
        mOnOffButton.setEnabled(false);

        if (mPresetReverb != null) {
            if (mSettings != "") {
                mPresetReverb.setProperties(new PresetReverb.Settings(mSettings));
            }
            mPresetReverb.setEnableStatusListener(mEffectListener);
            mPresetReverb.setControlStatusListener(mEffectListener);
            mPresetReverb.setParameterListener(mEffectListener);

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

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


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


    
        
        super.onCreate(icicle);

        setContentView(R.layout.presetreverbtest);

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

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

        mReleaseButton = (ToggleButton)findViewById(R.id.presetrvbReleaseButton);
        mOnOffButton = (ToggleButton)findViewById(R.id.presetrvbOnOff);

        getEffect(sSession);

        if (mPresetReverb != null) {
            mReleaseButton.setOnCheckedChangeListener(this);
            mOnOffButton.setOnCheckedChangeListener(this);
            // Presets
            SeekBar seekBar = (SeekBar)findViewById(R.id.presetrvbParam1SeekBar);
            TextView textView = (TextView)findViewById(R.id.presetrvbParam1Value);
            mParameters[0] = new PresetParam(mPresetReverb, (short)0, (short)(sPresetNames.length - 1), seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[0]);
        }
    
public voidonPause()

        super.onPause();
    
public voidonResume()

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

        mOnOffButton.setChecked(false);
        mOnOffButton.setEnabled(false);
        synchronized (sInstances) {
            if (mPresetReverb != null) {
                mSettings = mPresetReverb.getProperties().toString();
                mPresetReverb.release();
                Log.d(TAG,"PresetReverb released");
                mPresetReverb = null;
                sInstances.remove(session);
            }
        }
    
protected voidupdateParams()

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