Project

General

Profile

Download (9 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / effects2d / Effects2DActivity.java @ af225332

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.examples.effects2d;
21

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

    
27
import android.app.Activity;
28
import android.opengl.GLSurfaceView;
29
import android.os.Bundle;
30
import android.view.View;
31
import android.widget.AdapterView;
32
import android.widget.ArrayAdapter;
33
import android.widget.Spinner;
34

    
35
import java.util.ArrayList;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

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

    
45
  private int mPosID, mPosName, mPosType;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  @Override
50
  protected void onCreate(Bundle savedInstanceState) 
51
    {
52
    super.onCreate(savedInstanceState);
53
 
54
    setContentView(R.layout.effects2dlayout);
55

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

    
60
    mID   = (Spinner)findViewById(R.id.effects2d_spinnerID  );
61
    mName = (Spinner)findViewById(R.id.effects2d_spinnerName);
62
    mType = (Spinner)findViewById(R.id.effects2d_spinnerType);
63

    
64
    mID.setOnItemSelectedListener(this);
65
    mName.setOnItemSelectedListener(this);
66
    mType.setOnItemSelectedListener(this);
67

    
68
    ArrayList<Long> itemsID  = new ArrayList<>();
69

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

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

    
78
    mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID);
79
    mAdapterID.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
80
    mID.setAdapter(mAdapterID);
81

    
82
    mAdapterName = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName);
83
    mAdapterName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
84
    mName.setAdapter(mAdapterName);
85

    
86
    mAdapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsType);
87
    mAdapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
88
    mType.setAdapter(mAdapterType);
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  @Override
94
  protected void onResume() 
95
    {
96
    super.onResume();
97
      
98
    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
99
    mView.onResume();
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  @Override
105
  protected void onPause() 
106
    {
107
    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
108
    mView.onPause();
109
      
110
    super.onPause();
111
    }
112
    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  @Override
116
  public void onStop()
117
    {
118
    super.onStop();
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  @Override
124
  public void onDestroy()
125
    {
126
    Distorted.onDestroy();
127
    super.onDestroy();
128
    }     
129
 
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
    
132
  public void Distort(View v)
133
    {
134
    Effects2DSurfaceView.setEffect(0);
135
    }     
136
    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  public void Sink(View v)
140
    {
141
    Effects2DSurfaceView.setEffect(1);
142
    }       
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
    
146
  public void Transparency(View v)
147
    {
148
    Effects2DSurfaceView.setEffect(2);
149
    }     
150
    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  public void Macroblock(View v)
154
    {
155
    Effects2DSurfaceView.setEffect(3);
156
    }       
157
 
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
  public void Chroma(View v)
161
    {
162
    Effects2DSurfaceView.setEffect(4);
163
    }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
168
    {
169
    switch(parent.getId())
170
      {
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;
174
      }
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  public void onNothingSelected(AdapterView<?> parent)
180
    {
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)
199
      {
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  ;
206
      }
207

    
208
    Effects2DRenderer.mBackground.abortEffects(name);
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

    
262
  }
(1-1/3)