Project

General

Profile

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

examples / src / main / java / org / distorted / examples / TableOfContents.java @ 887e1853

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

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

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

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

    
128
    final int icon, title, subtitle;
129
    final Class<? extends Activity> activity;
130

    
131
    Application(int i, int t, int s, Class<? extends Activity> a)
132
      {
133
      icon     = i;
134
      title    = t;
135
      subtitle = s;
136
      activity = a;
137
      }
138
    }
139

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

    
151
    int index=0;
152

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

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