commit f53016ac7572b752a5889e3c34760d287e176fdb
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Jul 19 22:55:19 2022 +0200

    Lots of progress with the main screen

diff --git a/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanActivity.java b/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanActivity.java
index 0690ab9..3d4175d 100644
--- a/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanActivity.java
+++ b/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanActivity.java
@@ -19,7 +19,7 @@
 
 package org.distorted.sokoban;
 
-import android.app.ListActivity;
+import android.app.Activity;
 import android.os.Build;
 import android.os.Bundle;
 import android.util.DisplayMetrics;
@@ -29,28 +29,16 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.WindowManager;
 import android.widget.AdapterView;
+import android.widget.GridView;
 import android.widget.LinearLayout;
-import android.widget.SimpleAdapter;
 import android.widget.TextView;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import helpers.TransparentImageButton;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-public class SokobanActivity extends ListActivity
+public class SokobanActivity extends Activity
   {
-  private static final String L_NUMBER = "lNumber";
-  private static final String L_RECORD = "lRecord";
-  private static final String L_IMAGE  = "lImage";
-  private static final String R_NUMBER = "rNumber";
-  private static final String R_RECORD = "rRecord";
-  private static final String R_IMAGE  = "rImage";
-
   private static final float RATIO_BAR    = 0.10f;
   private static final float RATIO_INSET  = 0.09f;
   private static final float MENU_SIZE    = 0.05f;
@@ -128,7 +116,18 @@ public class SokobanActivity extends ListActivity
   public void onResume()
     {
     super.onResume();
-    createListOfLevels();
+
+    GridView gridview = findViewById(R.id.gridview);
+    gridview.setAdapter(new SokobanGridAdapter(this));
+
+    gridview.setOnItemClickListener(new AdapterView.OnItemClickListener()
+      {
+      @Override
+      public void onItemClick(AdapterView<?> parent, View v, int position, long id)
+        {
+        android.util.Log.e("D", "position="+position);
+        }
+      });
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -292,42 +291,4 @@ public class SokobanActivity extends ListActivity
       default: return huge;
       }
     }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private void createListOfLevels()
-    {
-    /*
-    final List<Map<String, Object>> data = new ArrayList<>();
-
-    int index=0;
-
-    for( Application app : Application.values() )
-      {
-      final Map<String, Object> item = new HashMap<>();
-      item.put(ITEM_IMAGE, app.icon);
-      item.put(ITEM_TITLE, (index+1)+". "+getText(app.title));
-      item.put(ITEM_SUBTITLE, getText(app.subtitle));
-      data.add(item);
-      }
-
-    final SimpleAdapter dataAdapter = new SimpleAdapter( this,
-                                                         data,
-                                                         R.layout.toc_item,
-                                                         new String[] {L_NUMBER, L_RECORD, L_IMAGE, R_NUMBER, R_RECORD, R_IMAGE},
-                                                         new int[] {R.id.leftNumber , R.id.leftRecord , R.id.leftImage ,
-                                                                    R.id.rightNumber, R.id.rightRecord, R.id.rightImage,}  );
-    setListAdapter(dataAdapter);
-
-    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener()
-      {
-      @Override
-      public void onItemClick(AdapterView<?> parent, View view, int position, long id)
-        {
-        android.util.Log.e("D","id="+id+" position="+position+" clicked!!");
-        }
-      });
-
-     */
-    }
   }
diff --git a/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanGridAdapter.java b/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanGridAdapter.java
new file mode 100644
index 0000000..038c36a
--- /dev/null
+++ b/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanGridAdapter.java
@@ -0,0 +1,117 @@
+package org.distorted.sokoban;
+
+import android.content.Context;
+
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import android.widget.BaseAdapter;
+import android.widget.GridView;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import java.lang.ref.WeakReference;
+
+///////////////////////////////////////////////////////////////////
+
+public class SokobanGridAdapter extends BaseAdapter
+{
+   private final WeakReference<SokobanActivity> mAct;
+   private final int mHSize, mVSize, mImgSize, mVRelSize;
+   private final int mGap;
+
+///////////////////////////////////////////////////////////////////
+
+   public SokobanGridAdapter(SokobanActivity act)
+     {
+     mAct = new WeakReference<>(act);
+
+     final float GAP   = 0.015f;
+     final float VREL  = 0.090f;
+     final float HSIZE = 0.500f;
+
+     final float IMG   = HSIZE-2*GAP;
+     final float VSIZE = 2*GAP+VREL+IMG;
+
+     int width = act.getScreenWidthInPixels();
+     mHSize   = (int)(HSIZE*width);
+     mVSize   = (int)(VSIZE*width);
+     mImgSize = (int)(IMG*width);
+     mVRelSize= (int)(VREL*width);
+     mGap     = (int)(GAP*width);
+     }
+
+///////////////////////////////////////////////////////////////////
+
+   public int getCount()
+     {
+     return SokobanLevels.getNumLevels();
+     }
+
+///////////////////////////////////////////////////////////////////
+
+   public Object getItem(int position)
+     {
+     return null;
+     }
+
+///////////////////////////////////////////////////////////////////
+
+   public long getItemId(int position)
+     {
+     return 0;
+     }
+
+///////////////////////////////////////////////////////////////////
+
+   public View getView(int position, View convertView, ViewGroup parent)
+     {
+     LinearLayout levelView;
+
+     if( convertView==null )
+       {
+       SokobanActivity act = mAct.get();
+       LayoutInflater layoutInflater = act.getLayoutInflater();
+       levelView = (LinearLayout)layoutInflater.inflate(R.layout.grid_item,null);
+       levelView.setLayoutParams(new GridView.LayoutParams(mHSize,mVSize));
+       levelView.setPadding(mGap,mGap,mGap,mGap);
+
+       RelativeLayout rel = levelView.findViewById(R.id.gridRelative);
+       rel.setLayoutParams(new LinearLayout.LayoutParams(mImgSize,mVRelSize));
+       ImageView image = levelView.findViewById(R.id.gridImage);
+       image.setLayoutParams(new LinearLayout.LayoutParams(mImgSize,mImgSize));
+
+       TextView number = levelView.findViewById(R.id.gridNumber);
+       TextView record = levelView.findViewById(R.id.gridRecord);
+
+       int size = (int)(mVRelSize*0.6f);
+       number.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
+       record.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
+       }
+     else
+       {
+       levelView = (LinearLayout) convertView;
+       }
+
+     SokobanLevel level = SokobanLevels.getLevel(position);
+
+     if( level!=null )
+       {
+       TextView number = levelView.findViewById(R.id.gridNumber);
+       number.setText( String.valueOf(position+1) );
+       TextView record = levelView.findViewById(R.id.gridRecord);
+       record.setText( level.getMyRecord() );
+       ImageView image = levelView.findViewById(R.id.gridImage);
+       image.setImageResource( level.getImage() );
+       }
+
+     return levelView;
+     }
+
+///////////////////////////////////////////////////////////////////
+
+}
diff --git a/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevel.java b/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevel.java
index f204bc8..8d4bed1 100644
--- a/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevel.java
+++ b/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevel.java
@@ -133,6 +133,20 @@ public class SokobanLevel
       decodeLevel(cols,position);
   }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int getImage()
+    {
+    return R.drawable.unknown_icon;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public String getMyRecord()
+    {
+    return "33m 21s";
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void allocate(int width,int height, int gap)
diff --git a/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevels.java b/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevels.java
index 1ad8c17..1fe2412 100644
--- a/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevels.java
+++ b/distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevels.java
@@ -960,7 +960,7 @@ public class SokobanLevels
       {
       int nDrag = mVertical ? y:x;
  
-      if( mSpringing==false ) mScrollSpeed = amountDrag-nDrag;
+      if( !mSpringing ) mScrollSpeed = amountDrag-nDrag;
       amountDrag = nDrag;
       
       scroll();
@@ -1126,7 +1126,7 @@ public class SokobanLevels
 
       if( currMoves%100==0 ) SokobanCanvas.getMenu().updatePlayState();
 
-      if( timerRunning==false ) startTimer(0);
+      if( !timerRunning ) startTimer(0);
 
       if( sl.isSolved() )
         {
diff --git a/distorted-sokoban/src/main/res/drawable/unknown_icon.png b/distorted-sokoban/src/main/res/drawable/unknown_icon.png
new file mode 100644
index 0000000..e6359c6
Binary files /dev/null and b/distorted-sokoban/src/main/res/drawable/unknown_icon.png differ
diff --git a/distorted-sokoban/src/main/res/layout/grid_item.xml b/distorted-sokoban/src/main/res/layout/grid_item.xml
new file mode 100644
index 0000000..c0b5f8b
--- /dev/null
+++ b/distorted-sokoban/src/main/res/layout/grid_item.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+	xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+ 	android:orientation="vertical"
+ 	android:layout_gravity="center_horizontal">
+
+ 	<RelativeLayout
+ 	    android:id="@+id/gridRelative"
+	    android:layout_width="match_parent"
+	    android:layout_height="30dp"
+	    android:orientation="horizontal"
+	    android:background="@color/dark_grey"
+	    android:paddingTop="4dp"
+	    android:paddingBottom="4dp"
+	    android:layout_gravity="center_vertical">
+
+		<TextView
+    		android:id="@+id/gridNumber"
+    		android:layout_width="wrap_content"
+    	    android:layout_height="wrap_content"
+    	    android:layout_alignParentStart="true"
+    	    android:textStyle="bold"/>
+   		<TextView
+    	    android:id="@+id/gridRecord"
+    		android:layout_width="wrap_content"
+    		android:layout_height="wrap_content"
+    		android:layout_alignParentEnd="true"
+    		android:textStyle="bold"/>
+    </RelativeLayout>
+
+   	<ImageView
+   		android:id="@+id/gridImage"
+   		android:layout_width="wrap_content"
+   		android:layout_height="wrap_content"
+   		android:contentDescription="@string/level_image"/>
+</LinearLayout>
diff --git a/distorted-sokoban/src/main/res/layout/main.xml b/distorted-sokoban/src/main/res/layout/main.xml
index 9cd14c9..b60dd2b 100644
--- a/distorted-sokoban/src/main/res/layout/main.xml
+++ b/distorted-sokoban/src/main/res/layout/main.xml
@@ -17,8 +17,13 @@
         android:layout_width="match_parent"
         android:layout_height="50dp"/>
 
-    <ListView
-     	android:id="@android:id/list"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"/>
+    <GridView
+        android:id="@+id/gridview"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:numColumns="2"
+        android:verticalSpacing="10dp"
+        android:horizontalSpacing="10dp"
+        android:stretchMode="columnWidth"
+        android:gravity="center_horizontal"/>
  </LinearLayout>
diff --git a/distorted-sokoban/src/main/res/layout/toc_item.xml b/distorted-sokoban/src/main/res/layout/toc_item.xml
deleted file mode 100644
index 74e8a25..0000000
--- a/distorted-sokoban/src/main/res/layout/toc_item.xml
+++ /dev/null
@@ -1,77 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout
-	xmlns:android="http://schemas.android.com/apk/res/android"
-	android:layout_width="match_parent"	
-	android:layout_height="wrap_content"
-	android:baselineAligned="false"
-	android:orientation="horizontal"
-	android:paddingTop="4dp"
-	android:paddingBottom="4dp">
-
-   	<LinearLayout
-   		android:layout_width="0dp"
- 		android:layout_height="wrap_content"
- 		android:layout_weight="1"
- 		android:orientation="vertical"
- 		android:layout_gravity="center_vertical">
-
- 		<LinearLayout
-	        android:layout_width="match_parent"
-	        android:layout_height="wrap_content"
-	        android:orientation="horizontal"
-	        android:paddingTop="4dp"
-	        android:paddingBottom="4dp">
-
-		    <TextView
-    		    android:id="@+id/leftNumber"
-    		    android:layout_width="match_parent"
-    		    android:layout_height="wrap_content"
-    		    android:textStyle="bold"/>
-   		    <TextView
-    		    android:id="@+id/leftRecord"
-    		    android:layout_width="wrap_content"
-    		    android:layout_height="wrap_content"/>
-    	</LinearLayout>
-
-   	    <ImageView
-   		    android:id="@+id/leftImage"
-   		    android:layout_width="wrap_content"
-   		    android:layout_height="wrap_content"
-   		    android:contentDescription="@string/level_image"
-   		    android:layout_margin="8dp"
-   		    android:background="@drawable/icon_border"/>
-	</LinearLayout>
-	<LinearLayout
-   		android:layout_width="0dp"
- 		android:layout_height="wrap_content"
- 		android:layout_weight="1"
- 		android:orientation="vertical"
- 		android:layout_gravity="center_vertical">
-
- 		<LinearLayout
-	        android:layout_width="match_parent"
-	        android:layout_height="wrap_content"
-	        android:orientation="horizontal"
-	        android:paddingTop="4dp"
-	        android:paddingBottom="4dp">
-
-		    <TextView
-    		    android:id="@+id/rightNumber"
-    		    android:layout_width="match_parent"
-    		    android:layout_height="wrap_content"
-    		    android:textStyle="bold"/>
-   		    <TextView
-    		    android:id="@+id/rightRecord"
-    		    android:layout_width="wrap_content"
-    		    android:layout_height="wrap_content"/>
-    	</LinearLayout>
-
-   	    <ImageView
-   		    android:id="@+id/rightImage"
-   		    android:layout_width="wrap_content"
-   		    android:layout_height="wrap_content"
-   		    android:contentDescription="@string/level_image"
-   		    android:layout_margin="8dp"
-   		    android:background="@drawable/icon_border"/>
- 	</LinearLayout>    
-</LinearLayout>
