1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.framesequence.samples;
18
19import android.app.ListActivity;
20import android.content.Intent;
21import android.os.Bundle;
22import android.view.View;
23import android.widget.ListView;
24import android.widget.SimpleAdapter;
25
26import java.util.ArrayList;
27import java.util.HashMap;
28import java.util.Map;
29
30public class SamplesList extends ListActivity {
31
32    static final String KEY_NAME = "name";
33    static final String KEY_CLASS = "clazz";
34    static final String KEY_RESOURCE = "res";
35
36    static Map<String,?> makeSample(String name, Class<?> activity, int resourceId) {
37        Map<String,Object> ret = new HashMap<String,Object>();
38        ret.put(KEY_NAME, name);
39        ret.put(KEY_CLASS, activity);
40        ret.put(KEY_RESOURCE, resourceId);
41        return ret;
42    }
43
44    @SuppressWarnings("serial")
45    static final ArrayList<Map<String,?>> SAMPLES = new ArrayList<Map<String,?>>() {{
46            add(makeSample("GIF animation", FrameSequenceTest.class, R.raw.animated_gif));
47            add(makeSample("WEBP animation", FrameSequenceTest.class, R.raw.animated_webp));
48    }};
49
50    @Override
51    protected void onCreate(Bundle savedInstanceState) {
52        super.onCreate(savedInstanceState);
53        setListAdapter(new SimpleAdapter(this, SAMPLES,
54                android.R.layout.simple_list_item_1, new String[] { KEY_NAME },
55                new int[] { android.R.id.text1 }));
56    }
57
58    @Override
59    protected void onListItemClick(ListView l, View v, int position, long id) {
60        Class<?> clazz = (Class<?>) SAMPLES.get(position).get(KEY_CLASS);
61        int resourceId = ((Integer) SAMPLES.get(position).get(KEY_RESOURCE)).intValue();
62
63        Intent intent = new Intent(this, clazz);
64        intent.putExtra("resourceId", resourceId);
65        startActivity(intent);
66    }
67
68}
69