Revision b9d062cf
Added by Leszek Koltunski about 2 years ago
src/main/java/org/distorted/bandaged/BandagedCreatorScreen.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.bandaged; |
21 | 21 |
|
22 |
import java.lang.ref.WeakReference; |
|
22 | 23 |
import java.util.ArrayList; |
23 | 24 |
|
24 | 25 |
import android.app.Activity; |
26 |
import android.content.SharedPreferences; |
|
25 | 27 |
import android.graphics.Bitmap; |
26 | 28 |
import android.view.View; |
29 |
import android.view.ViewGroup; |
|
30 |
import android.widget.AdapterView; |
|
31 |
import android.widget.ArrayAdapter; |
|
27 | 32 |
import android.widget.ImageView; |
28 | 33 |
import android.widget.LinearLayout; |
34 |
import android.widget.Spinner; |
|
29 | 35 |
|
30 | 36 |
import org.distorted.external.RubikFiles; |
31 | 37 |
import org.distorted.helpers.TransparentImageButton; |
... | ... | |
34 | 40 |
|
35 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
36 | 42 |
|
37 |
public class BandagedCreatorScreen |
|
43 |
public class BandagedCreatorScreen implements AdapterView.OnItemSelectedListener
|
|
38 | 44 |
{ |
45 |
public static final int MAX_SUPPORTED_SIZE = 5; |
|
46 |
|
|
47 |
private WeakReference<BandagedCreatorActivity> mAct; |
|
39 | 48 |
private TransparentImageButton mBackButton, mResetButton, mDoneButton; |
40 | 49 |
private LinearLayout mObjectView; |
41 |
private int mNumObjects; |
|
42 |
private ArrayList<BandagedCreatorObjectView> mViews; |
|
50 |
private int mNumObjects, mX, mY, mZ; |
|
51 |
private final ArrayList<BandagedCreatorObjectView> mViews; |
|
52 |
private Spinner mSpinnerX, mSpinnerY, mSpinnerZ; |
|
53 |
private boolean mSpinnersReady; |
|
43 | 54 |
|
44 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
45 | 56 |
|
46 | 57 |
public BandagedCreatorScreen() |
47 | 58 |
{ |
59 |
mSpinnersReady = false; |
|
48 | 60 |
mNumObjects = 0; |
49 | 61 |
mViews = new ArrayList<>(); |
50 | 62 |
} |
... | ... | |
105 | 117 |
}); |
106 | 118 |
} |
107 | 119 |
|
120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
121 |
|
|
122 |
private String[] createSizes(String mark) |
|
123 |
{ |
|
124 |
String[] ret = new String[MAX_SUPPORTED_SIZE]; |
|
125 |
|
|
126 |
for(int i=1; i<=MAX_SUPPORTED_SIZE; i++) |
|
127 |
{ |
|
128 |
ret[i-1] = mark+" : "+i; |
|
129 |
} |
|
130 |
|
|
131 |
return ret; |
|
132 |
} |
|
133 |
|
|
134 |
|
|
135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
136 |
|
|
137 |
private void changeObject() |
|
138 |
{ |
|
139 |
if( mSpinnersReady ) |
|
140 |
{ |
|
141 |
BandagedCreatorActivity act = mAct.get(); |
|
142 |
if( act!=null ) act.changeObject(mX+1,mY+1,mZ+1); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
108 | 146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
109 | 147 |
|
110 | 148 |
void onAttachedToWindow(final BandagedCreatorActivity act) |
111 | 149 |
{ |
150 |
mAct = new WeakReference<>(act); |
|
112 | 151 |
mObjectView = act.findViewById(R.id.bandagedCreatorView); |
113 | 152 |
|
114 |
int width = act.getScreenWidthInPixels(); |
|
153 |
int width = act.getScreenWidthInPixels(); |
|
154 |
int height = act.getScreenHeightInPixels(); |
|
155 |
int padding= (int)(height*RubikActivity.PADDING/3); |
|
115 | 156 |
|
116 | 157 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
117 | 158 |
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT); |
... | ... | |
136 | 177 |
layout.addView(layoutLeft); |
137 | 178 |
layout.addView(layoutMid); |
138 | 179 |
layout.addView(layoutRight); |
180 |
|
|
181 |
mSpinnerX = act.findViewById(R.id.bandagedCreatorX); |
|
182 |
mSpinnerX.setOnItemSelectedListener(this); |
|
183 |
ArrayAdapter<String> adX = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, createSizes("X") ); |
|
184 |
adX.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
185 |
mSpinnerX.setAdapter(adX); |
|
186 |
|
|
187 |
mSpinnerY = act.findViewById(R.id.bandagedCreatorY); |
|
188 |
mSpinnerY.setOnItemSelectedListener(this); |
|
189 |
ArrayAdapter<String> adY = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, createSizes("Y") ); |
|
190 |
adY.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
191 |
mSpinnerY.setAdapter(adY); |
|
192 |
|
|
193 |
mSpinnerZ = act.findViewById(R.id.bandagedCreatorZ); |
|
194 |
mSpinnerZ.setOnItemSelectedListener(this); |
|
195 |
ArrayAdapter<String> adZ = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, createSizes("Z") ); |
|
196 |
adZ.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
197 |
mSpinnerZ.setAdapter(adZ); |
|
198 |
|
|
199 |
ViewGroup.MarginLayoutParams paramsX = (ViewGroup.MarginLayoutParams) mSpinnerX.getLayoutParams(); |
|
200 |
paramsX.setMargins(0,0,2*padding,0); |
|
201 |
ViewGroup.MarginLayoutParams paramsY = (ViewGroup.MarginLayoutParams) mSpinnerY.getLayoutParams(); |
|
202 |
paramsY.setMargins(padding,0,padding,0); |
|
203 |
ViewGroup.MarginLayoutParams paramsZ = (ViewGroup.MarginLayoutParams) mSpinnerZ.getLayoutParams(); |
|
204 |
paramsZ.setMargins(2*padding,0,0,0); |
|
139 | 205 |
} |
140 | 206 |
|
141 | 207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
153 | 219 |
|
154 | 220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
155 | 221 |
|
156 |
void addObjects(BandagedCreatorActivity act, String objectString) |
|
222 |
private void addObjects(BandagedCreatorActivity act, String objectString)
|
|
157 | 223 |
{ |
158 | 224 |
if( objectString.length()>0 ) |
159 | 225 |
{ |
... | ... | |
251 | 317 |
|
252 | 318 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
253 | 319 |
|
254 |
String generateObjectStrings() |
|
320 |
private String generateObjectStrings()
|
|
255 | 321 |
{ |
256 | 322 |
String result = ""; |
257 | 323 |
int numViews = mViews.size(); |
... | ... | |
267 | 333 |
|
268 | 334 |
return result; |
269 | 335 |
} |
336 |
|
|
337 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
338 |
|
|
339 |
@Override |
|
340 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
341 |
{ |
|
342 |
int spinnerID = parent.getId(); |
|
343 |
|
|
344 |
if( spinnerID==R.id.bandagedCreatorX ) |
|
345 |
{ |
|
346 |
mX = pos; |
|
347 |
} |
|
348 |
else if( spinnerID==R.id.bandagedCreatorY ) |
|
349 |
{ |
|
350 |
mY = pos; |
|
351 |
} |
|
352 |
else if( spinnerID==R.id.bandagedCreatorZ ) |
|
353 |
{ |
|
354 |
mZ = pos; |
|
355 |
} |
|
356 |
|
|
357 |
changeObject(); |
|
358 |
} |
|
359 |
|
|
360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
361 |
|
|
362 |
@Override |
|
363 |
public void onNothingSelected(AdapterView<?> parent) { } |
|
364 |
|
|
365 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
366 |
|
|
367 |
public void savePreferences(SharedPreferences.Editor editor) |
|
368 |
{ |
|
369 |
String objects = generateObjectStrings(); |
|
370 |
editor.putString("bandagedObjects", objects ); |
|
371 |
|
|
372 |
editor.putInt("bandagedX", mX); |
|
373 |
editor.putInt("bandagedY", mY); |
|
374 |
editor.putInt("bandagedZ", mZ); |
|
375 |
} |
|
376 |
|
|
377 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
378 |
|
|
379 |
public void restorePreferences(BandagedCreatorActivity act, SharedPreferences preferences) |
|
380 |
{ |
|
381 |
String objects = preferences.getString("bandagedObjects",""); |
|
382 |
addObjects(act,objects); |
|
383 |
|
|
384 |
mX = preferences.getInt("bandagedX", 2); |
|
385 |
mY = preferences.getInt("bandagedY", 2); |
|
386 |
mZ = preferences.getInt("bandagedZ", 2); |
|
387 |
|
|
388 |
mSpinnerX.setSelection(mX); |
|
389 |
mSpinnerY.setSelection(mY); |
|
390 |
mSpinnerZ.setSelection(mZ); |
|
391 |
|
|
392 |
mSpinnersReady = true; |
|
393 |
changeObject(); |
|
394 |
} |
|
270 | 395 |
} |
Also available in: Unified diff
Bandaged: progress.