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.DisplayMetrics;
|
24
|
import android.view.Gravity;
|
25
|
import android.view.LayoutInflater;
|
26
|
import android.view.View;
|
27
|
import android.widget.Button;
|
28
|
import android.widget.ImageButton;
|
29
|
import android.widget.LinearLayout;
|
30
|
import android.widget.TextView;
|
31
|
|
32
|
import org.distorted.main.R;
|
33
|
import org.distorted.main.RubikActivity;
|
34
|
import org.distorted.objects.RubikObject;
|
35
|
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
|
38
|
public class RubikStateSolution extends RubikStateAbstract
|
39
|
{
|
40
|
private Button mBackButton;
|
41
|
private ImageButton mPrevButton, mNextButton;
|
42
|
private TextView mMovesText;
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
void leaveState(RubikActivity act)
|
47
|
{
|
48
|
RubikObject object = act.getObject();
|
49
|
object.solve();
|
50
|
}
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
void enterState(final RubikActivity act)
|
55
|
{
|
56
|
DisplayMetrics metrics = act.getResources().getDisplayMetrics();
|
57
|
final float scale = metrics.density;
|
58
|
LayoutInflater inflater = act.getLayoutInflater();
|
59
|
|
60
|
// TOP ////////////////////////////
|
61
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
62
|
layoutTop.removeAllViews();
|
63
|
|
64
|
final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
|
65
|
text.setText(R.string.solution);
|
66
|
layoutTop.addView(text);
|
67
|
|
68
|
// BOT ////////////////////////////
|
69
|
if( mPrevButton==null ) setupPrevButton(act,scale);
|
70
|
if( mNextButton==null ) setupNextButton(act,scale);
|
71
|
if( mMovesText ==null ) setupTextView(act,scale);
|
72
|
|
73
|
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
|
74
|
layoutLeft.removeAllViews();
|
75
|
layoutLeft.addView(mPrevButton);
|
76
|
layoutLeft.addView(mMovesText);
|
77
|
layoutLeft.addView(mNextButton);
|
78
|
|
79
|
if( mBackButton==null ) setupBackButton(act,scale);
|
80
|
|
81
|
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
|
82
|
layoutRight.removeAllViews();
|
83
|
layoutRight.addView(mBackButton);
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
private void setupPrevButton(final RubikActivity act, final float scale)
|
89
|
{
|
90
|
int padding = (int)(3*scale + 0.5f);
|
91
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
92
|
mPrevButton = new ImageButton(act);
|
93
|
mPrevButton.setLayoutParams(params);
|
94
|
mPrevButton.setPadding(padding,0,padding,0);
|
95
|
mPrevButton.setImageResource(R.drawable.left);
|
96
|
|
97
|
mPrevButton.setOnClickListener( new View.OnClickListener()
|
98
|
{
|
99
|
@Override
|
100
|
public void onClick(View v)
|
101
|
{
|
102
|
|
103
|
}
|
104
|
});
|
105
|
}
|
106
|
|
107
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108
|
|
109
|
private void setupNextButton(final RubikActivity act, final float scale)
|
110
|
{
|
111
|
int padding = (int)( 3*scale + 0.5f);
|
112
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
|
113
|
mNextButton = new ImageButton(act);
|
114
|
mNextButton.setLayoutParams(params);
|
115
|
mNextButton.setPadding(padding,0,padding,0);
|
116
|
mNextButton.setImageResource(R.drawable.right);
|
117
|
|
118
|
mNextButton.setOnClickListener( new View.OnClickListener()
|
119
|
{
|
120
|
@Override
|
121
|
public void onClick(View v)
|
122
|
{
|
123
|
|
124
|
}
|
125
|
});
|
126
|
}
|
127
|
|
128
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129
|
|
130
|
private void setupTextView(final RubikActivity act, final float scale)
|
131
|
{
|
132
|
int padding = (int)( 3*scale + 0.5f);
|
133
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f);
|
134
|
|
135
|
mMovesText = new TextView(act);
|
136
|
mMovesText.setTextSize(20);
|
137
|
mMovesText.setLayoutParams(params);
|
138
|
mMovesText.setPadding(padding,0,padding,0);
|
139
|
mMovesText.setGravity(Gravity.CENTER);
|
140
|
mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));
|
141
|
}
|
142
|
|
143
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144
|
|
145
|
private void setupBackButton(final RubikActivity act, final float scale)
|
146
|
{
|
147
|
int padding = (int)(3*scale + 0.5f);
|
148
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
149
|
mBackButton = new Button(act);
|
150
|
mBackButton.setLayoutParams(backParams);
|
151
|
mBackButton.setPadding(padding,0,padding,0);
|
152
|
mBackButton.setText(R.string.back);
|
153
|
|
154
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
155
|
{
|
156
|
@Override
|
157
|
public void onClick(View v)
|
158
|
{
|
159
|
RubikState.goBack(act);
|
160
|
}
|
161
|
});
|
162
|
}
|
163
|
|
164
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165
|
|
166
|
public void savePreferences(SharedPreferences.Editor editor)
|
167
|
{
|
168
|
mBackButton= null;
|
169
|
mPrevButton= null;
|
170
|
mNextButton= null;
|
171
|
mMovesText = null;
|
172
|
}
|
173
|
|
174
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
public void restorePreferences(SharedPreferences preferences)
|
177
|
{
|
178
|
|
179
|
}
|
180
|
}
|