FileDocCategorySizeDatePackage
VisualizerTest.javaAPI DocAndroid 5.1 API10733Thu Mar 12 22:22:30 GMT 2015com.android.effectstest

VisualizerTest

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

Fields Summary
private static final String
TAG
private android.media.audiofx.Visualizer
mVisualizer
android.widget.ToggleButton
mOnOffButton
android.widget.ToggleButton
mReleaseButton
boolean
mEnabled
android.widget.EditText
mSessionText
static int
sSession
int
mCaptureSize
android.widget.ToggleButton
mCallbackButton
boolean
mCallbackOn
VisualizerListener
mVisualizerListener
private static HashMap
sInstances
private VisualizerTestHandler
mVisualizerTestHandler
private static final int
MSG_START_CAPTURE
private static final int
MSG_STOP_CAPTURE
private static final int
MSG_NEW_CAPTURE
private static final int
CAPTURE_PERIOD_MS
private View.OnKeyListener
mSessionKeyListener
Constructors Summary
public VisualizerTest()


      
        Log.d(TAG, "contructor");
    
Methods Summary
private voiddisplayVal(int viewId, int val)

        TextView textView = (TextView)findViewById(viewId);
        String text = Integer.toString(val);
        textView.setText(text);
    
private voidgetEffect(int session)

        synchronized (sInstances) {
            if (sInstances.containsKey(session)) {
                mVisualizer = sInstances.get(session);
            } else {
                try{
                    mVisualizer = new Visualizer(session);
                } catch (UnsupportedOperationException e) {
                    Log.e(TAG,"Visualizer library not loaded");
                    throw (new RuntimeException("Cannot initialize effect"));
                } catch (RuntimeException e) {
                    throw e;
                }
                sInstances.put(session, mVisualizer);
            }
        }
        mReleaseButton.setEnabled(false);
        mOnOffButton.setEnabled(false);
        if (mVisualizer != null) {
            mCaptureSize = mVisualizer.getCaptureSize();

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

            mEnabled = mVisualizer.getEnabled();
            mOnOffButton.setChecked(mEnabled);
            mOnOffButton.setEnabled(true);

            mCallbackButton.setEnabled(!mEnabled);
        }
    
public voidonCheckedChanged(android.widget.CompoundButton buttonView, boolean isChecked)


    // OnCheckedChangeListener
          
        if (buttonView.getId() == R.id.visualizerOnOff) {
            if (mVisualizer != null) {
                mEnabled = isChecked;
                mCallbackButton.setEnabled(!mEnabled);
                if (mCallbackOn && mEnabled) {
                    mVisualizer.setDataCaptureListener(mVisualizerListener,
                            10000,
                            true,
                            true);
                }
                mVisualizer.setEnabled(mEnabled);
                if (mCallbackOn) {
                    if (!mEnabled) {
                        mVisualizer.setDataCaptureListener(null,
                                10000,
                                false,
                                false);
                    }
                } else {
                    int msg = isChecked ? MSG_START_CAPTURE : MSG_STOP_CAPTURE;
                    mVisualizerTestHandler.sendMessage(
                            mVisualizerTestHandler.obtainMessage(msg, 0, 0, null));
                }
            }
        }
        if (buttonView.getId() == R.id.visuReleaseButton) {
            if (isChecked) {
                if (mVisualizer == null) {
                    getEffect(sSession);
                }
            } else {
                if (mVisualizer != null) {
                    putEffect(sSession);
                }
            }
        }
        if (buttonView.getId() == R.id.visuCallbackOnOff) {
            mCallbackOn = isChecked;
        }
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        TextView textView;

        setContentView(R.layout.visualizertest);

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

        mReleaseButton = (ToggleButton)findViewById(R.id.visuReleaseButton);
        mOnOffButton = (ToggleButton)findViewById(R.id.visualizerOnOff);
        mCallbackButton = (ToggleButton)findViewById(R.id.visuCallbackOnOff);
        mCallbackOn = false;
        mCallbackButton.setChecked(mCallbackOn);

        mVisualizerTestHandler = new VisualizerTestHandler();
        mVisualizerListener = new VisualizerListener();

        getEffect(sSession);

        if (mVisualizer != null) {
            mReleaseButton.setOnCheckedChangeListener(this);
            mOnOffButton.setOnCheckedChangeListener(this);
            mCallbackButton.setOnCheckedChangeListener(this);
        }
    
public voidonPause()

        super.onPause();
    
public voidonResume()

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

        mOnOffButton.setChecked(false);
        mOnOffButton.setEnabled(false);
        synchronized (sInstances) {
            if (mVisualizer != null) {
                mVisualizer.release();
                Log.d(TAG,"Visualizer released");
                mVisualizer = null;
                sInstances.remove(session);
            }
        }