1/*
2 * Copyright (C) 2008 Esmertec AG.
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.mms.ui;
19
20import java.util.ArrayList;
21import java.util.List;
22
23import android.content.Context;
24
25import com.android.mms.MmsConfig;
26import com.android.mms.R;
27
28/**
29 * An adapter to store icons and strings for attachment type list.
30 */
31public class AttachmentTypeSelectorAdapter extends IconListAdapter {
32    public final static int MODE_WITH_SLIDESHOW    = 0;
33    public final static int MODE_WITHOUT_SLIDESHOW = 1;
34
35    public final static int ADD_IMAGE               = 0;
36    public final static int TAKE_PICTURE            = 1;
37    public final static int ADD_VIDEO               = 2;
38    public final static int RECORD_VIDEO            = 3;
39    public final static int ADD_SOUND               = 4;
40    public final static int RECORD_SOUND            = 5;
41    public final static int ADD_SLIDESHOW           = 6;
42
43    public AttachmentTypeSelectorAdapter(Context context, int mode) {
44        super(context, getData(mode, context));
45    }
46
47    public int buttonToCommand(int whichButton) {
48        AttachmentListItem item = (AttachmentListItem)getItem(whichButton);
49        return item.getCommand();
50    }
51
52    protected static List<IconListItem> getData(int mode, Context context) {
53        List<IconListItem> data = new ArrayList<IconListItem>(7);
54        addItem(data, context.getString(R.string.attach_image),
55                R.drawable.ic_attach_picture_holo_light, ADD_IMAGE);
56
57        addItem(data, context.getString(R.string.attach_take_photo),
58                R.drawable.ic_attach_capture_picture_holo_light, TAKE_PICTURE);
59
60        addItem(data, context.getString(R.string.attach_video),
61                R.drawable.ic_attach_video_holo_light, ADD_VIDEO);
62
63        addItem(data, context.getString(R.string.attach_record_video),
64                R.drawable.ic_attach_capture_video_holo_light, RECORD_VIDEO);
65
66        if (MmsConfig.getAllowAttachAudio()) {
67            addItem(data, context.getString(R.string.attach_sound),
68                    R.drawable.ic_attach_audio_holo_light, ADD_SOUND);
69        }
70
71        addItem(data, context.getString(R.string.attach_record_sound),
72                R.drawable.ic_attach_capture_audio_holo_light, RECORD_SOUND);
73
74        if (mode == MODE_WITH_SLIDESHOW) {
75            addItem(data, context.getString(R.string.attach_slideshow),
76                    R.drawable.ic_attach_slideshow_holo_light, ADD_SLIDESHOW);
77        }
78
79        return data;
80    }
81
82    protected static void addItem(List<IconListItem> data, String title,
83            int resource, int command) {
84        AttachmentListItem temp = new AttachmentListItem(title, resource, command);
85        data.add(temp);
86    }
87
88    public static class AttachmentListItem extends IconListAdapter.IconListItem {
89        private int mCommand;
90
91        public AttachmentListItem(String title, int resource, int command) {
92            super(title, resource);
93
94            mCommand = command;
95        }
96
97        public int getCommand() {
98            return mCommand;
99        }
100    }
101}
102