1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2023 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.solverui;
|
11
|
|
12
|
import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG;
|
13
|
import static org.distorted.objectlib.main.ObjectControl.MODE_REPLACE;
|
14
|
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
|
15
|
|
16
|
import android.content.SharedPreferences;
|
17
|
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
public enum ScreenList
|
21
|
{
|
22
|
SVER ( null , MODE_REPLACE, new ScreenSolver() ),
|
23
|
SOLU ( SVER , MODE_DRAG , new ScreenSolution() ),
|
24
|
;
|
25
|
|
26
|
public static final int LENGTH = values().length;
|
27
|
private static final ScreenList[] screens;
|
28
|
private final ScreenList mBack;
|
29
|
private final int mMode;
|
30
|
private final ScreenAbstract mClass;
|
31
|
|
32
|
private static ScreenList mCurrScreen;
|
33
|
|
34
|
static
|
35
|
{
|
36
|
int i = 0;
|
37
|
screens = new ScreenList[LENGTH];
|
38
|
for(ScreenList state: ScreenList.values()) screens[i++] = state;
|
39
|
}
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
public static ScreenList getScreen(int ordinal)
|
44
|
{
|
45
|
return ordinal>=0 && ordinal<LENGTH ? screens[ordinal] : SVER;
|
46
|
}
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
public static ScreenList getScreenFromName(String name)
|
51
|
{
|
52
|
for(int i=0; i<LENGTH; i++)
|
53
|
{
|
54
|
if( name.equals(screens[i].name()) )
|
55
|
{
|
56
|
return screens[i];
|
57
|
}
|
58
|
}
|
59
|
|
60
|
return SVER;
|
61
|
}
|
62
|
|
63
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
|
65
|
public static ScreenList getCurrentScreen()
|
66
|
{
|
67
|
return mCurrScreen;
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
|
72
|
public static int getMode()
|
73
|
{
|
74
|
return mCurrScreen.mMode;
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
|
79
|
public static void savePreferences(SharedPreferences.Editor editor)
|
80
|
{
|
81
|
editor.putString("curr_state_name", mCurrScreen.name() );
|
82
|
}
|
83
|
|
84
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
|
86
|
public static void restorePreferences(SharedPreferences preferences)
|
87
|
{
|
88
|
String currScreenName = preferences.getString("curr_state_name", ScreenList.SVER.name() );
|
89
|
mCurrScreen = getScreenFromName(currScreenName);
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
public static void goBack(SolverActivity act)
|
95
|
{
|
96
|
switchScreen(act, mCurrScreen.mBack );
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
|
101
|
public static void setScreen(SolverActivity act)
|
102
|
{
|
103
|
mCurrScreen.enterScreen(act);
|
104
|
}
|
105
|
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
public static void switchScreen(SolverActivity act, ScreenList next)
|
109
|
{
|
110
|
if( next!=null )
|
111
|
{
|
112
|
if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act);
|
113
|
next.enterScreen(act);
|
114
|
mCurrScreen = next;
|
115
|
}
|
116
|
else
|
117
|
{
|
118
|
act.finish();
|
119
|
}
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
|
124
|
ScreenList(ScreenList back, int mode, ScreenAbstract clazz)
|
125
|
{
|
126
|
mBack = back;
|
127
|
mMode = mode;
|
128
|
mClass= clazz;
|
129
|
}
|
130
|
|
131
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132
|
|
133
|
public ScreenAbstract getScreenClass()
|
134
|
{
|
135
|
return mClass;
|
136
|
}
|
137
|
|
138
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139
|
|
140
|
public void leaveScreen(SolverActivity act)
|
141
|
{
|
142
|
mClass.leaveScreen(act);
|
143
|
}
|
144
|
|
145
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146
|
|
147
|
public void enterScreen(SolverActivity act)
|
148
|
{
|
149
|
mClass.enterScreen(act);
|
150
|
}
|
151
|
}
|