1 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
fdec60a3
|
Leszek Koltunski
|
// This file is part of Magic Cube. //
|
5 |
0c52af30
|
Leszek Koltunski
|
// //
|
6 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
0c52af30
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
0c52af30
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.main;
|
21 |
0c52af30
|
Leszek Koltunski
|
|
22 |
33499c56
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
23 |
0c52af30
|
Leszek Koltunski
|
import android.os.Bundle;
|
24 |
33499c56
|
Leszek Koltunski
|
import android.preference.PreferenceManager;
|
25 |
66e777b0
|
Leszek Koltunski
|
import androidx.appcompat.app.AppCompatActivity;
|
26 |
e3c74c0f
|
Leszek Koltunski
|
|
27 |
|
|
import android.util.DisplayMetrics;
|
28 |
0c52af30
|
Leszek Koltunski
|
|
29 |
1b3cbd5b
|
Leszek Koltunski
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
30 |
|
|
|
31 |
2d9fc972
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogError;
|
32 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.effects.BaseEffect;
|
33 |
e1111500
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
34 |
0c52af30
|
Leszek Koltunski
|
|
35 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
36 |
c3ffcf58
|
Leszek Koltunski
|
import org.distorted.scores.RubikScores;
|
37 |
f0e87514
|
Leszek Koltunski
|
import org.distorted.scores.RubikScoresDownloader;
|
38 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.objects.RubikObjectList;
|
39 |
|
|
import org.distorted.states.RubikState;
|
40 |
|
|
import org.distorted.states.RubikStatePlay;
|
41 |
211b48f2
|
Leszek Koltunski
|
|
42 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
a6d3b158
|
Leszek Koltunski
|
public class RubikActivity extends AppCompatActivity
|
45 |
0c52af30
|
Leszek Koltunski
|
{
|
46 |
054fbee1
|
Leszek Koltunski
|
public static final float PADDING = 0.01f;
|
47 |
|
|
public static final float MARGIN = 0.004f;
|
48 |
|
|
public static final float LARGE_MARGIN = 0.025f;
|
49 |
|
|
public static final float BUTTON_TEXT_SIZE = 0.05f;
|
50 |
|
|
public static final float TITLE_TEXT_SIZE = 0.06f;
|
51 |
6d4d56cb
|
Leszek Koltunski
|
public static final float BITMAP_TEXT_SIZE = 0.05f;
|
52 |
054fbee1
|
Leszek Koltunski
|
public static final float MENU_ITEM_SIZE = 0.12f;
|
53 |
5de2c572
|
Leszek Koltunski
|
public static final float PATTERN_GROUP_TEXT = 0.03f;
|
54 |
|
|
public static final float PATTERN_CHILD_TEXT = 0.02f;
|
55 |
362807f0
|
Leszek Koltunski
|
public static final float SCORES_LEVEL_TEXT = 0.035f;
|
56 |
|
|
public static final float SCORES_ITEM_TEXT = 0.030f;
|
57 |
2eb74743
|
Leszek Koltunski
|
|
58 |
|
|
public static final float MENU_BIG_TEXT_SIZE = 0.05f;
|
59 |
|
|
public static final float MENU_MEDIUM_TEXT_SIZE= 0.04f;
|
60 |
|
|
public static final float MENU_SMALL_TEXT_SIZE = 0.035f;
|
61 |
e3c74c0f
|
Leszek Koltunski
|
|
62 |
c3ffcf58
|
Leszek Koltunski
|
private boolean mJustStarted;
|
63 |
1b3cbd5b
|
Leszek Koltunski
|
private FirebaseAnalytics mFirebaseAnalytics;
|
64 |
f6a9c538
|
Leszek Koltunski
|
private static int mScreenWidth, mScreenHeight;
|
65 |
c3ffcf58
|
Leszek Koltunski
|
|
66 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
|
|
|
68 |
0c52af30
|
Leszek Koltunski
|
@Override
|
69 |
34747dd1
|
Leszek Koltunski
|
protected void onCreate(Bundle savedState)
|
70 |
0c52af30
|
Leszek Koltunski
|
{
|
71 |
34747dd1
|
Leszek Koltunski
|
super.onCreate(savedState);
|
72 |
f6fcf06a
|
Leszek Koltunski
|
setTheme(R.style.CustomActivityThemeNoActionBar);
|
73 |
1cbcc6bf
|
Leszek Koltunski
|
setContentView(R.layout.main);
|
74 |
c3ffcf58
|
Leszek Koltunski
|
|
75 |
|
|
mJustStarted = true;
|
76 |
1b3cbd5b
|
Leszek Koltunski
|
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
|
77 |
e3c74c0f
|
Leszek Koltunski
|
|
78 |
|
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
79 |
|
|
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
80 |
88fb92ba
|
Leszek Koltunski
|
mScreenWidth =displaymetrics.widthPixels;
|
81 |
|
|
mScreenHeight=displaymetrics.heightPixels;
|
82 |
0c52af30
|
Leszek Koltunski
|
}
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
|
86 |
|
|
@Override
|
87 |
|
|
protected void onPause()
|
88 |
|
|
{
|
89 |
4235de9b
|
Leszek Koltunski
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
90 |
0c52af30
|
Leszek Koltunski
|
view.onPause();
|
91 |
e1111500
|
Leszek Koltunski
|
DistortedLibrary.onPause();
|
92 |
f3e12931
|
Leszek Koltunski
|
RubikScoresDownloader.onPause();
|
93 |
33499c56
|
Leszek Koltunski
|
savePreferences();
|
94 |
0c52af30
|
Leszek Koltunski
|
super.onPause();
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
@Override
|
100 |
|
|
protected void onResume()
|
101 |
|
|
{
|
102 |
|
|
super.onResume();
|
103 |
4235de9b
|
Leszek Koltunski
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
104 |
0c52af30
|
Leszek Koltunski
|
view.onResume();
|
105 |
e03e0352
|
Leszek Koltunski
|
view.initialize();
|
106 |
33499c56
|
Leszek Koltunski
|
restorePreferences();
|
107 |
211b48f2
|
Leszek Koltunski
|
RubikState.setState(this);
|
108 |
4888e97c
|
Leszek Koltunski
|
|
109 |
c3ffcf58
|
Leszek Koltunski
|
if( mJustStarted )
|
110 |
|
|
{
|
111 |
|
|
mJustStarted = false;
|
112 |
82ce8e64
|
Leszek Koltunski
|
RubikScores scores = RubikScores.getInstance();
|
113 |
|
|
scores.incrementNumRuns();
|
114 |
|
|
scores.setCountry(this);
|
115 |
c3ffcf58
|
Leszek Koltunski
|
}
|
116 |
|
|
|
117 |
53f23b64
|
Leszek Koltunski
|
boolean success = false;
|
118 |
e41e7dc3
|
Leszek Koltunski
|
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
119 |
4888e97c
|
Leszek Koltunski
|
int object = play.getObject();
|
120 |
|
|
int size = play.getSize();
|
121 |
|
|
|
122 |
4c0cd600
|
Leszek Koltunski
|
if( object>=0 && object<RubikObjectList.NUM_OBJECTS )
|
123 |
|
|
{
|
124 |
|
|
RubikObjectList obj = RubikObjectList.getObject(object);
|
125 |
|
|
int[] sizes = obj.getSizes();
|
126 |
53f23b64
|
Leszek Koltunski
|
int sizeIndex = RubikObjectList.getSizeIndex(object,size);
|
127 |
4c0cd600
|
Leszek Koltunski
|
|
128 |
53f23b64
|
Leszek Koltunski
|
if( sizeIndex>=0 && sizeIndex<sizes.length )
|
129 |
4c0cd600
|
Leszek Koltunski
|
{
|
130 |
53f23b64
|
Leszek Koltunski
|
success = true;
|
131 |
5a4d4fba
|
Leszek Koltunski
|
view.getPreRender().changeObject(obj,size);
|
132 |
4c0cd600
|
Leszek Koltunski
|
}
|
133 |
53f23b64
|
Leszek Koltunski
|
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
if( !success )
|
137 |
|
|
{
|
138 |
|
|
RubikObjectList obj = RubikObjectList.getObject(RubikStatePlay.DEF_OBJECT);
|
139 |
|
|
int s = RubikStatePlay.DEF_SIZE;
|
140 |
|
|
|
141 |
7b7d65ce
|
Leszek Koltunski
|
play.setObjectAndSize(this,obj,s);
|
142 |
5a4d4fba
|
Leszek Koltunski
|
view.getPreRender().changeObject(obj,s);
|
143 |
4c0cd600
|
Leszek Koltunski
|
}
|
144 |
0c52af30
|
Leszek Koltunski
|
}
|
145 |
|
|
|
146 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147 |
|
|
|
148 |
|
|
@Override
|
149 |
|
|
protected void onDestroy()
|
150 |
|
|
{
|
151 |
e1111500
|
Leszek Koltunski
|
DistortedLibrary.onDestroy();
|
152 |
0c52af30
|
Leszek Koltunski
|
super.onDestroy();
|
153 |
|
|
}
|
154 |
|
|
|
155 |
33499c56
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156 |
|
|
|
157 |
|
|
private void savePreferences()
|
158 |
|
|
{
|
159 |
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
160 |
|
|
SharedPreferences.Editor editor = preferences.edit();
|
161 |
|
|
|
162 |
211b48f2
|
Leszek Koltunski
|
for (int i=0; i<BaseEffect.Type.LENGTH; i++)
|
163 |
33499c56
|
Leszek Koltunski
|
{
|
164 |
|
|
BaseEffect.Type.getType(i).savePreferences(editor);
|
165 |
|
|
}
|
166 |
|
|
|
167 |
211b48f2
|
Leszek Koltunski
|
for (int i=0; i<RubikState.LENGTH; i++)
|
168 |
|
|
{
|
169 |
|
|
RubikState.getState(i).getStateClass().savePreferences(editor);
|
170 |
|
|
}
|
171 |
33499c56
|
Leszek Koltunski
|
|
172 |
211b48f2
|
Leszek Koltunski
|
RubikState.savePreferences(editor);
|
173 |
0333d81e
|
Leszek Koltunski
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
174 |
5a4d4fba
|
Leszek Koltunski
|
view.getPreRender().savePreferences(editor);
|
175 |
0333d81e
|
Leszek Koltunski
|
|
176 |
33499c56
|
Leszek Koltunski
|
editor.apply();
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
180 |
|
|
|
181 |
|
|
private void restorePreferences()
|
182 |
|
|
{
|
183 |
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
184 |
|
|
|
185 |
|
|
for (int i=0; i< BaseEffect.Type.LENGTH; i++)
|
186 |
4235de9b
|
Leszek Koltunski
|
{
|
187 |
33499c56
|
Leszek Koltunski
|
BaseEffect.Type.getType(i).restorePreferences(preferences);
|
188 |
4235de9b
|
Leszek Koltunski
|
}
|
189 |
33499c56
|
Leszek Koltunski
|
|
190 |
211b48f2
|
Leszek Koltunski
|
for (int i=0; i< RubikState.LENGTH; i++)
|
191 |
|
|
{
|
192 |
|
|
RubikState.getState(i).getStateClass().restorePreferences(preferences);
|
193 |
|
|
}
|
194 |
33499c56
|
Leszek Koltunski
|
|
195 |
211b48f2
|
Leszek Koltunski
|
RubikState.restorePreferences(preferences);
|
196 |
0333d81e
|
Leszek Koltunski
|
|
197 |
|
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
198 |
5a4d4fba
|
Leszek Koltunski
|
view.getPreRender().restorePreferences(preferences);
|
199 |
f3e12931
|
Leszek Koltunski
|
}
|
200 |
|
|
|
201 |
2d9fc972
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
202 |
|
|
|
203 |
|
|
void OpenGLError(String message)
|
204 |
|
|
{
|
205 |
|
|
Bundle bundle = new Bundle();
|
206 |
|
|
bundle.putString("error", message );
|
207 |
|
|
|
208 |
|
|
RubikDialogError errDiag = new RubikDialogError();
|
209 |
|
|
errDiag.setArguments(bundle);
|
210 |
|
|
errDiag.show(getSupportFragmentManager(), null);
|
211 |
|
|
}
|
212 |
|
|
|
213 |
34747dd1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214 |
47ba5ddc
|
Leszek Koltunski
|
// PUBLIC API
|
215 |
1b3cbd5b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
216 |
|
|
|
217 |
|
|
public FirebaseAnalytics getAnalytics()
|
218 |
|
|
{
|
219 |
|
|
return mFirebaseAnalytics;
|
220 |
|
|
}
|
221 |
|
|
|
222 |
a6d3b158
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
223 |
|
|
|
224 |
aa171dee
|
Leszek Koltunski
|
public RubikObject getObject()
|
225 |
|
|
{
|
226 |
|
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
227 |
5a4d4fba
|
Leszek Koltunski
|
RubikPreRender pre = view.getPreRender();
|
228 |
|
|
return pre.getObject();
|
229 |
8becce57
|
Leszek Koltunski
|
}
|
230 |
|
|
|
231 |
e3c74c0f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232 |
|
|
|
233 |
88fb92ba
|
Leszek Koltunski
|
public int getScreenWidthInPixels()
|
234 |
e3c74c0f
|
Leszek Koltunski
|
{
|
235 |
|
|
return mScreenWidth;
|
236 |
|
|
}
|
237 |
|
|
|
238 |
88fb92ba
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
239 |
|
|
|
240 |
|
|
public int getScreenHeightInPixels()
|
241 |
|
|
{
|
242 |
|
|
return mScreenHeight;
|
243 |
|
|
}
|
244 |
|
|
|
245 |
8becce57
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
246 |
|
|
|
247 |
5a4d4fba
|
Leszek Koltunski
|
public RubikPreRender getPreRender()
|
248 |
8becce57
|
Leszek Koltunski
|
{
|
249 |
|
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
250 |
5a4d4fba
|
Leszek Koltunski
|
return view.getPreRender();
|
251 |
aa171dee
|
Leszek Koltunski
|
}
|
252 |
|
|
|
253 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
254 |
|
|
|
255 |
7eae2d49
|
Leszek Koltunski
|
public void changeObject(RubikObjectList newObject, int newSize, boolean reportChange)
|
256 |
769d7b9f
|
Leszek Koltunski
|
{
|
257 |
|
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
258 |
5a4d4fba
|
Leszek Koltunski
|
RubikPreRender pre = view.getPreRender();
|
259 |
7eae2d49
|
Leszek Koltunski
|
|
260 |
|
|
if( reportChange )
|
261 |
|
|
{
|
262 |
|
|
RubikObject oldObject = pre.getObject();
|
263 |
|
|
RubikObjectList oldList = oldObject.getObjectList();
|
264 |
|
|
int oldSize = oldObject.getSize();
|
265 |
|
|
float fps = view.getRenderer().getFPS();
|
266 |
|
|
StringBuilder name = new StringBuilder();
|
267 |
|
|
name.append(oldList.name());
|
268 |
|
|
name.append('_');
|
269 |
|
|
name.append(oldSize);
|
270 |
|
|
name.append(' ');
|
271 |
|
|
name.append(fps);
|
272 |
|
|
name.append(" --> ");
|
273 |
|
|
name.append(newObject.name());
|
274 |
|
|
name.append('_');
|
275 |
|
|
name.append(newSize);
|
276 |
|
|
|
277 |
|
|
if( BuildConfig.DEBUG )
|
278 |
|
|
{
|
279 |
|
|
android.util.Log.e("rubik", name.toString());
|
280 |
|
|
}
|
281 |
|
|
else
|
282 |
|
|
{
|
283 |
|
|
FirebaseAnalytics analytics = getAnalytics();
|
284 |
|
|
|
285 |
|
|
if( analytics!=null )
|
286 |
|
|
{
|
287 |
|
|
Bundle bundle = new Bundle();
|
288 |
|
|
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString());
|
289 |
|
|
analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle);
|
290 |
|
|
}
|
291 |
|
|
}
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
pre.changeObject(newObject,newSize);
|
295 |
2e8ec627
|
Leszek Koltunski
|
}
|
296 |
|
|
|
297 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
298 |
|
|
|
299 |
|
|
public void setupObject(RubikObjectList object, int size, int[][] moves)
|
300 |
|
|
{
|
301 |
|
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
302 |
5a4d4fba
|
Leszek Koltunski
|
RubikPreRender pre = view.getPreRender();
|
303 |
|
|
pre.setupObject(object,size,moves);
|
304 |
769d7b9f
|
Leszek Koltunski
|
}
|
305 |
|
|
|
306 |
f6a9c538
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
307 |
|
|
|
308 |
|
|
public static int getDrawableSize()
|
309 |
|
|
{
|
310 |
|
|
if( mScreenHeight<1000 )
|
311 |
|
|
{
|
312 |
|
|
//android.util.Log.e("view", "returning small, mScrH="+mScreenHeight);
|
313 |
|
|
return 0;
|
314 |
|
|
}
|
315 |
|
|
if( mScreenHeight<1600 )
|
316 |
|
|
{
|
317 |
|
|
//android.util.Log.e("view", "returning medium, mScrH="+mScreenHeight);
|
318 |
|
|
return 1;
|
319 |
|
|
}
|
320 |
31a9f38d
|
Leszek Koltunski
|
if( mScreenHeight<1900 )
|
321 |
|
|
{
|
322 |
|
|
//android.util.Log.e("view", "returning bug, mScrH="+mScreenHeight);
|
323 |
|
|
return 2;
|
324 |
|
|
}
|
325 |
f6a9c538
|
Leszek Koltunski
|
|
326 |
31a9f38d
|
Leszek Koltunski
|
//android.util.Log.e("view", "returning huge, mScrH="+mScreenHeight);
|
327 |
|
|
return 3;
|
328 |
f6a9c538
|
Leszek Koltunski
|
}
|
329 |
|
|
|
330 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
331 |
|
|
|
332 |
31a9f38d
|
Leszek Koltunski
|
public static int getDrawable(int small, int medium, int big, int huge)
|
333 |
f6a9c538
|
Leszek Koltunski
|
{
|
334 |
|
|
int size = getDrawableSize();
|
335 |
|
|
|
336 |
|
|
switch(size)
|
337 |
|
|
{
|
338 |
|
|
case 0 : return small;
|
339 |
|
|
case 1 : return medium;
|
340 |
31a9f38d
|
Leszek Koltunski
|
case 2 : return big;
|
341 |
|
|
default: return huge;
|
342 |
f6a9c538
|
Leszek Koltunski
|
}
|
343 |
|
|
}
|
344 |
|
|
|
345 |
769d7b9f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
346 |
|
|
|
347 |
|
|
public boolean isVertical()
|
348 |
|
|
{
|
349 |
|
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
350 |
|
|
return view.isVertical();
|
351 |
|
|
}
|
352 |
0c52af30
|
Leszek Koltunski
|
}
|