1 |
f5da732a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2021 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.control;
|
21 |
|
|
|
22 |
|
|
import org.distorted.library.message.EffectListener;
|
23 |
|
|
import org.distorted.main.RubikActivity;
|
24 |
|
|
|
25 |
|
|
import java.lang.ref.WeakReference;
|
26 |
|
|
|
27 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28 |
|
|
|
29 |
|
|
public class RubikControl implements EffectListener, Runnable
|
30 |
|
|
{
|
31 |
|
|
WeakReference<RubikActivity> mRefAct;
|
32 |
|
|
long mWholeID, mRotateID;
|
33 |
|
|
boolean mWholeReturned, mRotateReturned;
|
34 |
|
|
|
35 |
|
|
long mRetID;
|
36 |
|
|
|
37 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38 |
|
|
|
39 |
|
|
private void addWholeObjects()
|
40 |
|
|
{
|
41 |
|
|
mWholeID = 0;
|
42 |
|
|
|
43 |
|
|
mRetID = mWholeID;
|
44 |
|
|
|
45 |
|
|
Thread networkThrd = new Thread(this);
|
46 |
|
|
networkThrd.start();
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
|
|
private void addWholeEffects()
|
52 |
|
|
{
|
53 |
|
|
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
|
|
private void removeWholeObjects()
|
59 |
|
|
{
|
60 |
|
|
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64 |
|
|
|
65 |
|
|
private void addRotateObjects()
|
66 |
|
|
{
|
67 |
|
|
mRotateID = 1;
|
68 |
|
|
|
69 |
|
|
mRetID = mRotateID;
|
70 |
|
|
|
71 |
|
|
Thread networkThrd = new Thread(this);
|
72 |
|
|
networkThrd.start();
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76 |
|
|
|
77 |
|
|
private void addRotateEffects()
|
78 |
|
|
{
|
79 |
|
|
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83 |
|
|
|
84 |
|
|
private void removeRotateObjects()
|
85 |
|
|
{
|
86 |
|
|
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90 |
|
|
|
91 |
|
|
private void animateCubeWhole()
|
92 |
|
|
{
|
93 |
|
|
addWholeObjects();
|
94 |
|
|
addWholeEffects();
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
private void finishWhole()
|
100 |
|
|
{
|
101 |
|
|
removeWholeObjects();
|
102 |
|
|
|
103 |
|
|
mWholeReturned = true;
|
104 |
|
|
|
105 |
|
|
if( !mRotateReturned ) animateCubeRotate();
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
|
|
private void animateCubeRotate()
|
111 |
|
|
{
|
112 |
|
|
addRotateObjects();
|
113 |
|
|
addRotateEffects();
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117 |
|
|
|
118 |
|
|
private void finishRotate()
|
119 |
|
|
{
|
120 |
|
|
removeRotateObjects();
|
121 |
|
|
|
122 |
|
|
mRotateReturned= true;
|
123 |
|
|
|
124 |
|
|
RubikActivity act = mRefAct.get();
|
125 |
|
|
if( act!=null ) act.unblockEverything();
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
|
|
// PUBLIC
|
130 |
|
|
|
131 |
|
|
@Override
|
132 |
|
|
public void run()
|
133 |
|
|
{
|
134 |
|
|
android.util.Log.e("D", "running...");
|
135 |
|
|
|
136 |
|
|
try
|
137 |
|
|
{
|
138 |
|
|
Thread.sleep(4000);
|
139 |
|
|
}
|
140 |
|
|
catch(InterruptedException ex)
|
141 |
|
|
{
|
142 |
|
|
// ignore
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
android.util.Log.e("D", "end running...");
|
146 |
|
|
|
147 |
|
|
effectFinished(mRetID);
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151 |
|
|
|
152 |
|
|
public void effectFinished(long effectID)
|
153 |
|
|
{
|
154 |
|
|
if( effectID==mWholeID ) finishWhole();
|
155 |
|
|
if( effectID==mRotateID ) finishRotate();
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
159 |
|
|
|
160 |
|
|
public void animateAll(RubikActivity act)
|
161 |
|
|
{
|
162 |
|
|
act.blockEverything();
|
163 |
|
|
mRefAct = new WeakReference<>(act);
|
164 |
|
|
|
165 |
|
|
mWholeReturned = false;
|
166 |
|
|
mRotateReturned= false;
|
167 |
|
|
|
168 |
|
|
animateCubeWhole();
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
172 |
|
|
|
173 |
|
|
public void animateRotate(RubikActivity act)
|
174 |
|
|
{
|
175 |
|
|
act.blockEverything();
|
176 |
|
|
mRefAct = new WeakReference<>(act);
|
177 |
|
|
|
178 |
|
|
mWholeReturned = true;
|
179 |
|
|
mRotateReturned= false;
|
180 |
|
|
|
181 |
|
|
animateCubeRotate();
|
182 |
|
|
}
|
183 |
|
|
}
|