Revision 50ac40a6
Added by Leszek Koltunski over 9 years ago
| src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java | ||
|---|---|---|
| 24 | 24 |
import android.os.Bundle; |
| 25 | 25 |
import android.view.Gravity; |
| 26 | 26 |
import android.view.View; |
| 27 |
import android.widget.AdapterView; |
|
| 28 |
import android.widget.ArrayAdapter; |
|
| 27 | 29 |
import android.widget.Button; |
| 28 | 30 |
import android.widget.LinearLayout; |
| 29 | 31 |
import android.widget.NumberPicker; |
| 30 | 32 |
import android.widget.SeekBar; |
| 31 | 33 |
import android.widget.SeekBar.OnSeekBarChangeListener; |
| 34 |
import android.widget.Spinner; |
|
| 32 | 35 |
import android.widget.TableRow; |
| 33 | 36 |
import android.widget.TextView; |
| 34 | 37 |
|
| 35 | 38 |
import org.distorted.examples.R; |
| 36 | 39 |
import org.distorted.library.Distorted; |
| 40 |
import org.distorted.library.DistortedBitmap; |
|
| 41 |
import org.distorted.library.DistortedCubes; |
|
| 42 |
import org.distorted.library.DistortedObject; |
|
| 37 | 43 |
import org.distorted.library.EffectNames; |
| 38 | 44 |
|
| 39 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 40 | 46 |
|
| 41 |
public class Vertex3DActivity extends Activity implements OnSeekBarChangeListener, View.OnClickListener |
|
| 47 |
public class Vertex3DActivity extends Activity |
|
| 48 |
implements OnSeekBarChangeListener, |
|
| 49 |
View.OnClickListener, |
|
| 50 |
AdapterView.OnItemSelectedListener |
|
| 42 | 51 |
{
|
| 52 |
private static final int COLOR_OFF = 0xffffe81f; |
|
| 53 |
private static final int COLOR_ON = 0xff0000ff; |
|
| 54 |
|
|
| 43 | 55 |
private boolean firstScreen; |
| 44 | 56 |
|
| 45 | 57 |
// fields needed for the first 'pick-a-shape' screen |
| 46 | 58 |
// |
| 47 |
private static int mNumCols = 3; |
|
| 48 |
private static int mNumRows = 3; |
|
| 49 |
|
|
| 50 |
private static final int COLOR_OFF = 0xffffe81f; |
|
| 51 |
private static final int COLOR_ON = 0xff0000ff; |
|
| 52 |
|
|
| 59 |
private int mNumCols = 3; |
|
| 60 |
private int mNumRows = 3; |
|
| 53 | 61 |
private NumberPicker mColsPicker, mRowsPicker; |
| 54 | 62 |
private LinearLayout mLay; |
| 55 |
private static boolean[] mShape;
|
|
| 63 |
private boolean[] mShape; |
|
| 56 | 64 |
|
| 57 | 65 |
// fields needed for the second 'apply vertex effects' screen |
| 58 | 66 |
// |
| ... | ... | |
| 70 | 78 |
private float fswirlA; |
| 71 | 79 |
private float fcenterX, fcenterY; |
| 72 | 80 |
|
| 81 |
private DistortedObject mObject; |
|
| 82 |
|
|
| 73 | 83 |
private EffectNames[] effects = new EffectNames[4]; |
| 74 |
|
|
| 84 |
private int mObjectType; |
|
| 85 |
|
|
| 75 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 76 | 87 |
|
| 77 | 88 |
@Override |
| ... | ... | |
| 79 | 90 |
{
|
| 80 | 91 |
super.onCreate(savedState); |
| 81 | 92 |
|
| 82 |
setContentView(R.layout.cubes1layout);
|
|
| 93 |
setContentView(R.layout.objectpickerlayout);
|
|
| 83 | 94 |
|
| 84 |
mLay = (LinearLayout)findViewById(R.id.buttongrid); |
|
| 95 |
mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
|
|
| 85 | 96 |
|
| 86 |
mColsPicker = (NumberPicker)findViewById(R.id.colsPicker);
|
|
| 87 |
mRowsPicker = (NumberPicker)findViewById(R.id.rowsPicker);
|
|
| 97 |
mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols);
|
|
| 98 |
mRowsPicker = (NumberPicker)findViewById(R.id.objectpicker_rows);
|
|
| 88 | 99 |
|
| 89 | 100 |
mColsPicker.setMaxValue(10); |
| 90 | 101 |
mColsPicker.setMinValue( 0); |
| ... | ... | |
| 110 | 121 |
}); |
| 111 | 122 |
|
| 112 | 123 |
firstScreen = true; |
| 113 |
} |
|
| 114 | 124 |
|
| 115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 116 |
// 'first screen' methods |
|
| 125 |
mObjectType = 0; |
|
| 117 | 126 |
|
| 118 |
public static int getCols() |
|
| 119 |
{
|
|
| 120 |
return mNumCols; |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 124 |
|
|
| 125 |
public static String getShape() |
|
| 126 |
{
|
|
| 127 |
String str = ""; |
|
| 127 |
Spinner typeSpinner = (Spinner)findViewById(R.id.objectpicker_spinnerType); |
|
| 128 |
typeSpinner.setOnItemSelectedListener(this); |
|
| 128 | 129 |
|
| 129 |
for(int i=0; i<mNumRows*mNumCols; i++) |
|
| 130 |
str += mShape[i] ? "1" : "0"; |
|
| 130 |
String[] objectType = new String[] {"DistortedCubes", "DistortedBitmap"};
|
|
| 131 | 131 |
|
| 132 |
//android.util.Log.d("CUBES", str);
|
|
| 133 |
|
|
| 134 |
return str;
|
|
| 132 |
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
|
|
| 133 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 134 |
typeSpinner.setAdapter(adapter);
|
|
| 135 | 135 |
} |
| 136 | 136 |
|
| 137 | 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 138 | 138 |
|
| 139 |
public void setGrid()
|
|
| 139 |
private void setGrid()
|
|
| 140 | 140 |
{
|
| 141 | 141 |
mNumCols = mColsPicker.getValue(); |
| 142 | 142 |
mNumRows = mRowsPicker.getValue(); |
| ... | ... | |
| 181 | 181 |
} |
| 182 | 182 |
} |
| 183 | 183 |
|
| 184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 185 |
|
|
| 186 |
public DistortedObject getObject() |
|
| 187 |
{
|
|
| 188 |
return mObject; |
|
| 189 |
} |
|
| 190 |
|
|
| 184 | 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 185 | 192 |
|
| 186 | 193 |
public void onClick(View view) |
| ... | ... | |
| 193 | 200 |
|
| 194 | 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 195 | 202 |
|
| 196 |
public void Continue(View v)
|
|
| 203 |
public void Create(View v)
|
|
| 197 | 204 |
{
|
| 198 | 205 |
firstScreen = false; |
| 206 |
|
|
| 207 |
if( mObjectType==1 ) |
|
| 208 |
{
|
|
| 209 |
mObject = new DistortedBitmap(100,100,mNumCols); |
|
| 210 |
} |
|
| 211 |
else |
|
| 212 |
{
|
|
| 213 |
String str = ""; |
|
| 214 |
|
|
| 215 |
for(int i=0; i<mNumRows*mNumCols; i++) |
|
| 216 |
str += mShape[i] ? "1" : "0"; |
|
| 217 |
|
|
| 218 |
mObject = new DistortedCubes(mNumCols, str, 10); |
|
| 219 |
} |
|
| 220 |
|
|
| 199 | 221 |
setContentView(R.layout.vertex3dlayout); |
| 200 | 222 |
Default(null); |
| 201 | 223 |
} |
| 202 | 224 |
|
| 225 |
|
|
| 226 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 227 |
|
|
| 228 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
| 229 |
{
|
|
| 230 |
switch(parent.getId()) |
|
| 231 |
{
|
|
| 232 |
case R.id.objectpicker_spinnerType: mObjectType = pos; break; |
|
| 233 |
} |
|
| 234 |
} |
|
| 235 |
|
|
| 236 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 237 |
|
|
| 238 |
public void onNothingSelected(AdapterView<?> parent) |
|
| 239 |
{
|
|
| 240 |
} |
|
| 241 |
|
|
| 203 | 242 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 204 | 243 |
// 'second screen' methods |
| 205 | 244 |
|
Also available in: Unified diff
some improvements for the way we test DistortedObjects.