1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 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.bandaged;
|
11
|
|
12
|
import static android.view.View.LAYOUT_DIRECTION_RTL;
|
13
|
|
14
|
import java.io.InputStream;
|
15
|
|
16
|
import android.content.Intent;
|
17
|
import android.content.SharedPreferences;
|
18
|
import android.content.res.Configuration;
|
19
|
import android.graphics.Bitmap;
|
20
|
import android.os.Bundle;
|
21
|
import android.view.ViewGroup;
|
22
|
import android.widget.LinearLayout;
|
23
|
|
24
|
import org.distorted.dialogs.RubikDialogError;
|
25
|
import org.distorted.dialogs.RubikDialogMessage;
|
26
|
import org.distorted.external.RubikFiles;
|
27
|
import org.distorted.helpers.BaseActivity;
|
28
|
import org.distorted.library.main.DistortedLibrary;
|
29
|
import org.distorted.main.R;
|
30
|
import org.distorted.objectlib.main.InitAssets;
|
31
|
import org.distorted.objectlib.main.TwistyJson;
|
32
|
import org.distorted.objectlib.main.TwistyObject;
|
33
|
import org.distorted.os.OSInterface;
|
34
|
import org.distorted.playui.PlayActivity;
|
35
|
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
|
38
|
public class BandagedActivity extends BaseActivity
|
39
|
{
|
40
|
public static final float SPINNER_TEXT_SIZE = 0.03f;
|
41
|
public static final float PADDING = 0.010f;
|
42
|
public static final float RATIO_SCROLL = 0.30f;
|
43
|
|
44
|
private static final int ACTIVITY_NUMBER = 2;
|
45
|
private static final float RATIO_BUT = 0.07f;
|
46
|
private static final int NUM_SCRAMBLES = 300;
|
47
|
|
48
|
private BandagedScreen mScreen;
|
49
|
private boolean mRTL;
|
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
|
|
60
|
Bundle b = getIntent().getExtras();
|
61
|
mObjectOrdinal = (b != null) ? b.getInt("obj") : 0;
|
62
|
mDisplayMessageDialog = true;
|
63
|
|
64
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
65
|
setContentView(R.layout.bandaged);
|
66
|
|
67
|
final Configuration config = getResources().getConfiguration();
|
68
|
final int layoutDirection = config.getLayoutDirection();
|
69
|
mRTL = layoutDirection==LAYOUT_DIRECTION_RTL;
|
70
|
|
71
|
computeScreenDimensions();
|
72
|
hideNavigationBar();
|
73
|
cutoutHack();
|
74
|
computeHeights();
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
// this does not include possible insets
|
79
|
|
80
|
private void computeHeights()
|
81
|
{
|
82
|
int barHeight = (int)(mScreenHeight*RATIO_BAR);
|
83
|
int butHeight = (int)(mScreenHeight*RATIO_BUT);
|
84
|
int viewHeight = (int)(mScreenHeight*RATIO_SCROLL);
|
85
|
int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL+RATIO_BAR));
|
86
|
int padding = (int)(mScreenHeight*PADDING);
|
87
|
|
88
|
LinearLayout botLayout = findViewById(R.id.lowerBar);
|
89
|
ViewGroup.LayoutParams paramsL = botLayout.getLayoutParams();
|
90
|
paramsL.height = barHeight;
|
91
|
botLayout.setLayoutParams(paramsL);
|
92
|
|
93
|
LinearLayout butLayout = findViewById(R.id.bandagedCreatorButtons);
|
94
|
ViewGroup.LayoutParams paramsB = butLayout.getLayoutParams();
|
95
|
paramsB.height = butHeight;
|
96
|
butLayout.setPadding(padding,0,padding,padding);
|
97
|
butLayout.setLayoutParams(paramsB);
|
98
|
|
99
|
LinearLayout topLayout = findViewById(R.id.bandagedCreatorTopView);
|
100
|
ViewGroup.LayoutParams paramsT = topLayout.getLayoutParams();
|
101
|
paramsT.height = viewHeight;
|
102
|
topLayout.setPadding(padding,padding,padding,padding);
|
103
|
topLayout.setLayoutParams(paramsT);
|
104
|
|
105
|
BandagedView creator = findViewById(R.id.bandagedCreatorObjectView);
|
106
|
ViewGroup.LayoutParams paramsC = creator.getLayoutParams();
|
107
|
paramsC.height = objectHeight;
|
108
|
creator.setLayoutParams(paramsC);
|
109
|
}
|
110
|
|
111
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
|
113
|
@Override
|
114
|
protected void onPause()
|
115
|
{
|
116
|
super.onPause();
|
117
|
BandagedView view = findViewById(R.id.bandagedCreatorObjectView);
|
118
|
view.onPause();
|
119
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
120
|
savePreferences();
|
121
|
}
|
122
|
|
123
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124
|
|
125
|
@Override
|
126
|
protected void onResume()
|
127
|
{
|
128
|
super.onResume();
|
129
|
|
130
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
131
|
BandagedView view = findViewById(R.id.bandagedCreatorObjectView);
|
132
|
view.onResume();
|
133
|
|
134
|
if( mScreen==null )
|
135
|
{
|
136
|
int ordinal = getObjectOrdinal();
|
137
|
mScreen = new BandagedScreen(ordinal);
|
138
|
}
|
139
|
|
140
|
mScreen.onAttachedToWindow(this);
|
141
|
|
142
|
restorePreferences();
|
143
|
BandagedWorkerThread.create(this);
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
@Override
|
149
|
protected void onDestroy()
|
150
|
{
|
151
|
super.onDestroy();
|
152
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
153
|
}
|
154
|
|
155
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156
|
|
157
|
void OpenGLError()
|
158
|
{
|
159
|
RubikDialogError errDiag = new RubikDialogError();
|
160
|
errDiag.show(getSupportFragmentManager(), null);
|
161
|
}
|
162
|
|
163
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164
|
|
165
|
private void savePreferences()
|
166
|
{
|
167
|
SharedPreferences.Editor editor = mPreferences.edit();
|
168
|
mScreen.savePreferences(editor);
|
169
|
|
170
|
editor.putBoolean("bandageDisplayDialog", mDisplayMessageDialog );
|
171
|
|
172
|
editor.apply();
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
|
177
|
private void restorePreferences()
|
178
|
{
|
179
|
mScreen.restorePreferences(this,mPreferences);
|
180
|
|
181
|
mDisplayMessageDialog = mPreferences.getBoolean("bandageDisplayDialog",true);
|
182
|
|
183
|
if( mDisplayMessageDialog )
|
184
|
{
|
185
|
Bundle bundle = new Bundle();
|
186
|
bundle.putString("argument", getString(R.string.bandage_message) );
|
187
|
RubikDialogMessage diag = new RubikDialogMessage();
|
188
|
diag.setArguments(bundle);
|
189
|
diag.show( getSupportFragmentManager(), RubikDialogMessage.getDialogTag() );
|
190
|
}
|
191
|
}
|
192
|
|
193
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194
|
|
195
|
void doNotShowDialogAnymore()
|
196
|
{
|
197
|
mDisplayMessageDialog = false;
|
198
|
}
|
199
|
|
200
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201
|
// PUBLIC API
|
202
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203
|
|
204
|
public void changeObject(int x, int y, int z)
|
205
|
{
|
206
|
BandagedRenderer renderer = getRenderer();
|
207
|
renderer.changeObject(x,y,z);
|
208
|
}
|
209
|
|
210
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
211
|
|
212
|
public boolean isRTL()
|
213
|
{
|
214
|
return mRTL;
|
215
|
}
|
216
|
|
217
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
218
|
|
219
|
public BandagedRenderer getRenderer()
|
220
|
{
|
221
|
BandagedView view = findViewById(R.id.bandagedCreatorObjectView);
|
222
|
return view.getRenderer();
|
223
|
}
|
224
|
|
225
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226
|
|
227
|
public boolean objectDoesntExist(String name)
|
228
|
{
|
229
|
return mScreen.objectDoesntExist(name);
|
230
|
}
|
231
|
|
232
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
233
|
|
234
|
public void addObject(String name)
|
235
|
{
|
236
|
mScreen.addObject(this,name);
|
237
|
}
|
238
|
|
239
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
240
|
|
241
|
public void deleteObject(String name)
|
242
|
{
|
243
|
RubikFiles files = RubikFiles.getInstance();
|
244
|
InputStream jsonStream = files.openFile(this,name+"_object.json");
|
245
|
InitAssets assets = new InitAssets(jsonStream,null,null);
|
246
|
|
247
|
if( !assets.noJsonStream() )
|
248
|
{
|
249
|
TwistyObject object = new TwistyJson( TwistyObject.MODE_NORM, null, null, 1.0f, assets);
|
250
|
|
251
|
if( !object.getError() )
|
252
|
{
|
253
|
SharedPreferences.Editor editor = mPreferences.edit();
|
254
|
OSInterface os = new OSInterface(this,null);
|
255
|
os.setEditor(editor);
|
256
|
object.removePreferences(os);
|
257
|
editor.apply();
|
258
|
}
|
259
|
}
|
260
|
|
261
|
mScreen.deleteObject(this,name);
|
262
|
files.deleteIcon(this,name);
|
263
|
files.deleteJsonObject(this,name);
|
264
|
}
|
265
|
|
266
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
267
|
|
268
|
public void playObject(String name)
|
269
|
{
|
270
|
Intent intent = new Intent(this, PlayActivity.class);
|
271
|
intent.putExtra("level", -1);
|
272
|
intent.putExtra("name", name);
|
273
|
intent.putExtra("scrambles", NUM_SCRAMBLES);
|
274
|
intent.putExtra("local", true);
|
275
|
intent.putExtra("ordinal", 0);
|
276
|
startActivity(intent);
|
277
|
}
|
278
|
|
279
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
280
|
|
281
|
public void iconCreationDone(Bitmap bmp)
|
282
|
{
|
283
|
mScreen.iconCreationDone(this,bmp);
|
284
|
}
|
285
|
|
286
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
287
|
|
288
|
public int getObjectOrdinal()
|
289
|
{
|
290
|
return mObjectOrdinal;
|
291
|
}
|
292
|
}
|