Project

General

Profile

« Previous | Next » 

Revision af225332

Added by Leszek Koltunski almost 8 years ago

More progress with Effects2D app.

View differences:

src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java
21 21

  
22 22
import org.distorted.library.Distorted;
23 23
import org.distorted.examples.R;
24
import org.distorted.library.EffectNames;
25
import org.distorted.library.EffectTypes;
24 26

  
25 27
import android.app.Activity;
26 28
import android.opengl.GLSurfaceView;
......
30 32
import android.widget.ArrayAdapter;
31 33
import android.widget.Spinner;
32 34

  
35
import java.util.ArrayList;
36

  
33 37
///////////////////////////////////////////////////////////////////////////////////////////////////
34 38

  
35 39
public class Effects2DActivity extends Activity implements AdapterView.OnItemSelectedListener
36 40
  {
37 41
  private Spinner mID, mName, mType;
38
  private ArrayAdapter<String> mAdapterID, mAdapterName, mAdapterType;
42
  private static ArrayAdapter<String> mAdapterName, mAdapterType;
43
  private static ArrayAdapter<Long> mAdapterID;
44

  
45
  private int mPosID, mPosName, mPosType;
39 46

  
40 47
///////////////////////////////////////////////////////////////////////////////////////////////////
41 48

  
......
46 53
 
47 54
    setContentView(R.layout.effects2dlayout);
48 55

  
56
    mPosID   = 0;
57
    mPosName = 0;
58
    mPosType = 0;
59

  
49 60
    mID   = (Spinner)findViewById(R.id.effects2d_spinnerID  );
50 61
    mName = (Spinner)findViewById(R.id.effects2d_spinnerName);
51 62
    mType = (Spinner)findViewById(R.id.effects2d_spinnerType);
......
54 65
    mName.setOnItemSelectedListener(this);
55 66
    mType.setOnItemSelectedListener(this);
56 67

  
57
    String[] itemsID   = new String[] {"1", "2", "3"};
68
    ArrayList<Long> itemsID  = new ArrayList<>();
69

  
58 70
    String[] itemsName = new String[] { getText(R.string.distort     ).toString(),
59 71
                                        getText(R.string.sink        ).toString(),
60 72
                                        getText(R.string.transparency).toString(),
61 73
                                        getText(R.string.macroblock  ).toString(),
62 74
                                        getText(R.string.chroma      ).toString()};
75

  
63 76
    String[] itemsType = new String[] {"VERTEX", "FRAGMENT"};
64 77

  
65 78
    mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID);
......
82 95
    {
83 96
    super.onResume();
84 97
      
85
    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.scratchpadSurfaceView);
98
    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
86 99
    mView.onResume();
87 100
    }
88 101

  
......
91 104
  @Override
92 105
  protected void onPause() 
93 106
    {
94
    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.scratchpadSurfaceView);
107
    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
95 108
    mView.onPause();
96 109
      
97 110
    super.onPause();
......
153 166

  
154 167
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
155 168
    {
156
    // An item was selected. You can retrieve the selected item using
157
    // parent.getItemAtPosition(pos)
158

  
159 169
    switch(parent.getId())
160 170
      {
161
      case R.id.effects2d_spinnerID  : android.util.Log.d("EFFECTS2D", "ID spinner!!"  ); break;
162
      case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "Name spinner!!"); break;
163
      case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "Type spinner!!"); break;
171
      case R.id.effects2d_spinnerID  : mPosID   = pos; break;
172
      case R.id.effects2d_spinnerName: mPosName = pos; break;
173
      case R.id.effects2d_spinnerType: mPosType = pos; break;
164 174
      }
165 175
    }
166 176

  
......
168 178

  
169 179
  public void onNothingSelected(AdapterView<?> parent)
170 180
    {
171
    switch(parent.getId())
181
    }
182

  
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

  
185
  public void removeByID(View view)
186
    {
187
    Long currID   = (Long)  mID.getItemAtPosition(mPosID);
188

  
189
    Effects2DRenderer.mBackground.abortEffect(currID);
190
    }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

  
194
  public void removeByName(View view)
195
    {
196
    EffectNames name;
197

  
198
    switch(mPosName)
172 199
      {
173
      case R.id.effects2d_spinnerID  : android.util.Log.d("EFFECTS2D", "(nothing) ID spinner!!"  ); break;
174
      case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "(nothing) Name spinner!!"); break;
175
      case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "(nothing) Type spinner!!"); break;
200
      case  0: name = EffectNames.DISTORT   ; break;
201
      case  1: name = EffectNames.SINK      ; break;
202
      case  2: name = EffectNames.ALPHA     ; break;
203
      case  3: name = EffectNames.MACROBLOCK; break;
204
      case  4: name = EffectNames.CHROMA    ; break;
205
      default: name = EffectNames.CONTRAST  ;
176 206
      }
207

  
208
    Effects2DRenderer.mBackground.abortEffects(name);
177 209
    }
210

  
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

  
213
  public void removeByType(View view)
214
    {
215
    EffectTypes type;
216

  
217
    switch(mPosType)
218
      {
219
      case  0: type = EffectTypes.VERTEX  ; break;
220
      case  1: type = EffectTypes.FRAGMENT; break;
221
      default: type = EffectTypes.MATRIX;
222
      }
223

  
224
    Effects2DRenderer.mBackground.abortEffects(type);
225
    }
226

  
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228

  
229
  public void effectAdded(final long id, final int type)
230
    {
231
    android.util.Log.d("EFFECTS2D", "new effect added, id="+id+" type="+type);
232

  
233
    mAdapterID.add( new Long(id) );
234
    mAdapterID.notifyDataSetChanged();
235
    }
236

  
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

  
239
  public void effectRemoved(final long id)
240
    {
241
    android.util.Log.d("EFFECTS2D", "new effect removed, id="+id);
242

  
243
    runOnUiThread(new Runnable()
244
        {
245
        public void run()
246
          {
247
          mAdapterID.remove( new Long(id) );
248
          mAdapterID.notifyDataSetChanged();
249
          }
250
        });
251

  
252

  
253
    }
254

  
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

  
257
  public void effectFinished(final long id)
258
    {
259
    android.util.Log.d("EFFECTS2D", "new effect finished, id="+id);
260
    }
261

  
178 262
  }

Also available in: Unified diff