| 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 |
7e9d918b
|
leszek
|
package org.distorted.patterns;
|
| 11 |
e9245b7b
|
leszek
|
|
| 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 |
8477cf44
|
leszek
|
import org.distorted.dialogs.DialogError;
|
| 20 |
a5972f92
|
leszek
|
import org.distorted.helpers.BaseActivity;
|
| 21 |
e9245b7b
|
leszek
|
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 |
a5972f92
|
leszek
|
public class PatternActivity extends BaseActivity
|
| 36 |
e9245b7b
|
leszek
|
{
|
| 37 |
a5972f92
|
leszek
|
public static final float RATIO_UPP = 0.100f;
|
| 38 |
e9245b7b
|
leszek
|
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 |
017f24b3
|
leszek
|
public static final float TITLE_TEXT_SIZE = 0.045f;
|
| 42 |
e9245b7b
|
leszek
|
|
| 43 |
c9f72ca3
|
leszek
|
private static final int ACTIVITY_NUMBER = 5;
|
| 44 |
e9245b7b
|
leszek
|
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 |
a5972f92
|
leszek
|
computeScreenDimensions();
|
| 61 |
|
|
hideNavigationBar();
|
| 62 |
e9245b7b
|
leszek
|
cutoutHack();
|
| 63 |
a5972f92
|
leszek
|
computeLowerBarHeight(RATIO_BAR);
|
| 64 |
|
|
computeUpperBarHeight(RATIO_UPP);
|
| 65 |
e9245b7b
|
leszek
|
}
|
| 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 |
9881dc03
|
leszek
|
restorePreferences();
|
| 110 |
e9245b7b
|
leszek
|
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 |
9881dc03
|
leszek
|
SharedPreferences.Editor editor = mPreferences.edit();
|
| 127 |
e9245b7b
|
leszek
|
|
| 128 |
017f24b3
|
leszek
|
for(int i=0; i< ScreenList.LENGTH; i++ )
|
| 129 |
e9245b7b
|
leszek
|
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 |
9881dc03
|
leszek
|
private void restorePreferences()
|
| 140 |
e9245b7b
|
leszek
|
{
|
| 141 |
017f24b3
|
leszek
|
for (int i=0; i<ScreenList.LENGTH; i++)
|
| 142 |
9881dc03
|
leszek
|
ScreenList.getScreen(i).getScreenClass().restorePreferences(mPreferences);
|
| 143 |
e9245b7b
|
leszek
|
|
| 144 |
9881dc03
|
leszek
|
ScreenList.restorePreferences(mPreferences);
|
| 145 |
e9245b7b
|
leszek
|
}
|
| 146 |
|
|
|
| 147 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 148 |
|
|
|
| 149 |
|
|
void OpenGLError()
|
| 150 |
|
|
{
|
| 151 |
8477cf44
|
leszek
|
DialogError errDiag = new DialogError();
|
| 152 |
e9245b7b
|
leszek
|
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 |
c02235d5
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 182 |
|
|
|
| 183 |
|
|
public int getObjectOrdinal()
|
| 184 |
|
|
{
|
| 185 |
|
|
return mObjectOrdinal;
|
| 186 |
|
|
}
|
| 187 |
|
|
|
| 188 |
e9245b7b
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 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 |
337f4660
|
leszek
|
control.changeIfDifferent(mObjectOrdinal,name,iconMode,asset);
|
| 203 |
e9245b7b
|
leszek
|
}
|
| 204 |
|
|
}
|