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.util.TypedValue;
|
24
|
import android.view.LayoutInflater;
|
25
|
import android.view.View;
|
26
|
import android.widget.ImageButton;
|
27
|
import android.widget.LinearLayout;
|
28
|
import android.widget.TextView;
|
29
|
|
30
|
import org.distorted.main.R;
|
31
|
import org.distorted.main.RubikActivity;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class RubikStateReady extends RubikStateAbstract
|
36
|
{
|
37
|
private ImageButton mPrevButton, mLockButton, mBackButton;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
void leaveState(RubikActivity act)
|
42
|
{
|
43
|
|
44
|
}
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
void enterState(final RubikActivity act)
|
49
|
{
|
50
|
float width = act.getScreenWidthInPixels();
|
51
|
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE;
|
52
|
|
53
|
LayoutInflater inflater = act.getLayoutInflater();
|
54
|
|
55
|
// TOP ////////////////////////////
|
56
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
57
|
layoutTop.removeAllViews();
|
58
|
TextView label = (TextView)inflater.inflate(R.layout.upper_text, null);
|
59
|
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
60
|
label.setText(R.string.ready);
|
61
|
layoutTop.addView(label);
|
62
|
|
63
|
// BOT ////////////////////////////
|
64
|
LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
|
65
|
layoutBot.removeAllViews();
|
66
|
|
67
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
|
68
|
|
69
|
LinearLayout layoutLeft = new LinearLayout(act);
|
70
|
layoutLeft.setLayoutParams(paramsL);
|
71
|
LinearLayout layoutMid = new LinearLayout(act);
|
72
|
layoutMid.setLayoutParams(paramsL);
|
73
|
LinearLayout layoutRight = new LinearLayout(act);
|
74
|
layoutRight.setLayoutParams(paramsL);
|
75
|
|
76
|
setupPrevButtom(act,width);
|
77
|
layoutLeft.addView(mPrevButton);
|
78
|
setupLockButton(act,width);
|
79
|
layoutMid.addView(mLockButton);
|
80
|
setupBackButton(act,width);
|
81
|
layoutRight.addView(mBackButton);
|
82
|
|
83
|
layoutBot.addView(layoutLeft);
|
84
|
layoutBot.addView(layoutMid);
|
85
|
layoutBot.addView(layoutRight);
|
86
|
}
|
87
|
|
88
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89
|
|
90
|
private void setupBackButton(final RubikActivity act, float width)
|
91
|
{
|
92
|
int padding = (int)(width*RubikActivity.PADDING);
|
93
|
int margin = (int)(width*RubikActivity.MARGIN);
|
94
|
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);
|
95
|
|
96
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
97
|
params.topMargin = margin;
|
98
|
params.bottomMargin = margin;
|
99
|
params.leftMargin = margin;
|
100
|
params.rightMargin = margin;
|
101
|
|
102
|
mBackButton = new ImageButton(act);
|
103
|
mBackButton.setLayoutParams(params);
|
104
|
mBackButton.setPadding(padding,0,padding,0);
|
105
|
mBackButton.setImageResource(icon);
|
106
|
|
107
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
108
|
{
|
109
|
@Override
|
110
|
public void onClick(View v)
|
111
|
{
|
112
|
RubikState.goBack(act);
|
113
|
}
|
114
|
});
|
115
|
}
|
116
|
|
117
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118
|
|
119
|
private void setupLockButton(final RubikActivity act, final float width)
|
120
|
{
|
121
|
int padding = (int)(width*RubikActivity.PADDING);
|
122
|
int margin = (int)(width*RubikActivity.MARGIN);
|
123
|
|
124
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
125
|
params.topMargin = margin;
|
126
|
params.bottomMargin = margin;
|
127
|
params.leftMargin = margin;
|
128
|
params.rightMargin = margin;
|
129
|
|
130
|
mLockButton = new ImageButton(act);
|
131
|
mLockButton.setLayoutParams(params);
|
132
|
mLockButton.setPadding(padding,0,padding,0);
|
133
|
mLockButton.setImageResource(getLockIcon(act));
|
134
|
|
135
|
mLockButton.setOnClickListener( new View.OnClickListener()
|
136
|
{
|
137
|
@Override
|
138
|
public void onClick(View v)
|
139
|
{
|
140
|
toggleLock(act);
|
141
|
}
|
142
|
});
|
143
|
}
|
144
|
|
145
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146
|
|
147
|
private void setupPrevButtom(final RubikActivity act, float width)
|
148
|
{
|
149
|
int padding = (int)(width*RubikActivity.PADDING);
|
150
|
int margin = (int)(width*RubikActivity.MARGIN);
|
151
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back);
|
152
|
|
153
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
154
|
params.topMargin = margin;
|
155
|
params.bottomMargin = margin;
|
156
|
params.leftMargin = margin;
|
157
|
params.rightMargin = margin;
|
158
|
|
159
|
mPrevButton = new ImageButton(act);
|
160
|
mPrevButton.setLayoutParams(params);
|
161
|
mPrevButton.setPadding(padding,0,padding,0);
|
162
|
mPrevButton.setImageResource(icon);
|
163
|
|
164
|
mPrevButton.setOnClickListener( new View.OnClickListener()
|
165
|
{
|
166
|
@Override
|
167
|
public void onClick(View v)
|
168
|
{
|
169
|
// empty
|
170
|
}
|
171
|
});
|
172
|
}
|
173
|
|
174
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
private void toggleLock(RubikActivity act)
|
177
|
{
|
178
|
act.toggleLock();
|
179
|
mLockButton.setImageResource(getLockIcon(act));
|
180
|
}
|
181
|
|
182
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
183
|
|
184
|
private int getLockIcon(RubikActivity act)
|
185
|
{
|
186
|
if( act.retLocked() )
|
187
|
{
|
188
|
return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked);
|
189
|
}
|
190
|
else
|
191
|
{
|
192
|
return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked);
|
193
|
}
|
194
|
}
|
195
|
|
196
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
197
|
|
198
|
public void savePreferences(SharedPreferences.Editor editor)
|
199
|
{
|
200
|
|
201
|
}
|
202
|
|
203
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
204
|
|
205
|
public void restorePreferences(SharedPreferences preferences)
|
206
|
{
|
207
|
|
208
|
}
|
209
|
}
|