Project

General

Profile

« Previous | Next » 

Revision 47ba5ddc

Added by Leszek Koltunski over 4 years ago

RubikCube: further fixes

View differences:

src/main/java/org/distorted/magic/RubikActivity.java
42 42
    private static final int[] button_ids  = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
43 43

  
44 44
    public static final int MIN_SCRAMBLE =  1;
45
    public static final int DEF_SCRAMBLE =  3;
45 46
    public static final int MAX_SCRAMBLE = 10;
46 47

  
47 48
    private static int mSize = DEFAULT_SIZE;
48 49
    private HorizontalNumberPicker mPicker;
49 50

  
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

  
53
    private void markButton(int size)
54
      {
55
      mSize = size;
56

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

  
61
        if( size == b+SMALLEST_SIZE )
62
          {
63
          d.setColorFilter(ContextCompat.getColor(this,R.color.red), PorterDuff.Mode.MULTIPLY);
64
          }
65
        else
66
          {
67
          d.clearColorFilter();
68
          }
69
        }
70
      }
71

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

  
74
    private void savePreferences()
75
      {
76
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
77
      SharedPreferences.Editor editor = preferences.edit();
78

  
79
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
80
        {
81
        BaseEffect.Type.getType(i).savePreferences(editor);
82
        }
83

  
84
      editor.putInt("scramble", mPicker.getValue() );
85

  
86
      editor.apply();
87
      }
88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

  
91
    private void restorePreferences()
92
      {
93
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
94

  
95
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
96
        {
97
        BaseEffect.Type.getType(i).restorePreferences(preferences);
98
        }
99

  
100
      int scramble= preferences.getInt("scramble", DEF_SCRAMBLE);
101

  
102
      mPicker.setValue(scramble);
103
      }
104

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

  
107
    static int getSize()
108
      {
109
      return mSize;
110
      }
111

  
50 112
///////////////////////////////////////////////////////////////////////////////////////////////////
51 113

  
52 114
    @Override
......
96 158
      }
97 159

  
98 160
///////////////////////////////////////////////////////////////////////////////////////////////////
99

  
100
    static int getSize()
101
      {
102
      return mSize;
103
      }
104

  
161
// PUBLIC API
105 162
///////////////////////////////////////////////////////////////////////////////////////////////////
106 163

  
107 164
    public void Settings(View v)
......
157 214
        markButton(size);
158 215
        }
159 216
      }
160

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

  
163
   private void markButton(int size)
164
     {
165
     mSize = size;
166

  
167
     for(int b=0; b<button_ids.length; b++)
168
       {
169
       Drawable d = findViewById(button_ids[b]).getBackground();
170

  
171
       if( size == b+SMALLEST_SIZE )
172
         {
173
         d.setColorFilter(ContextCompat.getColor(this,R.color.red), PorterDuff.Mode.MULTIPLY);
174
         }
175
       else
176
         {
177
         d.clearColorFilter();
178
         }
179
       }
180
     }
181

  
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

  
184
   private void savePreferences()
185
     {
186
     SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
187
     SharedPreferences.Editor editor = preferences.edit();
188

  
189
     for (int i=0; i< BaseEffect.Type.LENGTH; i++)
190
       {
191
       BaseEffect.Type.getType(i).savePreferences(editor);
192
       }
193

  
194
     editor.putInt("scramble", mPicker.getValue() );
195

  
196
     editor.apply();
197
     }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

  
201
   private void restorePreferences()
202
     {
203
     SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
204

  
205
     for (int i=0; i< BaseEffect.Type.LENGTH; i++)
206
       {
207
       BaseEffect.Type.getType(i).restorePreferences(preferences);
208
       }
209

  
210
     int scramble= preferences.getInt("scramble", MIN_SCRAMBLE);
211

  
212
     mPicker.setValue(scramble);
213
     }
214 217
}

Also available in: Unified diff