Revision 85038b84
Added by Leszek Koltunski over 3 years ago
| build.gradle | ||
|---|---|---|
| 15 | 15 |
applicationId "org.distorted.magic" |
| 16 | 16 |
minSdkVersion 21 |
| 17 | 17 |
targetSdkVersion 31 |
| 18 |
versionCode 56
|
|
| 19 |
versionName "1.10.5"
|
|
| 18 |
versionCode 57
|
|
| 19 |
versionName "2.0.0"
|
|
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
buildTypes {
|
| ... | ... | |
| 38 | 38 |
api project(':distorted-flags')
|
| 39 | 39 |
|
| 40 | 40 |
implementation 'com.google.firebase:firebase-analytics:21.0.0' |
| 41 |
implementation 'com.google.firebase:firebase-crashlytics:18.2.10'
|
|
| 41 |
implementation 'com.google.firebase:firebase-crashlytics:18.2.11'
|
|
| 42 | 42 |
implementation 'com.google.android.play:core:1.10.3' |
| 43 |
implementation 'androidx.appcompat:appcompat:1.4.1'
|
|
| 44 |
implementation 'com.google.android.material:material:1.6.0'
|
|
| 43 |
implementation 'androidx.appcompat:appcompat:1.4.2'
|
|
| 44 |
implementation 'com.google.android.material:material:1.6.1'
|
|
| 45 | 45 |
implementation project(path: ':distorted-puzzle-jsons') |
| 46 | 46 |
implementation project(path: ':distorted-puzzle-dmesh') |
| 47 | 47 |
} |
| src/main/java/org/distorted/main/RubikActivity.java | ||
|---|---|---|
| 56 | 56 |
import org.distorted.external.RubikNetwork; |
| 57 | 57 |
import org.distorted.objects.RubikObject; |
| 58 | 58 |
import org.distorted.objects.RubikObjectList; |
| 59 |
import org.distorted.screens.RubikScreenFreePlay; |
|
| 59 | 60 |
import org.distorted.screens.RubikScreenSolving; |
| 60 | 61 |
import org.distorted.screens.ScreenList; |
| 61 |
import org.distorted.screens.RubikScreenPlay; |
|
| 62 | 62 |
import org.distorted.tutorials.TutorialActivity; |
| 63 | 63 |
|
| 64 | 64 |
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE; |
| ... | ... | |
| 126 | 126 |
mIsChinese = localeIsChinese(); |
| 127 | 127 |
|
| 128 | 128 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
| 129 |
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
| 130 |
mScreenWidth =displaymetrics.widthPixels; |
|
| 131 |
mScreenHeight=displaymetrics.heightPixels; |
|
| 132 |
mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar |
|
| 133 |
// which is not yet hidden. |
|
| 134 |
// TODO: figure this out exactly. |
|
| 129 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
| 130 |
mScreenWidth = (int)(displaymetrics.widthPixels); |
|
| 131 |
mScreenHeight = (int)(displaymetrics.heightPixels); |
|
| 132 |
|
|
| 135 | 133 |
hideNavigationBar(); |
| 136 | 134 |
cutoutHack(); |
| 137 | 135 |
computeBarHeights(); |
| ... | ... | |
| 142 | 140 |
|
| 143 | 141 |
private void computeBarHeights() |
| 144 | 142 |
{
|
| 145 |
float height = mScreenHeight; |
|
| 146 |
int barHeight = (int)(height*RATIO_BAR); |
|
| 143 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
| 147 | 144 |
mHeightLowerBar = barHeight; |
| 148 | 145 |
mHeightUpperBar = barHeight; |
| 149 | 146 |
|
| ... | ... | |
| 242 | 239 |
} |
| 243 | 240 |
|
| 244 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 245 |
|
|
| 242 |
|
|
| 246 | 243 |
@Override |
| 247 | 244 |
protected void onResume() |
| 248 | 245 |
{
|
| ... | ... | |
| 325 | 322 |
|
| 326 | 323 |
ScreenList curr = ScreenList.getCurrentScreen(); |
| 327 | 324 |
|
| 328 |
if( curr==ScreenList.PLAY )
|
|
| 325 |
if( curr==ScreenList.FREE )
|
|
| 329 | 326 |
{
|
| 330 |
RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
|
|
| 331 |
play.saveMovePreferences(KEY_PLAY,editor);
|
|
| 327 |
RubikScreenFreePlay free = (RubikScreenFreePlay)ScreenList.FREE.getScreenClass();
|
|
| 328 |
free.saveMovePreferences(KEY_PLAY,editor);
|
|
| 332 | 329 |
} |
| 333 | 330 |
if( curr==ScreenList.SOLV ) |
| 334 | 331 |
{
|
| ... | ... | |
| 393 | 390 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
| 394 | 391 |
ScreenList curr = ScreenList.getCurrentScreen(); |
| 395 | 392 |
|
| 396 |
if( curr==ScreenList.PLAY )
|
|
| 393 |
if( curr==ScreenList.FREE )
|
|
| 397 | 394 |
{
|
| 398 |
RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
|
|
| 399 |
play.restoreMovePreferences(this,KEY_PLAY,preferences);
|
|
| 395 |
RubikScreenFreePlay free = (RubikScreenFreePlay)ScreenList.FREE.getScreenClass();
|
|
| 396 |
free.restoreMovePreferences(this,KEY_PLAY,preferences);
|
|
| 400 | 397 |
} |
| 401 | 398 |
if( curr==ScreenList.SOLV ) |
| 402 | 399 |
{
|
| ... | ... | |
| 421 | 418 |
errDiag.show(getSupportFragmentManager(), null); |
| 422 | 419 |
} |
| 423 | 420 |
|
| 424 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 425 |
|
|
| 426 |
void setScreenSize(int width, int height) |
|
| 427 |
{
|
|
| 428 |
mScreenWidth = width; |
|
| 429 |
mScreenHeight= height; |
|
| 430 |
} |
|
| 431 |
|
|
| 432 | 421 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 433 | 422 |
// PUBLIC API |
| 434 | 423 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 618 | 607 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
| 619 | 608 |
ObjectControl control = view.getObjectControl(); |
| 620 | 609 |
control.blockEverything(place); |
| 610 |
ScreenList curr = ScreenList.getCurrentScreen(); |
|
| 621 | 611 |
|
| 622 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 623 |
play.setLockState(this); |
|
| 612 |
if( curr==ScreenList.FREE ) |
|
| 613 |
{
|
|
| 614 |
RubikScreenFreePlay free = (RubikScreenFreePlay)ScreenList.FREE.getScreenClass(); |
|
| 615 |
free.setLockState(this); |
|
| 616 |
} |
|
| 617 |
if( curr==ScreenList.SOLV ) |
|
| 618 |
{
|
|
| 619 |
RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass(); |
|
| 620 |
solv.setLockState(this); |
|
| 621 |
} |
|
| 624 | 622 |
} |
| 625 | 623 |
|
| 626 | 624 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 630 | 628 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
| 631 | 629 |
ObjectControl control = view.getObjectControl(); |
| 632 | 630 |
control.unblockEverything(); |
| 631 |
ScreenList curr = ScreenList.getCurrentScreen(); |
|
| 633 | 632 |
|
| 634 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 635 |
play.setLockState(this); |
|
| 633 |
if( curr==ScreenList.FREE ) |
|
| 634 |
{
|
|
| 635 |
RubikScreenFreePlay free = (RubikScreenFreePlay)ScreenList.FREE.getScreenClass(); |
|
| 636 |
free.setLockState(this); |
|
| 637 |
} |
|
| 638 |
if( curr==ScreenList.SOLV ) |
|
| 639 |
{
|
|
| 640 |
RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass(); |
|
| 641 |
solv.setLockState(this); |
|
| 642 |
} |
|
| 636 | 643 |
} |
| 637 | 644 |
|
| 638 | 645 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 662 | 669 |
startActivity(intent); |
| 663 | 670 |
} |
| 664 | 671 |
|
| 672 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 673 |
|
|
| 674 |
public void switchRenderingOff() |
|
| 675 |
{
|
|
| 676 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
| 677 |
RubikRenderer renderer = view.getRenderer(); |
|
| 678 |
renderer.switchRendering(false); |
|
| 679 |
} |
|
| 680 |
|
|
| 681 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 682 |
|
|
| 683 |
public void switchRenderingOn() |
|
| 684 |
{
|
|
| 685 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
| 686 |
RubikRenderer renderer = view.getRenderer(); |
|
| 687 |
renderer.switchRendering(true); |
|
| 688 |
} |
|
| 689 |
|
|
| 665 | 690 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 666 | 691 |
|
| 667 | 692 |
public void reloadObject(String shortName) |
| src/main/java/org/distorted/main/RubikObjectLibInterface.java | ||
|---|---|---|
| 45 | 45 |
import org.distorted.external.RubikScores; |
| 46 | 46 |
import org.distorted.objects.RubikObject; |
| 47 | 47 |
import org.distorted.objects.RubikObjectList; |
| 48 |
import org.distorted.screens.RubikScreenFreePlay; |
|
| 48 | 49 |
import org.distorted.screens.RubikScreenPlay; |
| 49 | 50 |
import org.distorted.screens.RubikScreenReady; |
| 50 | 51 |
import org.distorted.screens.RubikScreenSolver; |
| ... | ... | |
| 254 | 255 |
|
| 255 | 256 |
public void onFinishRotation(int axis, int row, int angle) |
| 256 | 257 |
{
|
| 257 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV ) |
|
| 258 |
ScreenList curr = ScreenList.getCurrentScreen(); |
|
| 259 |
|
|
| 260 |
if( curr==ScreenList.SOLV ) |
|
| 258 | 261 |
{
|
| 259 | 262 |
RubikScreenSolving solv = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
| 260 | 263 |
solv.addMove(mAct.get(), axis, row, angle); |
| 261 | 264 |
} |
| 262 |
if( ScreenList.getCurrentScreen()== ScreenList.PLAY )
|
|
| 265 |
if( curr==ScreenList.FREE )
|
|
| 263 | 266 |
{
|
| 264 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 265 |
play.addMove(mAct.get(), axis, row, angle);
|
|
| 267 |
RubikScreenFreePlay free = (RubikScreenFreePlay) ScreenList.FREE.getScreenClass();
|
|
| 268 |
free.addMove(mAct.get(), axis, row, angle);
|
|
| 266 | 269 |
} |
| 267 | 270 |
} |
| 268 | 271 |
|
| ... | ... | |
| 293 | 296 |
{
|
| 294 | 297 |
ScreenList curr = ScreenList.getCurrentScreen(); |
| 295 | 298 |
|
| 296 |
if( curr==ScreenList.PLAY )
|
|
| 299 |
if( curr==ScreenList.FREE )
|
|
| 297 | 300 |
{
|
| 298 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 299 |
play.reddenLock(mAct.get());
|
|
| 301 |
RubikScreenFreePlay free = (RubikScreenFreePlay) ScreenList.FREE.getScreenClass();
|
|
| 302 |
free.reddenLock(mAct.get());
|
|
| 300 | 303 |
} |
| 301 | 304 |
else if( curr==ScreenList.READ ) |
| 302 | 305 |
{
|
| src/main/java/org/distorted/main/RubikRenderer.java | ||
|---|---|---|
| 45 | 45 |
public static final float BRIGHTNESS = 0.30f; |
| 46 | 46 |
|
| 47 | 47 |
private final RubikSurfaceView mView; |
| 48 |
private final DistortedScreen mScreen; |
|
| 48 |
private final DistortedScreen mScreen, mEmptyScreen;
|
|
| 49 | 49 |
private final ObjectControl mControl; |
| 50 | 50 |
private final Fps mFPS; |
| 51 | 51 |
private boolean mErrorShown; |
| 52 | 52 |
private boolean mDebugSent; |
| 53 |
private boolean mRenderingOn; |
|
| 53 | 54 |
|
| 54 | 55 |
private static class Fps |
| 55 | 56 |
{
|
| ... | ... | |
| 93 | 94 |
|
| 94 | 95 |
RubikRenderer(RubikSurfaceView v) |
| 95 | 96 |
{
|
| 97 |
mRenderingOn= true; |
|
| 96 | 98 |
mErrorShown = false; |
| 97 | 99 |
mView = v; |
| 98 | 100 |
mControl = v.getObjectControl(); |
| 99 | 101 |
mFPS = new Fps(); |
| 102 |
|
|
| 100 | 103 |
mScreen = new DistortedScreen(); |
| 101 | 104 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
| 105 |
mEmptyScreen = new DistortedScreen(); |
|
| 106 |
mEmptyScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
|
| 102 | 107 |
} |
| 103 | 108 |
|
| 104 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 109 | 114 |
public void onDrawFrame(GL10 glUnused) |
| 110 | 115 |
{
|
| 111 | 116 |
long time = System.currentTimeMillis(); |
| 112 |
mFPS.onRender(time); |
|
| 113 |
mControl.preRender(); |
|
| 114 |
mScreen.render(time); |
|
| 117 |
|
|
| 118 |
if( mRenderingOn ) |
|
| 119 |
{
|
|
| 120 |
mFPS.onRender(time); |
|
| 121 |
mControl.preRender(); |
|
| 122 |
mScreen.render(time); |
|
| 123 |
} |
|
| 124 |
else |
|
| 125 |
{
|
|
| 126 |
mEmptyScreen.render(time); |
|
| 127 |
} |
|
| 115 | 128 |
} |
| 116 | 129 |
|
| 117 | 130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 120 | 133 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 121 | 134 |
{
|
| 122 | 135 |
mScreen.resize(width,height); |
| 136 |
mEmptyScreen.resize(width,height); |
|
| 123 | 137 |
mView.setScreenSize(width,height); |
| 124 | 138 |
} |
| 125 | 139 |
|
| ... | ... | |
| 188 | 202 |
} |
| 189 | 203 |
} |
| 190 | 204 |
|
| 205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 206 |
|
|
| 207 |
void switchRendering(boolean on) |
|
| 208 |
{
|
|
| 209 |
mRenderingOn = on; |
|
| 210 |
} |
|
| 211 |
|
|
| 191 | 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 192 | 213 |
|
| 193 | 214 |
float getFPS() |
| src/main/java/org/distorted/main/RubikSurfaceView.java | ||
|---|---|---|
| 59 | 59 |
TwistyObjectNode objectNode = mObjectController.getNode(); |
| 60 | 60 |
mRenderer.getScreen().attach(objectNode); |
| 61 | 61 |
} |
| 62 |
|
|
| 63 |
try |
|
| 64 |
{
|
|
| 65 |
RubikActivity act = (RubikActivity)getContext(); |
|
| 66 |
act.setScreenSize(width,height); |
|
| 67 |
} |
|
| 68 |
catch( Exception ex ) |
|
| 69 |
{
|
|
| 70 |
android.util.Log.e("D", "Failed to set screen size!");
|
|
| 71 |
} |
|
| 72 | 62 |
} |
| 73 | 63 |
|
| 74 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/screens/RubikScreenDetails.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.screens; |
|
| 21 |
|
|
| 22 |
import android.app.Activity; |
|
| 23 |
import android.content.Context; |
|
| 24 |
import android.content.SharedPreferences; |
|
| 25 |
import android.content.res.Resources; |
|
| 26 |
import android.graphics.drawable.BitmapDrawable; |
|
| 27 |
import android.os.Build; |
|
| 28 |
import android.os.Bundle; |
|
| 29 |
import android.util.TypedValue; |
|
| 30 |
import android.view.Gravity; |
|
| 31 |
import android.view.LayoutInflater; |
|
| 32 |
import android.view.View; |
|
| 33 |
import android.widget.Button; |
|
| 34 |
import android.widget.GridLayout; |
|
| 35 |
import android.widget.ImageButton; |
|
| 36 |
import android.widget.LinearLayout; |
|
| 37 |
import android.widget.PopupWindow; |
|
| 38 |
import android.widget.RelativeLayout; |
|
| 39 |
import android.widget.TextView; |
|
| 40 |
|
|
| 41 |
import org.distorted.dialogs.RubikDialogAbout; |
|
| 42 |
import org.distorted.dialogs.RubikDialogPattern; |
|
| 43 |
import org.distorted.dialogs.RubikDialogScores; |
|
| 44 |
import org.distorted.dialogs.RubikDialogTutorial; |
|
| 45 |
import org.distorted.dialogs.RubikDialogUpdates; |
|
| 46 |
import org.distorted.external.RubikNetwork; |
|
| 47 |
import org.distorted.external.RubikScores; |
|
| 48 |
import org.distorted.external.RubikUpdates; |
|
| 49 |
import org.distorted.helpers.TransparentButton; |
|
| 50 |
import org.distorted.helpers.TransparentImageButton; |
|
| 51 |
import org.distorted.main.R; |
|
| 52 |
import org.distorted.main.RubikActivity; |
|
| 53 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 54 |
import org.distorted.objects.RubikObject; |
|
| 55 |
import org.distorted.objects.RubikObjectList; |
|
| 56 |
|
|
| 57 |
import java.lang.ref.WeakReference; |
|
| 58 |
|
|
| 59 |
import static android.view.View.inflate; |
|
| 60 |
|
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
|
|
| 63 |
public class RubikScreenDetails extends RubikScreenBase implements RubikNetwork.Updatee |
|
| 64 |
{
|
|
| 65 |
public static final int NUM_COLUMNS = 5; |
|
| 66 |
public static final int LEVELS_SHOWN = 10; |
|
| 67 |
|
|
| 68 |
private static final int[] BUTTON_LABELS = { R.string.scores,
|
|
| 69 |
R.string.patterns, |
|
| 70 |
R.string.solver, |
|
| 71 |
R.string.tutorials, |
|
| 72 |
R.string.bandaged, |
|
| 73 |
R.string.about }; |
|
| 74 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length; |
|
| 75 |
|
|
| 76 |
private static final float LAST_BUTTON = 1.5f; |
|
| 77 |
private static final int[] mLocation = new int[2]; |
|
| 78 |
|
|
| 79 |
private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton; |
|
| 80 |
private TransparentButton mPlayButton; |
|
| 81 |
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
|
| 82 |
private LinearLayout mPlayLayout; |
|
| 83 |
private TextView mBubbleUpdates; |
|
| 84 |
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth; |
|
| 85 |
private int mLevelValue; |
|
| 86 |
private float mButtonSize, mMenuItemSize, mMenuTextSize; |
|
| 87 |
private int mColCount, mRowCount, mMaxRowCount; |
|
| 88 |
private int mUpperBarHeight; |
|
| 89 |
private boolean mShouldReactToEndOfScrambling; |
|
| 90 |
private int mBottomHeight; |
|
| 91 |
private float mScreenWidth; |
|
| 92 |
private WeakReference<RubikActivity> mWeakAct; |
|
| 93 |
|
|
| 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 95 |
|
|
| 96 |
void leaveScreen(RubikActivity act) |
|
| 97 |
{
|
|
| 98 |
|
|
| 99 |
} |
|
| 100 |
|
|
| 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 102 |
|
|
| 103 |
void enterScreen(final RubikActivity act) |
|
| 104 |
{
|
|
| 105 |
mWeakAct = new WeakReference<>(act); |
|
| 106 |
int numObjects = RubikObjectList.getNumObjects(); |
|
| 107 |
mScreenWidth = act.getScreenWidthInPixels(); |
|
| 108 |
mUpperBarHeight = act.getHeightUpperBar(); |
|
| 109 |
|
|
| 110 |
mMenuTextSize = mScreenWidth*RubikActivity.MENU_MED_TEXT_SIZE; |
|
| 111 |
mButtonSize = mScreenWidth*RubikActivity.BUTTON_TEXT_SIZE; |
|
| 112 |
mMenuItemSize = mScreenWidth*RubikActivity.MENU_ITEM_SIZE; |
|
| 113 |
|
|
| 114 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS; |
|
| 115 |
mColCount = NUM_COLUMNS; |
|
| 116 |
|
|
| 117 |
// TOP //////////////////////////// |
|
| 118 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
| 119 |
layoutTop.removeAllViews(); |
|
| 120 |
|
|
| 121 |
setupObjectButton(act,mScreenWidth); |
|
| 122 |
layoutTop.addView(mObjButton); |
|
| 123 |
|
|
| 124 |
setupMenuButton(act,mScreenWidth); |
|
| 125 |
layoutTop.addView(mMenuButton); |
|
| 126 |
|
|
| 127 |
setupPlayButton(act,mScreenWidth); |
|
| 128 |
layoutTop.addView(mPlayButton); |
|
| 129 |
|
|
| 130 |
setupSolveButton(act); |
|
| 131 |
setupScrambleButton(act); |
|
| 132 |
createBottomPane(act,mSolveButton,mScrambleButton); |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 136 |
|
|
| 137 |
private void setupObjectButton(final RubikActivity act, final float width) |
|
| 138 |
{
|
|
| 139 |
final int margin = (int)(width*RubikActivity.SMALL_MARGIN); |
|
| 140 |
final int lMargin = (int)(width*RubikActivity.LARGE_MARGIN); |
|
| 141 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu); |
|
| 142 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 143 |
mObjButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params); |
|
| 144 |
|
|
| 145 |
mObjButton.setOnClickListener( new View.OnClickListener() |
|
| 146 |
{
|
|
| 147 |
@Override |
|
| 148 |
public void onClick(View view) |
|
| 149 |
{
|
|
| 150 |
if( mObjectPopup==null ) |
|
| 151 |
{
|
|
| 152 |
float width = act.getScreenWidthInPixels(); |
|
| 153 |
float height= act.getScreenHeightInPixels(); |
|
| 154 |
setupObjectWindow(act,width,height); |
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
if( act.getControl().isUINotBlocked()) |
|
| 158 |
{
|
|
| 159 |
int rowCount = Math.min(mMaxRowCount,mRowCount); |
|
| 160 |
View popupView = mObjectPopup.getContentView(); |
|
| 161 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
|
| 162 |
displayPopup(act,view,mObjectPopup,mObjectSize*mColCount,mObjectSize*rowCount+mBottomHeight+2*lMargin+5*margin,margin,margin); |
|
| 163 |
} |
|
| 164 |
} |
|
| 165 |
}); |
|
| 166 |
} |
|
| 167 |
|
|
| 168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 169 |
|
|
| 170 |
private void setupPlayButton(final RubikActivity act, final float width) |
|
| 171 |
{
|
|
| 172 |
final int margin = (int)(width*RubikActivity.SMALL_MARGIN); |
|
| 173 |
|
|
| 174 |
mPlayButton = new TransparentButton(act, R.string.play, mButtonSize); |
|
| 175 |
|
|
| 176 |
mPlayButton.setOnClickListener( new View.OnClickListener() |
|
| 177 |
{
|
|
| 178 |
@Override |
|
| 179 |
public void onClick(View view) |
|
| 180 |
{
|
|
| 181 |
if( mPlayPopup==null ) |
|
| 182 |
{
|
|
| 183 |
float width = act.getScreenWidthInPixels(); |
|
| 184 |
setupPlayWindow(act,width); |
|
| 185 |
} |
|
| 186 |
|
|
| 187 |
if( act.getControl().isUINotBlocked()) |
|
| 188 |
{
|
|
| 189 |
adjustSolvedIcons(); |
|
| 190 |
float height= act.getScreenHeightInPixels(); |
|
| 191 |
final int maxHeight= (int)(0.9f*(height-mUpperBarHeight) ); |
|
| 192 |
View popupView = mPlayPopup.getContentView(); |
|
| 193 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
|
| 194 |
final int object = RubikObjectList.getCurrObject(); |
|
| 195 |
final int dbLevel = RubikObjectList.getDBLevel(object); |
|
| 196 |
final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN); |
|
| 197 |
final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f)); |
|
| 198 |
final int realHeight = Math.min(popupHeight,maxHeight); |
|
| 199 |
displayPopup(act,view,mPlayPopup,mPlayLayoutWidth,realHeight,margin,margin); |
|
| 200 |
} |
|
| 201 |
} |
|
| 202 |
}); |
|
| 203 |
} |
|
| 204 |
|
|
| 205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 206 |
|
|
| 207 |
private void setupMenuButton(final RubikActivity act, final float width) |
|
| 208 |
{
|
|
| 209 |
final int margin = (int)(width*RubikActivity.SMALL_MARGIN); |
|
| 210 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_menu,R.drawable.ui_medium_menu, R.drawable.ui_big_menu, R.drawable.ui_huge_menu); |
|
| 211 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 212 |
mMenuButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params); |
|
| 213 |
|
|
| 214 |
mMenuButton.setOnClickListener( new View.OnClickListener() |
|
| 215 |
{
|
|
| 216 |
@Override |
|
| 217 |
public void onClick(View view) |
|
| 218 |
{
|
|
| 219 |
if( mMenuPopup==null ) |
|
| 220 |
{
|
|
| 221 |
float width = act.getScreenWidthInPixels(); |
|
| 222 |
setupMenuWindow(act,width); |
|
| 223 |
} |
|
| 224 |
|
|
| 225 |
if( act.getControl().isUINotBlocked()) |
|
| 226 |
{
|
|
| 227 |
View popupView = mMenuPopup.getContentView(); |
|
| 228 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
|
| 229 |
displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-width/12),margin); |
|
| 230 |
} |
|
| 231 |
} |
|
| 232 |
}); |
|
| 233 |
} |
|
| 234 |
|
|
| 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 236 |
|
|
| 237 |
private void setupObjectWindow(final RubikActivity act, final float width, final float height) |
|
| 238 |
{
|
|
| 239 |
int cubeWidth = (int)(width/9); |
|
| 240 |
int margin = (int)(width*RubikActivity.LARGE_MARGIN); |
|
| 241 |
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f); |
|
| 242 |
mMaxRowCount = (int)((height-1.8f*mUpperBarHeight)/mObjectSize); |
|
| 243 |
|
|
| 244 |
LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null); |
|
| 245 |
GridLayout objectGrid = view.findViewById(R.id.objectGrid); |
|
| 246 |
|
|
| 247 |
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount]; |
|
| 248 |
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount]; |
|
| 249 |
|
|
| 250 |
objectGrid.setColumnCount(mColCount); |
|
| 251 |
objectGrid.setRowCount(mRowCount); |
|
| 252 |
|
|
| 253 |
RelativeLayout bottomLayout = view.findViewById(R.id.bottomLayout); |
|
| 254 |
setupBottomLayout(act,bottomLayout); |
|
| 255 |
|
|
| 256 |
mObjectPopup = new PopupWindow(act); |
|
| 257 |
mObjectPopup.setFocusable(true); |
|
| 258 |
mObjectPopup.setContentView(view); |
|
| 259 |
|
|
| 260 |
int[] nextInRow = new int[mRowCount]; |
|
| 261 |
|
|
| 262 |
for(int row=0; row<mRowCount; row++) |
|
| 263 |
{
|
|
| 264 |
rowSpecs[row] = GridLayout.spec(row); |
|
| 265 |
nextInRow[row]= 0; |
|
| 266 |
} |
|
| 267 |
for(int col=0; col<mColCount; col++) |
|
| 268 |
{
|
|
| 269 |
colSpecs[col] = GridLayout.spec(col); |
|
| 270 |
} |
|
| 271 |
|
|
| 272 |
int numObjects = RubikObjectList.getNumObjects(); |
|
| 273 |
|
|
| 274 |
for(int object=0; object<numObjects; object++) |
|
| 275 |
{
|
|
| 276 |
final int ordinal = object; |
|
| 277 |
final RubikObject rObject = RubikObjectList.getObject(object); |
|
| 278 |
int row = object/NUM_COLUMNS; |
|
| 279 |
ImageButton button = new ImageButton(act); |
|
| 280 |
if( rObject!=null ) rObject.setIconTo(act,button); |
|
| 281 |
|
|
| 282 |
button.setOnClickListener( new View.OnClickListener() |
|
| 283 |
{
|
|
| 284 |
@Override |
|
| 285 |
public void onClick(View v) |
|
| 286 |
{
|
|
| 287 |
if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY ) |
|
| 288 |
{
|
|
| 289 |
RubikObjectList.setCurrObject(act,ordinal); |
|
| 290 |
act.changeObject(ordinal,true); |
|
| 291 |
if( mPlayLayout!=null ) adjustLevels(act); |
|
| 292 |
mMovesController.clearMoves(act); |
|
| 293 |
} |
|
| 294 |
|
|
| 295 |
if( mObjectPopup!=null ) mObjectPopup.dismiss(); |
|
| 296 |
} |
|
| 297 |
}); |
|
| 298 |
|
|
| 299 |
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]); |
|
| 300 |
params.bottomMargin = margin; |
|
| 301 |
params.topMargin = margin; |
|
| 302 |
params.leftMargin = margin; |
|
| 303 |
params.rightMargin = margin; |
|
| 304 |
|
|
| 305 |
params.width = cubeWidth; |
|
| 306 |
params.height= cubeWidth; |
|
| 307 |
|
|
| 308 |
nextInRow[row]++; |
|
| 309 |
|
|
| 310 |
objectGrid.addView(button, params); |
|
| 311 |
} |
|
| 312 |
} |
|
| 313 |
|
|
| 314 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 315 |
|
|
| 316 |
private void setupBottomLayout(final RubikActivity act, final RelativeLayout layout) |
|
| 317 |
{
|
|
| 318 |
int iconT = RubikActivity.getDrawable(R.drawable.ui_small_tutorial,R.drawable.ui_medium_tutorial, R.drawable.ui_big_tutorial, R.drawable.ui_huge_tutorial); |
|
| 319 |
int iconD = RubikActivity.getDrawable(R.drawable.ui_small_download,R.drawable.ui_medium_download, R.drawable.ui_big_download, R.drawable.ui_huge_download); |
|
| 320 |
int iconI = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info); |
|
| 321 |
|
|
| 322 |
ImageButton buttonTut = layout.findViewById(R.id.buttonTut); |
|
| 323 |
ImageButton buttonDow = layout.findViewById(R.id.buttonDow); |
|
| 324 |
ImageButton buttonInf = layout.findViewById(R.id.buttonInf); |
|
| 325 |
|
|
| 326 |
buttonTut.setImageResource(iconT); |
|
| 327 |
buttonDow.setImageResource(iconD); |
|
| 328 |
buttonInf.setImageResource(iconI); |
|
| 329 |
|
|
| 330 |
Resources res = act.getResources(); |
|
| 331 |
BitmapDrawable bd = (BitmapDrawable)res.getDrawable(iconI); |
|
| 332 |
mBottomHeight = bd.getIntrinsicHeight(); |
|
| 333 |
|
|
| 334 |
TypedValue outValue = new TypedValue(); |
|
| 335 |
act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
|
| 336 |
buttonTut.setBackgroundResource(outValue.resourceId); |
|
| 337 |
buttonDow.setBackgroundResource(outValue.resourceId); |
|
| 338 |
buttonInf.setBackgroundResource(outValue.resourceId); |
|
| 339 |
|
|
| 340 |
buttonTut.setOnClickListener( new View.OnClickListener() |
|
| 341 |
{
|
|
| 342 |
@Override |
|
| 343 |
public void onClick(View v) |
|
| 344 |
{
|
|
| 345 |
if( mObjectPopup!=null ) mObjectPopup.dismiss(); |
|
| 346 |
RubikDialogTutorial tDiag = new RubikDialogTutorial(); |
|
| 347 |
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() ); |
|
| 348 |
} |
|
| 349 |
}); |
|
| 350 |
|
|
| 351 |
buttonDow.setOnClickListener( new View.OnClickListener() |
|
| 352 |
{
|
|
| 353 |
@Override |
|
| 354 |
public void onClick(View v) |
|
| 355 |
{
|
|
| 356 |
if( mObjectPopup!=null ) mObjectPopup.dismiss(); |
|
| 357 |
RubikDialogUpdates uDiag = new RubikDialogUpdates(); |
|
| 358 |
uDiag.show( act.getSupportFragmentManager(), RubikDialogUpdates.getDialogTag() ); |
|
| 359 |
} |
|
| 360 |
}); |
|
| 361 |
|
|
| 362 |
buttonInf.setOnClickListener( new View.OnClickListener() |
|
| 363 |
{
|
|
| 364 |
@Override |
|
| 365 |
public void onClick(View v) |
|
| 366 |
{
|
|
| 367 |
if( mObjectPopup!=null ) mObjectPopup.dismiss(); |
|
| 368 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 369 |
act.switchConfig(currObject); |
|
| 370 |
} |
|
| 371 |
}); |
|
| 372 |
|
|
| 373 |
mBubbleUpdates = layout.findViewById(R.id.bubbleUpdates); |
|
| 374 |
mBubbleUpdates.setVisibility(View.INVISIBLE); |
|
| 375 |
|
|
| 376 |
RubikNetwork network = RubikNetwork.getInstance(); |
|
| 377 |
network.signUpForUpdates(this); |
|
| 378 |
} |
|
| 379 |
|
|
| 380 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 381 |
|
|
| 382 |
private void setupMenuWindow(final RubikActivity act, final float width) |
|
| 383 |
{
|
|
| 384 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
| 385 |
final View layout = layoutInflater.inflate(R.layout.popup_menu, null); |
|
| 386 |
LinearLayout menuLayout = layout.findViewById(R.id.menuGrid); |
|
| 387 |
|
|
| 388 |
mMenuPopup = new PopupWindow(act); |
|
| 389 |
mMenuPopup.setContentView(layout); |
|
| 390 |
mMenuPopup.setFocusable(true); |
|
| 391 |
int margin = (int)(width*RubikActivity.SMALL_MARGIN); |
|
| 392 |
int padding = (int)(width*RubikActivity.PADDING); |
|
| 393 |
|
|
| 394 |
mMenuLayoutWidth = (int)(width/2); |
|
| 395 |
mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin)); |
|
| 396 |
|
|
| 397 |
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize); |
|
| 398 |
|
|
| 399 |
for(int i=0; i<NUM_BUTTONS; i++) |
|
| 400 |
{
|
|
| 401 |
final int but = i; |
|
| 402 |
Button button = new Button(act); |
|
| 403 |
button.setLayoutParams(p); |
|
| 404 |
button.setText(BUTTON_LABELS[i]); |
|
| 405 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize); |
|
| 406 |
|
|
| 407 |
button.setOnClickListener( new View.OnClickListener() |
|
| 408 |
{
|
|
| 409 |
@Override |
|
| 410 |
public void onClick(View v) |
|
| 411 |
{
|
|
| 412 |
mMenuPopup.dismiss(); |
|
| 413 |
MenuAction(act,but); |
|
| 414 |
} |
|
| 415 |
}); |
|
| 416 |
|
|
| 417 |
menuLayout.addView(button); |
|
| 418 |
} |
|
| 419 |
} |
|
| 420 |
|
|
| 421 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 422 |
|
|
| 423 |
private void setupPlayWindow(final RubikActivity act, final float width) |
|
| 424 |
{
|
|
| 425 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
| 426 |
final View layout = layoutInflater.inflate(R.layout.popup_play, null); |
|
| 427 |
mPlayLayout = layout.findViewById(R.id.playGrid); |
|
| 428 |
|
|
| 429 |
mPlayLayoutWidth = (int)(width*0.4f); |
|
| 430 |
|
|
| 431 |
mPlayPopup = new PopupWindow(act); |
|
| 432 |
mPlayPopup.setContentView(layout); |
|
| 433 |
mPlayPopup.setFocusable(true); |
|
| 434 |
|
|
| 435 |
adjustLevels(act); |
|
| 436 |
} |
|
| 437 |
|
|
| 438 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 439 |
|
|
| 440 |
private void MenuAction(RubikActivity act, int button) |
|
| 441 |
{
|
|
| 442 |
switch(button) |
|
| 443 |
{
|
|
| 444 |
case 0: Bundle sBundle = new Bundle(); |
|
| 445 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 446 |
sBundle.putInt("tab", currObject );
|
|
| 447 |
sBundle.putBoolean("submitting", false);
|
|
| 448 |
RubikDialogScores scores = new RubikDialogScores(); |
|
| 449 |
scores.setArguments(sBundle); |
|
| 450 |
scores.show(act.getSupportFragmentManager(), null); |
|
| 451 |
break; |
|
| 452 |
case 1: RubikDialogPattern pDiag = new RubikDialogPattern(); |
|
| 453 |
pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() ); |
|
| 454 |
break; |
|
| 455 |
case 2: ScreenList.switchScreen(act, ScreenList.SVER); |
|
| 456 |
break; |
|
| 457 |
case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial(); |
|
| 458 |
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() ); |
|
| 459 |
break; |
|
| 460 |
case 4: act.switchToBandagedCreator(); |
|
| 461 |
break; |
|
| 462 |
case 5: RubikDialogAbout aDiag = new RubikDialogAbout(); |
|
| 463 |
aDiag.show(act.getSupportFragmentManager(), null); |
|
| 464 |
break; |
|
| 465 |
} |
|
| 466 |
} |
|
| 467 |
|
|
| 468 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 469 |
|
|
| 470 |
void setupSolveButton(final RubikActivity act) |
|
| 471 |
{
|
|
| 472 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve_new,R.drawable.ui_medium_cube_solve_new, R.drawable.ui_big_cube_solve_new, R.drawable.ui_huge_cube_solve_new); |
|
| 473 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 474 |
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_END,params); |
|
| 475 |
|
|
| 476 |
mSolveButton.setOnClickListener( new View.OnClickListener() |
|
| 477 |
{
|
|
| 478 |
@Override |
|
| 479 |
public void onClick(View v) |
|
| 480 |
{
|
|
| 481 |
act.getControl().solveObject(); |
|
| 482 |
mMovesController.clearMoves(act); |
|
| 483 |
} |
|
| 484 |
}); |
|
| 485 |
} |
|
| 486 |
|
|
| 487 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 488 |
|
|
| 489 |
private void setupScrambleButton(final RubikActivity act) |
|
| 490 |
{
|
|
| 491 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble_new,R.drawable.ui_medium_cube_scramble_new, R.drawable.ui_big_cube_scramble_new, R.drawable.ui_huge_cube_scramble_new); |
|
| 492 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 493 |
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_START, params); |
|
| 494 |
|
|
| 495 |
mScrambleButton.setOnClickListener( new View.OnClickListener() |
|
| 496 |
{
|
|
| 497 |
@Override |
|
| 498 |
public void onClick(View v) |
|
| 499 |
{
|
|
| 500 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 501 |
RubikObject object = RubikObjectList.getObject(currObject); |
|
| 502 |
int numScrambles = object==null ? 0 : object.getNumScramble(); |
|
| 503 |
mShouldReactToEndOfScrambling = false; |
|
| 504 |
act.getControl().scrambleObject(numScrambles); |
|
| 505 |
} |
|
| 506 |
}); |
|
| 507 |
} |
|
| 508 |
|
|
| 509 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 510 |
// This is necessary! Otherwise the ObjectPopup will not be re-created next time and we will still |
|
| 511 |
// hold a reference to the old instance of the RubikActivity class (because setupObjectWindow is not |
|
| 512 |
// going to be called) |
|
| 513 |
// An reference to the old instance of RubikActivity will cause all sorts of strange issues. |
|
| 514 |
|
|
| 515 |
public void savePreferences(SharedPreferences.Editor editor) |
|
| 516 |
{
|
|
| 517 |
editor.putInt("play_LevelValue", mLevelValue );
|
|
| 518 |
|
|
| 519 |
if( mObjectPopup!=null ) |
|
| 520 |
{
|
|
| 521 |
mObjectPopup.dismiss(); |
|
| 522 |
mObjectPopup = null; |
|
| 523 |
} |
|
| 524 |
|
|
| 525 |
if( mMenuPopup!=null ) |
|
| 526 |
{
|
|
| 527 |
mMenuPopup.dismiss(); |
|
| 528 |
mMenuPopup = null; |
|
| 529 |
} |
|
| 530 |
|
|
| 531 |
if( mPlayPopup!=null ) |
|
| 532 |
{
|
|
| 533 |
mPlayPopup.dismiss(); |
|
| 534 |
mPlayPopup = null; |
|
| 535 |
} |
|
| 536 |
} |
|
| 537 |
|
|
| 538 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 539 |
|
|
| 540 |
public void restorePreferences(SharedPreferences preferences) |
|
| 541 |
{
|
|
| 542 |
mLevelValue = preferences.getInt("play_LevelValue", 0);
|
|
| 543 |
} |
|
| 544 |
|
|
| 545 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 546 |
|
|
| 547 |
public void setCurrObject(RubikActivity act) |
|
| 548 |
{
|
|
| 549 |
if( mPlayLayout!=null ) adjustLevels(act); |
|
| 550 |
} |
|
| 551 |
|
|
| 552 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 553 |
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes |
|
| 554 |
|
|
| 555 |
private void displayPopup(RubikActivity act, View view, PopupWindow window, int w, int h, int xoff, int yoff) |
|
| 556 |
{
|
|
| 557 |
View topLayout = act.findViewById(R.id.relativeLayout); |
|
| 558 |
boolean isFullScreen; |
|
| 559 |
|
|
| 560 |
if( topLayout!=null ) |
|
| 561 |
{
|
|
| 562 |
topLayout.getLocationOnScreen(mLocation); |
|
| 563 |
isFullScreen = (mLocation[1]==0); |
|
| 564 |
} |
|
| 565 |
else |
|
| 566 |
{
|
|
| 567 |
isFullScreen = true; |
|
| 568 |
} |
|
| 569 |
|
|
| 570 |
try |
|
| 571 |
{
|
|
| 572 |
// if on Android 11 or we are fullscreen |
|
| 573 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || isFullScreen ) |
|
| 574 |
{
|
|
| 575 |
window.showAsDropDown(view, xoff, yoff, Gravity.CENTER); |
|
| 576 |
window.update(view, w, h); |
|
| 577 |
} |
|
| 578 |
else // Android 10 or below in pop-up mode or split-screen mode |
|
| 579 |
{
|
|
| 580 |
view.getLocationOnScreen(mLocation); |
|
| 581 |
int width = view.getWidth(); |
|
| 582 |
int height = view.getHeight(); |
|
| 583 |
int x = mLocation[0]+(width-w)/2; |
|
| 584 |
int y = mLocation[1]+height+yoff; |
|
| 585 |
|
|
| 586 |
window.showAsDropDown(view); |
|
| 587 |
window.update(x,y,w,h); |
|
| 588 |
} |
|
| 589 |
} |
|
| 590 |
catch( IllegalArgumentException iae ) |
|
| 591 |
{
|
|
| 592 |
// ignore, this means window is 'not attached to window manager' - |
|
| 593 |
// which most probably is because we are already exiting the app. |
|
| 594 |
} |
|
| 595 |
} |
|
| 596 |
|
|
| 597 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 598 |
|
|
| 599 |
private void adjustSolvedIcons() |
|
| 600 |
{
|
|
| 601 |
if( mPlayLayout!=null ) |
|
| 602 |
{
|
|
| 603 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 604 |
int dbLevel = RubikObjectList.getDBLevel(currObject); |
|
| 605 |
int numLevel= Math.min(dbLevel, LEVELS_SHOWN); |
|
| 606 |
RubikScores scores = RubikScores.getInstance(); |
|
| 607 |
|
|
| 608 |
for(int i=0; i<numLevel; i++) |
|
| 609 |
{
|
|
| 610 |
int level = i<numLevel-1 ? i+1 : dbLevel; |
|
| 611 |
Button button = (Button)mPlayLayout.getChildAt(i); |
|
| 612 |
int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved; |
|
| 613 |
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0); |
|
| 614 |
} |
|
| 615 |
} |
|
| 616 |
} |
|
| 617 |
|
|
| 618 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 619 |
|
|
| 620 |
private void adjustLevels(final RubikActivity act) |
|
| 621 |
{
|
|
| 622 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 623 |
int dbLevel = RubikObjectList.getDBLevel(currObject); |
|
| 624 |
RubikObject object = RubikObjectList.getObject(currObject); |
|
| 625 |
int numScrambles = object==null ? 0 : object.getNumScramble(); |
|
| 626 |
int numLevel = Math.min(dbLevel, LEVELS_SHOWN); |
|
| 627 |
String[] levels = new String[numLevel]; |
|
| 628 |
|
|
| 629 |
for(int i=0; i<numLevel-1; i++) |
|
| 630 |
{
|
|
| 631 |
levels[i] = act.getString(R.string.lv_placeholder,i+1); |
|
| 632 |
} |
|
| 633 |
|
|
| 634 |
if( numLevel>0 ) |
|
| 635 |
{
|
|
| 636 |
levels[numLevel-1] = act.getString(R.string.level_full); |
|
| 637 |
} |
|
| 638 |
|
|
| 639 |
if( mLevelValue>dbLevel || mLevelValue<1 || |
|
| 640 |
(mLevelValue<dbLevel || mLevelValue>LEVELS_SHOWN ) ) |
|
| 641 |
{
|
|
| 642 |
mLevelValue=1; |
|
| 643 |
} |
|
| 644 |
|
|
| 645 |
float width = act.getScreenWidthInPixels(); |
|
| 646 |
int margin = (int)(width*RubikActivity.SMALL_MARGIN); |
|
| 647 |
int padding = (int)(width*RubikActivity.PADDING); |
|
| 648 |
int butWidth = mPlayLayoutWidth - 2*padding; |
|
| 649 |
int butHeight= (int)mMenuItemSize; |
|
| 650 |
int lastButH = (int)(mMenuItemSize*LAST_BUTTON) ; |
|
| 651 |
|
|
| 652 |
LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( butWidth, butHeight ); |
|
| 653 |
pM.setMargins(margin, 0, margin, margin); |
|
| 654 |
LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( butWidth, butHeight ); |
|
| 655 |
pT.setMargins(margin, margin, margin, margin); |
|
| 656 |
LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( butWidth, lastButH ); |
|
| 657 |
pB.setMargins(margin, margin, margin, 2*margin); |
|
| 658 |
|
|
| 659 |
mPlayLayout.removeAllViews(); |
|
| 660 |
|
|
| 661 |
RubikScores scores = RubikScores.getInstance(); |
|
| 662 |
|
|
| 663 |
for(int i=0; i<numLevel; i++) |
|
| 664 |
{
|
|
| 665 |
final int level = i<numLevel-1 ? i+1 : dbLevel; |
|
| 666 |
final int scrambles = i<numLevel-1 ? i+1 : numScrambles; |
|
| 667 |
Button button = new Button(act); |
|
| 668 |
button.setLayoutParams(i==0 ? pT : (i==numLevel-1 ? pB : pM)); |
|
| 669 |
button.setText(levels[i]); |
|
| 670 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize); |
|
| 671 |
|
|
| 672 |
int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved; |
|
| 673 |
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0); |
|
| 674 |
|
|
| 675 |
button.setOnClickListener( new View.OnClickListener() |
|
| 676 |
{
|
|
| 677 |
@Override |
|
| 678 |
public void onClick(View v) |
|
| 679 |
{
|
|
| 680 |
ObjectControl control = act.getControl(); |
|
| 681 |
|
|
| 682 |
if(control.isUINotBlocked()) |
|
| 683 |
{
|
|
| 684 |
if( mPlayPopup!=null ) mPlayPopup.dismiss(); |
|
| 685 |
mLevelValue = level; |
|
| 686 |
mShouldReactToEndOfScrambling = true; |
|
| 687 |
control.scrambleObject(scrambles); |
|
| 688 |
} |
|
| 689 |
} |
|
| 690 |
}); |
|
| 691 |
|
|
| 692 |
mPlayLayout.addView(button); |
|
| 693 |
} |
|
| 694 |
} |
|
| 695 |
|
|
| 696 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 697 |
|
|
| 698 |
public int getLevel() |
|
| 699 |
{
|
|
| 700 |
return mLevelValue; |
|
| 701 |
} |
|
| 702 |
|
|
| 703 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 704 |
|
|
| 705 |
public void recreatePopup() |
|
| 706 |
{
|
|
| 707 |
mObjectPopup = null; |
|
| 708 |
|
|
| 709 |
int numObjects = RubikObjectList.getNumObjects(); |
|
| 710 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS; |
|
| 711 |
mColCount = NUM_COLUMNS; |
|
| 712 |
} |
|
| 713 |
|
|
| 714 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 715 |
|
|
| 716 |
public boolean shouldReactToEndOfScrambling() |
|
| 717 |
{
|
|
| 718 |
return mShouldReactToEndOfScrambling; |
|
| 719 |
} |
|
| 720 |
|
|
| 721 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 722 |
|
|
| 723 |
public void receiveUpdate(RubikUpdates updates) |
|
| 724 |
{
|
|
| 725 |
Activity act = mWeakAct.get(); |
|
| 726 |
|
|
| 727 |
if( act!=null ) |
|
| 728 |
{
|
|
| 729 |
act.runOnUiThread(new Runnable() |
|
| 730 |
{
|
|
| 731 |
@Override |
|
| 732 |
public void run() |
|
| 733 |
{
|
|
| 734 |
int num = updates.getCompletedNumber(); |
|
| 735 |
|
|
| 736 |
if( num>0 ) |
|
| 737 |
{
|
|
| 738 |
String shownNum = String.valueOf(num); |
|
| 739 |
mBubbleUpdates.setText(shownNum); |
|
| 740 |
mBubbleUpdates.setVisibility(View.VISIBLE); |
|
| 741 |
int height = (int)(0.05f*mScreenWidth); |
|
| 742 |
mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height); |
|
| 743 |
} |
|
| 744 |
else |
|
| 745 |
{
|
|
| 746 |
mBubbleUpdates.setVisibility(View.INVISIBLE); |
|
| 747 |
} |
|
| 748 |
} |
|
| 749 |
}); |
|
| 750 |
} |
|
| 751 |
} |
|
| 752 |
|
|
| 753 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 754 |
|
|
| 755 |
public void errorUpdate() |
|
| 756 |
{
|
|
| 757 |
android.util.Log.e("D", "Screen: Error receiving update");
|
|
| 758 |
} |
|
| 759 |
} |
|
| src/main/java/org/distorted/screens/RubikScreenFreePlay.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.screens; |
|
| 21 |
|
|
| 22 |
import android.content.SharedPreferences; |
|
| 23 |
import android.view.View; |
|
| 24 |
import android.widget.LinearLayout; |
|
| 25 |
|
|
| 26 |
import org.distorted.bandaged.BandagedPlayActivity; |
|
| 27 |
import org.distorted.dialogs.RubikDialogAbandon; |
|
| 28 |
import org.distorted.helpers.TransparentImageButton; |
|
| 29 |
import org.distorted.main.R; |
|
| 30 |
import org.distorted.main.RubikActivity; |
|
| 31 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 32 |
import org.distorted.objects.RubikObject; |
|
| 33 |
import org.distorted.objects.RubikObjectList; |
|
| 34 |
|
|
| 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 36 |
|
|
| 37 |
public class RubikScreenFreePlay extends RubikScreenBase |
|
| 38 |
{
|
|
| 39 |
private static final int MOVES_THRESHHOLD = 10; |
|
| 40 |
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton; |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
RubikScreenFreePlay() |
|
| 45 |
{
|
|
| 46 |
|
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
void leaveScreen(RubikActivity act) |
|
| 52 |
{
|
|
| 53 |
|
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
void enterScreen(final RubikActivity act) |
|
| 59 |
{
|
|
| 60 |
int width = act.getScreenWidthInPixels(); |
|
| 61 |
|
|
| 62 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 63 |
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 64 |
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 65 |
|
|
| 66 |
// TOP //////////////////////////// |
|
| 67 |
setupSolveButton(act); |
|
| 68 |
setupScrambleButton(act); |
|
| 69 |
|
|
| 70 |
LinearLayout layoutUpper = act.findViewById(R.id.upperBar); |
|
| 71 |
|
|
| 72 |
LinearLayout layoutLeftU = new LinearLayout(act); |
|
| 73 |
layoutLeftU.setLayoutParams(paramsL); |
|
| 74 |
LinearLayout layoutMidU = new LinearLayout(act); |
|
| 75 |
layoutMidU.setLayoutParams(paramsM); |
|
| 76 |
LinearLayout layoutRightU= new LinearLayout(act); |
|
| 77 |
layoutRightU.setLayoutParams(paramsR); |
|
| 78 |
|
|
| 79 |
layoutLeftU.addView(mSolveButton); |
|
| 80 |
layoutRightU.addView(mScrambleButton); |
|
| 81 |
|
|
| 82 |
layoutUpper.removeAllViews(); |
|
| 83 |
layoutUpper.addView(layoutLeftU); |
|
| 84 |
layoutUpper.addView(layoutMidU); |
|
| 85 |
layoutUpper.addView(layoutRightU); |
|
| 86 |
|
|
| 87 |
// BOTTOM ////////////////////////// |
|
| 88 |
setupBackButton(act); |
|
| 89 |
createBottomPane(act,mBackButton,null); |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
|
|
| 94 |
private void setupSolveButton(final RubikActivity act) |
|
| 95 |
{
|
|
| 96 |
int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve); |
|
| 97 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 98 |
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params); |
|
| 99 |
|
|
| 100 |
mSolveButton.setOnClickListener( new View.OnClickListener() |
|
| 101 |
{
|
|
| 102 |
@Override |
|
| 103 |
public void onClick(View v) |
|
| 104 |
{
|
|
| 105 |
ObjectControl control = act.getControl(); |
|
| 106 |
control.solveObject(); |
|
| 107 |
mMovesController.clearMoves(act); |
|
| 108 |
} |
|
| 109 |
}); |
|
| 110 |
} |
|
| 111 |
|
|
| 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 113 |
|
|
| 114 |
private void setupScrambleButton(final RubikActivity act) |
|
| 115 |
{
|
|
| 116 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble,R.drawable.ui_medium_cube_scramble, R.drawable.ui_big_cube_scramble, R.drawable.ui_huge_cube_scramble); |
|
| 117 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 118 |
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params); |
|
| 119 |
|
|
| 120 |
mScrambleButton.setOnClickListener( new View.OnClickListener() |
|
| 121 |
{
|
|
| 122 |
@Override |
|
| 123 |
public void onClick(View v) |
|
| 124 |
{
|
|
| 125 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 126 |
RubikObject object = RubikObjectList.getObject(currObject); |
|
| 127 |
int numScrambles = object==null ? 0 : object.getNumScramble(); |
|
| 128 |
//mShouldReactToEndOfScrambling = false; |
|
| 129 |
act.getControl().scrambleObject(numScrambles); |
|
| 130 |
} |
|
| 131 |
}); |
|
| 132 |
} |
|
| 133 |
|
|
| 134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 135 |
|
|
| 136 |
private void setupBackButton(final RubikActivity act) |
|
| 137 |
{
|
|
| 138 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back); |
|
| 139 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
| 140 |
mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params); |
|
| 141 |
|
|
| 142 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
| 143 |
{
|
|
| 144 |
@Override |
|
| 145 |
public void onClick(View v) |
|
| 146 |
{
|
|
| 147 |
if( mMovesController.getNumMoves() > MOVES_THRESHHOLD ) |
|
| 148 |
{
|
|
| 149 |
RubikDialogAbandon abaDiag = new RubikDialogAbandon(); |
|
| 150 |
abaDiag.show(act.getSupportFragmentManager(), null); |
|
| 151 |
} |
|
| 152 |
else |
|
| 153 |
{
|
|
| 154 |
ScreenList.goBack(act); |
|
| 155 |
} |
|
| 156 |
} |
|
| 157 |
}); |
|
| 158 |
} |
|
| 159 |
|
|
| 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 161 |
|
|
| 162 |
public void savePreferences(SharedPreferences.Editor editor) |
|
| 163 |
{
|
|
| 164 |
|
|
| 165 |
} |
|
| 166 |
|
|
| 167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 168 |
|
|
| 169 |
public void restorePreferences(SharedPreferences preferences) |
|
| 170 |
{
|
|
| 171 |
|
|
| 172 |
} |
|
| 173 |
} |
|
| src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
|---|---|---|
| 25 | 25 |
import android.content.Context; |
| 26 | 26 |
import android.content.SharedPreferences; |
| 27 | 27 |
import android.content.res.Resources; |
| 28 |
import android.graphics.Color; |
|
| 28 | 29 |
import android.graphics.drawable.BitmapDrawable; |
| 29 | 30 |
import android.os.Build; |
| 30 | 31 |
import android.os.Bundle; |
| ... | ... | |
| 32 | 33 |
import android.view.Gravity; |
| 33 | 34 |
import android.view.LayoutInflater; |
| 34 | 35 |
import android.view.View; |
| 36 |
import android.view.ViewGroup; |
|
| 35 | 37 |
import android.widget.Button; |
| 36 | 38 |
import android.widget.GridLayout; |
| 37 | 39 |
import android.widget.ImageButton; |
| 38 | 40 |
import android.widget.LinearLayout; |
| 39 | 41 |
import android.widget.PopupWindow; |
| 40 | 42 |
import android.widget.RelativeLayout; |
| 43 |
import android.widget.ScrollView; |
|
| 41 | 44 |
import android.widget.TextView; |
| 42 | 45 |
|
| 46 |
import org.distorted.config.ConfigActivity; |
|
| 43 | 47 |
import org.distorted.dialogs.RubikDialogUpdates; |
| 44 | 48 |
import org.distorted.external.RubikNetwork; |
| 45 | 49 |
import org.distorted.external.RubikUpdates; |
| 50 |
import org.distorted.main.RubikRenderer; |
|
| 46 | 51 |
import org.distorted.objectlib.main.ObjectControl; |
| 47 | 52 |
|
| 48 | 53 |
import org.distorted.main.R; |
| ... | ... | |
| 61 | 66 |
|
| 62 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 63 | 68 |
|
| 64 |
public class RubikScreenPlay extends RubikScreenBase implements RubikNetwork.Updatee
|
|
| 69 |
public class RubikScreenPlay extends RubikScreenAbstract implements RubikNetwork.Updatee
|
|
| 65 | 70 |
{
|
| 66 | 71 |
public static final int NUM_COLUMNS = 5; |
| 67 | 72 |
public static final int LEVELS_SHOWN = 10; |
| 68 | 73 |
|
| 69 |
private static final int[] BUTTON_LABELS = { R.string.scores,
|
|
| 70 |
R.string.patterns, |
|
| 71 |
R.string.solver, |
|
| 72 |
R.string.tutorials, |
|
| 73 |
R.string.bandaged, |
|
| 74 |
R.string.about }; |
|
| 75 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length; |
|
| 76 |
|
|
| 77 | 74 |
private static final float LAST_BUTTON = 1.5f; |
| 78 | 75 |
private static final int[] mLocation = new int[2]; |
| 79 | 76 |
|
| 80 |
private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton; |
|
| 81 |
private TransparentButton mPlayButton; |
|
| 82 |
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
|
| 77 |
private ImageButton mAboutButton, mUpdatesButton, mExitButton; |
|
| 78 |
// private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
|
| 83 | 79 |
private LinearLayout mPlayLayout; |
| 84 | 80 |
private TextView mBubbleUpdates; |
| 81 |
private int mCurrentBubbleNumber; |
|
| 85 | 82 |
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth; |
| 86 | 83 |
private int mLevelValue; |
| 87 | 84 |
private float mButtonSize, mMenuItemSize, mMenuTextSize; |
| 88 | 85 |
private int mColCount, mRowCount, mMaxRowCount; |
| 89 |
private int mUpperBarHeight; |
|
| 86 |
private int mUpperBarHeight, mLowerBarHeight;
|
|
| 90 | 87 |
private boolean mShouldReactToEndOfScrambling; |
| 91 | 88 |
private int mBottomHeight; |
| 92 |
private float mScreenWidth; |
|
| 89 |
private float mScreenWidth, mScreenHeight;
|
|
| 93 | 90 |
private WeakReference<RubikActivity> mWeakAct; |
| 94 | 91 |
|
| 95 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 96 | 93 |
|
| 97 | 94 |
void leaveScreen(RubikActivity act) |
| 98 | 95 |
{
|
| 99 |
|
|
| 96 |
act.switchRenderingOn(); |
|
| 97 |
LinearLayout hiddenView = act.findViewById(R.id.hiddenView); |
|
| 98 |
hiddenView.removeAllViews(); |
|
| 100 | 99 |
} |
| 101 | 100 |
|
| 102 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 103 | 102 |
|
| 104 | 103 |
void enterScreen(final RubikActivity act) |
| 105 | 104 |
{
|
| 105 |
act.switchRenderingOff(); |
|
| 106 | 106 |
mWeakAct = new WeakReference<>(act); |
| 107 | 107 |
int numObjects = RubikObjectList.getNumObjects(); |
| 108 | 108 |
mScreenWidth = act.getScreenWidthInPixels(); |
| 109 |
mScreenHeight= act.getScreenHeightInPixels(); |
|
| 109 | 110 |
mUpperBarHeight = act.getHeightUpperBar(); |
| 111 |
mLowerBarHeight = act.getHeightLowerBar(); |
|
| 110 | 112 |
|
| 111 | 113 |
mMenuTextSize = mScreenWidth*RubikActivity.MENU_MED_TEXT_SIZE; |
| 112 | 114 |
mButtonSize = mScreenWidth*RubikActivity.BUTTON_TEXT_SIZE; |
| ... | ... | |
| 115 | 117 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS; |
| 116 | 118 |
mColCount = NUM_COLUMNS; |
| 117 | 119 |
|
| 120 |
float titleSize = mScreenWidth*RubikActivity.TITLE_TEXT_SIZE; |
|
| 121 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 122 |
|
|
| 118 | 123 |
// TOP //////////////////////////// |
| 119 | 124 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
| 120 | 125 |
layoutTop.removeAllViews(); |
| 126 |
TextView label = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
| 127 |
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
| 128 |
// label.setText(R.string.app_name); |
|
| 129 |
layoutTop.addView(label); |
|
| 130 |
|
|
| 131 |
// BOTTOM ///////////////////////// |
|
| 132 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
| 133 |
layoutBot.removeAllViews(); |
|
| 134 |
RelativeLayout relLayout = (RelativeLayout)inflater.inflate(R.layout.play_bottom_bar, null); |
|
| 135 |
//relLayout.setBackgroundColor(Color.parseColor("#000000"));
|
|
| 136 |
layoutBot.addView(relLayout); |
|
| 137 |
|
|
| 138 |
TypedValue outValue = new TypedValue(); |
|
| 139 |
act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
|
| 140 |
|
|
| 141 |
setupAboutButton(act,relLayout,outValue); |
|
| 142 |
setupUpdatesButtonAndBubble(act,relLayout,outValue); |
|
| 143 |
setupExitButton(act,relLayout,outValue); |
|
| 144 |
|
|
| 145 |
// POPUP ////////////////////////// |
|
| 146 |
LinearLayout hiddenView = act.findViewById(R.id.hiddenView); |
|
| 147 |
hiddenView.removeAllViews(); |
|
| 121 | 148 |
|
| 122 |
setupObjectButton(act,mScreenWidth); |
|
| 123 |
layoutTop.addView(mObjButton); |
|
| 149 |
ViewGroup.LayoutParams paramsMid = hiddenView.getLayoutParams(); |
|
| 150 |
paramsMid.height = (int)(mScreenHeight-mUpperBarHeight-mLowerBarHeight); |
|
| 151 |
hiddenView.setLayoutParams(paramsMid); |
|
| 124 | 152 |
|
| 125 |
setupMenuButton(act,mScreenWidth); |
|
| 126 |
layoutTop.addView(mMenuButton); |
|
| 153 |
label.setText("s:"+mScreenHeight+" u:"+mUpperBarHeight+" l:"+mLowerBarHeight);
|
|
| 127 | 154 |
|
| 128 |
setupPlayButton(act,mScreenWidth);
|
|
| 129 |
layoutTop.addView(mPlayButton);
|
|
| 155 |
ScrollView scroll = (ScrollView)inflater.inflate(R.layout.popup_object_simple, null);
|
|
| 156 |
hiddenView.addView(scroll);
|
|
| 130 | 157 |
|
| 131 |
setupSolveButton(act); |
|
| 132 |
setupScrambleButton(act); |
|
| 133 |
createBottomPane(act,mSolveButton,mScrambleButton); |
|
| 158 |
setupScrollingObjects(act,scroll,mScreenWidth,mScreenHeight); |
|
| 134 | 159 |
} |
| 135 | 160 |
|
| 136 | 161 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
| 137 | 162 |
|
| 163 |
private void setupAboutButton(final RubikActivity act, RelativeLayout relLayout, TypedValue value) |
|
| 164 |
{
|
|
| 165 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info); |
|
| 166 |
mAboutButton = relLayout.findViewById(R.id.buttonAbout); |
|
| 167 |
mAboutButton.setImageResource(icon); |
|
| 168 |
mAboutButton.setBackgroundResource(value.resourceId); |
|
| 169 |
|
|
| 170 |
mAboutButton.setOnClickListener( new View.OnClickListener() |
|
| 171 |
{
|
|
| 172 |
@Override |
|
| 173 |
public void onClick(View v) |
|
| 174 |
{
|
|
| 175 |
RubikDialogAbout aDiag = new RubikDialogAbout(); |
|
| 176 |
aDiag.show(act.getSupportFragmentManager(), null); |
|
| 177 |
} |
|
| 178 |
}); |
|
| 179 |
} |
|
| 180 |
|
|
| 181 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 182 |
|
|
| 183 |
private void setupUpdatesButtonAndBubble(final RubikActivity act, RelativeLayout relLayout, TypedValue value) |
|
| 184 |
{
|
|
| 185 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_download,R.drawable.ui_medium_download, R.drawable.ui_big_download, R.drawable.ui_huge_download); |
|
| 186 |
mUpdatesButton = relLayout.findViewById(R.id.buttonDown); |
|
| 187 |
mUpdatesButton.setImageResource(icon); |
|
| 188 |
mUpdatesButton.setBackgroundResource(value.resourceId); |
|
| 189 |
|
|
| 190 |
mUpdatesButton.setOnClickListener( new View.OnClickListener() |
|
| 191 |
{
|
|
| 192 |
@Override |
|
| 193 |
public void onClick(View v) |
|
| 194 |
{
|
|
| 195 |
RubikDialogUpdates uDiag = new RubikDialogUpdates(); |
|
| 196 |
uDiag.show( act.getSupportFragmentManager(), RubikDialogUpdates.getDialogTag() ); |
|
| 197 |
} |
|
| 198 |
}); |
|
| 199 |
|
|
| 200 |
mBubbleUpdates = relLayout.findViewById(R.id.bubbleUpdates); |
|
| 201 |
mBubbleUpdates.setVisibility(View.INVISIBLE); |
|
| 202 |
|
|
| 203 |
RubikNetwork network = RubikNetwork.getInstance(); |
|
| 204 |
network.signUpForUpdates(this); |
|
| 205 |
} |
|
| 206 |
|
|
| 207 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 208 |
|
|
| 209 |
private void setupExitButton(final RubikActivity act, RelativeLayout relLayout, TypedValue value) |
|
| 210 |
{
|
|
| 211 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_exit,R.drawable.ui_medium_exit, R.drawable.ui_big_exit, R.drawable.ui_huge_exit); |
|
| 212 |
mExitButton = relLayout.findViewById(R.id.buttonExit); |
|
| 213 |
mExitButton.setImageResource(icon); |
|
| 214 |
mExitButton.setBackgroundResource(value.resourceId); |
|
| 215 |
|
|
| 216 |
mExitButton.setOnClickListener( new View.OnClickListener() |
|
| 217 |
{
|
|
| 218 |
@Override |
|
| 219 |
public void onClick(View v) |
|
| 220 |
{
|
|
| 221 |
act.finish(); |
|
Also available in: Unified diff
New UI