Revision e019c70b
Added by Leszek Koltunski about 4 years ago
| src/main/java/org/distorted/helpers/LockController.java | ||
|---|---|---|
| 29 | 29 |
|
| 30 | 30 |
import org.distorted.main.R; |
| 31 | 31 |
import org.distorted.main.RubikActivity; |
| 32 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
| 33 | 32 |
import org.distorted.objectlib.main.ObjectControl; |
| 34 | 33 |
|
| 35 | 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 152 | 151 |
|
| 153 | 152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 154 | 153 |
|
| 155 |
public void setupButton(final TwistyActivity act, ObjectControl control, final float width)
|
|
| 154 |
public void setupButton(final Activity act, ObjectControl control, final float width) |
|
| 156 | 155 |
{
|
| 157 | 156 |
boolean locked = control.retLocked(); |
| 158 | 157 |
final int icon = getLockIcon(locked,false); |
| src/main/java/org/distorted/helpers/MovesController.java | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
import java.util.ArrayList; |
| 23 | 23 |
|
| 24 |
import android.app.Activity; |
|
| 24 | 25 |
import android.view.View; |
| 25 | 26 |
import android.widget.ImageButton; |
| 26 | 27 |
import android.widget.LinearLayout; |
| 27 | 28 |
|
| 28 | 29 |
import org.distorted.objectlib.helpers.BlockController; |
| 29 | 30 |
import org.distorted.objectlib.helpers.MovesFinished; |
| 30 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
| 31 | 31 |
import org.distorted.objectlib.main.ObjectControl; |
| 32 | 32 |
|
| 33 | 33 |
import org.distorted.main.R; |
| ... | ... | |
| 87 | 87 |
|
| 88 | 88 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
| 89 | 89 |
|
| 90 |
public void backMove(TwistyActivity act)
|
|
| 90 |
public void backMove(Activity act, ObjectControl control)
|
|
| 91 | 91 |
{
|
| 92 | 92 |
if( mCanPrevMove ) |
| 93 | 93 |
{
|
| ... | ... | |
| 102 | 102 |
if( angle!=0 ) |
| 103 | 103 |
{
|
| 104 | 104 |
mCanPrevMove = false; |
| 105 |
mControl = act.getControl();
|
|
| 105 |
mControl = control;
|
|
| 106 | 106 |
mControl.blockTouch(BlockController.MOVES_PLACE_0); |
| 107 | 107 |
mControl.addRotation(this, axis, (1<<move.mRow), -angle, MILLIS_PER_DEGREE); |
| 108 | 108 |
} |
| ... | ... | |
| 118 | 118 |
|
| 119 | 119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 120 | 120 |
|
| 121 |
private void changeBackMove(TwistyActivity act, final boolean on)
|
|
| 121 |
private void changeBackMove(Activity act, final boolean on) |
|
| 122 | 122 |
{
|
| 123 | 123 |
act.runOnUiThread(new Runnable() |
| 124 | 124 |
{
|
| ... | ... | |
| 133 | 133 |
|
| 134 | 134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 135 | 135 |
|
| 136 |
public void addMove(TwistyActivity act, int axis, int row, int angle)
|
|
| 136 |
public void addMove(Activity act, int axis, int row, int angle) |
|
| 137 | 137 |
{
|
| 138 | 138 |
if( mMoves.isEmpty() ) changeBackMove(act,true); |
| 139 | 139 |
mMoves.add(new Move(axis,row,angle)); |
| ... | ... | |
| 149 | 149 |
|
| 150 | 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 151 | 151 |
|
| 152 |
public void clearMoves(final TwistyActivity act)
|
|
| 152 |
public void clearMoves(final Activity act) |
|
| 153 | 153 |
{
|
| 154 | 154 |
mMoves.clear(); |
| 155 | 155 |
changeBackMove(act,false); |
| ... | ... | |
| 164 | 164 |
|
| 165 | 165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 166 | 166 |
|
| 167 |
public void setupButton(final TwistyActivity act, final float width)
|
|
| 167 |
public void setupButton(final Activity act, ObjectControl control, final float width)
|
|
| 168 | 168 |
{
|
| 169 | 169 |
final int icon = getPrevIcon( !mMoves.isEmpty() ); |
| 170 | 170 |
mPrevButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT); |
| ... | ... | |
| 174 | 174 |
@Override |
| 175 | 175 |
public void onClick(View v) |
| 176 | 176 |
{
|
| 177 |
backMove(act); |
|
| 177 |
backMove(act,control);
|
|
| 178 | 178 |
} |
| 179 | 179 |
}); |
| 180 | 180 |
} |
| src/main/java/org/distorted/main/RubikActivity.java | ||
|---|---|---|
| 35 | 35 |
import android.view.WindowManager; |
| 36 | 36 |
import android.widget.LinearLayout; |
| 37 | 37 |
|
| 38 |
import androidx.appcompat.app.AppCompatActivity; |
|
| 39 |
|
|
| 38 | 40 |
import com.google.firebase.analytics.FirebaseAnalytics; |
| 39 | 41 |
|
| 40 | 42 |
import org.distorted.library.main.DistortedLibrary; |
| ... | ... | |
| 45 | 47 |
import org.distorted.objectlib.main.ObjectType; |
| 46 | 48 |
import org.distorted.objectlib.helpers.BlockController; |
| 47 | 49 |
import org.distorted.objectlib.effects.BaseEffect; |
| 48 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
| 49 | 50 |
|
| 50 | 51 |
import org.distorted.dialogs.RubikDialogError; |
| 51 | 52 |
import org.distorted.dialogs.RubikDialogPrivacy; |
| ... | ... | |
| 57 | 58 |
|
| 58 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 59 | 60 |
|
| 60 |
public class RubikActivity extends TwistyActivity
|
|
| 61 |
public class RubikActivity extends AppCompatActivity
|
|
| 61 | 62 |
{
|
| 62 | 63 |
public static final float PADDING = 0.01f; |
| 63 | 64 |
public static final float MARGIN = 0.004f; |
| src/main/java/org/distorted/main/RubikObjectLibInterface.java | ||
|---|---|---|
| 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.main; |
|
| 21 |
|
|
| 22 |
import android.os.Bundle; |
|
| 23 |
|
|
| 24 |
import androidx.annotation.NonNull; |
|
| 25 |
|
|
| 26 |
import com.google.android.play.core.review.ReviewInfo; |
|
| 27 |
import com.google.android.play.core.review.ReviewManager; |
|
| 28 |
import com.google.android.play.core.review.ReviewManagerFactory; |
|
| 29 |
import com.google.android.play.core.tasks.OnCompleteListener; |
|
| 30 |
import com.google.android.play.core.tasks.OnFailureListener; |
|
| 31 |
import com.google.android.play.core.tasks.Task; |
|
| 32 |
import com.google.firebase.analytics.FirebaseAnalytics; |
|
| 33 |
|
|
| 34 |
import org.distorted.library.main.DistortedScreen; |
|
| 35 |
import org.distorted.objectlib.helpers.ObjectLibInterface; |
|
| 36 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 37 |
import org.distorted.objectlib.main.ObjectType; |
|
| 38 |
|
|
| 39 |
import org.distorted.dialogs.RubikDialogNewRecord; |
|
| 40 |
import org.distorted.dialogs.RubikDialogSolved; |
|
| 41 |
import org.distorted.network.RubikScores; |
|
| 42 |
import org.distorted.screens.RubikScreenPlay; |
|
| 43 |
import org.distorted.screens.RubikScreenReady; |
|
| 44 |
import org.distorted.screens.RubikScreenSolver; |
|
| 45 |
import org.distorted.screens.RubikScreenSolving; |
|
| 46 |
import org.distorted.screens.ScreenList; |
|
| 47 |
import org.distorted.solvers.SolverMain; |
|
| 48 |
|
|
| 49 |
import java.lang.ref.WeakReference; |
|
| 50 |
|
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
|
|
| 53 |
public class RubikObjectLibInterface implements ObjectLibInterface |
|
| 54 |
{
|
|
| 55 |
WeakReference<RubikActivity> mAct; |
|
| 56 |
private boolean mIsNewRecord; |
|
| 57 |
private long mNewRecord; |
|
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
RubikObjectLibInterface(RubikActivity act) |
|
| 62 |
{
|
|
| 63 |
mAct = new WeakReference<>(act); |
|
| 64 |
} |
|
| 65 |
|
|
| 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 67 |
|
|
| 68 |
private void analyticsReport(RubikActivity act, String message, String name, long timeBegin) |
|
| 69 |
{
|
|
| 70 |
long elapsed = System.currentTimeMillis() - timeBegin; |
|
| 71 |
String msg = message+" startTime: "+timeBegin+" elapsed: "+elapsed+" name: "+name; |
|
| 72 |
|
|
| 73 |
if( BuildConfig.DEBUG ) |
|
| 74 |
{
|
|
| 75 |
android.util.Log.d("pre", msg);
|
|
| 76 |
} |
|
| 77 |
else |
|
| 78 |
{
|
|
| 79 |
FirebaseAnalytics analytics = act.getAnalytics(); |
|
| 80 |
|
|
| 81 |
if( analytics!=null ) |
|
| 82 |
{
|
|
| 83 |
Bundle bundle = new Bundle(); |
|
| 84 |
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, msg); |
|
| 85 |
analytics.logEvent(FirebaseAnalytics.Event.SHARE, bundle); |
|
| 86 |
} |
|
| 87 |
} |
|
| 88 |
} |
|
| 89 |
|
|
| 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 91 |
|
|
| 92 |
private void reportRecord(RubikActivity act, String debug, int scrambleNum) |
|
| 93 |
{
|
|
| 94 |
RubikScreenPlay play= (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 95 |
RubikScores scores = RubikScores.getInstance(); |
|
| 96 |
ObjectType object = play.getObject(); |
|
| 97 |
int level = play.getLevel(); |
|
| 98 |
String name = scores.getName(); |
|
| 99 |
|
|
| 100 |
String record = object.name()+" level "+level+" time "+mNewRecord+" isNew: "+mIsNewRecord+" scrambleNum: "+scrambleNum; |
|
| 101 |
|
|
| 102 |
if( BuildConfig.DEBUG ) |
|
| 103 |
{
|
|
| 104 |
android.util.Log.e("pre", debug);
|
|
| 105 |
android.util.Log.e("pre", name);
|
|
| 106 |
android.util.Log.e("pre", record);
|
|
| 107 |
} |
|
| 108 |
else |
|
| 109 |
{
|
|
| 110 |
FirebaseAnalytics analytics = act.getAnalytics(); |
|
| 111 |
|
|
| 112 |
if( analytics!=null ) |
|
| 113 |
{
|
|
| 114 |
Bundle bundle = new Bundle(); |
|
| 115 |
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, debug); |
|
| 116 |
bundle.putString(FirebaseAnalytics.Param.CHARACTER, name); |
|
| 117 |
bundle.putString(FirebaseAnalytics.Param.LEVEL, record); |
|
| 118 |
analytics.logEvent(FirebaseAnalytics.Event.LEVEL_UP, bundle); |
|
| 119 |
} |
|
| 120 |
} |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 124 |
|
|
| 125 |
private void requestReview(RubikActivity act) |
|
| 126 |
{
|
|
| 127 |
final RubikScores scores = RubikScores.getInstance(); |
|
| 128 |
int numWins = scores.incrementNumWins(); |
|
| 129 |
|
|
| 130 |
if( numWins==7 || numWins==30 || numWins==100 || numWins==200) |
|
| 131 |
{
|
|
| 132 |
final long timeBegin = System.currentTimeMillis(); |
|
| 133 |
final ReviewManager manager = ReviewManagerFactory.create(act); |
|
| 134 |
Task<ReviewInfo> request = manager.requestReviewFlow(); |
|
| 135 |
|
|
| 136 |
request.addOnCompleteListener(new OnCompleteListener<ReviewInfo>() |
|
| 137 |
{
|
|
| 138 |
@Override |
|
| 139 |
public void onComplete (@NonNull Task<ReviewInfo> task) |
|
| 140 |
{
|
|
| 141 |
if (task.isSuccessful()) |
|
| 142 |
{
|
|
| 143 |
final String name = scores.getName(); |
|
| 144 |
ReviewInfo reviewInfo = task.getResult(); |
|
| 145 |
Task<Void> flow = manager.launchReviewFlow(act, reviewInfo); |
|
| 146 |
|
|
| 147 |
flow.addOnFailureListener(new OnFailureListener() |
|
| 148 |
{
|
|
| 149 |
@Override |
|
| 150 |
public void onFailure(Exception e) |
|
| 151 |
{
|
|
| 152 |
analyticsReport(act,"Failed", name, timeBegin); |
|
| 153 |
} |
|
| 154 |
}); |
|
| 155 |
|
|
| 156 |
flow.addOnCompleteListener(new OnCompleteListener<Void>() |
|
| 157 |
{
|
|
| 158 |
@Override |
|
| 159 |
public void onComplete(@NonNull Task<Void> task) |
|
| 160 |
{
|
|
| 161 |
analyticsReport(act,"Complete", name, timeBegin); |
|
| 162 |
} |
|
| 163 |
}); |
|
| 164 |
} |
|
| 165 |
else |
|
| 166 |
{
|
|
| 167 |
String name = scores.getName(); |
|
| 168 |
analyticsReport(act,"Not Successful", name, timeBegin); |
|
| 169 |
} |
|
| 170 |
} |
|
| 171 |
}); |
|
| 172 |
} |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 176 |
|
|
| 177 |
public void onWinEffectFinished(String debug, int scrambleNum) |
|
| 178 |
{
|
|
| 179 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV ) |
|
| 180 |
{
|
|
| 181 |
RubikActivity act = mAct.get(); |
|
| 182 |
Bundle bundle = new Bundle(); |
|
| 183 |
bundle.putLong("time", mNewRecord );
|
|
| 184 |
|
|
| 185 |
reportRecord(act,debug,scrambleNum); |
|
| 186 |
requestReview(act); |
|
| 187 |
|
|
| 188 |
if( mIsNewRecord ) |
|
| 189 |
{
|
|
| 190 |
RubikDialogNewRecord dialog = new RubikDialogNewRecord(); |
|
| 191 |
dialog.setArguments(bundle); |
|
| 192 |
dialog.show( act.getSupportFragmentManager(), RubikDialogNewRecord.getDialogTag() ); |
|
| 193 |
} |
|
| 194 |
else |
|
| 195 |
{
|
|
| 196 |
RubikDialogSolved dialog = new RubikDialogSolved(); |
|
| 197 |
dialog.setArguments(bundle); |
|
| 198 |
dialog.show( act.getSupportFragmentManager(), RubikDialogSolved.getDialogTag() ); |
|
| 199 |
} |
|
| 200 |
|
|
| 201 |
act.runOnUiThread(new Runnable() |
|
| 202 |
{
|
|
| 203 |
@Override |
|
| 204 |
public void run() |
|
| 205 |
{
|
|
| 206 |
ScreenList.switchScreen( act, ScreenList.DONE); |
|
| 207 |
} |
|
| 208 |
}); |
|
| 209 |
} |
|
| 210 |
} |
|
| 211 |
|
|
| 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 213 |
|
|
| 214 |
public void onScrambleEffectFinished() |
|
| 215 |
{
|
|
| 216 |
RubikActivity act = mAct.get(); |
|
| 217 |
RubikScores.getInstance().incrementNumPlays(); |
|
| 218 |
|
|
| 219 |
act.runOnUiThread(new Runnable() |
|
| 220 |
{
|
|
| 221 |
@Override |
|
| 222 |
public void run() |
|
| 223 |
{
|
|
| 224 |
ScreenList.switchScreen( act, ScreenList.READ); |
|
| 225 |
} |
|
| 226 |
}); |
|
| 227 |
} |
|
| 228 |
|
|
| 229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 230 |
|
|
| 231 |
public void onFinishRotation(int axis, int row, int angle) |
|
| 232 |
{
|
|
| 233 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV ) |
|
| 234 |
{
|
|
| 235 |
RubikScreenSolving solv = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
| 236 |
solv.addMove(mAct.get(), axis, row, angle); |
|
| 237 |
} |
|
| 238 |
if( ScreenList.getCurrentScreen()== ScreenList.PLAY ) |
|
| 239 |
{
|
|
| 240 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 241 |
play.addMove(mAct.get(), axis, row, angle); |
|
| 242 |
} |
|
| 243 |
} |
|
| 244 |
|
|
| 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 246 |
|
|
| 247 |
public void onBeginRotation() |
|
| 248 |
{
|
|
| 249 |
if( ScreenList.getCurrentScreen()== ScreenList.READ ) |
|
| 250 |
{
|
|
| 251 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
| 252 |
solving.resetElapsed(); |
|
| 253 |
RubikActivity act = mAct.get(); |
|
| 254 |
|
|
| 255 |
act.runOnUiThread(new Runnable() |
|
| 256 |
{
|
|
| 257 |
@Override |
|
| 258 |
public void run() |
|
| 259 |
{
|
|
| 260 |
ScreenList.switchScreen( act, ScreenList.SOLV); |
|
| 261 |
} |
|
| 262 |
}); |
|
| 263 |
} |
|
| 264 |
} |
|
| 265 |
|
|
| 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 267 |
|
|
| 268 |
public void failedToDrag() |
|
| 269 |
{
|
|
| 270 |
ScreenList curr = ScreenList.getCurrentScreen(); |
|
| 271 |
|
|
| 272 |
if( curr==ScreenList.PLAY ) |
|
| 273 |
{
|
|
| 274 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 275 |
play.reddenLock(mAct.get()); |
|
| 276 |
} |
|
| 277 |
else if( curr==ScreenList.READ ) |
|
| 278 |
{
|
|
| 279 |
RubikScreenReady read = (RubikScreenReady) ScreenList.READ.getScreenClass(); |
|
| 280 |
read.reddenLock(mAct.get()); |
|
| 281 |
} |
|
| 282 |
else if( curr==ScreenList.SOLV ) |
|
| 283 |
{
|
|
| 284 |
RubikScreenSolving solv = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
| 285 |
solv.reddenLock(mAct.get()); |
|
| 286 |
} |
|
| 287 |
} |
|
| 288 |
|
|
| 289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 290 |
|
|
| 291 |
public void onSolved() |
|
| 292 |
{
|
|
| 293 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV ) |
|
| 294 |
{
|
|
| 295 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
| 296 |
mNewRecord = solving.getRecord(); |
|
| 297 |
|
|
| 298 |
if( mNewRecord< 0 ) |
|
| 299 |
{
|
|
| 300 |
mNewRecord = -mNewRecord; |
|
| 301 |
mIsNewRecord = false; |
|
| 302 |
} |
|
| 303 |
else |
|
| 304 |
{
|
|
| 305 |
mIsNewRecord = true; |
|
| 306 |
} |
|
| 307 |
} |
|
| 308 |
} |
|
| 309 |
|
|
| 310 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 311 |
|
|
| 312 |
public int getCurrentColor() |
|
| 313 |
{
|
|
| 314 |
RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getScreenClass(); |
|
| 315 |
return solver.getCurrentColor(); |
|
| 316 |
} |
|
| 317 |
|
|
| 318 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 319 |
|
|
| 320 |
public int cubitIsLocked(ObjectType type, int cubit) |
|
| 321 |
{
|
|
| 322 |
return SolverMain.cubitIsLocked(type,cubit); |
|
| 323 |
} |
|
| 324 |
|
|
| 325 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 326 |
|
|
| 327 |
public ObjectControl getControl() |
|
| 328 |
{
|
|
| 329 |
RubikActivity act = mAct.get(); |
|
| 330 |
return act.getControl(); |
|
| 331 |
} |
|
| 332 |
|
|
| 333 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 334 |
|
|
| 335 |
public DistortedScreen getScreen() |
|
| 336 |
{
|
|
| 337 |
RubikActivity act = mAct.get(); |
|
| 338 |
return act.getScreen(); |
|
| 339 |
} |
|
| 340 |
} |
|
| src/main/java/org/distorted/main/RubikObjectStateActioner.java | ||
|---|---|---|
| 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.main; |
|
| 21 |
|
|
| 22 |
import android.os.Bundle; |
|
| 23 |
|
|
| 24 |
import androidx.annotation.NonNull; |
|
| 25 |
|
|
| 26 |
import com.google.android.play.core.review.ReviewInfo; |
|
| 27 |
import com.google.android.play.core.review.ReviewManager; |
|
| 28 |
import com.google.android.play.core.review.ReviewManagerFactory; |
|
| 29 |
import com.google.android.play.core.tasks.OnCompleteListener; |
|
| 30 |
import com.google.android.play.core.tasks.OnFailureListener; |
|
| 31 |
import com.google.android.play.core.tasks.Task; |
|
| 32 |
import com.google.firebase.analytics.FirebaseAnalytics; |
|
| 33 |
|
|
| 34 |
import org.distorted.objectlib.helpers.ObjectStateActioner; |
|
| 35 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
| 36 |
import org.distorted.objectlib.main.ObjectType; |
|
| 37 |
|
|
| 38 |
import org.distorted.dialogs.RubikDialogNewRecord; |
|
| 39 |
import org.distorted.dialogs.RubikDialogSolved; |
|
| 40 |
import org.distorted.network.RubikScores; |
|
| 41 |
import org.distorted.screens.RubikScreenPlay; |
|
| 42 |
import org.distorted.screens.RubikScreenReady; |
|
| 43 |
import org.distorted.screens.RubikScreenSolver; |
|
| 44 |
import org.distorted.screens.RubikScreenSolving; |
|
| 45 |
import org.distorted.screens.ScreenList; |
|
| 46 |
import org.distorted.solvers.SolverMain; |
|
| 47 |
|
|
| 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 49 |
|
|
| 50 |
public class RubikObjectStateActioner implements ObjectStateActioner |
|
| 51 |
{
|
|
| 52 |
private boolean mIsNewRecord; |
|
| 53 |
private long mNewRecord; |
|
| 54 |
|
|
| 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 56 |
|
|
| 57 |
private void analyticsReport(TwistyActivity act, String message, String name, long timeBegin) |
|
| 58 |
{
|
|
| 59 |
long elapsed = System.currentTimeMillis() - timeBegin; |
|
| 60 |
String msg = message+" startTime: "+timeBegin+" elapsed: "+elapsed+" name: "+name; |
|
| 61 |
|
|
| 62 |
if( BuildConfig.DEBUG ) |
|
| 63 |
{
|
|
| 64 |
android.util.Log.d("pre", msg);
|
|
| 65 |
} |
|
| 66 |
else |
|
| 67 |
{
|
|
| 68 |
RubikActivity ract = (RubikActivity)act; |
|
| 69 |
FirebaseAnalytics analytics = ract.getAnalytics(); |
|
| 70 |
|
|
| 71 |
if( analytics!=null ) |
|
| 72 |
{
|
|
| 73 |
Bundle bundle = new Bundle(); |
|
| 74 |
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, msg); |
|
| 75 |
analytics.logEvent(FirebaseAnalytics.Event.SHARE, bundle); |
|
| 76 |
} |
|
| 77 |
} |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
|
|
| 82 |
private void reportRecord(TwistyActivity act, String debug, int scrambleNum) |
|
| 83 |
{
|
|
| 84 |
RubikActivity ract = (RubikActivity)act; |
|
| 85 |
RubikScreenPlay play= (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 86 |
RubikScores scores = RubikScores.getInstance(); |
|
| 87 |
ObjectType object = play.getObject(); |
|
| 88 |
int level = play.getLevel(); |
|
| 89 |
String name = scores.getName(); |
|
| 90 |
|
|
| 91 |
String record = object.name()+" level "+level+" time "+mNewRecord+" isNew: "+mIsNewRecord+" scrambleNum: "+scrambleNum; |
|
| 92 |
|
|
| 93 |
if( BuildConfig.DEBUG ) |
|
| 94 |
{
|
|
| 95 |
android.util.Log.e("pre", debug);
|
|
| 96 |
android.util.Log.e("pre", name);
|
|
| 97 |
android.util.Log.e("pre", record);
|
|
| 98 |
} |
|
| 99 |
else |
|
| 100 |
{
|
|
| 101 |
FirebaseAnalytics analytics = ract.getAnalytics(); |
|
| 102 |
|
|
| 103 |
if( analytics!=null ) |
|
| 104 |
{
|
|
| 105 |
Bundle bundle = new Bundle(); |
|
| 106 |
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, debug); |
|
| 107 |
bundle.putString(FirebaseAnalytics.Param.CHARACTER, name); |
|
| 108 |
bundle.putString(FirebaseAnalytics.Param.LEVEL, record); |
|
| 109 |
analytics.logEvent(FirebaseAnalytics.Event.LEVEL_UP, bundle); |
|
| 110 |
} |
|
| 111 |
} |
|
| 112 |
} |
|
| 113 |
|
|
| 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 115 |
|
|
| 116 |
private void requestReview(TwistyActivity act) |
|
| 117 |
{
|
|
| 118 |
final RubikScores scores = RubikScores.getInstance(); |
|
| 119 |
int numWins = scores.incrementNumWins(); |
|
| 120 |
|
|
| 121 |
if( numWins==7 || numWins==30 || numWins==100 || numWins==200) |
|
| 122 |
{
|
|
| 123 |
final long timeBegin = System.currentTimeMillis(); |
|
| 124 |
final ReviewManager manager = ReviewManagerFactory.create(act); |
|
| 125 |
Task<ReviewInfo> request = manager.requestReviewFlow(); |
|
| 126 |
|
|
| 127 |
request.addOnCompleteListener(new OnCompleteListener<ReviewInfo>() |
|
| 128 |
{
|
|
| 129 |
@Override |
|
| 130 |
public void onComplete (@NonNull Task<ReviewInfo> task) |
|
| 131 |
{
|
|
| 132 |
if (task.isSuccessful()) |
|
| 133 |
{
|
|
| 134 |
final String name = scores.getName(); |
|
| 135 |
ReviewInfo reviewInfo = task.getResult(); |
|
| 136 |
Task<Void> flow = manager.launchReviewFlow(act, reviewInfo); |
|
| 137 |
|
|
| 138 |
flow.addOnFailureListener(new OnFailureListener() |
|
| 139 |
{
|
|
| 140 |
@Override |
|
| 141 |
public void onFailure(Exception e) |
|
| 142 |
{
|
|
| 143 |
analyticsReport(act,"Failed", name, timeBegin); |
|
| 144 |
} |
|
| 145 |
}); |
|
| 146 |
|
|
| 147 |
flow.addOnCompleteListener(new OnCompleteListener<Void>() |
|
| 148 |
{
|
|
| 149 |
@Override |
|
| 150 |
public void onComplete(@NonNull Task<Void> task) |
|
| 151 |
{
|
|
| 152 |
analyticsReport(act,"Complete", name, timeBegin); |
|
| 153 |
} |
|
| 154 |
}); |
|
| 155 |
} |
|
| 156 |
else |
|
| 157 |
{
|
|
| 158 |
String name = scores.getName(); |
|
| 159 |
analyticsReport(act,"Not Successful", name, timeBegin); |
|
| 160 |
} |
|
| 161 |
} |
|
| 162 |
}); |
|
| 163 |
} |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 167 |
|
|
| 168 |
public void onWinEffectFinished(TwistyActivity act, String debug, int scrambleNum) |
|
| 169 |
{
|
|
| 170 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV ) |
|
| 171 |
{
|
|
| 172 |
RubikActivity ract = (RubikActivity)act; |
|
| 173 |
Bundle bundle = new Bundle(); |
|
| 174 |
bundle.putLong("time", mNewRecord );
|
|
| 175 |
|
|
| 176 |
reportRecord(act,debug,scrambleNum); |
|
| 177 |
requestReview(act); |
|
| 178 |
|
|
| 179 |
if( mIsNewRecord ) |
|
| 180 |
{
|
|
| 181 |
RubikDialogNewRecord dialog = new RubikDialogNewRecord(); |
|
| 182 |
dialog.setArguments(bundle); |
|
| 183 |
dialog.show( act.getSupportFragmentManager(), RubikDialogNewRecord.getDialogTag() ); |
|
| 184 |
} |
|
| 185 |
else |
|
| 186 |
{
|
|
| 187 |
RubikDialogSolved dialog = new RubikDialogSolved(); |
|
| 188 |
dialog.setArguments(bundle); |
|
| 189 |
dialog.show( act.getSupportFragmentManager(), RubikDialogSolved.getDialogTag() ); |
|
| 190 |
} |
|
| 191 |
|
|
| 192 |
act.runOnUiThread(new Runnable() |
|
| 193 |
{
|
|
| 194 |
@Override |
|
| 195 |
public void run() |
|
| 196 |
{
|
|
| 197 |
ScreenList.switchScreen( ract, ScreenList.DONE); |
|
| 198 |
} |
|
| 199 |
}); |
|
| 200 |
} |
|
| 201 |
} |
|
| 202 |
|
|
| 203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 204 |
|
|
| 205 |
public void onScrambleEffectFinished(TwistyActivity act) |
|
| 206 |
{
|
|
| 207 |
RubikActivity ract = (RubikActivity)act; |
|
| 208 |
|
|
| 209 |
RubikScores.getInstance().incrementNumPlays(); |
|
| 210 |
|
|
| 211 |
act.runOnUiThread(new Runnable() |
|
| 212 |
{
|
|
| 213 |
@Override |
|
| 214 |
public void run() |
|
| 215 |
{
|
|
| 216 |
ScreenList.switchScreen( ract, ScreenList.READ); |
|
| 217 |
} |
|
| 218 |
}); |
|
| 219 |
} |
|
| 220 |
|
|
| 221 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 222 |
|
|
| 223 |
public void onFinishRotation(TwistyActivity act, int axis, int row, int angle) |
|
| 224 |
{
|
|
| 225 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV ) |
|
| 226 |
{
|
|
| 227 |
RubikScreenSolving solv = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
| 228 |
solv.addMove(act, axis, row, angle); |
|
| 229 |
} |
|
| 230 |
if( ScreenList.getCurrentScreen()== ScreenList.PLAY ) |
|
| 231 |
{
|
|
| 232 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 233 |
play.addMove(act, axis, row, angle); |
|
| 234 |
} |
|
| 235 |
} |
|
| 236 |
|
|
| 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 |
|
|
| 239 |
public void onBeginRotation(TwistyActivity act) |
|
| 240 |
{
|
|
| 241 |
if( ScreenList.getCurrentScreen()== ScreenList.READ ) |
|
| 242 |
{
|
|
| 243 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
| 244 |
solving.resetElapsed(); |
|
| 245 |
RubikActivity ract = (RubikActivity)act; |
|
| 246 |
|
|
| 247 |
ract.runOnUiThread(new Runnable() |
|
| 248 |
{
|
|
| 249 |
@Override |
|
| 250 |
public void run() |
|
| 251 |
{
|
|
| 252 |
ScreenList.switchScreen( ract, ScreenList.SOLV); |
|
| 253 |
} |
|
| 254 |
}); |
|
| 255 |
} |
|
| 256 |
} |
|
| 257 |
|
|
| 258 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 259 |
|
|
| 260 |
public void failedToDrag(TwistyActivity act) |
|
| 261 |
{
|
|
| 262 |
ScreenList curr = ScreenList.getCurrentScreen(); |
|
| 263 |
|
|
| 264 |
if( curr==ScreenList.PLAY ) |
|
| 265 |
{
|
|
| 266 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
| 267 |
play.reddenLock(act); |
|
| 268 |
} |
|
| 269 |
else if( curr==ScreenList.READ ) |
|
| 270 |
{
|
|
| 271 |
RubikScreenReady read = (RubikScreenReady) ScreenList.READ.getScreenClass(); |
|
| 272 |
read.reddenLock(act); |
|
| 273 |
} |
|
| 274 |
else if( curr==ScreenList.SOLV ) |
|
| 275 |
{
|
|
| 276 |
RubikScreenSolving solv = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
| 277 |
solv.reddenLock(act); |
|
| 278 |
} |
|
| 279 |
} |
|
| 280 |
|
|
| 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 282 |
|
|
| 283 |
public void onSolved() |
|
| 284 |
{
|
|
| 285 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV ) |
|
| 286 |
{
|
|
| 287 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass(); |
|
| 288 |
mNewRecord = solving.getRecord(); |
|
| 289 |
|
|
| 290 |
if( mNewRecord< 0 ) |
|
| 291 |
{
|
|
| 292 |
mNewRecord = -mNewRecord; |
|
| 293 |
mIsNewRecord = false; |
|
| 294 |
} |
|
| 295 |
else |
|
| 296 |
{
|
|
| 297 |
mIsNewRecord = true; |
|
| 298 |
} |
|
| 299 |
} |
|
| 300 |
} |
|
| 301 |
|
|
| 302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 303 |
|
|
| 304 |
public int getCurrentColor() |
|
| 305 |
{
|
|
| 306 |
RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getScreenClass(); |
|
| 307 |
return solver.getCurrentColor(); |
|
| 308 |
} |
|
| 309 |
|
|
| 310 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 311 |
|
|
| 312 |
public int cubitIsLocked(ObjectType type, int cubit) |
|
| 313 |
{
|
|
| 314 |
return SolverMain.cubitIsLocked(type,cubit); |
|
| 315 |
} |
|
| 316 |
} |
|
| src/main/java/org/distorted/main/RubikSurfaceView.java | ||
|---|---|---|
| 84 | 84 |
if(!isInEditMode()) |
| 85 | 85 |
{
|
| 86 | 86 |
RubikActivity act = (RubikActivity)context; |
| 87 |
mObjectController = new ObjectControl(act,new RubikObjectStateActioner()); |
|
| 87 |
RubikObjectLibInterface ref = new RubikObjectLibInterface(act); |
|
| 88 |
mObjectController = new ObjectControl(act,ref); |
|
| 88 | 89 |
mRenderer = new RubikRenderer(this); |
| 89 | 90 |
|
| 90 | 91 |
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
| src/main/java/org/distorted/screens/RubikScreenBase.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.screens; |
| 21 | 21 |
|
| 22 |
import android.app.Activity; |
|
| 22 | 23 |
import android.widget.ImageButton; |
| 23 | 24 |
import android.widget.LinearLayout; |
| 24 | 25 |
|
| 25 |
import org.distorted.objectlib.helpers.TwistyActivity;
|
|
| 26 |
import org.distorted.main.RubikActivity;
|
|
| 26 | 27 |
import org.distorted.objectlib.main.ObjectControl; |
| 27 | 28 |
|
| 28 | 29 |
import org.distorted.helpers.LockController; |
| ... | ... | |
| 38 | 39 |
|
| 39 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 40 | 41 |
|
| 41 |
void createBottomPane(final TwistyActivity act, float width, ImageButton button)
|
|
| 42 |
void createBottomPane(final RubikActivity act, float width, ImageButton button)
|
|
| 42 | 43 |
{
|
| 43 | 44 |
mMovesController.clearMoves(act); |
| 44 | 45 |
|
| ... | ... | |
| 54 | 55 |
LinearLayout layoutRight = new LinearLayout(act); |
| 55 | 56 |
layoutRight.setLayoutParams(params); |
| 56 | 57 |
|
| 57 |
mMovesController.setupButton(act,width); |
|
| 58 |
ObjectControl control = act.getControl(); |
|
| 59 |
mMovesController.setupButton(act,control,width); |
|
| 58 | 60 |
layoutLeft.addView(mMovesController.getButton()); |
| 59 |
mLockController.setupButton(act,act.getControl(),width);
|
|
| 61 |
mLockController.setupButton(act,control,width);
|
|
| 60 | 62 |
layoutMid.addView(mLockController.getButton()); |
| 61 | 63 |
layoutRight.addView(button); |
| 62 | 64 |
|
| ... | ... | |
| 67 | 69 |
|
| 68 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 69 | 71 |
|
| 70 |
public void setLockState(final TwistyActivity act)
|
|
| 72 |
public void setLockState(final RubikActivity act)
|
|
| 71 | 73 |
{
|
| 72 | 74 |
boolean locked = act.getControl().retLocked(); |
| 73 | 75 |
mLockController.setState(act,locked); |
| ... | ... | |
| 84 | 86 |
|
| 85 | 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 86 | 88 |
|
| 87 |
public void addMove(TwistyActivity act, int axis, int row, int angle)
|
|
| 89 |
public void addMove(Activity act, int axis, int row, int angle) |
|
| 88 | 90 |
{
|
| 89 | 91 |
mMovesController.addMove(act,axis,row,angle); |
| 90 | 92 |
} |
| 91 | 93 |
|
| 92 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 93 | 95 |
|
| 94 |
public void reddenLock(final TwistyActivity act)
|
|
| 96 |
public void reddenLock(final RubikActivity act)
|
|
| 95 | 97 |
{
|
| 96 | 98 |
ObjectControl control = act.getControl(); |
| 97 | 99 |
mLockController.reddenLock(act,control); |
| src/main/java/org/distorted/tutorials/TutorialActivity.java | ||
|---|---|---|
| 28 | 28 |
import android.webkit.WebView; |
| 29 | 29 |
import android.widget.LinearLayout; |
| 30 | 30 |
|
| 31 |
import androidx.appcompat.app.AppCompatActivity; |
|
| 32 |
|
|
| 31 | 33 |
import com.google.firebase.analytics.FirebaseAnalytics; |
| 32 | 34 |
|
| 33 | 35 |
import org.distorted.library.main.DistortedLibrary; |
| ... | ... | |
| 36 | 38 |
import org.distorted.objectlib.main.ObjectControl; |
| 37 | 39 |
import org.distorted.objectlib.main.ObjectType; |
| 38 | 40 |
import org.distorted.objectlib.helpers.BlockController; |
| 39 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
| 40 | 41 |
|
| 41 | 42 |
import org.distorted.main.R; |
| 42 | 43 |
import org.distorted.dialogs.RubikDialogError; |
| ... | ... | |
| 45 | 46 |
|
| 46 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 47 | 48 |
|
| 48 |
public class TutorialActivity extends TwistyActivity
|
|
| 49 |
public class TutorialActivity extends AppCompatActivity
|
|
| 49 | 50 |
{
|
| 50 | 51 |
private static final String URL = "https://www.youtube.com/embed/"; |
| 51 | 52 |
|
| src/main/java/org/distorted/tutorials/TutorialObjectLibInterface.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 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.tutorials; |
|
| 21 |
|
|
| 22 |
import org.distorted.library.main.DistortedScreen; |
|
| 23 |
import org.distorted.objectlib.helpers.ObjectLibInterface; |
|
| 24 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 25 |
import org.distorted.objectlib.main.ObjectType; |
|
| 26 |
|
|
| 27 |
import java.lang.ref.WeakReference; |
|
| 28 |
|
|
| 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 30 |
|
|
| 31 |
public class TutorialObjectLibInterface implements ObjectLibInterface |
|
| 32 |
{
|
|
| 33 |
WeakReference<TutorialActivity> mAct; |
|
| 34 |
|
|
| 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 36 |
|
|
| 37 |
TutorialObjectLibInterface(TutorialActivity act) |
|
| 38 |
{
|
|
| 39 |
mAct = new WeakReference<>(act); |
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
public void onWinEffectFinished(String debug, int scrambleNum) { }
|
|
| 43 |
public void onScrambleEffectFinished() { }
|
|
| 44 |
public void onBeginRotation() { }
|
|
| 45 |
public void onSolved() { }
|
|
| 46 |
public int getCurrentColor() { return 0; }
|
|
| 47 |
public int cubitIsLocked(ObjectType type, int cubit) { return 0; }
|
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
public void onFinishRotation(int axis, int row, int angle) |
|
| 52 |
{
|
|
| 53 |
TutorialActivity act = mAct.get(); |
|
| 54 |
TutorialScreen state = act.getState(); |
|
| 55 |
state.addMove(act, axis, row, angle); |
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 59 |
|
|
| 60 |
public void failedToDrag() |
|
| 61 |
{
|
|
| 62 |
TutorialActivity act = mAct.get(); |
|
| 63 |
TutorialScreen state = act.getState(); |
|
| 64 |
state.reddenLock(act); |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
|
|
| 69 |
public ObjectControl getControl() |
|
| 70 |
{
|
|
| 71 |
TutorialActivity act = mAct.get(); |
|
| 72 |
return act.getControl(); |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
|
|
| 77 |
public DistortedScreen getScreen() |
|
| 78 |
{
|
|
| 79 |
TutorialActivity act = mAct.get(); |
|
| 80 |
return act.getScreen(); |
|
| 81 |
} |
|
| 82 |
} |
|
| src/main/java/org/distorted/tutorials/TutorialObjectStateActioner.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 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.tutorials; |
|
| 21 |
|
|
| 22 |
import org.distorted.objectlib.helpers.ObjectStateActioner; |
|
| 23 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
| 24 |
import org.distorted.objectlib.main.ObjectType; |
|
| 25 |
|
|
| 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 27 |
|
|
| 28 |
public class TutorialObjectStateActioner implements ObjectStateActioner |
|
| 29 |
{
|
|
| 30 |
public void onWinEffectFinished(TwistyActivity act, String debug, int scrambleNum) { }
|
|
| 31 |
public void onScrambleEffectFinished(TwistyActivity act) { }
|
|
| 32 |
public void onBeginRotation(TwistyActivity act) { }
|
|
| 33 |
public void onSolved() { }
|
|
| 34 |
public int getCurrentColor() { return 0; }
|
|
| 35 |
public int cubitIsLocked(ObjectType type, int cubit) { return 0; }
|
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
public void onFinishRotation(TwistyActivity act, int axis, int row, int angle) |
|
| 40 |
{
|
|
| 41 |
TutorialActivity tact = (TutorialActivity)act; |
|
| 42 |
TutorialScreen state = tact.getState(); |
|
| 43 |
state.addMove(act,axis, row, angle); |
|
| 44 |
} |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
public void failedToDrag(TwistyActivity act) |
|
| 49 |
{
|
|
| 50 |
final TutorialActivity tact = (TutorialActivity)act; |
|
| 51 |
TutorialScreen state = tact.getState(); |
|
| 52 |
state.reddenLock(act); |
|
| 53 |
} |
|
| 54 |
} |
|
| src/main/java/org/distorted/tutorials/TutorialScreen.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.tutorials; |
| 21 | 21 |
|
| 22 |
import android.app.Activity; |
|
| 22 | 23 |
import android.view.View; |
| 23 | 24 |
import android.widget.ImageButton; |
| 24 | 25 |
import android.widget.LinearLayout; |
| ... | ... | |
| 26 | 27 |
import org.distorted.helpers.MovesController; |
| 27 | 28 |
import org.distorted.objectlib.main.ObjectControl; |
| 28 | 29 |
import org.distorted.objectlib.main.ObjectType; |
| 29 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
| 30 | 30 |
|
| 31 | 31 |
import org.distorted.helpers.LockController; |
| 32 | 32 |
import org.distorted.main.R; |
| ... | ... | |
| 107 | 107 |
LinearLayout layout = act.findViewById(R.id.tutorialRightBar); |
| 108 | 108 |
layout.removeAllViews(); |
| 109 | 109 |
|
| 110 |
mMovesController.setupButton(act,width); |
|
| 111 |
mLockController.setupButton(act,act.getControl(),width); |
|
| 110 |
ObjectControl control = act.getControl(); |
|
| 111 |
mMovesController.setupButton(act,control, width); |
|
| 112 |
mLockController.setupButton(act,control,width); |
|
| 112 | 113 |
setupSolveButton(act,width); |
| 113 | 114 |
setupScrambleButton(act,width); |
| 114 | 115 |
setupBackButton(act,width); |
| ... | ... | |
| 122 | 123 |
|
| 123 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 124 | 125 |
|
| 125 |
void addMove(TwistyActivity act, int axis, int row, int angle)
|
|
| 126 |
void addMove(Activity act, int axis, int row, int angle) |
|
| 126 | 127 |
{
|
| 127 | 128 |
mMovesController.addMove(act, axis,row,angle); |
| 128 | 129 |
} |
| ... | ... | |
| 138 | 139 |
|
| 139 | 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 140 | 141 |
|
| 141 |
public void reddenLock(final TwistyActivity act)
|
|
| 142 |
public void reddenLock(final TutorialActivity act)
|
|
| 142 | 143 |
{
|
| 143 |
mLockController.reddenLock(act,act.getControl()); |
|
| 144 |
ObjectControl control = act.getControl(); |
|
| 145 |
mLockController.reddenLock(act,control); |
|
| 144 | 146 |
} |
| 145 | 147 |
} |
| src/main/java/org/distorted/tutorials/TutorialSurfaceView.java | ||
|---|---|---|
| 82 | 82 |
if(!isInEditMode()) |
| 83 | 83 |
{
|
| 84 | 84 |
TutorialActivity act = (TutorialActivity)context; |
| 85 |
mObjectController = new ObjectControl(act,new TutorialObjectStateActioner()); |
|
| 85 |
TutorialObjectLibInterface ref = new TutorialObjectLibInterface(act); |
|
| 86 |
mObjectController = new ObjectControl(act,ref); |
|
| 86 | 87 |
mRenderer = new TutorialRenderer(this); |
| 87 | 88 |
|
| 88 | 89 |
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
Also available in: Unified diff
Remove the concept of a 'TwistyActivity' altogether.