FileDocCategorySizeDatePackage
VirtualizerTest.javaAPI DocAndroid 5.1 API9721Thu Mar 12 22:22:30 GMT 2015com.android.effectstest

VirtualizerTest

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

Fields Summary
private static final String
TAG
private static int
NUM_PARAMS
private EffectParameter
mStrength
private android.media.audiofx.Virtualizer
mVirtualizer
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 VirtualizerTest()


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

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

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

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

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


    // OnCheckedChangeListener
          
        if (buttonView.getId() == R.id.virtualizerOnOff) {
            if (mVirtualizer != null) {
                mVirtualizer.setEnabled(isChecked);
                mStrength.updateDisplay();
            }
        }
        if (buttonView.getId() == R.id.virtReleaseButton) {
            if (isChecked) {
                if (mVirtualizer == null) {
                    getEffect(sSession);
                    if (mVirtualizer != null) {
                        mStrength.setEffect(mVirtualizer);
                        mStrength.setEnabled(mVirtualizer.getStrengthSupported());
                    }
                }
            } else {
                if (mVirtualizer != null) {
                    mStrength.setEnabled(false);
                    putEffect(sSession);
                }
            }
        }
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        SeekBar seekBar;
        TextView textView;

        setContentView(R.layout.virtualizertest);

        mSessionText = (EditText) findViewById(R.id.sessionEdit);
        mSessionText.setOnKeyListener(mSessionKeyListener);
        mSessionText.setText(Integer.toString(sSession));

        mReleaseButton = (ToggleButton)findViewById(R.id.virtReleaseButton);
        mOnOffButton = (ToggleButton)findViewById(R.id.virtualizerOnOff);

        getEffect(sSession);

        if (mVirtualizer != null) {
            mReleaseButton.setOnCheckedChangeListener(this);
            mOnOffButton.setOnCheckedChangeListener(this);
            textView = (TextView)findViewById(R.id.virtStrengthMin);
            textView.setText("0");
            textView = (TextView)findViewById(R.id.virtStrengthMax);
            textView.setText("1000");
            seekBar = (SeekBar)findViewById(R.id.virtStrengthSeekBar);
            textView = (TextView)findViewById(R.id.virtStrengthValue);
            mStrength = new VirtualizerParam(mVirtualizer, 0, 1000, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mStrength);
            mStrength.setEnabled(mVirtualizer.getStrengthSupported());
        }
    
public voidonPause()

        super.onPause();
    
public voidonResume()

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

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