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.os.Bundle;
20 import android.util.Log;
21 import android.widget.TextView;
22 import android.widget.SeekBar;
23 
24 
25 abstract class EffectParameter implements SeekBar.OnSeekBarChangeListener {
26 
27     private final static String TAG = "EffectParameter";
28 
29     protected int mMin;
30     protected int mMax;
31     protected String mUnit;
32     protected SeekBar mSeekBar;
33     protected TextView mValueText;
34 
EffectParameter(int min, int max, SeekBar seekBar, TextView textView, String unit)35     public EffectParameter (int min, int max, SeekBar seekBar, TextView textView, String unit) {
36         mMin = min;
37         mMax = max;
38         mSeekBar = seekBar;
39         mValueText = textView;
40         mUnit = unit;
41         byte[] paramBuf = new byte[4];
42 
43         mSeekBar.setMax(max-min);
44     }
45 
displayValue(int value, boolean fromTouch)46     public void displayValue(int value, boolean fromTouch) {
47         String text = Integer.toString(value)+" "+mUnit;
48         mValueText.setText(text);
49         if (!fromTouch) {
50             mSeekBar.setProgress(value - mMin);
51         }
52     }
53 
updateDisplay()54     public void updateDisplay() {
55         displayValue(getParameter(), false);
56     }
57 
setParameter(Integer value)58     public abstract void setParameter(Integer value);
59 
getParameter()60     public abstract Integer getParameter();
61 
setEffect(Object effect)62     public abstract void setEffect(Object effect);
63 
64     // SeekBar.OnSeekBarChangeListener
onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch)65     public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
66 
67         if (seekBar != mSeekBar) {
68             Log.e(TAG, "onProgressChanged called with wrong seekBar");
69             return;
70         }
71 
72         int value = progress + mMin;
73         if (fromTouch) {
74             setParameter(value);
75         }
76 
77         displayValue(getParameter(), fromTouch);
78     }
79 
onStartTrackingTouch(SeekBar seekBar)80     public void onStartTrackingTouch(SeekBar seekBar) {
81     }
82 
onStopTrackingTouch(SeekBar seekBar)83     public void onStopTrackingTouch(SeekBar seekBar) {
84     }
85 
setEnabled(boolean e)86     public void setEnabled(boolean e) {
87         mSeekBar.setEnabled(e);
88     }
89 }
90