Revision 7e9d918b
Added by Leszek Koltunski 11 months ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 32 | 32 |
<activity android:name="org.distorted.tutorials.TutorialActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 33 | 33 |
<activity android:name="org.distorted.info.InfoActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 34 | 34 |
<activity android:name="org.distorted.bandaged.BandagedActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 35 |
<activity android:name="org.distorted.solverui.SolverActivity" android:exported="false" android:screenOrientation="portrait"/>
|
|
| 36 |
<activity android:name="org.distorted.patternui.PatternActivity" android:exported="false" android:screenOrientation="portrait"/>
|
|
| 37 |
<activity android:name="org.distorted.playui.PlayActivity" android:exported="false" android:screenOrientation="portrait"/>
|
|
| 35 |
<activity android:name="org.distorted.solvers.SolverActivity" android:exported="false" android:screenOrientation="portrait"/>
|
|
| 36 |
<activity android:name="org.distorted.patterns.PatternActivity" android:exported="false" android:screenOrientation="portrait"/>
|
|
| 37 |
<activity android:name="org.distorted.play.PlayActivity" android:exported="false" android:screenOrientation="portrait"/> |
|
| 38 | 38 |
<activity android:name="org.distorted.config.ConfigActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 39 | 39 |
|
| 40 | 40 |
<service |
| src/main/java/org/distorted/bandaged/BandagedActivity.java | ||
|---|---|---|
| 31 | 31 |
import org.distorted.objectlib.main.TwistyJson; |
| 32 | 32 |
import org.distorted.objectlib.main.TwistyObject; |
| 33 | 33 |
import org.distorted.os.OSInterface; |
| 34 |
import org.distorted.playui.PlayActivity;
|
|
| 34 |
import org.distorted.play.PlayActivity; |
|
| 35 | 35 |
|
| 36 | 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 37 | 37 |
|
| src/main/java/org/distorted/dialogs/DialogAbandon.java | ||
|---|---|---|
| 16 | 16 |
import androidx.fragment.app.FragmentActivity; |
| 17 | 17 |
|
| 18 | 18 |
import org.distorted.main.R; |
| 19 |
import org.distorted.playui.PlayActivity;
|
|
| 20 |
import org.distorted.playui.ScreenList;
|
|
| 19 |
import org.distorted.play.PlayActivity; |
|
| 20 |
import org.distorted.play.ScreenList; |
|
| 21 | 21 |
|
| 22 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 23 | 23 |
|
| src/main/java/org/distorted/dialogs/DialogNewRecord.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
import org.distorted.main.R; |
| 21 | 21 |
import org.distorted.helpers.RubikScores; |
| 22 |
import org.distorted.playui.PlayActivity;
|
|
| 22 |
import org.distorted.play.PlayActivity; |
|
| 23 | 23 |
|
| 24 | 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 25 | 25 |
|
| src/main/java/org/distorted/dialogs/DialogPattern.java | ||
|---|---|---|
| 23 | 23 |
import org.distorted.objectlib.patterns.RubikPatternList; |
| 24 | 24 |
import org.distorted.objects.RubikObject; |
| 25 | 25 |
import org.distorted.objects.RubikObjectList; |
| 26 |
import org.distorted.patternui.PatternActivity;
|
|
| 27 |
import org.distorted.patternui.ScreenList;
|
|
| 28 |
import org.distorted.patternui.ScreenPattern;
|
|
| 26 |
import org.distorted.patterns.PatternActivity;
|
|
| 27 |
import org.distorted.patterns.ScreenList;
|
|
| 28 |
import org.distorted.patterns.ScreenPattern;
|
|
| 29 | 29 |
|
| 30 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 31 | 31 |
|
| src/main/java/org/distorted/dialogs/DialogSetName.java | ||
|---|---|---|
| 24 | 24 |
|
| 25 | 25 |
import org.distorted.main.R; |
| 26 | 26 |
import org.distorted.helpers.RubikScores; |
| 27 |
import org.distorted.playui.PlayActivity;
|
|
| 27 |
import org.distorted.play.PlayActivity; |
|
| 28 | 28 |
|
| 29 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 30 | 30 |
|
| src/main/java/org/distorted/dialogs/DialogSolved.java | ||
|---|---|---|
| 17 | 17 |
import android.widget.TextView; |
| 18 | 18 |
|
| 19 | 19 |
import org.distorted.main.R; |
| 20 |
import org.distorted.playui.PlayActivity;
|
|
| 20 |
import org.distorted.play.PlayActivity; |
|
| 21 | 21 |
|
| 22 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 23 | 23 |
|
| src/main/java/org/distorted/dialogs/DialogSolverView.java | ||
|---|---|---|
| 20 | 20 |
import org.distorted.objectlib.main.TwistyObject; |
| 21 | 21 |
import org.distorted.objectlib.solvers.verifiers.SolverAbstract; |
| 22 | 22 |
import org.distorted.objectlib.solvers.verifiers.SolvingList; |
| 23 |
import org.distorted.solverui.ScreenList;
|
|
| 24 |
import org.distorted.solverui.ScreenSetupPosition;
|
|
| 25 |
import org.distorted.solverui.SolverActivity;
|
|
| 23 |
import org.distorted.solvers.ScreenList;
|
|
| 24 |
import org.distorted.solvers.ScreenSetupPosition;
|
|
| 25 |
import org.distorted.solvers.SolverActivity;
|
|
| 26 | 26 |
|
| 27 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 | 28 |
|
| src/main/java/org/distorted/dialogs/DialogSolvers.java | ||
|---|---|---|
| 22 | 22 |
|
| 23 | 23 |
import org.distorted.main.R; |
| 24 | 24 |
import org.distorted.objectlib.metadata.ListObjects; |
| 25 |
import org.distorted.solverui.SolverActivity;
|
|
| 25 |
import org.distorted.solvers.SolverActivity;
|
|
| 26 | 26 |
import org.distorted.objectlib.solvers.verifiers.SolvingList; |
| 27 | 27 |
|
| 28 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/main/MainActivity.java | ||
|---|---|---|
| 42 | 42 |
import org.distorted.messaging.RubikInAppMessanging; |
| 43 | 43 |
import org.distorted.objects.RubikObject; |
| 44 | 44 |
import org.distorted.objects.RubikObjectList; |
| 45 |
import org.distorted.patternui.PatternActivity;
|
|
| 46 |
import org.distorted.playui.PlayActivity;
|
|
| 47 |
import org.distorted.solverui.SolverActivity;
|
|
| 45 |
import org.distorted.patterns.PatternActivity;
|
|
| 46 |
import org.distorted.play.PlayActivity; |
|
| 47 |
import org.distorted.solvers.SolverActivity;
|
|
| 48 | 48 |
import org.distorted.tutorials.TutorialActivity; |
| 49 | 49 |
|
| 50 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/patterns/PatternActivity.java | ||
|---|---|---|
| 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.patterns; |
|
| 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.DialogError; |
|
| 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 |
DialogError errDiag = new DialogError(); |
|
| 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 |
} |
|
| src/main/java/org/distorted/patterns/PatternObjectLibInterface.java | ||
|---|---|---|
| 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.patterns; |
|
| 11 |
|
|
| 12 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
|
| 13 |
|
|
| 14 |
import org.distorted.library.message.EffectMessageSender; |
|
| 15 |
import org.distorted.main.BuildConfig; |
|
| 16 |
import org.distorted.objectlib.helpers.BlockController; |
|
| 17 |
import org.distorted.objectlib.helpers.ObjectLibInterface; |
|
| 18 |
import org.distorted.objects.RubikObject; |
|
| 19 |
import org.distorted.objects.RubikObjectList; |
|
| 20 |
|
|
| 21 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 22 |
|
|
| 23 |
public class PatternObjectLibInterface implements ObjectLibInterface |
|
| 24 |
{
|
|
| 25 |
PatternObjectLibInterface(PatternActivity act) { }
|
|
| 26 |
public void onScrambleEffectFinished() { }
|
|
| 27 |
public void onRemoveRotation(int axis, int row, int angle) { }
|
|
| 28 |
public void onBeginRotation() { }
|
|
| 29 |
public void failedToDrag() { }
|
|
| 30 |
public void onSolved() { }
|
|
| 31 |
public void onObjectCreated(long time) { }
|
|
| 32 |
public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
|
|
| 33 |
public void onReplaceModeDown(int cubit, int face) { }
|
|
| 34 |
public void onReplaceModeUp() { }
|
|
| 35 |
|
|
| 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 37 |
|
|
| 38 |
public void reportProblem(String problem, boolean recordException) |
|
| 39 |
{
|
|
| 40 |
if( BuildConfig.DEBUG ) |
|
| 41 |
{
|
|
| 42 |
android.util.Log.e("libInterface", problem);
|
|
| 43 |
} |
|
| 44 |
else |
|
| 45 |
{
|
|
| 46 |
if( recordException ) |
|
| 47 |
{
|
|
| 48 |
Exception ex = new Exception(problem); |
|
| 49 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 50 |
crashlytics.setCustomKey("problem" , problem);
|
|
| 51 |
crashlytics.recordException(ex); |
|
| 52 |
} |
|
| 53 |
else |
|
| 54 |
{
|
|
| 55 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 56 |
crashlytics.log(problem); |
|
| 57 |
} |
|
| 58 |
} |
|
| 59 |
} |
|
| 60 |
|
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
|
|
| 63 |
private void reportScramblingProblem(int place, long pause, long resume, long time) |
|
| 64 |
{
|
|
| 65 |
String error = "SCRAMBLING BLOCK "+place+" blocked for "+time; |
|
| 66 |
|
|
| 67 |
if( BuildConfig.DEBUG ) |
|
| 68 |
{
|
|
| 69 |
android.util.Log.e("libInterface", error);
|
|
| 70 |
} |
|
| 71 |
else |
|
| 72 |
{
|
|
| 73 |
Exception ex = new Exception(error); |
|
| 74 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 75 |
crashlytics.setCustomKey("pause" , pause );
|
|
| 76 |
crashlytics.setCustomKey("resume", resume );
|
|
| 77 |
crashlytics.recordException(ex); |
|
| 78 |
} |
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 82 |
|
|
| 83 |
private void reportRotationProblem(int place, long pause, long resume, long time) |
|
| 84 |
{
|
|
| 85 |
String error = "ROTATION BLOCK "+place+" blocked for "+time; |
|
| 86 |
|
|
| 87 |
if( BuildConfig.DEBUG ) |
|
| 88 |
{
|
|
| 89 |
android.util.Log.e("libInterface", error);
|
|
| 90 |
} |
|
| 91 |
else |
|
| 92 |
{
|
|
| 93 |
Exception ex = new Exception(error); |
|
| 94 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 95 |
crashlytics.setCustomKey("pause" , pause );
|
|
| 96 |
crashlytics.setCustomKey("resume", resume);
|
|
| 97 |
crashlytics.recordException(ex); |
|
| 98 |
} |
|
| 99 |
} |
|
| 100 |
|
|
| 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 102 |
|
|
| 103 |
private void reportThreadProblem(int place, long pause, long resume, long time) |
|
| 104 |
{
|
|
| 105 |
String error = EffectMessageSender.reportState(); |
|
| 106 |
|
|
| 107 |
if( BuildConfig.DEBUG ) |
|
| 108 |
{
|
|
| 109 |
android.util.Log.e("libInterface", error);
|
|
| 110 |
} |
|
| 111 |
else |
|
| 112 |
{
|
|
| 113 |
Exception ex = new Exception(error); |
|
| 114 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 115 |
crashlytics.setCustomKey("pause" , pause );
|
|
| 116 |
crashlytics.setCustomKey("resume", resume );
|
|
| 117 |
crashlytics.recordException(ex); |
|
| 118 |
} |
|
| 119 |
} |
|
| 120 |
|
|
| 121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 122 |
|
|
| 123 |
public void reportBlockProblem(int type, int place, long pause, long resume, long time) |
|
| 124 |
{
|
|
| 125 |
switch(type) |
|
| 126 |
{
|
|
| 127 |
case BlockController.TYPE_SCRAMBLING: reportScramblingProblem(place,pause,resume,time); break; |
|
| 128 |
case BlockController.TYPE_ROTATION : reportRotationProblem(place,pause,resume,time); break; |
|
| 129 |
case BlockController.TYPE_THREAD : reportThreadProblem(place,pause,resume,time); break; |
|
| 130 |
} |
|
| 131 |
} |
|
| 132 |
|
|
| 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 134 |
|
|
| 135 |
public void reportJSONError(String error, int ordinal) |
|
| 136 |
{
|
|
| 137 |
RubikObject object = RubikObjectList.getObject(ordinal); |
|
| 138 |
String name = object==null ? "NULL" : object.getUpperName(); |
|
| 139 |
|
|
| 140 |
if( BuildConfig.DEBUG ) |
|
| 141 |
{
|
|
| 142 |
android.util.Log.e("libInterface", "name="+name+" JSON error: "+error);
|
|
| 143 |
} |
|
| 144 |
else |
|
| 145 |
{
|
|
| 146 |
Exception ex = new Exception(error); |
|
| 147 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 148 |
crashlytics.setCustomKey("name" , name );
|
|
| 149 |
crashlytics.setCustomKey("JSONerror", error );
|
|
| 150 |
crashlytics.recordException(ex); |
|
| 151 |
} |
|
| 152 |
} |
|
| 153 |
} |
|
| src/main/java/org/distorted/patterns/PatternRenderer.java | ||
|---|---|---|
| 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.patterns; |
|
| 11 |
|
|
| 12 |
import android.content.res.Resources; |
|
| 13 |
import android.opengl.GLES30; |
|
| 14 |
import android.opengl.GLSurfaceView; |
|
| 15 |
|
|
| 16 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
|
| 17 |
|
|
| 18 |
import org.distorted.library.effect.EffectType; |
|
| 19 |
import org.distorted.library.effect.VertexEffectQuaternion; |
|
| 20 |
import org.distorted.library.effect.VertexEffectRotate; |
|
| 21 |
import org.distorted.library.main.DistortedLibrary; |
|
| 22 |
import org.distorted.library.main.DistortedScreen; |
|
| 23 |
import org.distorted.library.main.InternalOutputSurface; |
|
| 24 |
import org.distorted.library.mesh.MeshBase; |
|
| 25 |
import org.distorted.main.BuildConfig; |
|
| 26 |
import org.distorted.objectlib.effects.BaseEffect; |
|
| 27 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 28 |
|
|
| 29 |
import java.io.InputStream; |
|
| 30 |
|
|
| 31 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 32 |
import javax.microedition.khronos.opengles.GL10; |
|
| 33 |
|
|
| 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 35 |
|
|
| 36 |
public class PatternRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser |
|
| 37 |
{
|
|
| 38 |
private final PatternSurfaceView mView; |
|
| 39 |
private final Resources mResources; |
|
| 40 |
private final DistortedScreen mScreen; |
|
| 41 |
private final ObjectControl mControl; |
|
| 42 |
private boolean mErrorShown; |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
PatternRenderer(PatternSurfaceView v) |
|
| 47 |
{
|
|
| 48 |
mView = v; |
|
| 49 |
mResources = v.getResources(); |
|
| 50 |
|
|
| 51 |
mErrorShown = false; |
|
| 52 |
mControl = v.getObjectControl(); |
|
| 53 |
mScreen = new DistortedScreen(); |
|
| 54 |
|
|
| 55 |
PatternActivity act = (PatternActivity)v.getContext(); |
|
| 56 |
act.setUpBackgroundColor(mScreen); |
|
| 57 |
|
|
| 58 |
mScreen.enableDepthStencil(InternalOutputSurface.DEPTH_NO_STENCIL); |
|
| 59 |
} |
|
| 60 |
|
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
|
|
| 63 |
DistortedScreen getScreen() |
|
| 64 |
{
|
|
| 65 |
return mScreen; |
|
| 66 |
} |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
// various things are done here delayed, 'after the next render' as not to be done mid-render and |
|
| 70 |
// cause artifacts. |
|
| 71 |
|
|
| 72 |
@Override |
|
| 73 |
public void onDrawFrame(GL10 glUnused) |
|
| 74 |
{
|
|
| 75 |
long time = System.currentTimeMillis(); |
|
| 76 |
mControl.preRender(); |
|
| 77 |
mScreen.render(time); |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
|
|
| 82 |
@Override |
|
| 83 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 84 |
{
|
|
| 85 |
mScreen.resize(width,height); |
|
| 86 |
mView.setScreenSize(width,height); |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 90 |
|
|
| 91 |
@Override |
|
| 92 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 93 |
{
|
|
| 94 |
DistortedLibrary.setMax(EffectType.VERTEX,ObjectControl.MAX_QUATS+1); |
|
| 95 |
MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS); |
|
| 96 |
|
|
| 97 |
VertexEffectRotate.enable(); |
|
| 98 |
VertexEffectQuaternion.enable(); |
|
| 99 |
BaseEffect.Type.enableEffects(); |
|
| 100 |
|
|
| 101 |
DistortedLibrary.onSurfaceCreated(this,1); |
|
| 102 |
DistortedLibrary.setCull(true); |
|
| 103 |
} |
|
| 104 |
|
|
| 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 106 |
|
|
| 107 |
public void distortedException(Exception ex) |
|
| 108 |
{
|
|
| 109 |
String message = ex.getMessage(); |
|
| 110 |
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION); |
|
| 111 |
String version = GLES30.glGetString(GLES30.GL_VERSION); |
|
| 112 |
String vendor = GLES30.glGetString(GLES30.GL_VENDOR); |
|
| 113 |
String renderer= GLES30.glGetString(GLES30.GL_RENDERER); |
|
| 114 |
|
|
| 115 |
if( message==null ) message = "exception NULL"; |
|
| 116 |
|
|
| 117 |
if( BuildConfig.DEBUG ) |
|
| 118 |
{
|
|
| 119 |
android.util.Log.e("DISTORTED", message );
|
|
| 120 |
android.util.Log.e("DISTORTED", "GLSL Version "+shading);
|
|
| 121 |
android.util.Log.e("DISTORTED", "GL Version " +version);
|
|
| 122 |
android.util.Log.e("DISTORTED", "GL Vendor " +vendor);
|
|
| 123 |
android.util.Log.e("DISTORTED", "GL Renderer " +renderer);
|
|
| 124 |
} |
|
| 125 |
else |
|
| 126 |
{
|
|
| 127 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 128 |
crashlytics.setCustomKey("DistortedError", message );
|
|
| 129 |
crashlytics.setCustomKey("GLSL Version" , shading );
|
|
| 130 |
crashlytics.setCustomKey("GLversion" , version );
|
|
| 131 |
crashlytics.setCustomKey("GL Vendor " , vendor );
|
|
| 132 |
crashlytics.setCustomKey("GLSLrenderer" , renderer);
|
|
| 133 |
crashlytics.recordException(ex); |
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
int glsl = DistortedLibrary.getGLSL(); |
|
| 137 |
|
|
| 138 |
if( glsl< 300 && !mErrorShown ) |
|
| 139 |
{
|
|
| 140 |
mErrorShown = true; |
|
| 141 |
PatternActivity act = (PatternActivity)mView.getContext(); |
|
| 142 |
act.OpenGLError(); |
|
| 143 |
} |
|
| 144 |
} |
|
| 145 |
|
|
| 146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 147 |
|
|
| 148 |
public InputStream localFile(int fileID) |
|
| 149 |
{
|
|
| 150 |
return mResources.openRawResource(fileID); |
|
| 151 |
} |
|
| 152 |
|
|
| 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 154 |
|
|
| 155 |
public void logMessage(String message) |
|
| 156 |
{
|
|
| 157 |
android.util.Log.e("Rubik", message );
|
|
| 158 |
} |
|
| 159 |
} |
|
| src/main/java/org/distorted/patterns/PatternSurfaceView.java | ||
|---|---|---|
| 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.patterns; |
|
| 11 |
|
|
| 12 |
import android.annotation.SuppressLint; |
|
| 13 |
import android.app.ActivityManager; |
|
| 14 |
import android.content.Context; |
|
| 15 |
import android.content.pm.ConfigurationInfo; |
|
| 16 |
import android.opengl.GLES30; |
|
| 17 |
import android.opengl.GLSurfaceView; |
|
| 18 |
import android.util.AttributeSet; |
|
| 19 |
import android.view.MotionEvent; |
|
| 20 |
|
|
| 21 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
|
| 22 |
|
|
| 23 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 24 |
import org.distorted.objectlib.main.TwistyObjectNode; |
|
| 25 |
import org.distorted.os.OSInterface; |
|
| 26 |
|
|
| 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 28 |
|
|
| 29 |
public class PatternSurfaceView extends GLSurfaceView |
|
| 30 |
{
|
|
| 31 |
private ObjectControl mObjectController; |
|
| 32 |
private OSInterface mInterface; |
|
| 33 |
private PatternRenderer mRenderer; |
|
| 34 |
private boolean mCreated; |
|
| 35 |
|
|
| 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 37 |
|
|
| 38 |
void setScreenSize(int width, int height) |
|
| 39 |
{
|
|
| 40 |
mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height))); |
|
| 41 |
|
|
| 42 |
if( !mCreated ) |
|
| 43 |
{
|
|
| 44 |
mCreated = true; |
|
| 45 |
mObjectController.createNode(width,height); |
|
| 46 |
TwistyObjectNode objectNode = mObjectController.getNode(); |
|
| 47 |
objectNode.glDepthMask(false); |
|
| 48 |
objectNode.glStencilMask(0); |
|
| 49 |
mRenderer.getScreen().attach(objectNode); |
|
| 50 |
} |
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 54 |
|
|
| 55 |
PatternRenderer getRenderer() |
|
| 56 |
{
|
|
| 57 |
return mRenderer; |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
OSInterface getInterface() |
|
| 63 |
{
|
|
| 64 |
return mInterface; |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
|
|
| 69 |
ObjectControl getObjectControl() |
|
| 70 |
{
|
|
| 71 |
return mObjectController; |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 75 |
// PUBLIC API |
|
| 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 77 |
|
|
| 78 |
public PatternSurfaceView(Context context, AttributeSet attrs) |
|
| 79 |
{
|
|
| 80 |
super(context,attrs); |
|
| 81 |
|
|
| 82 |
mCreated = false; |
|
| 83 |
|
|
| 84 |
if(!isInEditMode()) |
|
| 85 |
{
|
|
| 86 |
PatternActivity act = (PatternActivity)context; |
|
| 87 |
PatternObjectLibInterface ref = new PatternObjectLibInterface(act); |
|
| 88 |
mInterface = new OSInterface(act,ref); |
|
| 89 |
mObjectController = new ObjectControl(mInterface); |
|
| 90 |
mRenderer = new PatternRenderer(this); |
|
| 91 |
|
|
| 92 |
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
| 93 |
|
|
| 94 |
try |
|
| 95 |
{
|
|
| 96 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
| 97 |
int esVersion = configurationInfo.reqGlEsVersion>>16; |
|
| 98 |
setEGLContextClientVersion(esVersion); |
|
| 99 |
setRenderer(mRenderer); |
|
| 100 |
} |
|
| 101 |
catch(Exception ex) |
|
| 102 |
{
|
|
| 103 |
act.OpenGLError(); |
|
| 104 |
|
|
| 105 |
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION); |
|
| 106 |
String version = GLES30.glGetString(GLES30.GL_VERSION); |
|
| 107 |
String vendor = GLES30.glGetString(GLES30.GL_VENDOR); |
|
| 108 |
String renderer= GLES30.glGetString(GLES30.GL_RENDERER); |
|
| 109 |
|
|
| 110 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 111 |
crashlytics.setCustomKey("GLSL Version" , shading );
|
|
| 112 |
crashlytics.setCustomKey("GL version" , version );
|
|
| 113 |
crashlytics.setCustomKey("GL Vendor " , vendor );
|
|
| 114 |
crashlytics.setCustomKey("GLSL renderer" , renderer);
|
|
| 115 |
crashlytics.recordException(ex); |
|
| 116 |
} |
|
| 117 |
} |
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 121 |
|
|
| 122 |
@Override |
|
| 123 |
public void onPause() |
|
| 124 |
{
|
|
| 125 |
super.onPause(); |
|
| 126 |
mObjectController.onPause(); |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 130 |
|
|
| 131 |
@Override |
|
| 132 |
public void onResume() |
|
| 133 |
{
|
|
| 134 |
super.onResume(); |
|
| 135 |
mObjectController.onResume(); |
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 139 |
|
|
| 140 |
@SuppressLint("ClickableViewAccessibility")
|
|
| 141 |
@Override |
|
| 142 |
public boolean onTouchEvent(MotionEvent event) |
|
| 143 |
{
|
|
| 144 |
mInterface.setMotionEvent(event); |
|
| 145 |
int mode = ScreenList.getMode(); |
|
| 146 |
return mObjectController.onTouchEvent(mode); |
|
| 147 |
} |
|
| 148 |
} |
|
| 149 |
|
|
| src/main/java/org/distorted/patterns/ScreenAbstract.java | ||
|---|---|---|
| 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.patterns; |
|
| 11 |
|
|
| 12 |
import android.content.SharedPreferences; |
|
| 13 |
|
|
| 14 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 15 |
|
|
| 16 |
public abstract class ScreenAbstract |
|
| 17 |
{
|
|
| 18 |
abstract void enterScreen(PatternActivity act); |
|
| 19 |
abstract void leaveScreen(PatternActivity act); |
|
| 20 |
public abstract void savePreferences(SharedPreferences.Editor editor); |
|
| 21 |
public abstract void restorePreferences(SharedPreferences preferences); |
|
| 22 |
} |
|
| src/main/java/org/distorted/patterns/ScreenList.java | ||
|---|---|---|
| 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.patterns; |
|
| 11 |
|
|
| 12 |
import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG; |
|
| 13 |
|
|
| 14 |
import android.content.SharedPreferences; |
|
| 15 |
|
|
| 16 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 17 |
|
|
| 18 |
public enum ScreenList |
|
| 19 |
{
|
|
| 20 |
PATT ( null, MODE_DRAG, new ScreenPattern() ), |
|
| 21 |
; |
|
| 22 |
|
|
| 23 |
public static final int LENGTH = values().length; |
|
| 24 |
private static final ScreenList[] screens; |
|
| 25 |
private final ScreenList mBack; |
|
| 26 |
private final int mMode; |
|
| 27 |
private final ScreenAbstract mClass; |
|
| 28 |
|
|
| 29 |
private static ScreenList mCurrScreen; |
|
| 30 |
|
|
| 31 |
static |
|
| 32 |
{
|
|
| 33 |
int i = 0; |
|
| 34 |
screens = new ScreenList[LENGTH]; |
|
| 35 |
for(ScreenList state: ScreenList.values()) screens[i++] = state; |
|
| 36 |
} |
|
| 37 |
|
|
| 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 39 |
|
|
| 40 |
public static ScreenList getScreen(int ordinal) |
|
| 41 |
{
|
|
| 42 |
return ordinal>=0 && ordinal<LENGTH ? screens[ordinal] : PATT; |
|
| 43 |
} |
|
| 44 |
|
|
| 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 46 |
|
|
| 47 |
public static ScreenList getScreenFromName(String name) |
|
| 48 |
{
|
|
| 49 |
for(int i=0; i<LENGTH; i++) |
|
| 50 |
{
|
|
| 51 |
if( name.equals(screens[i].name()) ) |
|
| 52 |
{
|
|
| 53 |
return screens[i]; |
|
| 54 |
} |
|
| 55 |
} |
|
| 56 |
|
|
| 57 |
return PATT; |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
public static ScreenList getCurrentScreen() |
|
| 63 |
{
|
|
| 64 |
return mCurrScreen; |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
|
|
| 69 |
public static int getMode() |
|
| 70 |
{
|
|
| 71 |
return mCurrScreen.mMode; |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 75 |
|
|
| 76 |
public static void savePreferences(SharedPreferences.Editor editor) |
|
| 77 |
{
|
|
| 78 |
editor.putString("curr_state_name", mCurrScreen.name() );
|
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 82 |
|
|
| 83 |
public static void restorePreferences(SharedPreferences preferences) |
|
| 84 |
{
|
|
| 85 |
String currScreenName = preferences.getString("curr_state_name", ScreenList.PATT.name() );
|
|
| 86 |
mCurrScreen = getScreenFromName(currScreenName); |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 90 |
|
|
| 91 |
public static void goBack(PatternActivity act) |
|
| 92 |
{
|
|
| 93 |
switchScreen(act, mCurrScreen.mBack ); |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 97 |
|
|
| 98 |
public static void setScreen(PatternActivity act) |
|
| 99 |
{
|
|
| 100 |
mCurrScreen.enterScreen(act); |
|
| 101 |
} |
|
| 102 |
|
|
| 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 104 |
|
|
| 105 |
public static void switchScreen(PatternActivity act, ScreenList next) |
|
| 106 |
{
|
|
| 107 |
if( next!=null ) |
|
| 108 |
{
|
|
| 109 |
if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act); |
|
| 110 |
next.enterScreen(act); |
|
| 111 |
mCurrScreen = next; |
|
| 112 |
} |
|
| 113 |
else |
|
| 114 |
{
|
|
| 115 |
act.finish(); |
|
| 116 |
} |
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 120 |
|
|
| 121 |
ScreenList(ScreenList back, int mode, ScreenAbstract clazz) |
|
| 122 |
{
|
|
| 123 |
mBack = back; |
|
| 124 |
mMode = mode; |
|
| 125 |
mClass= clazz; |
|
| 126 |
} |
|
| 127 |
|
|
| 128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 129 |
|
|
| 130 |
public ScreenAbstract getScreenClass() |
|
| 131 |
{
|
|
| 132 |
return mClass; |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 136 |
|
|
| 137 |
public void leaveScreen(PatternActivity act) |
|
| 138 |
{
|
|
| 139 |
mClass.leaveScreen(act); |
|
| 140 |
} |
|
| 141 |
|
|
| 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 143 |
|
|
| 144 |
public void enterScreen(PatternActivity act) |
|
| 145 |
{
|
|
| 146 |
mClass.enterScreen(act); |
|
| 147 |
} |
|
| 148 |
} |
|
| src/main/java/org/distorted/patterns/ScreenPattern.java | ||
|---|---|---|
| 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.patterns; |
|
| 11 |
|
|
| 12 |
import android.content.SharedPreferences; |
|
| 13 |
import android.os.Bundle; |
|
| 14 |
import android.util.TypedValue; |
|
| 15 |
import android.view.Gravity; |
|
| 16 |
import android.view.View; |
|
| 17 |
import android.widget.LinearLayout; |
|
| 18 |
import android.widget.TextView; |
|
| 19 |
|
|
| 20 |
import org.distorted.dialogs.DialogPattern; |
|
| 21 |
import org.distorted.helpers.TransparentButton; |
|
| 22 |
import org.distorted.helpers.TransparentImageButton; |
|
| 23 |
import org.distorted.main.R; |
|
| 24 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 25 |
import org.distorted.objectlib.patterns.RubikPattern; |
|
| 26 |
|
|
| 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 28 |
|
|
| 29 |
public class ScreenPattern extends ScreenAbstract |
|
| 30 |
{
|
|
| 31 |
private TransparentImageButton mPrevButton, mNextButton, mBackButton; |
|
| 32 |
private TransparentImageButton mPrevPatt, mNextPatt; |
|
| 33 |
private TransparentButton mTextButton; |
|
| 34 |
private TextView mMovesText; |
|
| 35 |
private int mNumMoves; |
|
| 36 |
private int mPatternOrdinal, mCategory, mPattern; |
|
| 37 |
private float mButtonSize; |
|
| 38 |
|
|
| 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 40 |
|
|
| 41 |
ScreenPattern() |
|
| 42 |
{
|
|
| 43 |
|
|
| 44 |
} |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
void leaveScreen(PatternActivity act) |
|
| 49 |
{
|
|
| 50 |
|
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 54 |
|
|
| 55 |
void enterScreen(final PatternActivity act) |
|
| 56 |
{
|
|
| 57 |
float width = act.getScreenWidthInPixels(); |
|
| 58 |
mButtonSize = width*PatternActivity.BUTTON_TEXT_SIZE; |
|
| 59 |
|
|
| 60 |
mPatternOrdinal = -1; |
|
| 61 |
mCategory = -1; |
|
| 62 |
mPattern = -1; |
|
| 63 |
|
|
| 64 |
// TOP //////////////////////////// |
|
| 65 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
| 66 |
layoutTop.removeAllViews(); |
|
| 67 |
|
|
| 68 |
setupPrevPatt(act); |
|
| 69 |
setupNextPatt(act); |
|
| 70 |
setupTextButton(act,width); |
|
| 71 |
|
|
| 72 |
LinearLayout.LayoutParams pTL = new LinearLayout.LayoutParams((int)( width/6),LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 73 |
LinearLayout.LayoutParams pTM = new LinearLayout.LayoutParams((int)(2*width/3),LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 74 |
LinearLayout.LayoutParams pTR = new LinearLayout.LayoutParams((int)( width/6),LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 75 |
|
|
| 76 |
LinearLayout layoutTL = new LinearLayout(act); |
|
| 77 |
layoutTL.setLayoutParams(pTL); |
|
| 78 |
LinearLayout layoutTM = new LinearLayout(act); |
|
| 79 |
layoutTM.setLayoutParams(pTM); |
|
| 80 |
LinearLayout layoutTR = new LinearLayout(act); |
|
| 81 |
layoutTR.setLayoutParams(pTR); |
|
| 82 |
|
|
| 83 |
layoutTL.addView(mPrevPatt); |
|
| 84 |
layoutTM.addView(mTextButton); |
|
| 85 |
layoutTR.addView(mNextPatt); |
|
| 86 |
|
|
| 87 |
layoutTop.addView(layoutTL); |
|
| 88 |
layoutTop.addView(layoutTM); |
|
| 89 |
layoutTop.addView(layoutTR); |
|
| 90 |
|
|
| 91 |
// BOT //////////////////////////// |
|
| 92 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
| 93 |
layoutBot.removeAllViews(); |
|
| 94 |
|
|
| 95 |
setupPrevButton(act); |
|
| 96 |
setupNextButton(act); |
|
| 97 |
setupTextView(act,width); |
|
| 98 |
|
|
| 99 |
LinearLayout.LayoutParams pBL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 100 |
LinearLayout.LayoutParams pBM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 101 |
LinearLayout.LayoutParams pBR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 102 |
|
|
| 103 |
LinearLayout layoutBL = new LinearLayout(act); |
|
| 104 |
layoutBL.setLayoutParams(pBL); |
|
| 105 |
LinearLayout layoutBM = new LinearLayout(act); |
|
| 106 |
layoutBM.setLayoutParams(pBM); |
|
| 107 |
LinearLayout layoutBR = new LinearLayout(act); |
|
| 108 |
layoutBR.setLayoutParams(pBR); |
|
| 109 |
|
|
| 110 |
layoutBL.addView(mPrevButton); |
|
| 111 |
layoutBL.addView(mMovesText); |
|
| 112 |
layoutBL.addView(mNextButton); |
|
| 113 |
|
|
| 114 |
setupBackButton(act); |
|
| 115 |
|
|
| 116 |
layoutBR.addView(mBackButton); |
|
| 117 |
|
|
| 118 |
layoutBot.addView(layoutBL); |
|
| 119 |
layoutBot.addView(layoutBM); |
|
| 120 |
layoutBot.addView(layoutBR); |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 124 |
|
|
| 125 |
private void showDialog(final PatternActivity act) |
|
| 126 |
{
|
|
| 127 |
int ordinal = act.getObjectOrdinal(); |
|
| 128 |
Bundle bundle = new Bundle(); |
|
| 129 |
bundle.putString("argument", String.valueOf(ordinal) );
|
|
| 130 |
DialogPattern diag = new DialogPattern(); |
|
| 131 |
diag.setArguments(bundle); |
|
| 132 |
diag.show( act.getSupportFragmentManager(), DialogPattern.getDialogTag()); |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 136 |
|
|
| 137 |
private void setupPrevPatt(final PatternActivity act) |
|
| 138 |
{
|
|
| 139 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 140 |
mPrevPatt = new TransparentImageButton(act,R.drawable.ui_left,params); |
|
| 141 |
|
|
| 142 |
mPrevPatt.setOnClickListener( new View.OnClickListener() |
|
| 143 |
{
|
|
| 144 |
@Override |
|
| 145 |
public void onClick(View v) |
|
| 146 |
{
|
|
| 147 |
if( mPatternOrdinal<0 ) showDialog(act); |
|
| 148 |
else prevPattern(act); |
|
| 149 |
} |
|
| 150 |
}); |
|
| 151 |
} |
|
| 152 |
|
|
| 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 154 |
|
|
| 155 |
private void setupNextPatt(final PatternActivity act) |
|
| 156 |
{
|
|
| 157 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 158 |
mNextPatt = new TransparentImageButton(act,R.drawable.ui_right,params); |
|
| 159 |
|
|
| 160 |
mNextPatt.setOnClickListener( new View.OnClickListener() |
|
| 161 |
{
|
|
| 162 |
@Override |
|
| 163 |
public void onClick(View v) |
|
| 164 |
{
|
|
| 165 |
if( mPatternOrdinal<0 ) showDialog(act); |
|
| 166 |
else nextPattern(act); |
|
| 167 |
} |
|
| 168 |
}); |
|
| 169 |
} |
|
| 170 |
|
|
| 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 172 |
|
|
| 173 |
private void setupTextButton(final PatternActivity act, float width) |
|
| 174 |
{
|
|
| 175 |
float textSize = width*PatternActivity.TITLE_TEXT_SIZE; |
|
| 176 |
mTextButton = new TransparentButton(act,R.string.choose_pattern,textSize); |
|
| 177 |
|
|
| 178 |
mTextButton.setOnClickListener( new View.OnClickListener() |
|
| 179 |
{
|
|
| 180 |
@Override |
|
| 181 |
public void onClick(View v) |
|
| 182 |
{
|
|
| 183 |
showDialog(act); |
|
| 184 |
} |
|
| 185 |
}); |
|
| 186 |
} |
|
| 187 |
|
|
| 188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 189 |
|
|
| 190 |
private void setupBackButton(final PatternActivity act) |
|
| 191 |
{
|
|
| 192 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 193 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params); |
|
| 194 |
|
|
| 195 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
| 196 |
{
|
|
| 197 |
@Override |
|
| 198 |
public void onClick(View v) |
|
| 199 |
{
|
|
| 200 |
ScreenList.goBack(act); |
|
| 201 |
} |
|
| 202 |
}); |
|
| 203 |
} |
|
| 204 |
|
|
| 205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 206 |
|
|
| 207 |
private void setupPrevButton(final PatternActivity act) |
|
| 208 |
{
|
|
| 209 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 210 |
mPrevButton = new TransparentImageButton(act,R.drawable.ui_left,params); |
|
| 211 |
|
|
| 212 |
mPrevButton.setOnClickListener( new View.OnClickListener() |
|
| 213 |
{
|
|
| 214 |
@Override |
|
| 215 |
public void onClick(View v) |
|
| 216 |
{
|
|
| 217 |
if( mPatternOrdinal>=0 ) |
|
| 218 |
{
|
|
| 219 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 220 |
ObjectControl control = act.getControl(); |
|
| 221 |
pattern.backMove(control, mPatternOrdinal, mCategory, mPattern); |
|
| 222 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern); |
|
| 223 |
mMovesText.setText(act.getString(R.string.mo_placeholder, currMove, mNumMoves)); |
|
| 224 |
} |
|
| 225 |
} |
|
| 226 |
}); |
|
| 227 |
} |
|
| 228 |
|
|
| 229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 230 |
|
|
| 231 |
private void setupNextButton(final PatternActivity act) |
|
| 232 |
{
|
|
| 233 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 234 |
mNextButton = new TransparentImageButton(act,R.drawable.ui_right,params); |
|
| 235 |
|
|
| 236 |
mNextButton.setOnClickListener( new View.OnClickListener() |
|
| 237 |
{
|
|
| 238 |
@Override |
|
| 239 |
public void onClick(View v) |
|
| 240 |
{
|
|
| 241 |
if( mPatternOrdinal>=0 ) |
|
| 242 |
{
|
|
| 243 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 244 |
ObjectControl control = act.getControl(); |
|
| 245 |
pattern.makeMove(control, mPatternOrdinal, mCategory, mPattern); |
|
| 246 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern); |
|
| 247 |
mMovesText.setText(act.getString(R.string.mo_placeholder, currMove, mNumMoves)); |
|
| 248 |
} |
|
| 249 |
} |
|
| 250 |
}); |
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 254 |
|
|
| 255 |
private void setupTextView(final PatternActivity act, final float width) |
|
| 256 |
{
|
|
| 257 |
int padding = (int)(width*PatternActivity.PADDING); |
|
| 258 |
int margin = (int)(width*PatternActivity.SMALL_MARGIN); |
|
| 259 |
|
|
| 260 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f); |
|
| 261 |
params.topMargin = margin; |
|
| 262 |
params.bottomMargin = margin; |
|
| 263 |
params.leftMargin = margin; |
|
| 264 |
params.rightMargin = margin; |
|
| 265 |
|
|
| 266 |
mMovesText = new TextView(act); |
|
| 267 |
mMovesText.setTextSize(20); |
|
| 268 |
mMovesText.setLayoutParams(params); |
|
| 269 |
mMovesText.setPadding(padding,0,padding,0); |
|
| 270 |
mMovesText.setGravity(Gravity.CENTER); |
|
| 271 |
mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
|
| 272 |
mMovesText.setText(act.getString(R.string.mo_placeholder,0,0)); |
|
| 273 |
} |
|
| 274 |
|
|
| 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 276 |
|
|
| 277 |
public void setPattern(final PatternActivity act, int ordinal, int category, int pattern) |
|
| 278 |
{
|
|
| 279 |
mPatternOrdinal = ordinal; |
|
| 280 |
mCategory = category; |
|
| 281 |
mPattern = pattern; |
|
| 282 |
|
|
| 283 |
RubikPattern patt = RubikPattern.getInstance(); |
|
| 284 |
String patternName = patt.getPatternName(ordinal,category,pattern); |
|
| 285 |
mTextButton.setText(patternName); |
|
| 286 |
|
|
| 287 |
mNumMoves = patt.getNumMoves(ordinal,category,pattern); |
|
| 288 |
int currMove= patt.getCurMove(ordinal,category,pattern); |
|
| 289 |
|
|
| 290 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
|
| 291 |
} |
|
| 292 |
|
|
| 293 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 294 |
|
|
| 295 |
private void prevPattern(final PatternActivity act) |
|
| 296 |
{
|
|
| 297 |
RubikPattern patt = RubikPattern.getInstance(); |
|
| 298 |
|
|
| 299 |
if( mPattern>0 ) |
|
| 300 |
{
|
|
| 301 |
setPattern(act,mPatternOrdinal,mCategory,mPattern-1); |
|
| 302 |
} |
|
| 303 |
else |
|
| 304 |
{
|
|
| 305 |
if( mCategory>0 ) |
|
| 306 |
{
|
|
| 307 |
int numPat = patt.getNumPatterns(mPatternOrdinal,mCategory-1); |
|
| 308 |
setPattern(act,mPatternOrdinal,mCategory-1,numPat-1); |
|
| 309 |
} |
|
| 310 |
else |
|
| 311 |
{
|
|
| 312 |
int numCat = patt.getNumCategories(mPatternOrdinal); |
|
| 313 |
int numPat = patt.getNumPatterns(mPatternOrdinal,numCat-1); |
|
| 314 |
setPattern(act,mPatternOrdinal,numCat-1,numPat-1); |
|
| 315 |
} |
|
| 316 |
} |
|
| 317 |
|
|
| 318 |
int[][] moves = patt.reInitialize(mPatternOrdinal, mCategory, mPattern); |
|
| 319 |
ObjectControl control = act.getControl(); |
|
| 320 |
if( control!=null ) control.initializeObject(moves); |
|
| 321 |
} |
|
| 322 |
|
|
| 323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 324 |
|
|
| 325 |
private void nextPattern(final PatternActivity act) |
|
| 326 |
{
|
|
| 327 |
RubikPattern patt = RubikPattern.getInstance(); |
|
| 328 |
int numPat = patt.getNumPatterns(mPatternOrdinal,mCategory); |
|
| 329 |
|
|
| 330 |
if( mPattern<numPat-1 ) |
|
| 331 |
{
|
|
| 332 |
setPattern(act,mPatternOrdinal,mCategory,mPattern+1); |
|
| 333 |
} |
|
| 334 |
else |
|
| 335 |
{
|
|
| 336 |
int numCat = patt.getNumCategories(mPatternOrdinal); |
|
| 337 |
|
|
| 338 |
if( mCategory<numCat-1 ) |
|
| 339 |
{
|
|
| 340 |
setPattern(act,mPatternOrdinal,mCategory+1,0); |
|
| 341 |
} |
|
| 342 |
else |
|
| 343 |
{
|
|
| 344 |
setPattern(act,mPatternOrdinal,0,0); |
|
| 345 |
} |
|
| 346 |
} |
|
| 347 |
|
|
| 348 |
int[][] moves = patt.reInitialize(mPatternOrdinal, mCategory, mPattern); |
|
| 349 |
ObjectControl control = act.getControl(); |
|
| 350 |
if( control!=null ) control.initializeObject(moves); |
|
| 351 |
} |
|
| 352 |
|
|
| 353 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 354 |
|
|
| 355 |
public void savePreferences(SharedPreferences.Editor editor) |
|
| 356 |
{
|
|
| 357 |
|
|
| 358 |
} |
|
| 359 |
|
|
| 360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 361 |
|
|
| 362 |
public void restorePreferences(SharedPreferences preferences) |
|
| 363 |
{
|
|
| 364 |
|
|
| 365 |
} |
|
| 366 |
} |
|
| src/main/java/org/distorted/patternui/PatternActivity.java | ||
|---|---|---|
| 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.DialogError; |
|
| 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 |
|
|
Also available in: Unified diff
minor