Project

General

Profile

« Previous | Next » 

Revision 264af0ad

Added by Leszek Koltunski about 4 years ago

More support for the 3x3x3 Solver.

View differences:

src/main/java/org/distorted/uistate/RubikState.java
26 26

  
27 27
public enum RubikState
28 28
  {
29
  MAIN ( null , false, new RubikStateMain()    ),
30
  PLAY ( MAIN , true , new RubikStatePlay()    ),
31
  SOLV ( PLAY , true , new RubikStateSolving() ),
32
  PATT ( MAIN , false, new RubikStatePattern() ),
33
  SVER ( MAIN , false, new RubikStateSolver()  ),
29
  MAIN ( null , false, new RubikStateMain()      ),
30
  PLAY ( MAIN , true , new RubikStatePlay()      ),
31
  SOLV ( PLAY , true , new RubikStateSolving()   ),
32
  PATT ( MAIN , false, new RubikStatePattern()   ),
33
  SVER ( MAIN , false, new RubikStateSolver()    ),
34
  SOLU ( SVER , false, new RubikStateSolution()  ),
34 35
  ;
35 36

  
36 37
  public static final int LENGTH = values().length;
src/main/java/org/distorted/uistate/RubikStateSolution.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.uistate;
21

  
22
import android.content.SharedPreferences;
23
import android.util.DisplayMetrics;
24
import android.view.Gravity;
25
import android.view.LayoutInflater;
26
import android.view.View;
27
import android.widget.Button;
28
import android.widget.ImageButton;
29
import android.widget.LinearLayout;
30
import android.widget.TextView;
31

  
32
import org.distorted.magic.R;
33
import org.distorted.magic.RubikActivity;
34

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
public class RubikStateSolution extends RubikStateAbstract
38
  {
39
  private Button mBackButton;
40
  private ImageButton mPrevButton, mNextButton;
41
  private TextView mMovesText;
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
  void leaveState(RubikActivity act)
46
    {
47

  
48
    }
49

  
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

  
52
  void enterState(final RubikActivity act)
53
    {
54
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
55
    final float scale = metrics.density;
56
    LayoutInflater inflater = act.getLayoutInflater();
57

  
58
    // TOP ////////////////////////////
59
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
60
    layoutTop.removeAllViews();
61

  
62
    final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
63
    text.setText(R.string.solution);
64
    layoutTop.addView(text);
65

  
66
    // BOT ////////////////////////////
67
    if( mPrevButton==null ) setupPrevButton(act,scale);
68
    if( mNextButton==null ) setupNextButton(act,scale);
69
    if( mMovesText ==null ) setupTextView(act,scale);
70

  
71
    LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
72
    layoutLeft.removeAllViews();
73
    layoutLeft.addView(mPrevButton);
74
    layoutLeft.addView(mMovesText);
75
    layoutLeft.addView(mNextButton);
76

  
77
    if( mBackButton==null ) setupBackButton(act,scale);
78

  
79
    LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
80
    layoutRight.removeAllViews();
81
    layoutRight.addView(mBackButton);
82
    }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
  private void setupPrevButton(final RubikActivity act, final float scale)
87
    {
88
    int padding = (int)(3*scale + 0.5f);
89
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
90
    mPrevButton = new ImageButton(act);
91
    mPrevButton.setLayoutParams(params);
92
    mPrevButton.setPadding(padding,0,padding,0);
93
    mPrevButton.setImageResource(R.drawable.left);
94

  
95
    mPrevButton.setOnClickListener( new View.OnClickListener()
96
      {
97
      @Override
98
      public void onClick(View v)
99
        {
100

  
101
        }
102
      });
103
    }
104

  
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

  
107
  private void setupNextButton(final RubikActivity act, final float scale)
108
    {
109
    int padding = (int)( 3*scale + 0.5f);
110
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
111
    mNextButton = new ImageButton(act);
112
    mNextButton.setLayoutParams(params);
113
    mNextButton.setPadding(padding,0,padding,0);
114
    mNextButton.setImageResource(R.drawable.right);
115

  
116
    mNextButton.setOnClickListener( new View.OnClickListener()
117
      {
118
      @Override
119
      public void onClick(View v)
120
        {
121

  
122
        }
123
      });
124
    }
125

  
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

  
128
  private void setupTextView(final RubikActivity act, final float scale)
129
    {
130
    int padding = (int)( 3*scale + 0.5f);
131
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f);
132

  
133
    mMovesText = new TextView(act);
134
    mMovesText.setTextSize(20);
135
    mMovesText.setLayoutParams(params);
136
    mMovesText.setPadding(padding,0,padding,0);
137
    mMovesText.setGravity(Gravity.CENTER);
138
    mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));
139
    }
140

  
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

  
143
  private void setupBackButton(final RubikActivity act, final float scale)
144
    {
145
    int padding = (int)(3*scale + 0.5f);
146
    LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
147
    mBackButton = new Button(act);
148
    mBackButton.setLayoutParams(backParams);
149
    mBackButton.setPadding(padding,0,padding,0);
150
    mBackButton.setText(R.string.back);
151

  
152
    mBackButton.setOnClickListener( new View.OnClickListener()
153
      {
154
      @Override
155
      public void onClick(View v)
156
        {
157
        RubikState.goBack(act);
158
        }
159
      });
160
    }
161

  
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

  
164
  public void savePreferences(SharedPreferences.Editor editor)
165
    {
166
    mBackButton = null;
167
    }
168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

  
171
  public void restorePreferences(SharedPreferences preferences)
172
    {
173

  
174
    }
175
  }
src/main/java/org/distorted/uistate/RubikStateSolver.java
49 49

  
50 50
  private static Bitmap[] mBitmap;
51 51
  private ImageButton[] mColorButton;
52
  private Button mBackButton;
52
  private Button mBackButton, mSolveButton;
53 53

  
54 54
///////////////////////////////////////////////////////////////////////////////////////////////////
55 55

  
......
77 77
    for(ImageButton button: mColorButton) layoutTop.addView(button);
78 78

  
79 79
    // BOT ////////////////////////////
80
    if( mSolveButton==null ) setupSolveButton(act,scale);
81

  
82
    LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
83
    layoutLeft.removeAllViews();
84
    layoutLeft.addView(mSolveButton);
85

  
80 86
    if( mBackButton==null ) setupBackButton(act,scale);
81 87

  
82 88
    LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
......
143 149
      }
144 150
    }
145 151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

  
154
  private void setupSolveButton(final RubikActivity act, final float scale)
155
    {
156
    int padding = (int)(3*scale + 0.5f);
157
    LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
158
    mSolveButton = new Button(act);
159
    mSolveButton.setLayoutParams(backParams);
160
    mSolveButton.setPadding(padding,0,padding,0);
161
    mSolveButton.setText(R.string.solve);
162

  
163
    mSolveButton.setOnClickListener( new View.OnClickListener()
164
      {
165
      @Override
166
      public void onClick(View v)
167
        {
168
        RubikState.switchState(act,RubikState.SOLU);
169
        }
170
      });
171
    }
172

  
146 173
///////////////////////////////////////////////////////////////////////////////////////////////////
147 174

  
148 175
  private void setupBackButton(final RubikActivity act, final float scale)
src/main/res/values/strings.xml
21 21
    <string name="yes">YES</string>
22 22
    <string name="no">NO</string>
23 23
    <string name="you">YOU</string>
24
    <string name="solution">Solution</string>
24 25
    <string name="ready">Ready?</string>
25 26
    <string name="sizechange_effect">Size Change Effect</string>
26 27
    <string name="solve_effect">Solve Effect</string>

Also available in: Unified diff