Project

General

Profile

« Previous | Next » 

Revision f53016ac

Added by Leszek Koltunski over 2 years ago

Lots of progress with the main screen

View differences:

distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanActivity.java
19 19

  
20 20
package org.distorted.sokoban;
21 21

  
22
import android.app.ListActivity;
22
import android.app.Activity;
23 23
import android.os.Build;
24 24
import android.os.Bundle;
25 25
import android.util.DisplayMetrics;
......
29 29
import android.view.ViewGroup;
30 30
import android.view.WindowManager;
31 31
import android.widget.AdapterView;
32
import android.widget.GridView;
32 33
import android.widget.LinearLayout;
33
import android.widget.SimpleAdapter;
34 34
import android.widget.TextView;
35 35

  
36
import java.util.ArrayList;
37
import java.util.HashMap;
38
import java.util.List;
39
import java.util.Map;
40

  
41 36
import helpers.TransparentImageButton;
42 37

  
43 38
///////////////////////////////////////////////////////////////////////////////////////////////////
44 39

  
45
public class SokobanActivity extends ListActivity
40
public class SokobanActivity extends Activity
46 41
  {
47
  private static final String L_NUMBER = "lNumber";
48
  private static final String L_RECORD = "lRecord";
49
  private static final String L_IMAGE  = "lImage";
50
  private static final String R_NUMBER = "rNumber";
51
  private static final String R_RECORD = "rRecord";
52
  private static final String R_IMAGE  = "rImage";
53

  
54 42
  private static final float RATIO_BAR    = 0.10f;
55 43
  private static final float RATIO_INSET  = 0.09f;
56 44
  private static final float MENU_SIZE    = 0.05f;
......
128 116
  public void onResume()
129 117
    {
130 118
    super.onResume();
131
    createListOfLevels();
119

  
120
    GridView gridview = findViewById(R.id.gridview);
121
    gridview.setAdapter(new SokobanGridAdapter(this));
122

  
123
    gridview.setOnItemClickListener(new AdapterView.OnItemClickListener()
124
      {
125
      @Override
126
      public void onItemClick(AdapterView<?> parent, View v, int position, long id)
127
        {
128
        android.util.Log.e("D", "position="+position);
129
        }
130
      });
132 131
    }
133 132

  
134 133
///////////////////////////////////////////////////////////////////////////////////////////////////
......
292 291
      default: return huge;
293 292
      }
294 293
    }
295

  
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

  
298
  private void createListOfLevels()
299
    {
300
    /*
301
    final List<Map<String, Object>> data = new ArrayList<>();
302

  
303
    int index=0;
304

  
305
    for( Application app : Application.values() )
306
      {
307
      final Map<String, Object> item = new HashMap<>();
308
      item.put(ITEM_IMAGE, app.icon);
309
      item.put(ITEM_TITLE, (index+1)+". "+getText(app.title));
310
      item.put(ITEM_SUBTITLE, getText(app.subtitle));
311
      data.add(item);
312
      }
313

  
314
    final SimpleAdapter dataAdapter = new SimpleAdapter( this,
315
                                                         data,
316
                                                         R.layout.toc_item,
317
                                                         new String[] {L_NUMBER, L_RECORD, L_IMAGE, R_NUMBER, R_RECORD, R_IMAGE},
318
                                                         new int[] {R.id.leftNumber , R.id.leftRecord , R.id.leftImage ,
319
                                                                    R.id.rightNumber, R.id.rightRecord, R.id.rightImage,}  );
320
    setListAdapter(dataAdapter);
321

  
322
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener()
323
      {
324
      @Override
325
      public void onItemClick(AdapterView<?> parent, View view, int position, long id)
326
        {
327
        android.util.Log.e("D","id="+id+" position="+position+" clicked!!");
328
        }
329
      });
330

  
331
     */
332
    }
333 294
  }
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanGridAdapter.java
1
package org.distorted.sokoban;
2

  
3
import android.content.Context;
4

  
5
import android.util.TypedValue;
6
import android.view.LayoutInflater;
7
import android.view.View;
8
import android.view.ViewGroup;
9

  
10
import android.widget.BaseAdapter;
11
import android.widget.GridView;
12
import android.widget.ImageView;
13
import android.widget.LinearLayout;
14
import android.widget.RelativeLayout;
15
import android.widget.TextView;
16

  
17
import java.lang.ref.WeakReference;
18

  
19
///////////////////////////////////////////////////////////////////
20

  
21
public class SokobanGridAdapter extends BaseAdapter
22
{
23
   private final WeakReference<SokobanActivity> mAct;
24
   private final int mHSize, mVSize, mImgSize, mVRelSize;
25
   private final int mGap;
26

  
27
///////////////////////////////////////////////////////////////////
28

  
29
   public SokobanGridAdapter(SokobanActivity act)
30
     {
31
     mAct = new WeakReference<>(act);
32

  
33
     final float GAP   = 0.015f;
34
     final float VREL  = 0.090f;
35
     final float HSIZE = 0.500f;
36

  
37
     final float IMG   = HSIZE-2*GAP;
38
     final float VSIZE = 2*GAP+VREL+IMG;
39

  
40
     int width = act.getScreenWidthInPixels();
41
     mHSize   = (int)(HSIZE*width);
42
     mVSize   = (int)(VSIZE*width);
43
     mImgSize = (int)(IMG*width);
44
     mVRelSize= (int)(VREL*width);
45
     mGap     = (int)(GAP*width);
46
     }
47

  
48
///////////////////////////////////////////////////////////////////
49

  
50
   public int getCount()
51
     {
52
     return SokobanLevels.getNumLevels();
53
     }
54

  
55
///////////////////////////////////////////////////////////////////
56

  
57
   public Object getItem(int position)
58
     {
59
     return null;
60
     }
61

  
62
///////////////////////////////////////////////////////////////////
63

  
64
   public long getItemId(int position)
65
     {
66
     return 0;
67
     }
68

  
69
///////////////////////////////////////////////////////////////////
70

  
71
   public View getView(int position, View convertView, ViewGroup parent)
72
     {
73
     LinearLayout levelView;
74

  
75
     if( convertView==null )
76
       {
77
       SokobanActivity act = mAct.get();
78
       LayoutInflater layoutInflater = act.getLayoutInflater();
79
       levelView = (LinearLayout)layoutInflater.inflate(R.layout.grid_item,null);
80
       levelView.setLayoutParams(new GridView.LayoutParams(mHSize,mVSize));
81
       levelView.setPadding(mGap,mGap,mGap,mGap);
82

  
83
       RelativeLayout rel = levelView.findViewById(R.id.gridRelative);
84
       rel.setLayoutParams(new LinearLayout.LayoutParams(mImgSize,mVRelSize));
85
       ImageView image = levelView.findViewById(R.id.gridImage);
86
       image.setLayoutParams(new LinearLayout.LayoutParams(mImgSize,mImgSize));
87

  
88
       TextView number = levelView.findViewById(R.id.gridNumber);
89
       TextView record = levelView.findViewById(R.id.gridRecord);
90

  
91
       int size = (int)(mVRelSize*0.6f);
92
       number.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
93
       record.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
94
       }
95
     else
96
       {
97
       levelView = (LinearLayout) convertView;
98
       }
99

  
100
     SokobanLevel level = SokobanLevels.getLevel(position);
101

  
102
     if( level!=null )
103
       {
104
       TextView number = levelView.findViewById(R.id.gridNumber);
105
       number.setText( String.valueOf(position+1) );
106
       TextView record = levelView.findViewById(R.id.gridRecord);
107
       record.setText( level.getMyRecord() );
108
       ImageView image = levelView.findViewById(R.id.gridImage);
109
       image.setImageResource( level.getImage() );
110
       }
111

  
112
     return levelView;
113
     }
114

  
115
///////////////////////////////////////////////////////////////////
116

  
117
}
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevel.java
133 133
      decodeLevel(cols,position);
134 134
  }
135 135

  
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

  
138
  public int getImage()
139
    {
140
    return R.drawable.unknown_icon;
141
    }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

  
145
  public String getMyRecord()
146
    {
147
    return "33m 21s";
148
    }
149

  
136 150
///////////////////////////////////////////////////////////////////////////////////////////////////
137 151

  
138 152
  public void allocate(int width,int height, int gap)
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevels.java
960 960
      {
961 961
      int nDrag = mVertical ? y:x;
962 962
 
963
      if( mSpringing==false ) mScrollSpeed = amountDrag-nDrag;
963
      if( !mSpringing ) mScrollSpeed = amountDrag-nDrag;
964 964
      amountDrag = nDrag;
965 965
      
966 966
      scroll();
......
1126 1126

  
1127 1127
      if( currMoves%100==0 ) SokobanCanvas.getMenu().updatePlayState();
1128 1128

  
1129
      if( timerRunning==false ) startTimer(0);
1129
      if( !timerRunning ) startTimer(0);
1130 1130

  
1131 1131
      if( sl.isSolved() )
1132 1132
        {
distorted-sokoban/src/main/res/layout/grid_item.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout
3
	xmlns:android="http://schemas.android.com/apk/res/android"
4
    android:layout_width="match_parent"
5
    android:layout_height="wrap_content"
6
 	android:orientation="vertical"
7
 	android:layout_gravity="center_horizontal">
8

  
9
 	<RelativeLayout
10
 	    android:id="@+id/gridRelative"
11
	    android:layout_width="match_parent"
12
	    android:layout_height="30dp"
13
	    android:orientation="horizontal"
14
	    android:background="@color/dark_grey"
15
	    android:paddingTop="4dp"
16
	    android:paddingBottom="4dp"
17
	    android:layout_gravity="center_vertical">
18

  
19
		<TextView
20
    		android:id="@+id/gridNumber"
21
    		android:layout_width="wrap_content"
22
    	    android:layout_height="wrap_content"
23
    	    android:layout_alignParentStart="true"
24
    	    android:textStyle="bold"/>
25
   		<TextView
26
    	    android:id="@+id/gridRecord"
27
    		android:layout_width="wrap_content"
28
    		android:layout_height="wrap_content"
29
    		android:layout_alignParentEnd="true"
30
    		android:textStyle="bold"/>
31
    </RelativeLayout>
32

  
33
   	<ImageView
34
   		android:id="@+id/gridImage"
35
   		android:layout_width="wrap_content"
36
   		android:layout_height="wrap_content"
37
   		android:contentDescription="@string/level_image"/>
38
</LinearLayout>
distorted-sokoban/src/main/res/layout/main.xml
17 17
        android:layout_width="match_parent"
18 18
        android:layout_height="50dp"/>
19 19

  
20
    <ListView
21
     	android:id="@android:id/list"
22
        android:layout_width="match_parent"
23
        android:layout_height="match_parent"/>
20
    <GridView
21
        android:id="@+id/gridview"
22
        android:layout_width="fill_parent"
23
        android:layout_height="fill_parent"
24
        android:numColumns="2"
25
        android:verticalSpacing="10dp"
26
        android:horizontalSpacing="10dp"
27
        android:stretchMode="columnWidth"
28
        android:gravity="center_horizontal"/>
24 29
 </LinearLayout>
distorted-sokoban/src/main/res/layout/toc_item.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout
3
	xmlns:android="http://schemas.android.com/apk/res/android"
4
	android:layout_width="match_parent"	
5
	android:layout_height="wrap_content"
6
	android:baselineAligned="false"
7
	android:orientation="horizontal"
8
	android:paddingTop="4dp"
9
	android:paddingBottom="4dp">
10

  
11
   	<LinearLayout
12
   		android:layout_width="0dp"
13
 		android:layout_height="wrap_content"
14
 		android:layout_weight="1"
15
 		android:orientation="vertical"
16
 		android:layout_gravity="center_vertical">
17

  
18
 		<LinearLayout
19
	        android:layout_width="match_parent"
20
	        android:layout_height="wrap_content"
21
	        android:orientation="horizontal"
22
	        android:paddingTop="4dp"
23
	        android:paddingBottom="4dp">
24

  
25
		    <TextView
26
    		    android:id="@+id/leftNumber"
27
    		    android:layout_width="match_parent"
28
    		    android:layout_height="wrap_content"
29
    		    android:textStyle="bold"/>
30
   		    <TextView
31
    		    android:id="@+id/leftRecord"
32
    		    android:layout_width="wrap_content"
33
    		    android:layout_height="wrap_content"/>
34
    	</LinearLayout>
35

  
36
   	    <ImageView
37
   		    android:id="@+id/leftImage"
38
   		    android:layout_width="wrap_content"
39
   		    android:layout_height="wrap_content"
40
   		    android:contentDescription="@string/level_image"
41
   		    android:layout_margin="8dp"
42
   		    android:background="@drawable/icon_border"/>
43
	</LinearLayout>
44
	<LinearLayout
45
   		android:layout_width="0dp"
46
 		android:layout_height="wrap_content"
47
 		android:layout_weight="1"
48
 		android:orientation="vertical"
49
 		android:layout_gravity="center_vertical">
50

  
51
 		<LinearLayout
52
	        android:layout_width="match_parent"
53
	        android:layout_height="wrap_content"
54
	        android:orientation="horizontal"
55
	        android:paddingTop="4dp"
56
	        android:paddingBottom="4dp">
57

  
58
		    <TextView
59
    		    android:id="@+id/rightNumber"
60
    		    android:layout_width="match_parent"
61
    		    android:layout_height="wrap_content"
62
    		    android:textStyle="bold"/>
63
   		    <TextView
64
    		    android:id="@+id/rightRecord"
65
    		    android:layout_width="wrap_content"
66
    		    android:layout_height="wrap_content"/>
67
    	</LinearLayout>
68

  
69
   	    <ImageView
70
   		    android:id="@+id/rightImage"
71
   		    android:layout_width="wrap_content"
72
   		    android:layout_height="wrap_content"
73
   		    android:contentDescription="@string/level_image"
74
   		    android:layout_margin="8dp"
75
   		    android:background="@drawable/icon_border"/>
76
 	</LinearLayout>    
77
</LinearLayout>

Also available in: Unified diff