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.uistate;
|
21
|
|
22
|
import android.content.SharedPreferences;
|
23
|
import android.graphics.Bitmap;
|
24
|
import android.graphics.Canvas;
|
25
|
import android.graphics.Paint;
|
26
|
import android.util.DisplayMetrics;
|
27
|
import android.view.View;
|
28
|
import android.widget.Button;
|
29
|
import android.widget.ImageButton;
|
30
|
import android.widget.LinearLayout;
|
31
|
|
32
|
import org.distorted.magic.R;
|
33
|
import org.distorted.magic.RubikActivity;
|
34
|
import org.distorted.object.RubikObjectList;
|
35
|
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
|
38
|
public class RubikStateSolver extends RubikStateAbstract
|
39
|
{
|
40
|
private static final int NUM_FACES = 6;
|
41
|
private static final int BITMAP_SIZE = 35;
|
42
|
|
43
|
private static final int[] FACE_COLORS = new int[]
|
44
|
{
|
45
|
0xffffff00, 0xffffffff,
|
46
|
0xff0000ff, 0xff00ff00,
|
47
|
0xffff0000, 0xffb5651d
|
48
|
};
|
49
|
|
50
|
private static Bitmap[] mBitmap;
|
51
|
private ImageButton[] mColorButton;
|
52
|
private Button mBackButton;
|
53
|
|
54
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55
|
|
56
|
void leaveState(RubikActivity act)
|
57
|
{
|
58
|
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
void enterState(final RubikActivity act)
|
64
|
{
|
65
|
act.changeObject(RubikObjectList.CUBE,3,null);
|
66
|
|
67
|
DisplayMetrics metrics = act.getResources().getDisplayMetrics();
|
68
|
final float scale = metrics.density;
|
69
|
|
70
|
// TOP ////////////////////////////
|
71
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
72
|
layoutTop.removeAllViews();
|
73
|
|
74
|
if( mBitmap ==null ) setupBitmaps(scale);
|
75
|
if( mColorButton==null ) setupColorButtons(act,scale);
|
76
|
|
77
|
for(ImageButton button: mColorButton) layoutTop.addView(button);
|
78
|
|
79
|
// BOT ////////////////////////////
|
80
|
if( mBackButton==null ) setupBackButton(act,scale);
|
81
|
|
82
|
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
|
83
|
layoutRight.removeAllViews();
|
84
|
layoutRight.addView(mBackButton);
|
85
|
}
|
86
|
|
87
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88
|
//createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side);
|
89
|
|
90
|
private void setupBitmaps(float scale)
|
91
|
{
|
92
|
final int SIZE = (int)(scale*BITMAP_SIZE);
|
93
|
final float R = SIZE*0.10f;
|
94
|
final float M = SIZE*0.05f;
|
95
|
|
96
|
mBitmap = new Bitmap[NUM_FACES];
|
97
|
|
98
|
Paint paint = new Paint();
|
99
|
paint.setColor(0xff008800);
|
100
|
paint.setStyle(Paint.Style.FILL);
|
101
|
|
102
|
paint.setAntiAlias(true);
|
103
|
paint.setTextAlign(Paint.Align.CENTER);
|
104
|
paint.setStyle(Paint.Style.FILL);
|
105
|
|
106
|
for(int i=0; i<NUM_FACES; i++)
|
107
|
{
|
108
|
mBitmap[i] = Bitmap.createBitmap(SIZE, SIZE, Bitmap.Config.ARGB_8888);
|
109
|
Canvas canvas = new Canvas(mBitmap[i]);
|
110
|
|
111
|
paint.setColor(0xff000000);
|
112
|
canvas.drawRect(0, 0, SIZE, SIZE, paint);
|
113
|
|
114
|
paint.setColor(FACE_COLORS[i]);
|
115
|
canvas.drawRoundRect( M, M, SIZE-M, SIZE-M, R, R, paint);
|
116
|
}
|
117
|
}
|
118
|
|
119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
|
121
|
private void setupColorButtons(final RubikActivity act, final float scale)
|
122
|
{
|
123
|
mColorButton = new ImageButton[NUM_FACES];
|
124
|
|
125
|
for(int i=0; i<NUM_FACES; i++)
|
126
|
{
|
127
|
final int ii = i;
|
128
|
int padding = (int)(3*scale + 0.5f);
|
129
|
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
|
130
|
mColorButton[i] = new ImageButton(act);
|
131
|
mColorButton[i].setLayoutParams(objectParams);
|
132
|
mColorButton[i].setPadding(padding,0,padding,0);
|
133
|
mColorButton[i].setImageBitmap(mBitmap[i]);
|
134
|
|
135
|
mColorButton[i].setOnClickListener( new View.OnClickListener()
|
136
|
{
|
137
|
@Override
|
138
|
public void onClick(View view)
|
139
|
{
|
140
|
android.util.Log.e("solver", "button "+FACE_COLORS[ii]+" clicked");
|
141
|
}
|
142
|
});
|
143
|
}
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
private void setupBackButton(final RubikActivity act, final float scale)
|
149
|
{
|
150
|
int padding = (int)(3*scale + 0.5f);
|
151
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
152
|
mBackButton = new Button(act);
|
153
|
mBackButton.setLayoutParams(backParams);
|
154
|
mBackButton.setPadding(padding,0,padding,0);
|
155
|
mBackButton.setText(R.string.back);
|
156
|
|
157
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
158
|
{
|
159
|
@Override
|
160
|
public void onClick(View v)
|
161
|
{
|
162
|
RubikState.goBack(act);
|
163
|
}
|
164
|
});
|
165
|
}
|
166
|
|
167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168
|
|
169
|
public void savePreferences(SharedPreferences.Editor editor)
|
170
|
{
|
171
|
mColorButton = null;
|
172
|
mBackButton = null;
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
|
177
|
public void restorePreferences(SharedPreferences preferences)
|
178
|
{
|
179
|
|
180
|
}
|
181
|
}
|