1/*
2 * Copyright (C) 2010 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.videoeditor;
18
19import android.content.Context;
20import android.graphics.Bitmap;
21import android.graphics.BitmapFactory;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.AbsListView;
26
27/**
28 * Adapter which displays a list of supported transitions
29 */
30public class TransitionsAdapter extends BaseAdapterWithImages<Integer> {
31    // Instance variables
32    private final TransitionType[] mTransitions;
33
34    /**
35     * Constructor
36     *
37     * @param context The context
38     * @param listView The list view
39     */
40    public TransitionsAdapter(Context context, AbsListView listView) {
41        super(context, listView);
42
43        mTransitions = TransitionType.getTransitions(context);
44    }
45
46    /**
47     * @return The array of transitions
48     */
49    public TransitionType[] getTransitions() {
50        return mTransitions;
51    }
52
53    /*
54     * {@inheritDoc}
55     */
56    @Override
57    public int getCount() {
58        return mTransitions.length;
59    }
60
61    /*
62     * {@inheritDoc}
63     */
64    public Object getItem(int position) {
65        return mTransitions[position];
66    }
67
68    /*
69     * {@inheritDoc}
70     */
71    @SuppressWarnings("unchecked")
72    public View getView(int position, View convertView, ViewGroup parent) {
73        final ImageTextViewHolder<Integer> viewHolder;
74        final View rowView;
75        if (convertView == null) {
76            final LayoutInflater vi =
77                (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
78            rowView = vi.inflate(R.layout.image_with_text_row_view, null);
79            viewHolder = new ImageTextViewHolder<Integer>(rowView);
80            rowView.setTag(viewHolder);
81        } else {
82            rowView = convertView;
83            viewHolder = (ImageTextViewHolder<Integer>)convertView.getTag();
84        }
85
86        final TransitionType transitionType = mTransitions[position];
87        final int type = transitionType.getType();
88        initiateLoad(type, type, viewHolder);
89
90        // Set the data in the views
91        viewHolder.mNameView.setText(transitionType.getName());
92
93        return rowView;
94    }
95
96    /*
97     * {@inheritDoc}
98     */
99    @Override
100    protected Bitmap loadImage(Object data) {
101        return BitmapFactory.decodeResource(mContext.getResources(),
102                TransitionType.TRANSITION_RESOURCE_IDS[(Integer)data]);
103    }
104}
105