1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2023 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.patternui;
|
11
|
|
12
|
import android.content.SharedPreferences;
|
13
|
import android.os.Bundle;
|
14
|
import android.util.TypedValue;
|
15
|
import android.view.Gravity;
|
16
|
import android.view.LayoutInflater;
|
17
|
import android.view.View;
|
18
|
import android.widget.LinearLayout;
|
19
|
import android.widget.TextView;
|
20
|
|
21
|
import org.distorted.dialogs.RubikDialogError;
|
22
|
import org.distorted.dialogs.RubikDialogPatternSingle;
|
23
|
import org.distorted.helpers.TransparentImageButton;
|
24
|
import org.distorted.main.R;
|
25
|
import org.distorted.objectlib.main.ObjectControl;
|
26
|
import org.distorted.objectlib.patterns.RubikPattern;
|
27
|
import org.distorted.objects.RubikObjectList;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
public class ScreenPattern extends ScreenAbstract
|
32
|
{
|
33
|
private TextView mText;
|
34
|
private TransparentImageButton mPrevButton, mNextButton, mBackButton;
|
35
|
private TextView mMovesText;
|
36
|
private int mNumMoves;
|
37
|
private int mPatternOrdinal, mCategory, mPattern;
|
38
|
private float mButtonSize;
|
39
|
|
40
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41
|
|
42
|
ScreenPattern()
|
43
|
{
|
44
|
|
45
|
}
|
46
|
|
47
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
|
49
|
void leaveScreen(PatternActivity act)
|
50
|
{
|
51
|
|
52
|
}
|
53
|
|
54
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55
|
|
56
|
void enterScreen(final PatternActivity act)
|
57
|
{
|
58
|
float width = act.getScreenWidthInPixels();
|
59
|
mButtonSize = width*PatternActivity.BUTTON_TEXT_SIZE;
|
60
|
float titleSize = width*PatternActivity.TITLE_TEXT_SIZE;
|
61
|
LayoutInflater inflater = act.getLayoutInflater();
|
62
|
|
63
|
mPatternOrdinal = -1;
|
64
|
mCategory = -1;
|
65
|
mPattern = -1;
|
66
|
|
67
|
// TOP ////////////////////////////
|
68
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
69
|
layoutTop.removeAllViews();
|
70
|
mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null);
|
71
|
mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
72
|
mText.setText(R.string.patterns);
|
73
|
layoutTop.addView(mText);
|
74
|
|
75
|
// BOT ////////////////////////////
|
76
|
LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
|
77
|
layoutBot.removeAllViews();
|
78
|
|
79
|
setupPrevButton(act);
|
80
|
setupNextButton(act);
|
81
|
setupTextView(act,width);
|
82
|
|
83
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT);
|
84
|
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT);
|
85
|
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT);
|
86
|
|
87
|
LinearLayout layoutLeft = new LinearLayout(act);
|
88
|
layoutLeft.setLayoutParams(paramsL);
|
89
|
LinearLayout layoutMid = new LinearLayout(act);
|
90
|
layoutMid.setLayoutParams(paramsM);
|
91
|
LinearLayout layoutRight = new LinearLayout(act);
|
92
|
layoutRight.setLayoutParams(paramsR);
|
93
|
|
94
|
layoutLeft.addView(mPrevButton);
|
95
|
layoutLeft.addView(mMovesText);
|
96
|
layoutLeft.addView(mNextButton);
|
97
|
|
98
|
setupBackButton(act);
|
99
|
|
100
|
layoutRight.addView(mBackButton);
|
101
|
|
102
|
layoutBot.addView(layoutLeft);
|
103
|
layoutBot.addView(layoutMid);
|
104
|
layoutBot.addView(layoutRight);
|
105
|
|
106
|
Bundle bundle = new Bundle();
|
107
|
bundle.putString("argument",RubikObjectList.getCurrentName());
|
108
|
RubikDialogPatternSingle diag = new RubikDialogPatternSingle();
|
109
|
diag.setArguments(bundle);
|
110
|
diag.show( act.getSupportFragmentManager(), RubikDialogPatternSingle.getDialogTag() );
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
private void setupBackButton(final PatternActivity act)
|
116
|
{
|
117
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
118
|
mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params);
|
119
|
|
120
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
121
|
{
|
122
|
@Override
|
123
|
public void onClick(View v)
|
124
|
{
|
125
|
ScreenList.goBack(act);
|
126
|
}
|
127
|
});
|
128
|
}
|
129
|
|
130
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131
|
|
132
|
private void setupPrevButton(final PatternActivity act)
|
133
|
{
|
134
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
135
|
mPrevButton = new TransparentImageButton(act,R.drawable.ui_left,params);
|
136
|
|
137
|
mPrevButton.setOnClickListener( new View.OnClickListener()
|
138
|
{
|
139
|
@Override
|
140
|
public void onClick(View v)
|
141
|
{
|
142
|
RubikPattern pattern = RubikPattern.getInstance();
|
143
|
ObjectControl control = act.getControl();
|
144
|
pattern.backMove( control, mPatternOrdinal, mCategory, mPattern);
|
145
|
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
146
|
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
|
147
|
}
|
148
|
});
|
149
|
}
|
150
|
|
151
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
152
|
|
153
|
private void setupNextButton(final PatternActivity act)
|
154
|
{
|
155
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
156
|
mNextButton = new TransparentImageButton(act,R.drawable.ui_right,params);
|
157
|
|
158
|
mNextButton.setOnClickListener( new View.OnClickListener()
|
159
|
{
|
160
|
@Override
|
161
|
public void onClick(View v)
|
162
|
{
|
163
|
RubikPattern pattern = RubikPattern.getInstance();
|
164
|
ObjectControl control = act.getControl();
|
165
|
pattern.makeMove( control, mPatternOrdinal, mCategory, mPattern);
|
166
|
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
167
|
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
|
168
|
}
|
169
|
});
|
170
|
}
|
171
|
|
172
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
173
|
|
174
|
private void setupTextView(final PatternActivity act, final float width)
|
175
|
{
|
176
|
int padding = (int)(width*PatternActivity.PADDING);
|
177
|
int margin = (int)(width*PatternActivity.SMALL_MARGIN);
|
178
|
|
179
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f);
|
180
|
params.topMargin = margin;
|
181
|
params.bottomMargin = margin;
|
182
|
params.leftMargin = margin;
|
183
|
params.rightMargin = margin;
|
184
|
|
185
|
mMovesText = new TextView(act);
|
186
|
mMovesText.setTextSize(20);
|
187
|
mMovesText.setLayoutParams(params);
|
188
|
mMovesText.setPadding(padding,0,padding,0);
|
189
|
mMovesText.setGravity(Gravity.CENTER);
|
190
|
mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
|
191
|
mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));
|
192
|
}
|
193
|
|
194
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
195
|
|
196
|
public void setPattern(final PatternActivity act, int ordinal, int category, int pattern)
|
197
|
{
|
198
|
mPatternOrdinal = ordinal;
|
199
|
mCategory = category;
|
200
|
mPattern = pattern;
|
201
|
|
202
|
RubikPattern patt = RubikPattern.getInstance();
|
203
|
String patternName = patt.getPatternName(ordinal,category,pattern);
|
204
|
mText.setText(patternName);
|
205
|
|
206
|
mNumMoves = patt.getNumMoves(ordinal,category,pattern);
|
207
|
int currMove= patt.getCurMove(ordinal,category,pattern);
|
208
|
|
209
|
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
|
210
|
}
|
211
|
|
212
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
213
|
|
214
|
public void savePreferences(SharedPreferences.Editor editor)
|
215
|
{
|
216
|
|
217
|
}
|
218
|
|
219
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
220
|
|
221
|
public void restorePreferences(SharedPreferences preferences)
|
222
|
{
|
223
|
|
224
|
}
|
225
|
}
|