Project

General

Profile

« Previous | Next » 

Revision d18993ac

Added by Leszek Koltunski about 4 years ago

Progress with Pretty Patterns.

View differences:

src/main/java/org/distorted/dialog/RubikDialogPattern.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.dialog;
21

  
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
import android.support.annotation.NonNull;
26
import android.support.v4.app.FragmentActivity;
27
import android.support.v4.view.ViewPager;
28
import android.support.v7.app.AlertDialog;
29
import android.support.v7.app.AppCompatDialogFragment;
30
import android.support.design.widget.TabLayout;
31
import android.view.LayoutInflater;
32
import android.view.View;
33
import android.view.Window;
34
import android.view.WindowManager;
35
import android.widget.ImageView;
36
import android.widget.TextView;
37

  
38
import org.distorted.magic.R;
39
import org.distorted.patterns.RubikPattern;
40

  
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

  
43
public class RubikDialogPattern extends AppCompatDialogFragment
44
  {
45
  RubikDialogPatternPagerAdapter mPagerAdapter;
46

  
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

  
49
  @Override
50
  public void onStart()
51
    {
52
    super.onStart();
53

  
54
    Window window = getDialog().getWindow();
55
    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
56
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
57
    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
  @NonNull
63
  @Override
64
  public Dialog onCreateDialog(Bundle savedInstanceState)
65
    {
66
    FragmentActivity act = getActivity();
67
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
68

  
69
    LayoutInflater layoutInflater = act.getLayoutInflater();
70
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
71
    tv.setText(R.string.patterns);
72
    builder.setCustomTitle(tv);
73

  
74
    builder.setCancelable(true);
75
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
76
      {
77
      @Override
78
      public void onClick(DialogInterface dialog, int which)
79
        {
80

  
81
        }
82
      });
83

  
84
    LayoutInflater inflater = act.getLayoutInflater();
85
    final View view = inflater.inflate(R.layout.dialog_tabbed, null);
86
    builder.setView(view);
87

  
88
    ViewPager viewPager = view.findViewById(R.id.viewpager);
89
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
90
    mPagerAdapter = new RubikDialogPatternPagerAdapter(act, viewPager);
91
    tabLayout.setupWithViewPager(viewPager);
92

  
93
    int[] iconID = { R.drawable.cube2, R.drawable.cube3, R.drawable.cube4, R.drawable.cube5 };
94

  
95
    for(int i=0; i< RubikPattern.NUM_CUBES; i++)
96
      {
97
      ImageView imageView = new ImageView(act);
98
      imageView.setImageResource(iconID[i]);
99
      TabLayout.Tab tab = tabLayout.getTabAt(i);
100
      if(tab!=null) tab.setCustomView(imageView);
101
      }
102

  
103
    return builder.create();
104
    }
105
  }
src/main/java/org/distorted/dialog/RubikDialogPatternPagerAdapter.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.dialog;
21

  
22
import android.support.annotation.NonNull;
23
import android.support.v4.app.FragmentActivity;
24
import android.support.v4.view.PagerAdapter;
25
import android.support.v4.view.ViewPager;
26
import android.view.View;
27
import android.view.ViewGroup;
28
import android.widget.LinearLayout;
29

  
30
import org.distorted.patterns.RubikPattern;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
class RubikDialogPatternPagerAdapter extends PagerAdapter
35
  {
36
  private FragmentActivity mAct;
37
  private RubikDialogPatternView[] mViews;
38
  private int mNumTabs;
39

  
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
// TODO: temporary mockup
42

  
43
  private String[] createCategories(int pos)
44
    {
45
    String[] ret = new String[8];
46

  
47
    for(int i=0; i<8; i++)
48
      {
49
      ret[i] = "CATEGORY "+pos+" "+i;
50
      }
51

  
52
    return ret;
53
    }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  RubikDialogPatternPagerAdapter(FragmentActivity act, ViewPager viewPager)
58
    {
59
    mAct = act;
60
    mNumTabs = RubikPattern.NUM_CUBES;
61
    mViews = new RubikDialogPatternView[mNumTabs];
62

  
63
    viewPager.setAdapter(this);
64
    viewPager.setOffscreenPageLimit(mNumTabs-1);
65
    }
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
  @Override
70
  @NonNull
71
  public Object instantiateItem(@NonNull ViewGroup collection, final int position)
72
    {
73
    mViews[position] = new RubikDialogPatternView(mAct);
74
    collection.addView(mViews[position]);
75

  
76
    String[] categories = createCategories(position);
77
    final LinearLayout section = mViews[position].createSection(mAct, categories);
78

  
79
    mAct.runOnUiThread(new Runnable()
80
        {
81
        @Override
82
        public void run()
83
          {
84
          mViews[position].addSection(section);
85
          }
86
        });
87

  
88
    return mViews[position];
89
    }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
  @Override
94
  public void destroyItem(ViewGroup collection, int position, @NonNull Object view)
95
    {
96
    collection.removeView((View) view);
97
    }
98

  
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

  
101
  @Override
102
  public int getCount()
103
    {
104
    return mNumTabs;
105
    }
106

  
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

  
109
  @Override
110
  public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
111
    {
112
    return view == object;
113
    }
114
  }
src/main/java/org/distorted/dialog/RubikDialogPatternView.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.dialog;
21

  
22
import android.content.Context;
23
import android.support.v4.app.FragmentActivity;
24
import android.util.DisplayMetrics;
25
import android.view.View;
26
import android.widget.Button;
27
import android.widget.FrameLayout;
28
import android.widget.LinearLayout;
29

  
30
import org.distorted.magic.R;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
public class RubikDialogPatternView extends FrameLayout
35
  {
36
  LinearLayout mLayout;
37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

  
40
  public RubikDialogPatternView(Context context)
41
    {
42
    super(context);
43

  
44
    View tab = inflate( context, R.layout.dialog_tab, null);
45
    mLayout = tab.findViewById(R.id.tabLayout);
46
    addView(tab);
47
    }
48

  
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

  
51
  LinearLayout createSection(FragmentActivity act, final String[] categories)
52
    {
53
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
54
    LinearLayout layout = new LinearLayout(act);
55
    layout.setLayoutParams(params);
56
    layout.setOrientation(LinearLayout.VERTICAL);
57

  
58
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
59
    final float scale = metrics.density;
60
    int len = categories.length;
61
    int margin = (int)(3*scale + 0.5f);
62
    LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
63
    bParams.setMargins(margin, margin, margin, margin);
64

  
65
    for(int i=0; i<len; i++)
66
      {
67
      android.util.Log.e("view", "adding button "+i +" to layout!");
68

  
69

  
70
      final int fi = i;
71
      Button button = new Button(act);
72
      button.setLayoutParams(bParams);
73
      button.setText(categories[i]);
74

  
75
      button.setOnClickListener( new View.OnClickListener()
76
        {
77
        @Override
78
        public void onClick(View view)
79
          {
80
          android.util.Log.e("view", "category "+categories[fi]+" clicked");
81
          }
82
        });
83
      }
84

  
85
    return layout;
86
    }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
// needs to run on UI thread
90

  
91
  void addSection(LinearLayout section)
92
    {
93
    android.util.Log.e("view", "adding section to tab!");
94

  
95
    mLayout.addView(section);
96
    }
97
  }
src/main/java/org/distorted/dialog/RubikDialogScores.java
97 97
      }
98 98

  
99 99
    LayoutInflater inflater = act.getLayoutInflater();
100
    final View view = inflater.inflate(R.layout.dialog_scores, null);
100
    final View view = inflater.inflate(R.layout.dialog_tabbed, null);
101 101
    builder.setView(view);
102 102

  
103 103
    ViewPager viewPager = view.findViewById(R.id.viewpager);
src/main/java/org/distorted/dialog/RubikDialogScoresView.java
157 157
    {
158 158
    removeAllViews();
159 159

  
160
    View tab = inflate(act, R.layout.dialog_scores_tab, null);
160
    View tab = inflate(act, R.layout.dialog_tab, null);
161 161
    mLayout = tab.findViewById(R.id.tabLayout);
162 162
    addView(tab);
163 163
    }
src/main/java/org/distorted/magic/RubikActivity.java
26 26
import android.view.View;
27 27

  
28 28
import org.distorted.dialog.RubikDialogAbout;
29
import org.distorted.dialog.RubikDialogPattern;
29 30
import org.distorted.dialog.RubikDialogScores;
30 31
import org.distorted.dialog.RubikDialogEffects;
31 32
import org.distorted.effect.BaseEffect;
......
227 228

  
228 229
    public void Patterns(View v)
229 230
      {
230
      android.util.Log.e("act", "Not implemented yet");
231
      RubikDialogPattern diag = new RubikDialogPattern();
232
      diag.show(getSupportFragmentManager(), null);
231 233
      }
232 234

  
233 235
///////////////////////////////////////////////////////////////////////////////////////////////////
......
241 243

  
242 244
    public void About(View v)
243 245
      {
244
      RubikDialogAbout about = new RubikDialogAbout();
245
      about.show(getSupportFragmentManager(), null);
246
      RubikDialogAbout diag = new RubikDialogAbout();
247
      diag.show(getSupportFragmentManager(), null);
246 248
      }
247 249

  
248 250
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/patterns/RubikPattern.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.patterns;
21

  
22
import java.util.Vector;
23
import android.graphics.Paint;
24

  
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

  
27
public class RubikPattern
28
{
29
  private static final int MIN_CUBE  = 2;
30
  private static final int MAX_CUBE  = 5;
31
  public  static final int NUM_CUBES = MAX_CUBE-MIN_CUBE+1;
32

  
33
  public int[] numCategories = new int[NUM_CUBES];
34
  private static String buffer="";
35
  private static Paint mPaint = new Paint();
36
  private static int width;
37

  
38
  private Vector<Category>[] mCategories;
39

  
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

  
42
  private class Category
43
    {
44
    private String name;
45
    private int numpatterns;
46
    private Vector<Pattern> patterns;
47
    private int curPattern;
48

  
49
    public Category(String n)
50
      {
51
      name=n;
52
      curPattern=0;
53
      numpatterns=0;
54
      patterns = new Vector<>();
55
      }
56
    public void addPattern(Pattern p)
57
      {
58
      patterns.addElement(p);
59
      numpatterns++;
60
      }
61
    public int getNumPatterns()
62
    {
63
    return numpatterns;
64
    };
65
    public String getName()
66
    {
67
    return name;
68
    }
69
    public void next()
70
      {
71
      curPattern++;
72
      if( curPattern>=numpatterns )
73
        curPattern=0;
74
      }
75
    public void prev()
76
      {
77
      curPattern--;
78
      if( curPattern<0 )
79
        curPattern=numpatterns-1;
80
      }
81
    public String getPatternName()
82
      {
83
      Pattern p = patterns.elementAt(curPattern);
84
      return  p!=null ? p.getName(curPattern+1,numpatterns):null;
85
      }
86
    public int getPatternCurMove()
87
      {
88
      Pattern p = patterns.elementAt(curPattern);
89
      return  p!=null ? p.getCurMove():-1;
90
      }
91
    public int getPatternNumMove()
92
      {
93
      Pattern p = patterns.elementAt(curPattern);
94
      return  p!=null ? p.getNumMove():-1;
95
      }
96
    public void initializeCube()
97
      {
98
      Pattern p = patterns.elementAt(curPattern);
99
      if( p!=null ) p.initializeCube();
100
      }
101
    public void makeNextMove()
102
      {
103
      Pattern p = patterns.elementAt(curPattern);
104
      if( p!=null ) p.makeNextMove();
105
      }
106
    public void makePrevMove()
107
      {
108
      Pattern p = patterns.elementAt(curPattern);
109
      if( p!=null ) p.makePrevMove();
110
      }
111
    }
112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

  
115
  private class Pattern
116
    {
117
    private String name;
118
    private String shortname=null;
119
    private String moves;
120
    private int curmove;
121
    private int nummove;
122

  
123
    public Pattern(String n, String m)
124
      {
125
      name=n;
126
      moves=m;
127
      nummove = moves.length()/4;
128
      curmove=nummove;
129
      }
130
    public String getName(int cur,int num)
131
      {
132
      if( shortname==null ) shortname=cutPatternName(name);
133
      return shortname;
134
      }
135
    public int getNumMove()
136
    {
137
    return nummove;
138
    }
139
    public int getCurMove()
140
    {
141
    return curmove;
142
    }
143
    public void makeNextMove()
144
      {
145
      curmove++;
146
      if( curmove>nummove)
147
        {
148
        curmove= 0;
149
        initializeCube();
150
        }
151
      else
152
        {
153

  
154
// TODO
155
//        RubikCube cube = world.getCube();
156
//        if( cube!=null && !cube.makeMove(moves.substring(4*curmove-4,4*curmove)) )
157
          curmove--;
158
        }
159
      }
160
    public void makePrevMove()
161
      {
162
      curmove--;
163
      if( curmove<0)
164
        {
165
        curmove=nummove;
166
        initializeCube();
167
        }
168
      else
169
        {
170
// TODO
171
//        RubikCube cube = world.getCube();
172
//        if( cube!=null && !cube.backMove(moves.substring(4*curmove,4*curmove+4)) )
173
          curmove++;
174
        }
175
      }
176
    public void initializeCube()
177
      {
178
// TODO
179
//	    RubikCube cube = world.getCube();
180
//      if( cube!=null ) cube.setupPosition(moves.substring(0,4*curmove));
181
      }
182
    }
183

  
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

  
186
  public RubikPattern(int wi, int h)
187
    {
188
    width = wi;
189
    mCategories = new Vector[NUM_CUBES];
190
    mPaint.setTextSize(h);
191
  
192
    initializeCategories(0, RubikPatternData2.patterns);
193
    initializeCategories(1, RubikPatternData3.patterns);
194
    initializeCategories(2, RubikPatternData4.patterns);
195
    initializeCategories(3, RubikPatternData5.patterns);
196
    }
197

  
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

  
200
  private void initializeCategories(int num, String[] pat)
201
    {
202
    int colon;
203
    mCategories[num] = new Vector<>();
204
    Category cat=null;
205
    String name, pattern;
206
    Pattern patt;
207

  
208
    numCategories[num]=0;
209

  
210
    for(String p: pat)
211
      {
212
      colon = p.indexOf(':');
213

  
214
      if( colon==-1 )
215
        {
216
        cat = new Category(p);
217
        mCategories[num].addElement(cat);
218
        numCategories[num]++;
219
        }
220
      else
221
        {
222
        pattern = p.substring(colon+1);
223
        name    = p.substring(0,colon);
224
        patt = new Pattern(name,pattern);
225
        cat.addPattern(patt);
226
        }
227
      }
228
    }
229

  
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

  
232
  private static String cutPatternName(String n)
233
    {
234
    int len1 = (int)mPaint.measureText(n);
235
  
236
    if( len1>width )
237
      {
238
      int l = n.length();
239

  
240
      while( l>=2 && len1>width )
241
        {
242
        l--;
243
        buffer = n.substring(0,l);
244
        len1 = (int)mPaint.measureText(buffer);
245
        }
246

  
247
      return buffer+"...";
248
      }
249

  
250
    return n;
251
    }
252

  
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

  
255
  public String getCategoryName(int size,int num)
256
    {
257
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
258
      {
259
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
260
      return c!=null ? c.getName() : null;
261
      }
262

  
263
    return null;
264
    }
265

  
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

  
268
  public String getPatternName(int size,int num)
269
    {
270
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
271
      {
272
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
273
      return c!=null ? c.getPatternName() : null;
274
      }
275

  
276
    return null;
277
    }
278

  
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

  
281
  public int getNumPatterns(int size, int num )
282
    {
283
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
284
      {
285
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
286
      return c!=null ? c.getNumPatterns() : 0;
287
      }
288

  
289
    return 0;
290
    }
291

  
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

  
294
  public void nextPattern(int size, int num )
295
    {
296
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
297
      {
298
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
299

  
300
      if( c!=null )
301
        {
302
// TODO
303
//        RubikMenu.texDirty[0] = true;
304
        c.next();
305
        c.initializeCube();
306
        }
307
      }
308
    }
309

  
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

  
312
  public void prevPattern(int size, int num )
313
    {
314
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
315
      {
316
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
317

  
318
      if( c!=null )
319
        {
320
// TODO
321
//        RubikMenu.texDirty[0] = true;
322
        c.prev();
323
        c.initializeCube();
324
        }
325
      }
326
    }
327

  
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329

  
330
  public int getCurrPattern(int size, int num )
331
    {
332
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
333
      {
334
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
335
      return c!=null ? c.curPattern:0;
336
      }
337

  
338
    return 0;
339
    }
340

  
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

  
343
  public int getCurMove(int size, int num )
344
    {
345
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
346
      {
347
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
348
      return c!=null ? c.getPatternCurMove():0;
349
      }
350

  
351
    return 0;
352
    }
353

  
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

  
356
  public int getNumMove(int size, int num )
357
    {
358
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
359
      {
360
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
361
      return c!=null ? c.getPatternNumMove():0;
362
      }
363

  
364
    return 0;
365
    }
366

  
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

  
369
  public void makeNextMove(int size, int num)
370
    {
371
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
372
      {
373
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
374
      if( c!=null ) c.makeNextMove();
375
      }
376
    }
377

  
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

  
380
  public void makePrevMove(int size, int num)
381
    {
382
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
383
      {
384
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
385
      if( c!=null ) c.makePrevMove();
386
      }
387
    }
388

  
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390

  
391
  public void initializeCube(int size,int num)
392
    {
393
    if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
394
      {
395
      Category c = mCategories[size-MIN_CUBE].elementAt(num);
396
      if( c!=null ) c.initializeCube();
397
      }
398
    }
399
}
src/main/java/org/distorted/uistate/RubikState.java
36 36
  private final RubikStateAbstract mClass;
37 37
  private static final RubikState[] sizes;
38 38

  
39
  private static RubikState mCurrentState;
39
  private static RubikState mCurrState, mPrevState;
40 40

  
41 41
  static
42 42
    {
......
61 61

  
62 62
  public static RubikState getCurrentState()
63 63
    {
64
    return mCurrentState;
64
    return mCurrState;
65 65
    }
66 66

  
67 67
///////////////////////////////////////////////////////////////////////////////////////////////////
68 68

  
69 69
  public static void savePreferences(SharedPreferences.Editor editor)
70 70
    {
71
    editor.putInt("state", mCurrentState.ordinal() );
71
    editor.putInt("curr_state", mCurrState.ordinal() );
72
    editor.putInt("prev_state", mPrevState.ordinal() );
72 73
    }
73 74

  
74 75
///////////////////////////////////////////////////////////////////////////////////////////////////
75 76

  
76 77
  public static void restorePreferences(SharedPreferences preferences)
77 78
    {
78
    int stateOrdinal = preferences.getInt("state", RubikState.MAIN.ordinal() );
79
    mCurrentState = getState(stateOrdinal);
79
    int currState = preferences.getInt("curr_state", RubikState.MAIN.ordinal() );
80
    int prevState = preferences.getInt("prev_state", RubikState.MAIN.ordinal() );
81

  
82
    mCurrState = getState(currState);
83
    mPrevState = getState(prevState);
80 84
    }
81 85

  
82 86
///////////////////////////////////////////////////////////////////////////////////////////////////
83 87

  
84 88
  public static void goBack(RubikActivity act)
85 89
    {
86
    switchState(act, mCurrentState.mBack );
90
    switchState(act, mCurrState.mBack );
87 91
    }
88 92

  
89 93
///////////////////////////////////////////////////////////////////////////////////////////////////
90 94

  
91 95
  public static void setState(RubikActivity act)
92 96
    {
93
    mCurrentState.enterState(act);
97
    mCurrState.enterState(act,mPrevState);
94 98
    }
95 99

  
96 100
///////////////////////////////////////////////////////////////////////////////////////////////////
......
99 103
    {
100 104
    if( state!=null )
101 105
      {
102
      if( mCurrentState!=null ) mCurrentState.leaveState(act);
103
      state.enterState(act);
104
      mCurrentState = state;
106
      if( mCurrState!=null ) mCurrState.leaveState(act);
107
      state.enterState(act,mCurrState);
108
      mPrevState = mCurrState;
109
      mCurrState = state;
105 110
      }
106 111
    else
107 112
      {
......
133 138

  
134 139
///////////////////////////////////////////////////////////////////////////////////////////////////
135 140

  
136
  public void enterState(RubikActivity act)
141
  public void enterState(RubikActivity act, RubikState prevState)
137 142
    {
138
    mClass.enterState(act);
143
    mClass.enterState(act,prevState);
139 144
    }
140 145
  }
src/main/java/org/distorted/uistate/RubikStateAbstract.java
28 28
  {
29 29
  public static final int BUTTON_ID_BACK  = 1023;
30 30

  
31
  abstract void enterState(RubikActivity act);
31
  abstract void enterState(RubikActivity act, RubikState prev);
32 32
  abstract void leaveState(RubikActivity act);
33 33
  public abstract void savePreferences(SharedPreferences.Editor editor);
34 34
  public abstract void restorePreferences(SharedPreferences preferences);
src/main/java/org/distorted/uistate/RubikStateMain.java
52 52

  
53 53
///////////////////////////////////////////////////////////////////////////////////////////////////
54 54

  
55
  void enterState(RubikActivity act)
55
  void enterState(RubikActivity act, RubikState prev)
56 56
    {
57 57
    FragmentManager mana = act.getSupportFragmentManager();
58 58
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
src/main/java/org/distorted/uistate/RubikStatePlay.java
65 65

  
66 66
///////////////////////////////////////////////////////////////////////////////////////////////////
67 67

  
68
  void enterState(final RubikActivity act)
68
  void enterState(final RubikActivity act, RubikState prev)
69 69
    {
70 70
    LayoutInflater inflater = act.getLayoutInflater();
71 71

  
src/main/java/org/distorted/uistate/RubikStateSolving.java
60 60

  
61 61
///////////////////////////////////////////////////////////////////////////////////////////////////
62 62

  
63
  void enterState(RubikActivity act)
63
  void enterState(RubikActivity act, RubikState prev)
64 64
    {
65 65
    LayoutInflater inflater = act.getLayoutInflater();
66 66

  
src/main/res/layout/dialog_scores.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent"
5
    android:layout_weight="1"
6
    android:orientation="vertical" >
7

  
8
    <android.support.design.widget.TabLayout
9
        android:id="@+id/sliding_tabs"
10
        android:layout_width="match_parent"
11
        android:layout_height="32dp"
12
        android:theme="@style/Theme.AppCompat.NoActionBar">
13
    </android.support.design.widget.TabLayout>
14

  
15
    <android.support.v4.view.ViewPager
16
        android:id="@+id/viewpager"
17
        android:layout_width="match_parent"
18
        android:layout_height="0dp"
19
        android:layout_weight="1"
20
        android:background="@android:color/black" />
21

  
22
</LinearLayout>
src/main/res/layout/dialog_scores_tab.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:id="@+id/tabScrollView"
4
    android:layout_width="match_parent"
5
    android:layout_height="match_parent">
6

  
7
    <LinearLayout
8
        android:id="@+id/tabLayout"
9
        android:layout_width="match_parent"
10
        android:layout_height="wrap_content"
11
        android:orientation="vertical" >
12
    </LinearLayout>
13

  
14
</ScrollView>
15

  
src/main/res/layout/dialog_tab.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:id="@+id/tabScrollView"
4
    android:layout_width="match_parent"
5
    android:layout_height="match_parent">
6

  
7
    <LinearLayout
8
        android:id="@+id/tabLayout"
9
        android:layout_width="match_parent"
10
        android:layout_height="wrap_content"
11
        android:orientation="vertical" >
12
    </LinearLayout>
13

  
14
</ScrollView>
15

  
src/main/res/layout/dialog_tabbed.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent"
5
    android:layout_weight="1"
6
    android:orientation="vertical" >
7

  
8
    <android.support.design.widget.TabLayout
9
        android:id="@+id/sliding_tabs"
10
        android:layout_width="match_parent"
11
        android:layout_height="32dp"
12
        android:theme="@style/Theme.AppCompat.NoActionBar">
13
    </android.support.design.widget.TabLayout>
14

  
15
    <android.support.v4.view.ViewPager
16
        android:id="@+id/viewpager"
17
        android:layout_width="match_parent"
18
        android:layout_height="0dp"
19
        android:layout_weight="1"
20
        android:background="@android:color/black" />
21

  
22
</LinearLayout>

Also available in: Unified diff