Revision d28ddc9b
Added by Leszek Koltunski almost 6 years ago
src/main/java/org/distorted/examples/generic/GenericActivity2.java | ||
---|---|---|
31 | 31 |
import android.widget.CheckBox; |
32 | 32 |
|
33 | 33 |
import org.distorted.examples.R; |
34 |
import org.distorted.library.effect.EffectType; |
|
35 | 34 |
import org.distorted.library.main.Distorted; |
36 | 35 |
import org.distorted.library.main.DistortedEffects; |
37 | 36 |
import org.distorted.library.main.DistortedTexture; |
... | ... | |
187 | 186 |
return mBitmap; |
188 | 187 |
} |
189 | 188 |
|
189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
190 |
|
|
191 |
public DistortedEffects getEffects() |
|
192 |
{ |
|
193 |
return mEffects; |
|
194 |
} |
|
195 |
|
|
196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
197 |
|
|
198 |
public GenericViewPager getPager() |
|
199 |
{ |
|
200 |
return mViewPager; |
|
201 |
} |
|
202 |
|
|
190 | 203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
191 | 204 |
|
192 | 205 |
public int getWidth() |
... | ... | |
232 | 245 |
view.getRenderer().setRegion( region.get1(), region.get2(), region.get3(), region.get4() ); |
233 | 246 |
} |
234 | 247 |
|
235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
236 |
|
|
237 |
void resetMatrixEffects() |
|
238 |
{ |
|
239 |
GenericSurfaceView view = findViewById(R.id.genericSurfaceView); |
|
240 |
GenericRenderer renderer= view.getRenderer(); |
|
241 |
|
|
242 |
renderer.resetMatrixEffects(); |
|
243 |
} |
|
244 |
|
|
245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
246 |
|
|
247 |
void setCurrentTab(EffectType type) |
|
248 |
{ |
|
249 |
mViewPager.setCurrentTab(type); |
|
250 |
} |
|
251 |
|
|
252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
253 |
|
|
254 |
void setTab(GenericTab tab, int position) |
|
255 |
{ |
|
256 |
mViewPager.setTab(tab,position); |
|
257 |
} |
|
258 |
|
|
259 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
260 |
|
|
261 |
public DistortedEffects getEffects() |
|
262 |
{ |
|
263 |
return mEffects; |
|
264 |
} |
|
265 |
|
|
266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
267 |
|
|
268 |
public void newEffect(View v) |
|
269 |
{ |
|
270 |
mViewPager.newEffect(); |
|
271 |
} |
|
272 |
|
|
273 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
274 |
|
|
275 |
public void removeAll(View v) |
|
276 |
{ |
|
277 |
mViewPager.removeAll(); |
|
278 |
} |
|
279 |
|
|
280 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
281 |
|
|
282 |
public void remove(View v) |
|
283 |
{ |
|
284 |
mViewPager.remove(v); |
|
285 |
} |
|
286 |
|
|
287 | 248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
288 | 249 |
|
289 | 250 |
public void showRegionAndCenter(View view) |
src/main/java/org/distorted/examples/generic/GenericEffect.java | ||
---|---|---|
788 | 788 |
return mId; |
789 | 789 |
} |
790 | 790 |
|
791 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
792 |
|
|
793 |
public int getDimension() |
|
794 |
{ |
|
795 |
return mDimension; |
|
796 |
} |
|
797 |
|
|
791 | 798 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
792 | 799 |
|
793 | 800 |
public View getEffect() |
src/main/java/org/distorted/examples/generic/GenericTab.java | ||
---|---|---|
26 | 26 |
import android.view.ViewGroup; |
27 | 27 |
import android.widget.AdapterView; |
28 | 28 |
import android.widget.ArrayAdapter; |
29 |
import android.widget.Button; |
|
29 | 30 |
import android.widget.LinearLayout; |
30 | 31 |
import android.widget.Spinner; |
31 | 32 |
|
33 |
import org.distorted.examples.R; |
|
32 | 34 |
import org.distorted.library.effect.EffectName; |
33 | 35 |
import org.distorted.library.effect.EffectType; |
34 | 36 |
import org.distorted.library.main.DistortedEffects; |
... | ... | |
37 | 39 |
|
38 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
39 | 41 |
|
40 |
public class GenericTab extends Fragment implements AdapterView.OnItemSelectedListener |
|
42 |
public class GenericTab extends Fragment implements AdapterView.OnItemSelectedListener, View.OnClickListener
|
|
41 | 43 |
{ |
42 | 44 |
private EffectType mType; |
43 | 45 |
private ArrayList<GenericEffect> mList; |
... | ... | |
73 | 75 |
|
74 | 76 |
GenericActivity2 act = (GenericActivity2)getActivity(); |
75 | 77 |
|
76 |
if( act!=null ) |
|
77 |
{ |
|
78 |
act.setTab(this,position); |
|
79 |
mEffects = act.getEffects(); |
|
80 |
} |
|
78 |
if( act!=null ) mEffects = act.getEffects(); |
|
81 | 79 |
|
82 | 80 |
createEffectNames(mType); |
83 | 81 |
mEffectStrings = new String[mEffectNames.length]; |
... | ... | |
87 | 85 |
mEffectStrings[i] = mEffectNames[i].name(); |
88 | 86 |
} |
89 | 87 |
|
90 |
return inflater.inflate( tab, container, false); |
|
88 |
View view = inflater.inflate( tab, container, false); |
|
89 |
|
|
90 |
Button add = view.findViewById(R.id.effects3dButtonAdd); |
|
91 |
add.setOnClickListener(this); |
|
92 |
Button rem = view.findViewById(R.id.effects3dButtonRemove); |
|
93 |
rem.setOnClickListener(this); |
|
94 |
|
|
95 |
return view; |
|
91 | 96 |
} |
92 | 97 |
|
93 | 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
108 | 113 |
effectSpinner.setAdapter(adapterEffect); |
109 | 114 |
} |
110 | 115 |
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
@Override |
|
119 |
public void onClick(View v) |
|
120 |
{ |
|
121 |
switch (v.getId()) |
|
122 |
{ |
|
123 |
case R.id.effects3dButtonAdd : newEffect(); break; |
|
124 |
case R.id.effects3dButtonRemove: removeAll(); break; |
|
125 |
case R.id.button1dRemove : |
|
126 |
case R.id.button2dRemove : |
|
127 |
case R.id.button3dRemove : |
|
128 |
case R.id.button4dRemove : |
|
129 |
case R.id.button5dRemove : remove(v) ; break; |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
111 | 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
112 | 134 |
|
113 | 135 |
@Override |
... | ... | |
123 | 145 |
|
124 | 146 |
if( act!=null ) |
125 | 147 |
{ |
126 |
act.setCurrentTab(mType); |
|
148 |
GenericViewPager pager = act.getPager(); |
|
149 |
pager.setCurrentTab(mType); |
|
127 | 150 |
act.showRegionAndCenter(null); |
128 | 151 |
} |
129 | 152 |
} |
... | ... | |
160 | 183 |
View view = eff.createView(mChildren); |
161 | 184 |
layout.addView(view); |
162 | 185 |
|
186 |
int dimension = eff.getDimension(); |
|
187 |
Button butt; |
|
188 |
|
|
189 |
switch(dimension) |
|
190 |
{ |
|
191 |
case 1: butt = view.findViewById(R.id.button1dRemove); |
|
192 |
butt.setOnClickListener(this); |
|
193 |
break; |
|
194 |
case 2: butt = view.findViewById(R.id.button2dRemove); |
|
195 |
butt.setOnClickListener(this); |
|
196 |
break; |
|
197 |
case 3: butt = view.findViewById(R.id.button3dRemove); |
|
198 |
butt.setOnClickListener(this); |
|
199 |
break; |
|
200 |
case 4: butt = view.findViewById(R.id.button4dRemove); |
|
201 |
butt.setOnClickListener(this); |
|
202 |
break; |
|
203 |
case 5: butt = view.findViewById(R.id.button5dRemove); |
|
204 |
butt.setOnClickListener(this); |
|
205 |
break; |
|
206 |
} |
|
207 |
|
|
163 | 208 |
if( mEffectNames[mEffectAdd].getCenterDimension() > 0 ) |
164 | 209 |
{ |
165 | 210 |
View center = eff.createCenter(mChildren); |
... | ... | |
175 | 220 |
eff.apply(mEffects); |
176 | 221 |
} |
177 | 222 |
|
178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
179 |
|
|
180 |
private void createEffectNames(EffectType type) |
|
181 |
{ |
|
182 |
EffectName[] names = EffectName.values(); |
|
183 |
|
|
184 |
int numEffects=0; |
|
185 |
|
|
186 |
for(int i=0; i<names.length; i++) |
|
187 |
if( names[i].getType() == type ) numEffects++; |
|
188 |
|
|
189 |
mEffectNames = new EffectName[numEffects]; |
|
190 |
|
|
191 |
numEffects=0; |
|
192 |
|
|
193 |
for(int i=0; i<names.length; i++) |
|
194 |
if( names[i].getType() == type ) |
|
195 |
{ |
|
196 |
mEffectNames[numEffects++] = names[i]; |
|
197 |
} |
|
198 |
} |
|
199 |
|
|
200 | 223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
201 | 224 |
|
202 | 225 |
void removeAll() |
... | ... | |
212 | 235 |
|
213 | 236 |
if( mType==EffectType.MATRIX ) |
214 | 237 |
{ |
215 |
act.resetMatrixEffects(); |
|
238 |
GenericSurfaceView view = act.findViewById(R.id.genericSurfaceView); |
|
239 |
GenericRenderer renderer= view.getRenderer(); |
|
240 |
renderer.resetMatrixEffects(); |
|
216 | 241 |
} |
217 | 242 |
} |
218 | 243 |
|
... | ... | |
252 | 277 |
} |
253 | 278 |
} |
254 | 279 |
} |
280 |
|
|
281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
282 |
|
|
283 |
private void createEffectNames(EffectType type) |
|
284 |
{ |
|
285 |
EffectName[] names = EffectName.values(); |
|
286 |
|
|
287 |
int numEffects=0; |
|
288 |
|
|
289 |
for(int i=0; i<names.length; i++) |
|
290 |
if( names[i].getType() == type ) numEffects++; |
|
291 |
|
|
292 |
mEffectNames = new EffectName[numEffects]; |
|
293 |
|
|
294 |
numEffects=0; |
|
295 |
|
|
296 |
for(int i=0; i<names.length; i++) |
|
297 |
if( names[i].getType() == type ) |
|
298 |
{ |
|
299 |
mEffectNames[numEffects++] = names[i]; |
|
300 |
} |
|
301 |
} |
|
255 | 302 |
} |
src/main/java/org/distorted/examples/generic/GenericViewPager.java | ||
---|---|---|
25 | 25 |
import android.support.v4.app.FragmentPagerAdapter; |
26 | 26 |
import android.support.v4.view.ViewPager; |
27 | 27 |
import android.support.v7.app.AppCompatActivity; |
28 |
import android.view.View; |
|
29 | 28 |
|
30 | 29 |
import org.distorted.examples.R; |
31 | 30 |
import org.distorted.library.effect.EffectType; |
... | ... | |
50 | 49 |
private static final int NUM_TABS = TABS.length/NUM; |
51 | 50 |
|
52 | 51 |
private ViewPager mViewPager; |
53 |
private GenericTab[] mTab; |
|
54 | 52 |
private int mCurrentTab; |
55 | 53 |
|
56 | 54 |
private class GenericTabViewPager extends FragmentPagerAdapter |
... | ... | |
100 | 98 |
GenericTabViewPager pager = new GenericTabViewPager( act.getSupportFragmentManager() ); |
101 | 99 |
mViewPager.setAdapter(pager); |
102 | 100 |
|
103 |
mTab = new GenericTab[NUM_TABS]; |
|
104 | 101 |
mCurrentTab = 0; |
105 | 102 |
} |
106 | 103 |
|
... | ... | |
108 | 105 |
|
109 | 106 |
void showRegionAndCenter(boolean showR, boolean showC, GenericSurfaceView sv) |
110 | 107 |
{ |
111 |
boolean localShowC = showCenter(mCurrentTab);
|
|
112 |
boolean localShowR = showRegion(mCurrentTab);
|
|
108 |
boolean localShowC = (TABS[NUM*mCurrentTab + 4] == 1);
|
|
109 |
boolean localShowR = (TABS[NUM*mCurrentTab + 5] == 1);
|
|
113 | 110 |
|
114 | 111 |
sv.getRenderer().showRegionAndCenter( (showR&&localShowR) , (showC&&localShowC) ); |
115 | 112 |
} |
116 | 113 |
|
117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
118 |
|
|
119 |
void newEffect() |
|
120 |
{ |
|
121 |
int pos = mViewPager.getCurrentItem(); |
|
122 |
|
|
123 |
if( pos>=0 && pos<NUM_TABS ) mTab[pos].newEffect(); |
|
124 |
} |
|
125 |
|
|
126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
127 |
|
|
128 |
void removeAll() |
|
129 |
{ |
|
130 |
int pos = mViewPager.getCurrentItem(); |
|
131 |
|
|
132 |
if( pos>=0 && pos<NUM_TABS ) mTab[pos].removeAll(); |
|
133 |
} |
|
134 |
|
|
135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
136 |
|
|
137 |
void remove(View v) |
|
138 |
{ |
|
139 |
int pos = mViewPager.getCurrentItem(); |
|
140 |
|
|
141 |
if( pos>=0 && pos<NUM_TABS ) mTab[pos].remove(v); |
|
142 |
} |
|
143 |
|
|
144 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
145 | 115 |
|
146 | 116 |
ViewPager getPager() |
... | ... | |
161 | 131 |
} |
162 | 132 |
} |
163 | 133 |
} |
164 |
|
|
165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
166 |
|
|
167 |
void setTab(GenericTab tab, int position) |
|
168 |
{ |
|
169 |
if( position>=0 && position<NUM_TABS ) mTab[position] = tab; |
|
170 |
} |
|
171 |
|
|
172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
173 |
|
|
174 |
private static boolean showCenter(int position) |
|
175 |
{ |
|
176 |
return TABS[NUM*position + 4] == 1; |
|
177 |
} |
|
178 |
|
|
179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
180 |
|
|
181 |
private static boolean showRegion(int position) |
|
182 |
{ |
|
183 |
return TABS[NUM*position + 5] == 1; |
|
184 |
} |
|
185 | 134 |
} |
src/main/res/layout/effect1d.xml | ||
---|---|---|
26 | 26 |
android:layout_height="wrap_content" |
27 | 27 |
android:id="@+id/button1dRemove" |
28 | 28 |
android:layout_weight="0.2" |
29 |
android:layout_marginTop="3dp" |
|
30 |
android:onClick="remove"/> |
|
29 |
android:layout_marginTop="3dp"/> |
|
31 | 30 |
</LinearLayout> |
32 | 31 |
|
33 | 32 |
<SeekBar |
src/main/res/layout/effect2d.xml | ||
---|---|---|
26 | 26 |
android:layout_height="wrap_content" |
27 | 27 |
android:id="@+id/button2dRemove" |
28 | 28 |
android:layout_weight="0.2" |
29 |
android:layout_marginTop="3dp" |
|
30 |
android:onClick="remove"/> |
|
29 |
android:layout_marginTop="3dp"/> |
|
31 | 30 |
</LinearLayout> |
32 | 31 |
|
33 | 32 |
<SeekBar |
src/main/res/layout/effect3d.xml | ||
---|---|---|
26 | 26 |
android:layout_height="wrap_content" |
27 | 27 |
android:id="@+id/button3dRemove" |
28 | 28 |
android:layout_weight="0.2" |
29 |
android:layout_marginTop="3dp" |
|
30 |
android:onClick="remove"/> |
|
29 |
android:layout_marginTop="3dp"/> |
|
31 | 30 |
</LinearLayout> |
32 | 31 |
|
33 | 32 |
<SeekBar |
src/main/res/layout/effect4d.xml | ||
---|---|---|
26 | 26 |
android:layout_height="wrap_content" |
27 | 27 |
android:id="@+id/button4dRemove" |
28 | 28 |
android:layout_weight="0.2" |
29 |
android:layout_marginTop="3dp" |
|
30 |
android:onClick="remove"/> |
|
29 |
android:layout_marginTop="3dp"/> |
|
31 | 30 |
</LinearLayout> |
32 | 31 |
|
33 | 32 |
<SeekBar |
src/main/res/layout/effect5d.xml | ||
---|---|---|
26 | 26 |
android:layout_height="wrap_content" |
27 | 27 |
android:id="@+id/button5dRemove" |
28 | 28 |
android:layout_weight="0.2" |
29 |
android:layout_marginTop="3dp" |
|
30 |
android:onClick="remove"/> |
|
29 |
android:layout_marginTop="3dp"/> |
|
31 | 30 |
</LinearLayout> |
32 | 31 |
|
33 | 32 |
<SeekBar |
src/main/res/layout/effects3dtab0.xml | ||
---|---|---|
11 | 11 |
android:orientation="horizontal"> |
12 | 12 |
|
13 | 13 |
<Button |
14 |
android:id="@+id/buttonAdd"
|
|
14 |
android:id="@+id/effects3dButtonAdd"
|
|
15 | 15 |
android:layout_width="wrap_content" |
16 | 16 |
android:layout_height="wrap_content" |
17 |
android:onClick="newEffect" |
|
18 | 17 |
android:text="@string/Add" |
19 | 18 |
/> |
20 | 19 |
|
... | ... | |
32 | 31 |
android:layout_weight="0.5"/> |
33 | 32 |
|
34 | 33 |
<Button |
35 |
android:id="@+id/buttonRemove"
|
|
34 |
android:id="@+id/effects3dButtonRemove"
|
|
36 | 35 |
android:layout_width="wrap_content" |
37 | 36 |
android:layout_height="wrap_content" |
38 |
android:onClick="removeAll" |
|
39 | 37 |
android:text="@string/reset" |
40 | 38 |
/> |
41 | 39 |
|
src/main/res/layout/effects3dtab1.xml | ||
---|---|---|
11 | 11 |
android:orientation="horizontal"> |
12 | 12 |
|
13 | 13 |
<Button |
14 |
android:id="@+id/buttonAdd"
|
|
14 |
android:id="@+id/effects3dButtonAdd"
|
|
15 | 15 |
android:layout_width="wrap_content" |
16 | 16 |
android:layout_height="wrap_content" |
17 |
android:onClick="newEffect" |
|
18 | 17 |
android:text="@string/Add" |
19 | 18 |
/> |
20 | 19 |
|
... | ... | |
32 | 31 |
android:layout_weight="0.5"/> |
33 | 32 |
|
34 | 33 |
<Button |
35 |
android:id="@+id/buttonRemove"
|
|
34 |
android:id="@+id/effects3dButtonRemove"
|
|
36 | 35 |
android:layout_width="wrap_content" |
37 | 36 |
android:layout_height="wrap_content" |
38 |
android:onClick="removeAll" |
|
39 | 37 |
android:text="@string/reset" |
40 | 38 |
/> |
41 | 39 |
|
src/main/res/layout/effects3dtab2.xml | ||
---|---|---|
11 | 11 |
android:orientation="horizontal"> |
12 | 12 |
|
13 | 13 |
<Button |
14 |
android:id="@+id/buttonAdd"
|
|
14 |
android:id="@+id/effects3dButtonAdd"
|
|
15 | 15 |
android:layout_width="wrap_content" |
16 | 16 |
android:layout_height="wrap_content" |
17 |
android:onClick="newEffect" |
|
18 | 17 |
android:text="@string/Add" |
19 | 18 |
/> |
20 | 19 |
|
... | ... | |
32 | 31 |
android:layout_weight="0.5"/> |
33 | 32 |
|
34 | 33 |
<Button |
35 |
android:id="@+id/buttonRemove"
|
|
34 |
android:id="@+id/effects3dButtonRemove"
|
|
36 | 35 |
android:layout_width="wrap_content" |
37 | 36 |
android:layout_height="wrap_content" |
38 |
android:onClick="removeAll" |
|
39 | 37 |
android:text="@string/reset" |
40 | 38 |
/> |
41 | 39 |
|
src/main/res/layout/effects3dtab3.xml | ||
---|---|---|
11 | 11 |
android:orientation="horizontal"> |
12 | 12 |
|
13 | 13 |
<Button |
14 |
android:id="@+id/buttonAdd"
|
|
14 |
android:id="@+id/effects3dButtonAdd"
|
|
15 | 15 |
android:layout_width="wrap_content" |
16 | 16 |
android:layout_height="wrap_content" |
17 |
android:onClick="newEffect" |
|
18 | 17 |
android:text="@string/Add" |
19 | 18 |
/> |
20 | 19 |
|
... | ... | |
32 | 31 |
android:layout_weight="0.5"/> |
33 | 32 |
|
34 | 33 |
<Button |
35 |
android:id="@+id/buttonRemove"
|
|
34 |
android:id="@+id/effects3dButtonRemove"
|
|
36 | 35 |
android:layout_width="wrap_content" |
37 | 36 |
android:layout_height="wrap_content" |
38 |
android:onClick="removeAll" |
|
39 | 37 |
android:text="@string/reset" |
40 | 38 |
/> |
41 | 39 |
|
src/main/res/layout/genericlayout.xml | ||
---|---|---|
5 | 5 |
android:layout_weight="1" |
6 | 6 |
android:orientation="vertical" > |
7 | 7 |
|
8 |
<org.distorted.examples.generic.GenericSurfaceView |
|
9 |
android:id="@+id/genericSurfaceView" |
|
10 |
android:layout_width="fill_parent" |
|
11 |
android:layout_height="0dp" |
|
12 |
android:layout_weight="1" /> |
|
13 |
|
|
14 | 8 |
<LinearLayout |
15 | 9 |
android:layout_width="match_parent" |
16 | 10 |
android:layout_height="32dp" |
... | ... | |
58 | 52 |
|
59 | 53 |
</LinearLayout> |
60 | 54 |
|
55 |
<org.distorted.examples.generic.GenericSurfaceView |
|
56 |
android:id="@+id/genericSurfaceView" |
|
57 |
android:layout_width="fill_parent" |
|
58 |
android:layout_height="0dp" |
|
59 |
android:layout_weight="1" /> |
|
60 |
|
|
61 | 61 |
<android.support.design.widget.TabLayout |
62 | 62 |
android:id="@+id/generic_sliding_tabs" |
63 | 63 |
android:layout_width="match_parent" |
Also available in: Unified diff
Further improvement for the Generic app.