Revision 7ba38011
Added by Leszek Koltunski about 8 years ago
src/main/AndroidManifest.xml | ||
---|---|---|
40 | 40 |
<activity android:name=".save.SaveActivity"/> |
41 | 41 |
<activity android:name=".flag.FlagActivity"/> |
42 | 42 |
<activity android:name=".wind.WindActivity"/> |
43 |
<activity android:name=".aroundtheworld.AroundTheWorldActivity"/> |
|
43 | 44 |
</application> |
44 | 45 |
</manifest> |
src/main/java/org/distorted/examples/TableOfContents.java | ||
---|---|---|
34 | 34 |
import android.widget.AdapterView.OnItemClickListener; |
35 | 35 |
import android.widget.SimpleAdapter; |
36 | 36 |
|
37 |
import org.distorted.examples.aroundtheworld.AroundTheWorldActivity; |
|
37 | 38 |
import org.distorted.examples.monalisa.MonaLisaActivity; |
38 | 39 |
import org.distorted.examples.sink.SinkActivity; |
39 | 40 |
import org.distorted.examples.fov.FOVActivity; |
... | ... | |
59 | 60 |
import org.distorted.examples.save.SaveActivity; |
60 | 61 |
import org.distorted.examples.flag.FlagActivity; |
61 | 62 |
import org.distorted.examples.wind.WindActivity; |
63 |
import org.distorted.examples.aroundtheworld.AroundTheWorldActivity; |
|
62 | 64 |
|
63 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 | 66 |
|
... | ... | |
306 | 308 |
activityMapping.put(i++, WindActivity.class); |
307 | 309 |
} |
308 | 310 |
|
311 |
{ |
|
312 |
final Map<String, Object> item = new HashMap<>(); |
|
313 |
item.put(ITEM_IMAGE, R.drawable.icon_example_aroundtheworld); |
|
314 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_aroundtheworld)); |
|
315 |
item.put(ITEM_SUBTITLE, getText(R.string.example_aroundtheworld_subtitle)); |
|
316 |
data.add(item); |
|
317 |
activityMapping.put(i++, AroundTheWorldActivity.class); |
|
318 |
} |
|
319 |
|
|
309 | 320 |
final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle}); |
310 | 321 |
setListAdapter(dataAdapter); |
311 | 322 |
|
src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldActivity.java | ||
---|---|---|
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.aroundtheworld; |
|
21 |
|
|
22 |
import android.app.Activity; |
|
23 |
import android.os.Bundle; |
|
24 |
|
|
25 |
import org.distorted.examples.R; |
|
26 |
import org.distorted.library.Distorted; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
public class AroundTheWorldActivity extends Activity |
|
31 |
{ |
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
@Override |
|
35 |
protected void onCreate(Bundle icicle) |
|
36 |
{ |
|
37 |
super.onCreate(icicle); |
|
38 |
setContentView(R.layout.aroundtheworldlayout); |
|
39 |
} |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void onPause() |
|
45 |
{ |
|
46 |
AroundTheWorldSurfaceView view = (AroundTheWorldSurfaceView) this.findViewById(R.id.aroundTheWorldSurfaceView); |
|
47 |
view.onPause(); |
|
48 |
|
|
49 |
super.onPause(); |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
@Override |
|
55 |
protected void onResume() |
|
56 |
{ |
|
57 |
super.onResume(); |
|
58 |
|
|
59 |
AroundTheWorldSurfaceView view = (AroundTheWorldSurfaceView) this.findViewById(R.id.aroundTheWorldSurfaceView); |
|
60 |
view.onResume(); |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
@Override |
|
66 |
protected void onDestroy() |
|
67 |
{ |
|
68 |
Distorted.onDestroy(); |
|
69 |
super.onDestroy(); |
|
70 |
} |
|
71 |
} |
src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldEffectsManager.java | ||
---|---|---|
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.aroundtheworld; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
import org.distorted.library.DistortedObject; |
|
25 |
import org.distorted.library.type.Dynamic; |
|
26 |
import org.distorted.library.type.Dynamic3D; |
|
27 |
import org.distorted.library.type.Dynamic5D; |
|
28 |
import org.distorted.library.type.Static3D; |
|
29 |
import org.distorted.library.type.Static4D; |
|
30 |
import org.distorted.library.type.Static5D; |
|
31 |
|
|
32 |
class AroundTheWorldEffectsManager |
|
33 |
{ |
|
34 |
private int mHeight, mWidth; |
|
35 |
|
|
36 |
private Static3D shearFactor; |
|
37 |
private Dynamic3D shearDynamic; |
|
38 |
private Static3D scaleFactor; |
|
39 |
private Dynamic3D scaleDynamic; |
|
40 |
private Static3D deformForce; |
|
41 |
private Static5D windFactor11, windFactor12; |
|
42 |
private Dynamic5D windDynamic1; |
|
43 |
private Static5D windFactor21, windFactor22; |
|
44 |
private Dynamic5D windDynamic2; |
|
45 |
private Static5D windFactor31, windFactor32; |
|
46 |
private Dynamic5D windDynamic3; |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
AroundTheWorldEffectsManager(DistortedObject obj) |
|
51 |
{ |
|
52 |
mHeight = obj.getHeight(); |
|
53 |
mWidth = obj.getWidth(); |
|
54 |
|
|
55 |
shearFactor = new Static3D(0,0,0); |
|
56 |
shearDynamic= new Dynamic3D(); |
|
57 |
shearDynamic.add(shearFactor); |
|
58 |
|
|
59 |
scaleFactor = new Static3D(1,1,1); |
|
60 |
scaleDynamic= new Dynamic3D(); |
|
61 |
scaleDynamic.add(scaleFactor); |
|
62 |
|
|
63 |
deformForce = new Static3D(mWidth/3,0,0); |
|
64 |
|
|
65 |
windFactor11 = new Static5D(mHeight/10,mHeight/5, 180, 0, 90); |
|
66 |
windFactor12 = new Static5D(mHeight/10,mHeight/5,-180, 0, 90); |
|
67 |
windDynamic1 = new Dynamic5D(1000,0.0f); |
|
68 |
windDynamic1.add(windFactor11); |
|
69 |
windDynamic1.add(windFactor12); |
|
70 |
windDynamic1.setMode(Dynamic.MODE_JUMP); |
|
71 |
windDynamic1.setAccessMode(Dynamic.ACCESS_SEQUENTIAL); |
|
72 |
|
|
73 |
windFactor21 = new Static5D(mHeight/10,mHeight/5,-180, 90, 10); |
|
74 |
windFactor22 = new Static5D(mHeight/10,mHeight/5,+180, 90, 10); |
|
75 |
windDynamic2 = new Dynamic5D(1000,0.0f); |
|
76 |
windDynamic2.add(windFactor21); |
|
77 |
windDynamic2.add(windFactor22); |
|
78 |
windDynamic2.setMode(Dynamic.MODE_JUMP); |
|
79 |
windDynamic2.setAccessMode(Dynamic.ACCESS_SEQUENTIAL); |
|
80 |
|
|
81 |
windFactor31 = new Static5D(mHeight/10,mHeight/10,-180, 90, 90); |
|
82 |
windFactor32 = new Static5D(mHeight/10,mHeight/10,+180, 90, 90); |
|
83 |
windDynamic3 = new Dynamic5D(1000,0.0f); |
|
84 |
windDynamic3.add(windFactor31); |
|
85 |
windDynamic3.add(windFactor32); |
|
86 |
windDynamic3.setMode(Dynamic.MODE_JUMP); |
|
87 |
windDynamic3.setAccessMode(Dynamic.ACCESS_SEQUENTIAL); |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
synchronized void apply(DistortedObject obj, int wind) |
|
93 |
{ |
|
94 |
Static3D midLeft = new Static3D(0,mHeight/2,0); |
|
95 |
Static3D midRight = new Static3D(mWidth,mHeight/2,0); |
|
96 |
Static4D windRegion = new Static4D(0,0,mWidth,mHeight); |
|
97 |
|
|
98 |
setWind(wind); |
|
99 |
|
|
100 |
obj.shear(shearDynamic,midLeft); |
|
101 |
obj.scale(scaleDynamic); |
|
102 |
obj.deform(deformForce,midRight); |
|
103 |
obj.wave(windDynamic1, midRight, windRegion); |
|
104 |
obj.wave(windDynamic2, midRight, windRegion); |
|
105 |
obj.wave(windDynamic3, midRight, windRegion); |
|
106 |
} |
|
107 |
|
|
108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
109 |
|
|
110 |
synchronized void setWind(int wind) |
|
111 |
{ |
|
112 |
float tanAngle = (wind-50)/50.0f; |
|
113 |
|
|
114 |
shearFactor.set2(tanAngle); |
|
115 |
scaleFactor.set1(1/(float)Math.sqrt(1+tanAngle*tanAngle)); |
|
116 |
windDynamic1.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE); |
|
117 |
windDynamic2.setDuration( wind > 0 ? 80000/wind : Long.MAX_VALUE); |
|
118 |
windDynamic3.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE); |
|
119 |
|
|
120 |
float waveA = (mHeight/(20.0f-0.15f*wind)); |
|
121 |
windFactor21.set1(waveA); |
|
122 |
windFactor22.set1(waveA); |
|
123 |
|
|
124 |
float waveB = (mHeight/(wind+5.0f)); |
|
125 |
windFactor31.set1(waveB); |
|
126 |
windFactor32.set1(waveB); |
|
127 |
} |
|
128 |
} |
src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java | ||
---|---|---|
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.aroundtheworld; |
|
21 |
|
|
22 |
import android.graphics.Bitmap; |
|
23 |
import android.graphics.BitmapFactory; |
|
24 |
import android.opengl.GLES20; |
|
25 |
import android.opengl.GLSurfaceView; |
|
26 |
|
|
27 |
import org.distorted.examples.R; |
|
28 |
import org.distorted.library.Distorted; |
|
29 |
import org.distorted.library.DistortedBitmap; |
|
30 |
import org.distorted.library.DistortedCubes; |
|
31 |
import org.distorted.library.DistortedObject; |
|
32 |
import org.distorted.library.EffectTypes; |
|
33 |
import org.distorted.library.type.Static1D; |
|
34 |
import org.distorted.library.type.Static3D; |
|
35 |
|
|
36 |
import java.io.IOException; |
|
37 |
import java.io.InputStream; |
|
38 |
|
|
39 |
import javax.microedition.khronos.egl.EGLConfig; |
|
40 |
import javax.microedition.khronos.opengles.GL10; |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
class AroundTheWorldRenderer implements GLSurfaceView.Renderer |
|
45 |
{ |
|
46 |
private GLSurfaceView mView; |
|
47 |
private DistortedObject mObject; |
|
48 |
private AroundTheWorldEffectsManager mEffects; |
|
49 |
private int mObjWidth, mObjHeight; |
|
50 |
|
|
51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
52 |
|
|
53 |
AroundTheWorldRenderer(GLSurfaceView view) |
|
54 |
{ |
|
55 |
mView = view; |
|
56 |
} |
|
57 |
|
|
58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
|
60 |
public void onDrawFrame(GL10 glUnused) |
|
61 |
{ |
|
62 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
63 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
|
64 |
|
|
65 |
mObject.draw(System.currentTimeMillis()); |
|
66 |
} |
|
67 |
|
|
68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
69 |
|
|
70 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
71 |
{ |
|
72 |
mObject.abortEffects(EffectTypes.MATRIX); |
|
73 |
|
|
74 |
if( mObjHeight/mObjWidth > height/width ) |
|
75 |
{ |
|
76 |
int w = (height*mObjWidth)/mObjHeight; |
|
77 |
float factor = (float)height/mObjHeight; |
|
78 |
mObject.move( new Static3D((width-w)/2,0,0) ); |
|
79 |
mObject.scale(factor); |
|
80 |
} |
|
81 |
else |
|
82 |
{ |
|
83 |
int h = (width*mObjHeight)/mObjWidth; |
|
84 |
float factor = (float)width/mObjWidth; |
|
85 |
mObject.move( new Static3D(0,(height-h)/2,0) ); |
|
86 |
mObject.scale(factor); |
|
87 |
} |
|
88 |
|
|
89 |
Distorted.onSurfaceChanged(width, height); |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
95 |
{ |
|
96 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.face); |
|
97 |
Bitmap bitmap; |
|
98 |
|
|
99 |
try |
|
100 |
{ |
|
101 |
bitmap = BitmapFactory.decodeStream(is); |
|
102 |
} |
|
103 |
finally |
|
104 |
{ |
|
105 |
try |
|
106 |
{ |
|
107 |
is.close(); |
|
108 |
} |
|
109 |
catch(IOException e) { } |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
mObject = new DistortedBitmap(bitmap.getWidth(),bitmap.getHeight(),30); |
|
114 |
mEffects = new AroundTheWorldEffectsManager(mObject); |
|
115 |
|
|
116 |
mObjWidth = mObject.getWidth(); |
|
117 |
mObjHeight= mObject.getHeight(); |
|
118 |
|
|
119 |
mObject.setBitmap(bitmap); |
|
120 |
|
|
121 |
try |
|
122 |
{ |
|
123 |
Distorted.onSurfaceCreated(mView.getContext()); |
|
124 |
} |
|
125 |
catch(Exception ex) |
|
126 |
{ |
|
127 |
android.util.Log.e("AroundTheWorld", ex.getMessage() ); |
|
128 |
} |
|
129 |
} |
|
130 |
} |
src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldSurfaceView.java | ||
---|---|---|
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.aroundtheworld; |
|
21 |
|
|
22 |
import android.content.Context; |
|
23 |
import android.opengl.GLSurfaceView; |
|
24 |
import android.os.Build; |
|
25 |
import android.util.AttributeSet; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class AroundTheWorldSurfaceView extends GLSurfaceView |
|
30 |
{ |
|
31 |
private AroundTheWorldRenderer mRenderer; |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 |
public AroundTheWorldSurfaceView(Context c, AttributeSet attrs) |
|
36 |
{ |
|
37 |
super(c, attrs); |
|
38 |
|
|
39 |
if(!isInEditMode()) |
|
40 |
{ |
|
41 |
setEGLContextClientVersion(2); |
|
42 |
|
|
43 |
if( Build.FINGERPRINT.startsWith("generic") ) |
|
44 |
{ |
|
45 |
setEGLConfigChooser(8, 8, 8, 8, 16, 0); |
|
46 |
} |
|
47 |
|
|
48 |
mRenderer = new AroundTheWorldRenderer(this); |
|
49 |
setRenderer(mRenderer); |
|
50 |
} |
|
51 |
} |
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
public AroundTheWorldRenderer getRenderer() |
|
55 |
{ |
|
56 |
return mRenderer; |
|
57 |
} |
|
58 |
} |
|
59 |
|
src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldSurfaceViewPicker.java | ||
---|---|---|
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.aroundtheworld; |
|
21 |
|
|
22 |
import android.content.Context; |
|
23 |
import android.graphics.Canvas; |
|
24 |
import android.util.AttributeSet; |
|
25 |
import android.view.MotionEvent; |
|
26 |
import android.view.SurfaceHolder; |
|
27 |
import android.view.SurfaceView; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
class AroundTheWorldSurfaceViewPicker extends SurfaceView implements SurfaceHolder.Callback |
|
32 |
{ |
|
33 |
private static final int FRAME_INTERVAL = 70; |
|
34 |
|
|
35 |
private boolean refreshScreen = true; |
|
36 |
private boolean mFinishedBooting=false; |
|
37 |
private int scrWidth, scrHeight; |
|
38 |
private GraphicsThread mThread; |
|
39 |
private int mX, mY; |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
private class GraphicsThread extends Thread |
|
44 |
{ |
|
45 |
private SurfaceHolder mSurfaceHolder; |
|
46 |
private AroundTheWorldSurfaceViewPicker mPicker; |
|
47 |
private boolean mRun = false; |
|
48 |
|
|
49 |
///////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
GraphicsThread(SurfaceHolder surfaceHolder, AroundTheWorldSurfaceViewPicker p) |
|
52 |
{ |
|
53 |
mSurfaceHolder = surfaceHolder; |
|
54 |
mPicker = p; |
|
55 |
} |
|
56 |
|
|
57 |
///////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
void setRunning(boolean run) |
|
60 |
{ |
|
61 |
mRun = run; |
|
62 |
} |
|
63 |
|
|
64 |
///////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
public void run() |
|
67 |
{ |
|
68 |
Canvas c; |
|
69 |
long time; |
|
70 |
|
|
71 |
while (mRun) |
|
72 |
{ |
|
73 |
c = null; |
|
74 |
time = 0; |
|
75 |
|
|
76 |
if( refreshScreen && mFinishedBooting ) |
|
77 |
{ |
|
78 |
refreshScreen=false; |
|
79 |
time = System.currentTimeMillis(); |
|
80 |
|
|
81 |
try |
|
82 |
{ |
|
83 |
c = mSurfaceHolder.lockCanvas(null); |
|
84 |
synchronized (mSurfaceHolder) { mPicker.draw(c); } |
|
85 |
} |
|
86 |
finally |
|
87 |
{ |
|
88 |
if (c != null) mSurfaceHolder.unlockCanvasAndPost(c); |
|
89 |
} |
|
90 |
|
|
91 |
time = System.currentTimeMillis() -time; |
|
92 |
} |
|
93 |
|
|
94 |
if( time<FRAME_INTERVAL ) |
|
95 |
{ |
|
96 |
try { Thread.sleep(FRAME_INTERVAL-time); } |
|
97 |
catch(InterruptedException ex) {} |
|
98 |
} |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
|
105 |
public AroundTheWorldSurfaceViewPicker(Context c, AttributeSet attrs) |
|
106 |
{ |
|
107 |
super(c, attrs); |
|
108 |
|
|
109 |
mX = -100; |
|
110 |
mY = -100; |
|
111 |
|
|
112 |
getHolder().addCallback(this); |
|
113 |
setFocusable(true); |
|
114 |
setFocusableInTouchMode(true); |
|
115 |
|
|
116 |
mFinishedBooting=true; |
|
117 |
} |
|
118 |
|
|
119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
120 |
|
|
121 |
public void surfaceCreated(SurfaceHolder holder) |
|
122 |
{ |
|
123 |
android.util.Log.e( "Picker", "surfaceCreated"); |
|
124 |
|
|
125 |
mThread = new GraphicsThread(getHolder(), this); |
|
126 |
mThread.setRunning(true); |
|
127 |
mThread.start(); |
|
128 |
} |
|
129 |
|
|
130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 |
|
|
132 |
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) |
|
133 |
{ |
|
134 |
android.util.Log.e( "Picker", "surfaceChanged: width="+w+" height="+h); |
|
135 |
|
|
136 |
scrWidth = w; |
|
137 |
scrHeight= h; |
|
138 |
refreshScreen = true; |
|
139 |
} |
|
140 |
|
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
public void surfaceDestroyed(SurfaceHolder holder) |
|
144 |
{ |
|
145 |
android.util.Log.e( "Picker", "surfaceDestroyed"); |
|
146 |
|
|
147 |
stopThread(); |
|
148 |
} |
|
149 |
|
|
150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
151 |
|
|
152 |
private void stopThread() |
|
153 |
{ |
|
154 |
if( mThread!=null ) |
|
155 |
{ |
|
156 |
boolean retry = true; |
|
157 |
mThread.setRunning(false); |
|
158 |
|
|
159 |
while (retry) |
|
160 |
{ |
|
161 |
try |
|
162 |
{ |
|
163 |
mThread.join(); |
|
164 |
retry = false; |
|
165 |
} |
|
166 |
catch (InterruptedException e) { android.util.Log.e( "Picker", "Joining thread interrupted!"); } |
|
167 |
} |
|
168 |
|
|
169 |
mThread=null; |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
174 |
|
|
175 |
public void draw(Canvas c) |
|
176 |
{ |
|
177 |
if( c!=null ) |
|
178 |
{ |
|
179 |
|
|
180 |
} |
|
181 |
} |
|
182 |
|
|
183 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
184 |
|
|
185 |
public void setRepaint() |
|
186 |
{ |
|
187 |
refreshScreen=true; |
|
188 |
} |
|
189 |
|
|
190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 |
|
|
192 |
public boolean onTouchEvent(MotionEvent event) |
|
193 |
{ |
|
194 |
mX = (int)event.getX(); |
|
195 |
mY = (int)event.getY(); |
|
196 |
|
|
197 |
android.util.Log.e( "Picker", "onTouchEvent: x="+mX+" y="+mY); |
|
198 |
|
|
199 |
setRepaint(); |
|
200 |
|
|
201 |
return true; |
|
202 |
} |
|
203 |
} |
src/main/res/layout/aroundtheworldlayout.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<org.distorted.examples.aroundtheworld.AroundTheWorldSurfaceView |
|
8 |
android:id="@+id/aroundTheWorldSurfaceView" |
|
9 |
android:layout_width="fill_parent" |
|
10 |
android:layout_height="0dp" |
|
11 |
android:layout_weight="1" /> |
|
12 |
|
|
13 |
<Space |
|
14 |
android:layout_width="match_parent" |
|
15 |
android:layout_height="5dp"/> |
|
16 |
|
|
17 |
<org.distorted.examples.aroundtheworld.AroundTheWorldSurfaceViewPicker |
|
18 |
android:id="@+id/aroundTheWorldSurfaceViewPicker" |
|
19 |
android:layout_width="fill_parent" |
|
20 |
android:layout_height="0dp" |
|
21 |
android:layout_weight="0.6" /> |
|
22 |
|
|
23 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
108 | 108 |
<string name="example_flag_subtitle">See the WAVE effect.</string> |
109 | 109 |
<string name="example_wind">Variable wind</string> |
110 | 110 |
<string name="example_wind_subtitle">A couple of effects put together to create an effect of a waving flag.</string> |
111 |
<string name="example_aroundtheworld">Around the World</string> |
|
112 |
<string name="example_aroundtheworld_subtitle">Combine several effects to change facial features.</string> |
|
111 | 113 |
|
112 | 114 |
<string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string> |
113 | 115 |
<string name="example_rotate_toast">Rotate the scene by swiping the screen</string> |
Also available in: Unified diff
New app: Around The World (beginnings)