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 |
|
|
import android.widget.LinearLayout;
|
30 |
|
|
import android.widget.TextView;
|
31 |
|
|
|
32 |
e108b57e
|
Leszek Koltunski
|
import org.distorted.dialog.RubikDialogPattern;
|
33 |
4f470e00
|
Leszek Koltunski
|
import org.distorted.magic.R;
|
34 |
|
|
import org.distorted.magic.RubikActivity;
|
35 |
53f23b64
|
Leszek Koltunski
|
import org.distorted.object.RubikObjectList;
|
36 |
|
|
import org.distorted.patterns.RubikPattern;
|
37 |
4f470e00
|
Leszek Koltunski
|
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
|
|
public class RubikStatePattern extends RubikStateAbstract
|
41 |
|
|
{
|
42 |
e0e84674
|
Leszek Koltunski
|
// TODO: read this from upper_text.xml; this is the height of the TextView there.
|
43 |
|
|
private static final int DEFAULT_TEXT_SIZE = 30;
|
44 |
|
|
|
45 |
3a9d19ed
|
Leszek Koltunski
|
private TextView mText;
|
46 |
53f23b64
|
Leszek Koltunski
|
private Button mBackButton;
|
47 |
|
|
private int mSize;
|
48 |
4f470e00
|
Leszek Koltunski
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
|
|
RubikStatePattern()
|
52 |
|
|
{
|
53 |
|
|
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
|
|
void leaveState(RubikActivity act)
|
59 |
|
|
{
|
60 |
53f23b64
|
Leszek Koltunski
|
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
61 |
|
|
|
62 |
|
|
if( !play.setObjectAndSize(RubikObjectList.CUBE, mSize) )
|
63 |
|
|
{
|
64 |
|
|
int object= play.getObject();
|
65 |
|
|
int size = play.getSize();
|
66 |
|
|
|
67 |
|
|
act.changeObject(RubikObjectList.getObject(object),size);
|
68 |
|
|
}
|
69 |
4f470e00
|
Leszek Koltunski
|
}
|
70 |
|
|
|
71 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72 |
|
|
|
73 |
a6d3b158
|
Leszek Koltunski
|
void enterState(final RubikActivity act)
|
74 |
4f470e00
|
Leszek Koltunski
|
{
|
75 |
53f23b64
|
Leszek Koltunski
|
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
76 |
|
|
int obj = play.getObject();
|
77 |
|
|
int size = play.getSize();
|
78 |
|
|
|
79 |
|
|
if( size>=RubikPattern.MIN_CUBE && size<=RubikPattern.MAX_CUBE && obj==RubikObjectList.CUBE.ordinal() )
|
80 |
|
|
{
|
81 |
|
|
mSize = size;
|
82 |
|
|
}
|
83 |
|
|
else
|
84 |
|
|
{
|
85 |
|
|
mSize = RubikStatePlay.DEF_SIZE;
|
86 |
|
|
act.changeObject(RubikObjectList.CUBE,mSize);
|
87 |
|
|
}
|
88 |
a6d3b158
|
Leszek Koltunski
|
|
89 |
e108b57e
|
Leszek Koltunski
|
FragmentManager mana = act.getSupportFragmentManager();
|
90 |
|
|
RubikDialogPattern diag = (RubikDialogPattern) mana.findFragmentByTag(RubikDialogPattern.getDialogTag());
|
91 |
|
|
|
92 |
|
|
if( diag==null ) showDialog(mana);
|
93 |
|
|
|
94 |
4f470e00
|
Leszek Koltunski
|
LayoutInflater inflater = act.getLayoutInflater();
|
95 |
|
|
|
96 |
|
|
// TOP ////////////////////////////
|
97 |
|
|
LinearLayout layoutTop = act.findViewById(R.id.mainTitle);
|
98 |
|
|
layoutTop.removeAllViews();
|
99 |
3a9d19ed
|
Leszek Koltunski
|
mText = (TextView)inflater.inflate(R.layout.upper_text, null);
|
100 |
|
|
mText.setText(R.string.patterns);
|
101 |
|
|
layoutTop.addView(mText);
|
102 |
4f470e00
|
Leszek Koltunski
|
|
103 |
|
|
// BOT ////////////////////////////
|
104 |
53f23b64
|
Leszek Koltunski
|
DisplayMetrics metrics = act.getResources().getDisplayMetrics();
|
105 |
|
|
final float scale = metrics.density;
|
106 |
|
|
|
107 |
|
|
if( mBackButton==null ) setupBackButton(act,scale);
|
108 |
|
|
|
109 |
4f470e00
|
Leszek Koltunski
|
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
|
110 |
|
|
layoutRight.removeAllViews();
|
111 |
53f23b64
|
Leszek Koltunski
|
layoutRight.addView(mBackButton);
|
112 |
|
|
}
|
113 |
4f470e00
|
Leszek Koltunski
|
|
114 |
53f23b64
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115 |
a6d3b158
|
Leszek Koltunski
|
|
116 |
e108b57e
|
Leszek Koltunski
|
private void showDialog(FragmentManager manager)
|
117 |
53f23b64
|
Leszek Koltunski
|
{
|
118 |
e108b57e
|
Leszek Koltunski
|
Bundle bundle = new Bundle();
|
119 |
|
|
int object = RubikObjectList.CUBE.ordinal();
|
120 |
|
|
int sizeIndex = RubikObjectList.getSizeIndex(object,mSize);
|
121 |
|
|
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) );
|
122 |
|
|
|
123 |
|
|
RubikDialogPattern diag = new RubikDialogPattern();
|
124 |
|
|
diag.setArguments(bundle);
|
125 |
|
|
diag.show( manager, RubikDialogPattern.getDialogTag() );
|
126 |
53f23b64
|
Leszek Koltunski
|
}
|
127 |
|
|
|
128 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
|
|
|
130 |
|
|
private void setupBackButton(final RubikActivity act, final float scale)
|
131 |
|
|
{
|
132 |
|
|
int padding = (int)(3*scale + 0.5f);
|
133 |
|
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
134 |
|
|
mBackButton = new Button(act);
|
135 |
|
|
mBackButton.setLayoutParams(backParams);
|
136 |
|
|
mBackButton.setId(BUTTON_ID_BACK);
|
137 |
|
|
mBackButton.setPadding(padding,0,padding,0);
|
138 |
|
|
mBackButton.setText(R.string.back);
|
139 |
|
|
|
140 |
|
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
141 |
a6d3b158
|
Leszek Koltunski
|
{
|
142 |
|
|
@Override
|
143 |
|
|
public void onClick(View v)
|
144 |
|
|
{
|
145 |
e108b57e
|
Leszek Koltunski
|
FragmentManager mana = act.getSupportFragmentManager();
|
146 |
|
|
RubikDialogPattern diag = (RubikDialogPattern) mana.findFragmentByTag(RubikDialogPattern.getDialogTag());
|
147 |
53f23b64
|
Leszek Koltunski
|
|
148 |
e108b57e
|
Leszek Koltunski
|
if( diag==null )
|
149 |
53f23b64
|
Leszek Koltunski
|
{
|
150 |
e0e84674
|
Leszek Koltunski
|
mText.setTextSize(DEFAULT_TEXT_SIZE);
|
151 |
|
|
mText.setText(R.string.patterns);
|
152 |
e108b57e
|
Leszek Koltunski
|
showDialog(mana);
|
153 |
53f23b64
|
Leszek Koltunski
|
}
|
154 |
e108b57e
|
Leszek Koltunski
|
else
|
155 |
|
|
{
|
156 |
044529c1
|
Leszek Koltunski
|
diag.rememberCategories();
|
157 |
e108b57e
|
Leszek Koltunski
|
diag.dismiss();
|
158 |
|
|
RubikState.goBack(act);
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
});
|
162 |
4f470e00
|
Leszek Koltunski
|
}
|
163 |
|
|
|
164 |
3a9d19ed
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165 |
|
|
|
166 |
e0e84674
|
Leszek Koltunski
|
public void setPattern(int sizeIndex, int category, int pattern)
|
167 |
3a9d19ed
|
Leszek Koltunski
|
{
|
168 |
044529c1
|
Leszek Koltunski
|
mSize = RubikObjectList.CUBE.getSizes()[sizeIndex];
|
169 |
|
|
|
170 |
e0e84674
|
Leszek Koltunski
|
RubikPattern patt = RubikPattern.getInstance();
|
171 |
|
|
String patternName = patt.getPatternName(sizeIndex,category,pattern);
|
172 |
|
|
mText.setText(patternName);
|
173 |
3a9d19ed
|
Leszek Koltunski
|
}
|
174 |
|
|
|
175 |
4f470e00
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176 |
|
|
|
177 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
178 |
|
|
{
|
179 |
53f23b64
|
Leszek Koltunski
|
mBackButton= null;
|
180 |
4f470e00
|
Leszek Koltunski
|
}
|
181 |
|
|
|
182 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
183 |
|
|
|
184 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
185 |
|
|
{
|
186 |
|
|
|
187 |
|
|
}
|
188 |
|
|
}
|