Revision e03e0352
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/dialogs/RubikDialogMain.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 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.dialogs; |
|
21 |
|
|
22 |
import android.app.Dialog; |
|
23 |
import android.os.Bundle; |
|
24 |
import androidx.annotation.NonNull; |
|
25 |
import androidx.fragment.app.FragmentActivity; |
|
26 |
import androidx.appcompat.app.AlertDialog; |
|
27 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
28 |
|
|
29 |
import android.util.DisplayMetrics; |
|
30 |
import android.util.TypedValue; |
|
31 |
import android.view.LayoutInflater; |
|
32 |
import android.view.View; |
|
33 |
import android.view.Window; |
|
34 |
import android.view.WindowManager; |
|
35 |
import android.widget.Button; |
|
36 |
|
|
37 |
import org.distorted.main.R; |
|
38 |
import org.distorted.main.RubikActivity; |
|
39 |
|
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
public class RubikDialogMain extends AppCompatDialogFragment |
|
43 |
{ |
|
44 |
@NonNull |
|
45 |
@Override |
|
46 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
47 |
{ |
|
48 |
FragmentActivity act = getActivity(); |
|
49 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
50 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
51 |
final View view = inflater.inflate(R.layout.dialog_main, null); |
|
52 |
|
|
53 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
54 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
55 |
float textSize = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE; |
|
56 |
int buttonSize = (int)(2.5f*textSize); |
|
57 |
|
|
58 |
Button play = view.findViewById(R.id.rubikPlay); |
|
59 |
play.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
60 |
play.setHeight(buttonSize); |
|
61 |
Button scor = view.findViewById(R.id.rubikScores); |
|
62 |
scor.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
63 |
scor.setHeight(buttonSize); |
|
64 |
Button patt = view.findViewById(R.id.rubikPatterns); |
|
65 |
patt.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
66 |
patt.setHeight(buttonSize); |
|
67 |
Button solv = view.findViewById(R.id.rubikSolver); |
|
68 |
solv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
69 |
solv.setHeight(buttonSize); |
|
70 |
Button abou = view.findViewById(R.id.rubikAbout); |
|
71 |
abou.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
72 |
abou.setHeight(buttonSize); |
|
73 |
|
|
74 |
builder.setView(view); |
|
75 |
|
|
76 |
Dialog dialog = builder.create(); |
|
77 |
|
|
78 |
dialog.setCanceledOnTouchOutside(false); |
|
79 |
|
|
80 |
Window window = dialog.getWindow(); |
|
81 |
|
|
82 |
if( window!=null ) |
|
83 |
{ |
|
84 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
85 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
86 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
87 |
} |
|
88 |
|
|
89 |
return dialog; |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public static String getDialogTag() |
|
95 |
{ |
|
96 |
return "DialogMain"; |
|
97 |
} |
|
98 |
} |
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
25 | 25 |
import androidx.appcompat.app.AppCompatActivity; |
26 | 26 |
|
27 | 27 |
import android.util.DisplayMetrics; |
28 |
import android.view.View; |
|
29 | 28 |
|
30 | 29 |
import com.google.firebase.analytics.FirebaseAnalytics; |
31 | 30 |
|
32 |
import org.distorted.dialogs.RubikDialogAbout; |
|
33 | 31 |
import org.distorted.dialogs.RubikDialogError; |
34 |
import org.distorted.dialogs.RubikDialogScores; |
|
35 | 32 |
import org.distorted.effects.BaseEffect; |
36 | 33 |
import org.distorted.library.main.DistortedLibrary; |
37 | 34 |
|
... | ... | |
96 | 93 |
super.onResume(); |
97 | 94 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
98 | 95 |
view.onResume(); |
96 |
view.initialize(); |
|
99 | 97 |
restorePreferences(); |
100 | 98 |
RubikState.setState(this); |
101 | 99 |
|
... | ... | |
296 | 294 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
297 | 295 |
return view.isVertical(); |
298 | 296 |
} |
299 |
|
|
300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
301 |
|
|
302 |
public void Play(View v) |
|
303 |
{ |
|
304 |
RubikState.switchState(this,RubikState.PLAY); |
|
305 |
} |
|
306 |
|
|
307 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
308 |
|
|
309 |
public void Scores(View v) |
|
310 |
{ |
|
311 |
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass(); |
|
312 |
int object = play.getObject(); |
|
313 |
int size = play.getSize(); |
|
314 |
int sizeIndex = RubikObjectList.getSizeIndex(object,size); |
|
315 |
|
|
316 |
Bundle bundle = new Bundle(); |
|
317 |
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) ); |
|
318 |
bundle.putBoolean("submitting", false); |
|
319 |
|
|
320 |
RubikDialogScores scores = new RubikDialogScores(); |
|
321 |
scores.setArguments(bundle); |
|
322 |
scores.show(getSupportFragmentManager(), null); |
|
323 |
} |
|
324 |
|
|
325 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
326 |
|
|
327 |
public void Patterns(View v) |
|
328 |
{ |
|
329 |
RubikState.switchState(this,RubikState.PATT); |
|
330 |
} |
|
331 |
|
|
332 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
333 |
|
|
334 |
public void Solver(View v) |
|
335 |
{ |
|
336 |
RubikState.switchState(this,RubikState.SVER); |
|
337 |
} |
|
338 |
|
|
339 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
340 |
|
|
341 |
public void About(View v) |
|
342 |
{ |
|
343 |
RubikDialogAbout diag = new RubikDialogAbout(); |
|
344 |
diag.show(getSupportFragmentManager(), null); |
|
345 |
} |
|
346 | 297 |
} |
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
633 | 633 |
} |
634 | 634 |
} |
635 | 635 |
|
636 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
637 |
|
|
638 |
void initialize() |
|
639 |
{ |
|
640 |
mPtrID1 = INVALID_POINTER_ID; |
|
641 |
mPtrID2 = INVALID_POINTER_ID; |
|
642 |
} |
|
643 |
|
|
636 | 644 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
637 | 645 |
// PUBLIC API |
638 | 646 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
652 | 660 |
mFirstIndex =0; |
653 | 661 |
mLastIndex =0; |
654 | 662 |
|
655 |
mPtrID1 = INVALID_POINTER_ID; |
|
656 |
mPtrID2 = INVALID_POINTER_ID; |
|
657 |
|
|
658 | 663 |
mRenderer = new RubikRenderer(this); |
659 | 664 |
mPreRender = new RubikPreRender(this); |
660 | 665 |
|
src/main/java/org/distorted/objects/RubikObject.java | ||
---|---|---|
460 | 460 |
final float ratio = 1.0f/(NUM_FACES+1); |
461 | 461 |
final Static4D[] maps = new Static4D[NUM_FACES]; |
462 | 462 |
|
463 |
try |
|
464 |
{ |
|
465 |
maps[face] = new Static4D( newColor*ratio, 0.0f, ratio, 1.0f); |
|
466 |
mMesh.setTextureMap(maps,NUM_FACES*cubit); |
|
467 |
} |
|
468 |
catch(ArrayIndexOutOfBoundsException ignored) |
|
469 |
{ |
|
470 |
// the object must have changed in between of us touching the screen and getting here |
|
471 |
// (which happens after the next render, i.e. about 30 miliseconds later) |
|
472 |
// ignore. |
|
473 |
} |
|
463 |
maps[face] = new Static4D( newColor*ratio, 0.0f, ratio, 1.0f); |
|
464 |
mMesh.setTextureMap(maps,NUM_FACES*cubit); |
|
474 | 465 |
} |
475 | 466 |
|
476 | 467 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/RubikPyraminxMovement.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
class RubikPyraminxMovement extends RubikObjectMovement |
25 | 25 |
{ |
26 |
private static final float SQ2 = (float)Math.sqrt(2);
|
|
26 |
private static final float SQ6 = (float)Math.sqrt(6);
|
|
27 | 27 |
private static final float SQ3 = (float)Math.sqrt(3); |
28 | 28 |
|
29 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
30 | 30 |
|
31 | 31 |
RubikPyraminxMovement() |
32 | 32 |
{ |
33 |
super(RubikPyraminx.AXIS, 1, SQ2*SQ3/12, SQ3/6);
|
|
33 |
super(RubikPyraminx.AXIS, 1, SQ6/12, SQ3/6);
|
|
34 | 34 |
} |
35 | 35 |
|
36 | 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/states/RubikState.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
public enum RubikState |
33 | 33 |
{ |
34 |
MAIN ( null , MODE_DRAG , new RubikStateMain() ), |
|
35 |
PLAY ( MAIN , MODE_ROTATE , new RubikStatePlay() ), |
|
34 |
PLAY ( null , MODE_ROTATE , new RubikStatePlay() ), |
|
36 | 35 |
SOLV ( PLAY , MODE_ROTATE , new RubikStateSolving() ), |
37 |
PATT ( MAIN , MODE_DRAG , new RubikStatePattern() ),
|
|
38 |
SVER ( MAIN , MODE_REPLACE, new RubikStateSolver() ),
|
|
36 |
PATT ( PLAY , MODE_DRAG , new RubikStatePattern() ),
|
|
37 |
SVER ( PLAY , MODE_REPLACE, new RubikStateSolver() ),
|
|
39 | 38 |
SOLU ( SVER , MODE_DRAG , new RubikStateSolution() ), |
40 | 39 |
READ ( PLAY , MODE_ROTATE , new RubikStateReady() ), |
41 |
DONE ( PLAY , MODE_DRAG , new RubikStateDone() ), |
|
40 |
DONE ( PLAY , MODE_DRAG , new RubikStateDone() ),
|
|
42 | 41 |
; |
43 | 42 |
|
44 | 43 |
public static final int LENGTH = values().length; |
... | ... | |
65 | 64 |
|
66 | 65 |
public static RubikState getState(int ordinal) |
67 | 66 |
{ |
68 |
return sizes[ordinal];
|
|
67 |
return ordinal>=0 && ordinal<LENGTH ? sizes[ordinal] : PLAY;
|
|
69 | 68 |
} |
70 | 69 |
|
71 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
93 | 92 |
|
94 | 93 |
public static void restorePreferences(SharedPreferences preferences) |
95 | 94 |
{ |
96 |
int currState = preferences.getInt("curr_state", RubikState.MAIN.ordinal() );
|
|
95 |
int currState = preferences.getInt("curr_state", RubikState.PLAY.ordinal() );
|
|
97 | 96 |
mCurrState = getState(currState); |
98 | 97 |
} |
99 | 98 |
|
src/main/java/org/distorted/states/RubikStateMain.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.states; |
|
21 |
|
|
22 |
import android.content.SharedPreferences; |
|
23 |
import androidx.fragment.app.FragmentManager; |
|
24 |
import android.util.DisplayMetrics; |
|
25 |
import android.util.TypedValue; |
|
26 |
import android.view.LayoutInflater; |
|
27 |
import android.view.View; |
|
28 |
import android.widget.Button; |
|
29 |
import android.widget.LinearLayout; |
|
30 |
import android.widget.TextView; |
|
31 |
|
|
32 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
|
33 |
|
|
34 |
import org.distorted.dialogs.RubikDialogMain; |
|
35 |
import org.distorted.main.BuildConfig; |
|
36 |
import org.distorted.main.R; |
|
37 |
import org.distorted.main.RubikActivity; |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
public class RubikStateMain extends RubikStateAbstract |
|
42 |
{ |
|
43 |
void leaveState(RubikActivity act) |
|
44 |
{ |
|
45 |
FragmentManager mana = act.getSupportFragmentManager(); |
|
46 |
RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag()); |
|
47 |
|
|
48 |
if( diag!=null ) |
|
49 |
{ |
|
50 |
try |
|
51 |
{ |
|
52 |
diag.dismiss(); |
|
53 |
} |
|
54 |
catch(IllegalStateException ex) |
|
55 |
{ |
|
56 |
if( !BuildConfig.DEBUG ) |
|
57 |
{ |
|
58 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
59 |
crashlytics.setCustomKey("MainDialog", ex.toString()); |
|
60 |
crashlytics.recordException(ex); |
|
61 |
} |
|
62 |
} |
|
63 |
} |
|
64 |
else |
|
65 |
{ |
|
66 |
if( !BuildConfig.DEBUG ) |
|
67 |
{ |
|
68 |
Exception ex = new Exception("Cannot find MainDialog"); |
|
69 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
70 |
crashlytics.setCustomKey("MainDialog", ex.toString()); |
|
71 |
crashlytics.recordException(ex); |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
|
78 |
void enterState(final RubikActivity act) |
|
79 |
{ |
|
80 |
float width = act.getScreenWidthInPixels(); |
|
81 |
float buttonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
|
82 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
|
83 |
|
|
84 |
FragmentManager mana = act.getSupportFragmentManager(); |
|
85 |
RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag()); |
|
86 |
|
|
87 |
if( diag==null ) |
|
88 |
{ |
|
89 |
RubikDialogMain diag2 = new RubikDialogMain(); |
|
90 |
diag2.show( mana, RubikDialogMain.getDialogTag() ); |
|
91 |
} |
|
92 |
|
|
93 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
94 |
|
|
95 |
// TOP //////////////////////////// |
|
96 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
97 |
layoutTop.removeAllViews(); |
|
98 |
final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
99 |
|
|
100 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
101 |
text.setText(R.string.app_name); |
|
102 |
layoutTop.addView(text); |
|
103 |
|
|
104 |
// BOT //////////////////////////// |
|
105 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
|
106 |
layoutLeft.removeAllViews(); |
|
107 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
|
108 |
layoutRight.removeAllViews(); |
|
109 |
|
|
110 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
111 |
float scale = metrics.density; |
|
112 |
int padding = (int)( 5*scale + 0.5f); |
|
113 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
114 |
|
|
115 |
Button buttonR = new Button(act); |
|
116 |
buttonR.setLayoutParams(params); |
|
117 |
buttonR.setPadding(padding,0,padding,0); |
|
118 |
buttonR.setTextSize(TypedValue.COMPLEX_UNIT_PX, buttonSize); |
|
119 |
buttonR.setText(R.string.exit); |
|
120 |
|
|
121 |
buttonR.setOnClickListener( new View.OnClickListener() |
|
122 |
{ |
|
123 |
@Override |
|
124 |
public void onClick(View v) |
|
125 |
{ |
|
126 |
RubikState.goBack(act); |
|
127 |
} |
|
128 |
}); |
|
129 |
|
|
130 |
layoutRight.addView(buttonR); |
|
131 |
} |
|
132 |
|
|
133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
134 |
|
|
135 |
public void savePreferences(SharedPreferences.Editor editor) |
|
136 |
{ |
|
137 |
|
|
138 |
} |
|
139 |
|
|
140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
141 |
|
|
142 |
public void restorePreferences(SharedPreferences preferences) |
|
143 |
{ |
|
144 |
|
|
145 |
} |
|
146 |
} |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
23 | 23 |
import android.content.SharedPreferences; |
24 | 24 |
import android.graphics.drawable.BitmapDrawable; |
25 | 25 |
import android.os.Build; |
26 |
import android.os.Bundle; |
|
26 | 27 |
import android.util.DisplayMetrics; |
27 | 28 |
import android.util.TypedValue; |
28 | 29 |
import android.view.Gravity; |
... | ... | |
40 | 41 |
import androidx.annotation.NonNull; |
41 | 42 |
import androidx.appcompat.widget.AppCompatSpinner; |
42 | 43 |
|
43 |
import org.distorted.dialogs.RubikDialogEffects; |
|
44 |
import org.distorted.dialogs.RubikDialogAbout; |
|
45 |
import org.distorted.dialogs.RubikDialogScores; |
|
44 | 46 |
import org.distorted.main.R; |
45 | 47 |
import org.distorted.main.RubikActivity; |
46 | 48 |
import org.distorted.objects.RubikObjectList; |
... | ... | |
53 | 55 |
public static final int DEF_OBJECT= RubikObjectList.CUBE.ordinal(); |
54 | 56 |
public static final int DEF_SIZE = 3; |
55 | 57 |
|
56 |
private ImageButton mObjButton, mSettingsButton; |
|
58 |
private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.about }; |
|
59 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length; |
|
60 |
|
|
61 |
private ImageButton mObjButton, mMenuButton; |
|
57 | 62 |
private Button mBackButton, mSolveButton, mPlayButton; |
58 |
private PopupWindow mPopup; |
|
63 |
private PopupWindow mObjectPopup, mMenuPopup;
|
|
59 | 64 |
private int mObject = DEF_OBJECT; |
60 | 65 |
private int mSize = DEF_SIZE; |
61 |
private int mLayoutWidth;
|
|
62 |
private LinearLayout mLayout; |
|
66 |
private int mObjectLayoutWidth, mMenuLayoutHeight;
|
|
67 |
private LinearLayout mObjectLayout, mMenuLayout;
|
|
63 | 68 |
private AppCompatSpinner mLevelSpinner; |
64 | 69 |
private ArrayAdapter<String> mSpinnerAdapter; |
65 | 70 |
private int mLevelValue; |
... | ... | |
94 | 99 |
setupPlayButton(act,scale); |
95 | 100 |
layoutTop.addView(mPlayButton); |
96 | 101 |
|
102 |
setupObjectWindow(act, scale); |
|
103 |
|
|
97 | 104 |
// BOT //////////////////////////// |
98 | 105 |
|
99 | 106 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
100 | 107 |
layoutLeft.removeAllViews(); |
101 | 108 |
|
102 |
setupSettingsButton(act,scale,width);
|
|
103 |
layoutLeft.addView(mSettingsButton);
|
|
109 |
setupMenuButton(act,scale,width);
|
|
110 |
layoutLeft.addView(mMenuButton);
|
|
104 | 111 |
setupSolveButton(act,scale); |
105 | 112 |
layoutLeft.addView(mSolveButton); |
106 | 113 |
|
... | ... | |
110 | 117 |
setupBackButton(act,scale); |
111 | 118 |
layoutRight.addView(mBackButton); |
112 | 119 |
|
113 |
setupPopupWindow(act, scale);
|
|
120 |
setupMenuWindow(act, scale);
|
|
114 | 121 |
} |
115 | 122 |
|
116 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
133 | 140 |
{ |
134 | 141 |
int total = RubikObjectList.getTotal(); |
135 | 142 |
boolean vertical = act.isVertical(); |
136 |
mLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL); |
|
143 |
mObjectLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL);
|
|
137 | 144 |
|
138 | 145 |
int width = view.getWidth(); |
139 |
int layhei = mLayoutWidth * (vertical? total:1); |
|
140 |
int laywid = mLayoutWidth * (vertical? 1:total); |
|
146 |
int layhei = mObjectLayoutWidth * (vertical? total:1);
|
|
147 |
int laywid = mObjectLayoutWidth * (vertical? 1:total);
|
|
141 | 148 |
|
142 |
mPopup.showAsDropDown(view, (width-laywid)/2, 0, Gravity.LEFT); |
|
149 |
mObjectPopup.showAsDropDown(view, (width-laywid)/2, 0, Gravity.LEFT);
|
|
143 | 150 |
|
144 | 151 |
if( android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1 ) |
145 | 152 |
{ |
146 |
mPopup.update(view, laywid, layhei); |
|
153 |
mObjectPopup.update(view, laywid, layhei);
|
|
147 | 154 |
} |
148 | 155 |
} |
149 | 156 |
} |
... | ... | |
221 | 228 |
|
222 | 229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
223 | 230 |
|
224 |
private void setupSettingsButton(final RubikActivity act, final float scale, final float width)
|
|
231 |
private void setupMenuButton(final RubikActivity act, final float scale, final float width)
|
|
225 | 232 |
{ |
226 | 233 |
int padding = (int)(3*scale + 0.5f); |
227 | 234 |
int widthBut = (int)(width/6); |
228 | 235 |
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(widthBut,LinearLayout.LayoutParams.MATCH_PARENT); |
229 |
mSettingsButton = new ImageButton(act);
|
|
230 |
mSettingsButton.setLayoutParams(objectParams);
|
|
231 |
mSettingsButton.setPadding(padding,0,padding,0);
|
|
232 |
mSettingsButton.setImageResource(R.drawable.settings);
|
|
236 |
mMenuButton = new ImageButton(act);
|
|
237 |
mMenuButton.setLayoutParams(objectParams);
|
|
238 |
mMenuButton.setPadding(padding,0,padding,0);
|
|
239 |
mMenuButton.setImageResource(R.drawable.menu);
|
|
233 | 240 |
|
234 |
mSettingsButton.setOnClickListener( new View.OnClickListener()
|
|
241 |
mMenuButton.setOnClickListener( new View.OnClickListener()
|
|
235 | 242 |
{ |
236 | 243 |
@Override |
237 | 244 |
public void onClick(View view) |
238 | 245 |
{ |
239 |
RubikDialogEffects settings = new RubikDialogEffects(); |
|
240 |
settings.show(act.getSupportFragmentManager(), null); |
|
246 |
if( act.getPreRender().canPlay() ) |
|
247 |
{ |
|
248 |
int total = RubikObjectList.getTotal(); |
|
249 |
boolean vertical = act.isVertical(); |
|
250 |
mMenuLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL); |
|
251 |
|
|
252 |
mMenuPopup.showAsDropDown(view, 0, -3*mMenuLayoutHeight, Gravity.LEFT); |
|
253 |
mMenuPopup.update(); |
|
254 |
} |
|
241 | 255 |
} |
242 | 256 |
}); |
243 | 257 |
} |
... | ... | |
275 | 289 |
mBackButton.setLayoutParams(backParams); |
276 | 290 |
mBackButton.setPadding(padding,0,padding,0); |
277 | 291 |
mBackButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
278 |
mBackButton.setText(R.string.back);
|
|
292 |
mBackButton.setText(R.string.exit);
|
|
279 | 293 |
|
280 | 294 |
mBackButton.setOnClickListener( new View.OnClickListener() |
281 | 295 |
{ |
... | ... | |
289 | 303 |
|
290 | 304 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
291 | 305 |
|
292 |
private void setupPopupWindow(final RubikActivity act, final float scale)
|
|
306 |
private void setupObjectWindow(final RubikActivity act, final float scale)
|
|
293 | 307 |
{ |
294 | 308 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
295 | 309 |
final View layout = layoutInflater.inflate(R.layout.popup_objects, null); |
296 |
mLayout = layout.findViewById(R.id.popup); |
|
310 |
mObjectLayout = layout.findViewById(R.id.popup);
|
|
297 | 311 |
|
298 |
mPopup = new PopupWindow(act); |
|
299 |
mPopup.setContentView(layout); |
|
300 |
mPopup.setFocusable(true); |
|
312 |
mObjectPopup = new PopupWindow(act);
|
|
313 |
mObjectPopup.setContentView(layout);
|
|
314 |
mObjectPopup.setFocusable(true);
|
|
301 | 315 |
int margin = (int)(5*scale + 0.5f); |
302 | 316 |
|
303 | 317 |
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(R.drawable.cube2); |
304 | 318 |
int cubeWidth = bd.getIntrinsicWidth(); |
305 |
mLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f); |
|
319 |
mObjectLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f);
|
|
306 | 320 |
|
307 | 321 |
for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++) |
308 | 322 |
{ |
... | ... | |
336 | 350 |
adjustSpinner(act); |
337 | 351 |
} |
338 | 352 |
|
339 |
mPopup.dismiss(); |
|
353 |
mObjectPopup.dismiss();
|
|
340 | 354 |
} |
341 | 355 |
}); |
342 | 356 |
|
343 |
mLayout.addView(button); |
|
357 |
mObjectLayout.addView(button);
|
|
344 | 358 |
} |
345 | 359 |
} |
346 | 360 |
} |
347 | 361 |
|
362 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
363 |
|
|
364 |
private void setupMenuWindow(final RubikActivity act, final float scale) |
|
365 |
{ |
|
366 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
367 |
final View layout = layoutInflater.inflate(R.layout.popup_objects, null); |
|
368 |
mMenuLayout = layout.findViewById(R.id.popup); |
|
369 |
|
|
370 |
mMenuPopup = new PopupWindow(act); |
|
371 |
mMenuPopup.setContentView(layout); |
|
372 |
mMenuPopup.setFocusable(true); |
|
373 |
int margin = (int)(5*scale + 0.5f); |
|
374 |
|
|
375 |
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); |
|
376 |
p.setMargins(margin, margin, margin, margin); |
|
377 |
|
|
378 |
for(int i=0; i<NUM_BUTTONS; i++) |
|
379 |
{ |
|
380 |
final int but = i; |
|
381 |
Button button = new Button(act); |
|
382 |
button.setLayoutParams(p); |
|
383 |
button.setText(BUTTON_LABELS[i]); |
|
384 |
|
|
385 |
button.setOnClickListener( new View.OnClickListener() |
|
386 |
{ |
|
387 |
@Override |
|
388 |
public void onClick(View v) |
|
389 |
{ |
|
390 |
mMenuPopup.dismiss(); |
|
391 |
Action(act,but); |
|
392 |
} |
|
393 |
}); |
|
394 |
|
|
395 |
mMenuLayout.addView(button); |
|
396 |
} |
|
397 |
|
|
398 |
mMenuLayoutHeight= (int)(margin + NUM_BUTTONS*(mButtonSize+margin)); |
|
399 |
} |
|
400 |
|
|
401 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
402 |
|
|
403 |
private void Action(RubikActivity act, int button) |
|
404 |
{ |
|
405 |
switch(button) |
|
406 |
{ |
|
407 |
case 0: RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass(); |
|
408 |
int object = play.getObject(); |
|
409 |
int size = play.getSize(); |
|
410 |
int sizeIndex = RubikObjectList.getSizeIndex(object,size); |
|
411 |
|
|
412 |
Bundle bundle = new Bundle(); |
|
413 |
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) ); |
|
414 |
bundle.putBoolean("submitting", false); |
|
415 |
|
|
416 |
RubikDialogScores scores = new RubikDialogScores(); |
|
417 |
scores.setArguments(bundle); |
|
418 |
scores.show(act.getSupportFragmentManager(), null); |
|
419 |
break; |
|
420 |
case 1: RubikState.switchState(act,RubikState.PATT); |
|
421 |
break; |
|
422 |
case 2: RubikState.switchState(act,RubikState.SVER); |
|
423 |
break; |
|
424 |
case 3: RubikDialogAbout diag = new RubikDialogAbout(); |
|
425 |
diag.show(act.getSupportFragmentManager(), null); |
|
426 |
break; |
|
427 |
} |
|
428 |
} |
|
429 |
|
|
348 | 430 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
349 | 431 |
|
350 | 432 |
public void savePreferences(SharedPreferences.Editor editor) |
... | ... | |
353 | 435 |
editor.putInt("statePlay_object", mObject); |
354 | 436 |
editor.putInt("statePlay_size" , mSize); |
355 | 437 |
|
356 |
if( mPopup!=null ) |
|
438 |
if( mObjectPopup!=null ) |
|
439 |
{ |
|
440 |
mObjectPopup.dismiss(); |
|
441 |
mObjectPopup = null; |
|
442 |
} |
|
443 |
|
|
444 |
if( mMenuPopup!=null ) |
|
357 | 445 |
{ |
358 |
mPopup.dismiss(); |
|
359 |
mPopup = null; |
|
446 |
mMenuPopup.dismiss();
|
|
447 |
mMenuPopup = null;
|
|
360 | 448 |
} |
361 | 449 |
} |
362 | 450 |
|
src/main/res/layout/dialog_main.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:gravity="center|fill_horizontal" |
|
6 |
android:layout_marginLeft="10dp" |
|
7 |
android:layout_marginRight="10dp" |
|
8 |
android:layout_marginTop="10dp" |
|
9 |
android:layout_marginBottom="10dp" |
|
10 |
android:background="@color/grey" |
|
11 |
android:orientation="vertical"> |
|
12 |
|
|
13 |
<Button |
|
14 |
android:id="@+id/rubikPlay" |
|
15 |
android:layout_width="fill_parent" |
|
16 |
android:layout_height="fill_parent" |
|
17 |
android:layout_weight="1" |
|
18 |
android:onClick="Play" |
|
19 |
android:layout_marginTop="10dp" |
|
20 |
android:layout_marginLeft="10dp" |
|
21 |
android:layout_marginRight="10dp" |
|
22 |
android:text="@string/play" /> |
|
23 |
|
|
24 |
<Button |
|
25 |
android:id="@+id/rubikScores" |
|
26 |
android:layout_width="fill_parent" |
|
27 |
android:layout_height="fill_parent" |
|
28 |
android:layout_weight="1" |
|
29 |
android:onClick="Scores" |
|
30 |
android:layout_marginLeft="10dp" |
|
31 |
android:layout_marginRight="10dp" |
|
32 |
android:text="@string/scores" /> |
|
33 |
|
|
34 |
<Button |
|
35 |
android:id="@+id/rubikPatterns" |
|
36 |
android:layout_width="fill_parent" |
|
37 |
android:layout_height="fill_parent" |
|
38 |
android:layout_weight="1" |
|
39 |
android:onClick="Patterns" |
|
40 |
android:layout_marginLeft="10dp" |
|
41 |
android:layout_marginRight="10dp" |
|
42 |
android:text="@string/patterns" /> |
|
43 |
|
|
44 |
<Button |
|
45 |
android:id="@+id/rubikSolver" |
|
46 |
android:layout_width="fill_parent" |
|
47 |
android:layout_height="fill_parent" |
|
48 |
android:layout_weight="1" |
|
49 |
android:onClick="Solver" |
|
50 |
android:layout_marginLeft="10dp" |
|
51 |
android:layout_marginRight="10dp" |
|
52 |
android:text="@string/solver" /> |
|
53 |
|
|
54 |
<Button |
|
55 |
android:id="@+id/rubikAbout" |
|
56 |
android:layout_width="fill_parent" |
|
57 |
android:layout_height="fill_parent" |
|
58 |
android:layout_weight="1" |
|
59 |
android:onClick="About" |
|
60 |
android:layout_marginLeft="10dp" |
|
61 |
android:layout_marginRight="10dp" |
|
62 |
android:layout_marginBottom="10dp" |
|
63 |
android:text="@string/about" /> |
|
64 |
|
|
65 |
</LinearLayout> |
Also available in: Unified diff
Remove the 'MAIN' state.
Fix one crasher with two-fingered dragging in the View.