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 android.os.Bundle;
|
24
|
import androidx.fragment.app.FragmentManager;
|
25
|
import android.util.TypedValue;
|
26
|
import android.view.Gravity;
|
27
|
import android.view.LayoutInflater;
|
28
|
import android.view.View;
|
29
|
import android.widget.ImageButton;
|
30
|
import android.widget.LinearLayout;
|
31
|
import android.widget.TextView;
|
32
|
|
33
|
import org.distorted.dialogs.RubikDialogPattern;
|
34
|
import org.distorted.main.R;
|
35
|
import org.distorted.main.RubikActivity;
|
36
|
import org.distorted.main.RubikPreRender;
|
37
|
import org.distorted.objects.ObjectList;
|
38
|
import org.distorted.patterns.RubikPattern;
|
39
|
import org.distorted.patterns.RubikPatternList;
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
public class RubikStatePattern extends RubikStateAbstract
|
44
|
{
|
45
|
private TextView mText;
|
46
|
private ImageButton mPrevButton, mNextButton, mBackButton;
|
47
|
private TextView mMovesText;
|
48
|
private int mNumMoves;
|
49
|
private int mPatternOrdinal, mCategory, mPattern;
|
50
|
private float mButtonSize;
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
RubikStatePattern()
|
55
|
{
|
56
|
|
57
|
}
|
58
|
|
59
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60
|
|
61
|
void leaveState(RubikActivity act)
|
62
|
{
|
63
|
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
64
|
|
65
|
ObjectList object = RubikPatternList.getObject(mPatternOrdinal);
|
66
|
int size = RubikPatternList.getSize(mPatternOrdinal);
|
67
|
|
68
|
if( !play.setObjectAndSize(act,object,size) )
|
69
|
{
|
70
|
int objectPlay= play.getObject();
|
71
|
int sizePlay = play.getSize();
|
72
|
|
73
|
act.changeObject(ObjectList.getObject(objectPlay),sizePlay, false);
|
74
|
}
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
|
79
|
void enterState(final RubikActivity act)
|
80
|
{
|
81
|
float width = act.getScreenWidthInPixels();
|
82
|
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
|
83
|
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE;
|
84
|
mPatternOrdinal = getPatternOrdinal();
|
85
|
LayoutInflater inflater = act.getLayoutInflater();
|
86
|
|
87
|
// TOP ////////////////////////////
|
88
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
89
|
layoutTop.removeAllViews();
|
90
|
mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null);
|
91
|
mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
92
|
mText.setText(R.string.patterns);
|
93
|
layoutTop.addView(mText);
|
94
|
|
95
|
// BOT ////////////////////////////
|
96
|
LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
|
97
|
layoutBot.removeAllViews();
|
98
|
|
99
|
setupPrevButton(act,width);
|
100
|
setupNextButton(act,width);
|
101
|
setupTextView(act,width);
|
102
|
|
103
|
setTrioState(false);
|
104
|
|
105
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT);
|
106
|
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT);
|
107
|
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT);
|
108
|
|
109
|
LinearLayout layoutLeft = new LinearLayout(act);
|
110
|
layoutLeft.setLayoutParams(paramsL);
|
111
|
LinearLayout layoutMid = new LinearLayout(act);
|
112
|
layoutMid.setLayoutParams(paramsM);
|
113
|
LinearLayout layoutRight = new LinearLayout(act);
|
114
|
layoutRight.setLayoutParams(paramsR);
|
115
|
|
116
|
layoutLeft.addView(mPrevButton);
|
117
|
layoutLeft.addView(mMovesText);
|
118
|
layoutLeft.addView(mNextButton);
|
119
|
|
120
|
setupBackButton(act,width);
|
121
|
|
122
|
layoutRight.addView(mBackButton);
|
123
|
|
124
|
layoutBot.addView(layoutLeft);
|
125
|
layoutBot.addView(layoutMid);
|
126
|
layoutBot.addView(layoutRight);
|
127
|
}
|
128
|
|
129
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130
|
|
131
|
private void showDialog(FragmentManager manager)
|
132
|
{
|
133
|
RubikDialogPattern diag = new RubikDialogPattern();
|
134
|
Bundle bundle = new Bundle();
|
135
|
bundle.putInt("tab", mPatternOrdinal );
|
136
|
diag.setArguments(bundle);
|
137
|
diag.show( manager, RubikDialogPattern.getDialogTag() );
|
138
|
}
|
139
|
|
140
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141
|
|
142
|
private void setTrioState(boolean enable)
|
143
|
{
|
144
|
int state = enable ? View.VISIBLE : View.INVISIBLE;
|
145
|
|
146
|
if( mPrevButton!=null ) mPrevButton.setVisibility(state);
|
147
|
if( mNextButton!=null ) mNextButton.setVisibility(state);
|
148
|
if( mMovesText !=null ) mMovesText.setVisibility(state);
|
149
|
}
|
150
|
|
151
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
152
|
|
153
|
private void setupBackButton(final RubikActivity act, final float width)
|
154
|
{
|
155
|
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back);
|
156
|
mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
|
157
|
|
158
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
159
|
{
|
160
|
@Override
|
161
|
public void onClick(View v)
|
162
|
{
|
163
|
FragmentManager mana = act.getSupportFragmentManager();
|
164
|
StateList.goBack(act);
|
165
|
showDialog(mana);
|
166
|
}
|
167
|
});
|
168
|
}
|
169
|
|
170
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171
|
|
172
|
private void setupPrevButton(final RubikActivity act, final float width)
|
173
|
{
|
174
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_left,R.drawable.ui_medium_left, R.drawable.ui_big_left, R.drawable.ui_huge_left);
|
175
|
mPrevButton = new TransparentImageButton(act,icon,width,0);
|
176
|
|
177
|
mPrevButton.setOnClickListener( new View.OnClickListener()
|
178
|
{
|
179
|
@Override
|
180
|
public void onClick(View v)
|
181
|
{
|
182
|
RubikPattern pattern = RubikPattern.getInstance();
|
183
|
RubikPreRender pre = act.getPreRender();
|
184
|
pattern.backMove( pre, mPatternOrdinal, mCategory, mPattern);
|
185
|
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
186
|
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
|
187
|
}
|
188
|
});
|
189
|
}
|
190
|
|
191
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192
|
|
193
|
private void setupNextButton(final RubikActivity act, final float width)
|
194
|
{
|
195
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_right,R.drawable.ui_medium_right, R.drawable.ui_big_right, R.drawable.ui_huge_right);
|
196
|
mNextButton = new TransparentImageButton(act,icon,width,0);
|
197
|
|
198
|
mNextButton.setOnClickListener( new View.OnClickListener()
|
199
|
{
|
200
|
@Override
|
201
|
public void onClick(View v)
|
202
|
{
|
203
|
RubikPattern pattern = RubikPattern.getInstance();
|
204
|
RubikPreRender pre = act.getPreRender();
|
205
|
pattern.makeMove( pre, mPatternOrdinal, mCategory, mPattern);
|
206
|
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
207
|
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
|
208
|
}
|
209
|
});
|
210
|
}
|
211
|
|
212
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
213
|
|
214
|
private void setupTextView(final RubikActivity act, final float width)
|
215
|
{
|
216
|
int padding = (int)(width*RubikActivity.PADDING);
|
217
|
int margin = (int)(width*RubikActivity.MARGIN);
|
218
|
|
219
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f);
|
220
|
params.topMargin = margin;
|
221
|
params.bottomMargin = margin;
|
222
|
params.leftMargin = margin;
|
223
|
params.rightMargin = margin;
|
224
|
|
225
|
mMovesText = new TextView(act);
|
226
|
mMovesText.setTextSize(20);
|
227
|
mMovesText.setLayoutParams(params);
|
228
|
mMovesText.setPadding(padding,0,padding,0);
|
229
|
mMovesText.setGravity(Gravity.CENTER);
|
230
|
mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
|
231
|
mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));
|
232
|
}
|
233
|
|
234
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
235
|
|
236
|
public void setPattern(final RubikActivity act, int ordinal, int category, int pattern)
|
237
|
{
|
238
|
mPatternOrdinal = ordinal;
|
239
|
mCategory = category;
|
240
|
mPattern = pattern;
|
241
|
|
242
|
setTrioState(true);
|
243
|
|
244
|
RubikPattern patt = RubikPattern.getInstance();
|
245
|
String patternName = patt.getPatternName(ordinal,category,pattern);
|
246
|
mText.setText(patternName);
|
247
|
|
248
|
mNumMoves = patt.getNumMoves(ordinal,category,pattern);
|
249
|
int currMove= patt.getCurMove(ordinal,category,pattern);
|
250
|
|
251
|
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
|
252
|
}
|
253
|
|
254
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
255
|
|
256
|
public void savePreferences(SharedPreferences.Editor editor)
|
257
|
{
|
258
|
|
259
|
}
|
260
|
|
261
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
262
|
|
263
|
public void restorePreferences(SharedPreferences preferences)
|
264
|
{
|
265
|
|
266
|
}
|
267
|
}
|