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