1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// 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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.screens;
|
11
|
|
12
|
import android.content.SharedPreferences;
|
13
|
import android.os.Bundle;
|
14
|
|
15
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
16
|
|
17
|
import org.distorted.main.RubikActivity;
|
18
|
import static org.distorted.objectlib.main.ObjectControl.*;
|
19
|
|
20
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
21
|
|
22
|
public enum ScreenList
|
23
|
{
|
24
|
PLAY ( null , MODE_ROTATE , new RubikScreenPlay() ),
|
25
|
SOLV ( PLAY , MODE_ROTATE , new RubikScreenSolving() ),
|
26
|
PATT ( PLAY , MODE_DRAG , new RubikScreenPattern() ),
|
27
|
SVER ( PLAY , MODE_REPLACE, new RubikScreenSolver() ),
|
28
|
SOLU ( SVER , MODE_DRAG , new RubikScreenSolution() ),
|
29
|
READ ( PLAY , MODE_ROTATE , new RubikScreenReady() ),
|
30
|
DONE ( PLAY , MODE_DRAG , new RubikScreenDone() ),
|
31
|
;
|
32
|
|
33
|
public static final int LENGTH = values().length;
|
34
|
private static final ScreenList[] screens;
|
35
|
private final ScreenList mBack;
|
36
|
private final int mMode;
|
37
|
private final RubikScreenAbstract mClass;
|
38
|
|
39
|
private static ScreenList mCurrScreen;
|
40
|
|
41
|
static
|
42
|
{
|
43
|
int i = 0;
|
44
|
screens = new ScreenList[LENGTH];
|
45
|
for(ScreenList state: ScreenList.values()) screens[i++] = state;
|
46
|
}
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
public static ScreenList getScreen(int ordinal)
|
51
|
{
|
52
|
return ordinal>=0 && ordinal<LENGTH ? screens[ordinal] : PLAY;
|
53
|
}
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
public static ScreenList getScreenFromName(String name)
|
58
|
{
|
59
|
for(int i=0; i<LENGTH; i++)
|
60
|
{
|
61
|
if( name.equals(screens[i].name()) )
|
62
|
{
|
63
|
return screens[i];
|
64
|
}
|
65
|
}
|
66
|
|
67
|
return PLAY;
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
|
72
|
public static ScreenList getCurrentScreen()
|
73
|
{
|
74
|
return mCurrScreen;
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
|
79
|
public static int getMode()
|
80
|
{
|
81
|
return mCurrScreen.mMode;
|
82
|
}
|
83
|
|
84
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
|
86
|
public static void savePreferences(SharedPreferences.Editor editor)
|
87
|
{
|
88
|
editor.putString("curr_state_name", mCurrScreen.name() );
|
89
|
}
|
90
|
|
91
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92
|
|
93
|
public static void restorePreferences(SharedPreferences preferences)
|
94
|
{
|
95
|
String currScreenName = preferences.getString("curr_state_name", ScreenList.PLAY.name() );
|
96
|
mCurrScreen = getScreenFromName(currScreenName);
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
|
101
|
public static void goBack(RubikActivity act)
|
102
|
{
|
103
|
switchScreen(act, mCurrScreen.mBack );
|
104
|
}
|
105
|
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
public static void setScreen(RubikActivity act)
|
109
|
{
|
110
|
mCurrScreen.enterScreen(act);
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
public static void switchScreen(RubikActivity act, ScreenList next)
|
116
|
{
|
117
|
if( next!=null )
|
118
|
{
|
119
|
FirebaseAnalytics analytics = act.getAnalytics();
|
120
|
|
121
|
if( analytics!=null )
|
122
|
{
|
123
|
Bundle bundle = new Bundle();
|
124
|
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, next.toString());
|
125
|
analytics.logEvent(FirebaseAnalytics.Event.LEVEL_START, bundle);
|
126
|
}
|
127
|
|
128
|
if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act);
|
129
|
next.enterScreen(act);
|
130
|
mCurrScreen = next;
|
131
|
}
|
132
|
else
|
133
|
{
|
134
|
act.finish();
|
135
|
}
|
136
|
}
|
137
|
|
138
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139
|
|
140
|
ScreenList(ScreenList back, int mode, RubikScreenAbstract clazz)
|
141
|
{
|
142
|
mBack = back;
|
143
|
mMode = mode;
|
144
|
mClass= clazz;
|
145
|
}
|
146
|
|
147
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148
|
|
149
|
public RubikScreenAbstract getScreenClass()
|
150
|
{
|
151
|
return mClass;
|
152
|
}
|
153
|
|
154
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155
|
|
156
|
public void leaveScreen(RubikActivity act)
|
157
|
{
|
158
|
mClass.leaveScreen(act);
|
159
|
}
|
160
|
|
161
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162
|
|
163
|
public void enterScreen(RubikActivity act)
|
164
|
{
|
165
|
mClass.enterScreen(act);
|
166
|
}
|
167
|
}
|