Revision 50ac40a6
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/cubes/CubesActivity.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import org.distorted.library.Distorted; |
23 | 23 |
import org.distorted.examples.R; |
24 |
import org.distorted.library.DistortedBitmap; |
|
25 |
import org.distorted.library.DistortedCubes; |
|
26 |
import org.distorted.library.DistortedObject; |
|
24 | 27 |
|
25 | 28 |
import android.app.Activity; |
26 | 29 |
import android.opengl.GLSurfaceView; |
27 | 30 |
import android.os.Bundle; |
28 | 31 |
import android.view.Gravity; |
29 | 32 |
import android.view.View; |
33 |
import android.widget.AdapterView; |
|
34 |
import android.widget.ArrayAdapter; |
|
30 | 35 |
import android.widget.Button; |
31 | 36 |
import android.widget.LinearLayout; |
32 | 37 |
import android.widget.NumberPicker; |
33 | 38 |
import android.widget.NumberPicker.OnValueChangeListener; |
39 |
import android.widget.Spinner; |
|
34 | 40 |
import android.widget.TableRow; |
35 | 41 |
|
36 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
37 | 43 |
|
38 |
public class CubesActivity extends Activity implements View.OnClickListener |
|
44 |
public class CubesActivity extends Activity implements View.OnClickListener, AdapterView.OnItemSelectedListener
|
|
39 | 45 |
{ |
40 |
private static int mNumCols = 3; |
|
41 |
private static int mNumRows = 3; |
|
42 |
|
|
43 | 46 |
private static final int COLOR_OFF = 0xffffe81f; |
44 | 47 |
private static final int COLOR_ON = 0xff0000ff; |
45 |
|
|
48 |
|
|
49 |
private int mNumCols = 3; |
|
50 |
private int mNumRows = 3; |
|
46 | 51 |
private NumberPicker mColsPicker, mRowsPicker; |
47 | 52 |
private LinearLayout mLay; |
48 |
private static boolean[] mShape; |
|
49 |
|
|
53 |
private boolean[] mShape; |
|
54 |
private DistortedObject mObject; |
|
55 |
private int mObjectType; |
|
56 |
|
|
50 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 58 |
|
52 | 59 |
@Override |
... | ... | |
54 | 61 |
{ |
55 | 62 |
super.onCreate(savedState); |
56 | 63 |
|
57 |
setContentView(R.layout.cubes1layout);
|
|
64 |
setContentView(R.layout.objectpickerlayout);
|
|
58 | 65 |
|
59 |
mLay = (LinearLayout)findViewById(R.id.buttongrid); |
|
66 |
mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
|
|
60 | 67 |
|
61 |
mColsPicker = (NumberPicker)findViewById(R.id.colsPicker);
|
|
62 |
mRowsPicker = (NumberPicker)findViewById(R.id.rowsPicker);
|
|
68 |
mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols);
|
|
69 |
mRowsPicker = (NumberPicker)findViewById(R.id.objectpicker_rows);
|
|
63 | 70 |
|
64 | 71 |
mColsPicker.setMaxValue(10); |
65 | 72 |
mColsPicker.setMinValue( 0); |
... | ... | |
83 | 90 |
setGrid(); |
84 | 91 |
} |
85 | 92 |
}); |
86 |
} |
|
87 | 93 |
|
88 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
94 |
mObjectType = 0;
|
|
89 | 95 |
|
90 |
public static int getCols() |
|
91 |
{ |
|
92 |
return mNumCols; |
|
93 |
} |
|
96 |
Spinner typeSpinner = (Spinner)findViewById(R.id.objectpicker_spinnerType); |
|
97 |
typeSpinner.setOnItemSelectedListener(this); |
|
94 | 98 |
|
95 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
99 |
String[] objectType = new String[] {"DistortedCubes", "DistortedBitmap"};
|
|
96 | 100 |
|
97 |
public static String getShape() |
|
98 |
{ |
|
99 |
String str = ""; |
|
100 |
|
|
101 |
for(int i=0; i<mNumRows*mNumCols; i++) |
|
102 |
str += mShape[i] ? "1" : "0"; |
|
103 |
|
|
104 |
//android.util.Log.d("CUBES", str); |
|
105 |
|
|
106 |
return str; |
|
101 |
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType); |
|
102 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
103 |
typeSpinner.setAdapter(adapter); |
|
107 | 104 |
} |
108 |
|
|
105 |
|
|
109 | 106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
110 | 107 |
|
111 |
public void setGrid()
|
|
108 |
private void setGrid()
|
|
112 | 109 |
{ |
113 | 110 |
mNumCols = mColsPicker.getValue(); |
114 | 111 |
mNumRows = mRowsPicker.getValue(); |
... | ... | |
153 | 150 |
} |
154 | 151 |
} |
155 | 152 |
|
153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
154 |
|
|
155 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
156 |
{ |
|
157 |
switch(parent.getId()) |
|
158 |
{ |
|
159 |
case R.id.objectpicker_spinnerType: mObjectType = pos; break; |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
164 |
|
|
165 |
public void onNothingSelected(AdapterView<?> parent) |
|
166 |
{ |
|
167 |
} |
|
168 |
|
|
156 | 169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
157 | 170 |
|
158 | 171 |
public void onClick(View view) |
... | ... | |
209 | 222 |
|
210 | 223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
211 | 224 |
|
212 |
public void Continue(View v) |
|
213 |
{ |
|
214 |
setContentView(R.layout.cubes2layout); |
|
215 |
} |
|
225 |
public void Create(View v) |
|
226 |
{ |
|
227 |
if( mObjectType==1 ) |
|
228 |
{ |
|
229 |
mObject = new DistortedBitmap(100,100,mNumCols); |
|
230 |
} |
|
231 |
else |
|
232 |
{ |
|
233 |
String str = ""; |
|
234 |
|
|
235 |
for(int i=0; i<mNumRows*mNumCols; i++) |
|
236 |
str += mShape[i] ? "1" : "0"; |
|
237 |
|
|
238 |
mObject = new DistortedCubes(mNumCols, str, 10); |
|
239 |
} |
|
240 |
|
|
241 |
setContentView(R.layout.cubeslayout); |
|
242 |
} |
|
243 |
|
|
244 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
245 |
|
|
246 |
public DistortedObject getObject() |
|
247 |
{ |
|
248 |
return mObject; |
|
249 |
} |
|
216 | 250 |
} |
Also available in: Unified diff
some improvements for the way we test DistortedObjects.