Revision 6918030e
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/magic/RubikActivity.java | ||
|---|---|---|
| 22 | 22 | import android.content.SharedPreferences; | 
| 23 | 23 | import android.os.Bundle; | 
| 24 | 24 | import android.preference.PreferenceManager; | 
| 25 | import android.support.v4.app.FragmentManager; | |
| 26 | 25 | import android.support.v7.app.AppCompatActivity; | 
| 27 | 26 | import android.view.View; | 
| 28 | 27 |  | 
| ... | ... | |
| 43 | 42 | super.onCreate(savedState); | 
| 44 | 43 | setTheme(R.style.CustomActivityThemeNoActionBar); | 
| 45 | 44 | setContentView(R.layout.main); | 
| 46 |  | |
| 47 | if( savedState==null ) | |
| 48 |         {
 | |
| 49 | RubikDialogMain diag = new RubikDialogMain(); | |
| 50 | diag.show(getSupportFragmentManager(), RubikDialogMain.getDialogTag() ); | |
| 51 | } | |
| 52 | 45 | } | 
| 53 | 46 |  | 
| 54 | 47 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| ... | ... | |
| 113 | 106 |           {
 | 
| 114 | 107 | RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); | 
| 115 | 108 | view.enterState(this, mCurrentState); | 
| 116 |  | |
| 117 | RubikDialogMain diag = new RubikDialogMain(); | |
| 118 | diag.show(getSupportFragmentManager(), RubikDialogMain.getDialogTag() ); | |
| 119 | 109 | } | 
| 120 | 110 | else | 
| 121 | 111 |           {
 | 
| ... | ... | |
| 169 | 159 |  | 
| 170 | 160 | public void Play(View v) | 
| 171 | 161 |       {
 | 
| 172 | FragmentManager mana = getSupportFragmentManager(); | |
| 173 | RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag()); | |
| 174 |  | |
| 175 | if( diag!=null ) | |
| 176 |         {
 | |
| 177 | diag.dismiss(); | |
| 178 | } | |
| 179 | else | |
| 180 |         {
 | |
| 181 |         android.util.Log.e("act", "cannot find main dialog!");
 | |
| 182 | } | |
| 183 |  | |
| 184 | 162 | mCurrentState = RubikState.PLAY; | 
| 185 | 163 | RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); | 
| 186 | 164 | view.enterState(this,mCurrentState); | 
| src/main/java/org/distorted/magic/RubikSurfaceView.java | ||
|---|---|---|
| 26 | 26 | import android.graphics.PorterDuff; | 
| 27 | 27 | import android.graphics.drawable.Drawable; | 
| 28 | 28 | import android.opengl.GLSurfaceView; | 
| 29 | import android.support.v4.app.FragmentManager; | |
| 29 | 30 | import android.support.v4.content.ContextCompat; | 
| 30 | 31 | import android.util.AttributeSet; | 
| 31 | 32 | import android.util.DisplayMetrics; | 
| ... | ... | |
| 70 | 71 | private int mScreenWidth, mScreenHeight, mScreenMin; | 
| 71 | 72 |  | 
| 72 | 73 | private HorizontalNumberPicker mPicker; | 
| 73 | private int mScrambleValue; | |
| 74 | private int mPickerValue; | |
| 75 | private RubikState mCurrentState; | |
| 74 | 76 |  | 
| 75 | 77 | private static int mButton = RubikSize.SIZE3.ordinal(); | 
| 76 | 78 | private static Static4D mQuatCurrent = new Static4D(0,0,0,1); | 
| ... | ... | |
| 90 | 92 |  | 
| 91 | 93 | void savePreferences(SharedPreferences.Editor editor) | 
| 92 | 94 |       {
 | 
| 93 |       editor.putInt("scramble", mScrambleValue );
 | |
| 95 | if( mPicker!=null ) | |
| 96 |         {
 | |
| 97 |         editor.putInt("scramble", mPicker.getValue() );
 | |
| 98 | } | |
| 94 | 99 | } | 
| 95 | 100 |  | 
| 96 | 101 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 97 | 102 |  | 
| 98 | 103 | void restorePreferences(SharedPreferences preferences) | 
| 99 | 104 |       {
 | 
| 100 |       mScrambleValue= preferences.getInt("scramble", DEF_SCRAMBLE);
 | |
| 105 |       mPickerValue= preferences.getInt("scramble", DEF_SCRAMBLE);
 | |
| 101 | 106 | } | 
| 102 | 107 |  | 
| 103 | 108 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| ... | ... | |
| 260 | 265 |  | 
| 261 | 266 | void enterState(RubikActivity act, RubikState state) | 
| 262 | 267 |       {
 | 
| 263 | switch(state) | |
| 268 | if( mCurrentState!=state ) | |
| 269 |         {
 | |
| 270 | switch(state) | |
| 271 |           {
 | |
| 272 | case MAIN: enterMainState(act); break; | |
| 273 | case PLAY: enterPlayState(act); break; | |
| 274 | } | |
| 275 |  | |
| 276 | if( mCurrentState==RubikState.PLAY ) | |
| 277 |           {
 | |
| 278 | mPickerValue = mPicker.getValue(); | |
| 279 | } | |
| 280 | if( mCurrentState==RubikState.MAIN ) | |
| 281 |           {
 | |
| 282 | FragmentManager mana = act.getSupportFragmentManager(); | |
| 283 | RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag()); | |
| 284 |  | |
| 285 | if( diag!=null ) | |
| 286 |             {
 | |
| 287 | diag.dismiss(); | |
| 288 | } | |
| 289 | else | |
| 290 |             {
 | |
| 291 |             android.util.Log.e("act", "cannot find main dialog!");
 | |
| 292 | } | |
| 293 | } | |
| 294 | if( state==RubikState.MAIN ) | |
| 295 |           {
 | |
| 296 | FragmentManager mana = act.getSupportFragmentManager(); | |
| 297 | RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag()); | |
| 298 |  | |
| 299 | if( diag==null ) | |
| 300 |             {
 | |
| 301 | RubikDialogMain diag2 = new RubikDialogMain(); | |
| 302 | diag2.show( mana, RubikDialogMain.getDialogTag() ); | |
| 303 | } | |
| 304 | } | |
| 305 |  | |
| 306 | mCurrentState = state; | |
| 307 | } | |
| 308 | else | |
| 264 | 309 |         {
 | 
| 265 | case MAIN: enterMainState(act); break; | |
| 266 | case PLAY: enterPlayState(act); break; | |
| 310 |         android.util.Log.e("act", "trying to change into same state "+state);
 | |
| 267 | 311 | } | 
| 268 | 312 | } | 
| 269 | 313 |  | 
| ... | ... | |
| 361 | 405 |         {
 | 
| 362 | 406 | mPicker.setMin(MIN_SCRAMBLE); | 
| 363 | 407 | mPicker.setMax(MAX_SCRAMBLE); | 
| 364 |         mPicker.setValue(mScrambleValue);
 | |
| 408 |         mPicker.setValue(mPickerValue);
 | |
| 365 | 409 | } | 
| 366 | 410 | } | 
| 367 | 411 |  | 
| ... | ... | |
| 378 | 422 | mRenderer = new RubikRenderer(this); | 
| 379 | 423 | mMovement = new RubikCubeMovement(); | 
| 380 | 424 |  | 
| 425 | mCurrentState = null; | |
| 426 |  | |
| 381 | 427 | final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | 
| 382 | 428 | final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); | 
| 383 | 429 | setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); | 
Also available in: Unified diff
Major rearrangement of the UI.