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.annotation.SuppressLint;
|
23
|
import android.content.SharedPreferences;
|
24
|
import android.util.TypedValue;
|
25
|
import android.widget.LinearLayout;
|
26
|
|
27
|
import org.distorted.main.RubikActivity;
|
28
|
import org.distorted.objects.ObjectList;
|
29
|
import org.distorted.patterns.RubikPatternList;
|
30
|
|
31
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
|
33
|
public abstract class RubikStateAbstract
|
34
|
{
|
35
|
@SuppressLint("ViewConstructor")
|
36
|
static class TransparentImageButton extends androidx.appcompat.widget.AppCompatImageButton
|
37
|
{
|
38
|
public TransparentImageButton(RubikActivity act, int icon, float scrWidth, int butWidth)
|
39
|
{
|
40
|
super(act);
|
41
|
|
42
|
final int padding = (int)(scrWidth*RubikActivity.PADDING);
|
43
|
final int margin = (int)(scrWidth*RubikActivity.MARGIN);
|
44
|
|
45
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(butWidth,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
46
|
|
47
|
params.topMargin = margin;
|
48
|
params.bottomMargin = margin;
|
49
|
params.leftMargin = margin;
|
50
|
params.rightMargin = margin;
|
51
|
|
52
|
setLayoutParams(params);
|
53
|
setPadding(padding,0,padding,0);
|
54
|
setImageResource(icon);
|
55
|
|
56
|
TypedValue outValue = new TypedValue();
|
57
|
act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
|
58
|
setBackgroundResource(outValue.resourceId);
|
59
|
}
|
60
|
}
|
61
|
|
62
|
@SuppressLint("ViewConstructor")
|
63
|
static class TransparentButton extends androidx.appcompat.widget.AppCompatButton
|
64
|
{
|
65
|
public TransparentButton(RubikActivity act, int resId, float size, float scrWidth)
|
66
|
{
|
67
|
super(act);
|
68
|
|
69
|
final int padding = (int)(scrWidth*RubikActivity.PADDING);
|
70
|
final int margin = (int)(scrWidth*RubikActivity.MARGIN);
|
71
|
|
72
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
|
73
|
params.topMargin = margin;
|
74
|
params.bottomMargin = margin;
|
75
|
params.leftMargin = margin;
|
76
|
params.rightMargin = margin;
|
77
|
|
78
|
setLayoutParams(params);
|
79
|
setPadding(padding,0,padding,0);
|
80
|
setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
|
81
|
setText(resId);
|
82
|
|
83
|
TypedValue outValue = new TypedValue();
|
84
|
act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
|
85
|
setBackgroundResource(outValue.resourceId);
|
86
|
}
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
|
91
|
int getPatternOrdinal()
|
92
|
{
|
93
|
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
94
|
int obj = play.getObject();
|
95
|
int size = play.getSize();
|
96
|
int ret = RubikPatternList.getOrdinal(obj,size);
|
97
|
|
98
|
if( ret<0 )
|
99
|
{
|
100
|
ret = ObjectList.getSizeIndex(RubikStatePlay.DEF_OBJECT,RubikStatePlay.DEF_SIZE);
|
101
|
}
|
102
|
|
103
|
return ret;
|
104
|
}
|
105
|
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
abstract void enterState(RubikActivity act);
|
109
|
abstract void leaveState(RubikActivity act);
|
110
|
public abstract void savePreferences(SharedPreferences.Editor editor);
|
111
|
public abstract void restorePreferences(SharedPreferences preferences);
|
112
|
}
|