commit 50f5819742e8104e843eb6fea5397b5624e17bb5
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Tue Jul 5 23:33:37 2016 +0100

    Make the Fragment3D app more generic: beginnings.

diff --git a/src/main/java/org/distorted/examples/fragment3d/Fragment3DEffect.java b/src/main/java/org/distorted/examples/fragment3d/Fragment3DEffect.java
new file mode 100644
index 0000000..47bbb8c
--- /dev/null
+++ b/src/main/java/org/distorted/examples/fragment3d/Fragment3DEffect.java
@@ -0,0 +1,206 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.examples.fragment3d;
+
+import android.app.Activity;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+import org.distorted.examples.R;
+import org.distorted.library.EffectNames;
+import org.distorted.library.type.Dynamic1D;
+import org.distorted.library.type.Dynamic3D;
+import org.distorted.library.type.Static1D;
+import org.distorted.library.type.Static3D;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class Fragment3DEffect implements SeekBar.OnSeekBarChangeListener
+  {
+  private EffectNames mName;
+  private int[] mInter;
+  private SeekBar[] mSeek;
+  private int mDimension;
+  private TextView mText;
+
+  private Dynamic1D mDyn1;
+  private Dynamic3D mDyn3;
+  private Static1D  mSta1;
+  private Static3D  mSta3;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void fillStatics()
+    {
+    switch(mName)
+      {
+      case CHROMA    : mSta1.set(mInter[0]/100.0f);
+                       mSta3.set(255.0f*mInter[1]/100,
+                                 255.0f*mInter[2]/100,
+                                 255.0f*mInter[3]/100);
+                       break;
+      case ALPHA     : mSta1.set(mInter[0]/100.0f);
+                       break;
+      case SATURATION: mSta1.set(mInter[0]/100.0f);
+                       break;
+      case CONTRAST  : mSta1.set(mInter[0]/100.0f);
+                       break;
+      case BRIGHTNESS: mSta1.set(mInter[0]/100.0f);
+                       break;
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void setDefaultInter()
+    {
+    switch(mName)
+      {
+      case CHROMA    : mInter[0] = 100;
+                       mInter[1] =   0;
+                       mInter[2] =   0;
+                       mInter[3] =   0;
+                       break;
+      case ALPHA     : mInter[0] = 100;
+                       break;
+      case SATURATION: mInter[0] = 100;
+                       break;
+      case CONTRAST  : mInter[0] = 100;
+                       break;
+      case BRIGHTNESS: mInter[0] = 100;
+                       break;
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void setText()
+    {
+    switch(mName)
+      {
+      case CHROMA    : mText.setText("chroma "+mSta1.getX()+"("+mSta3.getX()+","+mSta3.getY()+","+mSta3.getZ()+")");
+                       break;
+      case ALPHA     : mText.setText("alpha ("+mSta1.getX()+")");
+                       break;
+      case SATURATION: mText.setText("saturation ("+mSta1.getX()+")");
+                       break;
+      case CONTRAST  : mText.setText("contrast ("+mSta1.getX()+")");
+                       break;
+      case BRIGHTNESS: mText.setText("brightness ("+mSta1.getX()+")");
+                       break;
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public Fragment3DEffect(EffectNames name)
+    {
+    mName = name;
+    mDimension = name.getDimension();
+
+    mInter = new int[mDimension];
+    mSeek  = new SeekBar[mDimension];
+
+    mDyn1 = new Dynamic1D();
+    mSta1 = new Static1D(0);
+    mDyn1.add(mSta1);
+
+    if( mName==EffectNames.CHROMA )
+      {
+      mDyn3 = new Dynamic3D();
+      mSta3 = new Static3D(0,0,0);
+      mDyn3.add(mSta3);
+      }
+    else
+      {
+      mDyn3 = null;
+      mSta3 = null;
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void addView(Activity act, LinearLayout layout)
+    {
+    View effect;
+
+    switch(mDimension)
+      {
+      case 1 : effect   = act.getLayoutInflater().inflate(R.layout.effect1d, null);
+               mText    = (TextView)effect.findViewById(R.id.effect1dText);
+               mSeek[0] = (SeekBar)effect.findViewById(R.id.effect1dbar1);
+               break;
+      case 2 : effect   = act.getLayoutInflater().inflate(R.layout.effect2d, null);
+               mText    = (TextView)effect.findViewById(R.id.effect2dText);
+               mSeek[0] = (SeekBar)effect.findViewById(R.id.effect2dbar1);
+               mSeek[1] = (SeekBar)effect.findViewById(R.id.effect2dbar2);
+               break;
+      case 3 : effect   = act.getLayoutInflater().inflate(R.layout.effect3d, null);
+               mText    = (TextView)effect.findViewById(R.id.effect3dText);
+               mSeek[0] = (SeekBar)effect.findViewById(R.id.effect3dbar1);
+               mSeek[1] = (SeekBar)effect.findViewById(R.id.effect3dbar2);
+               mSeek[2] = (SeekBar)effect.findViewById(R.id.effect3dbar3);
+               break;
+      case 4 : effect   = act.getLayoutInflater().inflate(R.layout.effect4d, null);
+               mText    = (TextView)effect.findViewById(R.id.effect4dText);
+               mSeek[0] = (SeekBar)effect.findViewById(R.id.effect4dbar1);
+               mSeek[1] = (SeekBar)effect.findViewById(R.id.effect4dbar2);
+               mSeek[2] = (SeekBar)effect.findViewById(R.id.effect4dbar3);
+               mSeek[3] = (SeekBar)effect.findViewById(R.id.effect4dbar3);
+               break;
+      default: android.util.Log.e("Fragment3DEffect", "dimension "+mDimension+" not supported!");
+               return;
+      }
+
+    setDefaultInter();
+    fillStatics();
+    setText();
+
+    for(int i=0; i<mDimension; i++)
+      {
+      mSeek[i].setOnSeekBarChangeListener(this);
+      mSeek[i].setProgress( mInter[i] );
+      }
+
+    layout.addView(effect, 0);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
+    {
+    if ( mDimension>=1 && bar.getId()==mSeek[0].getId() ) mInter[0] = progress;
+    if ( mDimension>=2 && bar.getId()==mSeek[1].getId() ) mInter[1] = progress;
+    if ( mDimension>=3 && bar.getId()==mSeek[2].getId() ) mInter[2] = progress;
+    if ( mDimension>=4 && bar.getId()==mSeek[3].getId() ) mInter[3] = progress;
+
+    fillStatics();
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void onStartTrackingTouch(SeekBar bar) { }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void onStopTrackingTouch(SeekBar bar)  { }
+  }
diff --git a/src/main/res/layout/effect1d.xml b/src/main/res/layout/effect1d.xml
new file mode 100644
index 0000000..68bf791
--- /dev/null
+++ b/src/main/res/layout/effect1d.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/effect1dLayout"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/effect1dText"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginStart="5dp"
+            android:layout_marginTop="3dp"
+            />
+
+        <SeekBar
+            android:id="@+id/effect1dbar1"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+
+</LinearLayout>
diff --git a/src/main/res/layout/effect2d.xml b/src/main/res/layout/effect2d.xml
new file mode 100644
index 0000000..3fdadb5
--- /dev/null
+++ b/src/main/res/layout/effect2d.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/effect2dLayout"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/effect2dText"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginStart="5dp"
+            android:layout_marginTop="3dp"
+            />
+
+        <SeekBar
+            android:id="@+id/effect2dbar1"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+
+        <SeekBar
+            android:id="@+id/effect2dbar2"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+</LinearLayout>
\ No newline at end of file
diff --git a/src/main/res/layout/effect3d.xml b/src/main/res/layout/effect3d.xml
new file mode 100644
index 0000000..e3409fd
--- /dev/null
+++ b/src/main/res/layout/effect3d.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/effect3dLayout"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/effect3dText"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginStart="5dp"
+            android:layout_marginTop="3dp" />
+
+        <SeekBar
+            android:id="@+id/effect3dbar1"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+
+        <SeekBar
+            android:id="@+id/effect3dbar2"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+
+        <SeekBar
+            android:id="@+id/effect3dbar3"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+</LinearLayout>
\ No newline at end of file
diff --git a/src/main/res/layout/effect4d.xml b/src/main/res/layout/effect4d.xml
new file mode 100644
index 0000000..3744ebc
--- /dev/null
+++ b/src/main/res/layout/effect4d.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/effect4dLayout"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/effect4dText"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginStart="5dp"
+            android:layout_marginTop="3dp" />
+
+        <SeekBar
+            android:id="@+id/effect4dbar1"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+
+        <SeekBar
+            android:id="@+id/effect4dbar2"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+
+        <SeekBar
+            android:id="@+id/effect4dbar3"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+
+        <SeekBar
+            android:id="@+id/effect4dbar4"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="5dp"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp" />
+</LinearLayout>
\ No newline at end of file
