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