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.bandaged;
|
21
|
|
22
|
import android.app.Activity;
|
23
|
import android.content.SharedPreferences;
|
24
|
import android.view.View;
|
25
|
import android.widget.LinearLayout;
|
26
|
|
27
|
import org.distorted.helpers.LockController;
|
28
|
import org.distorted.helpers.MovesController;
|
29
|
import org.distorted.helpers.TransparentImageButton;
|
30
|
import org.distorted.main.R;
|
31
|
import org.distorted.objectlib.main.ObjectControl;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class BandagedPlayScreen
|
36
|
{
|
37
|
private static final int NUM_SCRAMBLES = 500;
|
38
|
|
39
|
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
|
40
|
private final LockController mLockController;
|
41
|
private final MovesController mMovesController;
|
42
|
private String mKey;
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
public BandagedPlayScreen()
|
47
|
{
|
48
|
mLockController = new LockController();
|
49
|
mMovesController= new MovesController();
|
50
|
}
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
private void setupBackButton(final BandagedPlayActivity act)
|
55
|
{
|
56
|
int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
|
57
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
58
|
mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
59
|
|
60
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
61
|
{
|
62
|
@Override
|
63
|
public void onClick(View v)
|
64
|
{
|
65
|
ObjectControl control = act.getControl();
|
66
|
if( control!=null ) control.unblockEverything();
|
67
|
act.finish();
|
68
|
}
|
69
|
});
|
70
|
}
|
71
|
|
72
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73
|
|
74
|
private void setupSolveButton(final BandagedPlayActivity act)
|
75
|
{
|
76
|
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);
|
77
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
78
|
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
|
79
|
|
80
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
81
|
{
|
82
|
@Override
|
83
|
public void onClick(View v)
|
84
|
{
|
85
|
ObjectControl control = act.getControl();
|
86
|
control.solveObject();
|
87
|
mMovesController.clearMoves(act);
|
88
|
}
|
89
|
});
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
private void setupScrambleButton(final BandagedPlayActivity act)
|
95
|
{
|
96
|
int icon = BandagedPlayActivity.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);
|
97
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
98
|
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
99
|
|
100
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
101
|
{
|
102
|
@Override
|
103
|
public void onClick(View v)
|
104
|
{
|
105
|
ObjectControl control = act.getControl();
|
106
|
control.fastScrambleObject(NUM_SCRAMBLES);
|
107
|
mMovesController.clearMoves(act);
|
108
|
}
|
109
|
});
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
|
114
|
void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
|
115
|
{
|
116
|
mKey = "moveController_"+objectName;
|
117
|
|
118
|
int width = act.getScreenWidthInPixels();
|
119
|
|
120
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
121
|
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
|
122
|
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
123
|
|
124
|
LinearLayout layoutLeft = new LinearLayout(act);
|
125
|
layoutLeft.setLayoutParams(paramsL);
|
126
|
LinearLayout layoutMid = new LinearLayout(act);
|
127
|
layoutMid.setLayoutParams(paramsM);
|
128
|
LinearLayout layoutRight= new LinearLayout(act);
|
129
|
layoutRight.setLayoutParams(paramsR);
|
130
|
|
131
|
setupBackButton(act);
|
132
|
ObjectControl control = act.getControl();
|
133
|
mMovesController.setupButton(act,control);
|
134
|
layoutLeft.addView(mMovesController.getButton());
|
135
|
mLockController.setupButton(act,control);
|
136
|
layoutMid.addView(mLockController.getButton());
|
137
|
|
138
|
layoutRight.addView(mBackButton);
|
139
|
|
140
|
LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
|
141
|
layoutLower.removeAllViews();
|
142
|
layoutLower.addView(layoutLeft);
|
143
|
layoutLower.addView(layoutMid);
|
144
|
layoutLower.addView(layoutRight);
|
145
|
|
146
|
setupSolveButton(act);
|
147
|
setupScrambleButton(act);
|
148
|
|
149
|
LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
|
150
|
|
151
|
LinearLayout layoutLeftU = new LinearLayout(act);
|
152
|
layoutLeftU.setLayoutParams(paramsL);
|
153
|
LinearLayout layoutMidU = new LinearLayout(act);
|
154
|
layoutMidU.setLayoutParams(paramsM);
|
155
|
LinearLayout layoutRightU= new LinearLayout(act);
|
156
|
layoutRightU.setLayoutParams(paramsR);
|
157
|
|
158
|
layoutLeftU.addView(mSolveButton);
|
159
|
layoutRightU.addView(mScrambleButton);
|
160
|
|
161
|
layoutUpper.removeAllViews();
|
162
|
layoutUpper.addView(layoutLeftU);
|
163
|
layoutUpper.addView(layoutMidU);
|
164
|
layoutUpper.addView(layoutRightU);
|
165
|
}
|
166
|
|
167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168
|
|
169
|
public void setLockState(final BandagedPlayActivity act)
|
170
|
{
|
171
|
boolean locked = act.getControl().retLocked();
|
172
|
mLockController.setState(act,locked);
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
|
177
|
public void reddenLock(final BandagedPlayActivity act)
|
178
|
{
|
179
|
ObjectControl control = act.getControl();
|
180
|
mLockController.reddenLock(act,control);
|
181
|
}
|
182
|
|
183
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
184
|
|
185
|
public void addMove(Activity act, int axis, int row, int angle)
|
186
|
{
|
187
|
mMovesController.addMove(act,axis,row,angle);
|
188
|
}
|
189
|
|
190
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
191
|
|
192
|
public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
|
193
|
{
|
194
|
mMovesController.savePreferences(mKey,editor);
|
195
|
ObjectControl control = act.getControl();
|
196
|
control.savePreferences(editor);
|
197
|
}
|
198
|
|
199
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200
|
|
201
|
public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
|
202
|
{
|
203
|
mMovesController.restorePreferences(act,mKey,preferences);
|
204
|
ObjectControl control = act.getControl();
|
205
|
control.restorePreferences(preferences);
|
206
|
}
|
207
|
}
|