1 |
4f470e00
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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.uistate;
|
21 |
|
|
|
22 |
|
|
import android.content.SharedPreferences;
|
23 |
e108b57e
|
Leszek Koltunski
|
import android.os.Bundle;
|
24 |
|
|
import android.support.v4.app.FragmentManager;
|
25 |
4f470e00
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
26 |
|
|
import android.view.LayoutInflater;
|
27 |
a6d3b158
|
Leszek Koltunski
|
import android.view.View;
|
28 |
4f470e00
|
Leszek Koltunski
|
import android.widget.Button;
|
29 |
0a57000c
|
Leszek Koltunski
|
import android.widget.ImageButton;
|
30 |
4f470e00
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
31 |
|
|
import android.widget.TextView;
|
32 |
|
|
|
33 |
e108b57e
|
Leszek Koltunski
|
import org.distorted.dialog.RubikDialogPattern;
|
34 |
4f470e00
|
Leszek Koltunski
|
import org.distorted.magic.R;
|
35 |
|
|
import org.distorted.magic.RubikActivity;
|
36 |
53f23b64
|
Leszek Koltunski
|
import org.distorted.object.RubikObjectList;
|
37 |
|
|
import org.distorted.patterns.RubikPattern;
|
38 |
4f470e00
|
Leszek Koltunski
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
|
|
public class RubikStatePattern extends RubikStateAbstract
|
42 |
|
|
{
|
43 |
e0e84674
|
Leszek Koltunski
|
// TODO: read this from upper_text.xml; this is the height of the TextView there.
|
44 |
|
|
private static final int DEFAULT_TEXT_SIZE = 30;
|
45 |
|
|
|
46 |
3a9d19ed
|
Leszek Koltunski
|
private TextView mText;
|
47 |
53f23b64
|
Leszek Koltunski
|
private Button mBackButton;
|
48 |
0a57000c
|
Leszek Koltunski
|
private ImageButton mPrevButton, mNextButton;
|
49 |
|
|
private TextView mMovesText;
|
50 |
53f23b64
|
Leszek Koltunski
|
private int mSize;
|
51 |
4f470e00
|
Leszek Koltunski
|
|
52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53 |
|
|
|
54 |
|
|
RubikStatePattern()
|
55 |
|
|
{
|
56 |
|
|
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60 |
|
|
|
61 |
|
|
void leaveState(RubikActivity act)
|
62 |
|
|
{
|
63 |
53f23b64
|
Leszek Koltunski
|
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
64 |
|
|
|
65 |
|
|
if( !play.setObjectAndSize(RubikObjectList.CUBE, mSize) )
|
66 |
|
|
{
|
67 |
|
|
int object= play.getObject();
|
68 |
|
|
int size = play.getSize();
|
69 |
|
|
|
70 |
|
|
act.changeObject(RubikObjectList.getObject(object),size);
|
71 |
|
|
}
|
72 |
4f470e00
|
Leszek Koltunski
|
}
|
73 |
|
|
|
74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75 |
|
|
|
76 |
a6d3b158
|
Leszek Koltunski
|
void enterState(final RubikActivity act)
|
77 |
4f470e00
|
Leszek Koltunski
|
{
|
78 |
53f23b64
|
Leszek Koltunski
|
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
79 |
|
|
int obj = play.getObject();
|
80 |
|
|
int size = play.getSize();
|
81 |
|
|
|
82 |
|
|
if( size>=RubikPattern.MIN_CUBE && size<=RubikPattern.MAX_CUBE && obj==RubikObjectList.CUBE.ordinal() )
|
83 |
|
|
{
|
84 |
|
|
mSize = size;
|
85 |
|
|
}
|
86 |
|
|
else
|
87 |
|
|
{
|
88 |
|
|
mSize = RubikStatePlay.DEF_SIZE;
|
89 |
|
|
act.changeObject(RubikObjectList.CUBE,mSize);
|
90 |
|
|
}
|
91 |
a6d3b158
|
Leszek Koltunski
|
|
92 |
e108b57e
|
Leszek Koltunski
|
FragmentManager mana = act.getSupportFragmentManager();
|
93 |
|
|
RubikDialogPattern diag = (RubikDialogPattern) mana.findFragmentByTag(RubikDialogPattern.getDialogTag());
|
94 |
|
|
|
95 |
|
|
if( diag==null ) showDialog(mana);
|
96 |
|
|
|
97 |
4f470e00
|
Leszek Koltunski
|
LayoutInflater inflater = act.getLayoutInflater();
|
98 |
|
|
|
99 |
|
|
// TOP ////////////////////////////
|
100 |
|
|
LinearLayout layoutTop = act.findViewById(R.id.mainTitle);
|
101 |
|
|
layoutTop.removeAllViews();
|
102 |
3a9d19ed
|
Leszek Koltunski
|
mText = (TextView)inflater.inflate(R.layout.upper_text, null);
|
103 |
|
|
mText.setText(R.string.patterns);
|
104 |
|
|
layoutTop.addView(mText);
|
105 |
4f470e00
|
Leszek Koltunski
|
|
106 |
|
|
// BOT ////////////////////////////
|
107 |
53f23b64
|
Leszek Koltunski
|
DisplayMetrics metrics = act.getResources().getDisplayMetrics();
|
108 |
|
|
final float scale = metrics.density;
|
109 |
|
|
|
110 |
0a57000c
|
Leszek Koltunski
|
if( mPrevButton==null ) setupPrevButton(act,scale);
|
111 |
|
|
if( mNextButton==null ) setupNextButton(act,scale);
|
112 |
|
|
if( mMovesText ==null ) setupTextView(act,scale);
|
113 |
|
|
|
114 |
|
|
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
|
115 |
|
|
layoutLeft.removeAllViews();
|
116 |
|
|
layoutLeft.addView(mPrevButton);
|
117 |
|
|
layoutLeft.addView(mMovesText);
|
118 |
|
|
layoutLeft.addView(mNextButton);
|
119 |
|
|
|
120 |
53f23b64
|
Leszek Koltunski
|
if( mBackButton==null ) setupBackButton(act,scale);
|
121 |
|
|
|
122 |
4f470e00
|
Leszek Koltunski
|
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
|
123 |
|
|
layoutRight.removeAllViews();
|
124 |
53f23b64
|
Leszek Koltunski
|
layoutRight.addView(mBackButton);
|
125 |
|
|
}
|
126 |
4f470e00
|
Leszek Koltunski
|
|
127 |
53f23b64
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128 |
a6d3b158
|
Leszek Koltunski
|
|
129 |
e108b57e
|
Leszek Koltunski
|
private void showDialog(FragmentManager manager)
|
130 |
53f23b64
|
Leszek Koltunski
|
{
|
131 |
e108b57e
|
Leszek Koltunski
|
Bundle bundle = new Bundle();
|
132 |
|
|
int object = RubikObjectList.CUBE.ordinal();
|
133 |
|
|
int sizeIndex = RubikObjectList.getSizeIndex(object,mSize);
|
134 |
|
|
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) );
|
135 |
|
|
|
136 |
|
|
RubikDialogPattern diag = new RubikDialogPattern();
|
137 |
|
|
diag.setArguments(bundle);
|
138 |
|
|
diag.show( manager, RubikDialogPattern.getDialogTag() );
|
139 |
53f23b64
|
Leszek Koltunski
|
}
|
140 |
|
|
|
141 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142 |
|
|
|
143 |
|
|
private void setupBackButton(final RubikActivity act, final float scale)
|
144 |
|
|
{
|
145 |
|
|
int padding = (int)(3*scale + 0.5f);
|
146 |
|
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
147 |
|
|
mBackButton = new Button(act);
|
148 |
|
|
mBackButton.setLayoutParams(backParams);
|
149 |
|
|
mBackButton.setPadding(padding,0,padding,0);
|
150 |
|
|
mBackButton.setText(R.string.back);
|
151 |
|
|
|
152 |
|
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
153 |
a6d3b158
|
Leszek Koltunski
|
{
|
154 |
|
|
@Override
|
155 |
|
|
public void onClick(View v)
|
156 |
|
|
{
|
157 |
e108b57e
|
Leszek Koltunski
|
FragmentManager mana = act.getSupportFragmentManager();
|
158 |
|
|
RubikDialogPattern diag = (RubikDialogPattern) mana.findFragmentByTag(RubikDialogPattern.getDialogTag());
|
159 |
53f23b64
|
Leszek Koltunski
|
|
160 |
e108b57e
|
Leszek Koltunski
|
if( diag==null )
|
161 |
53f23b64
|
Leszek Koltunski
|
{
|
162 |
e0e84674
|
Leszek Koltunski
|
mText.setTextSize(DEFAULT_TEXT_SIZE);
|
163 |
|
|
mText.setText(R.string.patterns);
|
164 |
e108b57e
|
Leszek Koltunski
|
showDialog(mana);
|
165 |
53f23b64
|
Leszek Koltunski
|
}
|
166 |
e108b57e
|
Leszek Koltunski
|
else
|
167 |
|
|
{
|
168 |
044529c1
|
Leszek Koltunski
|
diag.rememberCategories();
|
169 |
e108b57e
|
Leszek Koltunski
|
diag.dismiss();
|
170 |
|
|
RubikState.goBack(act);
|
171 |
|
|
}
|
172 |
|
|
}
|
173 |
|
|
});
|
174 |
4f470e00
|
Leszek Koltunski
|
}
|
175 |
|
|
|
176 |
0a57000c
|
Leszek Koltunski
|
|
177 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178 |
|
|
|
179 |
|
|
private void setupPrevButton(final RubikActivity act, final float scale)
|
180 |
|
|
{
|
181 |
|
|
int padding = (int)(3*scale + 0.5f);
|
182 |
|
|
int length = (int)(40*scale + 0.5f);
|
183 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(length,LinearLayout.LayoutParams.MATCH_PARENT);
|
184 |
|
|
mPrevButton = new ImageButton(act);
|
185 |
|
|
mPrevButton.setLayoutParams(params);
|
186 |
|
|
mPrevButton.setPadding(padding,0,padding,0);
|
187 |
|
|
mPrevButton.setImageResource(R.drawable.left);
|
188 |
|
|
|
189 |
|
|
mPrevButton.setOnClickListener( new View.OnClickListener()
|
190 |
|
|
{
|
191 |
|
|
@Override
|
192 |
|
|
public void onClick(View v)
|
193 |
|
|
{
|
194 |
|
|
android.util.Log.e("patt", "prev button clicked!");
|
195 |
|
|
}
|
196 |
|
|
});
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200 |
|
|
|
201 |
|
|
private void setupNextButton(final RubikActivity act, final float scale)
|
202 |
|
|
{
|
203 |
|
|
int padding = (int)( 3*scale + 0.5f);
|
204 |
|
|
int length = (int)(40*scale + 0.5f);
|
205 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(length,LinearLayout.LayoutParams.MATCH_PARENT);
|
206 |
|
|
mNextButton = new ImageButton(act);
|
207 |
|
|
mNextButton.setLayoutParams(params);
|
208 |
|
|
mNextButton.setPadding(padding,0,padding,0);
|
209 |
|
|
mNextButton.setImageResource(R.drawable.right);
|
210 |
|
|
|
211 |
|
|
mNextButton.setOnClickListener( new View.OnClickListener()
|
212 |
|
|
{
|
213 |
|
|
@Override
|
214 |
|
|
public void onClick(View v)
|
215 |
|
|
{
|
216 |
|
|
android.util.Log.e("patt", "next button clicked!");
|
217 |
|
|
}
|
218 |
|
|
});
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
222 |
|
|
|
223 |
|
|
private void setupTextView(final RubikActivity act, final float scale)
|
224 |
|
|
{
|
225 |
|
|
int padding = (int)( 3*scale + 0.5f);
|
226 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
227 |
|
|
|
228 |
|
|
mMovesText = new TextView(act);
|
229 |
|
|
mMovesText.setLayoutParams(params);
|
230 |
|
|
mMovesText.setPadding(padding,0,padding,0);
|
231 |
|
|
|
232 |
|
|
mMovesText.setText("aaa");
|
233 |
|
|
}
|
234 |
|
|
|
235 |
3a9d19ed
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
236 |
|
|
|
237 |
e0e84674
|
Leszek Koltunski
|
public void setPattern(int sizeIndex, int category, int pattern)
|
238 |
3a9d19ed
|
Leszek Koltunski
|
{
|
239 |
044529c1
|
Leszek Koltunski
|
mSize = RubikObjectList.CUBE.getSizes()[sizeIndex];
|
240 |
|
|
|
241 |
e0e84674
|
Leszek Koltunski
|
RubikPattern patt = RubikPattern.getInstance();
|
242 |
|
|
String patternName = patt.getPatternName(sizeIndex,category,pattern);
|
243 |
|
|
mText.setText(patternName);
|
244 |
3a9d19ed
|
Leszek Koltunski
|
}
|
245 |
|
|
|
246 |
4f470e00
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
247 |
|
|
|
248 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
249 |
|
|
{
|
250 |
53f23b64
|
Leszek Koltunski
|
mBackButton= null;
|
251 |
0a57000c
|
Leszek Koltunski
|
mPrevButton= null;
|
252 |
|
|
mNextButton= null;
|
253 |
|
|
mMovesText = null;
|
254 |
4f470e00
|
Leszek Koltunski
|
}
|
255 |
|
|
|
256 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
257 |
|
|
|
258 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
259 |
|
|
{
|
260 |
|
|
|
261 |
|
|
}
|
262 |
|
|
}
|