Revision e763f1ee
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java | ||
---|---|---|
31 | 31 |
import android.widget.AdapterView; |
32 | 32 |
import android.widget.ArrayAdapter; |
33 | 33 |
import android.widget.Spinner; |
34 |
import android.widget.TableLayout; |
|
35 |
import android.widget.TableRow; |
|
36 |
import android.widget.TextView; |
|
34 | 37 |
|
35 | 38 |
import java.util.ArrayList; |
39 |
import java.util.HashMap; |
|
36 | 40 |
|
37 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 42 |
|
... | ... | |
43 | 47 |
private static ArrayAdapter<Long> mAdapterID; |
44 | 48 |
|
45 | 49 |
private int mPosID, mPosName, mPosType; |
50 |
private TableLayout mLayoutList; |
|
51 |
|
|
52 |
private HashMap<Long,TableRow> mMap = new HashMap<>(); |
|
46 | 53 |
|
47 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
48 | 55 |
|
... | ... | |
86 | 93 |
mAdapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsType); |
87 | 94 |
mAdapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
88 | 95 |
mType.setAdapter(mAdapterType); |
96 |
|
|
97 |
mLayoutList = (TableLayout)findViewById(R.id.effects2dTableList); |
|
89 | 98 |
} |
90 | 99 |
|
91 | 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
184 | 193 |
|
185 | 194 |
public void removeByID(View view) |
186 | 195 |
{ |
187 |
Long currID = (Long) mID.getItemAtPosition(mPosID);
|
|
196 |
Long currID = (Long)mID.getItemAtPosition(mPosID);
|
|
188 | 197 |
|
189 | 198 |
Effects2DRenderer.mBackground.abortEffect(currID); |
190 | 199 |
} |
... | ... | |
197 | 206 |
|
198 | 207 |
switch(mPosName) |
199 | 208 |
{ |
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 ; |
|
209 |
case 0: name = EffectNames.DISTORT ; break;
|
|
210 |
case 1: name = EffectNames.SINK ; break;
|
|
211 |
case 2: name = EffectNames.SMOOTH_ALPHA ; break;
|
|
212 |
case 3: name = EffectNames.MACROBLOCK ; break;
|
|
213 |
case 4: name = EffectNames.SMOOTH_CHROMA; break;
|
|
214 |
default: name = EffectNames.CONTRAST ;
|
|
206 | 215 |
} |
207 | 216 |
|
208 | 217 |
Effects2DRenderer.mBackground.abortEffects(name); |
... | ... | |
226 | 235 |
|
227 | 236 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
228 | 237 |
|
229 |
public void effectAdded(final long id, final int type)
|
|
238 |
public void effectAdded(final long id, final EffectNames name, final EffectTypes type)
|
|
230 | 239 |
{ |
231 |
android.util.Log.d("EFFECTS2D", "new effect added, id="+id+" type="+type); |
|
232 |
|
|
233 | 240 |
mAdapterID.add( new Long(id) ); |
234 | 241 |
mAdapterID.notifyDataSetChanged(); |
242 |
|
|
243 |
TableRow tr = new TableRow(this); |
|
244 |
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
245 |
|
|
246 |
TextView b1 = new TextView(this); |
|
247 |
b1.setText("ID: "+id); |
|
248 |
b1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
249 |
tr.addView(b1); |
|
250 |
|
|
251 |
TextView b2 = new TextView(this); |
|
252 |
b2.setText(name.name()); |
|
253 |
b2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
254 |
tr.addView(b2); |
|
255 |
|
|
256 |
TextView b3 = new TextView(this); |
|
257 |
b3.setText(type.name()); |
|
258 |
b3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
259 |
tr.addView(b3); |
|
260 |
|
|
261 |
TextView b4 = new TextView(this); |
|
262 |
b4.setText("LIVE"); |
|
263 |
b4.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
264 |
tr.addView(b4); |
|
265 |
|
|
266 |
mMap.put(id,tr); |
|
267 |
|
|
268 |
mLayoutList.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT)); |
|
235 | 269 |
} |
236 | 270 |
|
237 | 271 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
238 | 272 |
|
239 | 273 |
public void effectRemoved(final long id) |
240 | 274 |
{ |
241 |
android.util.Log.d("EFFECTS2D", "new effect removed, id="+id); |
|
242 |
|
|
243 | 275 |
runOnUiThread(new Runnable() |
276 |
{ |
|
277 |
public void run() |
|
244 | 278 |
{ |
245 |
public void run() |
|
246 |
{ |
|
247 |
mAdapterID.remove( new Long(id) ); |
|
248 |
mAdapterID.notifyDataSetChanged(); |
|
249 |
} |
|
250 |
}); |
|
279 |
mAdapterID.remove( new Long(id) ); |
|
280 |
mAdapterID.notifyDataSetChanged(); |
|
251 | 281 |
|
282 |
TableRow row = mMap.remove(id); |
|
252 | 283 |
|
284 |
if( row!=null ) |
|
285 |
{ |
|
286 |
mLayoutList.removeView(row); |
|
287 |
} |
|
288 |
else |
|
289 |
{ |
|
290 |
android.util.Log.e("EFFECTS2D", "Impossible: id="+id+" not in the map!"); |
|
291 |
} |
|
292 |
} |
|
293 |
}); |
|
253 | 294 |
} |
254 | 295 |
|
255 | 296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
256 | 297 |
|
257 | 298 |
public void effectFinished(final long id) |
258 | 299 |
{ |
259 |
android.util.Log.d("EFFECTS2D", "new effect finished, id="+id); |
|
260 |
} |
|
300 |
runOnUiThread(new Runnable() |
|
301 |
{ |
|
302 |
public void run() |
|
303 |
{ |
|
304 |
TableRow row = mMap.get(id); |
|
261 | 305 |
|
306 |
if( row!=null ) |
|
307 |
{ |
|
308 |
TextView v = (TextView)row.getVirtualChildAt(3); |
|
309 |
v.setText("FINISHED"); |
|
310 |
} |
|
311 |
} |
|
312 |
}); |
|
313 |
} |
|
262 | 314 |
} |
src/main/java/org/distorted/examples/effects2d/Effects2DRenderer.java | ||
---|---|---|
120 | 120 |
{ |
121 | 121 |
Effects2DActivity act = (Effects2DActivity)mView.getContext(); |
122 | 122 |
|
123 |
android.util.Log.e("EFFECT2D", "message came! "+effectID); |
|
124 |
|
|
123 | 125 |
switch(em) |
124 | 126 |
{ |
125 | 127 |
case EFFECT_REMOVED : act.effectRemoved(effectID) ; break; |
src/main/java/org/distorted/examples/effects2d/Effects2DSurfaceView.java | ||
---|---|---|
25 | 25 |
import android.view.MotionEvent; |
26 | 26 |
import android.util.AttributeSet; |
27 | 27 |
|
28 |
import org.distorted.library.EffectNames; |
|
29 |
import org.distorted.library.EffectTypes; |
|
28 | 30 |
import org.distorted.library.type.Dynamic1D; |
29 | 31 |
import org.distorted.library.type.Static1D; |
30 | 32 |
import org.distorted.library.type.Static2D; |
... | ... | |
145 | 147 |
y = (int)event.getY()* Effects2DRenderer.BHEI/mScrH; |
146 | 148 |
point.set(x,y); |
147 | 149 |
mRegion.set(x,y,60,60); |
150 |
Effects2DActivity act = (Effects2DActivity)getContext(); |
|
148 | 151 |
|
149 | 152 |
switch(mCurrentEffect) |
150 | 153 |
{ |
151 | 154 |
case 0: id = Effects2DRenderer.mBackground.distort(mInterD, point, region); |
152 |
break; |
|
155 |
act.effectAdded(id, EffectNames.DISTORT, EffectTypes.VERTEX); |
|
156 |
break; |
|
153 | 157 |
case 1: id = Effects2DRenderer.mBackground.sink(mInterS, point, region); |
154 |
break; |
|
155 |
case 2: id = Effects2DRenderer.mBackground.alpha(mInterA, mRegion, false); |
|
156 |
break; |
|
158 |
act.effectAdded(id, EffectNames.SINK, EffectTypes.VERTEX); |
|
159 |
break; |
|
160 |
case 2: id = Effects2DRenderer.mBackground.alpha(mInterA, mRegion, true); |
|
161 |
act.effectAdded(id, EffectNames.ALPHA, EffectTypes.FRAGMENT); |
|
162 |
break; |
|
157 | 163 |
case 3: id = Effects2DRenderer.mBackground.macroblock(mInterM, mRegion); |
158 |
break; |
|
159 |
case 4: id = Effects2DRenderer.mBackground.chroma(mInterC, mRED, mRegion, false); |
|
160 |
break; |
|
164 |
act.effectAdded(id, EffectNames.MACROBLOCK, EffectTypes.FRAGMENT); |
|
165 |
break; |
|
166 |
case 4: id = Effects2DRenderer.mBackground.chroma(mInterC, mRED, mRegion, true); |
|
167 |
act.effectAdded(id, EffectNames.CHROMA, EffectTypes.FRAGMENT); |
|
168 |
break; |
|
161 | 169 |
} |
162 | 170 |
|
163 |
Effects2DActivity act = (Effects2DActivity)getContext(); |
|
164 |
act.effectAdded(id, mCurrentEffect); |
|
165 |
|
|
166 | 171 |
break; |
167 | 172 |
} |
168 | 173 |
|
src/main/res/layout/effects2dlayout.xml | ||
---|---|---|
193 | 193 |
android:text="@string/list" |
194 | 194 |
android:id="@+id/textView6" |
195 | 195 |
android:layout_gravity="center_horizontal"/> |
196 |
|
|
197 |
<TableLayout |
|
198 |
android:id="@+id/effects2dTableList" |
|
199 |
android:layout_width="match_parent" |
|
200 |
android:layout_height="match_parent" |
|
201 |
android:paddingTop="2dp" |
|
202 |
android:paddingBottom="2dp" |
|
203 |
android:stretchColumns="0,1,2,3" |
|
204 |
android:paddingLeft="10dp" |
|
205 |
android:paddingRight="10dp"> |
|
206 |
</TableLayout> |
|
207 |
|
|
196 | 208 |
</LinearLayout> |
209 |
|
|
197 | 210 |
</ScrollView> |
198 | 211 |
</LinearLayout> |
Also available in: Unified diff
Effects2D almost finished.