Project

General

Profile

« Previous | Next » 

Revision 9211042f

Added by Leszek Koltunski 10 months ago

Restore the colors and sticker properties from Preferences.

View differences:

src/main/java/org/distorted/config/ConfigActivity.java
155 155
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
156 156
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
157 157
      view.onResume();
158

  
159
      if( mScreen==null ) mScreen = new ConfigScreen();
160
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
161
      mPane = new ConfigScreenPane(this,mObjectOrdinal);
158
      String key ="";
162 159

  
163 160
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
164 161
        {
165 162
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
166 163
        changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
164
        if( object!=null ) key = object.getUpperName();
167 165
        }
166

  
167
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
168
      restorePreferences(preferences);
169

  
170
      if( mScreen==null ) mScreen = new ConfigScreen();
171
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
172

  
173
      ObjectControl control = view.getObjectControl();
174
      OSInterface os = view.getInterface();
175
      TwistyObject obj = control.getObject();
176

  
177
      mPane = new ConfigScreenPane(this,key,os);
168 178
      }
169 179

  
170 180
///////////////////////////////////////////////////////////////////////////////////////////////////
......
227 237
      editor.apply();
228 238
      }
229 239

  
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

  
242
    private void restorePreferences(SharedPreferences preferences)
243
      {
244
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
245
      OSInterface os = view.getInterface();
246
      os.setPreferences(preferences);
247
      view.getObjectControl().restorePreferences();
248
      }
249

  
230 250
///////////////////////////////////////////////////////////////////////////////////////////////////
231 251
// PUBLIC API
232 252
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/config/ConfigScreenPane.java
24 24

  
25 25
import org.distorted.main.MainActivity;
26 26
import org.distorted.main.R;
27
import org.distorted.os.OSInterface;
27 28

  
28 29
///////////////////////////////////////////////////////////////////////////////////////////////////
29 30

  
......
187 188

  
188 189
///////////////////////////////////////////////////////////////////////////////////////////////////
189 190

  
190
  int getCurrentBorders()
191
  private int extractIndex(float val, float[] table)
191 192
    {
192
    return mCurrentBorders;
193
    }
193
    int len = table.length;
194 194

  
195
///////////////////////////////////////////////////////////////////////////////////////////////////
195
    for(int i=0; i<len; i++)
196
      if( table[i]==val ) return i;
196 197

  
197
  int getCurrentCorners()
198
    {
199
    return mCurrentCorners;
198
    return len/2;
200 199
    }
201 200

  
202 201
///////////////////////////////////////////////////////////////////////////////////////////////////
203 202

  
204
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
203
  ConfigScreenPane(final ConfigActivity act, String key, OSInterface os)
205 204
    {
206 205
    mRow = 0;
207 206
    mCol = 0;
......
210 209
    float textSize = height*TEXT_RATIO;
211 210
    int padding = (int)(height*PADDING_RATIO);
212 211

  
212
    float borders = os.getFloat(key+"_border",1.0f);
213
    float corners = os.getFloat(key+"_corner",1.0f);
214

  
213 215
    ///// UPPER LAYOUT /////////////////////////////////
214 216
    LinearLayout configLayoutU = act.findViewById(R.id.configLayoutUpper);
215 217
    configLayoutU.setPadding(padding,padding,padding,padding);
......
228 230
    textCorner.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
229 231

  
230 232
    mSeekBarBorders = configLayoutU.findViewById(R.id.configSeekBarBorder);
231
    mCurrentBorders = mSeekBarBorders.getProgress();
233
    mCurrentBorders = extractIndex(borders,BORDER_STEPS);
234

  
235
    if( mCurrentBorders!=mSeekBarBorders.getProgress() )
236
      {
237
      mSeekBarBorders.setProgress(mCurrentBorders);
238
      }
232 239

  
233 240
    mSeekBarBorders.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
234 241
      {
......
248 255
      });
249 256

  
250 257
    mSeekBarCorners = configLayoutU.findViewById(R.id.configSeekBarCorner);
251
    mCurrentCorners = mSeekBarCorners.getProgress();
258
    mCurrentCorners = extractIndex(corners,CORNER_STEPS);
259

  
260
    if( mCurrentCorners!=mSeekBarCorners.getProgress() )
261
      {
262
      mSeekBarCorners.setProgress(mCurrentCorners);
263
      }
252 264

  
253 265
    mSeekBarCorners.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
254 266
      {

Also available in: Unified diff