1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 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.magic;
|
21
|
|
22
|
import android.os.Bundle;
|
23
|
import android.support.v7.app.AppCompatActivity;
|
24
|
import android.view.View;
|
25
|
|
26
|
import org.distorted.library.main.DistortedLibrary;
|
27
|
|
28
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29
|
|
30
|
public class RubikActivity extends AppCompatActivity implements View.OnClickListener
|
31
|
{
|
32
|
private RubikDialogMain mMain;
|
33
|
|
34
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35
|
|
36
|
@Override
|
37
|
protected void onCreate(Bundle savedState)
|
38
|
{
|
39
|
super.onCreate(savedState);
|
40
|
setTheme(R.style.CustomActivityThemeNoActionBar);
|
41
|
setContentView(R.layout.main);
|
42
|
|
43
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
44
|
view.enterMainState(this);
|
45
|
|
46
|
if( savedState==null )
|
47
|
{
|
48
|
mMain = new RubikDialogMain();
|
49
|
mMain.show(getSupportFragmentManager(), null);
|
50
|
}
|
51
|
}
|
52
|
|
53
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
|
55
|
@Override
|
56
|
protected void onPause()
|
57
|
{
|
58
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
59
|
view.onPause();
|
60
|
DistortedLibrary.onPause();
|
61
|
RubikScoresDownloader.onPause();
|
62
|
view.savePreferences();
|
63
|
super.onPause();
|
64
|
}
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
@Override
|
69
|
protected void onResume()
|
70
|
{
|
71
|
super.onResume();
|
72
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
73
|
view.onResume();
|
74
|
view.restorePreferences();
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
|
79
|
@Override
|
80
|
protected void onDestroy()
|
81
|
{
|
82
|
DistortedLibrary.onDestroy();
|
83
|
super.onDestroy();
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
@Override
|
89
|
public void onClick(View v)
|
90
|
{
|
91
|
int id = v.getId();
|
92
|
|
93
|
if( id>=0 && id<RubikSize.LENGTH )
|
94
|
{
|
95
|
int size = RubikSize.getSize(id).getCubeSize();
|
96
|
|
97
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
98
|
boolean success = view.getRenderer().createCube(size);
|
99
|
|
100
|
if( success )
|
101
|
{
|
102
|
view.markButton(id);
|
103
|
}
|
104
|
}
|
105
|
|
106
|
if( id == RubikSurfaceView.BUTTON_ID_BACK )
|
107
|
{
|
108
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
109
|
view.enterMainState(this);
|
110
|
mMain.show(getSupportFragmentManager(), null);
|
111
|
}
|
112
|
if( id == RubikSurfaceView.BUTTON_ID_EXIT )
|
113
|
{
|
114
|
finish();
|
115
|
}
|
116
|
}
|
117
|
|
118
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119
|
// PUBLIC API
|
120
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121
|
|
122
|
public void Play(View v)
|
123
|
{
|
124
|
mMain.dismiss();
|
125
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
126
|
view.enterPlayState(this);
|
127
|
}
|
128
|
|
129
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130
|
|
131
|
public void Settings(View v)
|
132
|
{
|
133
|
RubikDialogSettings settings = new RubikDialogSettings();
|
134
|
settings.show(getSupportFragmentManager(), null);
|
135
|
}
|
136
|
|
137
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138
|
|
139
|
public void Scores(View v)
|
140
|
{
|
141
|
Bundle bundle = new Bundle();
|
142
|
bundle.putInt("tab", RubikSurfaceView.getRedButton());
|
143
|
|
144
|
RubikDialogScores scores = new RubikDialogScores();
|
145
|
scores.setArguments(bundle);
|
146
|
scores.show(getSupportFragmentManager(), null);
|
147
|
}
|
148
|
|
149
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150
|
|
151
|
public void About(View v)
|
152
|
{
|
153
|
RubikDialogAbout about = new RubikDialogAbout();
|
154
|
about.show(getSupportFragmentManager(), null);
|
155
|
}
|
156
|
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
|
159
|
public void Scramble(View v)
|
160
|
{
|
161
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
162
|
view.scramble();
|
163
|
}
|
164
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166
|
|
167
|
public void Solve(View v)
|
168
|
{
|
169
|
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
170
|
view.getRenderer().solveCube();
|
171
|
}
|
172
|
}
|