Revision fcd5b990
Added by Leszek Koltunski over 4 years ago
| src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java | ||
|---|---|---|
| 39 | 39 | 
    import org.distorted.main.RubikActivity;  | 
| 40 | 40 | 
    import org.distorted.objects.ObjectList;  | 
| 41 | 41 | 
    import org.distorted.network.RubikScores;  | 
| 42 | 
    import org.distorted.states.StateList;
   | 
|
| 43 | 
    import org.distorted.states.RubikStatePlay;
   | 
|
| 42 | 
    import org.distorted.screens.ScreenList;
   | 
|
| 43 | 
    import org.distorted.screens.RubikScreenPlay;
   | 
|
| 44 | 44 | 
     | 
| 45 | 45 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 46 | 46 | 
     | 
| ... | ... | |
| 75 | 75 | 
    RubikScores scores = RubikScores.getInstance();  | 
| 76 | 76 | 
    String name = scores.getName();  | 
| 77 | 77 | 
    Bundle bundle = new Bundle();  | 
| 78 | 
            StateList.switchState(act, StateList.PLAY);
   | 
|
| 78 | 
            ScreenList.switchState(act, ScreenList.PLAY);
   | 
|
| 79 | 79 | 
     | 
| 80 | 80 | 
    if( name.length()>0 )  | 
| 81 | 81 | 
              {
   | 
| 82 | 
              RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
   | 
|
| 82 | 
              RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
   | 
|
| 83 | 83 | 
    int object = play.getObject();  | 
| 84 | 84 | 
    int size = play.getSize();  | 
| 85 | 85 | 
    int sizeIndex = ObjectList.getSizeIndex(object,size);  | 
| ... | ... | |
| 108 | 108 | 
    public void onClick(DialogInterface dialog, int which)  | 
| 109 | 109 | 
            {
   | 
| 110 | 110 | 
    RubikActivity act = (RubikActivity)getActivity();  | 
| 111 | 
            StateList.switchState(act, StateList.PLAY);
   | 
|
| 111 | 
            ScreenList.switchState(act, ScreenList.PLAY);
   | 
|
| 112 | 112 | 
    }  | 
| 113 | 113 | 
    });  | 
| 114 | 114 | 
     | 
| src/main/java/org/distorted/dialogs/RubikDialogPatternView.java | ||
|---|---|---|
| 31 | 31 | 
    import org.distorted.objects.ObjectList;  | 
| 32 | 32 | 
    import org.distorted.patterns.RubikPattern;  | 
| 33 | 33 | 
    import org.distorted.patterns.RubikPatternList;  | 
| 34 | 
    import org.distorted.states.StateList;
   | 
|
| 35 | 
    import org.distorted.states.RubikStatePattern;
   | 
|
| 34 | 
    import org.distorted.screens.ScreenList;
   | 
|
| 35 | 
    import org.distorted.screens.RubikScreenPattern;
   | 
|
| 36 | 36 | 
     | 
| 37 | 37 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 38 | 38 | 
     | 
| ... | ... | |
| 98 | 98 | 
     | 
| 99 | 99 | 
    ract.setupObject(list, size, moves);  | 
| 100 | 100 | 
     | 
| 101 | 
            StateList.switchState(ract,StateList.PATT);
   | 
|
| 102 | 
            RubikStatePattern state = (RubikStatePattern) StateList.PATT.getStateClass();
   | 
|
| 101 | 
            ScreenList.switchState(ract, ScreenList.PATT);
   | 
|
| 102 | 
            RubikScreenPattern state = (RubikScreenPattern) ScreenList.PATT.getStateClass();
   | 
|
| 103 | 103 | 
    state.setPattern(ract, mTab, groupPosition, childPosition);  | 
| 104 | 104 | 
     | 
| 105 | 105 | 
    mDialog.rememberState();  | 
| src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java | ||
|---|---|---|
| 34 | 34 | 
    import org.distorted.network.RubikScores;  | 
| 35 | 35 | 
    import org.distorted.network.RubikNetwork;  | 
| 36 | 36 | 
    import org.distorted.objects.ObjectList;  | 
| 37 | 
    import org.distorted.states.RubikStatePlay;
   | 
|
| 37 | 
    import org.distorted.screens.RubikScreenPlay;
   | 
|
| 38 | 38 | 
     | 
| 39 | 39 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 40 | 40 | 
     | 
| ... | ... | |
| 108 | 108 | 
        {
   | 
| 109 | 109 | 
    prepareView();  | 
| 110 | 110 | 
     | 
| 111 | 
        int MAX = RubikStatePlay.LEVELS_SHOWN;
   | 
|
| 111 | 
        int MAX = RubikScreenPlay.LEVELS_SHOWN;
   | 
|
| 112 | 112 | 
    int toDo=0;  | 
| 113 | 113 | 
    int[] toDoTab = new int[mNumTabs];  | 
| 114 | 114 | 
    int[] maxTab = new int[mNumTabs];  | 
| src/main/java/org/distorted/dialogs/RubikDialogSetName.java | ||
|---|---|---|
| 42 | 42 | 
    import org.distorted.main.RubikActivity;  | 
| 43 | 43 | 
    import org.distorted.objects.ObjectList;  | 
| 44 | 44 | 
    import org.distorted.network.RubikScores;  | 
| 45 | 
    import org.distorted.states.StateList;
   | 
|
| 46 | 
    import org.distorted.states.RubikStatePlay;
   | 
|
| 45 | 
    import org.distorted.screens.ScreenList;
   | 
|
| 46 | 
    import org.distorted.screens.RubikScreenPlay;
   | 
|
| 47 | 47 | 
     | 
| 48 | 48 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 49 | 49 | 
     | 
| ... | ... | |
| 144 | 144 | 
              name = name.replace(' ', '_');
   | 
| 145 | 145 | 
     | 
| 146 | 146 | 
    RubikActivity act = (RubikActivity)getActivity();  | 
| 147 | 
              StateList.switchState(act, StateList.PLAY);
   | 
|
| 147 | 
              ScreenList.switchState(act, ScreenList.PLAY);
   | 
|
| 148 | 148 | 
    RubikScores.getInstance().setName(name);  | 
| 149 | 
              RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
   | 
|
| 149 | 
              RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
   | 
|
| 150 | 150 | 
     | 
| 151 | 151 | 
    int object = play.getObject();  | 
| 152 | 152 | 
    int size = play.getSize();  | 
| src/main/java/org/distorted/dialogs/RubikDialogSolved.java | ||
|---|---|---|
| 32 | 32 | 
    import android.view.LayoutInflater;  | 
| 33 | 33 | 
    import android.view.View;  | 
| 34 | 34 | 
    import android.view.Window;  | 
| 35 | 
    import android.view.WindowManager;  | 
|
| 36 | 35 | 
    import android.widget.Button;  | 
| 37 | 36 | 
    import android.widget.TextView;  | 
| 38 | 37 | 
     | 
| 39 | 38 | 
    import org.distorted.main.R;  | 
| 40 | 39 | 
    import org.distorted.main.RubikActivity;  | 
| 41 | 
    import org.distorted.states.StateList;
   | 
|
| 40 | 
    import org.distorted.screens.ScreenList;
   | 
|
| 42 | 41 | 
     | 
| 43 | 42 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 44 | 43 | 
     | 
| ... | ... | |
| 70 | 69 | 
    public void onClick(DialogInterface dialog, int which)  | 
| 71 | 70 | 
            {
   | 
| 72 | 71 | 
    RubikActivity act = (RubikActivity)getActivity();  | 
| 73 | 
            StateList.switchState(act, StateList.PLAY);
   | 
|
| 72 | 
            ScreenList.switchState(act, ScreenList.PLAY);
   | 
|
| 74 | 73 | 
    }  | 
| 75 | 74 | 
    });  | 
| 76 | 75 | 
     | 
| src/main/java/org/distorted/main/RubikActivity.java | ||
|---|---|---|
| 45 | 45 | 
    import org.distorted.network.RubikScores;  | 
| 46 | 46 | 
    import org.distorted.network.RubikNetwork;  | 
| 47 | 47 | 
    import org.distorted.objects.ObjectList;  | 
| 48 | 
    import org.distorted.states.StateList;
   | 
|
| 49 | 
    import org.distorted.states.RubikStatePlay;
   | 
|
| 48 | 
    import org.distorted.screens.ScreenList;
   | 
|
| 49 | 
    import org.distorted.screens.RubikScreenPlay;
   | 
|
| 50 | 50 | 
    import org.distorted.tutorials.TutorialActivity;  | 
| 51 | 51 | 
     | 
| 52 | 52 | 
    import java.util.Locale;  | 
| ... | ... | |
| 242 | 242 | 
    view.onResume();  | 
| 243 | 243 | 
    view.initialize();  | 
| 244 | 244 | 
    restorePreferences();  | 
| 245 | 
          StateList.setState(this);
   | 
|
| 245 | 
          ScreenList.setState(this);
   | 
|
| 246 | 246 | 
     | 
| 247 | 247 | 
    if( mJustStarted )  | 
| 248 | 248 | 
            {
   | 
| ... | ... | |
| 253 | 253 | 
    }  | 
| 254 | 254 | 
     | 
| 255 | 255 | 
    boolean success = false;  | 
| 256 | 
          RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
   | 
|
| 256 | 
          RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
   | 
|
| 257 | 257 | 
    int object = play.getObject();  | 
| 258 | 258 | 
    int size = play.getSize();  | 
| 259 | 259 | 
     | 
| ... | ... | |
| 272 | 272 | 
     | 
| 273 | 273 | 
    if( !success )  | 
| 274 | 274 | 
            {
   | 
| 275 | 
            ObjectList obj = ObjectList.getObject(RubikStatePlay.DEF_OBJECT);
   | 
|
| 276 | 
            int s = RubikStatePlay.DEF_SIZE;
   | 
|
| 275 | 
            ObjectList obj = ObjectList.getObject(RubikScreenPlay.DEF_OBJECT);
   | 
|
| 276 | 
            int s = RubikScreenPlay.DEF_SIZE;
   | 
|
| 277 | 277 | 
     | 
| 278 | 278 | 
    play.setObjectAndSize(this,obj,s);  | 
| 279 | 279 | 
    view.getPreRender().changeObject(obj,s);  | 
| ... | ... | |
| 305 | 305 | 
    BaseEffect.Type.getType(i).savePreferences(editor);  | 
| 306 | 306 | 
    }  | 
| 307 | 307 | 
     | 
| 308 | 
          for (int i = 0; i< StateList.LENGTH; i++)
   | 
|
| 308 | 
          for (int i = 0; i< ScreenList.LENGTH; i++)
   | 
|
| 309 | 309 | 
            {
   | 
| 310 | 
            StateList.getState(i).getStateClass().savePreferences(editor);
   | 
|
| 310 | 
            ScreenList.getState(i).getStateClass().savePreferences(editor);
   | 
|
| 311 | 311 | 
    }  | 
| 312 | 312 | 
     | 
| 313 | 
          StateList.savePreferences(editor);
   | 
|
| 313 | 
          ScreenList.savePreferences(editor);
   | 
|
| 314 | 314 | 
    RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);  | 
| 315 | 315 | 
    view.getPreRender().savePreferences(editor);  | 
| 316 | 316 | 
     | 
| ... | ... | |
| 330 | 330 | 
    BaseEffect.Type.getType(i).restorePreferences(preferences);  | 
| 331 | 331 | 
    }  | 
| 332 | 332 | 
     | 
| 333 | 
          for (int i = 0; i< StateList.LENGTH; i++)
   | 
|
| 333 | 
          for (int i = 0; i< ScreenList.LENGTH; i++)
   | 
|
| 334 | 334 | 
            {
   | 
| 335 | 
            StateList.getState(i).getStateClass().restorePreferences(preferences);
   | 
|
| 335 | 
            ScreenList.getState(i).getStateClass().restorePreferences(preferences);
   | 
|
| 336 | 336 | 
    }  | 
| 337 | 337 | 
     | 
| 338 | 
          StateList.restorePreferences(preferences);
   | 
|
| 338 | 
          ScreenList.restorePreferences(preferences);
   | 
|
| 339 | 339 | 
     | 
| 340 | 340 | 
    RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);  | 
| 341 | 341 | 
    view.getPreRender().restorePreferences(preferences);  | 
| ... | ... | |
| 545 | 545 | 
     | 
| 546 | 546 | 
    public boolean isLocked()  | 
| 547 | 547 | 
          {
   | 
| 548 | 
          StateList state = StateList.getCurrentState();
   | 
|
| 548 | 
          ScreenList state = ScreenList.getCurrentState();
   | 
|
| 549 | 549 | 
     | 
| 550 | 
          if( state== StateList.PLAY || state== StateList.READ || state== StateList.SOLV )
   | 
|
| 550 | 
          if( state== ScreenList.PLAY || state== ScreenList.READ || state== ScreenList.SOLV )
   | 
|
| 551 | 551 | 
            {
   | 
| 552 | 552 | 
    return mIsLocked;  | 
| 553 | 553 | 
    }  | 
| src/main/java/org/distorted/main/RubikPreRender.java | ||
|---|---|---|
| 42 | 42 | 
    import org.distorted.objects.TwistyObject;  | 
| 43 | 43 | 
    import org.distorted.objects.ObjectList;  | 
| 44 | 44 | 
    import org.distorted.network.RubikScores;  | 
| 45 | 
    import org.distorted.states.RubikStatePlay;
   | 
|
| 46 | 
    import org.distorted.states.StateList;
   | 
|
| 47 | 
    import org.distorted.states.RubikStateSolving;
   | 
|
| 45 | 
    import org.distorted.screens.RubikScreenPlay;
   | 
|
| 46 | 
    import org.distorted.screens.ScreenList;
   | 
|
| 47 | 
    import org.distorted.screens.RubikScreenSolving;
   | 
|
| 48 | 48 | 
     | 
| 49 | 49 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 50 | 50 | 
     | 
| ... | ... | |
| 172 | 172 | 
     | 
| 173 | 173 | 
    if( solved && !mIsSolved )  | 
| 174 | 174 | 
          {
   | 
| 175 | 
          if( StateList.getCurrentState()== StateList.SOLV )
   | 
|
| 175 | 
          if( ScreenList.getCurrentState()== ScreenList.SOLV )
   | 
|
| 176 | 176 | 
            {
   | 
| 177 | 
            RubikStateSolving solving = (RubikStateSolving) StateList.SOLV.getStateClass();
   | 
|
| 177 | 
            RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getStateClass();
   | 
|
| 178 | 178 | 
    mNewRecord = solving.getRecord();  | 
| 179 | 179 | 
     | 
| 180 | 180 | 
    if( mNewRecord< 0 )  | 
| ... | ... | |
| 349 | 349 | 
     | 
| 350 | 350 | 
    private void reportRecord()  | 
| 351 | 351 | 
        {
   | 
| 352 | 
        RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
   | 
|
| 352 | 
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
   | 
|
| 353 | 353 | 
    RubikScores scores = RubikScores.getInstance();  | 
| 354 | 354 | 
     | 
| 355 | 355 | 
    int object = play.getObject();  | 
| ... | ... | |
| 693 | 693 | 
    @Override  | 
| 694 | 694 | 
    public void run()  | 
| 695 | 695 | 
                    {
   | 
| 696 | 
                    StateList.switchState( act, StateList.READ);
   | 
|
| 696 | 
                    ScreenList.switchState( act, ScreenList.READ);
   | 
|
| 697 | 697 | 
    }  | 
| 698 | 698 | 
    });  | 
| 699 | 699 | 
    }  | 
| 700 | 700 | 
     | 
| 701 | 701 | 
    if( i==BaseEffect.Type.WIN.ordinal() )  | 
| 702 | 702 | 
                {
   | 
| 703 | 
                if( StateList.getCurrentState()== StateList.SOLV )
   | 
|
| 703 | 
                if( ScreenList.getCurrentState()== ScreenList.SOLV )
   | 
|
| 704 | 704 | 
                  {
   | 
| 705 | 705 | 
    final RubikActivity act = (RubikActivity)mView.getContext();  | 
| 706 | 706 | 
    Bundle bundle = new Bundle();  | 
| ... | ... | |
| 727 | 727 | 
    @Override  | 
| 728 | 728 | 
    public void run()  | 
| 729 | 729 | 
                      {
   | 
| 730 | 
                      StateList.switchState( act, StateList.DONE);
   | 
|
| 730 | 
                      ScreenList.switchState( act, ScreenList.DONE);
   | 
|
| 731 | 731 | 
    }  | 
| 732 | 732 | 
    });  | 
| 733 | 733 | 
    }  | 
| src/main/java/org/distorted/main/RubikSurfaceView.java | ||
|---|---|---|
| 35 | 35 | 
    import org.distorted.objects.TwistyObject;  | 
| 36 | 36 | 
    import org.distorted.objects.Movement;  | 
| 37 | 37 | 
    import org.distorted.solvers.SolverMain;  | 
| 38 | 
    import org.distorted.states.StateList;
   | 
|
| 39 | 
    import org.distorted.states.RubikStatePlay;
   | 
|
| 40 | 
    import org.distorted.states.RubikStateSolver;
   | 
|
| 41 | 
    import org.distorted.states.RubikStateSolving;
   | 
|
| 38 | 
    import org.distorted.screens.ScreenList;
   | 
|
| 39 | 
    import org.distorted.screens.RubikScreenPlay;
   | 
|
| 40 | 
    import org.distorted.screens.RubikScreenSolver;
   | 
|
| 41 | 
    import org.distorted.screens.RubikScreenSolving;
   | 
|
| 42 | 42 | 
     | 
| 43 | 43 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 44 | 44 | 
     | 
| ... | ... | |
| 295 | 295 | 
     | 
| 296 | 296 | 
    private void setUpDragOrRotate(boolean down, float x, float y)  | 
| 297 | 297 | 
          {
   | 
| 298 | 
          int mode = StateList.getMode();
   | 
|
| 298 | 
          int mode = ScreenList.getMode();
   | 
|
| 299 | 299 | 
     | 
| 300 | 300 | 
    if( mode==MODE_DRAG )  | 
| 301 | 301 | 
            {
   | 
| ... | ... | |
| 327 | 327 | 
     | 
| 328 | 328 | 
    if( down )  | 
| 329 | 329 | 
                  {
   | 
| 330 | 
                  RubikStateSolver solver = (RubikStateSolver) StateList.SVER.getStateClass();
   | 
|
| 330 | 
                  RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getStateClass();
   | 
|
| 331 | 331 | 
    mLastCubitFace = mMovement.getTouchedFace();  | 
| 332 | 332 | 
    float[] point = mMovement.getTouchedPoint3D();  | 
| 333 | 333 | 
    int color = solver.getCurrentColor();  | 
| ... | ... | |
| 416 | 416 | 
     | 
| 417 | 417 | 
    if( angle!=0 )  | 
| 418 | 418 | 
            {
   | 
| 419 | 
            if( StateList.getCurrentState()== StateList.SOLV )
   | 
|
| 419 | 
            if( ScreenList.getCurrentState()== ScreenList.SOLV )
   | 
|
| 420 | 420 | 
              {
   | 
| 421 | 
              RubikStateSolving solving = (RubikStateSolving) StateList.SOLV.getStateClass();
   | 
|
| 421 | 
              RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getStateClass();
   | 
|
| 422 | 422 | 
    solving.addMove(mCurrentAxis, mCurrentRow, angle);  | 
| 423 | 423 | 
    }  | 
| 424 | 
            if( StateList.getCurrentState()== StateList.PLAY )
   | 
|
| 424 | 
            if( ScreenList.getCurrentState()== ScreenList.PLAY )
   | 
|
| 425 | 425 | 
              {
   | 
| 426 | 
              RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
   | 
|
| 426 | 
              RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
   | 
|
| 427 | 427 | 
    play.addMove(mCurrentAxis, mCurrentRow, angle);  | 
| 428 | 428 | 
    }  | 
| 429 | 429 | 
    }  | 
| ... | ... | |
| 477 | 477 | 
     | 
| 478 | 478 | 
    object.beginNewRotation( mCurrentAxis, mCurrentRow );  | 
| 479 | 479 | 
     | 
| 480 | 
          if( StateList.getCurrentState()== StateList.READ )
   | 
|
| 480 | 
          if( ScreenList.getCurrentState()== ScreenList.READ )
   | 
|
| 481 | 481 | 
            {
   | 
| 482 | 
            RubikStateSolving solving = (RubikStateSolving) StateList.SOLV.getStateClass();
   | 
|
| 482 | 
            RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getStateClass();
   | 
|
| 483 | 483 | 
    solving.resetElapsed();  | 
| 484 | 484 | 
     | 
| 485 | 485 | 
    final RubikActivity act = (RubikActivity)getContext();  | 
| ... | ... | |
| 489 | 489 | 
    @Override  | 
| 490 | 490 | 
    public void run()  | 
| 491 | 491 | 
                {
   | 
| 492 | 
                StateList.switchState( act, StateList.SOLV);
   | 
|
| 492 | 
                ScreenList.switchState( act, ScreenList.SOLV);
   | 
|
| 493 | 493 | 
    }  | 
| 494 | 494 | 
    });  | 
| 495 | 495 | 
    }  | 
| src/main/java/org/distorted/screens/RubikScreenAbstract.java | ||
|---|---|---|
| 1 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 2 | 
    // Copyright 2020 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.screens;  | 
|
| 21 | 
     | 
|
| 22 | 
    import android.content.SharedPreferences;  | 
|
| 23 | 
     | 
|
| 24 | 
    import org.distorted.main.RubikActivity;  | 
|
| 25 | 
    import org.distorted.objects.ObjectList;  | 
|
| 26 | 
    import org.distorted.patterns.RubikPatternList;  | 
|
| 27 | 
    import org.distorted.tutorials.TutorialList;  | 
|
| 28 | 
     | 
|
| 29 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 30 | 
     | 
|
| 31 | 
    public abstract class RubikScreenAbstract  | 
|
| 32 | 
      {
   | 
|
| 33 | 
    int getPatternOrdinal()  | 
|
| 34 | 
        {
   | 
|
| 35 | 
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();  | 
|
| 36 | 
    int obj = play.getObject();  | 
|
| 37 | 
    int size = play.getSize();  | 
|
| 38 | 
    int ret = RubikPatternList.getOrdinal(obj,size);  | 
|
| 39 | 
     | 
|
| 40 | 
    if( ret<0 )  | 
|
| 41 | 
          {
   | 
|
| 42 | 
    ret = ObjectList.getSizeIndex(RubikScreenPlay.DEF_OBJECT, RubikScreenPlay.DEF_SIZE);  | 
|
| 43 | 
    }  | 
|
| 44 | 
     | 
|
| 45 | 
    return ret;  | 
|
| 46 | 
    }  | 
|
| 47 | 
     | 
|
| 48 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 49 | 
     | 
|
| 50 | 
    int getTutorialOrdinal()  | 
|
| 51 | 
        {
   | 
|
| 52 | 
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();  | 
|
| 53 | 
    int obj = play.getObject();  | 
|
| 54 | 
    int size = play.getSize();  | 
|
| 55 | 
     | 
|
| 56 | 
    int ret = TutorialList.getOrdinal(obj,size);  | 
|
| 57 | 
     | 
|
| 58 | 
    if( ret<0 )  | 
|
| 59 | 
          {
   | 
|
| 60 | 
    ret = ObjectList.getSizeIndex(RubikScreenPlay.DEF_OBJECT, RubikScreenPlay.DEF_SIZE);  | 
|
| 61 | 
    }  | 
|
| 62 | 
     | 
|
| 63 | 
    return ret;  | 
|
| 64 | 
    }  | 
|
| 65 | 
     | 
|
| 66 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 67 | 
     | 
|
| 68 | 
    abstract void enterState(RubikActivity act);  | 
|
| 69 | 
    abstract void leaveState(RubikActivity act);  | 
|
| 70 | 
    public abstract void savePreferences(SharedPreferences.Editor editor);  | 
|
| 71 | 
    public abstract void restorePreferences(SharedPreferences preferences);  | 
|
| 72 | 
    }  | 
|
| src/main/java/org/distorted/screens/RubikScreenBase.java | ||
|---|---|---|
| 1 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 2 | 
    // Copyright 2020 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.screens;  | 
|
| 21 | 
     | 
|
| 22 | 
    import android.view.View;  | 
|
| 23 | 
    import android.widget.ImageButton;  | 
|
| 24 | 
    import android.widget.LinearLayout;  | 
|
| 25 | 
     | 
|
| 26 | 
    import org.distorted.main.R;  | 
|
| 27 | 
    import org.distorted.main.RubikActivity;  | 
|
| 28 | 
    import org.distorted.main.RubikPreRender;  | 
|
| 29 | 
    import org.distorted.objects.TwistyObject;  | 
|
| 30 | 
     | 
|
| 31 | 
    import java.util.ArrayList;  | 
|
| 32 | 
     | 
|
| 33 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 34 | 
     | 
|
| 35 | 
    abstract class RubikScreenBase extends RubikScreenAbstract implements RubikPreRender.ActionFinishedListener  | 
|
| 36 | 
      {
   | 
|
| 37 | 
    private static final int DURATION_MILLIS = 750;  | 
|
| 38 | 
     | 
|
| 39 | 
    private ImageButton mPrevButton, mLockButton;  | 
|
| 40 | 
     | 
|
| 41 | 
    private boolean mCanPrevMove;  | 
|
| 42 | 
     | 
|
| 43 | 
    private static class Move  | 
|
| 44 | 
        {
   | 
|
| 45 | 
    private final int mAxis, mRow, mAngle;  | 
|
| 46 | 
     | 
|
| 47 | 
    Move(int axis, int row, int angle)  | 
|
| 48 | 
          {
   | 
|
| 49 | 
    mAxis = axis;  | 
|
| 50 | 
    mRow = row;  | 
|
| 51 | 
    mAngle= angle;  | 
|
| 52 | 
    }  | 
|
| 53 | 
    }  | 
|
| 54 | 
     | 
|
| 55 | 
    ArrayList<Move> mMoves;  | 
|
| 56 | 
     | 
|
| 57 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 58 | 
     | 
|
| 59 | 
    private void backMove(RubikPreRender pre)  | 
|
| 60 | 
        {
   | 
|
| 61 | 
    if( mCanPrevMove )  | 
|
| 62 | 
          {
   | 
|
| 63 | 
    int numMoves = mMoves.size();  | 
|
| 64 | 
     | 
|
| 65 | 
    if( numMoves>0 )  | 
|
| 66 | 
            {
   | 
|
| 67 | 
    RubikScreenBase.Move move = mMoves.remove(numMoves-1);  | 
|
| 68 | 
    TwistyObject object = pre.getObject();  | 
|
| 69 | 
     | 
|
| 70 | 
    int axis = move.mAxis;  | 
|
| 71 | 
    int row = (1<<move.mRow);  | 
|
| 72 | 
    int angle = move.mAngle;  | 
|
| 73 | 
    int numRot= Math.abs(angle*object.getBasicAngle()/360);  | 
|
| 74 | 
     | 
|
| 75 | 
    if( angle!=0 )  | 
|
| 76 | 
              {
   | 
|
| 77 | 
    mCanPrevMove = false;  | 
|
| 78 | 
    pre.addRotation(this, axis, row, -angle, numRot*DURATION_MILLIS);  | 
|
| 79 | 
    }  | 
|
| 80 | 
    else  | 
|
| 81 | 
              {
   | 
|
| 82 | 
              android.util.Log.e("solution", "error: trying to back move of angle 0");
   | 
|
| 83 | 
    }  | 
|
| 84 | 
    }  | 
|
| 85 | 
    }  | 
|
| 86 | 
    }  | 
|
| 87 | 
     | 
|
| 88 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 89 | 
     | 
|
| 90 | 
    private void toggleLock(RubikActivity act)  | 
|
| 91 | 
        {
   | 
|
| 92 | 
    act.toggleLock();  | 
|
| 93 | 
    mLockButton.setImageResource(getLockIcon(act));  | 
|
| 94 | 
    }  | 
|
| 95 | 
     | 
|
| 96 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 97 | 
     | 
|
| 98 | 
    private int getLockIcon(RubikActivity act)  | 
|
| 99 | 
        {
   | 
|
| 100 | 
    if( act.retLocked() )  | 
|
| 101 | 
          {
   | 
|
| 102 | 
    return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked);  | 
|
| 103 | 
    }  | 
|
| 104 | 
    else  | 
|
| 105 | 
          {
   | 
|
| 106 | 
    return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked);  | 
|
| 107 | 
    }  | 
|
| 108 | 
    }  | 
|
| 109 | 
     | 
|
| 110 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 111 | 
     | 
|
| 112 | 
    void createBottomPane(final RubikActivity act, float width, ImageButton button)  | 
|
| 113 | 
        {
   | 
|
| 114 | 
    mCanPrevMove = true;  | 
|
| 115 | 
     | 
|
| 116 | 
    if( mMoves==null ) mMoves = new ArrayList<>();  | 
|
| 117 | 
    else mMoves.clear();  | 
|
| 118 | 
     | 
|
| 119 | 
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);  | 
|
| 120 | 
    layoutBot.removeAllViews();  | 
|
| 121 | 
     | 
|
| 122 | 
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);  | 
|
| 123 | 
     | 
|
| 124 | 
    LinearLayout layoutLeft = new LinearLayout(act);  | 
|
| 125 | 
    layoutLeft.setLayoutParams(params);  | 
|
| 126 | 
    LinearLayout layoutMid = new LinearLayout(act);  | 
|
| 127 | 
    layoutMid.setLayoutParams(params);  | 
|
| 128 | 
    LinearLayout layoutRight = new LinearLayout(act);  | 
|
| 129 | 
    layoutRight.setLayoutParams(params);  | 
|
| 130 | 
     | 
|
| 131 | 
    setupPrevButton(act,width);  | 
|
| 132 | 
    layoutLeft.addView(mPrevButton);  | 
|
| 133 | 
    setupLockButton(act,width);  | 
|
| 134 | 
    layoutMid.addView(mLockButton);  | 
|
| 135 | 
    layoutRight.addView(button);  | 
|
| 136 | 
     | 
|
| 137 | 
    layoutBot.addView(layoutLeft);  | 
|
| 138 | 
    layoutBot.addView(layoutMid);  | 
|
| 139 | 
    layoutBot.addView(layoutRight);  | 
|
| 140 | 
    }  | 
|
| 141 | 
     | 
|
| 142 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 143 | 
     | 
|
| 144 | 
    void setupLockButton(final RubikActivity act, final float width)  | 
|
| 145 | 
        {
   | 
|
| 146 | 
    final int icon = getLockIcon(act);  | 
|
| 147 | 
    mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 148 | 
     | 
|
| 149 | 
    mLockButton.setOnClickListener( new View.OnClickListener()  | 
|
| 150 | 
          {
   | 
|
| 151 | 
    @Override  | 
|
| 152 | 
    public void onClick(View v)  | 
|
| 153 | 
            {
   | 
|
| 154 | 
    toggleLock(act);  | 
|
| 155 | 
    }  | 
|
| 156 | 
    });  | 
|
| 157 | 
    }  | 
|
| 158 | 
     | 
|
| 159 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 160 | 
     | 
|
| 161 | 
    void setupPrevButton(final RubikActivity act, final float width)  | 
|
| 162 | 
        {
   | 
|
| 163 | 
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back);  | 
|
| 164 | 
    mPrevButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 165 | 
     | 
|
| 166 | 
    mPrevButton.setOnClickListener( new View.OnClickListener()  | 
|
| 167 | 
          {
   | 
|
| 168 | 
    @Override  | 
|
| 169 | 
    public void onClick(View v)  | 
|
| 170 | 
            {
   | 
|
| 171 | 
    RubikPreRender pre = act.getPreRender();  | 
|
| 172 | 
    backMove(pre);  | 
|
| 173 | 
    }  | 
|
| 174 | 
    });  | 
|
| 175 | 
    }  | 
|
| 176 | 
     | 
|
| 177 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 178 | 
     | 
|
| 179 | 
    public void addMove(int axis, int row, int angle)  | 
|
| 180 | 
        {
   | 
|
| 181 | 
    mMoves.add(new Move(axis,row,angle));  | 
|
| 182 | 
    }  | 
|
| 183 | 
     | 
|
| 184 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 185 | 
     | 
|
| 186 | 
    public void onActionFinished(final long effectID)  | 
|
| 187 | 
        {
   | 
|
| 188 | 
    mCanPrevMove = true;  | 
|
| 189 | 
    }  | 
|
| 190 | 
    }  | 
|
| src/main/java/org/distorted/screens/RubikScreenDone.java | ||
|---|---|---|
| 1 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 2 | 
    // Copyright 2020 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.screens;  | 
|
| 21 | 
     | 
|
| 22 | 
    import android.content.SharedPreferences;  | 
|
| 23 | 
    import android.util.TypedValue;  | 
|
| 24 | 
    import android.view.LayoutInflater;  | 
|
| 25 | 
    import android.view.View;  | 
|
| 26 | 
    import android.widget.ImageButton;  | 
|
| 27 | 
    import android.widget.LinearLayout;  | 
|
| 28 | 
    import android.widget.TextView;  | 
|
| 29 | 
     | 
|
| 30 | 
    import androidx.fragment.app.FragmentManager;  | 
|
| 31 | 
     | 
|
| 32 | 
    import org.distorted.dialogs.RubikDialogNewRecord;  | 
|
| 33 | 
    import org.distorted.dialogs.RubikDialogSolved;  | 
|
| 34 | 
    import org.distorted.main.R;  | 
|
| 35 | 
    import org.distorted.main.RubikActivity;  | 
|
| 36 | 
     | 
|
| 37 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 38 | 
     | 
|
| 39 | 
    public class RubikScreenDone extends RubikScreenAbstract  | 
|
| 40 | 
      {
   | 
|
| 41 | 
    private ImageButton mBackButton;  | 
|
| 42 | 
     | 
|
| 43 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 44 | 
     | 
|
| 45 | 
    void leaveState(RubikActivity act)  | 
|
| 46 | 
        {
   | 
|
| 47 | 
     | 
|
| 48 | 
    }  | 
|
| 49 | 
     | 
|
| 50 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 51 | 
     | 
|
| 52 | 
    void enterState(final RubikActivity act)  | 
|
| 53 | 
        {
   | 
|
| 54 | 
    float width = act.getScreenWidthInPixels();  | 
|
| 55 | 
    float titleSize = width*RubikActivity.TITLE_TEXT_SIZE;  | 
|
| 56 | 
    LayoutInflater inflater = act.getLayoutInflater();  | 
|
| 57 | 
     | 
|
| 58 | 
    // TOP ////////////////////////////  | 
|
| 59 | 
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);  | 
|
| 60 | 
    layoutTop.removeAllViews();  | 
|
| 61 | 
    TextView label = (TextView)inflater.inflate(R.layout.upper_text, null);  | 
|
| 62 | 
    label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);  | 
|
| 63 | 
    label.setText(R.string.solved);  | 
|
| 64 | 
    layoutTop.addView(label);  | 
|
| 65 | 
     | 
|
| 66 | 
    // BOT ////////////////////////////  | 
|
| 67 | 
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);  | 
|
| 68 | 
    layoutBot.removeAllViews();  | 
|
| 69 | 
     | 
|
| 70 | 
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);  | 
|
| 71 | 
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,2);  | 
|
| 72 | 
     | 
|
| 73 | 
    LinearLayout layoutLeft = new LinearLayout(act);  | 
|
| 74 | 
    layoutLeft.setLayoutParams(paramsL);  | 
|
| 75 | 
    LinearLayout layoutRight = new LinearLayout(act);  | 
|
| 76 | 
    layoutRight.setLayoutParams(paramsR);  | 
|
| 77 | 
     | 
|
| 78 | 
    setupBackButton(act,width);  | 
|
| 79 | 
     | 
|
| 80 | 
    layoutRight.addView(mBackButton);  | 
|
| 81 | 
    layoutBot.addView(layoutLeft);  | 
|
| 82 | 
    layoutBot.addView(layoutRight);  | 
|
| 83 | 
    }  | 
|
| 84 | 
     | 
|
| 85 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 86 | 
     | 
|
| 87 | 
    private void setupBackButton(final RubikActivity act, final float width)  | 
|
| 88 | 
        {
   | 
|
| 89 | 
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back);  | 
|
| 90 | 
    mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 91 | 
     | 
|
| 92 | 
    mBackButton.setOnClickListener( new View.OnClickListener()  | 
|
| 93 | 
          {
   | 
|
| 94 | 
    @Override  | 
|
| 95 | 
    public void onClick(View v)  | 
|
| 96 | 
            {
   | 
|
| 97 | 
    ScreenList.goBack(act);  | 
|
| 98 | 
     | 
|
| 99 | 
    FragmentManager mana = act.getSupportFragmentManager();  | 
|
| 100 | 
    RubikDialogNewRecord diag1 = (RubikDialogNewRecord) mana.findFragmentByTag(RubikDialogNewRecord.getDialogTag());  | 
|
| 101 | 
    RubikDialogSolved diag2 = (RubikDialogSolved ) mana.findFragmentByTag(RubikDialogSolved.getDialogTag());  | 
|
| 102 | 
     | 
|
| 103 | 
    if( diag1 !=null ) diag1.dismiss();  | 
|
| 104 | 
    if( diag2 !=null ) diag2.dismiss();  | 
|
| 105 | 
    }  | 
|
| 106 | 
    });  | 
|
| 107 | 
    }  | 
|
| 108 | 
     | 
|
| 109 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 110 | 
     | 
|
| 111 | 
    public void savePreferences(SharedPreferences.Editor editor)  | 
|
| 112 | 
        {
   | 
|
| 113 | 
     | 
|
| 114 | 
    }  | 
|
| 115 | 
     | 
|
| 116 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 117 | 
     | 
|
| 118 | 
    public void restorePreferences(SharedPreferences preferences)  | 
|
| 119 | 
        {
   | 
|
| 120 | 
     | 
|
| 121 | 
    }  | 
|
| 122 | 
    }  | 
|
| src/main/java/org/distorted/screens/RubikScreenPattern.java | ||
|---|---|---|
| 1 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 2 | 
    // Copyright 2020 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.screens;  | 
|
| 21 | 
     | 
|
| 22 | 
    import android.content.SharedPreferences;  | 
|
| 23 | 
    import android.os.Bundle;  | 
|
| 24 | 
    import androidx.fragment.app.FragmentManager;  | 
|
| 25 | 
    import android.util.TypedValue;  | 
|
| 26 | 
    import android.view.Gravity;  | 
|
| 27 | 
    import android.view.LayoutInflater;  | 
|
| 28 | 
    import android.view.View;  | 
|
| 29 | 
    import android.widget.ImageButton;  | 
|
| 30 | 
    import android.widget.LinearLayout;  | 
|
| 31 | 
    import android.widget.TextView;  | 
|
| 32 | 
     | 
|
| 33 | 
    import org.distorted.dialogs.RubikDialogPattern;  | 
|
| 34 | 
    import org.distorted.main.R;  | 
|
| 35 | 
    import org.distorted.main.RubikActivity;  | 
|
| 36 | 
    import org.distorted.main.RubikPreRender;  | 
|
| 37 | 
    import org.distorted.objects.ObjectList;  | 
|
| 38 | 
    import org.distorted.patterns.RubikPattern;  | 
|
| 39 | 
    import org.distorted.patterns.RubikPatternList;  | 
|
| 40 | 
     | 
|
| 41 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 42 | 
     | 
|
| 43 | 
    public class RubikScreenPattern extends RubikScreenAbstract  | 
|
| 44 | 
      {
   | 
|
| 45 | 
    private TextView mText;  | 
|
| 46 | 
    private ImageButton mPrevButton, mNextButton, mBackButton;  | 
|
| 47 | 
    private TextView mMovesText;  | 
|
| 48 | 
    private int mNumMoves;  | 
|
| 49 | 
    private int mPatternOrdinal, mCategory, mPattern;  | 
|
| 50 | 
    private float mButtonSize;  | 
|
| 51 | 
     | 
|
| 52 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 53 | 
     | 
|
| 54 | 
    RubikScreenPattern()  | 
|
| 55 | 
        {
   | 
|
| 56 | 
     | 
|
| 57 | 
    }  | 
|
| 58 | 
     | 
|
| 59 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 60 | 
     | 
|
| 61 | 
    void leaveState(RubikActivity act)  | 
|
| 62 | 
        {
   | 
|
| 63 | 
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();  | 
|
| 64 | 
     | 
|
| 65 | 
    ObjectList object = RubikPatternList.getObject(mPatternOrdinal);  | 
|
| 66 | 
    int size = RubikPatternList.getSize(mPatternOrdinal);  | 
|
| 67 | 
     | 
|
| 68 | 
    if( !play.setObjectAndSize(act,object,size) )  | 
|
| 69 | 
          {
   | 
|
| 70 | 
    int objectPlay= play.getObject();  | 
|
| 71 | 
    int sizePlay = play.getSize();  | 
|
| 72 | 
     | 
|
| 73 | 
    act.changeObject(ObjectList.getObject(objectPlay),sizePlay, false);  | 
|
| 74 | 
    }  | 
|
| 75 | 
    }  | 
|
| 76 | 
     | 
|
| 77 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 78 | 
     | 
|
| 79 | 
    void enterState(final RubikActivity act)  | 
|
| 80 | 
        {
   | 
|
| 81 | 
    float width = act.getScreenWidthInPixels();  | 
|
| 82 | 
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;  | 
|
| 83 | 
    float titleSize = width*RubikActivity.TITLE_TEXT_SIZE;  | 
|
| 84 | 
    mPatternOrdinal = getPatternOrdinal();  | 
|
| 85 | 
    LayoutInflater inflater = act.getLayoutInflater();  | 
|
| 86 | 
     | 
|
| 87 | 
    // TOP ////////////////////////////  | 
|
| 88 | 
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);  | 
|
| 89 | 
    layoutTop.removeAllViews();  | 
|
| 90 | 
    mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null);  | 
|
| 91 | 
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);  | 
|
| 92 | 
    mText.setText(R.string.patterns);  | 
|
| 93 | 
    layoutTop.addView(mText);  | 
|
| 94 | 
     | 
|
| 95 | 
    // BOT ////////////////////////////  | 
|
| 96 | 
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);  | 
|
| 97 | 
    layoutBot.removeAllViews();  | 
|
| 98 | 
     | 
|
| 99 | 
    setupPrevButton(act,width);  | 
|
| 100 | 
    setupNextButton(act,width);  | 
|
| 101 | 
    setupTextView(act,width);  | 
|
| 102 | 
     | 
|
| 103 | 
    setTrioState(false);  | 
|
| 104 | 
     | 
|
| 105 | 
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 106 | 
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 107 | 
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 108 | 
     | 
|
| 109 | 
    LinearLayout layoutLeft = new LinearLayout(act);  | 
|
| 110 | 
    layoutLeft.setLayoutParams(paramsL);  | 
|
| 111 | 
    LinearLayout layoutMid = new LinearLayout(act);  | 
|
| 112 | 
    layoutMid.setLayoutParams(paramsM);  | 
|
| 113 | 
    LinearLayout layoutRight = new LinearLayout(act);  | 
|
| 114 | 
    layoutRight.setLayoutParams(paramsR);  | 
|
| 115 | 
     | 
|
| 116 | 
    layoutLeft.addView(mPrevButton);  | 
|
| 117 | 
    layoutLeft.addView(mMovesText);  | 
|
| 118 | 
    layoutLeft.addView(mNextButton);  | 
|
| 119 | 
     | 
|
| 120 | 
    setupBackButton(act,width);  | 
|
| 121 | 
     | 
|
| 122 | 
    layoutRight.addView(mBackButton);  | 
|
| 123 | 
     | 
|
| 124 | 
    layoutBot.addView(layoutLeft);  | 
|
| 125 | 
    layoutBot.addView(layoutMid);  | 
|
| 126 | 
    layoutBot.addView(layoutRight);  | 
|
| 127 | 
    }  | 
|
| 128 | 
     | 
|
| 129 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 130 | 
     | 
|
| 131 | 
    private void showDialog(FragmentManager manager)  | 
|
| 132 | 
        {
   | 
|
| 133 | 
    RubikDialogPattern diag = new RubikDialogPattern();  | 
|
| 134 | 
    Bundle bundle = new Bundle();  | 
|
| 135 | 
        bundle.putInt("tab", mPatternOrdinal );
   | 
|
| 136 | 
    diag.setArguments(bundle);  | 
|
| 137 | 
    diag.show( manager, RubikDialogPattern.getDialogTag() );  | 
|
| 138 | 
    }  | 
|
| 139 | 
     | 
|
| 140 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 141 | 
     | 
|
| 142 | 
    private void setTrioState(boolean enable)  | 
|
| 143 | 
        {
   | 
|
| 144 | 
    int state = enable ? View.VISIBLE : View.INVISIBLE;  | 
|
| 145 | 
     | 
|
| 146 | 
    if( mPrevButton!=null ) mPrevButton.setVisibility(state);  | 
|
| 147 | 
    if( mNextButton!=null ) mNextButton.setVisibility(state);  | 
|
| 148 | 
    if( mMovesText !=null ) mMovesText.setVisibility(state);  | 
|
| 149 | 
    }  | 
|
| 150 | 
     | 
|
| 151 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 152 | 
     | 
|
| 153 | 
    private void setupBackButton(final RubikActivity act, final float width)  | 
|
| 154 | 
        {
   | 
|
| 155 | 
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back);  | 
|
| 156 | 
    mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 157 | 
     | 
|
| 158 | 
    mBackButton.setOnClickListener( new View.OnClickListener()  | 
|
| 159 | 
          {
   | 
|
| 160 | 
    @Override  | 
|
| 161 | 
    public void onClick(View v)  | 
|
| 162 | 
            {
   | 
|
| 163 | 
    FragmentManager mana = act.getSupportFragmentManager();  | 
|
| 164 | 
    ScreenList.goBack(act);  | 
|
| 165 | 
    showDialog(mana);  | 
|
| 166 | 
    }  | 
|
| 167 | 
    });  | 
|
| 168 | 
    }  | 
|
| 169 | 
     | 
|
| 170 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 171 | 
     | 
|
| 172 | 
    private void setupPrevButton(final RubikActivity act, final float width)  | 
|
| 173 | 
        {
   | 
|
| 174 | 
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_left,R.drawable.ui_medium_left, R.drawable.ui_big_left, R.drawable.ui_huge_left);  | 
|
| 175 | 
    mPrevButton = new TransparentImageButton(act,icon,width,0);  | 
|
| 176 | 
     | 
|
| 177 | 
    mPrevButton.setOnClickListener( new View.OnClickListener()  | 
|
| 178 | 
          {
   | 
|
| 179 | 
    @Override  | 
|
| 180 | 
    public void onClick(View v)  | 
|
| 181 | 
            {
   | 
|
| 182 | 
    RubikPattern pattern = RubikPattern.getInstance();  | 
|
| 183 | 
    RubikPreRender pre = act.getPreRender();  | 
|
| 184 | 
    pattern.backMove( pre, mPatternOrdinal, mCategory, mPattern);  | 
|
| 185 | 
    int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);  | 
|
| 186 | 
    mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));  | 
|
| 187 | 
    }  | 
|
| 188 | 
    });  | 
|
| 189 | 
    }  | 
|
| 190 | 
     | 
|
| 191 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 192 | 
     | 
|
| 193 | 
    private void setupNextButton(final RubikActivity act, final float width)  | 
|
| 194 | 
        {
   | 
|
| 195 | 
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_right,R.drawable.ui_medium_right, R.drawable.ui_big_right, R.drawable.ui_huge_right);  | 
|
| 196 | 
    mNextButton = new TransparentImageButton(act,icon,width,0);  | 
|
| 197 | 
     | 
|
| 198 | 
    mNextButton.setOnClickListener( new View.OnClickListener()  | 
|
| 199 | 
          {
   | 
|
| 200 | 
    @Override  | 
|
| 201 | 
    public void onClick(View v)  | 
|
| 202 | 
            {
   | 
|
| 203 | 
    RubikPattern pattern = RubikPattern.getInstance();  | 
|
| 204 | 
    RubikPreRender pre = act.getPreRender();  | 
|
| 205 | 
    pattern.makeMove( pre, mPatternOrdinal, mCategory, mPattern);  | 
|
| 206 | 
    int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);  | 
|
| 207 | 
    mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));  | 
|
| 208 | 
    }  | 
|
| 209 | 
    });  | 
|
| 210 | 
    }  | 
|
| 211 | 
     | 
|
| 212 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 213 | 
     | 
|
| 214 | 
    private void setupTextView(final RubikActivity act, final float width)  | 
|
| 215 | 
        {
   | 
|
| 216 | 
    int padding = (int)(width*RubikActivity.PADDING);  | 
|
| 217 | 
    int margin = (int)(width*RubikActivity.MARGIN);  | 
|
| 218 | 
     | 
|
| 219 | 
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f);  | 
|
| 220 | 
    params.topMargin = margin;  | 
|
| 221 | 
    params.bottomMargin = margin;  | 
|
| 222 | 
    params.leftMargin = margin;  | 
|
| 223 | 
    params.rightMargin = margin;  | 
|
| 224 | 
     | 
|
| 225 | 
    mMovesText = new TextView(act);  | 
|
| 226 | 
    mMovesText.setTextSize(20);  | 
|
| 227 | 
    mMovesText.setLayoutParams(params);  | 
|
| 228 | 
    mMovesText.setPadding(padding,0,padding,0);  | 
|
| 229 | 
    mMovesText.setGravity(Gravity.CENTER);  | 
|
| 230 | 
    mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);  | 
|
| 231 | 
    mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));  | 
|
| 232 | 
    }  | 
|
| 233 | 
     | 
|
| 234 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 235 | 
     | 
|
| 236 | 
    public void setPattern(final RubikActivity act, int ordinal, int category, int pattern)  | 
|
| 237 | 
        {
   | 
|
| 238 | 
    mPatternOrdinal = ordinal;  | 
|
| 239 | 
    mCategory = category;  | 
|
| 240 | 
    mPattern = pattern;  | 
|
| 241 | 
     | 
|
| 242 | 
    setTrioState(true);  | 
|
| 243 | 
     | 
|
| 244 | 
    RubikPattern patt = RubikPattern.getInstance();  | 
|
| 245 | 
    String patternName = patt.getPatternName(ordinal,category,pattern);  | 
|
| 246 | 
    mText.setText(patternName);  | 
|
| 247 | 
     | 
|
| 248 | 
    mNumMoves = patt.getNumMoves(ordinal,category,pattern);  | 
|
| 249 | 
    int currMove= patt.getCurMove(ordinal,category,pattern);  | 
|
| 250 | 
     | 
|
| 251 | 
    mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));  | 
|
| 252 | 
    }  | 
|
| 253 | 
     | 
|
| 254 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 255 | 
     | 
|
| 256 | 
    public void savePreferences(SharedPreferences.Editor editor)  | 
|
| 257 | 
        {
   | 
|
| 258 | 
     | 
|
| 259 | 
    }  | 
|
| 260 | 
     | 
|
| 261 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 262 | 
     | 
|
| 263 | 
    public void restorePreferences(SharedPreferences preferences)  | 
|
| 264 | 
        {
   | 
|
| 265 | 
     | 
|
| 266 | 
    }  | 
|
| 267 | 
    }  | 
|
| src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
|---|---|---|
| 1 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 2 | 
    // Copyright 2020 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.screens;  | 
|
| 21 | 
     | 
|
| 22 | 
    import android.content.Context;  | 
|
| 23 | 
    import android.content.SharedPreferences;  | 
|
| 24 | 
    import android.graphics.drawable.BitmapDrawable;  | 
|
| 25 | 
    import android.os.Bundle;  | 
|
| 26 | 
    import android.util.TypedValue;  | 
|
| 27 | 
    import android.view.Gravity;  | 
|
| 28 | 
    import android.view.LayoutInflater;  | 
|
| 29 | 
    import android.view.View;  | 
|
| 30 | 
    import android.widget.Button;  | 
|
| 31 | 
    import android.widget.GridLayout;  | 
|
| 32 | 
    import android.widget.ImageButton;  | 
|
| 33 | 
    import android.widget.LinearLayout;  | 
|
| 34 | 
    import android.widget.PopupWindow;  | 
|
| 35 | 
     | 
|
| 36 | 
    import org.distorted.dialogs.RubikDialogAbout;  | 
|
| 37 | 
    import org.distorted.dialogs.RubikDialogPattern;  | 
|
| 38 | 
    import org.distorted.dialogs.RubikDialogScores;  | 
|
| 39 | 
    import org.distorted.dialogs.RubikDialogTutorial;  | 
|
| 40 | 
    import org.distorted.main.R;  | 
|
| 41 | 
    import org.distorted.main.RubikActivity;  | 
|
| 42 | 
    import org.distorted.main.RubikPreRender;  | 
|
| 43 | 
    import org.distorted.objects.ObjectList;  | 
|
| 44 | 
    import org.distorted.network.RubikScores;  | 
|
| 45 | 
     | 
|
| 46 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 47 | 
     | 
|
| 48 | 
    public class RubikScreenPlay extends RubikScreenBase  | 
|
| 49 | 
      {
   | 
|
| 50 | 
    public static final int LEVELS_SHOWN = 10;  | 
|
| 51 | 
    public static final int DEF_OBJECT= ObjectList.CUBE.ordinal();  | 
|
| 52 | 
    public static final int DEF_SIZE = 3;  | 
|
| 53 | 
     | 
|
| 54 | 
      private static final int[] BUTTON_LABELS = { R.string.scores,
   | 
|
| 55 | 
    R.string.patterns,  | 
|
| 56 | 
    R.string.control,  | 
|
| 57 | 
    R.string.solver,  | 
|
| 58 | 
    R.string.tutorials,  | 
|
| 59 | 
    R.string.about };  | 
|
| 60 | 
     | 
|
| 61 | 
    private static final int NUM_BUTTONS = BUTTON_LABELS.length;  | 
|
| 62 | 
    private static final float LAST_BUTTON = 1.5f;  | 
|
| 63 | 
     | 
|
| 64 | 
    private ImageButton mObjButton, mMenuButton, mSolveButton;  | 
|
| 65 | 
    private Button mPlayButton;  | 
|
| 66 | 
    private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;  | 
|
| 67 | 
    private int mObject = DEF_OBJECT;  | 
|
| 68 | 
    private int mSize = DEF_SIZE;  | 
|
| 69 | 
    private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;  | 
|
| 70 | 
    private int mLevelValue;  | 
|
| 71 | 
    private float mButtonSize, mMenuItemSize, mMenuTextSize;  | 
|
| 72 | 
    private int mColCount, mRowCount;  | 
|
| 73 | 
    private LinearLayout mPlayLayout;  | 
|
| 74 | 
     | 
|
| 75 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 76 | 
     | 
|
| 77 | 
    void leaveState(RubikActivity act)  | 
|
| 78 | 
        {
   | 
|
| 79 | 
     | 
|
| 80 | 
    }  | 
|
| 81 | 
     | 
|
| 82 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 83 | 
     | 
|
| 84 | 
    void enterState(final RubikActivity act)  | 
|
| 85 | 
        {
   | 
|
| 86 | 
    float width = act.getScreenWidthInPixels();  | 
|
| 87 | 
     | 
|
| 88 | 
    mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE;  | 
|
| 89 | 
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;  | 
|
| 90 | 
    mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE;  | 
|
| 91 | 
     | 
|
| 92 | 
    mRowCount = ObjectList.getRowCount();  | 
|
| 93 | 
    mColCount = ObjectList.getColumnCount();  | 
|
| 94 | 
     | 
|
| 95 | 
    // TOP ////////////////////////////  | 
|
| 96 | 
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);  | 
|
| 97 | 
    layoutTop.removeAllViews();  | 
|
| 98 | 
     | 
|
| 99 | 
    setupObjectWindow(act,width);  | 
|
| 100 | 
    setupObjectButton(act,width);  | 
|
| 101 | 
    layoutTop.addView(mObjButton);  | 
|
| 102 | 
     | 
|
| 103 | 
    setupMenuWindow(act,width);  | 
|
| 104 | 
    setupMenuButton(act,width);  | 
|
| 105 | 
    layoutTop.addView(mMenuButton);  | 
|
| 106 | 
     | 
|
| 107 | 
    setupPlayWindow(act,width);  | 
|
| 108 | 
    setupPlayButton(act,width);  | 
|
| 109 | 
    layoutTop.addView(mPlayButton);  | 
|
| 110 | 
     | 
|
| 111 | 
    setupSolveButton(act,width);  | 
|
| 112 | 
    createBottomPane(act,width,mSolveButton);  | 
|
| 113 | 
    }  | 
|
| 114 | 
     | 
|
| 115 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 116 | 
     | 
|
| 117 | 
    private void setupObjectButton(final RubikActivity act, final float width)  | 
|
| 118 | 
        {
   | 
|
| 119 | 
    final int margin = (int)(width*RubikActivity.MARGIN);  | 
|
| 120 | 
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu);  | 
|
| 121 | 
    mObjButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 122 | 
     | 
|
| 123 | 
    mObjButton.setOnClickListener( new View.OnClickListener()  | 
|
| 124 | 
          {
   | 
|
| 125 | 
    @Override  | 
|
| 126 | 
    public void onClick(View view)  | 
|
| 127 | 
            {
   | 
|
| 128 | 
    if( act.getPreRender().canPlay() )  | 
|
| 129 | 
              {
   | 
|
| 130 | 
    if( mObjectPopup==null )  | 
|
| 131 | 
                {
   | 
|
| 132 | 
    // I completely don't understand it, but Firebase says occasionally mObjectPopup is null here. Recreate.  | 
|
| 133 | 
    float width = act.getScreenWidthInPixels();  | 
|
| 134 | 
    setupObjectWindow(act,width);  | 
|
| 135 | 
    }  | 
|
| 136 | 
     | 
|
| 137 | 
    mObjectPopup.setFocusable(false);  | 
|
| 138 | 
    mObjectPopup.update();  | 
|
| 139 | 
     | 
|
| 140 | 
    View popupView = mObjectPopup.getContentView();  | 
|
| 141 | 
    popupView.setSystemUiVisibility(RubikActivity.FLAGS);  | 
|
| 142 | 
     | 
|
| 143 | 
    mObjectPopup.showAsDropDown(view, margin, margin);  | 
|
| 144 | 
    mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*mRowCount);  | 
|
| 145 | 
     | 
|
| 146 | 
    mObjectPopup.setFocusable(true);  | 
|
| 147 | 
    mObjectPopup.update();  | 
|
| 148 | 
    }  | 
|
| 149 | 
    }  | 
|
| 150 | 
    });  | 
|
| 151 | 
    }  | 
|
| 152 | 
     | 
|
| 153 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 154 | 
     | 
|
| 155 | 
    private void setupPlayButton(final RubikActivity act, final float width)  | 
|
| 156 | 
        {
   | 
|
| 157 | 
    final int margin = (int)(width*RubikActivity.MARGIN);  | 
|
| 158 | 
    mPlayButton = new TransparentButton(act, R.string.play, mButtonSize, width);  | 
|
| 159 | 
     | 
|
| 160 | 
    mPlayButton.setOnClickListener( new View.OnClickListener()  | 
|
| 161 | 
          {
   | 
|
| 162 | 
    @Override  | 
|
| 163 | 
    public void onClick(View view)  | 
|
| 164 | 
            {
   | 
|
| 165 | 
    if( act.getPreRender().canPlay() )  | 
|
| 166 | 
              {
   | 
|
| 167 | 
    if( mPlayPopup==null )  | 
|
| 168 | 
                {
   | 
|
| 169 | 
    // I completely don't understand it, but Firebase says occasionally mPlayPopup is null here. Recreate.  | 
|
| 170 | 
    float width = act.getScreenWidthInPixels();  | 
|
| 171 | 
    setupPlayWindow(act,width);  | 
|
| 172 | 
    }  | 
|
| 173 | 
     | 
|
| 174 | 
    mPlayPopup.setFocusable(false);  | 
|
| 175 | 
    mPlayPopup.update();  | 
|
| 176 | 
     | 
|
| 177 | 
    View popupView = mPlayPopup.getContentView();  | 
|
| 178 | 
    popupView.setSystemUiVisibility(RubikActivity.FLAGS);  | 
|
| 179 | 
     | 
|
| 180 | 
    final int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);  | 
|
| 181 | 
    final int maxLevel = ObjectList.getMaxLevel(mObject, sizeIndex);  | 
|
| 182 | 
    final int levelsShown = Math.min(maxLevel,LEVELS_SHOWN);  | 
|
| 183 | 
     | 
|
| 184 | 
    mPlayPopup.showAsDropDown(view, margin, margin);  | 
|
| 185 | 
    mPlayPopup.update(view, mPlayLayoutWidth, (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f)));  | 
|
| 186 | 
    mPlayPopup.setFocusable(true);  | 
|
| 187 | 
    mPlayPopup.update();  | 
|
| 188 | 
    }  | 
|
| 189 | 
    }  | 
|
| 190 | 
    });  | 
|
| 191 | 
    }  | 
|
| 192 | 
     | 
|
| 193 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 194 | 
     | 
|
| 195 | 
    private void setupMenuButton(final RubikActivity act, final float width)  | 
|
| 196 | 
        {
   | 
|
| 197 | 
    final int margin = (int)(width*RubikActivity.MARGIN);  | 
|
| 198 | 
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_menu,R.drawable.ui_medium_menu, R.drawable.ui_big_menu, R.drawable.ui_huge_menu);  | 
|
| 199 | 
    mMenuButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 200 | 
     | 
|
| 201 | 
    mMenuButton.setOnClickListener( new View.OnClickListener()  | 
|
| 202 | 
          {
   | 
|
| 203 | 
    @Override  | 
|
| 204 | 
    public void onClick(View view)  | 
|
| 205 | 
            {
   | 
|
| 206 | 
    if( act.getPreRender().canPlay() )  | 
|
| 207 | 
              {
   | 
|
| 208 | 
    if( mMenuPopup==null )  | 
|
| 209 | 
                {
   | 
|
| 210 | 
    // I completely don't understand it, but Firebase says occasionally mMenuPopup is null here. Recreate.  | 
|
| 211 | 
    float width = act.getScreenWidthInPixels();  | 
|
| 212 | 
    setupMenuWindow(act,width);  | 
|
| 213 | 
    }  | 
|
| 214 | 
     | 
|
| 215 | 
    mMenuPopup.setFocusable(false);  | 
|
| 216 | 
    mMenuPopup.update();  | 
|
| 217 | 
     | 
|
| 218 | 
    View popupView = mMenuPopup.getContentView();  | 
|
| 219 | 
    popupView.setSystemUiVisibility(RubikActivity.FLAGS);  | 
|
| 220 | 
     | 
|
| 221 | 
    mMenuPopup.showAsDropDown(view, (int)(-width/12), margin, Gravity.CENTER);  | 
|
| 222 | 
    mMenuPopup.update(view, mMenuLayoutWidth, mMenuLayoutHeight);  | 
|
| 223 | 
    mMenuPopup.setFocusable(true);  | 
|
| 224 | 
    mMenuPopup.update();  | 
|
| 225 | 
    }  | 
|
| 226 | 
    }  | 
|
| 227 | 
    });  | 
|
| 228 | 
    }  | 
|
| 229 | 
     | 
|
| 230 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 231 | 
     | 
|
| 232 | 
    private void setupObjectWindow(final RubikActivity act, final float width)  | 
|
| 233 | 
        {
   | 
|
| 234 | 
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  | 
|
| 235 | 
    final View layout = layoutInflater.inflate(R.layout.popup_objects, null);  | 
|
| 236 | 
    GridLayout objectGrid = layout.findViewById(R.id.objectGrid);  | 
|
| 237 | 
     | 
|
| 238 | 
    int[] indices = ObjectList.getIndices();  | 
|
| 239 | 
     | 
|
| 240 | 
    GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];  | 
|
| 241 | 
    GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];  | 
|
| 242 | 
     | 
|
| 243 | 
    objectGrid.setColumnCount(mColCount);  | 
|
| 244 | 
    objectGrid.setRowCount(mRowCount);  | 
|
| 245 | 
     | 
|
| 246 | 
    int[] nextInRow = new int[mRowCount];  | 
|
| 247 | 
     | 
|
| 248 | 
    for(int row=0; row<mRowCount; row++)  | 
|
| 249 | 
          {
   | 
|
| 250 | 
    rowSpecs[row] = GridLayout.spec(row);  | 
|
| 251 | 
    nextInRow[row]= 0;  | 
|
| 252 | 
    }  | 
|
| 253 | 
    for(int col=0; col<mColCount; col++)  | 
|
| 254 | 
          {
   | 
|
| 255 | 
    colSpecs[col] = GridLayout.spec(col);  | 
|
| 256 | 
    }  | 
|
| 257 | 
     | 
|
| 258 | 
    mObjectPopup = new PopupWindow(act);  | 
|
| 259 | 
    mObjectPopup.setContentView(layout);  | 
|
| 260 | 
    mObjectPopup.setFocusable(true);  | 
|
| 261 | 
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube2,R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2);  | 
|
| 262 | 
     | 
|
| 263 | 
    BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon);  | 
|
| 264 | 
    int cubeWidth = bd.getIntrinsicWidth();  | 
|
| 265 | 
    int margin = (int)(width*RubikActivity.LARGE_MARGIN);  | 
|
| 266 | 
    mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);  | 
|
| 267 | 
     | 
|
| 268 | 
    for(int object=0; object< ObjectList.NUM_OBJECTS; object++)  | 
|
| 269 | 
          {
   | 
|
| 270 | 
    final ObjectList list = ObjectList.getObject(object);  | 
|
| 271 | 
    final int[] sizes = list.getSizes();  | 
|
| 272 | 
    int[] icons = list.getIconIDs();  | 
|
| 273 | 
    int len = sizes.length;  | 
|
| 274 | 
    final int obj = object;  | 
|
| 275 | 
    int row = indices[object];  | 
|
| 276 | 
     | 
|
| 277 | 
    for(int i=0; i<len; i++)  | 
|
| 278 | 
            {
   | 
|
| 279 | 
    final int index = i;  | 
|
| 280 | 
     | 
|
| 281 | 
    ImageButton button = new ImageButton(act);  | 
|
| 282 | 
    button.setBackgroundResource(icons[i]);  | 
|
| 283 | 
    button.setOnClickListener( new View.OnClickListener()  | 
|
| 284 | 
              {
   | 
|
| 285 | 
    @Override  | 
|
| 286 | 
    public void onClick(View v)  | 
|
| 287 | 
                {
   | 
|
| 288 | 
    if( act.getPreRender().canPlay() && ScreenList.getCurrentState()== ScreenList.PLAY )  | 
|
| 289 | 
                  {
   | 
|
| 290 | 
    mObject = obj;  | 
|
| 291 | 
    mSize = sizes[index];  | 
|
| 292 | 
    act.changeObject(list,sizes[index], true);  | 
|
| 293 | 
    adjustLevels(act);  | 
|
| 294 | 
    mMoves.clear();  | 
|
| 295 | 
    }  | 
|
| 296 | 
     | 
|
| 297 | 
    mObjectPopup.dismiss();  | 
|
| 298 | 
    }  | 
|
| 299 | 
    });  | 
|
| 300 | 
     | 
|
| 301 | 
    GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);  | 
|
| 302 | 
    params.bottomMargin = margin;  | 
|
| 303 | 
    params.topMargin = margin;  | 
|
| 304 | 
    params.leftMargin = margin;  | 
|
| 305 | 
    params.rightMargin = margin;  | 
|
| 306 | 
     | 
|
| 307 | 
    nextInRow[row]++;  | 
|
| 308 | 
     | 
|
| 309 | 
    objectGrid.addView(button, params);  | 
|
| 310 | 
    }  | 
|
| 311 | 
    }  | 
|
| 312 | 
    }  | 
|
| 313 | 
     | 
|
| 314 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 315 | 
     | 
|
| 316 | 
    private void setupMenuWindow(final RubikActivity act, final float width)  | 
|
| 317 | 
        {
   | 
|
| 318 | 
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  | 
|
| 319 | 
    final View layout = layoutInflater.inflate(R.layout.popup_menu, null);  | 
|
| 320 | 
    LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);  | 
|
| 321 | 
     | 
|
| 322 | 
    mMenuPopup = new PopupWindow(act);  | 
|
| 323 | 
    mMenuPopup.setContentView(layout);  | 
|
| 324 | 
    mMenuPopup.setFocusable(true);  | 
|
| 325 | 
    int margin = (int)(width*RubikActivity.MARGIN);  | 
|
| 326 | 
    int padding = (int)(width*RubikActivity.PADDING);  | 
|
| 327 | 
     | 
|
| 328 | 
    mMenuLayoutWidth = (int)(width/2);  | 
|
| 329 | 
    mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));  | 
|
| 330 | 
     | 
|
| 331 | 
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);  | 
|
| 332 | 
     | 
|
| 333 | 
    for(int i=0; i<NUM_BUTTONS; i++)  | 
|
| 334 | 
          {
   | 
|
| 335 | 
    final int but = i;  | 
|
| 336 | 
    Button button = new Button(act);  | 
|
| 337 | 
    button.setLayoutParams(p);  | 
|
| 338 | 
    button.setText(BUTTON_LABELS[i]);  | 
|
| 339 | 
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);  | 
|
| 340 | 
     | 
|
| 341 | 
    button.setOnClickListener( new View.OnClickListener()  | 
|
| 342 | 
            {
   | 
|
| 343 | 
    @Override  | 
|
| 344 | 
    public void onClick(View v)  | 
|
| 345 | 
              {
   | 
|
| 346 | 
    mMenuPopup.dismiss();  | 
|
| 347 | 
    MenuAction(act,but);  | 
|
| 348 | 
    }  | 
|
| 349 | 
    });  | 
|
| 350 | 
     | 
|
| 351 | 
    menuLayout.addView(button);  | 
|
| 352 | 
    }  | 
|
| 353 | 
    }  | 
|
| 354 | 
     | 
|
| 355 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 356 | 
     | 
|
| 357 | 
    private void setupPlayWindow(final RubikActivity act, final float width)  | 
|
| 358 | 
        {
   | 
|
| 359 | 
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  | 
|
| 360 | 
    final View layout = layoutInflater.inflate(R.layout.popup_play, null);  | 
|
| 361 | 
    mPlayLayout = layout.findViewById(R.id.playGrid);  | 
|
| 362 | 
     | 
|
| 363 | 
    mPlayLayoutWidth = (int)(width*0.4f);  | 
|
| 364 | 
     | 
|
| 365 | 
    mPlayPopup = new PopupWindow(act);  | 
|
| 366 | 
    mPlayPopup.setContentView(layout);  | 
|
| 367 | 
    mPlayPopup.setFocusable(true);  | 
|
| 368 | 
     | 
|
| 369 | 
    adjustLevels(act);  | 
|
| 370 | 
    }  | 
|
| 371 | 
     | 
|
| 372 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 373 | 
     | 
|
| 374 | 
    private void controlTheCube()  | 
|
| 375 | 
        {
   | 
|
| 376 | 
        android.util.Log.e("D", "Control");
   | 
|
| 377 | 
    }  | 
|
| 378 | 
     | 
|
| 379 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 380 | 
     | 
|
| 381 | 
    private void MenuAction(RubikActivity act, int button)  | 
|
| 382 | 
        {
   | 
|
| 383 | 
    switch(button)  | 
|
| 384 | 
          {
   | 
|
| 385 | 
    case 0: RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();  | 
|
| 386 | 
    int object = play.getObject();  | 
|
| 387 | 
    int size = play.getSize();  | 
|
| 388 | 
    int sizeIndex = ObjectList.getSizeIndex(object,size);  | 
|
| 389 | 
    Bundle sBundle = new Bundle();  | 
|
| 390 | 
                  sBundle.putInt("tab", ObjectList.pack(object,sizeIndex) );
   | 
|
| 391 | 
                  sBundle.putBoolean("submitting", false);
   | 
|
| 392 | 
    RubikDialogScores scores = new RubikDialogScores();  | 
|
| 393 | 
    scores.setArguments(sBundle);  | 
|
| 394 | 
    scores.show(act.getSupportFragmentManager(), null);  | 
|
| 395 | 
    break;  | 
|
| 396 | 
    case 1: RubikDialogPattern pDiag = new RubikDialogPattern();  | 
|
| 397 | 
    Bundle pBundle = new Bundle();  | 
|
| 398 | 
    int pOrd = getPatternOrdinal();  | 
|
| 399 | 
                  pBundle.putInt("tab", pOrd );
   | 
|
| 400 | 
    pDiag.setArguments(pBundle);  | 
|
| 401 | 
    pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );  | 
|
| 402 | 
    break;  | 
|
| 403 | 
    case 2: controlTheCube();  | 
|
| 404 | 
    break;  | 
|
| 405 | 
    case 3: ScreenList.switchState(act, ScreenList.SVER);  | 
|
| 406 | 
    break;  | 
|
| 407 | 
    case 4: RubikDialogTutorial tDiag = new RubikDialogTutorial();  | 
|
| 408 | 
    Bundle tBundle = new Bundle();  | 
|
| 409 | 
    int tOrd = getTutorialOrdinal();  | 
|
| 410 | 
                  tBundle.putInt("tab", tOrd );
   | 
|
| 411 | 
    tDiag.setArguments(tBundle);  | 
|
| 412 | 
    tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );  | 
|
| 413 | 
    break;  | 
|
| 414 | 
    case 5: RubikDialogAbout aDiag = new RubikDialogAbout();  | 
|
| 415 | 
    aDiag.show(act.getSupportFragmentManager(), null);  | 
|
| 416 | 
    break;  | 
|
| 417 | 
    }  | 
|
| 418 | 
    }  | 
|
| 419 | 
     | 
|
| 420 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 421 | 
     | 
|
| 422 | 
    void setupSolveButton(final RubikActivity act, final float width)  | 
|
| 423 | 
        {
   | 
|
| 424 | 
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve);  | 
|
| 425 | 
    mSolveButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);  | 
|
| 426 | 
     | 
|
| 427 | 
    mSolveButton.setOnClickListener( new View.OnClickListener()  | 
|
| 428 | 
          {
   | 
|
| 429 | 
    @Override  | 
|
| 430 | 
    public void onClick(View v)  | 
|
| 431 | 
            {
   | 
|
| 432 | 
    act.getPreRender().solveObject();  | 
|
| 433 | 
    mMoves.clear();  | 
|
| 434 | 
    }  | 
|
| 435 | 
    });  | 
|
| 436 | 
    }  | 
|
| 437 | 
     | 
|
| 438 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 439 | 
     | 
|
| 440 | 
    public void savePreferences(SharedPreferences.Editor editor)  | 
|
| 441 | 
        {
   | 
|
| 442 | 
        editor.putInt("statePlay_object", mObject);
   | 
|
| 443 | 
        editor.putInt("statePlay_size"  , mSize);
   | 
|
| 444 | 
     | 
|
Also available in: Unified diff
Rename 'state' to 'screen'