1 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
1c04d054
|
leszek
|
// Copyright 2023 Leszek Koltunski //
|
3 |
0c52af30
|
Leszek Koltunski
|
// //
|
4 |
fdec60a3
|
Leszek Koltunski
|
// This file is part of Magic Cube. //
|
5 |
0c52af30
|
Leszek Koltunski
|
// //
|
6 |
296219b4
|
Leszek Koltunski
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.main;
|
11 |
0c52af30
|
Leszek Koltunski
|
|
12 |
b6468abb
|
Leszek Koltunski
|
import android.content.Intent;
|
13 |
33499c56
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
14 |
4c9947bd
|
Leszek Koltunski
|
import android.content.pm.PackageInfo;
|
15 |
|
|
import android.content.pm.PackageManager;
|
16 |
b42c8399
|
leszek
|
import android.content.res.Configuration;
|
17 |
b1e9596b
|
Leszek Koltunski
|
import android.os.Build;
|
18 |
0c52af30
|
Leszek Koltunski
|
import android.os.Bundle;
|
19 |
e3c74c0f
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
20 |
1c04d054
|
leszek
|
import android.util.TypedValue;
|
21 |
fd0b901a
|
Leszek Koltunski
|
import android.view.DisplayCutout;
|
22 |
0254cfd7
|
Leszek Koltunski
|
import android.view.View;
|
23 |
1cb36646
|
Leszek Koltunski
|
import android.view.ViewGroup;
|
24 |
c9556e1e
|
Leszek Koltunski
|
import android.view.WindowManager;
|
25 |
1cb36646
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
26 |
1c04d054
|
leszek
|
import android.widget.ScrollView;
|
27 |
|
|
import android.widget.TextView;
|
28 |
0c52af30
|
Leszek Koltunski
|
|
29 |
b42c8399
|
leszek
|
import androidx.annotation.NonNull;
|
30 |
e019c70b
|
Leszek Koltunski
|
import androidx.appcompat.app.AppCompatActivity;
|
31 |
ada8ab26
|
leszek
|
import androidx.preference.PreferenceManager;
|
32 |
e019c70b
|
Leszek Koltunski
|
|
33 |
1b3cbd5b
|
Leszek Koltunski
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
34 |
a59f38d6
|
Leszek Koltunski
|
import com.google.firebase.inappmessaging.FirebaseInAppMessaging;
|
35 |
1b3cbd5b
|
Leszek Koltunski
|
|
36 |
7ee8337b
|
leszek
|
import org.distorted.bandaged.BandagedActivity;
|
37 |
58fd2ec0
|
leszek
|
import org.distorted.config.ConfigActivity;
|
38 |
5b22f901
|
leszek
|
import org.distorted.info.InfoActivity;
|
39 |
e71baee1
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogAbout;
|
40 |
1c04d054
|
leszek
|
import org.distorted.dialogs.RubikDialogCreators;
|
41 |
|
|
import org.distorted.dialogs.RubikDialogExit;
|
42 |
|
|
import org.distorted.dialogs.RubikDialogScores;
|
43 |
|
|
import org.distorted.dialogs.RubikDialogUpdates;
|
44 |
acabdd83
|
Leszek Koltunski
|
import org.distorted.external.RubikNetwork;
|
45 |
1c04d054
|
leszek
|
import org.distorted.external.RubikScores;
|
46 |
|
|
import org.distorted.external.RubikUpdates;
|
47 |
|
|
import org.distorted.messaging.RubikInAppMessanging;
|
48 |
7ee8337b
|
leszek
|
import org.distorted.objects.RubikObject;
|
49 |
d433b50e
|
Leszek Koltunski
|
import org.distorted.objects.RubikObjectList;
|
50 |
e9245b7b
|
leszek
|
import org.distorted.patternui.PatternActivity;
|
51 |
7ee8337b
|
leszek
|
import org.distorted.playui.PlayActivity;
|
52 |
cb30e768
|
leszek
|
import org.distorted.solverui.SolverActivity;
|
53 |
eaf87d1d
|
Leszek Koltunski
|
import org.distorted.tutorials.TutorialActivity;
|
54 |
211b48f2
|
Leszek Koltunski
|
|
55 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56 |
|
|
|
57 |
c02235d5
|
leszek
|
public class MainActivity extends AppCompatActivity implements RubikNetwork.Updatee, RubikDialogScores.ScoresInvoker
|
58 |
0c52af30
|
Leszek Koltunski
|
{
|
59 |
1c04d054
|
leszek
|
public static final float RATIO_BAR = 0.080f;
|
60 |
af7b68e6
|
Leszek Koltunski
|
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
61 |
ffd68f35
|
Leszek Koltunski
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
62 |
|
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
63 |
|
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
64 |
|
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
65 |
|
|
|
66 |
c3ffcf58
|
Leszek Koltunski
|
private boolean mJustStarted;
|
67 |
1b3cbd5b
|
Leszek Koltunski
|
private FirebaseAnalytics mFirebaseAnalytics;
|
68 |
0254cfd7
|
Leszek Koltunski
|
private int mCurrentApiVersion;
|
69 |
d05e7629
|
Leszek Koltunski
|
private String mOldVersion, mCurrVersion;
|
70 |
c820515c
|
leszek
|
private int mScreenWidth, mScreenHeight;
|
71 |
1c04d054
|
leszek
|
private TextView mBubbleUpdates;
|
72 |
|
|
private int mNumUpdates;
|
73 |
c02235d5
|
leszek
|
private int mCurrentObject;
|
74 |
1c04d054
|
leszek
|
private MainScrollGrid mGrid;
|
75 |
def32b2c
|
leszek
|
private int mSortMode;
|
76 |
c3ffcf58
|
Leszek Koltunski
|
|
77 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
|
|
|
79 |
0c52af30
|
Leszek Koltunski
|
@Override
|
80 |
34747dd1
|
Leszek Koltunski
|
protected void onCreate(Bundle savedState)
|
81 |
0c52af30
|
Leszek Koltunski
|
{
|
82 |
34747dd1
|
Leszek Koltunski
|
super.onCreate(savedState);
|
83 |
dd874ae8
|
Leszek Koltunski
|
setTheme(R.style.MaterialThemeNoActionBar);
|
84 |
cb30e768
|
leszek
|
setContentView(R.layout.main);
|
85 |
a7327225
|
leszek
|
hideNavigationBar();
|
86 |
c3ffcf58
|
Leszek Koltunski
|
|
87 |
c02235d5
|
leszek
|
mCurrentObject = 0;
|
88 |
c3ffcf58
|
Leszek Koltunski
|
mJustStarted = true;
|
89 |
1b3cbd5b
|
Leszek Koltunski
|
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
|
90 |
e3c74c0f
|
Leszek Koltunski
|
|
91 |
e8f6670f
|
Leszek Koltunski
|
cutoutHack();
|
92 |
1c04d054
|
leszek
|
computeHeights();
|
93 |
a59f38d6
|
Leszek Koltunski
|
|
94 |
e9e744f7
|
Leszek Koltunski
|
mCurrVersion = getAppVers();
|
95 |
|
|
|
96 |
c02235d5
|
leszek
|
mBubbleUpdates = findViewById(R.id.bubbleUpdates);
|
97 |
|
|
mBubbleUpdates.setVisibility(View.INVISIBLE);
|
98 |
|
|
mNumUpdates = 0;
|
99 |
|
|
|
100 |
83018ac4
|
Leszek Koltunski
|
Thread thread = new Thread()
|
101 |
|
|
{
|
102 |
|
|
public void run()
|
103 |
|
|
{
|
104 |
|
|
RubikInAppMessanging listener = new RubikInAppMessanging();
|
105 |
|
|
FirebaseInAppMessaging.getInstance().addClickListener(listener);
|
106 |
|
|
}
|
107 |
|
|
};
|
108 |
|
|
|
109 |
|
|
thread.start();
|
110 |
0254cfd7
|
Leszek Koltunski
|
}
|
111 |
|
|
|
112 |
598de3ee
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
|
|
// this does not include possible insets
|
114 |
|
|
|
115 |
1c04d054
|
leszek
|
private void computeHeights()
|
116 |
598de3ee
|
Leszek Koltunski
|
{
|
117 |
b42c8399
|
leszek
|
LinearLayout.LayoutParams pU = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, RATIO_BAR);
|
118 |
214e301a
|
Leszek Koltunski
|
LinearLayout layoutTop = findViewById(R.id.upperBar);
|
119 |
b42c8399
|
leszek
|
layoutTop.setLayoutParams(pU);
|
120 |
1c04d054
|
leszek
|
|
121 |
b42c8399
|
leszek
|
LinearLayout.LayoutParams pS = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1-2*RATIO_BAR);
|
122 |
1c04d054
|
leszek
|
ScrollView scroll = findViewById(R.id.objectScroll);
|
123 |
b42c8399
|
leszek
|
scroll.setLayoutParams(pS);
|
124 |
|
|
|
125 |
|
|
LinearLayout.LayoutParams pL = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, RATIO_BAR);
|
126 |
|
|
LinearLayout layoutBot = findViewById(R.id.lowerBar);
|
127 |
|
|
layoutBot.setLayoutParams(pL);
|
128 |
598de3ee
|
Leszek Koltunski
|
}
|
129 |
|
|
|
130 |
0254cfd7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131 |
|
|
|
132 |
|
|
private void hideNavigationBar()
|
133 |
|
|
{
|
134 |
c9556e1e
|
Leszek Koltunski
|
mCurrentApiVersion = Build.VERSION.SDK_INT;
|
135 |
0254cfd7
|
Leszek Koltunski
|
|
136 |
|
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
|
137 |
|
|
{
|
138 |
|
|
final View decorView = getWindow().getDecorView();
|
139 |
|
|
|
140 |
c9556e1e
|
Leszek Koltunski
|
decorView.setSystemUiVisibility(FLAGS);
|
141 |
|
|
|
142 |
0254cfd7
|
Leszek Koltunski
|
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
|
143 |
|
|
{
|
144 |
|
|
@Override
|
145 |
|
|
public void onSystemUiVisibilityChange(int visibility)
|
146 |
|
|
{
|
147 |
|
|
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
|
148 |
|
|
{
|
149 |
ffd68f35
|
Leszek Koltunski
|
decorView.setSystemUiVisibility(FLAGS);
|
150 |
0254cfd7
|
Leszek Koltunski
|
}
|
151 |
|
|
}
|
152 |
|
|
});
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
|
|
|
156 |
1cb36646
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
157 |
|
|
|
158 |
|
|
@Override
|
159 |
|
|
public void onAttachedToWindow()
|
160 |
|
|
{
|
161 |
fd0b901a
|
Leszek Koltunski
|
super.onAttachedToWindow();
|
162 |
|
|
|
163 |
b42c8399
|
leszek
|
getWindowWidth(getResources().getConfiguration());
|
164 |
|
|
mGrid = new MainScrollGrid();
|
165 |
def32b2c
|
leszek
|
mGrid.createGrid(this,mScreenWidth,mSortMode);
|
166 |
b42c8399
|
leszek
|
|
167 |
ada8ab26
|
leszek
|
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P )
|
168 |
e8f6670f
|
Leszek Koltunski
|
{
|
169 |
|
|
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
|
170 |
|
|
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
|
171 |
|
|
|
172 |
b42c8399
|
leszek
|
if( insetHeight>0 )
|
173 |
|
|
{
|
174 |
|
|
LinearLayout.LayoutParams pH = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, RATIO_BAR);
|
175 |
|
|
LinearLayout layoutHid = findViewById(R.id.hiddenBar);
|
176 |
|
|
layoutHid.setLayoutParams(pH);
|
177 |
|
|
|
178 |
|
|
LinearLayout.LayoutParams pS = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1-3*RATIO_BAR);
|
179 |
|
|
ScrollView scroll = findViewById(R.id.objectScroll);
|
180 |
|
|
scroll.setLayoutParams(pS);
|
181 |
|
|
}
|
182 |
e8f6670f
|
Leszek Koltunski
|
}
|
183 |
1cb36646
|
Leszek Koltunski
|
}
|
184 |
|
|
|
185 |
0254cfd7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
186 |
e8f6670f
|
Leszek Koltunski
|
// do not avoid cutouts
|
187 |
c9556e1e
|
Leszek Koltunski
|
|
188 |
e8f6670f
|
Leszek Koltunski
|
private void cutoutHack()
|
189 |
c9556e1e
|
Leszek Koltunski
|
{
|
190 |
ada8ab26
|
leszek
|
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P )
|
191 |
c9556e1e
|
Leszek Koltunski
|
{
|
192 |
|
|
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
|
|
|
196 |
b42c8399
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
197 |
|
|
|
198 |
|
|
private void getWindowWidth(Configuration conf)
|
199 |
|
|
{
|
200 |
|
|
int dpi = getResources().getDisplayMetrics().densityDpi;
|
201 |
|
|
float conv = ((float) dpi/DisplayMetrics.DENSITY_DEFAULT);
|
202 |
|
|
|
203 |
|
|
mScreenWidth = (int) (conf.screenWidthDp*conv + 0.5f);
|
204 |
c820515c
|
leszek
|
mScreenHeight= (int) (conf.screenHeightDp*conv + 0.5f);
|
205 |
b42c8399
|
leszek
|
}
|
206 |
|
|
|
207 |
c9556e1e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208 |
0254cfd7
|
Leszek Koltunski
|
|
209 |
|
|
@Override
|
210 |
|
|
public void onWindowFocusChanged(boolean hasFocus)
|
211 |
|
|
{
|
212 |
|
|
super.onWindowFocusChanged(hasFocus);
|
213 |
|
|
|
214 |
ada8ab26
|
leszek
|
if( mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus )
|
215 |
0254cfd7
|
Leszek Koltunski
|
{
|
216 |
ffd68f35
|
Leszek Koltunski
|
getWindow().getDecorView().setSystemUiVisibility(FLAGS);
|
217 |
0254cfd7
|
Leszek Koltunski
|
}
|
218 |
|
|
}
|
219 |
|
|
|
220 |
b42c8399
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221 |
|
|
|
222 |
|
|
@Override
|
223 |
|
|
public void onConfigurationChanged(@NonNull Configuration conf)
|
224 |
|
|
{
|
225 |
|
|
super.onConfigurationChanged(conf);
|
226 |
|
|
|
227 |
|
|
getWindowWidth(conf);
|
228 |
9a092737
|
leszek
|
if( mGrid!=null ) mGrid.updateGrid(this,mScreenWidth);
|
229 |
b42c8399
|
leszek
|
}
|
230 |
|
|
|
231 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232 |
|
|
|
233 |
|
|
@Override
|
234 |
|
|
protected void onPause()
|
235 |
|
|
{
|
236 |
82f42eeb
|
Leszek Koltunski
|
super.onPause();
|
237 |
6a083c6a
|
Leszek Koltunski
|
RubikNetwork.onPause();
|
238 |
33499c56
|
Leszek Koltunski
|
savePreferences();
|
239 |
0c52af30
|
Leszek Koltunski
|
}
|
240 |
|
|
|
241 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
242 |
|
|
|
243 |
|
|
@Override
|
244 |
|
|
protected void onResume()
|
245 |
|
|
{
|
246 |
|
|
super.onResume();
|
247 |
51853bf2
|
Leszek Koltunski
|
|
248 |
6142069a
|
Leszek Koltunski
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
249 |
|
|
restorePreferences(preferences,mJustStarted);
|
250 |
1c04d054
|
leszek
|
|
251 |
c02235d5
|
leszek
|
RubikNetwork network = RubikNetwork.getInstance();
|
252 |
|
|
network.signUpForUpdates(this);
|
253 |
1c04d054
|
leszek
|
|
254 |
c3ffcf58
|
Leszek Koltunski
|
if( mJustStarted )
|
255 |
|
|
{
|
256 |
|
|
mJustStarted = false;
|
257 |
72d3d383
|
leszek
|
|
258 |
|
|
network.downloadUpdates(this);
|
259 |
82ce8e64
|
Leszek Koltunski
|
RubikScores scores = RubikScores.getInstance();
|
260 |
|
|
scores.incrementNumRuns();
|
261 |
|
|
scores.setCountry(this);
|
262 |
c3ffcf58
|
Leszek Koltunski
|
}
|
263 |
|
|
|
264 |
ada8ab26
|
leszek
|
if( !mOldVersion.equals(mCurrVersion) ) displayNovelties();
|
265 |
0c52af30
|
Leszek Koltunski
|
}
|
266 |
d05e7629
|
Leszek Koltunski
|
|
267 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
268 |
|
|
|
269 |
1c89e2a7
|
Leszek Koltunski
|
private void displayNovelties()
|
270 |
d05e7629
|
Leszek Koltunski
|
{
|
271 |
1c89e2a7
|
Leszek Koltunski
|
Bundle bundle = new Bundle();
|
272 |
34d6b123
|
Leszek Koltunski
|
bundle.putString("argument",mOldVersion);
|
273 |
e71baee1
|
Leszek Koltunski
|
RubikDialogAbout newDialog = new RubikDialogAbout();
|
274 |
1c89e2a7
|
Leszek Koltunski
|
newDialog.setArguments(bundle);
|
275 |
e71baee1
|
Leszek Koltunski
|
newDialog.show(getSupportFragmentManager(), RubikDialogAbout.getDialogTag() );
|
276 |
d05e7629
|
Leszek Koltunski
|
}
|
277 |
|
|
|
278 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
279 |
|
|
|
280 |
|
|
@Override
|
281 |
|
|
protected void onDestroy()
|
282 |
|
|
{
|
283 |
|
|
super.onDestroy();
|
284 |
|
|
}
|
285 |
|
|
|
286 |
4c9947bd
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
287 |
|
|
|
288 |
b20e89d2
|
Leszek Koltunski
|
private String getAppVers()
|
289 |
4c9947bd
|
Leszek Koltunski
|
{
|
290 |
b20e89d2
|
Leszek Koltunski
|
try
|
291 |
|
|
{
|
292 |
|
|
PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
|
293 |
|
|
return pInfo.versionName;
|
294 |
|
|
}
|
295 |
1c04d054
|
leszek
|
catch( PackageManager.NameNotFoundException e )
|
296 |
b20e89d2
|
Leszek Koltunski
|
{
|
297 |
|
|
return "unknown";
|
298 |
|
|
}
|
299 |
4c9947bd
|
Leszek Koltunski
|
}
|
300 |
|
|
|
301 |
33499c56
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
302 |
|
|
|
303 |
|
|
private void savePreferences()
|
304 |
|
|
{
|
305 |
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
306 |
|
|
SharedPreferences.Editor editor = preferences.edit();
|
307 |
|
|
|
308 |
e9e744f7
|
Leszek Koltunski
|
editor.putString("appVersion", mCurrVersion );
|
309 |
def32b2c
|
leszek
|
editor.putInt("sortMode", mSortMode);
|
310 |
b1e9596b
|
Leszek Koltunski
|
|
311 |
400ff34d
|
Leszek Koltunski
|
RubikObjectList.savePreferences(editor);
|
312 |
2e3488f6
|
Leszek Koltunski
|
|
313 |
abc1e5af
|
leszek
|
RubikScores scores = RubikScores.getInstance();
|
314 |
|
|
scores.savePreferences(editor);
|
315 |
|
|
|
316 |
7480fbab
|
Leszek Koltunski
|
boolean success = editor.commit();
|
317 |
|
|
if( !success ) android.util.Log.e("D", "Failed to save preferences");
|
318 |
33499c56
|
Leszek Koltunski
|
}
|
319 |
|
|
|
320 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
321 |
|
|
|
322 |
6142069a
|
Leszek Koltunski
|
private void restorePreferences(SharedPreferences preferences, boolean justStarted)
|
323 |
33499c56
|
Leszek Koltunski
|
{
|
324 |
d05e7629
|
Leszek Koltunski
|
mOldVersion = preferences.getString("appVersion","");
|
325 |
417d51b6
|
leszek
|
mSortMode = preferences.getInt("sortMode", MainSettingsPopup.SORT_DEFAULT);
|
326 |
872307fe
|
Leszek Koltunski
|
|
327 |
7480fbab
|
Leszek Koltunski
|
RubikObjectList.restorePreferences(this,preferences,justStarted);
|
328 |
e9e744f7
|
Leszek Koltunski
|
RubikScores scores = RubikScores.getInstance();
|
329 |
abc1e5af
|
leszek
|
scores.restorePreferences(preferences);
|
330 |
e9e744f7
|
Leszek Koltunski
|
|
331 |
|
|
if( scores.isVerified() )
|
332 |
|
|
{
|
333 |
|
|
FirebaseAnalytics analytics = getAnalytics();
|
334 |
|
|
analytics.setUserId(scores.getName());
|
335 |
|
|
}
|
336 |
|
|
}
|
337 |
ee4e7896
|
Leszek Koltunski
|
|
338 |
e9e744f7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
339 |
ee4e7896
|
Leszek Koltunski
|
|
340 |
b42c8399
|
leszek
|
private void updateBubble(int num)
|
341 |
e9e744f7
|
Leszek Koltunski
|
{
|
342 |
b42c8399
|
leszek
|
runOnUiThread(new Runnable()
|
343 |
|
|
{
|
344 |
|
|
@Override
|
345 |
|
|
public void run()
|
346 |
|
|
{
|
347 |
|
|
mNumUpdates = num;
|
348 |
00fcfefa
|
Leszek Koltunski
|
|
349 |
b42c8399
|
leszek
|
if( num>0 )
|
350 |
|
|
{
|
351 |
|
|
String shownNum = String.valueOf(num);
|
352 |
|
|
mBubbleUpdates.setText(shownNum);
|
353 |
|
|
mBubbleUpdates.setVisibility(View.VISIBLE);
|
354 |
|
|
int height = (int)(0.05f*mScreenWidth);
|
355 |
|
|
mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height);
|
356 |
|
|
}
|
357 |
|
|
else
|
358 |
|
|
{
|
359 |
|
|
mBubbleUpdates.setVisibility(View.INVISIBLE);
|
360 |
|
|
}
|
361 |
|
|
}
|
362 |
|
|
});
|
363 |
f3e12931
|
Leszek Koltunski
|
}
|
364 |
|
|
|
365 |
2e3488f6
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
366 |
b42c8399
|
leszek
|
// PUBLIC API
|
367 |
2d9fc972
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
368 |
|
|
|
369 |
b42c8399
|
leszek
|
public FirebaseAnalytics getAnalytics()
|
370 |
2d9fc972
|
Leszek Koltunski
|
{
|
371 |
b42c8399
|
leszek
|
return mFirebaseAnalytics;
|
372 |
2d9fc972
|
Leszek Koltunski
|
}
|
373 |
|
|
|
374 |
c02235d5
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
375 |
|
|
|
376 |
|
|
public int getObjectOrdinal()
|
377 |
|
|
{
|
378 |
|
|
return mCurrentObject;
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
382 |
|
|
|
383 |
|
|
public void setCurrentObject(int current)
|
384 |
|
|
{
|
385 |
|
|
mCurrentObject = current;
|
386 |
|
|
}
|
387 |
|
|
|
388 |
1b3cbd5b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
389 |
|
|
|
390 |
b710a574
|
leszek
|
public void switchToTutorial(int objectOrdinal)
|
391 |
1b3cbd5b
|
Leszek Koltunski
|
{
|
392 |
1c04d054
|
leszek
|
Intent intent = new Intent(this, TutorialActivity.class);
|
393 |
|
|
intent.putExtra("obj", objectOrdinal);
|
394 |
|
|
startActivity(intent);
|
395 |
1b3cbd5b
|
Leszek Koltunski
|
}
|
396 |
|
|
|
397 |
598de3ee
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
398 |
|
|
|
399 |
5b22f901
|
leszek
|
public void switchToInfo(int objectOrdinal)
|
400 |
598de3ee
|
Leszek Koltunski
|
{
|
401 |
5b22f901
|
leszek
|
Intent intent = new Intent(this, InfoActivity.class);
|
402 |
1c04d054
|
leszek
|
intent.putExtra("obj", objectOrdinal);
|
403 |
|
|
startActivity(intent);
|
404 |
598de3ee
|
Leszek Koltunski
|
}
|
405 |
|
|
|
406 |
58fd2ec0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
407 |
|
|
|
408 |
|
|
public void switchToConfig(int objectOrdinal)
|
409 |
|
|
{
|
410 |
|
|
Intent intent = new Intent(this, ConfigActivity.class);
|
411 |
|
|
intent.putExtra("obj", objectOrdinal);
|
412 |
|
|
startActivity(intent);
|
413 |
|
|
}
|
414 |
|
|
|
415 |
a6d3b158
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
416 |
|
|
|
417 |
1c04d054
|
leszek
|
public void switchToBandagedCreator(int objectOrdinal)
|
418 |
aa171dee
|
Leszek Koltunski
|
{
|
419 |
7ee8337b
|
leszek
|
Intent intent = new Intent(this, BandagedActivity.class);
|
420 |
1c04d054
|
leszek
|
intent.putExtra("obj", objectOrdinal);
|
421 |
|
|
startActivity(intent);
|
422 |
8becce57
|
Leszek Koltunski
|
}
|
423 |
|
|
|
424 |
d7f0c07d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
425 |
|
|
|
426 |
cb30e768
|
leszek
|
public void switchToSolver(int objectOrdinal)
|
427 |
d7f0c07d
|
Leszek Koltunski
|
{
|
428 |
cb30e768
|
leszek
|
Intent intent = new Intent(this, SolverActivity.class);
|
429 |
1c04d054
|
leszek
|
intent.putExtra("obj", objectOrdinal);
|
430 |
|
|
startActivity(intent);
|
431 |
d7f0c07d
|
Leszek Koltunski
|
}
|
432 |
|
|
|
433 |
e9245b7b
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
434 |
|
|
|
435 |
|
|
public void switchToPattern(int objectOrdinal)
|
436 |
|
|
{
|
437 |
|
|
Intent intent = new Intent(this, PatternActivity.class);
|
438 |
|
|
intent.putExtra("obj", objectOrdinal);
|
439 |
|
|
startActivity(intent);
|
440 |
|
|
}
|
441 |
|
|
|
442 |
7ee8337b
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
443 |
|
|
|
444 |
1a206525
|
leszek
|
public void switchToPlay(RubikObject object, int ordinal, int scrambles, int level)
|
445 |
7ee8337b
|
leszek
|
{
|
446 |
5a2a7682
|
leszek
|
boolean local = object.isLocal();
|
447 |
|
|
String name = local ? object.getLowerName() : object.getUpperName();
|
448 |
|
|
|
449 |
7ee8337b
|
leszek
|
Intent intent = new Intent(this, PlayActivity.class);
|
450 |
7bb30586
|
leszek
|
intent.putExtra("level", level);
|
451 |
5a2a7682
|
leszek
|
intent.putExtra("name", name );
|
452 |
7ee8337b
|
leszek
|
intent.putExtra("scrambles", scrambles);
|
453 |
5a2a7682
|
leszek
|
intent.putExtra("local", local );
|
454 |
1a206525
|
leszek
|
intent.putExtra("ordinal", ordinal );
|
455 |
7ee8337b
|
leszek
|
startActivity(intent);
|
456 |
|
|
}
|
457 |
|
|
|
458 |
8ba7aeb1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
459 |
|
|
|
460 |
1c04d054
|
leszek
|
public void onScores(View v)
|
461 |
8ba7aeb1
|
Leszek Koltunski
|
{
|
462 |
1c04d054
|
leszek
|
Bundle sBundle = new Bundle();
|
463 |
|
|
sBundle.putString("argument", "false");
|
464 |
|
|
RubikDialogScores scores = new RubikDialogScores();
|
465 |
|
|
scores.setArguments(sBundle);
|
466 |
|
|
scores.show(getSupportFragmentManager(), null);
|
467 |
aa171dee
|
Leszek Koltunski
|
}
|
468 |
|
|
|
469 |
12a991f2
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
470 |
|
|
|
471 |
|
|
public void onSettings(View v)
|
472 |
|
|
{
|
473 |
c820515c
|
leszek
|
int sw = (int)(mScreenWidth*0.7);
|
474 |
|
|
int sh = (int)(mScreenHeight*0.2f);
|
475 |
12a991f2
|
leszek
|
|
476 |
c820515c
|
leszek
|
int vw = v.getWidth();
|
477 |
|
|
|
478 |
acee3e3e
|
leszek
|
MainSettingsPopup popup = new MainSettingsPopup(this,mSortMode,mScreenWidth,mScreenHeight);
|
479 |
c820515c
|
leszek
|
popup.displayPopup(this,v,sw,sh,(int)((vw-sw)/2),0);
|
480 |
12a991f2
|
leszek
|
}
|
481 |
|
|
|
482 |
aa171dee
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
483 |
|
|
|
484 |
1c04d054
|
leszek
|
public void onUpdates(View v)
|
485 |
769d7b9f
|
Leszek Koltunski
|
{
|
486 |
1c04d054
|
leszek
|
RubikDialogUpdates diag = new RubikDialogUpdates();
|
487 |
|
|
diag.show( getSupportFragmentManager(), RubikDialogUpdates.getDialogTag() );
|
488 |
b20e89d2
|
Leszek Koltunski
|
}
|
489 |
|
|
|
490 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
491 |
7eae2d49
|
Leszek Koltunski
|
|
492 |
1c04d054
|
leszek
|
public void onExit(View v)
|
493 |
b20e89d2
|
Leszek Koltunski
|
{
|
494 |
1c04d054
|
leszek
|
RubikDialogExit diag = new RubikDialogExit();
|
495 |
|
|
diag.show(getSupportFragmentManager(), null);
|
496 |
2e8ec627
|
Leszek Koltunski
|
}
|
497 |
|
|
|
498 |
b1e9596b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
499 |
|
|
|
500 |
1c04d054
|
leszek
|
public void onAbout(View v)
|
501 |
b6468abb
|
Leszek Koltunski
|
{
|
502 |
1c04d054
|
leszek
|
RubikDialogAbout diag = new RubikDialogAbout();
|
503 |
|
|
diag.show(getSupportFragmentManager(), null);
|
504 |
b6468abb
|
Leszek Koltunski
|
}
|
505 |
1237d25d
|
Leszek Koltunski
|
|
506 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
507 |
|
|
|
508 |
1c04d054
|
leszek
|
public void onBandage(View v)
|
509 |
1237d25d
|
Leszek Koltunski
|
{
|
510 |
1c04d054
|
leszek
|
RubikDialogCreators diag = new RubikDialogCreators();
|
511 |
|
|
diag.show(getSupportFragmentManager(), RubikDialogCreators.getDialogTag() );
|
512 |
9530f6b0
|
Leszek Koltunski
|
}
|
513 |
|
|
|
514 |
c7238c67
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
515 |
|
|
|
516 |
1c04d054
|
leszek
|
public void receiveUpdate(RubikUpdates updates)
|
517 |
c7238c67
|
Leszek Koltunski
|
{
|
518 |
1c04d054
|
leszek
|
int num = updates.getCompletedNumber();
|
519 |
|
|
updateBubble(num);
|
520 |
c7238c67
|
Leszek Koltunski
|
}
|
521 |
|
|
|
522 |
41a5dd89
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
523 |
|
|
|
524 |
1c04d054
|
leszek
|
public void objectDownloaded(String shortName)
|
525 |
41a5dd89
|
Leszek Koltunski
|
{
|
526 |
1c04d054
|
leszek
|
mNumUpdates--;
|
527 |
|
|
updateBubble(mNumUpdates);
|
528 |
b42c8399
|
leszek
|
mGrid.updateGrid(this,mScreenWidth);
|
529 |
41a5dd89
|
Leszek Koltunski
|
}
|
530 |
67d7fb28
|
Leszek Koltunski
|
|
531 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
532 |
|
|
|
533 |
1c04d054
|
leszek
|
public int getType()
|
534 |
67d7fb28
|
Leszek Koltunski
|
{
|
535 |
1c04d054
|
leszek
|
return 0;
|
536 |
67d7fb28
|
Leszek Koltunski
|
}
|
537 |
|
|
|
538 |
def32b2c
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
539 |
|
|
|
540 |
|
|
public void sortObjectsBy(int sortMode)
|
541 |
|
|
{
|
542 |
|
|
mSortMode = sortMode;
|
543 |
|
|
mGrid.createGrid(this,mScreenWidth,mSortMode);
|
544 |
|
|
}
|
545 |
|
|
|
546 |
67d7fb28
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
547 |
|
|
|
548 |
1c04d054
|
leszek
|
public void errorUpdate()
|
549 |
67d7fb28
|
Leszek Koltunski
|
{
|
550 |
1c04d054
|
leszek
|
android.util.Log.e("D", "NewRubikActivity: Error receiving downloaded objects update");
|
551 |
67d7fb28
|
Leszek Koltunski
|
}
|
552 |
0c52af30
|
Leszek Koltunski
|
}
|