Project

General

Profile

« Previous | Next » 

Revision 8e1231ae

Added by Leszek Koltunski almost 5 years ago

Saving Cube state: done

View differences:

src/main/java/org/distorted/object/RubikCube.java
373 373
      }
374 374

  
375 375
///////////////////////////////////////////////////////////////////////////////////////////////////
376
// mSize already saved as RubikStatePlay.mButton
376 377

  
377 378
   public void savePreferences(SharedPreferences.Editor editor)
378 379
     {
379
     android.util.Log.e("cube", "saving Preferences");
380
     float qx,qy,qz,qw;
381

  
382
     for(int x=0; x<mSize; x++)
383
        for(int y=0; y<mSize; y++)
384
          for(int z=0; z<mSize; z++)
385
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
386
              {
387
              qx = mQuatScramble[x][y][z].get0();
388
              qy = mQuatScramble[x][y][z].get1();
389
              qz = mQuatScramble[x][y][z].get2();
390
              qw = mQuatScramble[x][y][z].get3();
391

  
392
              editor.putFloat("qx_"+x+"_"+y+"_"+z, qx);
393
              editor.putFloat("qy_"+x+"_"+y+"_"+z, qy);
394
              editor.putFloat("qz_"+x+"_"+y+"_"+z, qz);
395
              editor.putFloat("qw_"+x+"_"+y+"_"+z, qw);
396
              }
380 397
     }
381 398

  
382 399
///////////////////////////////////////////////////////////////////////////////////////////////////
383 400

  
384 401
   public void restorePreferences(SharedPreferences preferences)
385 402
     {
386
     android.util.Log.e("cube", "restoring Preferences");
403
     float qx,qy,qz,qw;
404

  
405
     for(int x=0; x<mSize; x++)
406
        for(int y=0; y<mSize; y++)
407
          for(int z=0; z<mSize; z++)
408
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
409
              {
410
              qx = preferences.getFloat("qx_"+x+"_"+y+"_"+z, 0.0f);
411
              qy = preferences.getFloat("qy_"+x+"_"+y+"_"+z, 0.0f);
412
              qz = preferences.getFloat("qz_"+x+"_"+y+"_"+z, 0.0f);
413
              qw = preferences.getFloat("qw_"+x+"_"+y+"_"+z, 1.0f);
414

  
415
              mQuatScramble[x][y][z].set(qx,qy,qz,qw);
416
              modifyCurrentPosition(x, y, z, mQuatScramble[x][y][z]);
417
              }
387 418
     }
388 419

  
389 420
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/uistate/RubikStatePlay.java
43 43
  private static final int MIN_SCRAMBLE =  1;
44 44
  private static final int DEF_SCRAMBLE =  1;
45 45
  public  static final int MAX_SCRAMBLE = 18;
46
  private static final int DEF_BUTTON   = RubikObject.CUBE3.ordinal();
46 47

  
47 48
  private HorizontalNumberPicker mPicker;
48 49
  private int mPickerValue;
49
  private int mButton = RubikObject.CUBE3.ordinal();
50
  private int mButton = DEF_BUTTON;
50 51

  
51 52
///////////////////////////////////////////////////////////////////////////////////////////////////
52 53

  
......
120 121
      {
121 122
      editor.putInt("scramble", mPicker.getValue() );
122 123
      }
124

  
125
    editor.putInt("button", mButton);
123 126
    }
124 127

  
125 128
///////////////////////////////////////////////////////////////////////////////////////////////////
......
127 130
  public void restorePreferences(SharedPreferences preferences)
128 131
    {
129 132
    mPickerValue= preferences.getInt("scramble", DEF_SCRAMBLE);
133
    mButton     = preferences.getInt("button"  , DEF_BUTTON  );
130 134
    }
131 135

  
132 136
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff