Project

General

Profile

« Previous | Next » 

Revision 78843d15

Added by Leszek Koltunski about 1 month ago

Improve the Phased Solver App (show phases)

View differences:

src/main/java/org/distorted/phasedsolver/SolverLowerPane.java
49 49

  
50 50
  void backPhase(SolverActivity act)
51 51
    {
52
    if( mCurrMove>0 )
53
      {
54
      int[][] moves = transformMoves(mMoves[mCurrPhase],0,mCurrMove, false);
55
      mControl = act.getControl();
56
      mControl.applyScrambles(moves);
57
      mCurrMove = 0;
58
      }
59
    else if( mCurrPhase>0 )
60
      {
61
      mCurrPhase--;
62
      mNumMoves = mMoves[mCurrPhase].length;
63
      int[][] moves = transformMoves(mMoves[mCurrPhase],0,mNumMoves, false);
64
      mControl = act.getControl();
65
      mControl.applyScrambles(moves);
66
      }
67
    else
68
      {
69
      mCurrPhase = mNumPhases-1;
70
      mNumMoves = mMoves[mCurrPhase].length;
71
      mCurrMove = mNumMoves;
72
      mControl = act.getControl();
73

  
74
      int[][] moves = transformMoves(mMoves, true);
75
      mControl.applyScrambles(moves);
76
      }
52 77

  
78
    setText(act);
53 79
    }
54 80

  
55 81
///////////////////////////////////////////////////////////////////////////////////////////////////
56 82

  
57 83
  void nextPhase(SolverActivity act)
58 84
    {
85
    if( mCurrMove<mNumMoves )
86
      {
87
      int[][] moves = transformMoves(mMoves[mCurrPhase],mCurrMove,mNumMoves, true);
88
      mCurrMove = mNumMoves;
89
      mControl = act.getControl();
90
      mControl.applyScrambles(moves);
91
      }
92
    else if( mCurrPhase<mNumPhases-1 )
93
      {
94
      mCurrPhase++;
95
      mNumMoves = mMoves[mCurrPhase].length;
96
      mCurrMove = mNumMoves;
97
      int[][] moves = transformMoves(mMoves[mCurrPhase],0,mNumMoves, true);
98
      mControl = act.getControl();
99
      mControl.applyScrambles(moves);
100
      }
101
    else
102
      {
103
      mCurrPhase = 0;
104
      mNumMoves = mMoves[mCurrPhase].length;
105
      mCurrMove = 0;
106
      mControl = act.getControl();
107
      int[][] moves = transformMoves(mMoves, false);
108
      mControl.applyScrambles(moves);
109
      }
59 110

  
111
    setText(act);
60 112
    }
61 113

  
62 114
///////////////////////////////////////////////////////////////////////////////////////////////////
63 115

  
64 116
  private void setText(SolverActivity act)
65 117
    {
118
    int currMove = 0;
119
    int totalMove = 0;
120

  
121
    if( mMoves!=null )
122
      {
123
      currMove = mCurrMove;
124
      for(int p=0; p<mCurrPhase; p++) currMove  += (mMoves[p]==null ? 0: mMoves[p].length);
125
      for(int p=0; p<mNumPhases; p++) totalMove += (mMoves[p]==null ? 0: mMoves[p].length);
126
      }
127

  
128
    final int cMove = currMove;
129
    final int tMove = totalMove;
130

  
66 131
    act.runOnUiThread(new Runnable()
67 132
      {
68 133
      @Override
69 134
      public void run()
70 135
        {
71
        mPhase.setText(mPhaseNames[mCurrPhase]);
72
        mText.setText(mCurrMove+"/"+mNumMoves);
136
        mPhase.setText(mPhaseNames[mCurrPhase]+" "+mCurrMove+"/"+mNumMoves);
137
        mText.setText(cMove+"/"+tMove);
73 138
        }
74 139
      });
75 140
    }
76 141

  
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

  
144
  private int[][] transformMoves(int[][] moves, int start, int end, boolean front)
145
    {
146
    int mult = front ? 1:-1;
147
    int len = end-start;
148
    int[][] ret = new int[len][];
149

  
150
    for(int m=0; m<len; m++)
151
      {
152
      int[] mv = moves[front ? start+m : end-1-m];
153
      int[] rt = new int[3];
154
      rt[0] = mv[0];
155
      rt[1] = (1<<mv[1]);
156
      rt[2] = mult*mv[2];
157
      ret[m] = rt;
158
      }
159

  
160
    return ret;
161
    }
162

  
77 163
///////////////////////////////////////////////////////////////////////////////////////////////////
78 164

  
79 165
  private int[][] transformMoves(int[][][] moves, boolean front)
src/main/res/layout/mainlayout.xml
56 56
        android:textAppearance="?android:attr/textAppearanceLarge"
57 57
        android:gravity="center_vertical|start"/>
58 58

  
59
    <LinearLayout
60
        android:id="@+id/phaseBar"
61
        android:layout_above="@id/lowerBar"
62
        android:layout_width="match_parent"
63
        android:layout_height="70dp"
64
        android:orientation="horizontal"
65
        android:background="@android:color/transparent">
66

  
67
        <ImageButton
68
            android:id="@+id/solverPhaseLeft"
69
            android:background="@drawable/ui_left"
70
            android:layout_width="0dp"
71
            android:layout_height="match_parent"
72
            android:layout_weight="1.0"
73
            android:gravity="center_vertical|center"
74
            android:onClick="PhaseLeft"
75
            android:layout_gravity="center_vertical"/>
76

  
77
        <TextView
78
            android:id="@+id/solverPhaseName"
79
            android:layout_width="0dp"
80
            android:layout_height="match_parent"
81
            android:layout_weight="5"
82
            android:gravity="center"
83
            android:textSize="20sp"/>
84

  
85
        <ImageButton
86
            android:id="@+id/solverPhaseRight"
87
            android:background="@drawable/ui_right"
88
            android:layout_width="0dp"
89
            android:layout_height="match_parent"
90
            android:layout_weight="1.0"
91
            android:gravity="center_vertical|center"
92
            android:onClick="PhaseRight"
93
            android:layout_gravity="center_vertical"/>
94

  
95
    </LinearLayout>
96

  
59 97
    <LinearLayout
60 98
        android:id="@+id/lowerBar"
61 99
        android:layout_alignParentBottom="true"
62 100
        android:layout_width="match_parent"
63
        android:layout_height="80dp"
101
        android:layout_height="70dp"
64 102
        android:orientation="horizontal"
65 103
        android:background="@android:color/transparent">
66 104

  
......
74 112
            android:onClick="Left"
75 113
            android:layout_gravity="center_vertical"/>
76 114

  
77
        <LinearLayout
115
        <TextView
116
            android:id="@+id/solverText"
78 117
            android:layout_width="0dp"
79 118
            android:layout_height="match_parent"
80
            android:layout_weight="5.0"
81
            android:orientation="vertical"
82
            android:background="@android:color/transparent">
83

  
84
            <TextView
85
                android:id="@+id/solverPhaseName"
86
                android:layout_width="match_parent"
87
                android:layout_height="0dp"
88
                android:layout_weight="1"
89
                android:gravity="center"
90
                android:textSize="20sp"/>
91
            <TextView
92
                android:id="@+id/solverText"
93
                android:layout_width="match_parent"
94
                android:layout_height="0dp"
95
                android:layout_weight="2"
96
                android:gravity="center"
97
                android:textSize="30sp"/>
98

  
99
        </LinearLayout>
119
            android:layout_weight="5"
120
            android:gravity="center"
121
            android:textSize="20sp"/>
100 122

  
101 123
        <ImageButton
102 124
            android:id="@+id/solverRight"
......
107 129
            android:gravity="center_vertical|center"
108 130
            android:onClick="Right"
109 131
            android:layout_gravity="center_vertical"/>
132

  
110 133
    </LinearLayout>
111 134

  
112 135
</RelativeLayout>

Also available in: Unified diff