Project

General

Profile

« Previous | Next » 

Revision 462c74f4

Added by Leszek Koltunski over 8 years ago

Revert the Cubes App.

View differences:

src/main/java/org/distorted/examples/cubes/CubesActivity.java
30 30
import android.os.Bundle;
31 31
import android.view.Gravity;
32 32
import android.view.View;
33
import android.widget.AdapterView;
34
import android.widget.ArrayAdapter;
35 33
import android.widget.Button;
36 34
import android.widget.LinearLayout;
37 35
import android.widget.NumberPicker;
38 36
import android.widget.NumberPicker.OnValueChangeListener;
39
import android.widget.Spinner;
40 37
import android.widget.TableRow;
41 38

  
42 39
///////////////////////////////////////////////////////////////////////////////////////////////////
43 40

  
44
public class CubesActivity extends Activity implements View.OnClickListener, AdapterView.OnItemSelectedListener
41
public class CubesActivity extends Activity implements View.OnClickListener
45 42
{
46 43
    private static final int COLOR_OFF = 0xffffe81f;
47 44
    private static final int COLOR_ON  = 0xff0000ff;
......
52 49
    private LinearLayout mLay;
53 50
    private boolean[] mShape;
54 51
    private DistortedObject mObject;
55
    private int mObjectType;
56 52

  
57 53
///////////////////////////////////////////////////////////////////////////////////////////////////
58 54
    
......
61 57
      {
62 58
      super.onCreate(savedState);
63 59

  
64
      setContentView(R.layout.objectpickerlayout);
60
      setContentView(R.layout.cubespickerlayout);
65 61
      
66
      mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
62
      mLay = (LinearLayout)findViewById(R.id.cubespicker_buttongrid);
67 63
      
68
      mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols);
69
      mRowsPicker = (NumberPicker)findViewById(R.id.objectpicker_rows);
64
      mColsPicker = (NumberPicker)findViewById(R.id.cubespicker_cols);
65
      mRowsPicker = (NumberPicker)findViewById(R.id.cubespicker_rows);
70 66
      
71 67
      mColsPicker.setMaxValue(10);
72 68
      mColsPicker.setMinValue( 0);
......
90 86
           setGrid();
91 87
           }
92 88
         });
93

  
94
      mObjectType = 0;
95

  
96
      Spinner typeSpinner  = (Spinner)findViewById(R.id.objectpicker_spinnerType);
97
      typeSpinner.setOnItemSelectedListener(this);
98

  
99
      String[] objectType = new String[] {"DistortedCubes", "DistortedBitmap"};
100

  
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);
104 89
      }
105 90

  
106 91
///////////////////////////////////////////////////////////////////////////////////////////////////
......
150 135
        }
151 136
      }
152 137

  
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

  
169 138
///////////////////////////////////////////////////////////////////////////////////////////////////
170 139
    
171 140
    public void onClick(View view) 
......
224 193
    
225 194
    public void Create(View v)
226 195
      {
227
      if( mObjectType==1 )
228
        {
229
        mObject = new DistortedBitmap(100,100,mNumCols);
230
        }
231
      else
232
        {
233
        String str = "";
196
      String str = "";
234 197

  
235
        for(int i=0; i<mNumRows*mNumCols; i++)
236
          str += mShape[i] ? "1" : "0";
198
      for(int i=0; i<mNumRows*mNumCols; i++)
199
        str += mShape[i] ? "1" : "0";
237 200

  
238
        mObject = new DistortedCubes(mNumCols, str, 10);
239
        }
201
      mObject = new DistortedCubes(mNumCols, str, 10);
240 202

  
241 203
      setContentView(R.layout.cubeslayout);
242 204
      }
src/main/res/layout/cubespickerlayout.xml
1
<?xml version="1.0" encoding="utf-8"?>
2

  
3
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4
    android:orientation="vertical"
5
    android:layout_width="match_parent"
6
    android:layout_height="match_parent">
7

  
8
       <LinearLayout
9
        android:orientation="horizontal"
10
        android:layout_width="match_parent"
11
        android:layout_height="wrap_content">
12

  
13
        <NumberPicker
14
         android:id="@+id/cubespicker_rows"
15
         android:layout_width="wrap_content"
16
         android:layout_height="wrap_content"
17
         android:orientation="vertical"
18
         android:layout_span="1"
19
         />
20

  
21
        <NumberPicker
22
         android:id="@+id/cubespicker_cols"
23
         android:layout_width="wrap_content"
24
         android:layout_height="wrap_content"
25
         android:orientation="vertical"
26
         android:layout_span="2"/>
27

  
28
        <Button
29
            android:id="@+id/cubespicker_create"
30
            android:onClick="Create"
31
            android:text="@string/Create"
32
            android:layout_width="match_parent"
33
            android:layout_height="fill_parent"
34
            android:layout_span="3"
35
            android:layout_marginTop="5dp"/>
36
    </LinearLayout>
37

  
38
       <LinearLayout
39
        android:id="@+id/cubespicker_buttongrid"
40
        android:layout_width="match_parent"
41
        android:layout_height="fill_parent"
42
        android:gravity="center"
43
        android:orientation="vertical"
44
        android:layout_weight="0.8">
45
    </LinearLayout>
46

  
47
   </LinearLayout>

Also available in: Unified diff