Project

General

Profile

« Previous | Next » 

Revision 146661ec

Added by Leszek Koltunski over 3 years ago

Change the 'Cube Back' icon when there are no moves to back.

View differences:

src/main/java/org/distorted/helpers/MovesAndLockController.java
76 76
    {
77 77
    if( act.retLocked() )
78 78
      {
79
      return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked);
79
      return RubikActivity.getDrawable(R.drawable.ui_small_locked,
80
                                       R.drawable.ui_medium_locked,
81
                                       R.drawable.ui_big_locked,
82
                                       R.drawable.ui_huge_locked);
80 83
      }
81 84
    else
82 85
      {
83
      return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked);
86
      return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,
87
                                       R.drawable.ui_medium_unlocked,
88
                                       R.drawable.ui_big_unlocked,
89
                                       R.drawable.ui_huge_unlocked);
90
      }
91
    }
92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

  
95
  public int getPrevIcon(boolean on)
96
    {
97
    if( on )
98
      {
99
      return RubikActivity.getDrawable(R.drawable.ui_small_cube_back,
100
                                       R.drawable.ui_medium_cube_back,
101
                                       R.drawable.ui_big_cube_back,
102
                                       R.drawable.ui_huge_cube_back);
103
      }
104
    else
105
      {
106
      return RubikActivity.getDrawable(R.drawable.ui_small_cube_grey,
107
                                       R.drawable.ui_medium_cube_grey,
108
                                       R.drawable.ui_big_cube_grey,
109
                                       R.drawable.ui_huge_cube_grey);
84 110
      }
85 111
    }
86 112

  
87 113
//////////////////////////////////////////////////////////////////////////////////////////////////
88 114

  
89
  public void backMove(TwistyPreRender pre)
115
  public void backMove(TwistyActivity act)
90 116
    {
91 117
    if( mCanPrevMove )
92 118
      {
......
103 129
        if( angle!=0 )
104 130
          {
105 131
          mCanPrevMove = false;
106
          mPre = pre;
107
          pre.blockTouch();
108
          pre.addRotation(this, axis, row, -angle, duration);
132
          mPre = act.getTwistyPreRender();
133
          mPre.blockTouch();
134
          mPre.addRotation(this, axis, row, -angle, duration);
109 135
          }
110 136
        else
111 137
          {
112 138
          android.util.Log.e("solution", "error: trying to back move of angle 0");
113 139
          }
140

  
141
        if( numMoves==1 ) changeBackMove(act, false);
114 142
        }
115 143
      }
116 144
    }
117 145

  
118 146
///////////////////////////////////////////////////////////////////////////////////////////////////
119 147

  
120
  public void addMove(int axis, int row, int angle)
148
  private void changeBackMove(TwistyActivity act, final boolean on)
149
    {
150
    act.runOnUiThread(new Runnable()
151
      {
152
      @Override
153
      public void run()
154
        {
155
        if( mPrevButton!=null )
156
          mPrevButton.setImageResource(getPrevIcon(on));
157
        }
158
      });
159
    }
160

  
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

  
163
  public void addMove(TwistyActivity act, int axis, int row, int angle)
121 164
    {
165
    if( mMoves.isEmpty()) changeBackMove(act,true);
122 166
    mMoves.add(new Move(axis,row,angle));
123 167
    }
124 168

  
......
141 185

  
142 186
  public void setupPrevButton(final TwistyActivity act, final float width)
143 187
    {
144
    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);
188
    final int icon = getPrevIcon( !mMoves.isEmpty() );
145 189
    mPrevButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
146 190

  
147 191
    mPrevButton.setOnClickListener( new View.OnClickListener()
......
149 193
      @Override
150 194
      public void onClick(View v)
151 195
        {
152
        TwistyPreRender pre = act.getTwistyPreRender();
153
        backMove(pre);
196
        backMove(act);
154 197
        }
155 198
      });
156 199
    }
src/main/java/org/distorted/main/RubikSurfaceView.java
399 399
        {
400 400
        if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
401 401
          {
402
          RubikActivity act = (RubikActivity)getContext();
402 403
          RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
403
          solving.addMove(mCurrentAxis, mCurrentRow, angle);
404
          solving.addMove(act, mCurrentAxis, mCurrentRow, angle);
404 405
          }
405 406
        if( ScreenList.getCurrentScreen()== ScreenList.PLAY )
406 407
          {
408
          RubikActivity act = (RubikActivity)getContext();
407 409
          RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
408
          play.addMove(mCurrentAxis, mCurrentRow, angle);
410
          play.addMove(act, mCurrentAxis, mCurrentRow, angle);
409 411
          }
410 412
        }
411 413

  
src/main/java/org/distorted/screens/RubikScreenBase.java
23 23
import android.widget.LinearLayout;
24 24

  
25 25
import org.distorted.helpers.MovesAndLockController;
26
import org.distorted.helpers.TwistyActivity;
26 27
import org.distorted.main.R;
27 28
import org.distorted.main.RubikActivity;
28 29

  
......
36 37

  
37 38
  void createBottomPane(final RubikActivity act, float width, ImageButton button)
38 39
    {
39
    if( mController==null ) mController = new MovesAndLockController();
40

  
41 40
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
42 41
    layoutBot.removeAllViews();
43 42

  
......
68 67
    mController.setLockState(act);
69 68
    }
70 69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
// PUBLIC API
72

  
73
  public RubikScreenBase()
74
    {
75
    mController = new MovesAndLockController();
76
    }
77

  
71 78
///////////////////////////////////////////////////////////////////////////////////////////////////
72 79

  
73
  public void addMove(int axis, int row, int angle)
80
  public void addMove(TwistyActivity act, int axis, int row, int angle)
74 81
    {
75
    mController.addMove(axis,row,angle);
82
    mController.addMove(act,axis,row,angle);
76 83
    }
77 84
  }
src/main/java/org/distorted/tutorials/TutorialState.java
24 24
import android.widget.LinearLayout;
25 25

  
26 26
import org.distorted.helpers.MovesAndLockController;
27
import org.distorted.helpers.TwistyActivity;
27 28
import org.distorted.main.R;
28 29
import org.distorted.main.RubikActivity;
29 30
import org.distorted.objects.ObjectList;
......
36 37
public class TutorialState
37 38
{
38 39
  private ImageButton mSolveButton, mScrambleButton, mBackButton;
39
  private MovesAndLockController mController;
40
  private final MovesAndLockController mController;
40 41

  
41 42
///////////////////////////////////////////////////////////////////////////////////////////////////
42 43

  
......
100 101

  
101 102
  void createRightPane(final TutorialActivity act, float width)
102 103
    {
103
    if( mController==null ) mController = new MovesAndLockController();
104

  
105 104
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
106 105
    layout.removeAllViews();
107 106

  
......
120 119

  
121 120
///////////////////////////////////////////////////////////////////////////////////////////////////
122 121

  
123
  void addMove(int axis, int row, int angle)
122
  void addMove(TwistyActivity act, int axis, int row, int angle)
123
    {
124
    mController.addMove(act, axis,row,angle);
125
    }
126

  
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
// PUBLIC API
129

  
130
  public TutorialState()
124 131
    {
125
    mController.addMove(axis,row,angle);
132
    mController = new MovesAndLockController();
126 133
    }
127 134
}
src/main/java/org/distorted/tutorials/TutorialSurfaceView.java
373 373
        {
374 374
        final TutorialActivity act = (TutorialActivity)getContext();
375 375
        TutorialState state = act.getState();
376
        state.addMove(mCurrentAxis, mCurrentRow, angle);
376
        state.addMove(act,mCurrentAxis, mCurrentRow, angle);
377 377
        }
378 378

  
379 379
      mContinuingRotation = false;

Also available in: Unified diff