Revision 88b94310
Added by Leszek Koltunski over 3 years ago
| src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.bandaged; |
| 21 | 21 |
|
| 22 |
import android.content.Intent; |
|
| 22 | 23 |
import android.content.SharedPreferences; |
| 23 | 24 |
import android.graphics.Bitmap; |
| 24 | 25 |
import android.os.Build; |
| ... | ... | |
| 272 | 273 |
|
| 273 | 274 |
public void playObject(String name) |
| 274 | 275 |
{
|
| 275 |
|
|
| 276 |
Intent intent = new Intent(this, BandagedPlayActivity.class); |
|
| 277 |
intent.putExtra("name", name);
|
|
| 278 |
startActivity(intent); |
|
| 276 | 279 |
} |
| 277 | 280 |
|
| 278 | 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/bandaged/BandagedPlayActivity.java | ||
|---|---|---|
| 32 | 32 |
import com.google.firebase.analytics.FirebaseAnalytics; |
| 33 | 33 |
|
| 34 | 34 |
import org.distorted.dialogs.RubikDialogError; |
| 35 |
import org.distorted.external.RubikFiles; |
|
| 35 | 36 |
import org.distorted.library.main.DistortedLibrary; |
| 36 | 37 |
import org.distorted.main.R; |
| 37 | 38 |
import org.distorted.objectlib.main.ObjectControl; |
| 38 | 39 |
import org.distorted.objectlib.main.TwistyObject; |
| 39 |
import org.distorted.objects.RubikObject; |
|
| 40 |
import org.distorted.objects.RubikObjectList; |
|
| 41 | 40 |
|
| 42 | 41 |
import java.io.InputStream; |
| 43 | 42 |
|
| ... | ... | |
| 50 | 49 |
|
| 51 | 50 |
public static final float DIALOG_BUTTON_SIZE = 0.06f; |
| 52 | 51 |
public static final float MENU_BIG_TEXT_SIZE = 0.05f; |
| 52 |
public static final float BUTTON_TEXT_SIZE = 0.05f; |
|
| 53 | 53 |
|
| 54 | 54 |
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 55 | 55 |
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| ... | ... | |
| 61 | 61 |
private static int mScreenWidth, mScreenHeight; |
| 62 | 62 |
private int mCurrentApiVersion; |
| 63 | 63 |
private BandagedPlayScreen mScreen; |
| 64 |
private int mObjectOrdinal;
|
|
| 64 |
private String mObjectName;
|
|
| 65 | 65 |
private int mHeightBar; |
| 66 | 66 |
|
| 67 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 75 | 75 |
setContentView(R.layout.bandaged_play); |
| 76 | 76 |
|
| 77 | 77 |
Bundle b = getIntent().getExtras(); |
| 78 |
|
|
| 79 |
if(b != null) mObjectOrdinal = b.getInt("obj");
|
|
| 78 |
mObjectName = b!=null ? b.getString("name") : "";
|
|
| 80 | 79 |
|
| 81 | 80 |
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); |
| 82 | 81 |
|
| ... | ... | |
| 178 | 177 |
view.onResume(); |
| 179 | 178 |
|
| 180 | 179 |
if( mScreen==null ) mScreen = new BandagedPlayScreen(); |
| 181 |
mScreen.onAttachedToWindow(this,mObjectOrdinal);
|
|
| 180 |
mScreen.onAttachedToWindow(this,mObjectName);
|
|
| 182 | 181 |
|
| 183 |
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
|
|
| 182 |
if( mObjectName.length()>0 )
|
|
| 184 | 183 |
{
|
| 185 |
RubikObject object = RubikObjectList.getObject(mObjectOrdinal); |
|
| 186 |
changeIfDifferent(object,mObjectOrdinal,view.getObjectControl()); |
|
| 184 |
changeIfDifferent(mObjectName,view.getObjectControl()); |
|
| 187 | 185 |
} |
| 188 | 186 |
} |
| 189 | 187 |
|
| ... | ... | |
| 206 | 204 |
|
| 207 | 205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 208 | 206 |
|
| 209 |
private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
|
|
| 207 |
private void changeIfDifferent(String name,ObjectControl control)
|
|
| 210 | 208 |
{
|
| 211 |
if( object!=null ) |
|
| 212 |
{
|
|
| 213 |
int meshState = object.getMeshState(); |
|
| 214 |
int iconMode = TwistyObject.MODE_NORM; |
|
| 215 |
InputStream jsonStream = object.getObjectStream(this); |
|
| 216 |
InputStream meshStream = object.getMeshStream(this); |
|
| 217 |
String name = object.getUpperName(); |
|
| 209 |
RubikFiles files = RubikFiles.getInstance(); |
|
| 218 | 210 |
|
| 219 |
control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream); |
|
| 220 |
} |
|
| 211 |
int meshState = TwistyObject.MESH_NICE; |
|
| 212 |
int iconMode = TwistyObject.MODE_NORM; |
|
| 213 |
InputStream jsonStream = files.openFile(this,name+"_object.json"); |
|
| 214 |
InputStream meshStream = null; |
|
| 215 |
int ordinal = 0; // if jsonStream!=null, this doesn't matter |
|
| 216 |
|
|
| 217 |
control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream); |
|
| 221 | 218 |
} |
| 222 | 219 |
|
| 223 | 220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 224 | 221 |
// PUBLIC API |
| 225 | 222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 226 | 223 |
|
| 227 |
public void changeObject(int ordinal)
|
|
| 224 |
public void changeObject(String name)
|
|
| 228 | 225 |
{
|
| 229 |
mObjectOrdinal = ordinal; |
|
| 230 |
RubikObject object = RubikObjectList.getObject(ordinal); |
|
| 226 |
mObjectName = name; |
|
| 231 | 227 |
BandagedPlayView view = findViewById(R.id.bandagedPlayView); |
| 232 | 228 |
ObjectControl control = view.getObjectControl(); |
| 233 |
changeIfDifferent(object,ordinal,control);
|
|
| 229 |
changeIfDifferent(name,control);
|
|
| 234 | 230 |
} |
| 235 | 231 |
|
| 236 | 232 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 269 | 265 |
return view.getObjectControl(); |
| 270 | 266 |
} |
| 271 | 267 |
|
| 268 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 269 |
|
|
| 270 |
public BandagedPlayScreen getScreen() |
|
| 271 |
{
|
|
| 272 |
return mScreen; |
|
| 273 |
} |
|
| 274 |
|
|
| 272 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 273 | 276 |
|
| 274 | 277 |
public static int getDrawableSize() |
| src/main/java/org/distorted/bandaged/BandagedPlayLibInterface.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.bandaged; |
| 21 | 21 |
|
| 22 |
import java.lang.ref.WeakReference; |
|
| 23 |
|
|
| 22 | 24 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
| 23 | 25 |
|
| 24 | 26 |
import org.distorted.library.message.EffectMessageSender; |
| ... | ... | |
| 30 | 32 |
|
| 31 | 33 |
public class BandagedPlayLibInterface implements ObjectLibInterface |
| 32 | 34 |
{
|
| 35 |
private final WeakReference<BandagedPlayActivity> mAct; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
BandagedPlayLibInterface(BandagedPlayActivity act) |
|
| 40 |
{
|
|
| 41 |
mAct = new WeakReference<>(act); |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 33 | 46 |
public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
|
| 34 | 47 |
public void onScrambleEffectFinished() { }
|
| 35 | 48 |
public void onBeginRotation() { }
|
| ... | ... | |
| 37 | 50 |
public void onObjectCreated(long time) { }
|
| 38 | 51 |
public void onReplaceModeDown(int cubit, int face) { }
|
| 39 | 52 |
public void onReplaceModeUp() { }
|
| 40 |
public void onFinishRotation(int axis, int row, int angle) { }
|
|
| 41 |
public void failedToDrag() { }
|
|
| 53 |
|
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
public void onFinishRotation(int axis, int row, int angle) |
|
| 57 |
{
|
|
| 58 |
BandagedPlayActivity act = mAct.get(); |
|
| 59 |
|
|
| 60 |
if( act!=null ) |
|
| 61 |
{
|
|
| 62 |
BandagedPlayScreen play = act.getScreen(); |
|
| 63 |
play.addMove(act,axis,row,angle); |
|
| 64 |
} |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
|
|
| 69 |
public void failedToDrag() |
|
| 70 |
{
|
|
| 71 |
BandagedPlayActivity act = mAct.get(); |
|
| 72 |
|
|
| 73 |
if( act!=null ) |
|
| 74 |
{
|
|
| 75 |
BandagedPlayScreen play = act.getScreen(); |
|
| 76 |
play.reddenLock(act); |
|
| 77 |
} |
|
| 78 |
} |
|
| 42 | 79 |
|
| 43 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 44 | 81 |
|
| src/main/java/org/distorted/bandaged/BandagedPlayScreen.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.bandaged; |
| 21 | 21 |
|
| 22 |
import android.app.Activity; |
|
| 23 |
import android.content.SharedPreferences; |
|
| 22 | 24 |
import android.view.View; |
| 23 | 25 |
import android.widget.LinearLayout; |
| 24 | 26 |
|
| ... | ... | |
| 26 | 28 |
import org.distorted.helpers.MovesController; |
| 27 | 29 |
import org.distorted.helpers.TransparentImageButton; |
| 28 | 30 |
import org.distorted.main.R; |
| 29 |
import org.distorted.main.RubikActivity; |
|
| 30 | 31 |
import org.distorted.objectlib.main.ObjectControl; |
| 31 | 32 |
|
| 32 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 36 | 37 |
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton; |
| 37 | 38 |
private final LockController mLockController; |
| 38 | 39 |
protected MovesController mMovesController; |
| 39 |
private int mObjectOrdinal;
|
|
| 40 |
private String mObjectName;
|
|
| 40 | 41 |
private int mBarHeight; |
| 41 | 42 |
private float mButtonSize; |
| 42 | 43 |
|
| ... | ... | |
| 52 | 53 |
|
| 53 | 54 |
private void setupBackButton(final BandagedPlayActivity act) |
| 54 | 55 |
{
|
| 55 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
|
|
| 56 |
int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
|
|
| 56 | 57 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
| 57 | 58 |
mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params); |
| 58 | 59 |
|
| ... | ... | |
| 70 | 71 |
|
| 71 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 72 | 73 |
|
| 73 |
void onAttachedToWindow(final BandagedPlayActivity act, final int objectOrdinal)
|
|
| 74 |
void onAttachedToWindow(final BandagedPlayActivity act, final String objectName)
|
|
| 74 | 75 |
{
|
| 75 | 76 |
int width = act.getScreenWidthInPixels(); |
| 76 | 77 |
mBarHeight = act.getHeightBar(); |
| 77 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
|
|
| 78 |
mButtonSize = width*BandagedPlayActivity.BUTTON_TEXT_SIZE;
|
|
| 78 | 79 |
|
| 79 |
mObjectOrdinal = objectOrdinal;
|
|
| 80 |
mObjectName = objectName;
|
|
| 80 | 81 |
|
| 81 | 82 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
| 82 | 83 |
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT); |
| ... | ... | |
| 103 | 104 |
layout.addView(layoutLeft); |
| 104 | 105 |
layout.addView(layoutMid); |
| 105 | 106 |
layout.addView(layoutRight); |
| 106 |
|
|
| 107 | 107 |
} |
| 108 | 108 |
|
| 109 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 110 | 110 |
|
| 111 |
public void setLockState(final RubikActivity act)
|
|
| 111 |
public void setLockState(final BandagedPlayActivity act)
|
|
| 112 | 112 |
{
|
| 113 | 113 |
boolean locked = act.getControl().retLocked(); |
| 114 | 114 |
mLockController.setState(act,locked); |
| ... | ... | |
| 116 | 116 |
|
| 117 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 118 | 118 |
|
| 119 |
public void reddenLock(final RubikActivity act)
|
|
| 119 |
public void reddenLock(final BandagedPlayActivity act)
|
|
| 120 | 120 |
{
|
| 121 | 121 |
ObjectControl control = act.getControl(); |
| 122 | 122 |
mLockController.reddenLock(act,control); |
| 123 | 123 |
} |
| 124 |
|
|
| 125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 126 |
|
|
| 127 |
public void addMove(Activity act, int axis, int row, int angle) |
|
| 128 |
{
|
|
| 129 |
mMovesController.addMove(act,axis,row,angle); |
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 133 |
|
|
| 134 |
public void saveMovePreferences(SharedPreferences.Editor editor) |
|
| 135 |
{
|
|
| 136 |
mMovesController.savePreferences(editor); |
|
| 137 |
} |
|
| 138 |
|
|
| 139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 140 |
|
|
| 141 |
public void restoreMovePreferences(Activity act, SharedPreferences preferences) |
|
| 142 |
{
|
|
| 143 |
mMovesController.restorePreferences(act,preferences); |
|
| 144 |
} |
|
| 124 | 145 |
} |
| src/main/java/org/distorted/bandaged/BandagedPlayView.java | ||
|---|---|---|
| 85 | 85 |
if(!isInEditMode()) |
| 86 | 86 |
{
|
| 87 | 87 |
BandagedPlayActivity act = (BandagedPlayActivity)context; |
| 88 |
BandagedPlayLibInterface ref = new BandagedPlayLibInterface(); |
|
| 88 |
BandagedPlayLibInterface ref = new BandagedPlayLibInterface(act);
|
|
| 89 | 89 |
mObjectController = new ObjectControl(act,ref); |
| 90 | 90 |
mObjectController.setRotateOnCreation(true); |
| 91 | 91 |
mRenderer = new BandagedPlayRenderer(this); |
Also available in: Unified diff
Bandaged 3x3: beginnings of support for the Play Screen.