Revision 0333d81e
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java | ||
|---|---|---|
| 28 | 28 |
import android.widget.LinearLayout; |
| 29 | 29 |
|
| 30 | 30 |
import org.distorted.network.RubikScoresDownloader; |
| 31 |
import org.distorted.object.RubikObject;
|
|
| 32 |
import org.distorted.uistate.RubikStatePlay;
|
|
| 31 |
import static org.distorted.object.RubikObject.LENGTH;
|
|
| 32 |
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
|
|
| 33 | 33 |
|
| 34 | 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 35 | 35 |
|
| ... | ... | |
| 49 | 49 |
|
| 50 | 50 |
addPage(mViews[c],country[c],name[c],time[c]); |
| 51 | 51 |
|
| 52 |
for(int i = 0; i< RubikObject.LENGTH; i++)
|
|
| 52 |
for(int i=0; i<LENGTH; i++)
|
|
| 53 | 53 |
{
|
| 54 | 54 |
if( i==c ) continue; |
| 55 | 55 |
|
| ... | ... | |
| 66 | 66 |
@Override |
| 67 | 67 |
public void run() |
| 68 | 68 |
{
|
| 69 |
for(int i = 0; i< RubikObject.LENGTH; i++)
|
|
| 69 |
for(int i=0; i<LENGTH; i++)
|
|
| 70 | 70 |
{
|
| 71 | 71 |
mViews[i].prepareView(mAct); |
| 72 | 72 |
} |
| ... | ... | |
| 86 | 86 |
|
| 87 | 87 |
private void addPage(final RubikDialogScoresView view, final String[][] country, final String[][] name, final String[][] time) |
| 88 | 88 |
{
|
| 89 |
for(int i=0; i<RubikStatePlay.MAX_SCRAMBLE; i++)
|
|
| 89 |
for(int i=0; i<MAX_SCRAMBLE; i++) |
|
| 90 | 90 |
{
|
| 91 | 91 |
final LinearLayout section = view.createSection(mAct, i, country[i], name[i], time[i]); |
| 92 | 92 |
|
| ... | ... | |
| 119 | 119 |
@Override |
| 120 | 120 |
public void run() |
| 121 | 121 |
{
|
| 122 |
for(int i = 0; i< RubikObject.LENGTH; i++)
|
|
| 122 |
for(int i=0; i<LENGTH; i++)
|
|
| 123 | 123 |
{
|
| 124 | 124 |
mViews[i].exception(exce); |
| 125 | 125 |
} |
| ... | ... | |
| 132 | 132 |
RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager) |
| 133 | 133 |
{
|
| 134 | 134 |
mAct = act; |
| 135 |
mViews = new RubikDialogScoresView[RubikObject.LENGTH];
|
|
| 135 |
mViews = new RubikDialogScoresView[LENGTH]; |
|
| 136 | 136 |
mViewPager = viewPager; |
| 137 | 137 |
|
| 138 | 138 |
viewPager.setAdapter(this); |
| 139 |
viewPager.setOffscreenPageLimit( RubikObject.LENGTH-1 );
|
|
| 139 |
viewPager.setOffscreenPageLimit(LENGTH-1);
|
|
| 140 | 140 |
} |
| 141 | 141 |
|
| 142 | 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 150 | 150 |
|
| 151 | 151 |
boolean allCreated = true; |
| 152 | 152 |
|
| 153 |
for(int i = 0; i< RubikObject.LENGTH; i++)
|
|
| 153 |
for(int i=0; i<LENGTH; i++)
|
|
| 154 | 154 |
{
|
| 155 | 155 |
if( mViews[i]==null ) |
| 156 | 156 |
{
|
| ... | ... | |
| 181 | 181 |
@Override |
| 182 | 182 |
public int getCount() |
| 183 | 183 |
{
|
| 184 |
return RubikObject.LENGTH;
|
|
| 184 |
return LENGTH; |
|
| 185 | 185 |
} |
| 186 | 186 |
|
| 187 | 187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/dialog/RubikDialogScoresView.java | ||
|---|---|---|
| 30 | 30 |
import android.widget.TextView; |
| 31 | 31 |
|
| 32 | 32 |
import org.distorted.magic.R; |
| 33 |
import org.distorted.network.RubikScoresDownloader;
|
|
| 33 |
import static org.distorted.network.RubikScoresDownloader.MAX_PLACES;
|
|
| 34 | 34 |
|
| 35 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 36 | 36 |
|
| ... | ... | |
| 73 | 73 |
Resources res = act.getResources(); |
| 74 | 74 |
String packageName = act.getPackageName(); |
| 75 | 75 |
|
| 76 |
for(int j = 0; j< RubikScoresDownloader.MAX_PLACES; j++)
|
|
| 76 |
for(int j=0; j<MAX_PLACES; j++)
|
|
| 77 | 77 |
{
|
| 78 | 78 |
if( name[j] != null ) |
| 79 | 79 |
{
|
| src/main/java/org/distorted/magic/RubikActivity.java | ||
|---|---|---|
| 128 | 128 |
} |
| 129 | 129 |
|
| 130 | 130 |
RubikState.savePreferences(editor); |
| 131 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
| 132 |
view.getRenderer().savePreferences(editor); |
|
| 133 |
|
|
| 131 | 134 |
editor.apply(); |
| 132 | 135 |
} |
| 133 | 136 |
|
| ... | ... | |
| 148 | 151 |
} |
| 149 | 152 |
|
| 150 | 153 |
RubikState.restorePreferences(preferences); |
| 154 |
|
|
| 155 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
| 156 |
view.getRenderer().restorePreferences(preferences); |
|
| 151 | 157 |
} |
| 152 | 158 |
|
| 153 | 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/magic/RubikRenderer.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.magic; |
| 21 | 21 |
|
| 22 |
import android.content.SharedPreferences; |
|
| 22 | 23 |
import android.opengl.GLSurfaceView; |
| 23 | 24 |
|
| 24 | 25 |
import org.distorted.effect.BaseEffect; |
| ... | ... | |
| 33 | 34 |
import org.distorted.object.RubikObject; |
| 34 | 35 |
import org.distorted.uistate.RubikState; |
| 35 | 36 |
import org.distorted.uistate.RubikStatePlay; |
| 37 |
import org.distorted.uistate.RubikStateSolving; |
|
| 36 | 38 |
|
| 37 | 39 |
import javax.microedition.khronos.egl.EGLConfig; |
| 38 | 40 |
import javax.microedition.khronos.opengles.GL10; |
| ... | ... | |
| 133 | 135 |
} |
| 134 | 136 |
} |
| 135 | 137 |
|
| 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 139 |
|
|
| 140 |
void savePreferences(SharedPreferences.Editor editor) |
|
| 141 |
{
|
|
| 142 |
android.util.Log.e("renderer", "saving prefs");
|
|
| 143 |
|
|
| 144 |
//editor.putInt("state", mCurrentState.ordinal() );
|
|
| 145 |
} |
|
| 146 |
|
|
| 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 148 |
|
|
| 149 |
void restorePreferences(SharedPreferences preferences) |
|
| 150 |
{
|
|
| 151 |
android.util.Log.e("renderer", "restoring prefs");
|
|
| 152 |
|
|
| 153 |
//int stateOrdinal = preferences.getInt("state", RubikState.MAIN.ordinal() );
|
|
| 154 |
} |
|
| 155 |
|
|
| 136 | 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 137 | 157 |
// no this will not race with onDrawFrame |
| 138 | 158 |
|
| ... | ... | |
| 242 | 262 |
|
| 243 | 263 |
if( solved && !mIsSolved ) |
| 244 | 264 |
{
|
| 245 |
mCanDrag = true; |
|
| 246 |
mCanRotate = false; |
|
| 247 |
mCanUI = false; |
|
| 265 |
if( RubikState.getCurrentState()==RubikState.SOLV ) |
|
| 266 |
{
|
|
| 267 |
RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass(); |
|
| 268 |
long time = solving.stopCounting(); |
|
| 269 |
android.util.Log.e("renderer", "solving time: "+time+" milliseconds");
|
|
| 270 |
} |
|
| 271 |
|
|
| 272 |
mCanDrag = true; |
|
| 273 |
mCanRotate = false; |
|
| 274 |
mCanUI = false; |
|
| 248 | 275 |
doEffectNow( BaseEffect.Type.WIN ); |
| 249 | 276 |
} |
| 250 | 277 |
else |
| src/main/java/org/distorted/magic/RubikSurfaceView.java | ||
|---|---|---|
| 30 | 30 |
import org.distorted.library.type.Static4D; |
| 31 | 31 |
import org.distorted.object.RubikCube; |
| 32 | 32 |
import org.distorted.object.RubikCubeMovement; |
| 33 |
import org.distorted.uistate.RubikState; |
|
| 34 |
import org.distorted.uistate.RubikStateSolving; |
|
| 33 | 35 |
|
| 34 | 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 35 | 37 |
|
| ... | ... | |
| 221 | 223 |
Static4D rotatedTouchPoint1= rotateVectorByInvertedQuat(touchPoint1, mQuatAccumulated); |
| 222 | 224 |
Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuatAccumulated); |
| 223 | 225 |
|
| 224 |
if( mMovement.faceTouched(rotatedTouchPoint1, rotatedCamera) )
|
|
| 226 |
if( mMovement.faceTouched(rotatedTouchPoint1,rotatedCamera) ) |
|
| 225 | 227 |
{
|
| 226 | 228 |
mDragging = false; |
| 227 | 229 |
mBeginningRotation = mRenderer.canRotate(); |
| ... | ... | |
| 261 | 263 |
|
| 262 | 264 |
cube.addNewRotation( (int)rot.get0(), (int)(cube.getSize()*rot.get1()) ); |
| 263 | 265 |
|
| 266 |
if( RubikState.getCurrentState()==RubikState.SOLV ) |
|
| 267 |
{
|
|
| 268 |
RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass(); |
|
| 269 |
solving.startCounting( (RubikActivity)getContext() ); |
|
| 270 |
} |
|
| 271 |
|
|
| 264 | 272 |
mBeginningRotation = false; |
| 265 | 273 |
mContinuingRotation= true; |
| 266 | 274 |
} |
| src/main/java/org/distorted/network/RubikScoresDownloader.java | ||
|---|---|---|
| 184 | 184 |
private boolean doDownload() |
| 185 | 185 |
{
|
| 186 | 186 |
String version = R.string.app_version+"d"; |
| 187 |
|
|
| 188 | 187 |
String message=URL+"/download.cgi?n="+URLencode(mUserName)+"&r="+mNumRuns+"&e="+version; |
| 189 | 188 |
|
| 190 | 189 |
try |
| src/main/java/org/distorted/object/RubikObject.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.object; |
| 21 | 21 |
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 | 22 |
import org.distorted.magic.R; |
| 25 | 23 |
|
| 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 25 |
|
|
| 26 | 26 |
public enum RubikObject |
| 27 | 27 |
{
|
| 28 | 28 |
CUBE2 ( 2, R.drawable.button2 ), |
| src/main/java/org/distorted/uistate/RubikStateSolving.java | ||
|---|---|---|
| 29 | 29 |
import org.distorted.magic.R; |
| 30 | 30 |
import org.distorted.magic.RubikActivity; |
| 31 | 31 |
|
| 32 |
import java.util.Timer; |
|
| 33 |
import java.util.TimerTask; |
|
| 34 |
|
|
| 32 | 35 |
import static android.view.View.INVISIBLE; |
| 33 | 36 |
|
| 34 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 35 | 38 |
|
| 36 | 39 |
public class RubikStateSolving extends RubikStateAbstract |
| 37 | 40 |
{
|
| 41 |
private TextView mTime; |
|
| 42 |
private Timer mTimer; |
|
| 43 |
private long mStartTime; |
|
| 44 |
private boolean mRunning; |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 38 | 48 |
public void leaveState(RubikActivity act) |
| 39 | 49 |
{
|
| 40 |
|
|
| 50 |
stopCounting(); |
|
| 41 | 51 |
} |
| 42 | 52 |
|
| 43 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 49 | 59 |
// TOP //////////////////////////// |
| 50 | 60 |
LinearLayout layoutTop = act.findViewById(R.id.mainTitle); |
| 51 | 61 |
layoutTop.removeAllViews(); |
| 52 |
final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
|
|
| 53 |
text.setText(R.string.ready);
|
|
| 54 |
layoutTop.addView(text);
|
|
| 62 |
mTime = (TextView)inflater.inflate(R.layout.upper_text, null);
|
|
| 63 |
mTime.setText(R.string.ready);
|
|
| 64 |
layoutTop.addView(mTime);
|
|
| 55 | 65 |
|
| 56 | 66 |
// BOT //////////////////////////// |
| 57 | 67 |
LinearLayout layoutBot = act.findViewById(R.id.mainBar); |
| ... | ... | |
| 95 | 105 |
{
|
| 96 | 106 |
|
| 97 | 107 |
} |
| 108 |
|
|
| 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 110 |
|
|
| 111 |
public void startCounting(final RubikActivity act) |
|
| 112 |
{
|
|
| 113 |
if( !mRunning ) |
|
| 114 |
{
|
|
| 115 |
mRunning = true; |
|
| 116 |
mStartTime = System.currentTimeMillis(); |
|
| 117 |
mTimer = new Timer(); |
|
| 118 |
|
|
| 119 |
mTimer.scheduleAtFixedRate(new TimerTask() |
|
| 120 |
{
|
|
| 121 |
@Override |
|
| 122 |
public void run() |
|
| 123 |
{
|
|
| 124 |
act.runOnUiThread(new Runnable() |
|
| 125 |
{
|
|
| 126 |
@Override |
|
| 127 |
public void run() |
|
| 128 |
{
|
|
| 129 |
int elapsed = (int)(System.currentTimeMillis()-mStartTime)/1000; |
|
| 130 |
mTime.setText(act.getString(R.string.tm_placeholder,elapsed/60,elapsed%60)); |
|
| 131 |
} |
|
| 132 |
}); |
|
| 133 |
} |
|
| 134 |
}, 0, 1000); |
|
| 135 |
} |
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 139 |
|
|
| 140 |
public long stopCounting() |
|
| 141 |
{
|
|
| 142 |
if( mRunning ) |
|
| 143 |
{
|
|
| 144 |
if( mTimer!=null ) |
|
| 145 |
{
|
|
| 146 |
mTimer.cancel(); |
|
| 147 |
mTimer = null; |
|
| 148 |
} |
|
| 149 |
mRunning = false; |
|
| 150 |
|
|
| 151 |
return System.currentTimeMillis()-mStartTime; |
|
| 152 |
} |
|
| 153 |
|
|
| 154 |
return 0; |
|
| 155 |
} |
|
| 98 | 156 |
} |
| src/main/res/values/strings.xml | ||
|---|---|---|
| 25 | 25 |
|
| 26 | 26 |
<string name="ms_placeholder">%1$d ms</string> |
| 27 | 27 |
<string name="sc_placeholder">Scramble %1$d</string> |
| 28 |
<string name="tm_placeholder">%1$02d:%2$02d</string> |
|
| 28 | 29 |
</resources> |
Also available in: Unified diff
Progress with StateSolving