summaryrefslogtreecommitdiffstats
path: root/media/tests/EffectsTest/src/com/android/effectstest/EffectsTest.java
blob: 70202463a79e39e876df5c2b89a731af6dab0ef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.effectstest;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ListView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.media.audiofx.AudioEffect;

import java.util.UUID;

public class EffectsTest extends Activity {

    private final static String TAG = "EffectsTest";


    public EffectsTest() {
        Log.d(TAG, "contructor");
    }

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.effectstest);

        Button button = (Button) findViewById(R.id.env_reverb_actvity);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(EffectsTest.this, EnvReverbTest.class));
            }
        });

        button = (Button) findViewById(R.id.preset_reverb_actvity);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(EffectsTest.this, PresetReverbTest.class));
            }
        });

        button = (Button) findViewById(R.id.equalizer_actvity);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(EffectsTest.this, EqualizerTest.class));
            }
        });

        button = (Button) findViewById(R.id.virtualizer_actvity);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(EffectsTest.this, VirtualizerTest.class));
            }
        });

        button = (Button) findViewById(R.id.bassboost_actvity);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(EffectsTest.this, BassBoostTest.class));
            }
        });

        button = (Button) findViewById(R.id.visualizer_actvity);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(EffectsTest.this, VisualizerTest.class));
            }
        });

        AudioEffect.Descriptor[] descriptors = AudioEffect.queryEffects();

        ListView list = (ListView) findViewById(R.id.effect_list);
        list.setAdapter(new EffectListAdapter(this, descriptors));

    }

    private class EffectListAdapter extends BaseAdapter {

        private Context mContext;

        AudioEffect.Descriptor[] mDescriptors;

        public EffectListAdapter(Context context, AudioEffect.Descriptor[] descriptors) {
            Log.d(TAG, "EffectListAdapter contructor");
            mContext = context;
            mDescriptors = descriptors;
            for (int i = 0; i < mDescriptors.length; i++) {
                Log.d(TAG, "Effect: "+i+" name: "+ mDescriptors[i].name);
            }
        }

         public int getCount() {
            Log.d(TAG, "EffectListAdapter getCount(): "+mDescriptors.length);
            return mDescriptors.length;
        }

        public Object getItem(int position) {
            Log.d(TAG, "EffectListAdapter getItem() at: "+position+" name: "
                    +mDescriptors[position].name);
            return mDescriptors[position];
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            EffectView ev;
            if (convertView == null) {
                Log.d(TAG, "getView() new EffectView position: " + position);
                ev = new EffectView(mContext, mDescriptors);
            } else {
                Log.d(TAG, "getView() convertView position: " + position);
                ev = new EffectView(mContext, mDescriptors);
                //ev = (EffectView) convertView;
            }
            ev.set(position);
            return ev;
        }
    }

    private class EffectView extends LinearLayout {
        private Context mContext;
        AudioEffect.Descriptor[] mDescriptors;

        public EffectView(Context context, AudioEffect.Descriptor[] descriptors) {
            super(context);

            mContext = context;
            mDescriptors = descriptors;
            this.setOrientation(VERTICAL);
        }

        public String effectUuidToString(UUID effectType) {
            if (effectType.equals(AudioEffect.EFFECT_TYPE_VIRTUALIZER)) {
                return "Virtualizer";
            } else if (effectType.equals(AudioEffect.EFFECT_TYPE_ENV_REVERB)){
                return "Reverb";
            } else if (effectType.equals(AudioEffect.EFFECT_TYPE_PRESET_REVERB)){
                return "Preset Reverb";
            } else if (effectType.equals(AudioEffect.EFFECT_TYPE_EQUALIZER)){
                return "Equalizer";
            } else if (effectType.equals(AudioEffect.EFFECT_TYPE_BASS_BOOST)){
                return "Bass Boost";
            } else if (effectType.equals(AudioEffect.EFFECT_TYPE_AGC)){
                return "Automatic Gain Control";
            } else if (effectType.equals(AudioEffect.EFFECT_TYPE_AEC)){
                return "Acoustic Echo Canceler";
            } else if (effectType.equals(AudioEffect.EFFECT_TYPE_NS)){
                return "Noise Suppressor";
            }

            return effectType.toString();
        }

        public void set(int position) {
            TextView tv = new TextView(mContext);
            tv.setText("Effect "+ position);
            addView(tv, new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            tv = new TextView(mContext);
            tv.setText(" type: "+ effectUuidToString(mDescriptors[position].type));
            addView(tv, new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            tv = new TextView(mContext);
            tv.setText(" uuid: "+ mDescriptors[position].uuid.toString());
            addView(tv, new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            tv = new TextView(mContext);
            tv.setText(" name: "+ mDescriptors[position].name);
            addView(tv, new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            tv = new TextView(mContext);
            tv.setText(" vendor: "+ mDescriptors[position].implementor);
            addView(tv, new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            tv = new TextView(mContext);
            tv.setText(" mode: "+ mDescriptors[position].connectMode);
            addView(tv, new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        }
    }

}