Project

General

Profile

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

examples / src / main / java / org / distorted / examples / TableOfContents.java @ 42aa970f

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.deferredjob.DeferredJobActivity;
38
import org.distorted.examples.monalisa.MonaLisaActivity;
39
import org.distorted.examples.sink.SinkActivity;
40
import org.distorted.examples.projection.ProjectionActivity;
41
import org.distorted.examples.deform.DeformActivity;
42
import org.distorted.examples.listener.ListenerActivity;
43
import org.distorted.examples.dynamic.DynamicActivity;
44
import org.distorted.examples.girl.GirlActivity;
45
import org.distorted.examples.catanddog.CatAndDogActivity;
46
import org.distorted.examples.movingeffects.MovingEffectsActivity;
47
import org.distorted.examples.olimpic.OlimpicActivity;
48
import org.distorted.examples.differenteffects.DifferentEffectsActivity;
49
import org.distorted.examples.differentbitmaps.DifferentBitmapsActivity;
50
import org.distorted.examples.effectqueue.EffectQueueActivity;
51
import org.distorted.examples.check.CheckActivity;
52
import org.distorted.examples.bean.BeanActivity;
53
import org.distorted.examples.objecttree.ObjectTreeActivity;
54
import org.distorted.examples.starwars.StarWarsActivity;
55
import org.distorted.examples.inflate.InflateActivity;
56
import org.distorted.examples.quaternion.QuaternionActivity;
57
import org.distorted.examples.generic.GenericActivity;
58
import org.distorted.examples.surfaceview.SurfaceViewActivity;
59
import org.distorted.examples.save.SaveActivity;
60
import org.distorted.examples.flag.FlagActivity;
61
import org.distorted.examples.wind.WindActivity;
62
import org.distorted.examples.aroundtheworld.AroundTheWorldActivity;
63
import org.distorted.examples.mirror.MirrorActivity;
64
import org.distorted.examples.blur.BlurActivity;
65
import org.distorted.examples.multiblur.MultiblurActivity;
66
import org.distorted.examples.triblur.TriblurActivity;
67
import org.distorted.examples.transparency.TransparencyActivity;
68
import org.distorted.examples.postprocesstree.PostprocessTreeActivity;
69
import org.distorted.examples.stencil.StencilActivity;
70
import org.distorted.examples.glow.GlowActivity;
71
import org.distorted.examples.movingglow.MovingGlowActivity;
72
import org.distorted.examples.earth.EarthActivity;
73
import org.distorted.examples.rubik.RubikActivity;
74
import org.distorted.examples.meshjoin.MeshJoinActivity;
75
import org.distorted.examples.predeform.PredeformActivity;
76
import org.distorted.examples.singlemesh.SingleMeshActivity;
77
import org.distorted.examples.meshfile.MeshFileActivity;
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
public class TableOfContents extends ListActivity 
82
  {
83
  private static final String ITEM_IMAGE    = "item_image";
84
  private static final String ITEM_TITLE    = "item_title";
85
  private static final String ITEM_SUBTITLE = "item_subtitle"; 
86

    
87
  private enum Application
88
    {
89
    MONALISA          (R.drawable.icon_example_monalisa        , R.string.example_monalisa        , R.string.example_monalisa_subtitle        ,         MonaLisaActivity.class),
90
    SINK              (R.drawable.icon_example_sink            , R.string.example_sink            , R.string.example_sink_subtitle            ,             SinkActivity.class),
91
    BEAN              (R.drawable.icon_example_bean            , R.string.example_bean            , R.string.example_bean_subtitle            ,             BeanActivity.class),
92
    PROJECTION        (R.drawable.icon_example_projection      , R.string.example_projection      , R.string.example_projection_subtitle      ,       ProjectionActivity.class),
93
    DEFORM            (R.drawable.icon_example_deform          , R.string.example_deform          , R.string.example_deform_subtitle          ,           DeformActivity.class),
94
    LISTENER          (R.drawable.icon_example_listener        , R.string.example_listener        , R.string.example_listener_subtitle        ,         ListenerActivity.class),
95
    DYNAMIC           (R.drawable.icon_example_dynamic         , R.string.example_dynamic         , R.string.example_dynamic_subtitle         ,          DynamicActivity.class),
96
    GIRL              (R.drawable.icon_example_girl            , R.string.example_girl            , R.string.example_girl_subtitle            ,             GirlActivity.class),
97
    CATANDDOG         (R.drawable.icon_example_catanddog       , R.string.example_catanddog       , R.string.example_catanddog_subtitle       ,        CatAndDogActivity.class),
98
    MOVINGEFFECTS     (R.drawable.icon_example_movingeffects   , R.string.example_movingeffects   , R.string.example_movingeffects_subtitle   ,    MovingEffectsActivity.class),
99
    DIFFERENTEFFECTS  (R.drawable.icon_example_differenteffects, R.string.example_differenteffects, R.string.example_differenteffects_subtitle, DifferentEffectsActivity.class),
100
    DIFFERENTBITMAPS  (R.drawable.icon_example_differentbitmaps, R.string.example_differentbitmaps, R.string.example_differentbitmaps_subtitle, DifferentBitmapsActivity.class),
101
    EFFECTQUEUE       (R.drawable.icon_example_effectqueue     , R.string.example_effectqueue     , R.string.example_effectqueue_subtitle     ,      EffectQueueActivity.class),
102
    CHECK             (R.drawable.icon_example_check           , R.string.example_check           , R.string.example_check_subtitle           ,            CheckActivity.class),
103
    OBJECTTREE        (R.drawable.icon_example_objecttree      , R.string.example_objecttree      , R.string.example_objecttree_subtitle      ,       ObjectTreeActivity.class),
104
    STARWARS          (R.drawable.icon_example_starwars        , R.string.example_starwars        , R.string.example_starwars_subtitle        ,         StarWarsActivity.class),
105
    OLIMPIC           (R.drawable.icon_example_olimpic         , R.string.example_olimpic         , R.string.example_olimpic_subtitle         ,          OlimpicActivity.class),
106
    QUATERNION        (R.drawable.icon_example_quaternion      , R.string.example_quaternion      , R.string.example_quaternion_subtitle      ,       QuaternionActivity.class),
107
    INFLATE           (R.drawable.icon_example_inflate         , R.string.example_inflate         , R.string.example_inflate_subtitle         ,          InflateActivity.class),
108
    GENERIC           (R.drawable.icon_example_generic         , R.string.example_generic         , R.string.example_generic_subtitle         ,          GenericActivity.class),
109
    SURFACEVIEW       (R.drawable.icon_example_monalisa        , R.string.example_surfaceview   , R.string.example_surfaceview_subtitle   ,    SurfaceViewActivity.class),
110
    SAVE              (R.drawable.icon_example_save            , R.string.example_save            , R.string.example_save_subtitle            ,             SaveActivity.class),
111
    FLAG              (R.drawable.icon_example_flag            , R.string.example_flag            , R.string.example_flag_subtitle            ,             FlagActivity.class),
112
    WIND              (R.drawable.icon_example_wind            , R.string.example_wind            , R.string.example_wind_subtitle            ,             WindActivity.class),
113
    AROUNDTHEWORLD    (R.drawable.icon_example_aroundtheworld  , R.string.example_aroundtheworld  , R.string.example_aroundtheworld_subtitle  ,   AroundTheWorldActivity.class),
114
    MIRROR            (R.drawable.icon_example_mirror          , R.string.example_mirror          , R.string.example_mirror_subtitle          ,           MirrorActivity.class),
115
    STENCIL           (R.drawable.icon_example_stencil         , R.string.example_stencil         , R.string.example_stencil_subtitle         ,          StencilActivity.class),
116
    BLUR              (R.drawable.icon_example_blur            , R.string.example_blur            , R.string.example_blur_subtitle            ,             BlurActivity.class),
117
    MULTIBLUR         (R.drawable.icon_example_multiblur       , R.string.example_multiblur       , R.string.example_multiblur_subtitle       ,        MultiblurActivity.class),
118
    TRIBLUR           (R.drawable.icon_example_triblur         , R.string.example_triblur         , R.string.example_triblur_subtitle         ,          TriblurActivity.class),
119
    TRANSPARENCY      (R.drawable.icon_example_transparency    , R.string.example_transparency    , R.string.example_transparency_subtitle    ,     TransparencyActivity.class),
120
    POSTPROCESSTREE   (R.drawable.icon_example_postprocesstree , R.string.example_postprocesstree , R.string.example_postprocesstree_subtitle ,  PostprocessTreeActivity.class),
121
    GLOW              (R.drawable.icon_example_glow            , R.string.example_glow            , R.string.example_glow_subtitle            ,             GlowActivity.class),
122
    MOVINGGLOW        (R.drawable.icon_example_movingglow      , R.string.example_moving_glow     , R.string.example_moving_glow_subtitle     ,       MovingGlowActivity.class),
123
    EARTH             (R.drawable.icon_example_earth           , R.string.example_earth           , R.string.example_earth_subtitle           ,            EarthActivity.class),
124
    RUBIK             (R.drawable.icon_example_rubik           , R.string.example_rubik           , R.string.example_rubik_subtitle           ,            RubikActivity.class),
125
    MESHJOIN          (R.drawable.icon_example_meshjoin        , R.string.example_meshjoin           , R.string.example_meshjoin_subtitle           ,            MeshJoinActivity.class),
126
    PREDEFORM         (R.drawable.icon_example_predeform       , R.string.example_predeform           , R.string.example_predeform_subtitle           ,            PredeformActivity.class),
127
    DEFERREDJOB       (R.drawable.icon_example_deferredjob     , R.string.example_deferredjob           , R.string.example_deferredjob_subtitle           ,            DeferredJobActivity.class),
128
    SINGLEMESH        (R.drawable.icon_example_singlemesh      , R.string.example_singlemesh           , R.string.example_singlemesh_subtitle           ,            SingleMeshActivity.class),
129
    MESHFILE          (R.drawable.icon_example_wip             , R.string.example_meshfile           , R.string.example_meshfile_subtitle           ,            MeshFileActivity.class),
130
    ;
131

    
132
    final int icon, title, subtitle;
133
    final Class<? extends Activity> activity;
134

    
135
    Application(int i, int t, int s, Class<? extends Activity> a)
136
      {
137
      icon     = i;
138
      title    = t;
139
      subtitle = s;
140
      activity = a;
141
      }
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
   
146
  @Override
147
  public void onCreate(Bundle savedInstanceState) 
148
    {
149
    super.onCreate(savedInstanceState);
150
    setContentView(R.layout.table_of_contents);
151
      
152
    final List<Map<String, Object>> data = new ArrayList<>();
153
    final SparseArray<Class<? extends Activity>> activityMapping = new SparseArray<>();
154

    
155
    int index=0;
156

    
157
    for( Application app : Application.values() )
158
      {
159
      final Map<String, Object> item = new HashMap<>();
160
      item.put(ITEM_IMAGE, app.icon);
161
      item.put(ITEM_TITLE, (index+1)+". "+getText(app.title));
162
      item.put(ITEM_SUBTITLE, getText(app.subtitle));
163
      data.add(item);
164
      activityMapping.put(index++, app.activity);
165
      }
166

    
167
    final SimpleAdapter dataAdapter = new SimpleAdapter( this,
168
                                                         data,
169
                                                         R.layout.toc_item,
170
                                                         new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE},
171
                                                         new int[] {R.id.Image, R.id.Title, R.id.SubTitle}  );
172
    setListAdapter(dataAdapter);
173
      
174
    getListView().setOnItemClickListener(new OnItemClickListener()
175
      {
176
      @Override
177
      public void onItemClick(AdapterView<?> parent, View view, int position, long id)
178
        {
179
        final Class<? extends Activity> activityToLaunch = activityMapping.get(position);
180
            
181
        if (activityToLaunch != null)
182
          {
183
          final Intent launchIntent = new Intent(TableOfContents.this, activityToLaunch);
184
          startActivity(launchIntent);
185
          }
186
        }
187
      });
188
    }
189
  }
    (1-1/1)