commit be803eb39dd3828f636287d9df4b78bffb20e27c
Author: leszek <leszek@koltunski.pl>
Date:   Mon Dec 9 11:54:24 2024 +0100

    Add possibility to select different solvers.

diff --git a/src/main/java/org/distorted/phasedsolver/SolverActivity.java b/src/main/java/org/distorted/phasedsolver/SolverActivity.java
index af0b9d8..48dcce1 100644
--- a/src/main/java/org/distorted/phasedsolver/SolverActivity.java
+++ b/src/main/java/org/distorted/phasedsolver/SolverActivity.java
@@ -15,6 +15,9 @@ import android.app.Activity;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Spinner;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -22,6 +25,8 @@ import androidx.preference.PreferenceManager;
 
 import org.distorted.library.main.DistortedLibrary;
 import org.distorted.objectlib.algsolvers.*;
+import org.distorted.objectlib.algsolvers.implemented.Solver3x3Beginner;
+import org.distorted.objectlib.algsolvers.implemented.SolverAbstract;
 import org.distorted.objectlib.algsolvers.implemented.SolverKilominx;
 import org.distorted.objectlib.main.InitAssets;
 import org.distorted.objectlib.main.ObjectControl;
@@ -31,7 +36,7 @@ import org.distorted.os.OSInterface;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-public class SolverActivity extends Activity implements SolutionListener
+public class SolverActivity extends Activity implements SolutionListener, AdapterView.OnItemSelectedListener
 {
   private InitAssets mAsset;
   private SharedPreferences mPreferences;
@@ -40,7 +45,8 @@ public class SolverActivity extends Activity implements SolutionListener
   private SolvedObject mObject;
   private String mMoves;
   private int mNumMoves;
-  private SolverKilominx mBeginner;
+  private int mCurrSolver;
+  private SolverAbstract mSolver;
   private long mTime;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -58,15 +64,18 @@ public class SolverActivity extends Activity implements SolutionListener
     mText = findViewById(R.id.solverMoves);
     mMoves = "";
     mNumMoves = 0;
+    Spinner objectSpinner = findViewById(R.id.solverSpinner);
+    objectSpinner.setOnItemSelectedListener(this);
 
-    mBeginner = new SolverKilominx();
-    mObject = mBeginner.getObject();
+    mCurrSolver = 0;
+    String[] solverNames = createSolverNames();
+    ArrayAdapter<String> objAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, solverNames);
+    objAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+    objectSpinner.setAdapter(objAdapter);
 
-    int numPhases = mBeginner.getNumPhases();
-    String[] names = new String[numPhases];
-    for(int p=0; p<numPhases; p++) names[p] = mBeginner.getPhaseName(p);
+    String[] phaseNames = createSolver();
 
-    mLowerPane = new SolverLowerPane(this,names);
+    mLowerPane = new SolverLowerPane(this,phaseNames);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -94,8 +103,9 @@ public class SolverActivity extends Activity implements SolutionListener
 
     restorePreferences();
 
+    int ordinal = getObjectOrdinal();
     ObjectControl control = getControl();
-    control.changeObject(ListObjects.KILO_3.ordinal(), MODE_NORM, mAsset);
+    control.changeObject(ordinal, MODE_NORM, mAsset);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -107,6 +117,61 @@ public class SolverActivity extends Activity implements SolutionListener
     super.onDestroy();
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
+    {
+    if( parent.getId()==R.id.solverSpinner && mCurrSolver!=pos )
+      {
+      mCurrSolver = pos;
+      String[] phaseNames = createSolver();
+      mLowerPane.updateNames(this,phaseNames);
+      int ordinal = getObjectOrdinal();
+      ObjectControl control = getControl();
+      control.changeObject(ordinal, MODE_NORM, mAsset);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onNothingSelected(AdapterView<?> parent) { }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private String[] createSolverNames()
+    {
+    return new String[] {"3x3", "Kilo"};
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int getObjectOrdinal()
+    {
+    if( mCurrSolver==1 ) return ListObjects.KILO_3.ordinal();
+    return ListObjects.CUBE_3.ordinal();
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private String[] createSolver()
+    {
+    switch(mCurrSolver)
+      {
+      case 0 : mSolver = new Solver3x3Beginner(); break;
+      case 1 : mSolver = new SolverKilominx(); break;
+      default: android.util.Log.e("D", "unknown solver: "+mCurrSolver);
+               mSolver = new Solver3x3Beginner(); break;
+      }
+
+    mObject = mSolver.getObject();
+
+    int numPhases = mSolver.getNumPhases();
+    String[] names = new String[numPhases];
+    for(int p=0; p<numPhases; p++) names[p] = mSolver.getPhaseName(p);
+
+    return names;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void Left(View v)       { mLowerPane.backMove(this); }
@@ -189,7 +254,7 @@ public class SolverActivity extends Activity implements SolutionListener
       @Override
       public void run()
         {
-        mBeginner.solution(listener, qi);
+        mSolver.solution(listener, qi);
         }
       });
     }
diff --git a/src/main/java/org/distorted/phasedsolver/SolverLowerPane.java b/src/main/java/org/distorted/phasedsolver/SolverLowerPane.java
index b0aab22..b8493fb 100644
--- a/src/main/java/org/distorted/phasedsolver/SolverLowerPane.java
+++ b/src/main/java/org/distorted/phasedsolver/SolverLowerPane.java
@@ -22,11 +22,10 @@ public class SolverLowerPane implements MovesFinished
   private static final int MOVES_PLACE_1 = 101;
   private static final int MILLIS_PER_DEGREE = 6;
 
-  private final String[] mPhaseNames;
   private final TextView mText, mPhase;
-  private final int mNumPhases;
-  private final int[][][] mMoves;
-
+  private String[] mPhaseNames;
+  private int mNumPhases;
+  private int[][][] mMoves;
   private int mNumMoves,mCurrMove,mCurrPhase;
   private boolean mCanMove;
   private ObjectControl mControl;
@@ -45,6 +44,17 @@ public class SolverLowerPane implements MovesFinished
     setMoves(act,null,0);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void updateNames(SolverActivity act, String[] names)
+    {
+    mPhaseNames = names;
+    mNumPhases = names.length;
+    mMoves = new int[mNumPhases][][];
+    mCanMove = true;
+    setMoves(act,null,0);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   void backPhase(SolverActivity act)
diff --git a/src/main/res/layout/mainlayout.xml b/src/main/res/layout/mainlayout.xml
index 67d59e5..188e30e 100644
--- a/src/main/res/layout/mainlayout.xml
+++ b/src/main/res/layout/mainlayout.xml
@@ -55,17 +55,35 @@
 
     </LinearLayout>
 
-    <TextView
-        android:id="@+id/solverMoves"
+    <LinearLayout
+        android:id="@+id/middleBar"
         android:layout_below="@id/upperBar"
         android:layout_width="match_parent"
         android:layout_height="50dp"
-        android:background="@color/white"
-        android:textColor="@color/black"
-        android:layout_marginStart="4dp"
-        android:layout_marginEnd="4dp"
-        android:textAppearance="?android:attr/textAppearanceLarge"
-        android:gravity="center_vertical|start"/>
+        android:gravity="center"
+        android:orientation="horizontal"
+        android:background="@android:color/transparent">
+
+        <TextView
+            android:id="@+id/solverMoves"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="2"
+            android:background="@color/white"
+            android:textColor="@color/black"
+            android:layout_marginStart="4dp"
+            android:layout_marginEnd="4dp"
+            android:layout_marginTop="3dp"
+            android:layout_marginBottom="5dp"
+            android:textAppearance="?android:attr/textAppearanceLarge"
+            android:gravity="center_vertical|start"/>
+        <Spinner
+            android:id="@+id/solverSpinner"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"/>
+
+    </LinearLayout>
 
     <LinearLayout
         android:id="@+id/phaseBar"
