Revision 1f6d1786
Added by Leszek Koltunski almost 2 years ago
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanActivity.java | ||
---|---|---|
28 | 28 |
import android.view.View; |
29 | 29 |
import android.view.ViewGroup; |
30 | 30 |
import android.view.WindowManager; |
31 |
import android.widget.AdapterView; |
|
31 | 32 |
import android.widget.LinearLayout; |
33 |
import android.widget.SimpleAdapter; |
|
32 | 34 |
import android.widget.TextView; |
33 | 35 |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.HashMap; |
|
38 |
import java.util.List; |
|
39 |
import java.util.Map; |
|
40 |
|
|
34 | 41 |
import helpers.TransparentImageButton; |
35 | 42 |
|
36 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
37 | 44 |
|
38 | 45 |
public class SokobanActivity extends ListActivity |
39 | 46 |
{ |
40 |
private static final String ITEM_IMAGE = "item_image"; |
|
41 |
private static final String ITEM_TITLE = "item_title"; |
|
42 |
private static final String ITEM_SUBTITLE = "item_subtitle"; |
|
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"; |
|
43 | 53 |
|
44 | 54 |
private static final float RATIO_BAR = 0.10f; |
45 | 55 |
private static final float RATIO_INSET = 0.09f; |
... | ... | |
78 | 88 |
|
79 | 89 |
LinearLayout upper = findViewById(R.id.upper_layout); |
80 | 90 |
createUpperLayout(upper); |
81 |
|
|
82 |
/* |
|
83 |
final List<Map<String, Object>> data = new ArrayList<>(); |
|
84 |
final SparseArray<Class<? extends Activity>> activityMapping = new SparseArray<>(); |
|
85 |
|
|
86 |
int index=0; |
|
87 |
|
|
88 |
for( Application app : Application.values() ) |
|
89 |
{ |
|
90 |
final Map<String, Object> item = new HashMap<>(); |
|
91 |
item.put(ITEM_IMAGE, app.icon); |
|
92 |
item.put(ITEM_TITLE, (index+1)+". "+getText(app.title)); |
|
93 |
item.put(ITEM_SUBTITLE, getText(app.subtitle)); |
|
94 |
data.add(item); |
|
95 |
activityMapping.put(index++, app.activity); |
|
96 |
} |
|
97 |
|
|
98 |
final SimpleAdapter dataAdapter = new SimpleAdapter( this, |
|
99 |
data, |
|
100 |
R.layout.toc_item, |
|
101 |
new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, |
|
102 |
new int[] {R.id.Image, R.id.Title, R.id.SubTitle} ); |
|
103 |
setListAdapter(dataAdapter); |
|
104 |
|
|
105 |
getListView().setOnItemClickListener(new OnItemClickListener() |
|
106 |
{ |
|
107 |
@Override |
|
108 |
public void onItemClick(AdapterView<?> parent, View view, int position, long id) |
|
109 |
{ |
|
110 |
final Class<? extends Activity> activityToLaunch = activityMapping.get(position); |
|
111 |
|
|
112 |
if (activityToLaunch != null) |
|
113 |
{ |
|
114 |
final Intent launchIntent = new Intent(SokobanActivity.this, activityToLaunch); |
|
115 |
startActivity(launchIntent); |
|
116 |
} |
|
117 |
} |
|
118 |
}); |
|
119 |
|
|
120 |
*/ |
|
121 | 91 |
} |
122 | 92 |
|
123 | 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
152 | 122 |
} |
153 | 123 |
} |
154 | 124 |
|
125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
126 |
|
|
127 |
@Override |
|
128 |
public void onResume() |
|
129 |
{ |
|
130 |
super.onResume(); |
|
131 |
createListOfLevels(); |
|
132 |
} |
|
133 |
|
|
134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
135 |
|
|
136 |
@Override |
|
137 |
public void onPause() |
|
138 |
{ |
|
139 |
super.onPause(); |
|
140 |
} |
|
141 |
|
|
155 | 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
156 | 143 |
|
157 | 144 |
private void createUpperLayout(LinearLayout upper) |
... | ... | |
305 | 292 |
default: return huge; |
306 | 293 |
} |
307 | 294 |
} |
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 |
} |
|
308 | 333 |
} |
Also available in: Unified diff
Lots of progress with the main screen