| 1 |
58fd2ec0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 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 |
8cf17ca7
|
leszek
|
import android.content.SharedPreferences;
|
| 13 |
58fd2ec0
|
leszek
|
import android.os.Bundle;
|
| 14 |
|
|
|
| 15 |
8cf17ca7
|
leszek
|
import androidx.preference.PreferenceManager;
|
| 16 |
58fd2ec0
|
leszek
|
|
| 17 |
|
|
import org.distorted.dialogs.RubikDialogError;
|
| 18 |
e1637420
|
leszek
|
import org.distorted.dialogs.RubikDialogMessage;
|
| 19 |
a5972f92
|
leszek
|
import org.distorted.helpers.BaseActivity;
|
| 20 |
58fd2ec0
|
leszek
|
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 |
8cf17ca7
|
leszek
|
import org.distorted.os.OSInterface;
|
| 28 |
58fd2ec0
|
leszek
|
|
| 29 |
|
|
import java.io.InputStream;
|
| 30 |
|
|
|
| 31 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 32 |
|
|
|
| 33 |
a5972f92
|
leszek
|
public class ConfigActivity extends BaseActivity
|
| 34 |
58fd2ec0
|
leszek
|
{
|
| 35 |
|
|
private static final int ACTIVITY_NUMBER = 7;
|
| 36 |
|
|
private ConfigScreen mScreen;
|
| 37 |
14da3188
|
leszek
|
private ConfigScreenPane mPane;
|
| 38 |
58fd2ec0
|
leszek
|
private int mObjectOrdinal;
|
| 39 |
988e3d33
|
leszek
|
private boolean mSupportsAdjColors;
|
| 40 |
e1637420
|
leszek
|
private boolean mDisplayMessageDialog;
|
| 41 |
58fd2ec0
|
leszek
|
|
| 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 |
e1637420
|
leszek
|
mDisplayMessageDialog = true;
|
| 55 |
|
|
|
| 56 |
a5972f92
|
leszek
|
computeScreenDimensions();
|
| 57 |
58fd2ec0
|
leszek
|
hideNavigationBar();
|
| 58 |
|
|
cutoutHack();
|
| 59 |
a5972f92
|
leszek
|
computeLowerBarHeight(RATIO_BAR);
|
| 60 |
58fd2ec0
|
leszek
|
}
|
| 61 |
|
|
|
| 62 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 63 |
|
|
|
| 64 |
|
|
@Override
|
| 65 |
|
|
protected void onPause()
|
| 66 |
|
|
{
|
| 67 |
|
|
super.onPause();
|
| 68 |
|
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 69 |
|
|
view.onPause();
|
| 70 |
8cf17ca7
|
leszek
|
savePreferences();
|
| 71 |
58fd2ec0
|
leszek
|
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 |
9211042f
|
leszek
|
String key ="";
|
| 84 |
988e3d33
|
leszek
|
mSupportsAdjColors = false;
|
| 85 |
58fd2ec0
|
leszek
|
|
| 86 |
|
|
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
|
| 87 |
|
|
{
|
| 88 |
|
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
| 89 |
|
|
changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
|
| 90 |
988e3d33
|
leszek
|
|
| 91 |
|
|
if( object!=null )
|
| 92 |
|
|
{
|
| 93 |
|
|
key = object.getUpperName();
|
| 94 |
|
|
mSupportsAdjColors = object.supportsAdjustableColors();
|
| 95 |
|
|
}
|
| 96 |
58fd2ec0
|
leszek
|
}
|
| 97 |
9211042f
|
leszek
|
|
| 98 |
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
| 99 |
988e3d33
|
leszek
|
OSInterface os = view.getInterface();
|
| 100 |
|
|
os.setPreferences(preferences);
|
| 101 |
|
|
|
| 102 |
e1637420
|
leszek
|
restorePreferences(preferences);
|
| 103 |
9211042f
|
leszek
|
|
| 104 |
|
|
if( mScreen==null ) mScreen = new ConfigScreen();
|
| 105 |
|
|
mScreen.onAttachedToWindow(this,mObjectOrdinal);
|
| 106 |
|
|
|
| 107 |
988e3d33
|
leszek
|
mPane = new ConfigScreenPane(this,key,os,mSupportsAdjColors);
|
| 108 |
58fd2ec0
|
leszek
|
}
|
| 109 |
|
|
|
| 110 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 111 |
e91771e4
|
leszek
|
|
| 112 |
|
|
void repaintPuzzleFace(int cubit, int face)
|
| 113 |
|
|
{
|
| 114 |
988e3d33
|
leszek
|
if( mPane!=null && mSupportsAdjColors )
|
| 115 |
e91771e4
|
leszek
|
{
|
| 116 |
4bd09fe2
|
leszek
|
int color = mPane.getCurrentColor();
|
| 117 |
e91771e4
|
leszek
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 118 |
|
|
ObjectControl control = view.getObjectControl();
|
| 119 |
5b5b958a
|
leszek
|
control.repaintPuzzleFace(cubit,face,color);
|
| 120 |
e1637420
|
leszek
|
mDisplayMessageDialog = false;
|
| 121 |
e91771e4
|
leszek
|
}
|
| 122 |
|
|
}
|
| 123 |
|
|
|
| 124 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 125 |
|
|
|
| 126 |
58fd2ec0
|
leszek
|
@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 |
8cf17ca7
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 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 |
e1637420
|
leszek
|
editor.putBoolean("configDisplayDialog", mDisplayMessageDialog );
|
| 169 |
|
|
|
| 170 |
8cf17ca7
|
leszek
|
editor.apply();
|
| 171 |
|
|
}
|
| 172 |
|
|
|
| 173 |
9211042f
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 174 |
|
|
|
| 175 |
e1637420
|
leszek
|
private void restorePreferences(SharedPreferences preferences)
|
| 176 |
9211042f
|
leszek
|
{
|
| 177 |
|
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 178 |
15b600fd
|
leszek
|
view.getObjectControl().restoreStickers();
|
| 179 |
e1637420
|
leszek
|
|
| 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 |
9211042f
|
leszek
|
}
|
| 191 |
|
|
|
| 192 |
58fd2ec0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 193 |
|
|
// PUBLIC API
|
| 194 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 195 |
|
|
|
| 196 |
|
|
public ConfigRenderer getRenderer()
|
| 197 |
|
|
{
|
| 198 |
|
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 199 |
|
|
return view.getRenderer();
|
| 200 |
|
|
}
|
| 201 |
|
|
|
| 202 |
427ba5bf
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 203 |
|
|
|
| 204 |
|
|
public void recreateColors()
|
| 205 |
|
|
{
|
| 206 |
|
|
ObjectControl control = getControl();
|
| 207 |
|
|
control.recreateColors();
|
| 208 |
|
|
}
|
| 209 |
|
|
|
| 210 |
14da3188
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 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 |
4bd09fe2
|
leszek
|
mPane.resetUI(this);
|
| 227 |
14da3188
|
leszek
|
}
|
| 228 |
|
|
|
| 229 |
58fd2ec0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 230 |
|
|
|
| 231 |
|
|
public ObjectControl getControl()
|
| 232 |
|
|
{
|
| 233 |
|
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 234 |
|
|
return view.getObjectControl();
|
| 235 |
|
|
}
|
| 236 |
|
|
}
|