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