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