Project

General

Profile

« Previous | Next » 

Revision dd73fdab

Added by Leszek Koltunski almost 5 years ago

Improvements

View differences:

src/main/java/org/distorted/magic/RubikActivity.java
39 39
{
40 40
    static final int DEFAULT_SIZE  = 3;
41 41
    static final int SMALLEST_SIZE = 2;
42
    private static final int[] button_ids  = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4, R.id.rubikSize5};
43 42

  
44 43
    public static final int MIN_SCRAMBLE =  1;
45 44
    public static final int DEF_SCRAMBLE =  1;
......
54 53
      {
55 54
      mSize = size;
56 55

  
57
      for(int b=0; b<button_ids.length; b++)
56
      for(int b=0; b<RubikSize.LENGTH; b++)
58 57
        {
59
        Drawable d = findViewById(button_ids[b]).getBackground();
58
        Drawable d = findViewById(RubikSize.getSize(b).getImageButton()).getBackground();
60 59

  
61 60
        if( size == b+SMALLEST_SIZE )
62 61
          {
......
109 108
      return mSize;
110 109
      }
111 110

  
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

  
114
    static int getNumCubes()
115
      {
116
      return button_ids.length;
117
      }
118

  
119 111
///////////////////////////////////////////////////////////////////////////////////////////////////
120 112

  
121 113
    @Override
......
214 206
      {
215 207
      int size=0, id = v.getId();
216 208

  
217
      for(int b=0; b<button_ids.length; b++)
218
        if( button_ids[b] == id )
209
      for(int b=0; b<RubikSize.LENGTH; b++)
210
        if( RubikSize.getSize(b).getImageButton() == id )
219 211
          {
220 212
          size = b+SMALLEST_SIZE;
221 213
          break;
src/main/java/org/distorted/magic/RubikScores.java
72 72
    mViewPager = new RubikScoresViewPager(act,viewPager);
73 73
    tabLayout.setupWithViewPager(viewPager);
74 74

  
75
    for (int i=0; i<RubikScoresTab.LENGTH; i++)
75
    for (int i = 0; i< RubikSize.LENGTH; i++)
76 76
      {
77 77
      ImageView imageView = new ImageView(act);
78
      imageView.setImageResource(RubikScoresTab.getTab(i).getIcon());
78
      imageView.setImageResource(RubikSize.getSize(i).getIcon());
79 79
      TabLayout.Tab tab = tabLayout.getTabAt(i);
80 80
      if(tab!=null) tab.setCustomView(imageView);
81 81
      }
src/main/java/org/distorted/magic/RubikScoresTab.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.magic;
21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
public enum RubikScoresTab
25
  {
26
  TAB1 ( R.drawable.button2, R.layout.scores_tab2 ),
27
  TAB2 ( R.drawable.button3, R.layout.scores_tab3 ),
28
  TAB3 ( R.drawable.button4, R.layout.scores_tab4 ),
29
  TAB4 ( R.drawable.button5, R.layout.scores_tab5 ),
30
  ;
31

  
32
  static final int LENGTH = values().length;
33

  
34
  private final int mIconID, mLayoutID;
35

  
36
  private static final RubikScoresTab[] tabs;
37

  
38
  static
39
    {
40
    int i = 0;
41
    tabs = new RubikScoresTab[LENGTH];
42

  
43
    for(RubikScoresTab tab: RubikScoresTab.values())
44
      {
45
      tabs[i] = tab;
46
      i++;
47
      }
48
    }
49

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

  
52
  static RubikScoresTab getTab(int ordinal)
53
    {
54
    return tabs[ordinal];
55
    }
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

  
59
  RubikScoresTab(int iconID, int layoutID)
60
    {
61
    mIconID   = iconID;
62
    mLayoutID = layoutID;
63
    }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  int getIcon()
68
    {
69
    return mIconID;
70
    }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
  int getLayout()
75
    {
76
    return mLayoutID;
77
    }
78
  }
src/main/java/org/distorted/magic/RubikScoresViewPager.java
39 39
    {
40 40
    mContext = context;
41 41
    viewPager.setAdapter(this);
42
    viewPager.setOffscreenPageLimit( RubikScoresTab.LENGTH-1 );
42
    viewPager.setOffscreenPageLimit( RubikSize.LENGTH-1 );
43 43
    }
44 44

  
45 45
///////////////////////////////////////////////////////////////////////////////////////////////////
......
48 48
  @NonNull
49 49
  public Object instantiateItem(@NonNull ViewGroup collection, int position)
50 50
    {
51
    int scoresTab= RubikScoresTab.getTab(position).getLayout();
51
    int scoresTab= RubikSize.getSize(position).getLayout();
52 52
    LayoutInflater inflater = LayoutInflater.from(mContext);
53 53
    ViewGroup layout = (ViewGroup) inflater.inflate(scoresTab, collection, false);
54 54
    collection.addView(layout);
......
69 69
  @Override
70 70
  public int getCount()
71 71
    {
72
    return RubikScoresTab.LENGTH;
72
    return RubikSize.LENGTH;
73 73
    }
74 74

  
75 75
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/magic/RubikSize.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.magic;
21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
public enum RubikSize
25
  {
26
  SIZE2 ( R.id.rubikSize2, R.drawable.button2, R.layout.scores_tab2 ),
27
  SIZE3 ( R.id.rubikSize3, R.drawable.button3, R.layout.scores_tab3 ),
28
  SIZE4 ( R.id.rubikSize4, R.drawable.button4, R.layout.scores_tab4 ),
29
  SIZE5 ( R.id.rubikSize5, R.drawable.button5, R.layout.scores_tab5 ),
30
  ;
31

  
32
  static final int LENGTH = values().length;
33
  private final int mImageButtonID, mIconID, mLayoutID;
34
  private static final RubikSize[] sizes;
35

  
36
  static
37
    {
38
    int i = 0;
39
    sizes = new RubikSize[LENGTH];
40

  
41
    for(RubikSize size: RubikSize.values())
42
      {
43
      sizes[i] = size;
44
      i++;
45
      }
46
    }
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
50
  static RubikSize getSize(int ordinal)
51
    {
52
    return sizes[ordinal];
53
    }
54

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

  
57
  RubikSize(int imageID, int iconID, int layoutID)
58
    {
59
    mImageButtonID= imageID;
60
    mIconID       = iconID;
61
    mLayoutID     = layoutID;
62
    }
63

  
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

  
66
  int getImageButton()
67
    {
68
    return mImageButtonID;
69
    }
70

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
  int getIcon()
74
    {
75
    return mIconID;
76
    }
77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
  int getLayout()
81
    {
82
    return mLayoutID;
83
    }
84
  }
src/main/res/layout/scores_downloading.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3
  android:layout_width="match_parent"
4
  android:layout_height="match_parent"
5
  android:textSize="32sp"
6
  android:gravity="center"
7
  android:text="@string/downloading"
8
  android:padding="10dp"/>
src/main/res/values/strings.xml
16 16
    <string name="win_effect">Win Effect</string>
17 17
    <string name="duration">Duration:</string>
18 18
    <string name="type">Type:</string>
19
    <string name="downloading">Downloading...</string>
19 20
    <string name="credits1">Open Source app developed using the Distorted graphics library. </string>
20 21
    <string name="credits2">Code, tutorials, learn how to write your own graphics effect: <a href="http://www.distorted.org/cube">Distorted.org</a></string>
21 22

  

Also available in: Unified diff