1 |
5b4a2d76
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
8647eae2
|
Leszek Koltunski
|
// Copyright 2019 Leszek Koltunski //
|
3 |
5b4a2d76
|
Leszek Koltunski
|
// //
|
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.rubik;
|
21 |
|
|
|
22 |
|
|
import android.app.Activity;
|
23 |
5d8a1d51
|
Leszek Koltunski
|
import android.graphics.PorterDuff;
|
24 |
201376f3
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
25 |
5b4a2d76
|
Leszek Koltunski
|
import android.os.Bundle;
|
26 |
5d8a1d51
|
Leszek Koltunski
|
import android.support.v4.content.ContextCompat;
|
27 |
201376f3
|
Leszek Koltunski
|
import android.view.View;
|
28 |
5d8a1d51
|
Leszek Koltunski
|
import android.widget.ImageButton;
|
29 |
5b4a2d76
|
Leszek Koltunski
|
|
30 |
201376f3
|
Leszek Koltunski
|
import org.distorted.examples.R;
|
31 |
5b4a2d76
|
Leszek Koltunski
|
import org.distorted.library.main.Distorted;
|
32 |
|
|
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
|
|
public class RubikActivity extends Activity
|
36 |
|
|
{
|
37 |
5d8a1d51
|
Leszek Koltunski
|
static final int DEFAULT_CUBE_SIZE = 3;
|
38 |
|
|
private static final int STARTING_SIZE = 2;
|
39 |
|
|
private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
|
40 |
|
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
5b4a2d76
|
Leszek Koltunski
|
@Override
|
44 |
|
|
protected void onCreate(Bundle icicle)
|
45 |
|
|
{
|
46 |
|
|
super.onCreate(icicle);
|
47 |
201376f3
|
Leszek Koltunski
|
setContentView(R.layout.rubiklayout);
|
48 |
5d8a1d51
|
Leszek Koltunski
|
|
49 |
|
|
markButton(DEFAULT_CUBE_SIZE);
|
50 |
5b4a2d76
|
Leszek Koltunski
|
}
|
51 |
|
|
|
52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53 |
|
|
|
54 |
|
|
@Override
|
55 |
|
|
protected void onPause()
|
56 |
|
|
{
|
57 |
201376f3
|
Leszek Koltunski
|
GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
58 |
|
|
view.onPause();
|
59 |
5b4a2d76
|
Leszek Koltunski
|
Distorted.onPause();
|
60 |
|
|
super.onPause();
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64 |
|
|
|
65 |
|
|
@Override
|
66 |
|
|
protected void onResume()
|
67 |
|
|
{
|
68 |
|
|
super.onResume();
|
69 |
201376f3
|
Leszek Koltunski
|
GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
70 |
|
|
view.onResume();
|
71 |
5b4a2d76
|
Leszek Koltunski
|
}
|
72 |
|
|
|
73 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
|
|
|
75 |
|
|
@Override
|
76 |
|
|
protected void onDestroy()
|
77 |
|
|
{
|
78 |
|
|
Distorted.onDestroy();
|
79 |
|
|
super.onDestroy();
|
80 |
|
|
}
|
81 |
201376f3
|
Leszek Koltunski
|
|
82 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83 |
|
|
|
84 |
|
|
public void Scramble(View v)
|
85 |
|
|
{
|
86 |
5d8a1d51
|
Leszek Koltunski
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
87 |
|
|
view.scrambleCube();
|
88 |
201376f3
|
Leszek Koltunski
|
}
|
89 |
|
|
|
90 |
0094886e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
|
|
public void Credits(View v)
|
93 |
|
|
{
|
94 |
|
|
android.util.Log.e("rubik", "credits...");
|
95 |
|
|
}
|
96 |
|
|
|
97 |
201376f3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
public void setSize(View v)
|
100 |
|
|
{
|
101 |
5d8a1d51
|
Leszek Koltunski
|
int size=0;
|
102 |
|
|
int id = v.getId();
|
103 |
|
|
int numButtons = button_ids.length;
|
104 |
|
|
|
105 |
|
|
for(int b=0; b<numButtons; b++)
|
106 |
|
|
if( button_ids[b] == id )
|
107 |
|
|
{
|
108 |
|
|
size = b+STARTING_SIZE;
|
109 |
|
|
break;
|
110 |
|
|
}
|
111 |
0094886e
|
Leszek Koltunski
|
|
112 |
5d8a1d51
|
Leszek Koltunski
|
markButton(size);
|
113 |
0094886e
|
Leszek Koltunski
|
|
114 |
5d8a1d51
|
Leszek Koltunski
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
115 |
|
|
view.setNewCubeSize(size);
|
116 |
201376f3
|
Leszek Koltunski
|
}
|
117 |
5d8a1d51
|
Leszek Koltunski
|
|
118 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119 |
|
|
|
120 |
|
|
private void markButton(int size)
|
121 |
|
|
{
|
122 |
|
|
int color, numButtons = button_ids.length;
|
123 |
|
|
ImageButton[] button = new ImageButton[numButtons];
|
124 |
|
|
|
125 |
|
|
for(int b=0; b<numButtons; b++)
|
126 |
|
|
{
|
127 |
|
|
button[b] = findViewById(button_ids[b]);
|
128 |
|
|
color = (b==size-STARTING_SIZE ? R.color.red : R.color.gray);
|
129 |
|
|
button[b].getBackground().setColorFilter(ContextCompat.getColor(this,color), PorterDuff.Mode.MULTIPLY);
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
5b4a2d76
|
Leszek Koltunski
|
}
|