commit bfcf419ab9c0e73c97925161de0a972fc8d93357
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Thu Jan 19 13:37:56 2017 +0000

    Improvements for the 'Cubes' and 'Effects3D' apps.

diff --git a/src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java b/src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java
index ee79303..56b2a2b 100644
--- a/src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java
+++ b/src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java
@@ -53,16 +53,13 @@ import java.util.ArrayList;
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 public class Effects3DActivity extends Activity
-                              implements View.OnClickListener,
-                                         AdapterView.OnItemSelectedListener
+                               implements View.OnClickListener,
+                                          AdapterView.OnItemSelectedListener
   {
   private static final int COLOR_OFF = 0xffffe81f;
   private static final int COLOR_ON  = 0xff0000ff;
+  private static final int COLOR_INAC= 0xff00ff00;
 
-  private boolean firstScreen;
-
-  // fields needed for the first 'pick-a-shape' screen
-  //
   private int mNumCols = 10;
   private int mNumRows = 10;
   private NumberPicker mColsPicker, mRowsPicker;
@@ -73,6 +70,7 @@ public class Effects3DActivity extends Activity
   private int mObjectType;
   private int mBitmapID;
   private Bitmap mBitmap;
+  private LinearLayout mLay;
 
   private ArrayList<Effects3DEffect> mList;
   private int mEffectAdd;
@@ -97,6 +95,8 @@ public class Effects3DActivity 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);
 
@@ -106,31 +106,29 @@ public class Effects3DActivity extends Activity
     mRowsPicker.setMinValue( 0);
 
     mColsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
-      {
-      @Override
-      public void onValueChange(NumberPicker picker, int oldVal, int newVal)
-        {
-        mNumCols = mColsPicker.getValue();
-        }
-      });
+         {
+         @Override
+         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
+           {
+           setGrid();
+           }
+         });
 
     mRowsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
-      {
-      @Override
-      public void onValueChange(NumberPicker picker, int oldVal, int newVal)
-        {
-        mNumRows = mRowsPicker.getValue();
-        }
-      });
-
-    firstScreen = true;
+         {
+         @Override
+         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
+           {
+           setGrid();
+           }
+         });
 
     mObjectType = 0;
 
     Spinner typeSpinner  = (Spinner)findViewById(R.id.objectpicker_spinnerType);
     typeSpinner.setOnItemSelectedListener(this);
 
-    String[] objectType = new String[] {"Cubes", "Flat"};
+    String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat"};
 
     ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
     adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
@@ -139,7 +137,8 @@ public class Effects3DActivity extends Activity
     Spinner bitmapSpinner  = (Spinner)findViewById(R.id.objectpicker_spinnerBitmap);
     bitmapSpinner.setOnItemSelectedListener(this);
 
-    String[] objectBitmap = new String[] { "Grid", "Girl", "Dog", "Cat", "Squares", "Bean", "Lisa"};
+    String[] objectBitmap = new String[] { "Texture: Grid", "Texture: Girl", "Texture: Dog", "Texture: Cat",
+                                           "Texture: Squares", "Texture: Bean", "Texture: Lisa" };
 
     ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
     adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
@@ -175,16 +174,17 @@ public class Effects3DActivity extends Activity
 
   private void setGrid()
     {
-    LinearLayout lay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
+    mNumCols = mColsPicker.getValue();
+    mNumRows = mRowsPicker.getValue();
 
-    int width = lay.getWidth();
-    int height= lay.getHeight();
+    int width = mLay.getWidth();
+    int height= mLay.getHeight();
     int w = mNumCols>0 ? (int)( 0.9f*width / mNumCols) : 0;
     int h = mNumRows>0 ? (int)( 0.9f*height/ mNumRows) : 0;
     int size= w<h ? w:h;
     int pad = size<20 ? 1 : size/20;
 
-    lay.removeAllViews();
+    mLay.removeAllViews();
 
     mShape = new boolean[mNumRows*mNumCols];
 
@@ -208,12 +208,12 @@ public class Effects3DActivity extends Activity
         b.setOnClickListener(this);
         b.setId(rows*mNumCols+cols);
         b.setLayoutParams(p);
-        b.setBackgroundColor(COLOR_ON);
+        b.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
         tr.addView(b, p);
         mShape[rows*mNumCols+cols] = true;
         }
 
-      lay.addView(tr);
+      mLay.addView(tr);
       }
     }
 
@@ -320,10 +320,33 @@ public class Effects3DActivity extends Activity
 
   public void onClick(View view)
     {
-    Button tmp = (Button)view;
-    int id = tmp.getId();
-    mShape[id] = !mShape[id];
-    tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
+    if( mObjectType!=1 )
+      {
+      Button tmp = (Button)view;
+      int id = tmp.getId();
+      mShape[id] = !mShape[id];
+      tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void uncheckAll()
+    {
+    TableRow tr;
+    Button butt;
+
+    for (int row=0; row<mNumRows; row++)
+      {
+      tr = (TableRow)mLay.getChildAt(row);
+
+      for(int col=0; col<mNumCols; col++)
+        {
+        butt = (Button)tr.getVirtualChildAt(col);
+        butt.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
+        mShape[row*mNumCols+col] = true;
+        }
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -396,56 +419,46 @@ public class Effects3DActivity extends Activity
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void Continue(View v)
+  public void Create(View v)
     {
-    firstScreen = false;
-
     DistortedEffects.setMaxVertex(20);    // those have to be called before
     DistortedEffects.setMaxFragment(3);   // any DistortedEffect get created!
 
     if( mObjectType==1 )
       {
-      getBitmap();
-
-      int w = mBitmap.getWidth();
-      int h = mBitmap.getHeight();
-
-      mEffects = new DistortedEffects();
-      mTexture= new DistortedTexture(w,h);
-      mMesh = new MeshFlat(mNumCols,mNumCols*h/w);
-      setEffectView();
+      mMesh = new MeshFlat(mNumCols,mNumRows);
       }
     else
       {
-      View view = getLayoutInflater().inflate(R.layout.objectpicker2layout, null);
+      String str = "";
 
-      setContentView(view);
+      for(int i=0; i<mNumRows*mNumCols; i++)
+        str += mShape[i] ? "1" : "0";
 
-      view.post(new Runnable() {
-            @Override
-            public void run() {
-              setGrid();
-            }
-        });
+      mMesh = new MeshCubes(mNumCols, str, false);
       }
-    }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
+    mEffects= new DistortedEffects();
+    mTexture= new DistortedTexture(mNumCols,mNumRows);
 
-  public void Create(View v)
-    {
-    firstScreen = false;
+    resetData();
 
-    String str = "";
+    final View view = getLayoutInflater().inflate(R.layout.effects3dlayout, null);
 
-    for(int i=0; i<mNumRows*mNumCols; i++)
-      str += mShape[i] ? "1" : "0";
+    setContentView(view);
 
-    mEffects = new DistortedEffects();
-    mTexture= new DistortedTexture(mNumCols,mNumRows);
-    mMesh = new MeshCubes(mNumCols, str, false);
+    String[] effects = new String[mEffectNames.length];
 
-    setEffectView();
+    for(int i=0; i<mEffectNames.length; i++) effects[i] = mEffectNames[i].name();
+
+    Spinner effectSpinner = (Spinner)findViewById(R.id.effects3dspinner );
+    effectSpinner.setOnItemSelectedListener(this);
+
+    ArrayAdapter<String> adapterEffect = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, effects);
+    adapterEffect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+    effectSpinner.setAdapter(adapterEffect);
+
+    mEffectAdd = 0;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -454,7 +467,11 @@ public class Effects3DActivity extends Activity
     {
     switch(parent.getId())
       {
-      case R.id.objectpicker_spinnerType  : mObjectType = pos;
+      case R.id.objectpicker_spinnerType  : if( mObjectType!=pos )
+                                              {
+                                              mObjectType = pos;
+                                              uncheckAll();
+                                              }
                                             break;
       case R.id.objectpicker_spinnerBitmap: switch(pos)
                                               {
@@ -523,30 +540,6 @@ public class Effects3DActivity extends Activity
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // 'second screen' methods
 
-  private void setEffectView()
-    {
-    resetData();
-
-    final View view = getLayoutInflater().inflate(R.layout.effects3dlayout, null);
-
-    setContentView(view);
-
-    String[] effects = new String[mEffectNames.length];
-
-    for(int i=0; i<mEffectNames.length; i++) effects[i] = mEffectNames[i].name();
-
-    Spinner effectSpinner = (Spinner)findViewById(R.id.effects3dspinner );
-    effectSpinner.setOnItemSelectedListener(this);
-
-    ArrayAdapter<String> adapterEffect = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, effects);
-    adapterEffect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-    effectSpinner.setAdapter(adapterEffect);
-
-    mEffectAdd = 0;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
   public void newEffect(View v)
     {
     Effects3DEffect eff = new Effects3DEffect(mEffectNames[mEffectAdd], this);
@@ -648,11 +641,10 @@ public class Effects3DActivity extends Activity
     {
     super.onWindowFocusChanged(hasFocus);
 
-    if( firstScreen )
-      {
-      mColsPicker.setValue(mNumCols);
-      mRowsPicker.setValue(mNumRows);
-      }
+    mColsPicker.setValue(mNumCols);
+    mRowsPicker.setValue(mNumRows);
+
+    if( hasFocus ) setGrid();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java b/src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
index 18fd8e9..11d3558 100644
--- a/src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
+++ b/src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
@@ -75,7 +75,7 @@ class Effects3DRenderer implements GLSurfaceView.Renderer
       Effects3DActivity act = (Effects3DActivity)v.getContext();
 
       mObjectTexture     = act.getTexture();
-      mObjectMesh = act.getMesh();
+      mObjectMesh        = act.getMesh();
       mObjectEffects     = act.getEffects();
       mBackgroundTexture = new DistortedTexture(100,100);
       mCenterTexture     = new DistortedTexture(100,100);
diff --git a/src/main/res/layout/cubespickerlayout.xml b/src/main/res/layout/cubespickerlayout.xml
index 184b339..3bcdadc 100644
--- a/src/main/res/layout/cubespickerlayout.xml
+++ b/src/main/res/layout/cubespickerlayout.xml
@@ -1,47 +1,47 @@
 <?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">
 
        <LinearLayout
-        android:orientation="horizontal"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content">
+           android:orientation="horizontal"
+           android:layout_width="match_parent"
+           android:layout_height="wrap_content">
 
-        <NumberPicker
-         android:id="@+id/cubespicker_rows"
-         android:layout_width="wrap_content"
-         android:layout_height="wrap_content"
-         android:orientation="vertical"
-         android:layout_span="1"
-         />
+           <NumberPicker
+               android:id="@+id/cubespicker_rows"
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content"
+               android:orientation="vertical"
+               android:descendantFocusability="blocksDescendants"
+           />
 
-        <NumberPicker
-         android:id="@+id/cubespicker_cols"
-         android:layout_width="wrap_content"
-         android:layout_height="wrap_content"
-         android:orientation="vertical"
-         android:layout_span="2"/>
+           <NumberPicker
+               android:id="@+id/cubespicker_cols"
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content"
+               android:orientation="vertical"
+               android:descendantFocusability="blocksDescendants"
+           />
 
-        <Button
-            android:id="@+id/cubespicker_create"
-            android:onClick="Create"
-            android:text="@string/Create"
-            android:layout_width="match_parent"
-            android:layout_height="fill_parent"
-            android:layout_span="3"
-            android:layout_marginTop="5dp"/>
-    </LinearLayout>
+           <Button
+               android:id="@+id/cubespicker_create"
+               android:onClick="Create"
+               android:text="@string/Create"
+               android:layout_width="match_parent"
+               android:layout_height="fill_parent"
+           />
+       </LinearLayout>
 
        <LinearLayout
-        android:id="@+id/cubespicker_buttongrid"
-        android:layout_width="match_parent"
-        android:layout_height="fill_parent"
-        android:gravity="center"
-        android:orientation="vertical"
-        android:layout_weight="0.8">
-    </LinearLayout>
+           android:id="@+id/cubespicker_buttongrid"
+           android:layout_width="match_parent"
+           android:layout_height="0dp"
+           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/objectpicker2layout.xml b/src/main/res/layout/objectpicker2layout.xml
deleted file mode 100644
index 1405a47..0000000
--- a/src/main/res/layout/objectpicker2layout.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?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 844d820..27995cf 100644
--- a/src/main/res/layout/objectpickerlayout.xml
+++ b/src/main/res/layout/objectpickerlayout.xml
@@ -1,110 +1,67 @@
 <?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:gravity="center_vertical">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+     android:orientation="vertical"
+     android:layout_width="match_parent"
+     android:layout_height="match_parent">
 
-       <TableLayout
+     <LinearLayout
+           android:orientation="horizontal"
            android:layout_width="match_parent"
-           android:layout_height="wrap_content"
-           android:stretchColumns="1,2,3,4"
-           android:shrinkColumns="1,2,3,4"
-           >
+           android:layout_height="wrap_content">
 
-        <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/Create"
-                android:id="@+id/textView2"
-                android:layout_gravity="center_vertical"
-                android:layout_marginLeft="10dp"/>
-
-            <Spinner
-                android:layout_width="fill_parent"
+           <Spinner
+                android:layout_width="0dp"
                 android:layout_height="50dp"
+                android:layout_weight="0.5"
                 android:id="@+id/objectpicker_spinnerType"
-                android:layout_span="4"/>
-        </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"
+           <Spinner
+                   android:layout_width="0dp"
                    android:layout_height="50dp"
+                   android:layout_weight="0.5"
                    android:id="@+id/objectpicker_spinnerBitmap"
-                   android:layout_span="4"/>
-           </TableRow>
-
-           <TableRow
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:paddingTop="10dp"
-            android:paddingBottom="10dp">
-
-            <TextView
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:text="@string/rows"
-                android:id="@+id/textView8"
-                android:layout_gravity="center_vertical"
-                android:layout_marginLeft="10dp"
-                />
+           />
+     </LinearLayout>
 
-            <NumberPicker
-                android:id="@+id/objectpicker_rows"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:orientation="vertical"
-                />
-
-            <TextView
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:text="@string/cols"
-                android:id="@+id/textView9"
-                android:layout_marginLeft="10dp"
-                android:layout_gravity="center_vertical"
-                />
-
-            <NumberPicker
-                android:id="@+id/objectpicker_cols"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:orientation="vertical"
-                />
-        </TableRow>
-
-       </TableLayout>
+     <LinearLayout
+           android:orientation="horizontal"
+           android:layout_width="match_parent"
+           android:layout_height="wrap_content">
+
+           <NumberPicker
+               android:id="@+id/objectpicker_rows"
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content"
+               android:orientation="vertical"
+               android:descendantFocusability="blocksDescendants"
+           />
+
+           <NumberPicker
+               android:id="@+id/objectpicker_cols"
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content"
+               android:orientation="vertical"
+               android:descendantFocusability="blocksDescendants"
+           />
+
+           <Button
+               android:id="@+id/objectpicker_create"
+               android:onClick="Create"
+               android:text="@string/Create"
+               android:layout_width="match_parent"
+               android:layout_height="fill_parent"
+           />
+       </LinearLayout>
 
-    <Button
-        android:id="@+id/objectpicker_create"
-        android:onClick="Continue"
-        android:text="@string/continu"
-        android:layout_width="match_parent"
-        android:layout_height="50dp"
-        android:layout_span="4"
-        android:layout_marginTop="5dp"/>
+       <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>
 
 </LinearLayout>
\ No newline at end of file
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 1c6a9c9..346851f 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -60,6 +60,7 @@
     <string name="angleB">Beta</string>
     <string name="DepthYes">Depth</string>
     <string name="DepthNo">No Depth</string>
+    <string name="mesh">Mesh</string>
 
     <string name="radius_placeholder">Radius: %1$s</string>
     <string name="noise_placeholder">Noise %1$s</string>
