Home | History | Annotate | Download | only in effectstest
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.effectstest;
     18 
     19 import android.app.Activity;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.os.Bundle;
     23 import android.util.Log;
     24 import android.view.KeyEvent;
     25 import android.view.Menu;
     26 import android.view.View.OnClickListener;
     27 import android.view.View;
     28 import android.view.ViewGroup;
     29 import android.widget.Button;
     30 import android.widget.TextView;
     31 import android.widget.ListView;
     32 import android.widget.BaseAdapter;
     33 import android.widget.LinearLayout;
     34 import android.media.audiofx.AudioEffect;
     35 
     36 import java.util.UUID;
     37 
     38 public class EffectsTest extends Activity {
     39 
     40     private final static String TAG = "EffectsTest";
     41 
     42 
     43     public EffectsTest() {
     44         Log.d(TAG, "contructor");
     45     }
     46 
     47     @Override
     48     public void onCreate(Bundle icicle) {
     49         super.onCreate(icicle);
     50         setContentView(R.layout.effectstest);
     51 
     52         Button button = (Button) findViewById(R.id.env_reverb_actvity);
     53         button.setOnClickListener(new OnClickListener() {
     54             public void onClick(View v) {
     55                 startActivity(new Intent(EffectsTest.this, EnvReverbTest.class));
     56             }
     57         });
     58 
     59         button = (Button) findViewById(R.id.preset_reverb_actvity);
     60         button.setOnClickListener(new OnClickListener() {
     61             public void onClick(View v) {
     62                 startActivity(new Intent(EffectsTest.this, PresetReverbTest.class));
     63             }
     64         });
     65 
     66         button = (Button) findViewById(R.id.equalizer_actvity);
     67         button.setOnClickListener(new OnClickListener() {
     68             public void onClick(View v) {
     69                 startActivity(new Intent(EffectsTest.this, EqualizerTest.class));
     70             }
     71         });
     72 
     73         button = (Button) findViewById(R.id.virtualizer_actvity);
     74         button.setOnClickListener(new OnClickListener() {
     75             public void onClick(View v) {
     76                 startActivity(new Intent(EffectsTest.this, VirtualizerTest.class));
     77             }
     78         });
     79 
     80         button = (Button) findViewById(R.id.bassboost_actvity);
     81         button.setOnClickListener(new OnClickListener() {
     82             public void onClick(View v) {
     83                 startActivity(new Intent(EffectsTest.this, BassBoostTest.class));
     84             }
     85         });
     86 
     87         button = (Button) findViewById(R.id.visualizer_actvity);
     88         button.setOnClickListener(new OnClickListener() {
     89             public void onClick(View v) {
     90                 startActivity(new Intent(EffectsTest.this, VisualizerTest.class));
     91             }
     92         });
     93 
     94         AudioEffect.Descriptor[] descriptors = AudioEffect.queryEffects();
     95 
     96         ListView list = (ListView) findViewById(R.id.effect_list);
     97         list.setAdapter(new EffectListAdapter(this, descriptors));
     98 
     99     }
    100 
    101     private class EffectListAdapter extends BaseAdapter {
    102 
    103         private Context mContext;
    104 
    105         AudioEffect.Descriptor[] mDescriptors;
    106 
    107         public EffectListAdapter(Context context, AudioEffect.Descriptor[] descriptors) {
    108             Log.d(TAG, "EffectListAdapter contructor");
    109             mContext = context;
    110             mDescriptors = descriptors;
    111             for (int i = 0; i < mDescriptors.length; i++) {
    112                 Log.d(TAG, "Effect: "+i+" name: "+ mDescriptors[i].name);
    113             }
    114         }
    115 
    116          public int getCount() {
    117             Log.d(TAG, "EffectListAdapter getCount(): "+mDescriptors.length);
    118             return mDescriptors.length;
    119         }
    120 
    121         public Object getItem(int position) {
    122             Log.d(TAG, "EffectListAdapter getItem() at: "+position+" name: "
    123                     +mDescriptors[position].name);
    124             return mDescriptors[position];
    125         }
    126 
    127         public long getItemId(int position) {
    128             return position;
    129         }
    130 
    131         public View getView(int position, View convertView, ViewGroup parent) {
    132             EffectView ev;
    133             if (convertView == null) {
    134                 Log.d(TAG, "getView() new EffectView position: " + position);
    135                 ev = new EffectView(mContext, mDescriptors);
    136             } else {
    137                 Log.d(TAG, "getView() convertView position: " + position);
    138                 ev = new EffectView(mContext, mDescriptors);
    139                 //ev = (EffectView) convertView;
    140             }
    141             ev.set(position);
    142             return ev;
    143         }
    144     }
    145 
    146     private class EffectView extends LinearLayout {
    147         private Context mContext;
    148         AudioEffect.Descriptor[] mDescriptors;
    149 
    150         public EffectView(Context context, AudioEffect.Descriptor[] descriptors) {
    151             super(context);
    152 
    153             mContext = context;
    154             mDescriptors = descriptors;
    155             this.setOrientation(VERTICAL);
    156         }
    157 
    158         public String effectUuidToString(UUID effectType) {
    159             if (effectType.equals(AudioEffect.EFFECT_TYPE_VIRTUALIZER)) {
    160                 return "Virtualizer";
    161             } else if (effectType.equals(AudioEffect.EFFECT_TYPE_ENV_REVERB)){
    162                 return "Reverb";
    163             } else if (effectType.equals(AudioEffect.EFFECT_TYPE_PRESET_REVERB)){
    164                 return "Preset Reverb";
    165             } else if (effectType.equals(AudioEffect.EFFECT_TYPE_EQUALIZER)){
    166                 return "Equalizer";
    167             } else if (effectType.equals(AudioEffect.EFFECT_TYPE_BASS_BOOST)){
    168                 return "Bass Boost";
    169             } else if (effectType.equals(AudioEffect.EFFECT_TYPE_AGC)){
    170                 return "Automatic Gain Control";
    171             } else if (effectType.equals(AudioEffect.EFFECT_TYPE_AEC)){
    172                 return "Acoustic Echo Canceler";
    173             } else if (effectType.equals(AudioEffect.EFFECT_TYPE_NS)){
    174                 return "Noise Suppressor";
    175             }
    176 
    177             return effectType.toString();
    178         }
    179 
    180         public void set(int position) {
    181             TextView tv = new TextView(mContext);
    182             tv.setText("Effect "+ position);
    183             addView(tv, new LinearLayout.LayoutParams(
    184                     LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    185             tv = new TextView(mContext);
    186             tv.setText(" type: "+ effectUuidToString(mDescriptors[position].type));
    187             addView(tv, new LinearLayout.LayoutParams(
    188                     LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    189             tv = new TextView(mContext);
    190             tv.setText(" uuid: "+ mDescriptors[position].uuid.toString());
    191             addView(tv, new LinearLayout.LayoutParams(
    192                     LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    193             tv = new TextView(mContext);
    194             tv.setText(" name: "+ mDescriptors[position].name);
    195             addView(tv, new LinearLayout.LayoutParams(
    196                     LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    197             tv = new TextView(mContext);
    198             tv.setText(" vendor: "+ mDescriptors[position].implementor);
    199             addView(tv, new LinearLayout.LayoutParams(
    200                     LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    201             tv = new TextView(mContext);
    202             tv.setText(" mode: "+ mDescriptors[position].connectMode);
    203             addView(tv, new LinearLayout.LayoutParams(
    204                     LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    205         }
    206     }
    207 
    208 }
    209