commit 017f24b316ee8500a3c5d78dbbb187df013029b4
Author: leszek <leszek@koltunski.pl>
Date:   Thu Nov 9 00:00:59 2023 +0100

    new Pattern Activity!

diff --git a/src/main/java/org/distorted/dialogs/RubikDialogPatternListAdapter.java b/src/main/java/org/distorted/dialogs/RubikDialogPatternListAdapter.java
index 26e29161..bc670649 100644
--- a/src/main/java/org/distorted/dialogs/RubikDialogPatternListAdapter.java
+++ b/src/main/java/org/distorted/dialogs/RubikDialogPatternListAdapter.java
@@ -26,15 +26,15 @@ import org.distorted.main.R;
 class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
   {
   private final Context mContext;
-  private final int mTab, mWidth;
+  private final int mTab, mHeight;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public RubikDialogPatternListAdapter(Context context, int tab, int width)
+  public RubikDialogPatternListAdapter(Context context, int tab, int height)
     {
     mContext = context;
     mTab     = tab;
-    mWidth   = width;
+    mHeight  = height;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -67,7 +67,7 @@ class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
       view = infalInflater.inflate(R.layout.dialog_pattern_child_item, null);
       }
 
-    int size = (int)(mWidth* RubikActivity.PATTERN_CHILD_TEXT);
+    int size = (int)(mHeight* RubikActivity.PATTERN_CHILD_TEXT);
 
     TextView childItem = view.findViewById(R.id.child);
     childItem.setText(childName);
@@ -124,7 +124,7 @@ class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
       view = inf.inflate(R.layout.dialog_pattern_group_item, null);
       }
 
-    int size = (int)(mWidth* RubikActivity.PATTERN_GROUP_TEXT);
+    int size = (int)(mHeight* RubikActivity.PATTERN_GROUP_TEXT);
 
     TextView heading = view.findViewById(R.id.heading);
     heading.setText(groupName);
diff --git a/src/main/java/org/distorted/dialogs/RubikDialogPatternSingle.java b/src/main/java/org/distorted/dialogs/RubikDialogPatternSingle.java
index 9e996ab0..0da76e79 100644
--- a/src/main/java/org/distorted/dialogs/RubikDialogPatternSingle.java
+++ b/src/main/java/org/distorted/dialogs/RubikDialogPatternSingle.java
@@ -47,14 +47,14 @@ public class RubikDialogPatternSingle extends RubikDialogAbstract
       {
       WindowManager.LayoutParams params = window.getAttributes();
       params.width  = (int)Math.min( mHeight*0.65f,mWidth*0.98f );
-      params.height = (int)Math.min( mHeight*0.80f,mWidth*1.30f );
+      //params.height = (int)Math.min( mHeight*0.80f,mWidth*1.30f );
       window.setAttributes(params);
       }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public int getResource()      { return R.layout.dialog_pattern_tab; }
+  public int getResource()      { return R.layout.dialog_pattern_single; }
   public int getTitleResource() { return R.string.choose_pattern; }
   public boolean hasArgument()  { return true; }
   public int getPositive()      { return -1; }
@@ -82,6 +82,8 @@ public class RubikDialogPatternSingle extends RubikDialogAbstract
       return;
       }
 
+    android.util.Log.e("D", "prepareBody: object "+mArgument);
+
     final PatternActivity pact = (PatternActivity)getContext();
     int height = pact!=null ? pact.getScreenHeightInPixels() : 100;
     final ObjectControl control = pact!=null ? pact.getControl() : null;
@@ -93,15 +95,11 @@ public class RubikDialogPatternSingle extends RubikDialogAbstract
     RubikDialogPatternListAdapter listAdapter = new RubikDialogPatternListAdapter(act,mPatternOrdinal,height);
     mListView.setAdapter(listAdapter);
 
-    if( mExpandedGroup>=0 )
-      {
-      mListView.expandGroup(mExpandedGroup);
-      }
+    if( mExpandedGroup>=0 ) mListView.expandGroup(mExpandedGroup);
 
     int visible = pattern.recallVisiblePos(mPatternOrdinal);
     mListView.setSelectionFromTop(visible,0);
 
-
     mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
       {
       @Override
@@ -109,7 +107,7 @@ public class RubikDialogPatternSingle extends RubikDialogAbstract
         {
         RubikPattern pattern = RubikPattern.getInstance();
         int[][] moves = pattern.reInitialize(mPatternOrdinal, groupPosition, childPosition);
-        control.initializeObject(moves);
+        if( control!=null ) control.initializeObject(moves);
 
         ScreenPattern state = (ScreenPattern) ScreenList.PATT.getScreenClass();
         state.setPattern(pact, mPatternOrdinal, groupPosition, childPosition);
diff --git a/src/main/java/org/distorted/patternui/PatternActivity.java b/src/main/java/org/distorted/patternui/PatternActivity.java
index d13e3f92..ba9b27a4 100644
--- a/src/main/java/org/distorted/patternui/PatternActivity.java
+++ b/src/main/java/org/distorted/patternui/PatternActivity.java
@@ -46,7 +46,7 @@ public class PatternActivity extends AppCompatActivity
     public static final float PADDING         = 0.010f;
     public static final float SMALL_MARGIN    = 0.004f;
     public static final float BUTTON_TEXT_SIZE= 0.050f;
-    public static final float TITLE_TEXT_SIZE = 0.060f;
+    public static final float TITLE_TEXT_SIZE = 0.045f;
 
     private static final int ACTIVITY_NUMBER = 1;
     private static final float RATIO_INSET= 0.09f;
@@ -194,9 +194,8 @@ public class PatternActivity extends AppCompatActivity
 
       createObject();
       RubikObjectList.setCurrObject(mObjectOrdinal);
-
       SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
-      restorePreferences(preferences,mJustStarted);
+      restorePreferences(preferences);
       ScreenList.setScreen(this);
 
       if( mJustStarted )
@@ -222,18 +221,10 @@ public class PatternActivity extends AppCompatActivity
       SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
       SharedPreferences.Editor editor = preferences.edit();
 
-      for(int i = 0; i< ScreenList.LENGTH; i++ )
-        {
+      for(int i=0; i< ScreenList.LENGTH; i++ )
         ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
-        }
 
-      RubikObjectList.savePreferences(editor);
-      RubikObjectList.saveMeshState(editor);
       ScreenList.savePreferences(editor);
-      PatternSurfaceView view = findViewById(R.id.patternSurfaceView);
-      OSInterface os = view.getInterface();
-      os.setEditor(editor);
-      view.getObjectControl().savePreferences();
 
       boolean success = editor.commit();
       if( !success ) android.util.Log.e("D", "Failed to save preferences");
@@ -241,21 +232,12 @@ public class PatternActivity extends AppCompatActivity
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    private void restorePreferences(SharedPreferences preferences, boolean justStarted)
+    private void restorePreferences(SharedPreferences preferences)
       {
-      RubikObjectList.restorePreferences(this,preferences,justStarted);
-
-      for (int i = 0; i<ScreenList.LENGTH; i++)
-        {
+      for (int i=0; i<ScreenList.LENGTH; i++)
         ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
-        }
 
       ScreenList.restorePreferences(preferences);
-
-      PatternSurfaceView view = findViewById(R.id.patternSurfaceView);
-      OSInterface os = view.getInterface();
-      os.setPreferences(preferences);
-      view.getObjectControl().restorePreferences();
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/patternui/ScreenPattern.java b/src/main/java/org/distorted/patternui/ScreenPattern.java
index e23cc7e1..f86c1246 100644
--- a/src/main/java/org/distorted/patternui/ScreenPattern.java
+++ b/src/main/java/org/distorted/patternui/ScreenPattern.java
@@ -13,13 +13,12 @@ import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.util.TypedValue;
 import android.view.Gravity;
-import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
-import org.distorted.dialogs.RubikDialogError;
 import org.distorted.dialogs.RubikDialogPatternSingle;
+import org.distorted.helpers.TransparentButton;
 import org.distorted.helpers.TransparentImageButton;
 import org.distorted.main.R;
 import org.distorted.objectlib.main.ObjectControl;
@@ -30,8 +29,9 @@ import org.distorted.objects.RubikObjectList;
 
 public class ScreenPattern extends ScreenAbstract
   {
-  private TextView mText;
   private TransparentImageButton mPrevButton, mNextButton, mBackButton;
+  private TransparentImageButton mPrevPatt, mNextPatt;
+  private TransparentButton mTextButton;
   private TextView mMovesText;
   private int mNumMoves;
   private int mPatternOrdinal, mCategory, mPattern;
@@ -57,8 +57,6 @@ public class ScreenPattern extends ScreenAbstract
     {
     float width = act.getScreenWidthInPixels();
     mButtonSize = width*PatternActivity.BUTTON_TEXT_SIZE;
-    float titleSize  = width*PatternActivity.TITLE_TEXT_SIZE;
-    LayoutInflater inflater = act.getLayoutInflater();
 
     mPatternOrdinal = -1;
     mCategory       = -1;
@@ -67,10 +65,29 @@ public class ScreenPattern extends ScreenAbstract
     // TOP ////////////////////////////
     LinearLayout layoutTop = act.findViewById(R.id.upperBar);
     layoutTop.removeAllViews();
-    mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null);
-    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
-    mText.setText(R.string.patterns);
-    layoutTop.addView(mText);
+
+    setupPrevPatt(act);
+    setupNextPatt(act);
+    setupTextButton(act,width);
+
+    LinearLayout.LayoutParams pTL = new LinearLayout.LayoutParams((int)(  width/6),LinearLayout.LayoutParams.MATCH_PARENT);
+    LinearLayout.LayoutParams pTM = new LinearLayout.LayoutParams((int)(2*width/3),LinearLayout.LayoutParams.MATCH_PARENT);
+    LinearLayout.LayoutParams pTR = new LinearLayout.LayoutParams((int)(  width/6),LinearLayout.LayoutParams.MATCH_PARENT);
+
+    LinearLayout layoutTL = new LinearLayout(act);
+    layoutTL.setLayoutParams(pTL);
+    LinearLayout layoutTM = new LinearLayout(act);
+    layoutTM.setLayoutParams(pTM);
+    LinearLayout layoutTR = new LinearLayout(act);
+    layoutTR.setLayoutParams(pTR);
+
+    layoutTL.addView(mPrevPatt);
+    layoutTM.addView(mTextButton);
+    layoutTR.addView(mNextPatt);
+
+    layoutTop.addView(layoutTL);
+    layoutTop.addView(layoutTM);
+    layoutTop.addView(layoutTR);
 
     // BOT ////////////////////////////
     LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
@@ -80,29 +97,34 @@ public class ScreenPattern extends ScreenAbstract
     setupNextButton(act);
     setupTextView(act,width);
 
-    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT);
-    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT);
-    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT);
+    LinearLayout.LayoutParams pBL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT);
+    LinearLayout.LayoutParams pBM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT);
+    LinearLayout.LayoutParams pBR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT);
 
-    LinearLayout layoutLeft = new LinearLayout(act);
-    layoutLeft.setLayoutParams(paramsL);
-    LinearLayout layoutMid = new LinearLayout(act);
-    layoutMid.setLayoutParams(paramsM);
-    LinearLayout layoutRight = new LinearLayout(act);
-    layoutRight.setLayoutParams(paramsR);
+    LinearLayout layoutBL = new LinearLayout(act);
+    layoutBL.setLayoutParams(pBL);
+    LinearLayout layoutBM = new LinearLayout(act);
+    layoutBM.setLayoutParams(pBM);
+    LinearLayout layoutBR = new LinearLayout(act);
+    layoutBR.setLayoutParams(pBR);
 
-    layoutLeft.addView(mPrevButton);
-    layoutLeft.addView(mMovesText);
-    layoutLeft.addView(mNextButton);
+    layoutBL.addView(mPrevButton);
+    layoutBL.addView(mMovesText);
+    layoutBL.addView(mNextButton);
 
     setupBackButton(act);
 
-    layoutRight.addView(mBackButton);
+    layoutBR.addView(mBackButton);
 
-    layoutBot.addView(layoutLeft);
-    layoutBot.addView(layoutMid);
-    layoutBot.addView(layoutRight);
+    layoutBot.addView(layoutBL);
+    layoutBot.addView(layoutBM);
+    layoutBot.addView(layoutBR);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
+  private void showDialog(final PatternActivity act)
+    {
     Bundle bundle = new Bundle();
     bundle.putString("argument",RubikObjectList.getCurrentName());
     RubikDialogPatternSingle diag = new RubikDialogPatternSingle();
@@ -110,6 +132,59 @@ public class ScreenPattern extends ScreenAbstract
     diag.show( act.getSupportFragmentManager(), RubikDialogPatternSingle.getDialogTag() );
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void setupPrevPatt(final PatternActivity act)
+    {
+    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
+    mPrevPatt = new TransparentImageButton(act,R.drawable.ui_left,params);
+
+    mPrevPatt.setOnClickListener( new View.OnClickListener()
+      {
+      @Override
+      public void onClick(View v)
+        {
+        if( mPatternOrdinal<0 ) showDialog(act);
+        else prevPattern(act);
+        }
+      });
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void setupNextPatt(final PatternActivity act)
+    {
+    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
+    mNextPatt = new TransparentImageButton(act,R.drawable.ui_right,params);
+
+    mNextPatt.setOnClickListener( new View.OnClickListener()
+      {
+      @Override
+      public void onClick(View v)
+        {
+        if( mPatternOrdinal<0 ) showDialog(act);
+        else nextPattern(act);
+        }
+      });
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void setupTextButton(final PatternActivity act, float width)
+    {
+    float textSize = width*PatternActivity.TITLE_TEXT_SIZE;
+    mTextButton = new TransparentButton(act,R.string.choose_pattern,textSize);
+
+    mTextButton.setOnClickListener( new View.OnClickListener()
+      {
+      @Override
+      public void onClick(View v)
+        {
+        showDialog(act);
+        }
+      });
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private void setupBackButton(final PatternActivity act)
@@ -139,11 +214,14 @@ public class ScreenPattern extends ScreenAbstract
       @Override
       public void onClick(View v)
         {
-        RubikPattern pattern = RubikPattern.getInstance();
-        ObjectControl control = act.getControl();
-        pattern.backMove( control, mPatternOrdinal, mCategory, mPattern);
-        int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
-        mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
+        if( mPatternOrdinal>=0 )
+          {
+          RubikPattern pattern = RubikPattern.getInstance();
+          ObjectControl control = act.getControl();
+          pattern.backMove(control, mPatternOrdinal, mCategory, mPattern);
+          int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
+          mMovesText.setText(act.getString(R.string.mo_placeholder, currMove, mNumMoves));
+          }
         }
       });
     }
@@ -160,11 +238,14 @@ public class ScreenPattern extends ScreenAbstract
       @Override
       public void onClick(View v)
         {
-        RubikPattern pattern = RubikPattern.getInstance();
-        ObjectControl control = act.getControl();
-        pattern.makeMove( control, mPatternOrdinal, mCategory, mPattern);
-        int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
-        mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
+        if( mPatternOrdinal>=0 )
+          {
+          RubikPattern pattern = RubikPattern.getInstance();
+          ObjectControl control = act.getControl();
+          pattern.makeMove(control, mPatternOrdinal, mCategory, mPattern);
+          int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
+          mMovesText.setText(act.getString(R.string.mo_placeholder, currMove, mNumMoves));
+          }
         }
       });
     }
@@ -201,7 +282,7 @@ public class ScreenPattern extends ScreenAbstract
 
     RubikPattern patt = RubikPattern.getInstance();
     String patternName = patt.getPatternName(ordinal,category,pattern);
-    mText.setText(patternName);
+    mTextButton.setText(patternName);
 
     mNumMoves   = patt.getNumMoves(ordinal,category,pattern);
     int currMove= patt.getCurMove(ordinal,category,pattern);
@@ -209,6 +290,66 @@ public class ScreenPattern extends ScreenAbstract
     mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void prevPattern(final PatternActivity act)
+    {
+    RubikPattern patt = RubikPattern.getInstance();
+
+    if( mPattern>0 )
+      {
+      setPattern(act,mPatternOrdinal,mCategory,mPattern-1);
+      }
+    else
+      {
+      if( mCategory>0 )
+        {
+        int numPat = patt.getNumPatterns(mPatternOrdinal,mCategory-1);
+        setPattern(act,mPatternOrdinal,mCategory-1,numPat-1);
+        }
+      else
+        {
+        int numCat = patt.getNumCategories(mPatternOrdinal);
+        int numPat = patt.getNumPatterns(mPatternOrdinal,numCat-1);
+        setPattern(act,mPatternOrdinal,numCat-1,numPat-1);
+        }
+      }
+
+    int[][] moves = patt.reInitialize(mPatternOrdinal, mCategory, mPattern);
+    ObjectControl control = act.getControl();
+    if( control!=null ) control.initializeObject(moves);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void nextPattern(final PatternActivity act)
+    {
+    RubikPattern patt = RubikPattern.getInstance();
+    int numPat = patt.getNumPatterns(mPatternOrdinal,mCategory);
+
+    if( mPattern<numPat-1 )
+      {
+      setPattern(act,mPatternOrdinal,mCategory,mPattern+1);
+      }
+    else
+      {
+      int numCat = patt.getNumCategories(mPatternOrdinal);
+
+      if( mCategory<numCat-1 )
+        {
+        setPattern(act,mPatternOrdinal,mCategory+1,0);
+        }
+      else
+        {
+        setPattern(act,mPatternOrdinal,0,0);
+        }
+      }
+
+    int[][] moves = patt.reInitialize(mPatternOrdinal, mCategory, mPattern);
+    ObjectControl control = act.getControl();
+    if( control!=null ) control.initializeObject(moves);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void savePreferences(SharedPreferences.Editor editor)
diff --git a/src/main/res/layout/dialog_pattern_single.xml b/src/main/res/layout/dialog_pattern_single.xml
new file mode 100644
index 00000000..07c22448
--- /dev/null
+++ b/src/main/res/layout/dialog_pattern_single.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:gravity="center"
+    android:orientation="horizontal"
+    android:background="@android:color/transparent">
+
+    <ExpandableListView
+        android:id="@+id/patternListView"
+        android:background="@color/grey"
+        android:layout_marginLeft="10dp"
+        android:layout_marginRight="10dp"
+        android:layout_marginBottom="10dp"
+        android:paddingLeft="5dp"
+        android:paddingRight="5dp"
+        android:paddingTop="10dp"
+        android:paddingBottom="10dp"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"/>
+</LinearLayout>
