Project

General

Profile

Download (12.7 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / TableOfContents.java @ f9afbbf3

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.examples;
21

    
22
import java.util.ArrayList;
23
import java.util.HashMap;
24
import java.util.List;
25
import java.util.Map;
26

    
27
import android.app.Activity;
28
import android.app.ListActivity;
29
import android.content.Intent;
30
import android.os.Bundle;
31
import android.util.SparseArray;
32
import android.view.View;
33
import android.widget.AdapterView;
34
import android.widget.AdapterView.OnItemClickListener;
35
import android.widget.SimpleAdapter;
36

    
37
import org.distorted.examples.monalisa.MonaLisaActivity;
38
import org.distorted.examples.sink.SinkActivity;
39
import org.distorted.examples.fov.FOVActivity;
40
import org.distorted.examples.deform.DeformActivity;
41
import org.distorted.examples.listener.ListenerActivity;
42
import org.distorted.examples.dynamic.DynamicActivity;
43
import org.distorted.examples.girl.GirlActivity;
44
import org.distorted.examples.macroblock.MacroblockActivity;
45
import org.distorted.examples.movingeffects.MovingEffectsActivity;
46
import org.distorted.examples.olimpic.OlimpicActivity;
47
import org.distorted.examples.differenteffects.DifferentEffectsActivity;
48
import org.distorted.examples.differentbitmaps.DifferentBitmapsActivity;
49
import org.distorted.examples.effects2d.Effects2DActivity;
50
import org.distorted.examples.check.CheckActivity;
51
import org.distorted.examples.bean.BeanActivity;
52
import org.distorted.examples.fbo.FBOActivity;
53
import org.distorted.examples.starwars.StarWarsActivity;
54
import org.distorted.examples.cubes.CubesActivity;
55
import org.distorted.examples.quaternion.QuaternionActivity;
56
import org.distorted.examples.effects3d.Effects3DActivity;
57
import org.distorted.examples.plainmonalisa.PlainMonaLisaActivity;
58
import org.distorted.examples.save.SaveActivity;
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
public class TableOfContents extends ListActivity 
63
  {
64
  private static final String ITEM_IMAGE = "item_image";
65
  private static final String ITEM_TITLE = "item_title";
66
  private static final String ITEM_SUBTITLE = "item_subtitle"; 
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
   
70
  @Override
71
  public void onCreate(Bundle savedInstanceState) 
72
   {
73
   super.onCreate(savedInstanceState);
74
   setContentView(R.layout.table_of_contents);
75
      
76
   final List<Map<String, Object>> data = new ArrayList<>();
77
   final SparseArray<Class<? extends Activity>> activityMapping = new SparseArray<>();
78
      
79
   int i = 0;
80
   
81
   {
82
      final Map<String, Object> item = new HashMap<>();
83
      item.put(ITEM_IMAGE, R.drawable.icon_example_monalisa);
84
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_monalisa));
85
      item.put(ITEM_SUBTITLE, getText(R.string.example_monalisa_subtitle));
86
      data.add(item);
87
      activityMapping.put(i++, MonaLisaActivity.class);        
88
   }
89
      
90
   {
91
      final Map<String, Object> item = new HashMap<>();
92
      item.put(ITEM_IMAGE, R.drawable.icon_example_sink);
93
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_sink));
94
      item.put(ITEM_SUBTITLE, getText(R.string.example_sink_subtitle));
95
      data.add(item);
96
      activityMapping.put(i++, SinkActivity.class);
97
   }
98
   
99
   {
100
      final Map<String, Object> item = new HashMap<>();
101
      item.put(ITEM_IMAGE, R.drawable.icon_example_bean);
102
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_bean));
103
      item.put(ITEM_SUBTITLE, getText(R.string.example_bean_subtitle));
104
      data.add(item);
105
      activityMapping.put(i++, BeanActivity.class);
106
   }
107
   
108
   {
109
      final Map<String, Object> item = new HashMap<>();
110
      item.put(ITEM_IMAGE, R.drawable.icon_example_fov);
111
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_fov));
112
      item.put(ITEM_SUBTITLE, getText(R.string.example_fov_subtitle));
113
      data.add(item);
114
      activityMapping.put(i++, FOVActivity.class);
115
   }
116
         
117
   {
118
      final Map<String, Object> item = new HashMap<>();
119
      item.put(ITEM_IMAGE, R.drawable.icon_example_deform);
120
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_deform));
121
      item.put(ITEM_SUBTITLE, getText(R.string.example_deform_subtitle));
122
      data.add(item);
123
      activityMapping.put(i++, DeformActivity.class);
124
   }
125
  
126
   {
127
      final Map<String, Object> item = new HashMap<>();
128
      item.put(ITEM_IMAGE, R.drawable.icon_example_listener);
129
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_listener));
130
      item.put(ITEM_SUBTITLE, getText(R.string.example_listener_subtitle));
131
      data.add(item);
132
      activityMapping.put(i++, ListenerActivity.class);
133
   }
134
   
135
   {
136
      final Map<String, Object> item = new HashMap<>();
137
      item.put(ITEM_IMAGE, R.drawable.icon_example_dynamic);
138
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_dynamic));
139
      item.put(ITEM_SUBTITLE, getText(R.string.example_dynamic_subtitle));
140
      data.add(item);
141
      activityMapping.put(i++, DynamicActivity.class);
142
   }
143
   
144
   {
145
      final Map<String, Object> item = new HashMap<>();
146
      item.put(ITEM_IMAGE, R.drawable.icon_example_girl);
147
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_girl));
148
      item.put(ITEM_SUBTITLE, getText(R.string.example_girl_subtitle));
149
      data.add(item);
150
      activityMapping.put(i++, GirlActivity.class);
151
   }
152
   
153
   {
154
      final Map<String, Object> item = new HashMap<>();
155
      item.put(ITEM_IMAGE, R.drawable.icon_example_macroblock);
156
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_macroblock));
157
      item.put(ITEM_SUBTITLE, getText(R.string.example_macroblock_subtitle));
158
      data.add(item);
159
      activityMapping.put(i++, MacroblockActivity.class);
160
   }
161
   
162
   {
163
      final Map<String, Object> item = new HashMap<>();
164
      item.put(ITEM_IMAGE, R.drawable.icon_example_movingeffects);
165
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_movingeffects));
166
      item.put(ITEM_SUBTITLE, getText(R.string.example_movingeffects_subtitle));
167
      data.add(item);
168
      activityMapping.put(i++, MovingEffectsActivity.class);
169
   }
170
   
171
   {
172
      final Map<String, Object> item = new HashMap<>();
173
      item.put(ITEM_IMAGE, R.drawable.icon_example_differenteffects);
174
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_differenteffects));
175
      item.put(ITEM_SUBTITLE, getText(R.string.example_differenteffects_subtitle));
176
      data.add(item);
177
      activityMapping.put(i++, DifferentEffectsActivity.class);
178
   }
179
   
180
   {
181
      final Map<String, Object> item = new HashMap<>();
182
      item.put(ITEM_IMAGE, R.drawable.icon_example_differentbitmaps);
183
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_differentbitmaps));
184
      item.put(ITEM_SUBTITLE, getText(R.string.example_differentbitmaps_subtitle));
185
      data.add(item);
186
      activityMapping.put(i++, DifferentBitmapsActivity.class);
187
   }
188
   
189
   {
190
      final Map<String, Object> item = new HashMap<>();
191
      item.put(ITEM_IMAGE, R.drawable.icon_example_effects2d);
192
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_effects2d));
193
      item.put(ITEM_SUBTITLE, getText(R.string.example_effects2d_subtitle));
194
      data.add(item);
195
      activityMapping.put(i++, Effects2DActivity.class);
196
   }
197
   
198
   {
199
      final Map<String, Object> item = new HashMap<>();
200
      item.put(ITEM_IMAGE, R.drawable.icon_example_check);
201
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_check));
202
      item.put(ITEM_SUBTITLE, getText(R.string.example_check_subtitle));
203
      data.add(item);
204
      activityMapping.put(i++, CheckActivity.class);
205
   }
206
   
207
   {
208
      final Map<String, Object> item = new HashMap<>();
209
      item.put(ITEM_IMAGE, R.drawable.icon_example_fbo);
210
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_fbo));
211
      item.put(ITEM_SUBTITLE, getText(R.string.example_fbo_subtitle));
212
      data.add(item);
213
      activityMapping.put(i++, FBOActivity.class);
214
   }
215
      
216
   {
217
      final Map<String, Object> item = new HashMap<>();
218
      item.put(ITEM_IMAGE, R.drawable.icon_example_starwars);
219
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_starwars));
220
      item.put(ITEM_SUBTITLE, getText(R.string.example_starwars_subtitle));
221
      data.add(item);
222
      activityMapping.put(i++, StarWarsActivity.class);
223
   }
224
         
225
   {
226
      final Map<String, Object> item = new HashMap<>();
227
      item.put(ITEM_IMAGE, R.drawable.icon_example_olimpic);
228
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_olimpic));
229
      item.put(ITEM_SUBTITLE, getText(R.string.example_olimpic_subtitle));
230
      data.add(item);
231
      activityMapping.put(i++, OlimpicActivity.class);
232
   }
233
   
234
   {
235
      final Map<String, Object> item = new HashMap<>();
236
      item.put(ITEM_IMAGE, R.drawable.icon_example_quaternion);
237
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_quaternion));
238
      item.put(ITEM_SUBTITLE, getText(R.string.example_quaternion_subtitle));
239
      data.add(item);
240
      activityMapping.put(i++, QuaternionActivity.class);
241
   }
242
   
243
   {
244
      final Map<String, Object> item = new HashMap<>();
245
      item.put(ITEM_IMAGE, R.drawable.icon_example_cubes);
246
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_cubes));
247
      item.put(ITEM_SUBTITLE, getText(R.string.example_cubes_subtitle));
248
      data.add(item);
249
      activityMapping.put(i++, CubesActivity.class);
250
   }
251
   
252
   {
253
      final Map<String, Object> item = new HashMap<>();
254
      item.put(ITEM_IMAGE, R.drawable.icon_example_effects3d);
255
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_effects3d));
256
      item.put(ITEM_SUBTITLE, getText(R.string.example_effects3d_subtitle));
257
      data.add(item);
258
      activityMapping.put(i++, Effects3DActivity.class);
259
   }
260

    
261
   {
262
      final Map<String, Object> item = new HashMap<>();
263
      item.put(ITEM_IMAGE, R.drawable.icon_example_monalisa);
264
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_plainmonalisa));
265
      item.put(ITEM_SUBTITLE, getText(R.string.example_plainmonalisa_subtitle));
266
      data.add(item);
267
      activityMapping.put(i++, PlainMonaLisaActivity.class);
268
   }
269

    
270
   {
271
      final Map<String, Object> item = new HashMap<>();
272
      item.put(ITEM_IMAGE, R.drawable.icon_example_girl);
273
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_save));
274
      item.put(ITEM_SUBTITLE, getText(R.string.example_save_subtitle));
275
      data.add(item);
276
      activityMapping.put(i++, SaveActivity.class);
277
   }
278

    
279
   final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle});
280
   setListAdapter(dataAdapter);  
281
      
282
   getListView().setOnItemClickListener(new OnItemClickListener() 
283
     {
284
     @Override
285
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
286
      {
287
      final Class<? extends Activity> activityToLaunch = activityMapping.get(position);
288
            
289
      if (activityToLaunch != null)
290
        {
291
        final Intent launchIntent = new Intent(TableOfContents.this, activityToLaunch);
292
        startActivity(launchIntent);
293
        }            
294
      }
295
     });
296
   }  
297
  }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
    (1-1/1)