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 android.content.SharedPreferences;
|
13
|
import android.os.Build;
|
14
|
import android.os.Bundle;
|
15
|
import android.view.DisplayCutout;
|
16
|
import android.view.ViewGroup;
|
17
|
import android.widget.LinearLayout;
|
18
|
|
19
|
import org.distorted.dialogs.RubikDialogError;
|
20
|
import org.distorted.dialogs.RubikDialogMessage;
|
21
|
import org.distorted.helpers.BaseActivity;
|
22
|
import org.distorted.library.main.DistortedLibrary;
|
23
|
import org.distorted.library.main.DistortedScreen;
|
24
|
import org.distorted.main.R;
|
25
|
import org.distorted.objectlib.helpers.OperatingSystemInterface;
|
26
|
import org.distorted.objectlib.main.InitAssets;
|
27
|
import org.distorted.objectlib.main.ObjectControl;
|
28
|
import org.distorted.objectlib.main.TwistyObject;
|
29
|
import org.distorted.objects.RubikObject;
|
30
|
import org.distorted.objects.RubikObjectList;
|
31
|
import org.distorted.os.OSInterface;
|
32
|
import org.distorted.solvers.ImplementedSolversList;
|
33
|
|
34
|
import java.io.InputStream;
|
35
|
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
|
38
|
public class SolverActivity extends BaseActivity
|
39
|
{
|
40
|
public static final float RATIO_UPP = 0.100f;
|
41
|
public static final float PADDING = 0.010f;
|
42
|
public static final float SMALL_MARGIN = 0.004f;
|
43
|
public static final float BUTTON_TEXT_SIZE= 0.050f;
|
44
|
public static final float TITLE_TEXT_SIZE = 0.060f;
|
45
|
|
46
|
private static final int ACTIVITY_NUMBER = 4;
|
47
|
private static final float RATIO_INSET= 0.09f;
|
48
|
|
49
|
private int mSolverOrdinal;
|
50
|
private int mObjectOrdinal;
|
51
|
private boolean mDisplayMessageDialog;
|
52
|
|
53
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
|
55
|
@Override
|
56
|
protected void onCreate(Bundle savedState)
|
57
|
{
|
58
|
super.onCreate(savedState);
|
59
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
60
|
setContentView(R.layout.solver);
|
61
|
|
62
|
Bundle b = getIntent().getExtras();
|
63
|
mObjectOrdinal = b!=null ? b.getInt("obj") : 0;
|
64
|
mSolverOrdinal = ImplementedSolversList.getSolverOrdinal(mObjectOrdinal);
|
65
|
mDisplayMessageDialog = true;
|
66
|
|
67
|
computeScreenDimensions();
|
68
|
hideNavigationBar();
|
69
|
cutoutHack();
|
70
|
computeUpperBarHeight(RATIO_UPP);
|
71
|
computeLowerBarHeight(RATIO_BAR);
|
72
|
}
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
@Override
|
77
|
public void onAttachedToWindow()
|
78
|
{
|
79
|
super.onAttachedToWindow();
|
80
|
|
81
|
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P )
|
82
|
{
|
83
|
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
|
84
|
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
|
85
|
|
86
|
LinearLayout layoutHid = findViewById(R.id.hiddenBar);
|
87
|
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
|
88
|
paramsHid.height = (int)(insetHeight*RATIO_INSET);
|
89
|
layoutHid.setLayoutParams(paramsHid);
|
90
|
}
|
91
|
}
|
92
|
|
93
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94
|
|
95
|
@Override
|
96
|
protected void onPause()
|
97
|
{
|
98
|
super.onPause();
|
99
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
100
|
view.onPause();
|
101
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
102
|
savePreferences();
|
103
|
}
|
104
|
|
105
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106
|
|
107
|
@Override
|
108
|
protected void onResume()
|
109
|
{
|
110
|
super.onResume();
|
111
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
112
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
113
|
view.onResume();
|
114
|
|
115
|
createObject();
|
116
|
|
117
|
restorePreferences();
|
118
|
ScreenList.setScreen(this);
|
119
|
}
|
120
|
|
121
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
122
|
|
123
|
@Override
|
124
|
protected void onDestroy()
|
125
|
{
|
126
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
127
|
super.onDestroy();
|
128
|
}
|
129
|
|
130
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131
|
|
132
|
private void savePreferences()
|
133
|
{
|
134
|
SharedPreferences.Editor editor = mPreferences.edit();
|
135
|
|
136
|
for( int i=0; i< ScreenList.LENGTH; i++ )
|
137
|
{
|
138
|
ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
|
139
|
}
|
140
|
|
141
|
ScreenList.savePreferences(editor);
|
142
|
|
143
|
editor.putBoolean("solverDisplayDialog", mDisplayMessageDialog );
|
144
|
|
145
|
boolean success = editor.commit();
|
146
|
if( !success ) android.util.Log.e("D", "Failed to save preferences");
|
147
|
}
|
148
|
|
149
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150
|
|
151
|
private void restorePreferences()
|
152
|
{
|
153
|
for( int i=0; i<ScreenList.LENGTH; i++ )
|
154
|
{
|
155
|
ScreenList.getScreen(i).getScreenClass().restorePreferences(mPreferences);
|
156
|
}
|
157
|
|
158
|
ScreenList.restorePreferences(mPreferences);
|
159
|
|
160
|
mDisplayMessageDialog = mPreferences.getBoolean("solverDisplayDialog",true);
|
161
|
|
162
|
if( mDisplayMessageDialog )
|
163
|
{
|
164
|
Bundle bundle = new Bundle();
|
165
|
bundle.putString("argument", getString(R.string.solver_message) );
|
166
|
RubikDialogMessage diag = new RubikDialogMessage();
|
167
|
diag.setArguments(bundle);
|
168
|
diag.show( getSupportFragmentManager(), RubikDialogMessage.getDialogTag() );
|
169
|
}
|
170
|
}
|
171
|
|
172
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
173
|
|
174
|
void doNotShowDialogAnymore()
|
175
|
{
|
176
|
mDisplayMessageDialog = false;
|
177
|
}
|
178
|
|
179
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
180
|
|
181
|
void OpenGLError()
|
182
|
{
|
183
|
RubikDialogError errDiag = new RubikDialogError();
|
184
|
errDiag.show(getSupportFragmentManager(), null);
|
185
|
}
|
186
|
|
187
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
188
|
// PUBLIC API
|
189
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
190
|
|
191
|
public TwistyObject getObject()
|
192
|
{
|
193
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
194
|
return view.getObjectControl().getObject();
|
195
|
}
|
196
|
|
197
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
198
|
|
199
|
public DistortedScreen getScreen()
|
200
|
{
|
201
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
202
|
return view.getRenderer().getScreen();
|
203
|
}
|
204
|
|
205
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
206
|
|
207
|
public ObjectControl getControl()
|
208
|
{
|
209
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
210
|
return view.getObjectControl();
|
211
|
}
|
212
|
|
213
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214
|
|
215
|
public int getSolverOrdinal()
|
216
|
{
|
217
|
return mSolverOrdinal;
|
218
|
}
|
219
|
|
220
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221
|
|
222
|
public int getObjectOrdinal()
|
223
|
{
|
224
|
return mObjectOrdinal;
|
225
|
}
|
226
|
|
227
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
228
|
|
229
|
public void createObject()
|
230
|
{
|
231
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
232
|
ObjectControl control = view.getObjectControl();
|
233
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
234
|
InputStream jsonStream = object==null ? null : object.getObjectStream(this);
|
235
|
InputStream meshStream = object==null ? null : object.getMeshStream(this);
|
236
|
String name = object==null ? "NULL" : object.getUpperName();
|
237
|
OSInterface os = view.getInterface();
|
238
|
InitAssets asset = new InitAssets(jsonStream,meshStream,os);
|
239
|
control.changeIfDifferent(mObjectOrdinal,name,TwistyObject.MODE_NORM,asset);
|
240
|
}
|
241
|
|
242
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243
|
|
244
|
public OperatingSystemInterface getInterface()
|
245
|
{
|
246
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
247
|
return view.getInterface();
|
248
|
}
|
249
|
}
|