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
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
65
|
int objectIndex = object==null ? -1 : object.getIndex();
|
66
|
mSolverOrdinal = ImplementedSolversList.getSolverOrdinal(objectIndex);
|
67
|
mDisplayMessageDialog = true;
|
68
|
|
69
|
computeScreenDimensions();
|
70
|
hideNavigationBar();
|
71
|
cutoutHack();
|
72
|
computeUpperBarHeight(RATIO_UPP);
|
73
|
computeLowerBarHeight(RATIO_BAR);
|
74
|
}
|
75
|
|
76
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77
|
|
78
|
@Override
|
79
|
public void onAttachedToWindow()
|
80
|
{
|
81
|
super.onAttachedToWindow();
|
82
|
|
83
|
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P )
|
84
|
{
|
85
|
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
|
86
|
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
|
87
|
|
88
|
LinearLayout layoutHid = findViewById(R.id.hiddenBar);
|
89
|
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
|
90
|
paramsHid.height = (int)(insetHeight*RATIO_INSET);
|
91
|
layoutHid.setLayoutParams(paramsHid);
|
92
|
}
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
|
97
|
@Override
|
98
|
protected void onPause()
|
99
|
{
|
100
|
super.onPause();
|
101
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
102
|
view.onPause();
|
103
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
104
|
savePreferences();
|
105
|
}
|
106
|
|
107
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108
|
|
109
|
@Override
|
110
|
protected void onResume()
|
111
|
{
|
112
|
super.onResume();
|
113
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
114
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
115
|
view.onResume();
|
116
|
|
117
|
createObject();
|
118
|
|
119
|
restorePreferences();
|
120
|
ScreenList.setScreen(this);
|
121
|
}
|
122
|
|
123
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124
|
|
125
|
@Override
|
126
|
protected void onDestroy()
|
127
|
{
|
128
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
129
|
super.onDestroy();
|
130
|
}
|
131
|
|
132
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
133
|
|
134
|
private void savePreferences()
|
135
|
{
|
136
|
SharedPreferences.Editor editor = mPreferences.edit();
|
137
|
|
138
|
for( int i=0; i< ScreenList.LENGTH; i++ )
|
139
|
{
|
140
|
ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
|
141
|
}
|
142
|
|
143
|
ScreenList.savePreferences(editor);
|
144
|
|
145
|
editor.putBoolean("solverDisplayDialog", mDisplayMessageDialog );
|
146
|
|
147
|
boolean success = editor.commit();
|
148
|
if( !success ) android.util.Log.e("D", "Failed to save preferences");
|
149
|
}
|
150
|
|
151
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
152
|
|
153
|
private void restorePreferences()
|
154
|
{
|
155
|
for( int i=0; i<ScreenList.LENGTH; i++ )
|
156
|
{
|
157
|
ScreenList.getScreen(i).getScreenClass().restorePreferences(mPreferences);
|
158
|
}
|
159
|
|
160
|
ScreenList.restorePreferences(mPreferences);
|
161
|
|
162
|
mDisplayMessageDialog = mPreferences.getBoolean("solverDisplayDialog",true);
|
163
|
|
164
|
if( mDisplayMessageDialog )
|
165
|
{
|
166
|
Bundle bundle = new Bundle();
|
167
|
bundle.putString("argument", getString(R.string.solver_message) );
|
168
|
RubikDialogMessage diag = new RubikDialogMessage();
|
169
|
diag.setArguments(bundle);
|
170
|
diag.show( getSupportFragmentManager(), RubikDialogMessage.getDialogTag() );
|
171
|
}
|
172
|
}
|
173
|
|
174
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
void doNotShowDialogAnymore()
|
177
|
{
|
178
|
mDisplayMessageDialog = false;
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
|
183
|
void OpenGLError()
|
184
|
{
|
185
|
RubikDialogError errDiag = new RubikDialogError();
|
186
|
errDiag.show(getSupportFragmentManager(), null);
|
187
|
}
|
188
|
|
189
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
190
|
// PUBLIC API
|
191
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192
|
|
193
|
public TwistyObject getObject()
|
194
|
{
|
195
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
196
|
return view.getObjectControl().getObject();
|
197
|
}
|
198
|
|
199
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200
|
|
201
|
public DistortedScreen getScreen()
|
202
|
{
|
203
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
204
|
return view.getRenderer().getScreen();
|
205
|
}
|
206
|
|
207
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208
|
|
209
|
public ObjectControl getControl()
|
210
|
{
|
211
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
212
|
return view.getObjectControl();
|
213
|
}
|
214
|
|
215
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
216
|
|
217
|
public int getSolverOrdinal()
|
218
|
{
|
219
|
return mSolverOrdinal;
|
220
|
}
|
221
|
|
222
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
223
|
|
224
|
public int getObjectOrdinal()
|
225
|
{
|
226
|
return mObjectOrdinal;
|
227
|
}
|
228
|
|
229
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
230
|
|
231
|
public void createObject()
|
232
|
{
|
233
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
234
|
ObjectControl control = view.getObjectControl();
|
235
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
236
|
InputStream jsonStream = object==null ? null : object.getObjectStream(this);
|
237
|
InputStream meshStream = object==null ? null : object.getMeshStream(this);
|
238
|
String name = object==null ? "NULL" : object.getUpperName();
|
239
|
OSInterface os = view.getInterface();
|
240
|
InitAssets asset = new InitAssets(jsonStream,meshStream,os);
|
241
|
control.changeIfDifferent(mObjectOrdinal,name,TwistyObject.MODE_NORM,asset);
|
242
|
}
|
243
|
|
244
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
245
|
|
246
|
public OperatingSystemInterface getInterface()
|
247
|
{
|
248
|
SolverSurfaceView view = findViewById(R.id.solverSurfaceView);
|
249
|
return view.getInterface();
|
250
|
}
|
251
|
}
|