Revision e9245b7b
Added by Leszek Koltunski almost 2 years ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 36 | 36 |
<activity android:name="org.distorted.bandaged.BandagedPlayActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 37 | 37 |
<activity android:name="org.distorted.purchase.PurchaseActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 38 | 38 |
<activity android:name="org.distorted.solverui.SolverActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 39 |
<activity android:name="org.distorted.patternui.PatternActivity" android:exported="false" android:screenOrientation="portrait"/> |
|
| 39 | 40 |
|
| 40 | 41 |
<service |
| 41 | 42 |
android:name="org.distorted.messaging.RubikMessagingService" |
| src/main/java/org/distorted/dialogs/RubikDialogPattern.java | ||
|---|---|---|
| 57 | 57 |
public boolean hasArgument() { return false; }
|
| 58 | 58 |
public int getPositive() { return R.string.ok; }
|
| 59 | 59 |
public int getNegative() { return -1; }
|
| 60 |
|
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
|
|
| 63 |
public void positiveAction() |
|
| 64 |
{
|
|
| 65 |
|
|
| 66 |
} |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
|
|
| 70 |
public void negativeAction() |
|
| 71 |
{
|
|
| 72 |
|
|
| 73 |
} |
|
| 60 |
public void positiveAction() { }
|
|
| 61 |
public void negativeAction() { }
|
|
| 74 | 62 |
|
| 75 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 76 | 64 |
|
| src/main/java/org/distorted/dialogs/RubikDialogPatternSingle.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.dialogs; |
|
| 11 |
|
|
| 12 |
import android.app.Dialog; |
|
| 13 |
import android.view.View; |
|
| 14 |
import android.view.Window; |
|
| 15 |
import android.view.WindowManager; |
|
| 16 |
import android.widget.ExpandableListView; |
|
| 17 |
|
|
| 18 |
import androidx.fragment.app.FragmentActivity; |
|
| 19 |
|
|
| 20 |
import org.distorted.main.R; |
|
| 21 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 22 |
import org.distorted.objectlib.patterns.RubikPattern; |
|
| 23 |
import org.distorted.objectlib.patterns.RubikPatternList; |
|
| 24 |
import org.distorted.objects.RubikObjectList; |
|
| 25 |
import org.distorted.patternui.PatternActivity; |
|
| 26 |
import org.distorted.patternui.ScreenList; |
|
| 27 |
import org.distorted.patternui.ScreenPattern; |
|
| 28 |
|
|
| 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 30 |
|
|
| 31 |
public class RubikDialogPatternSingle extends RubikDialogAbstract |
|
| 32 |
{
|
|
| 33 |
private ExpandableListView mListView; |
|
| 34 |
private int mPatternOrdinal, mPos; |
|
| 35 |
private int mExpandedGroup; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
@Override |
|
| 40 |
public void onResume() |
|
| 41 |
{
|
|
| 42 |
super.onResume(); |
|
| 43 |
|
|
| 44 |
Window window = getDialog().getWindow(); |
|
| 45 |
|
|
| 46 |
if( window!=null ) |
|
| 47 |
{
|
|
| 48 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
| 49 |
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.98f ); |
|
| 50 |
params.height = (int)Math.min( mHeight*0.80f,mWidth*1.30f ); |
|
| 51 |
window.setAttributes(params); |
|
| 52 |
} |
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 56 |
|
|
| 57 |
public int getResource() { return R.layout.dialog_pattern_tab; }
|
|
| 58 |
public int getTitleResource() { return R.string.choose_pattern; }
|
|
| 59 |
public boolean hasArgument() { return true; }
|
|
| 60 |
public int getPositive() { return -1; }
|
|
| 61 |
public int getNegative() { return -1; }
|
|
| 62 |
public void positiveAction() { }
|
|
| 63 |
public void negativeAction() { }
|
|
| 64 |
|
|
| 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 66 |
|
|
| 67 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
| 68 |
{
|
|
| 69 |
int objectOrdinal = RubikObjectList.getOrdinal(mArgument); |
|
| 70 |
|
|
| 71 |
if( objectOrdinal<0 ) |
|
| 72 |
{
|
|
| 73 |
android.util.Log.e("D", "object "+mArgument+" not found");
|
|
| 74 |
return; |
|
| 75 |
} |
|
| 76 |
|
|
| 77 |
mPatternOrdinal = RubikPatternList.getOrdinal(objectOrdinal); |
|
| 78 |
|
|
| 79 |
if( mPatternOrdinal<0 ) |
|
| 80 |
{
|
|
| 81 |
android.util.Log.e("D", "patterns for object "+mArgument+" not found");
|
|
| 82 |
return; |
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
final PatternActivity pact = (PatternActivity)getContext(); |
|
| 86 |
int height = pact!=null ? pact.getScreenHeightInPixels() : 100; |
|
| 87 |
final ObjectControl control = pact!=null ? pact.getControl() : null; |
|
| 88 |
|
|
| 89 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 90 |
mExpandedGroup = pattern.recallExpanded(mPatternOrdinal); |
|
| 91 |
|
|
| 92 |
mListView = view.findViewById(R.id.patternListView); |
|
| 93 |
RubikDialogPatternListAdapter listAdapter = new RubikDialogPatternListAdapter(act,mPatternOrdinal,height); |
|
| 94 |
mListView.setAdapter(listAdapter); |
|
| 95 |
|
|
| 96 |
if( mExpandedGroup>=0 ) |
|
| 97 |
{
|
|
| 98 |
mListView.expandGroup(mExpandedGroup); |
|
| 99 |
} |
|
| 100 |
|
|
| 101 |
int visible = pattern.recallVisiblePos(mPatternOrdinal); |
|
| 102 |
mListView.setSelectionFromTop(visible,0); |
|
| 103 |
|
|
| 104 |
|
|
| 105 |
mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() |
|
| 106 |
{
|
|
| 107 |
@Override |
|
| 108 |
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) |
|
| 109 |
{
|
|
| 110 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 111 |
int[][] moves = pattern.reInitialize(mPatternOrdinal, groupPosition, childPosition); |
|
| 112 |
control.initializeObject(moves); |
|
| 113 |
|
|
| 114 |
ScreenPattern state = (ScreenPattern) ScreenList.PATT.getScreenClass(); |
|
| 115 |
state.setPattern(pact, mPatternOrdinal, groupPosition, childPosition); |
|
| 116 |
|
|
| 117 |
rememberState(); |
|
| 118 |
dismiss(); |
|
| 119 |
|
|
| 120 |
return false; |
|
| 121 |
} |
|
| 122 |
}); |
|
| 123 |
|
|
| 124 |
mListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() |
|
| 125 |
{
|
|
| 126 |
@Override |
|
| 127 |
public void onGroupExpand(int groupPosition) |
|
| 128 |
{
|
|
| 129 |
if(mExpandedGroup!=-1 && groupPosition!=mExpandedGroup) |
|
| 130 |
{
|
|
| 131 |
mListView.collapseGroup(mExpandedGroup); |
|
| 132 |
} |
|
| 133 |
|
|
| 134 |
mExpandedGroup = groupPosition; |
|
| 135 |
} |
|
| 136 |
}); |
|
| 137 |
} |
|
| 138 |
|
|
| 139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 140 |
|
|
| 141 |
private void rememberState() |
|
| 142 |
{
|
|
| 143 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 144 |
pattern.rememberState(mPatternOrdinal,mPos,mListView.getFirstVisiblePosition(),mExpandedGroup); |
|
| 145 |
} |
|
| 146 |
|
|
| 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 148 |
|
|
| 149 |
public static String getDialogTag() |
|
| 150 |
{
|
|
| 151 |
return "DialogPatternSingle"; |
|
| 152 |
} |
|
| 153 |
} |
|
| src/main/java/org/distorted/dialogs/RubikDialogPatternView.java | ||
|---|---|---|
| 30 | 30 |
public class RubikDialogPatternView extends FrameLayout |
| 31 | 31 |
{
|
| 32 | 32 |
private ExpandableListView mListView; |
| 33 |
private RubikDialogPatternListAdapter mListAdapter; |
|
| 34 | 33 |
private RubikDialogPattern mDialog; |
| 35 | 34 |
private int mTab, mPos; |
| 36 | 35 |
private int mExpandedGroup; |
| ... | ... | |
| 67 | 66 |
View tab = inflate( act, R.layout.dialog_pattern_tab, null); |
| 68 | 67 |
|
| 69 | 68 |
mListView = tab.findViewById(R.id.patternListView); |
| 70 |
mListAdapter = new RubikDialogPatternListAdapter(act,mTab, ract.getScreenHeightInPixels());
|
|
| 71 |
mListView.setAdapter(mListAdapter);
|
|
| 69 |
RubikDialogPatternListAdapter listAdapter = new RubikDialogPatternListAdapter(act,mTab, ract.getScreenHeightInPixels());
|
|
| 70 |
mListView.setAdapter(listAdapter);
|
|
| 72 | 71 |
|
| 73 | 72 |
if( mExpandedGroup>=0 ) |
| 74 | 73 |
{
|
| src/main/java/org/distorted/main/MainActivity.java | ||
|---|---|---|
| 43 | 43 |
import org.distorted.external.RubikNetwork; |
| 44 | 44 |
import org.distorted.external.RubikScores; |
| 45 | 45 |
import org.distorted.external.RubikUpdates; |
| 46 |
import org.distorted.main_old.RubikSurfaceView; |
|
| 46 | 47 |
import org.distorted.messaging.RubikInAppMessanging; |
| 48 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 47 | 49 |
import org.distorted.objects.RubikObjectList; |
| 48 |
import org.distorted.purchase.PurchaseActivity;
|
|
| 50 |
import org.distorted.patternui.PatternActivity;
|
|
| 49 | 51 |
import org.distorted.solverui.SolverActivity; |
| 50 | 52 |
import org.distorted.tutorials.TutorialActivity; |
| 51 | 53 |
|
| ... | ... | |
| 396 | 398 |
startActivity(intent); |
| 397 | 399 |
} |
| 398 | 400 |
|
| 401 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 402 |
|
|
| 403 |
public void switchToPattern(int objectOrdinal) |
|
| 404 |
{
|
|
| 405 |
Intent intent = new Intent(this, PatternActivity.class); |
|
| 406 |
intent.putExtra("obj", objectOrdinal);
|
|
| 407 |
startActivity(intent); |
|
| 408 |
} |
|
| 409 |
|
|
| 399 | 410 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 400 | 411 |
|
| 401 | 412 |
public void onScores(View v) |
| src/main/java/org/distorted/main/MainObjectPopup.java | ||
|---|---|---|
| 91 | 91 |
@Override |
| 92 | 92 |
public void onClick(View v) |
| 93 | 93 |
{
|
| 94 |
|
|
| 94 |
mPopup.dismiss(); |
|
| 95 |
act.switchToPattern(ordinal); |
|
| 95 | 96 |
} |
| 96 | 97 |
}); |
| 97 | 98 |
} |
| 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 static org.distorted.objectlib.main.TwistyObject.MESH_NICE; |
|
| 13 |
|
|
| 14 |
import android.content.SharedPreferences; |
|
| 15 |
import android.os.Build; |
|
| 16 |
import android.os.Bundle; |
|
| 17 |
import android.util.DisplayMetrics; |
|
| 18 |
import android.view.DisplayCutout; |
|
| 19 |
import android.view.View; |
|
| 20 |
import android.view.ViewGroup; |
|
| 21 |
import android.view.WindowManager; |
|
| 22 |
import android.widget.LinearLayout; |
|
| 23 |
|
|
| 24 |
import androidx.appcompat.app.AppCompatActivity; |
|
| 25 |
import androidx.preference.PreferenceManager; |
|
| 26 |
|
|
| 27 |
import org.distorted.dialogs.RubikDialogError; |
|
| 28 |
import org.distorted.library.main.DistortedLibrary; |
|
| 29 |
import org.distorted.library.main.DistortedScreen; |
|
| 30 |
import org.distorted.main.MainActivity; |
|
| 31 |
import org.distorted.main.R; |
|
| 32 |
import org.distorted.objectlib.main.InitAssets; |
|
| 33 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 34 |
import org.distorted.objectlib.main.TwistyObject; |
|
| 35 |
import org.distorted.objects.RubikObject; |
|
| 36 |
import org.distorted.objects.RubikObjectList; |
|
| 37 |
import org.distorted.os.OSInterface; |
|
| 38 |
|
|
| 39 |
import java.io.InputStream; |
|
| 40 |
|
|
| 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 42 |
|
|
| 43 |
public class PatternActivity extends AppCompatActivity |
|
| 44 |
{
|
|
| 45 |
public static final float RATIO_BAR = 0.100f; |
|
| 46 |
public static final float PADDING = 0.010f; |
|
| 47 |
public static final float SMALL_MARGIN = 0.004f; |
|
| 48 |
public static final float BUTTON_TEXT_SIZE= 0.050f; |
|
| 49 |
public static final float TITLE_TEXT_SIZE = 0.060f; |
|
| 50 |
|
|
| 51 |
private static final int ACTIVITY_NUMBER = 1; |
|
| 52 |
private static final float RATIO_INSET= 0.09f; |
|
| 53 |
|
|
| 54 |
private boolean mJustStarted; |
|
| 55 |
private static int mScreenWidth, mScreenHeight; |
|
| 56 |
private int mCurrentApiVersion; |
|
| 57 |
private int mHeightUpperBar; |
|
| 58 |
private int mObjectOrdinal; |
|
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
@Override |
|
| 63 |
protected void onCreate(Bundle savedState) |
|
| 64 |
{
|
|
| 65 |
super.onCreate(savedState); |
|
| 66 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
|
| 67 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
| 68 |
setContentView(R.layout.pattern); |
|
| 69 |
hideNavigationBar(); |
|
| 70 |
|
|
| 71 |
mJustStarted = true; |
|
| 72 |
Bundle b = getIntent().getExtras(); |
|
| 73 |
mObjectOrdinal = b!=null ? b.getInt("obj") : 0;
|
|
| 74 |
|
|
| 75 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
| 76 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
| 77 |
mScreenWidth =displaymetrics.widthPixels; |
|
| 78 |
mScreenHeight=displaymetrics.heightPixels; |
|
| 79 |
|
|
| 80 |
cutoutHack(); |
|
| 81 |
computeBarHeights(); |
|
| 82 |
} |
|
| 83 |
|
|
| 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 85 |
// this does not include possible insets |
|
| 86 |
|
|
| 87 |
private void computeBarHeights() |
|
| 88 |
{
|
|
| 89 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
| 90 |
mHeightUpperBar = barHeight; |
|
| 91 |
|
|
| 92 |
LinearLayout layoutTop = findViewById(R.id.upperBar); |
|
| 93 |
LinearLayout layoutBot = findViewById(R.id.lowerBar); |
|
| 94 |
|
|
| 95 |
ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams(); |
|
| 96 |
paramsTop.height = mHeightUpperBar; |
|
| 97 |
layoutTop.setLayoutParams(paramsTop); |
|
| 98 |
ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams(); |
|
| 99 |
paramsBot.height = barHeight; |
|
| 100 |
layoutBot.setLayoutParams(paramsBot); |
|
| 101 |
} |
|
| 102 |
|
|
| 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 104 |
|
|
| 105 |
private void hideNavigationBar() |
|
| 106 |
{
|
|
| 107 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
| 108 |
|
|
| 109 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
| 110 |
{
|
|
| 111 |
final View decorView = getWindow().getDecorView(); |
|
| 112 |
|
|
| 113 |
decorView.setSystemUiVisibility(MainActivity.FLAGS); |
|
| 114 |
|
|
| 115 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
| 116 |
{
|
|
| 117 |
@Override |
|
| 118 |
public void onSystemUiVisibilityChange(int visibility) |
|
| 119 |
{
|
|
| 120 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
| 121 |
{
|
|
| 122 |
decorView.setSystemUiVisibility(MainActivity.FLAGS); |
|
| 123 |
} |
|
| 124 |
} |
|
| 125 |
}); |
|
| 126 |
} |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 130 |
|
|
| 131 |
@Override |
|
| 132 |
public void onAttachedToWindow() |
|
| 133 |
{
|
|
| 134 |
super.onAttachedToWindow(); |
|
| 135 |
|
|
| 136 |
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ) |
|
| 137 |
{
|
|
| 138 |
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout(); |
|
| 139 |
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0; |
|
| 140 |
|
|
| 141 |
LinearLayout layoutHid = findViewById(R.id.hiddenBar); |
|
| 142 |
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams(); |
|
| 143 |
paramsHid.height = (int)(insetHeight*RATIO_INSET); |
|
| 144 |
layoutHid.setLayoutParams(paramsHid); |
|
| 145 |
mHeightUpperBar += paramsHid.height; |
|
| 146 |
} |
|
| 147 |
} |
|
| 148 |
|
|
| 149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 150 |
// do not avoid cutouts |
|
| 151 |
|
|
| 152 |
private void cutoutHack() |
|
| 153 |
{
|
|
| 154 |
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ) |
|
| 155 |
{
|
|
| 156 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
| 157 |
} |
|
| 158 |
} |
|
| 159 |
|
|
| 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 161 |
|
|
| 162 |
@Override |
|
| 163 |
public void onWindowFocusChanged(boolean hasFocus) |
|
| 164 |
{
|
|
| 165 |
super.onWindowFocusChanged(hasFocus); |
|
| 166 |
|
|
| 167 |
if( mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus ) |
|
| 168 |
{
|
|
| 169 |
getWindow().getDecorView().setSystemUiVisibility(MainActivity.FLAGS); |
|
| 170 |
} |
|
| 171 |
} |
|
| 172 |
|
|
| 173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 174 |
|
|
| 175 |
@Override |
|
| 176 |
protected void onPause() |
|
| 177 |
{
|
|
| 178 |
super.onPause(); |
|
| 179 |
PatternSurfaceView view = findViewById(R.id.patternSurfaceView); |
|
| 180 |
view.onPause(); |
|
| 181 |
DistortedLibrary.onPause(ACTIVITY_NUMBER); |
|
| 182 |
savePreferences(); |
|
| 183 |
} |
|
| 184 |
|
|
| 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 186 |
|
|
| 187 |
@Override |
|
| 188 |
protected void onResume() |
|
| 189 |
{
|
|
| 190 |
super.onResume(); |
|
| 191 |
DistortedLibrary.onResume(ACTIVITY_NUMBER); |
|
| 192 |
PatternSurfaceView view = findViewById(R.id.patternSurfaceView); |
|
| 193 |
view.onResume(); |
|
| 194 |
|
|
| 195 |
createObject(); |
|
| 196 |
RubikObjectList.setCurrObject(mObjectOrdinal); |
|
| 197 |
|
|
| 198 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 199 |
restorePreferences(preferences,mJustStarted); |
|
| 200 |
ScreenList.setScreen(this); |
|
| 201 |
|
|
| 202 |
if( mJustStarted ) |
|
| 203 |
{
|
|
| 204 |
mJustStarted = false; |
|
| 205 |
RubikObjectList.restoreMeshState(preferences); |
|
| 206 |
} |
|
| 207 |
} |
|
| 208 |
|
|
| 209 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 210 |
|
|
| 211 |
@Override |
|
| 212 |
protected void onDestroy() |
|
| 213 |
{
|
|
| 214 |
DistortedLibrary.onDestroy(ACTIVITY_NUMBER); |
|
| 215 |
super.onDestroy(); |
|
| 216 |
} |
|
| 217 |
|
|
| 218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 219 |
|
|
| 220 |
private void savePreferences() |
|
| 221 |
{
|
|
| 222 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 223 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 224 |
|
|
| 225 |
for(int i = 0; i< ScreenList.LENGTH; i++ ) |
|
| 226 |
{
|
|
| 227 |
ScreenList.getScreen(i).getScreenClass().savePreferences(editor); |
|
| 228 |
} |
|
| 229 |
|
|
| 230 |
RubikObjectList.savePreferences(editor); |
|
| 231 |
RubikObjectList.saveMeshState(editor); |
|
| 232 |
ScreenList.savePreferences(editor); |
|
| 233 |
PatternSurfaceView view = findViewById(R.id.patternSurfaceView); |
|
| 234 |
OSInterface os = view.getInterface(); |
|
| 235 |
os.setEditor(editor); |
|
| 236 |
view.getObjectControl().savePreferences(); |
|
| 237 |
|
|
| 238 |
boolean success = editor.commit(); |
|
| 239 |
if( !success ) android.util.Log.e("D", "Failed to save preferences");
|
|
| 240 |
} |
|
| 241 |
|
|
| 242 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 243 |
|
|
| 244 |
private void restorePreferences(SharedPreferences preferences, boolean justStarted) |
|
| 245 |
{
|
|
| 246 |
RubikObjectList.restorePreferences(this,preferences,justStarted); |
|
| 247 |
|
|
| 248 |
for (int i = 0; i<ScreenList.LENGTH; i++) |
|
| 249 |
{
|
|
| 250 |
ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences); |
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
ScreenList.restorePreferences(preferences); |
|
| 254 |
|
|
| 255 |
PatternSurfaceView view = findViewById(R.id.patternSurfaceView); |
|
| 256 |
OSInterface os = view.getInterface(); |
|
| 257 |
os.setPreferences(preferences); |
|
| 258 |
view.getObjectControl().restorePreferences(); |
|
| 259 |
} |
|
| 260 |
|
|
| 261 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 262 |
|
|
| 263 |
void OpenGLError() |
|
| 264 |
{
|
|
| 265 |
RubikDialogError errDiag = new RubikDialogError(); |
|
| 266 |
errDiag.show(getSupportFragmentManager(), null); |
|
| 267 |
} |
|
| 268 |
|
|
| 269 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 270 |
// PUBLIC API |
|
| 271 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 272 |
|
|
| 273 |
public TwistyObject getObject() |
|
| 274 |
{
|
|
| 275 |
PatternSurfaceView view = findViewById(R.id.patternSurfaceView); |
|
| 276 |
return view.getObjectControl().getObject(); |
|
| 277 |
} |
|
| 278 |
|
|
| 279 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 280 |
|
|
| 281 |
public DistortedScreen getScreen() |
|
| 282 |
{
|
|
| 283 |
PatternSurfaceView view = findViewById(R.id.patternSurfaceView); |
|
| 284 |
return view.getRenderer().getScreen(); |
|
| 285 |
} |
|
| 286 |
|
|
| 287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 288 |
|
|
| 289 |
public ObjectControl getControl() |
|
| 290 |
{
|
|
| 291 |
PatternSurfaceView view = findViewById(R.id.patternSurfaceView); |
|
| 292 |
return view.getObjectControl(); |
|
| 293 |
} |
|
| 294 |
|
|
| 295 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 296 |
|
|
| 297 |
public int getScreenWidthInPixels() |
|
| 298 |
{
|
|
| 299 |
return mScreenWidth; |
|
| 300 |
} |
|
| 301 |
|
|
| 302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 303 |
|
|
| 304 |
public int getScreenHeightInPixels() |
|
| 305 |
{
|
|
| 306 |
return mScreenHeight; |
|
| 307 |
} |
|
| 308 |
|
|
| 309 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 310 |
|
|
| 311 |
public void createObject() |
|
| 312 |
{
|
|
| 313 |
PatternSurfaceView view = findViewById(R.id.patternSurfaceView); |
|
| 314 |
ObjectControl control = view.getObjectControl(); |
|
| 315 |
RubikObject object = RubikObjectList.getObject(mObjectOrdinal); |
|
| 316 |
int iconMode = TwistyObject.MODE_NORM; |
|
| 317 |
InputStream jsonStream = object==null ? null : object.getObjectStream(this); |
|
| 318 |
InputStream meshStream = object==null ? null : object.getMeshStream(this); |
|
| 319 |
String name = object==null ? "NULL" : object.getUpperName(); |
|
| 320 |
OSInterface os = view.getInterface(); |
|
| 321 |
InitAssets asset = new InitAssets(jsonStream,meshStream,os); |
|
| 322 |
|
|
| 323 |
control.changeIfDifferent(mObjectOrdinal,name,MESH_NICE,iconMode,asset); |
|
| 324 |
} |
|
| 325 |
} |
|
| src/main/java/org/distorted/patternui/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.patternui; |
|
| 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 onFinishRotation(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/patternui/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.patternui; |
|
| 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 |
public static final float BRIGHTNESS = 0.30f; |
|
| 39 |
|
|
| 40 |
private final PatternSurfaceView mView; |
|
| 41 |
private final Resources mResources; |
|
| 42 |
private final DistortedScreen mScreen; |
|
| 43 |
private final ObjectControl mControl; |
|
| 44 |
private boolean mErrorShown; |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
PatternRenderer(PatternSurfaceView v) |
|
| 49 |
{
|
|
| 50 |
mView = v; |
|
| 51 |
mResources = v.getResources(); |
|
| 52 |
|
|
| 53 |
mErrorShown = false; |
|
| 54 |
mControl = v.getObjectControl(); |
|
| 55 |
mScreen = new DistortedScreen(); |
|
| 56 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
|
| 57 |
mScreen.enableDepthStencil(InternalOutputSurface.DEPTH_NO_STENCIL); |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
DistortedScreen getScreen() |
|
| 63 |
{
|
|
| 64 |
return mScreen; |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
// various things are done here delayed, 'after the next render' as not to be done mid-render and |
|
| 69 |
// cause artifacts. |
|
| 70 |
|
|
| 71 |
@Override |
|
| 72 |
public void onDrawFrame(GL10 glUnused) |
|
| 73 |
{
|
|
| 74 |
long time = System.currentTimeMillis(); |
|
| 75 |
mControl.preRender(); |
|
| 76 |
mScreen.render(time); |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 80 |
|
|
| 81 |
@Override |
|
| 82 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 83 |
{
|
|
| 84 |
mScreen.resize(width,height); |
|
| 85 |
mView.setScreenSize(width,height); |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 89 |
|
|
| 90 |
@Override |
|
| 91 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 92 |
{
|
|
| 93 |
DistortedLibrary.setMax(EffectType.VERTEX,ObjectControl.MAX_QUATS+1); |
|
| 94 |
MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS); |
|
| 95 |
|
|
| 96 |
VertexEffectRotate.enable(); |
|
| 97 |
VertexEffectQuaternion.enable(); |
|
| 98 |
BaseEffect.Type.enableEffects(); |
|
| 99 |
|
|
| 100 |
DistortedLibrary.onSurfaceCreated(this,1); |
|
| 101 |
DistortedLibrary.setCull(true); |
|
| 102 |
} |
|
| 103 |
|
|
| 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 105 |
|
|
| 106 |
public void distortedException(Exception ex) |
|
| 107 |
{
|
|
| 108 |
String message = ex.getMessage(); |
|
| 109 |
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION); |
|
| 110 |
String version = GLES30.glGetString(GLES30.GL_VERSION); |
|
| 111 |
String vendor = GLES30.glGetString(GLES30.GL_VENDOR); |
|
| 112 |
String renderer= GLES30.glGetString(GLES30.GL_RENDERER); |
|
| 113 |
|
|
| 114 |
if( message==null ) message = "exception NULL"; |
|
| 115 |
|
|
| 116 |
if( BuildConfig.DEBUG ) |
|
| 117 |
{
|
|
| 118 |
android.util.Log.e("DISTORTED", message );
|
|
| 119 |
android.util.Log.e("DISTORTED", "GLSL Version "+shading);
|
|
| 120 |
android.util.Log.e("DISTORTED", "GL Version " +version);
|
|
| 121 |
android.util.Log.e("DISTORTED", "GL Vendor " +vendor);
|
|
| 122 |
android.util.Log.e("DISTORTED", "GL Renderer " +renderer);
|
|
| 123 |
} |
|
| 124 |
else |
|
| 125 |
{
|
|
| 126 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 127 |
crashlytics.setCustomKey("DistortedError", message );
|
|
| 128 |
crashlytics.setCustomKey("GLSL Version" , shading );
|
|
| 129 |
crashlytics.setCustomKey("GLversion" , version );
|
|
| 130 |
crashlytics.setCustomKey("GL Vendor " , vendor );
|
|
| 131 |
crashlytics.setCustomKey("GLSLrenderer" , renderer);
|
|
| 132 |
crashlytics.recordException(ex); |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
int glsl = DistortedLibrary.getGLSL(); |
|
| 136 |
|
|
| 137 |
if( glsl< 300 && !mErrorShown ) |
|
| 138 |
{
|
|
| 139 |
mErrorShown = true; |
|
| 140 |
PatternActivity act = (PatternActivity)mView.getContext(); |
|
| 141 |
act.OpenGLError(); |
|
| 142 |
} |
|
| 143 |
} |
|
| 144 |
|
|
| 145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 146 |
|
|
| 147 |
public InputStream localFile(int fileID) |
|
| 148 |
{
|
|
| 149 |
return mResources.openRawResource(fileID); |
|
| 150 |
} |
|
| 151 |
|
|
| 152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 153 |
|
|
| 154 |
public void logMessage(String message) |
|
| 155 |
{
|
|
| 156 |
android.util.Log.e("Rubik", message );
|
|
| 157 |
} |
|
| 158 |
} |
|
| src/main/java/org/distorted/patternui/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.patternui; |
|
| 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/patternui/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.patternui; |
|
| 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/patternui/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.patternui; |
|
| 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/patternui/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.patternui; |
|
| 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.LayoutInflater; |
|
| 17 |
import android.view.View; |
|
| 18 |
import android.widget.LinearLayout; |
|
| 19 |
import android.widget.TextView; |
|
| 20 |
|
|
| 21 |
import org.distorted.dialogs.RubikDialogError; |
|
| 22 |
import org.distorted.dialogs.RubikDialogPatternSingle; |
|
| 23 |
import org.distorted.helpers.TransparentImageButton; |
|
| 24 |
import org.distorted.main.R; |
|
| 25 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 26 |
import org.distorted.objectlib.patterns.RubikPattern; |
|
| 27 |
import org.distorted.objects.RubikObjectList; |
|
| 28 |
|
|
| 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 30 |
|
|
| 31 |
public class ScreenPattern extends ScreenAbstract |
|
| 32 |
{
|
|
| 33 |
private TextView mText; |
|
| 34 |
private TransparentImageButton mPrevButton, mNextButton, mBackButton; |
|
| 35 |
private TextView mMovesText; |
|
| 36 |
private int mNumMoves; |
|
| 37 |
private int mPatternOrdinal, mCategory, mPattern; |
|
| 38 |
private float mButtonSize; |
|
| 39 |
|
|
| 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 41 |
|
|
| 42 |
ScreenPattern() |
|
| 43 |
{
|
|
| 44 |
|
|
| 45 |
} |
|
| 46 |
|
|
| 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 48 |
|
|
| 49 |
void leaveScreen(PatternActivity act) |
|
| 50 |
{
|
|
| 51 |
|
|
| 52 |
} |
|
| 53 |
|
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
void enterScreen(final PatternActivity act) |
|
| 57 |
{
|
|
| 58 |
float width = act.getScreenWidthInPixels(); |
|
| 59 |
mButtonSize = width*PatternActivity.BUTTON_TEXT_SIZE; |
|
| 60 |
float titleSize = width*PatternActivity.TITLE_TEXT_SIZE; |
|
| 61 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 62 |
|
|
| 63 |
mPatternOrdinal = -1; |
|
| 64 |
mCategory = -1; |
|
| 65 |
mPattern = -1; |
|
| 66 |
|
|
| 67 |
// TOP //////////////////////////// |
|
| 68 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
| 69 |
layoutTop.removeAllViews(); |
|
| 70 |
mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null); |
|
| 71 |
mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
| 72 |
mText.setText(R.string.patterns); |
|
| 73 |
layoutTop.addView(mText); |
|
| 74 |
|
|
| 75 |
// BOT //////////////////////////// |
|
| 76 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
| 77 |
layoutBot.removeAllViews(); |
|
| 78 |
|
|
| 79 |
setupPrevButton(act); |
|
| 80 |
setupNextButton(act); |
|
| 81 |
setupTextView(act,width); |
|
| 82 |
|
|
| 83 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 84 |
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 85 |
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 86 |
|
|
| 87 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
| 88 |
layoutLeft.setLayoutParams(paramsL); |
|
| 89 |
LinearLayout layoutMid = new LinearLayout(act); |
|
| 90 |
layoutMid.setLayoutParams(paramsM); |
|
| 91 |
LinearLayout layoutRight = new LinearLayout(act); |
|
| 92 |
layoutRight.setLayoutParams(paramsR); |
|
| 93 |
|
|
| 94 |
layoutLeft.addView(mPrevButton); |
|
| 95 |
layoutLeft.addView(mMovesText); |
|
| 96 |
layoutLeft.addView(mNextButton); |
|
| 97 |
|
|
| 98 |
setupBackButton(act); |
|
| 99 |
|
|
| 100 |
layoutRight.addView(mBackButton); |
|
| 101 |
|
|
| 102 |
layoutBot.addView(layoutLeft); |
|
| 103 |
layoutBot.addView(layoutMid); |
|
| 104 |
layoutBot.addView(layoutRight); |
|
| 105 |
|
|
| 106 |
Bundle bundle = new Bundle(); |
|
| 107 |
bundle.putString("argument",RubikObjectList.getCurrentName());
|
|
| 108 |
RubikDialogPatternSingle diag = new RubikDialogPatternSingle(); |
|
| 109 |
diag.setArguments(bundle); |
|
| 110 |
diag.show( act.getSupportFragmentManager(), RubikDialogPatternSingle.getDialogTag() ); |
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 114 |
|
|
| 115 |
private void setupBackButton(final PatternActivity act) |
|
| 116 |
{
|
|
| 117 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 118 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params); |
|
| 119 |
|
|
| 120 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
| 121 |
{
|
|
| 122 |
@Override |
|
| 123 |
public void onClick(View v) |
|
| 124 |
{
|
|
| 125 |
ScreenList.goBack(act); |
|
| 126 |
} |
|
| 127 |
}); |
|
| 128 |
} |
|
| 129 |
|
|
| 130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 131 |
|
|
| 132 |
private void setupPrevButton(final PatternActivity act) |
|
| 133 |
{
|
|
| 134 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 135 |
mPrevButton = new TransparentImageButton(act,R.drawable.ui_left,params); |
|
| 136 |
|
|
| 137 |
mPrevButton.setOnClickListener( new View.OnClickListener() |
|
| 138 |
{
|
|
| 139 |
@Override |
|
| 140 |
public void onClick(View v) |
|
| 141 |
{
|
|
| 142 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 143 |
ObjectControl control = act.getControl(); |
|
| 144 |
pattern.backMove( control, mPatternOrdinal, mCategory, mPattern); |
|
| 145 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern); |
|
| 146 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
|
| 147 |
} |
|
| 148 |
}); |
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 152 |
|
|
| 153 |
private void setupNextButton(final PatternActivity act) |
|
| 154 |
{
|
|
| 155 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 156 |
mNextButton = new TransparentImageButton(act,R.drawable.ui_right,params); |
|
| 157 |
|
|
| 158 |
mNextButton.setOnClickListener( new View.OnClickListener() |
|
| 159 |
{
|
|
| 160 |
@Override |
|
| 161 |
public void onClick(View v) |
|
| 162 |
{
|
|
| 163 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 164 |
ObjectControl control = act.getControl(); |
|
| 165 |
pattern.makeMove( control, mPatternOrdinal, mCategory, mPattern); |
|
| 166 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern); |
|
| 167 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
|
| 168 |
} |
|
| 169 |
}); |
|
| 170 |
} |
|
| 171 |
|
|
| 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 173 |
|
|
| 174 |
private void setupTextView(final PatternActivity act, final float width) |
|
| 175 |
{
|
|
| 176 |
int padding = (int)(width*PatternActivity.PADDING); |
|
| 177 |
int margin = (int)(width*PatternActivity.SMALL_MARGIN); |
|
| 178 |
|
|
| 179 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f); |
|
| 180 |
params.topMargin = margin; |
|
| 181 |
params.bottomMargin = margin; |
|
| 182 |
params.leftMargin = margin; |
|
| 183 |
params.rightMargin = margin; |
|
| 184 |
|
|
| 185 |
mMovesText = new TextView(act); |
|
| 186 |
mMovesText.setTextSize(20); |
|
| 187 |
mMovesText.setLayoutParams(params); |
|
| 188 |
mMovesText.setPadding(padding,0,padding,0); |
|
| 189 |
mMovesText.setGravity(Gravity.CENTER); |
|
| 190 |
mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
|
| 191 |
mMovesText.setText(act.getString(R.string.mo_placeholder,0,0)); |
|
| 192 |
} |
|
| 193 |
|
|
| 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 195 |
|
|
| 196 |
public void setPattern(final PatternActivity act, int ordinal, int category, int pattern) |
|
| 197 |
{
|
|
| 198 |
mPatternOrdinal = ordinal; |
|
| 199 |
mCategory = category; |
|
| 200 |
mPattern = pattern; |
|
| 201 |
|
|
| 202 |
RubikPattern patt = RubikPattern.getInstance(); |
|
| 203 |
String patternName = patt.getPatternName(ordinal,category,pattern); |
|
| 204 |
mText.setText(patternName); |
|
| 205 |
|
|
| 206 |
mNumMoves = patt.getNumMoves(ordinal,category,pattern); |
|
| 207 |
int currMove= patt.getCurMove(ordinal,category,pattern); |
|
| 208 |
|
|
| 209 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
|
| 210 |
} |
|
| 211 |
|
|
| 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 213 |
|
|
| 214 |
public void savePreferences(SharedPreferences.Editor editor) |
|
| 215 |
{
|
|
| 216 |
|
|
| 217 |
} |
|
| 218 |
|
|
| 219 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 220 |
|
|
| 221 |
public void restorePreferences(SharedPreferences preferences) |
|
| 222 |
{
|
|
| 223 |
|
|
| 224 |
} |
|
| 225 |
} |
|
Also available in: Unified diff
Initial support for the new Pattern Dialog.