Revision 201376f3
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/examples/rubik/RubikActivity.java | ||
---|---|---|
20 | 20 |
package org.distorted.examples.rubik; |
21 | 21 |
|
22 | 22 |
import android.app.Activity; |
23 |
import android.opengl.GLSurfaceView; |
|
23 | 24 |
import android.os.Bundle; |
25 |
import android.view.View; |
|
24 | 26 |
|
27 |
import org.distorted.examples.R; |
|
25 | 28 |
import org.distorted.library.main.Distorted; |
26 | 29 |
|
27 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
28 | 31 |
|
29 | 32 |
public class RubikActivity extends Activity |
30 | 33 |
{ |
31 |
private RubikSurfaceView mView; |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 | 34 |
@Override |
36 | 35 |
protected void onCreate(Bundle icicle) |
37 | 36 |
{ |
38 | 37 |
super.onCreate(icicle); |
39 |
mView = new RubikSurfaceView(this); |
|
40 |
setContentView(mView); |
|
38 |
setContentView(R.layout.rubiklayout); |
|
41 | 39 |
} |
42 | 40 |
|
43 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
45 | 43 |
@Override |
46 | 44 |
protected void onPause() |
47 | 45 |
{ |
48 |
mView.onPause(); |
|
46 |
GLSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
47 |
view.onPause(); |
|
49 | 48 |
Distorted.onPause(); |
50 | 49 |
super.onPause(); |
51 | 50 |
} |
... | ... | |
56 | 55 |
protected void onResume() |
57 | 56 |
{ |
58 | 57 |
super.onResume(); |
59 |
mView.onResume(); |
|
58 |
GLSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
59 |
view.onResume(); |
|
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
67 | 67 |
Distorted.onDestroy(); |
68 | 68 |
super.onDestroy(); |
69 | 69 |
} |
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
public void Scramble(View v) |
|
74 |
{ |
|
75 |
android.util.Log.e("rubik", "scrambling..."); |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
public void setSize(View v) |
|
81 |
{ |
|
82 |
android.util.Log.e("rubik", "setting size..."); |
|
83 |
} |
|
70 | 84 |
} |
src/main/java/org/distorted/examples/rubik/RubikSurfaceView.java | ||
---|---|---|
23 | 23 |
import android.content.Context; |
24 | 24 |
import android.content.pm.ConfigurationInfo; |
25 | 25 |
import android.opengl.GLSurfaceView; |
26 |
import android.util.AttributeSet; |
|
26 | 27 |
import android.view.MotionEvent; |
27 | 28 |
|
28 | 29 |
import org.distorted.library.type.Static4D; |
... | ... | |
59 | 60 |
|
60 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 62 |
|
62 |
public RubikSurfaceView(Context context) |
|
63 |
public RubikSurfaceView(Context context, AttributeSet attrs)
|
|
63 | 64 |
{ |
64 |
super(context); |
|
65 |
super(context,attrs);
|
|
65 | 66 |
|
66 |
mRotationVect = VECT[0]; |
|
67 |
if(!isInEditMode()) |
|
68 |
{ |
|
69 |
mRotationVect = VECT[0]; |
|
67 | 70 |
|
68 |
mPoint = new float[3]; |
|
69 |
mCamera= new float[3]; |
|
70 |
mDiff = new float[3]; |
|
71 |
mTouchPoint = new float[3]; |
|
72 |
mTouchPointCastOntoFace = new float[3]; |
|
71 |
mPoint = new float[3];
|
|
72 |
mCamera= new float[3];
|
|
73 |
mDiff = new float[3];
|
|
74 |
mTouchPoint = new float[3];
|
|
75 |
mTouchPointCastOntoFace = new float[3];
|
|
73 | 76 |
|
74 |
mScreenWidth = mScreenHeight = mScreenMin = 0; |
|
77 |
mScreenWidth = mScreenHeight = mScreenMin = 0;
|
|
75 | 78 |
|
76 |
mRenderer = new RubikRenderer(this); |
|
77 |
mCube = mRenderer.getCube(); |
|
79 |
mRenderer = new RubikRenderer(this);
|
|
80 |
mCube = mRenderer.getCube();
|
|
78 | 81 |
|
79 |
mQuatCurrent = new Static4D(0,0,0,1); |
|
80 |
mQuatAccumulated = mRenderer.initializeQuat(); |
|
82 |
mQuatCurrent = new Static4D(0,0,0,1);
|
|
83 |
mQuatAccumulated = mRenderer.initializeQuat();
|
|
81 | 84 |
|
82 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
83 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
84 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
85 |
setRenderer(mRenderer); |
|
85 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
86 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
87 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
88 |
setRenderer(mRenderer); |
|
89 |
} |
|
86 | 90 |
} |
87 | 91 |
|
88 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/res/layout/rubiklayout.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 |
<LinearLayout |
|
8 |
android:id="@+id/linearLayout" |
|
9 |
android:layout_width="fill_parent" |
|
10 |
android:layout_height="wrap_content" |
|
11 |
android:gravity="center|fill_horizontal" |
|
12 |
android:paddingBottom="10dp" |
|
13 |
android:paddingTop="10dp" > |
|
14 |
|
|
15 |
<Button |
|
16 |
android:id="@+id/rubikSize2" |
|
17 |
android:layout_width="wrap_content" |
|
18 |
android:layout_height="wrap_content" |
|
19 |
android:layout_marginLeft="2dp" |
|
20 |
android:layout_marginRight="2dp" |
|
21 |
android:layout_weight="0.17" |
|
22 |
android:onClick="setSize" |
|
23 |
android:paddingLeft="5dp" |
|
24 |
android:paddingRight="5dp" |
|
25 |
android:text="@string/swirl" /> |
|
26 |
|
|
27 |
<Button |
|
28 |
android:id="@+id/rubikSize3" |
|
29 |
android:layout_width="wrap_content" |
|
30 |
android:layout_height="wrap_content" |
|
31 |
android:layout_marginLeft="2dp" |
|
32 |
android:layout_marginRight="2dp" |
|
33 |
android:layout_weight="0.17" |
|
34 |
android:onClick="setSize" |
|
35 |
android:paddingLeft="5dp" |
|
36 |
android:paddingRight="5dp" |
|
37 |
android:text="@string/bubble" /> |
|
38 |
|
|
39 |
<Button |
|
40 |
android:id="@+id/rubikSize4" |
|
41 |
android:layout_width="54dp" |
|
42 |
android:layout_height="wrap_content" |
|
43 |
android:layout_marginLeft="2dp" |
|
44 |
android:layout_marginRight="2dp" |
|
45 |
android:layout_weight="0.17" |
|
46 |
android:onClick="setSize" |
|
47 |
android:paddingLeft="5dp" |
|
48 |
android:paddingRight="5dp" |
|
49 |
android:text="@string/sink" /> |
|
50 |
|
|
51 |
<Button |
|
52 |
android:id="@+id/rubikScramble" |
|
53 |
android:layout_width="wrap_content" |
|
54 |
android:layout_height="wrap_content" |
|
55 |
android:layout_marginLeft="2dp" |
|
56 |
android:layout_marginRight="2dp" |
|
57 |
android:layout_weight="0.17" |
|
58 |
android:onClick="Scramble" |
|
59 |
android:paddingLeft="5dp" |
|
60 |
android:paddingRight="5dp" |
|
61 |
android:text="@string/alpha" /> |
|
62 |
|
|
63 |
</LinearLayout> |
|
64 |
|
|
65 |
<org.distorted.examples.rubik.RubikSurfaceView |
|
66 |
android:id="@+id/rubikSurfaceView" |
|
67 |
android:layout_width="fill_parent" |
|
68 |
android:layout_height="0dp" |
|
69 |
android:layout_weight="1" /> |
|
70 |
|
|
71 |
</LinearLayout> |
Also available in: Unified diff
Rubk App: add 4 buttons in the top.