commit bcc8e01662a8ac60721672cda054037445fbcfc6
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Sun Jul 3 02:05:38 2016 +0100

    Improve the Vertex3D app some more.

diff --git a/src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java b/src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
index 312b5ca..cf7aa59 100644
--- a/src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
+++ b/src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
@@ -61,6 +61,9 @@ public class Vertex3DActivity extends Activity
   private NumberPicker mColsPicker, mRowsPicker;
   private LinearLayout mLay;
   private boolean[] mShape;
+  private DistortedObject mObject;
+  private int mObjectType;
+  private int mBitmap;
 
   // fields needed for the second 'apply vertex effects' screen
   //
@@ -77,11 +80,8 @@ public class Vertex3DActivity extends Activity
   private float fsinkA;
   private float fswirlA;
   private float fcenterX, fcenterY;
-
-  private DistortedObject mObject;
-
   private EffectNames[] effects = new EffectNames[4];
-  private int mObjectType;
+
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
     
@@ -92,8 +92,6 @@ public class Vertex3DActivity extends Activity
 
     setContentView(R.layout.objectpickerlayout);
 
-    mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
-
     mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols);
     mRowsPicker = (NumberPicker)findViewById(R.id.objectpicker_rows);
 
@@ -107,7 +105,7 @@ public class Vertex3DActivity extends Activity
       @Override
       public void onValueChange(NumberPicker picker, int oldVal, int newVal)
         {
-        setGrid();
+        mNumCols = mColsPicker.getValue();
         }
       });
 
@@ -116,7 +114,7 @@ public class Vertex3DActivity extends Activity
       @Override
       public void onValueChange(NumberPicker picker, int oldVal, int newVal)
         {
-        setGrid();
+        mNumRows = mRowsPicker.getValue();
         }
       });
 
@@ -129,17 +127,25 @@ public class Vertex3DActivity extends Activity
 
     String[] objectType = new String[] {"DistortedCubes", "DistortedBitmap"};
 
-    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
-    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-    typeSpinner.setAdapter(adapter);
+    ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
+    adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+    typeSpinner.setAdapter(adapterType);
+
+    Spinner bitmapSpinner  = (Spinner)findViewById(R.id.objectpicker_spinnerBitmap);
+    bitmapSpinner.setOnItemSelectedListener(this);
+
+    String[] objectBitmap = new String[] {"Girl", "Dog", "Cat", "Grid"};
+
+    ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
+    adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+    bitmapSpinner.setAdapter(adapterBitmap);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private void setGrid()
     {
-    mNumCols = mColsPicker.getValue();
-    mNumRows = mRowsPicker.getValue();
+    mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
 
     int width = mLay.getWidth();
     int height= mLay.getHeight();
@@ -172,9 +178,9 @@ public class Vertex3DActivity extends Activity
         b.setOnClickListener(this);
         b.setId(rows*mNumCols+cols);
         b.setLayoutParams(p);
-        b.setBackgroundColor(COLOR_OFF);
+        b.setBackgroundColor(COLOR_ON);
         tr.addView(b, p);
-        mShape[rows*mNumCols+cols] = false;
+        mShape[rows*mNumCols+cols] = true;
         }
 
       mLay.addView(tr);
@@ -200,23 +206,49 @@ public class Vertex3DActivity extends Activity
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void Create(View v)
+  public int getBitmap()
     {
-    firstScreen = false;
+    return mBitmap;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
+  public void Continue(View v)
+    {
     if( mObjectType==1 )
       {
+      firstScreen = false;
       mObject = new DistortedBitmap(100,100,mNumCols);
+      setContentView(R.layout.vertex3dlayout);
+      Default(null);
       }
     else
       {
-      String str = "";
+      View view = getLayoutInflater().inflate(R.layout.objectpicker2layout, null);
 
-      for(int i=0; i<mNumRows*mNumCols; i++)
-        str += mShape[i] ? "1" : "0";
+      setContentView(view);
 
-      mObject = new DistortedCubes(mNumCols, str, 10);
+      view.post(new Runnable() {
+            @Override
+            public void run() {
+              setGrid();
+            }
+        });
       }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void Create(View v)
+    {
+    firstScreen = false;
+
+    String str = "";
+
+    for(int i=0; i<mNumRows*mNumCols; i++)
+      str += mShape[i] ? "1" : "0";
+
+    mObject = new DistortedCubes(mNumCols, str, 10);
 
     setContentView(R.layout.vertex3dlayout);
     Default(null);
@@ -229,7 +261,15 @@ public class Vertex3DActivity extends Activity
     {
     switch(parent.getId())
       {
-      case R.id.objectpicker_spinnerType: mObjectType = pos; break;
+      case R.id.objectpicker_spinnerType  : mObjectType = pos; break;
+      case R.id.objectpicker_spinnerBitmap: switch(pos)
+                                              {
+                                              case 0: mBitmap = R.raw.face; break;
+                                              case 1: mBitmap = R.raw.dog;  break;
+                                              case 2: mBitmap = R.raw.cat;  break;
+                                              case 3: mBitmap = R.raw.grid; break;
+                                              }
+                                            break;
       }
     }
 
@@ -550,8 +590,6 @@ public class Vertex3DActivity extends Activity
       {
       mColsPicker.setValue(mNumCols);
       mRowsPicker.setValue(mNumRows);
-
-      if( hasFocus ) setGrid();
       }
     }
 
diff --git a/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java b/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
index aaefcbc..def9bf0 100644
--- a/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
+++ b/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
@@ -251,8 +251,10 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
     
     public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
       {
-      InputStream is1 = mView.getContext().getResources().openRawResource(R.raw.grid);
-      InputStream is2 = mView.getContext().getResources().openRawResource(R.raw.center);
+      Vertex3DActivity act = (Vertex3DActivity)mView.getContext();
+
+      InputStream is1 = act.getResources().openRawResource(act.getBitmap());
+      InputStream is2 = act.getResources().openRawResource(R.raw.center);
 
       Bitmap bitmap1,bitmap2;
         
diff --git a/src/main/res/layout/objectpicker2layout.xml b/src/main/res/layout/objectpicker2layout.xml
new file mode 100644
index 0000000..1405a47
--- /dev/null
+++ b/src/main/res/layout/objectpicker2layout.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+       <Button
+        android:id="@+id/objectpicker_create"
+        android:onClick="Create"
+        android:text="@string/Create"
+        android:layout_width="match_parent"
+        android:layout_height="80dp"
+        android:layout_span="3"
+        android:layout_marginTop="5dp"/>
+
+       <LinearLayout
+        android:id="@+id/objectpicker_buttongrid"
+        android:layout_width="match_parent"
+        android:layout_height="fill_parent"
+        android:gravity="center"
+        android:orientation="vertical"
+        android:layout_weight="0.8">
+    </LinearLayout>
+
+   </LinearLayout>
\ No newline at end of file
diff --git a/src/main/res/layout/objectpickerlayout.xml b/src/main/res/layout/objectpickerlayout.xml
index e6bb1db..844d820 100644
--- a/src/main/res/layout/objectpickerlayout.xml
+++ b/src/main/res/layout/objectpickerlayout.xml
@@ -1,19 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
+                 android:orientation="vertical"
+                 android:layout_width="match_parent"
+                 android:layout_height="match_parent"
+                 android:gravity="center_vertical">
 
        <TableLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:stretchColumns="1,2,3"
-        android:shrinkColumns="1,2,3">
+           android:layout_width="match_parent"
+           android:layout_height="wrap_content"
+           android:stretchColumns="1,2,3,4"
+           android:shrinkColumns="1,2,3,4"
+           >
 
         <TableRow
             android:layout_width="match_parent"
-            android:layout_height="match_parent">
+            android:layout_height="match_parent"
+            android:paddingTop="10dp">
 
             <TextView
                 android:layout_width="wrap_content"
@@ -28,12 +31,35 @@
                 android:layout_width="fill_parent"
                 android:layout_height="50dp"
                 android:id="@+id/objectpicker_spinnerType"
-                android:layout_span="3"/>
+                android:layout_span="4"/>
         </TableRow>
 
-        <TableRow
+           <TableRow
+               android:layout_width="match_parent"
+               android:layout_height="match_parent"
+               android:paddingTop="10dp">
+
+               <TextView
+                   android:layout_width="wrap_content"
+                   android:layout_height="wrap_content"
+                   android:textAppearance="?android:attr/textAppearanceMedium"
+                   android:text="@string/Bitmap"
+                   android:id="@+id/textView7"
+                   android:layout_marginLeft="10dp"
+                   android:layout_gravity="center_vertical"/>
+
+               <Spinner
+                   android:layout_width="wrap_content"
+                   android:layout_height="50dp"
+                   android:id="@+id/objectpicker_spinnerBitmap"
+                   android:layout_span="4"/>
+           </TableRow>
+
+           <TableRow
             android:layout_width="match_parent"
-            android:layout_height="match_parent">
+            android:layout_height="match_parent"
+            android:paddingTop="10dp"
+            android:paddingBottom="10dp">
 
             <TextView
                 android:layout_width="wrap_content"
@@ -42,14 +68,14 @@
                 android:text="@string/rows"
                 android:id="@+id/textView8"
                 android:layout_gravity="center_vertical"
-                android:layout_marginLeft="10dp"/>
+                android:layout_marginLeft="10dp"
+                />
 
             <NumberPicker
                 android:id="@+id/objectpicker_rows"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:orientation="vertical"
-                android:layout_span="1"
                 />
 
             <TextView
@@ -59,7 +85,8 @@
                 android:text="@string/cols"
                 android:id="@+id/textView9"
                 android:layout_marginLeft="10dp"
-                android:layout_gravity="center_vertical"/>
+                android:layout_gravity="center_vertical"
+                />
 
             <NumberPicker
                 android:id="@+id/objectpicker_cols"
@@ -71,19 +98,10 @@
 
        </TableLayout>
 
-    <LinearLayout
-        android:id="@+id/objectpicker_buttongrid"
-        android:layout_width="match_parent"
-        android:layout_height="0dp"
-        android:gravity="center"
-        android:orientation="vertical"
-        android:layout_weight="0.8">
-    </LinearLayout>
-
     <Button
         android:id="@+id/objectpicker_create"
-        android:onClick="Create"
-        android:text="@string/Create"
+        android:onClick="Continue"
+        android:text="@string/continu"
         android:layout_width="match_parent"
         android:layout_height="50dp"
         android:layout_span="4"
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 5c2bd66..77d3a50 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -46,6 +46,7 @@
     <string name="Default">Default</string>
     <string name="save">Save</string>
     <string name="Create">Create</string>
+    <string name="Bitmap">Bitmap</string>
 
     <string name="example_monalisa">Mona Lisa</string>  
     <string name="example_monalisa_subtitle">The basics of Distortions.</string>
