Project

General

Profile

« Previous | Next » 

Revision 7da27d2b

Added by Leszek Koltunski over 1 year ago

initial support for Bandaged UI.

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
190 190
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
191 191
      view.onResume();
192 192

  
193
      if( mScreen==null ) mScreen = new BandagedCreatorScreen();
193
      if( mScreen==null )
194
        {
195
        int ordinal = getObjectOrdinal();
196
        mScreen = new BandagedCreatorScreen(ordinal);
197
        }
198

  
194 199
      mScreen.onAttachedToWindow(this);
195 200

  
196 201
      restorePreferences();
......
329 334
      return mScreenHeight;
330 335
      }
331 336

  
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

  
339
    public int getObjectOrdinal()
340
      {
341
      return 0;
342
      }
343

  
332 344
///////////////////////////////////////////////////////////////////////////////////////////////////
333 345

  
334 346
    public static int getDrawableSize()
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
40 40
import org.distorted.library.type.Static3D;
41 41
import org.distorted.library.type.Static4D;
42 42
import org.distorted.objectlib.bandaged.BandagedObject;
43
//import org.distorted.objectlib.bandaged.BandagedObjectCuboid;
44
import org.distorted.objectlib.bandaged.BandagedObjectCuboid;
45
import org.distorted.objectlib.bandaged.BandagedObjectPyraminx;
43
import org.distorted.objectlib.bandaged.LocallyBandagedList;
46 44
import org.distorted.objectlib.json.JsonWriter;
47 45
import org.distorted.objectlib.main.TwistyObject;
48 46

  
......
79 77

  
80 78
///////////////////////////////////////////////////////////////////////////////////////////////////
81 79

  
82
   BandagedCreatorRenderer(BandagedCreatorView v)
80
   BandagedCreatorRenderer(BandagedCreatorView v, int ordinal)
83 81
     {
84 82
     mView = v;
85 83
     mResources = v.getResources();
......
100 98
     mScreen = new DistortedScreen();
101 99
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
102 100
     mScale = new Static3D(1,1,1);
103
     mObject = new BandagedObjectPyraminx(mScreen);
101
     mObject= LocallyBandagedList.create(ordinal,mScreen);
104 102

  
105 103
     mInitRatio = mObject.getScreenRatio();
106 104
     mObjectScreenRatio= mInitRatio;
src/main/java/org/distorted/bandaged/BandagedCreatorScreen.java
30 30
import org.distorted.helpers.TransparentImageButton;
31 31
import org.distorted.main.R;
32 32
import org.distorted.main.RubikActivity;
33

  
34
import static org.distorted.objectlib.scrambling.ScrambleStateLocallyBandaged.MAX_SUPPORTED_SIZE;
33
import org.distorted.objectlib.bandaged.LocallyBandagedList;
35 34

  
36 35
///////////////////////////////////////////////////////////////////////////////////////////////////
37 36

  
......
45 44
  private Spinner mSpinnerX, mSpinnerY, mSpinnerZ;
46 45
  private boolean mSpinnersReady;
47 46
  private float mTextSize;
47
  private final int mOrdinal;
48
  private final int mDimension;
49
  private final int mMaxSupported;
48 50

  
49 51
///////////////////////////////////////////////////////////////////////////////////////////////////
50 52

  
51
  public BandagedCreatorScreen()
53
  public BandagedCreatorScreen(int ordinal)
52 54
    {
53
    mSpinnersReady = false;
55
    mOrdinal      = ordinal;
56
    mMaxSupported = LocallyBandagedList.getMaxSupported(ordinal);
57
    mDimension    = LocallyBandagedList.getDimension(ordinal);
58
    mSpinnersReady= false;
54 59
    mNumObjects = 0;
55 60
    mViews = new ArrayList<>();
56 61
    }
......
115 120

  
116 121
  private String[] createSizes(String mark)
117 122
    {
118
    String[] ret = new String[MAX_SUPPORTED_SIZE];
123
    String[] ret = new String[mMaxSupported];
119 124

  
120
    for(int i=1; i<=MAX_SUPPORTED_SIZE; i++)
125
    for(int i=1; i<=mMaxSupported; i++)
121 126
      {
122 127
      ret[i-1] = mark+" : "+i;
123 128
      }
......
173 178
    layout.addView(layoutRight);
174 179

  
175 180
    mSpinnerX = act.findViewById(R.id.bandagedCreatorX);
176
    mSpinnerX.setOnItemSelectedListener(this);
177
    ArrayAdapter<String> adX = new ArrayAdapter<>(act, R.layout.spinner_item, createSizes("X") );
178
    mSpinnerX.setAdapter(adX);
179

  
180 181
    mSpinnerY = act.findViewById(R.id.bandagedCreatorY);
181
    mSpinnerY.setOnItemSelectedListener(this);
182
    ArrayAdapter<String> adY = new ArrayAdapter<>(act, R.layout.spinner_item, createSizes("Y") );
183
    mSpinnerY.setAdapter(adY);
184

  
185 182
    mSpinnerZ = act.findViewById(R.id.bandagedCreatorZ);
186
    mSpinnerZ.setOnItemSelectedListener(this);
187
    ArrayAdapter<String> adZ = new ArrayAdapter<>(act, R.layout.spinner_item, createSizes("Z") );
188
    mSpinnerZ.setAdapter(adZ);
189

  
190
    ViewGroup.MarginLayoutParams paramsX = (ViewGroup.MarginLayoutParams) mSpinnerX.getLayoutParams();
191
    paramsX.setMargins(0,0,2*padding,0);
192
    ViewGroup.MarginLayoutParams paramsY = (ViewGroup.MarginLayoutParams) mSpinnerY.getLayoutParams();
193
    paramsY.setMargins(padding,0,padding,0);
194
    ViewGroup.MarginLayoutParams paramsZ = (ViewGroup.MarginLayoutParams) mSpinnerZ.getLayoutParams();
195
    paramsZ.setMargins(2*padding,0,0,0);
183

  
184
    if( mDimension>=1 )
185
      {
186
      mSpinnerX.setOnItemSelectedListener(this);
187
      ArrayAdapter<String> adX=new ArrayAdapter<>(act, R.layout.spinner_item, createSizes("X"));
188
      mSpinnerX.setAdapter(adX);
189
      ViewGroup.MarginLayoutParams paramsX=(ViewGroup.MarginLayoutParams) mSpinnerX.getLayoutParams();
190
      paramsX.setMargins(0, 0, 2*padding, 0);
191
      }
192
    else
193
      {
194
      mSpinnerX.setVisibility(View.INVISIBLE);
195
      }
196

  
197
    if( mDimension>=2 )
198
      {
199
      mSpinnerY.setOnItemSelectedListener(this);
200
      ArrayAdapter<String> adY=new ArrayAdapter<>(act, R.layout.spinner_item, createSizes("Y"));
201
      mSpinnerY.setAdapter(adY);
202
      ViewGroup.MarginLayoutParams paramsY=(ViewGroup.MarginLayoutParams) mSpinnerY.getLayoutParams();
203
      paramsY.setMargins(padding, 0, padding, 0);
204
      }
205
    else
206
      {
207
      mSpinnerY.setVisibility(View.INVISIBLE);
208
      }
209

  
210
    if( mDimension>=3 )
211
      {
212
      mSpinnerZ.setOnItemSelectedListener(this);
213
      ArrayAdapter<String> adZ=new ArrayAdapter<>(act, R.layout.spinner_item, createSizes("Z"));
214
      mSpinnerZ.setAdapter(adZ);
215
      ViewGroup.MarginLayoutParams paramsZ=(ViewGroup.MarginLayoutParams) mSpinnerZ.getLayoutParams();
216
      paramsZ.setMargins(2*padding, 0, 0, 0);
217
      }
218
    else
219
      {
220
      mSpinnerZ.setVisibility(View.INVISIBLE);
221
      }
196 222
    }
197 223

  
198 224
///////////////////////////////////////////////////////////////////////////////////////////////////
......
339 365
    @Override
340 366
    public void onNothingSelected(AdapterView<?> parent) { }
341 367

  
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369

  
370
    private String generateObjectKey()
371
      {
372
      return mOrdinal==0 ? "bandagedObjects" : "bandagedObjects"+mOrdinal;
373
      }
374

  
342 375
///////////////////////////////////////////////////////////////////////////////////////////////////
343 376

  
344 377
    public void savePreferences(SharedPreferences.Editor editor)
345 378
      {
346 379
      String objects = generateObjectStrings();
347
      editor.putString("bandagedObjects", objects );
380
      editor.putString(generateObjectKey(), objects );
348 381

  
349
      editor.putInt("bandagedX", mX);
350
      editor.putInt("bandagedY", mY);
351
      editor.putInt("bandagedZ", mZ);
382
      editor.putInt("bandagedX"+mOrdinal, mX);
383
      editor.putInt("bandagedY"+mOrdinal, mY);
384
      editor.putInt("bandagedZ"+mOrdinal, mZ);
352 385
      }
353 386

  
354 387
///////////////////////////////////////////////////////////////////////////////////////////////////
355 388

  
356 389
    public void restorePreferences(BandagedCreatorActivity act, SharedPreferences preferences)
357 390
      {
358
      String objects = preferences.getString("bandagedObjects","");
391
      String objects = preferences.getString(generateObjectKey(),"");
359 392
      addObjects(act,objects);
360 393

  
361
      mX = preferences.getInt("bandagedX", 2);
362
      mY = preferences.getInt("bandagedY", 2);
363
      mZ = preferences.getInt("bandagedZ", 2);
394
      mX = preferences.getInt("bandagedX"+mOrdinal, 2);
395
      mY = preferences.getInt("bandagedY"+mOrdinal, 2);
396
      mZ = preferences.getInt("bandagedZ"+mOrdinal, 2);
364 397

  
365 398
      mSpinnerX.setSelection(mX);
366 399
      mSpinnerY.setSelection(mY);
src/main/java/org/distorted/bandaged/BandagedCreatorView.java
51 51
      if(!isInEditMode())
52 52
        {
53 53
        BandagedCreatorActivity act = (BandagedCreatorActivity)context;
54
        mRenderer = new BandagedCreatorRenderer(this);
54
        mRenderer = new BandagedCreatorRenderer(this,act.getObjectOrdinal() );
55 55
        mTouchControl = mRenderer.createTouchControl();
56 56

  
57 57
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

Also available in: Unified diff