1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 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.config;
|
11
|
|
12
|
import android.content.SharedPreferences;
|
13
|
import android.os.Bundle;
|
14
|
|
15
|
import androidx.preference.PreferenceManager;
|
16
|
|
17
|
import org.distorted.dialogs.RubikDialogError;
|
18
|
import org.distorted.dialogs.RubikDialogMessage;
|
19
|
import org.distorted.helpers.BaseActivity;
|
20
|
import org.distorted.library.main.DistortedLibrary;
|
21
|
import org.distorted.main.R;
|
22
|
import org.distorted.objectlib.main.InitAssets;
|
23
|
import org.distorted.objectlib.main.ObjectControl;
|
24
|
import org.distorted.objectlib.main.TwistyObject;
|
25
|
import org.distorted.objects.RubikObject;
|
26
|
import org.distorted.objects.RubikObjectList;
|
27
|
import org.distorted.os.OSInterface;
|
28
|
|
29
|
import java.io.InputStream;
|
30
|
|
31
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
|
33
|
public class ConfigActivity extends BaseActivity
|
34
|
{
|
35
|
private static final int ACTIVITY_NUMBER = 7;
|
36
|
private ConfigScreen mScreen;
|
37
|
private ConfigScreenPane mPane;
|
38
|
private int mObjectOrdinal;
|
39
|
private boolean mSupportsAdjColors;
|
40
|
private boolean mDisplayMessageDialog;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
@Override
|
45
|
protected void onCreate(Bundle savedState)
|
46
|
{
|
47
|
super.onCreate(savedState);
|
48
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
49
|
setContentView(R.layout.config);
|
50
|
|
51
|
Bundle b = getIntent().getExtras();
|
52
|
if(b != null) mObjectOrdinal = b.getInt("obj");
|
53
|
|
54
|
mDisplayMessageDialog = true;
|
55
|
|
56
|
computeScreenDimensions();
|
57
|
hideNavigationBar();
|
58
|
cutoutHack();
|
59
|
computeLowerBarHeight(RATIO_BAR);
|
60
|
}
|
61
|
|
62
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63
|
|
64
|
@Override
|
65
|
protected void onPause()
|
66
|
{
|
67
|
super.onPause();
|
68
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
69
|
view.onPause();
|
70
|
savePreferences();
|
71
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
72
|
}
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
@Override
|
77
|
protected void onResume()
|
78
|
{
|
79
|
super.onResume();
|
80
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
81
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
82
|
view.onResume();
|
83
|
String key ="";
|
84
|
mSupportsAdjColors = false;
|
85
|
|
86
|
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
|
87
|
{
|
88
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
89
|
changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
|
90
|
|
91
|
if( object!=null )
|
92
|
{
|
93
|
key = object.getUpperName();
|
94
|
mSupportsAdjColors = object.supportsAdjustableColors();
|
95
|
}
|
96
|
}
|
97
|
|
98
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
99
|
OSInterface os = view.getInterface();
|
100
|
os.setPreferences(preferences);
|
101
|
|
102
|
restorePreferences(preferences);
|
103
|
|
104
|
if( mScreen==null ) mScreen = new ConfigScreen();
|
105
|
mScreen.onAttachedToWindow(this,mObjectOrdinal);
|
106
|
|
107
|
mPane = new ConfigScreenPane(this,key,os,mSupportsAdjColors);
|
108
|
}
|
109
|
|
110
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111
|
|
112
|
void repaintPuzzleFace(int cubit, int face)
|
113
|
{
|
114
|
if( mPane!=null && mSupportsAdjColors )
|
115
|
{
|
116
|
int color = mPane.getCurrentColor();
|
117
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
118
|
ObjectControl control = view.getObjectControl();
|
119
|
control.repaintPuzzleFace(cubit,face,color);
|
120
|
mDisplayMessageDialog = false;
|
121
|
}
|
122
|
}
|
123
|
|
124
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125
|
|
126
|
@Override
|
127
|
protected void onDestroy()
|
128
|
{
|
129
|
super.onDestroy();
|
130
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
131
|
}
|
132
|
|
133
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
134
|
|
135
|
void OpenGLError()
|
136
|
{
|
137
|
RubikDialogError errDiag = new RubikDialogError();
|
138
|
errDiag.show(getSupportFragmentManager(), null);
|
139
|
}
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
|
143
|
private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
|
144
|
{
|
145
|
if( object!=null )
|
146
|
{
|
147
|
int iconMode = TwistyObject.MODE_NORM;
|
148
|
InputStream jsonStream = object.getObjectStream(this);
|
149
|
InputStream meshStream = object.getMeshStream(this);
|
150
|
String name = object.getUpperName();
|
151
|
InitAssets asset = new InitAssets(jsonStream,meshStream,null);
|
152
|
control.changeIfDifferent(ordinal,name,iconMode,asset);
|
153
|
}
|
154
|
}
|
155
|
|
156
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
157
|
|
158
|
private void savePreferences()
|
159
|
{
|
160
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
161
|
SharedPreferences.Editor editor = preferences.edit();
|
162
|
|
163
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
164
|
OSInterface os = view.getInterface();
|
165
|
os.setEditor(editor);
|
166
|
view.getObjectControl().savePreferences();
|
167
|
|
168
|
editor.putBoolean("configDisplayDialog", mDisplayMessageDialog );
|
169
|
|
170
|
editor.apply();
|
171
|
}
|
172
|
|
173
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174
|
|
175
|
private void restorePreferences(SharedPreferences preferences)
|
176
|
{
|
177
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
178
|
view.getObjectControl().restoreStickers();
|
179
|
|
180
|
mDisplayMessageDialog = preferences.getBoolean("configDisplayDialog",true);
|
181
|
|
182
|
if( mDisplayMessageDialog )
|
183
|
{
|
184
|
Bundle bundle = new Bundle();
|
185
|
bundle.putString("argument", getString(R.string.config_message) );
|
186
|
RubikDialogMessage diag = new RubikDialogMessage();
|
187
|
diag.setArguments(bundle);
|
188
|
diag.show( getSupportFragmentManager(), RubikDialogMessage.getDialogTag() );
|
189
|
}
|
190
|
}
|
191
|
|
192
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
193
|
// PUBLIC API
|
194
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
195
|
|
196
|
public ConfigRenderer getRenderer()
|
197
|
{
|
198
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
199
|
return view.getRenderer();
|
200
|
}
|
201
|
|
202
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203
|
|
204
|
public void recreateColors()
|
205
|
{
|
206
|
ObjectControl control = getControl();
|
207
|
control.recreateColors();
|
208
|
}
|
209
|
|
210
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
211
|
|
212
|
public void recreateStickers(int borders, int corners)
|
213
|
{
|
214
|
ObjectControl control = getControl();
|
215
|
|
216
|
float border_step = ConfigScreenPane.BORDER_STEPS[borders];
|
217
|
float corner_step = ConfigScreenPane.CORNER_STEPS[corners];
|
218
|
|
219
|
control.recreateSticker(border_step,corner_step);
|
220
|
}
|
221
|
|
222
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
223
|
|
224
|
public void resetUI()
|
225
|
{
|
226
|
mPane.resetUI(this);
|
227
|
}
|
228
|
|
229
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
230
|
|
231
|
public ObjectControl getControl()
|
232
|
{
|
233
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
234
|
return view.getObjectControl();
|
235
|
}
|
236
|
}
|