commit 42772cff4f6527dbd3a82625280192d73b3341a2
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Jan 21 12:34:22 2020 +0000

    RubikCube: major progress with a separate RubikSettingsEnum enum - has been introduced into RubikActivity & RubikRenderer.

diff --git a/src/main/java/org/distorted/effect/ScrambleEffect.java b/src/main/java/org/distorted/effect/ScrambleEffect.java
index eb64dfd4..59e3fd2b 100644
--- a/src/main/java/org/distorted/effect/ScrambleEffect.java
+++ b/src/main/java/org/distorted/effect/ScrambleEffect.java
@@ -83,13 +83,6 @@ public abstract class ScrambleEffect implements EffectListener
     mLastVector = -1;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static Type getType(int ordinal)
-    {
-    return types[ordinal];
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public static String[] getNames()
@@ -106,9 +99,9 @@ public abstract class ScrambleEffect implements EffectListener
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public static ScrambleEffect create(Type type) throws InstantiationException, IllegalAccessException
+  public static ScrambleEffect create(int ordinal) throws InstantiationException, IllegalAccessException
     {
-    return type.effect.newInstance();
+    return types[ordinal].effect.newInstance();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/effect/SizeChangeEffect.java b/src/main/java/org/distorted/effect/SizeChangeEffect.java
index b4d5afed..81984751 100644
--- a/src/main/java/org/distorted/effect/SizeChangeEffect.java
+++ b/src/main/java/org/distorted/effect/SizeChangeEffect.java
@@ -94,13 +94,6 @@ public abstract class SizeChangeEffect implements EffectListener
     mCube               = new RubikCube[NUM_PHASES];
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static Type getType(int index)
-    {
-    return types[index];
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public static String[] getNames()
@@ -117,9 +110,9 @@ public abstract class SizeChangeEffect implements EffectListener
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public static SizeChangeEffect create(Type type) throws InstantiationException, IllegalAccessException
+  public static SizeChangeEffect create(int ordinal) throws InstantiationException, IllegalAccessException
     {
-    return type.effect.newInstance();
+    return types[ordinal].effect.newInstance();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/effect/SolveEffect.java b/src/main/java/org/distorted/effect/SolveEffect.java
index cad0d40f..1ebe4bac 100644
--- a/src/main/java/org/distorted/effect/SolveEffect.java
+++ b/src/main/java/org/distorted/effect/SolveEffect.java
@@ -88,13 +88,6 @@ public abstract class SolveEffect implements EffectListener
     mNodeEffects        = new Effect[NUM_PHASES][];
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static Type getType(int ordinal)
-    {
-    return types[ordinal];
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public static String[] getNames()
@@ -111,9 +104,9 @@ public abstract class SolveEffect implements EffectListener
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public static SolveEffect create(Type type) throws InstantiationException, IllegalAccessException
+  public static SolveEffect create(int ordinal) throws InstantiationException, IllegalAccessException
     {
-    return type.effect.newInstance();
+    return types[ordinal].effect.newInstance();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/magic/RubikActivity.java b/src/main/java/org/distorted/magic/RubikActivity.java
index a8470485..3f7929bc 100644
--- a/src/main/java/org/distorted/magic/RubikActivity.java
+++ b/src/main/java/org/distorted/magic/RubikActivity.java
@@ -30,9 +30,6 @@ import android.support.v7.app.AppCompatActivity;
 import android.view.View;
 
 import org.distorted.component.HorizontalNumberPicker;
-import org.distorted.effect.ScrambleEffect;
-import org.distorted.effect.SizeChangeEffect;
-import org.distorted.effect.SolveEffect;
 import org.distorted.library.main.DistortedLibrary;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -43,20 +40,13 @@ public class RubikActivity extends AppCompatActivity implements RubikSettings.On
     private static final int SMALLEST_SIZE = 2;
     private static final int[] button_ids  = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
 
-    public static final int DEFAULT_SIZECHANGE_POS = 20;
-    public static final int DEFAULT_SOLVE_POS      = 20;
-    public static final int DEFAULT_SCRAMBLE_POS   =100;
-    public static final int DEFAULT_SIZECHANGE_TYPE= 1;
-    public static final int DEFAULT_SOLVE_TYPE     = 1;
-    public static final int DEFAULT_SCRAMBLE_TYPE  = 0;
-
     public static final int MIN_SCRAMBLE =  1;
     public static final int MAX_SCRAMBLE = 10;
 
     private static int mSize = DEFAULT_SIZE;
 
-    private int mSizeChangePos, mSolvePos, mScramblePos;
-    private int mSizeChangeType, mSolveType, mScrambleType;
+    private int[] mPos;
+    private int[] mType;
 
     private HorizontalNumberPicker mPicker;
 
@@ -70,12 +60,19 @@ public class RubikActivity extends AppCompatActivity implements RubikSettings.On
       setContentView(R.layout.main);
       markButton(mSize);
 
+      mPos = new int[RubikSettingsEnum.LENGTH];
+      mType= new int[RubikSettingsEnum.LENGTH];
+
       mPicker = findViewById(R.id.rubikNumberPicker);
       mPicker.setMin(MIN_SCRAMBLE);
       mPicker.setMax(MAX_SCRAMBLE);
 
       restorePreferences();
-      applyPreferences();
+
+      for (int i=0; i<RubikSettingsEnum.LENGTH; i++)
+       {
+       applyPreferences(i);
+       }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -122,12 +119,16 @@ public class RubikActivity extends AppCompatActivity implements RubikSettings.On
       {
       Bundle args = new Bundle();
 
-      args.putInt("SIZECHANGE_Pos" , mSizeChangePos );
-      args.putInt("SOLVE_Pos"      , mSolvePos      );
-      args.putInt("SCRAMBLE_Pos"   , mScramblePos   );
-      args.putInt("SIZECHANGE_Type", mSizeChangeType);
-      args.putInt("SOLVE_Type"     , mSolveType     );
-      args.putInt("SCRAMBLE_Type"  , mScrambleType  );
+      String name;
+
+      for (int i=0; i<RubikSettingsEnum.LENGTH; i++)
+        {
+        RubikSettingsEnum rse = RubikSettingsEnum.getEnum(i);
+        name = rse.name();
+
+        args.putInt(name+"_Pos" , mPos[i]);
+        args.putInt(name+"_Type", mType[i]);
+        }
 
       RubikSettings settings = new RubikSettings();
       settings.setArguments(args);
@@ -162,16 +163,15 @@ public class RubikActivity extends AppCompatActivity implements RubikSettings.On
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    public void onComplete(int sizeP, int solvP, int scraP, int sizeT, int solvT, int scraT )
+    public void onComplete(int index, int position, int type )
       {
-      mSizeChangePos = sizeP;
-      mSolvePos      = solvP;
-      mScramblePos   = scraP;
-      mSizeChangeType= sizeT;
-      mSolveType     = solvT;
-      mScrambleType  = scraT;
-
-      applyPreferences();
+      if( index>=0 && index<RubikSettingsEnum.LENGTH )
+        {
+        mPos[index] = position;
+        mType[index]= type;
+
+        applyPreferences(index);
+        }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -223,14 +223,18 @@ public class RubikActivity extends AppCompatActivity implements RubikSettings.On
      {
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
      SharedPreferences.Editor editor = preferences.edit();
+     String name;
+
+     for (int i=0; i<RubikSettingsEnum.LENGTH; i++)
+       {
+       RubikSettingsEnum rse = RubikSettingsEnum.getEnum(i);
+       name = rse.name();
+
+       editor.putInt(name+"_Pos" , mPos[i]);
+       editor.putInt(name+"_Type", mType[i]);
+       }
 
-     editor.putInt("SIZECHANGE_Pos" , mSizeChangePos );
-     editor.putInt("SOLVE_Pos"      , mSolvePos      );
-     editor.putInt("SCRAMBLE_Pos"   , mScramblePos   );
-     editor.putInt("SIZECHANGE_Type", mSizeChangeType);
-     editor.putInt("SOLVE_Type"     , mSolveType     );
-     editor.putInt("SCRAMBLE_Type"  , mScrambleType  );
-     editor.putInt("scramble"       , mPicker.getValue() );
+     editor.putInt("scramble", mPicker.getValue() );
 
      editor.apply();
      }
@@ -241,30 +245,31 @@ public class RubikActivity extends AppCompatActivity implements RubikSettings.On
      {
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
 
-     mSizeChangePos = preferences.getInt("SIZECHANGE_Pos" , DEFAULT_SIZECHANGE_POS );
-     mSolvePos      = preferences.getInt("SOLVE_Pos"      , DEFAULT_SOLVE_POS      );
-     mScramblePos   = preferences.getInt("SCRAMBLE_Pos"   , DEFAULT_SCRAMBLE_POS   );
-     mSizeChangeType= preferences.getInt("SIZECHANGE_Type", DEFAULT_SIZECHANGE_TYPE);
-     mSolveType     = preferences.getInt("SOLVE_Type"     , DEFAULT_SOLVE_TYPE     );
-     mScrambleType  = preferences.getInt("SCRAMBLE_Type"  , DEFAULT_SCRAMBLE_TYPE  );
-     int scramble   = preferences.getInt("scramble"       , MIN_SCRAMBLE           );
+     String name;
+
+     for (int i=0; i<RubikSettingsEnum.LENGTH; i++)
+       {
+       RubikSettingsEnum rse = RubikSettingsEnum.getEnum(i);
+       name = rse.name();
+
+       mPos[i]  = preferences.getInt(name+"_Pos" , rse.getDefaultPos() );
+       mType[i] = preferences.getInt(name+"_Type", rse.getDefaultType());
+       }
+
+     int scramble= preferences.getInt("scramble", MIN_SCRAMBLE);
 
      mPicker.setValue(scramble);
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-   private void applyPreferences()
+   private void applyPreferences(int index)
      {
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
      RubikRenderer renderer = view.getRenderer();
 
-     renderer.setSizeChangeDuration(translateDuration(mSizeChangePos)+1);
-     renderer.setSolveDuration(translateDuration(mSolvePos)+1);
-     renderer.setScrambleDuration(translateDuration(mScramblePos)+1);
-     renderer.setSizeChangeType(SizeChangeEffect.getType(mSizeChangeType));
-     renderer.setSolveType(SolveEffect.getType(mSolveType));
-     renderer.setScrambleType(ScrambleEffect.getType(mScrambleType));
+     renderer.setPos (index, translateDuration(mPos[index])+1);
+     renderer.setType(index, mType[index] );
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/magic/RubikRenderer.java b/src/main/java/org/distorted/magic/RubikRenderer.java
index 56c03f11..b61f889e 100644
--- a/src/main/java/org/distorted/magic/RubikRenderer.java
+++ b/src/main/java/org/distorted/magic/RubikRenderer.java
@@ -56,10 +56,8 @@ public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
     private RubikCube mOldCube, mNewCube;
     private int mScreenWidth, mScreenHeight;
     private MeshFlat mMesh;
-    private SizeChangeEffect.Type mSizeChangeType;
-    private SolveEffect.Type mSolveType;
-    private ScrambleEffect.Type mScrambleType;
-    private int mSizeChangeDuration, mSolveDuration, mScrambleDuration;
+    private int[] mPos;
+    private int[] mType;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -92,13 +90,13 @@ public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
       mCanScramble = true;
       mCanSolve    = true;
 
-      mSizeChangeType= SizeChangeEffect.Type.TRANSPARENCY;
-      mSolveType     = SolveEffect.Type.SPIN;
-      mScrambleType  = ScrambleEffect.Type.NONE;
+      mPos  = new int[RubikSettingsEnum.LENGTH];
+      mType = new int[RubikSettingsEnum.LENGTH];
 
-      mSizeChangeDuration= 1000;
-      mSolveDuration     = 1000;
-      mScrambleDuration  = 1000;
+      for (int i=0; i<RubikSettingsEnum.LENGTH; i++)
+        {
+        mPos[i] = 1000;
+        }
 
       mMesh= new MeshFlat(20,20);
       mNextCubeSize =RubikActivity.getSize();
@@ -247,8 +245,8 @@ public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
      {
      try
        {
-       SizeChangeEffect effect = SizeChangeEffect.create(mSizeChangeType);
-       mSizeChangeEffectID = effect.start(mSizeChangeDuration,mScreen,mOldCube,mNewCube,this);
+       SizeChangeEffect effect = SizeChangeEffect.create(mType[0]);
+       mSizeChangeEffectID = effect.start(mPos[0],mScreen,mOldCube,mNewCube,this);
        }
      catch(Exception ex)
        {
@@ -279,44 +277,16 @@ public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-   void setSizeChangeDuration(int duration)
-     {
-     mSizeChangeDuration = duration;
-     }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-   void setSolveDuration(int duration)
-     {
-     mSolveDuration = duration;
-     }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-   void setScrambleDuration(int duration)
-     {
-     mScrambleDuration = duration;
-     }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-   void setSizeChangeType(SizeChangeEffect.Type type)
-     {
-     mSizeChangeType = type;
-     }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-   void setSolveType(SolveEffect.Type type)
+   void setPos(int index, int pos)
      {
-     mSolveType = type;
+     if( index>=0 && index<RubikSettingsEnum.LENGTH )  mPos[index] = pos;
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-   void setScrambleType(ScrambleEffect.Type type)
+   void setType(int index, int type)
      {
-     mScrambleType = type;
+     if( index>=0 && index<RubikSettingsEnum.LENGTH )  mType[index] = type;
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -380,8 +350,8 @@ public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
      {
      try
        {
-       ScrambleEffect effect = ScrambleEffect.create(mScrambleType);
-       mScrambleEffectID = effect.start(mScrambleDuration,mNewCube,mScrambleCubeNum,this);
+       ScrambleEffect effect = ScrambleEffect.create(mType[2]);
+       mScrambleEffectID = effect.start(mPos[2],mNewCube,mScrambleCubeNum,this);
        }
      catch(Exception ex)
        {
@@ -408,8 +378,8 @@ public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
      {
      try
        {
-       SolveEffect effect = SolveEffect.create(mSolveType);
-       mSolveEffectID = effect.start(mSolveDuration,mScreen,mNewCube,this);
+       SolveEffect effect = SolveEffect.create(mType[1]);
+       mSolveEffectID = effect.start(mPos[1],mScreen,mNewCube,this);
        }
      catch(Exception ex)
        {
diff --git a/src/main/java/org/distorted/magic/RubikSettings.java b/src/main/java/org/distorted/magic/RubikSettings.java
index 2c9441f4..ff4ccdfe 100644
--- a/src/main/java/org/distorted/magic/RubikSettings.java
+++ b/src/main/java/org/distorted/magic/RubikSettings.java
@@ -44,7 +44,7 @@ public class RubikSettings extends AppCompatDialogFragment implements SeekBar.On
   {
   public interface OnCompleteListener
     {
-    void onComplete(int sizeP, int solvP, int scraP, int sizeT, int solvT, int scraT);
+    void onComplete(int index, int position, int type);
     }
 
   private OnCompleteListener mListener;
@@ -293,7 +293,10 @@ public class RubikSettings extends AppCompatDialogFragment implements SeekBar.On
 
     private void saveOptions()
       {
-      mListener.onComplete(mPos[0], mPos[1], mPos[2], mType[0], mType[1], mType[2]);
+      for (int i=0; i<RubikSettingsEnum.LENGTH; i++)
+        {
+        mListener.onComplete(i, mPos[i], mType[i]);
+        }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
