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.patternui;
|
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.helpers.BaseActivity;
|
21
|
import org.distorted.library.main.DistortedLibrary;
|
22
|
import org.distorted.library.main.DistortedScreen;
|
23
|
import org.distorted.main.R;
|
24
|
import org.distorted.objectlib.main.InitAssets;
|
25
|
import org.distorted.objectlib.main.ObjectControl;
|
26
|
import org.distorted.objectlib.main.TwistyObject;
|
27
|
import org.distorted.objects.RubikObject;
|
28
|
import org.distorted.objects.RubikObjectList;
|
29
|
import org.distorted.os.OSInterface;
|
30
|
|
31
|
import java.io.InputStream;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class PatternActivity extends BaseActivity
|
36
|
{
|
37
|
public static final float RATIO_UPP = 0.100f;
|
38
|
public static final float PADDING = 0.010f;
|
39
|
public static final float SMALL_MARGIN = 0.004f;
|
40
|
public static final float BUTTON_TEXT_SIZE= 0.050f;
|
41
|
public static final float TITLE_TEXT_SIZE = 0.045f;
|
42
|
|
43
|
private static final int ACTIVITY_NUMBER = 5;
|
44
|
private static final float RATIO_INSET= 0.09f;
|
45
|
|
46
|
private int mObjectOrdinal;
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
@Override
|
51
|
protected void onCreate(Bundle savedState)
|
52
|
{
|
53
|
super.onCreate(savedState);
|
54
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
55
|
setContentView(R.layout.pattern);
|
56
|
|
57
|
Bundle b = getIntent().getExtras();
|
58
|
mObjectOrdinal = b!=null ? b.getInt("obj") : 0;
|
59
|
|
60
|
computeScreenDimensions();
|
61
|
hideNavigationBar();
|
62
|
cutoutHack();
|
63
|
computeLowerBarHeight(RATIO_BAR);
|
64
|
computeUpperBarHeight(RATIO_UPP);
|
65
|
}
|
66
|
|
67
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68
|
|
69
|
@Override
|
70
|
public void onAttachedToWindow()
|
71
|
{
|
72
|
super.onAttachedToWindow();
|
73
|
|
74
|
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P )
|
75
|
{
|
76
|
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
|
77
|
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
|
78
|
|
79
|
LinearLayout layoutHid = findViewById(R.id.hiddenBar);
|
80
|
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
|
81
|
paramsHid.height = (int)(insetHeight*RATIO_INSET);
|
82
|
layoutHid.setLayoutParams(paramsHid);
|
83
|
}
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
@Override
|
89
|
protected void onPause()
|
90
|
{
|
91
|
super.onPause();
|
92
|
PatternSurfaceView view = findViewById(R.id.patternSurfaceView);
|
93
|
view.onPause();
|
94
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
95
|
savePreferences();
|
96
|
}
|
97
|
|
98
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
99
|
|
100
|
@Override
|
101
|
protected void onResume()
|
102
|
{
|
103
|
super.onResume();
|
104
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
105
|
PatternSurfaceView view = findViewById(R.id.patternSurfaceView);
|
106
|
view.onResume();
|
107
|
|
108
|
createObject();
|
109
|
restorePreferences();
|
110
|
ScreenList.setScreen(this);
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
@Override
|
116
|
protected void onDestroy()
|
117
|
{
|
118
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
119
|
super.onDestroy();
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
|
124
|
private void savePreferences()
|
125
|
{
|
126
|
SharedPreferences.Editor editor = mPreferences.edit();
|
127
|
|
128
|
for(int i=0; i< ScreenList.LENGTH; i++ )
|
129
|
ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
|
130
|
|
131
|
ScreenList.savePreferences(editor);
|
132
|
|
133
|
boolean success = editor.commit();
|
134
|
if( !success ) android.util.Log.e("D", "Failed to save preferences");
|
135
|
}
|
136
|
|
137
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138
|
|
139
|
private void restorePreferences()
|
140
|
{
|
141
|
for (int i=0; i<ScreenList.LENGTH; i++)
|
142
|
ScreenList.getScreen(i).getScreenClass().restorePreferences(mPreferences);
|
143
|
|
144
|
ScreenList.restorePreferences(mPreferences);
|
145
|
}
|
146
|
|
147
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148
|
|
149
|
void OpenGLError()
|
150
|
{
|
151
|
RubikDialogError errDiag = new RubikDialogError();
|
152
|
errDiag.show(getSupportFragmentManager(), null);
|
153
|
}
|
154
|
|
155
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156
|
// PUBLIC API
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
|
159
|
public TwistyObject getObject()
|
160
|
{
|
161
|
PatternSurfaceView view = findViewById(R.id.patternSurfaceView);
|
162
|
return view.getObjectControl().getObject();
|
163
|
}
|
164
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166
|
|
167
|
public DistortedScreen getScreen()
|
168
|
{
|
169
|
PatternSurfaceView view = findViewById(R.id.patternSurfaceView);
|
170
|
return view.getRenderer().getScreen();
|
171
|
}
|
172
|
|
173
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174
|
|
175
|
public ObjectControl getControl()
|
176
|
{
|
177
|
PatternSurfaceView view = findViewById(R.id.patternSurfaceView);
|
178
|
return view.getObjectControl();
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
|
183
|
public int getObjectOrdinal()
|
184
|
{
|
185
|
return mObjectOrdinal;
|
186
|
}
|
187
|
|
188
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189
|
|
190
|
public void createObject()
|
191
|
{
|
192
|
PatternSurfaceView view = findViewById(R.id.patternSurfaceView);
|
193
|
ObjectControl control = view.getObjectControl();
|
194
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
195
|
int iconMode = TwistyObject.MODE_NORM;
|
196
|
InputStream jsonStream = object==null ? null : object.getObjectStream(this);
|
197
|
InputStream meshStream = object==null ? null : object.getMeshStream(this);
|
198
|
String name = object==null ? "NULL" : object.getUpperName();
|
199
|
OSInterface os = view.getInterface();
|
200
|
InitAssets asset = new InitAssets(jsonStream,meshStream,os);
|
201
|
|
202
|
control.changeIfDifferent(mObjectOrdinal,name,iconMode,asset);
|
203
|
}
|
204
|
}
|