PageRenderTime 46ms CodeModel.GetById 19ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/v3.2/nimbits-android/src/com/nimbits/android/ImageCursorAdapter.java

http://nimbits-server.googlecode.com/
Java | 86 lines | 73 code | 12 blank | 1 comment | 3 complexity | 4c947c2b86e107cc16c3ffd3a0ce1cda MD5 | raw file
 1package com.nimbits.android;
 2
 3
 4import android.content.Context;
 5import android.database.Cursor;
 6import android.view.LayoutInflater;
 7import android.view.View;
 8import android.view.ViewGroup;
 9import android.widget.ImageView;
10import android.widget.SimpleCursorAdapter;
11import android.widget.TextView;
12import com.nimbits.client.model.Const;
13
14public class ImageCursorAdapter extends SimpleCursorAdapter {
15    private final Cursor c;
16    private final Context context;
17
18    public ImageCursorAdapter(final Context context, final int layout, final Cursor c,
19                              final String[] from, final int[] to) {
20        super(context, layout, c, from, to);
21        this.c = c;
22        this.context = context;
23    }
24
25    public View getView(final int pos, final View inView,final ViewGroup parent) {
26        //Log.v("getview", "" + pos);
27
28        View v = inView;
29        if (v == null) {
30            final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
31            v = inflater.inflate(R.layout.main_list, null);
32        }
33        this.c.moveToPosition(pos);
34        final String name = this.c.getString(this.c.getColumnIndex(Const.ANDROID_COL_NAME));
35        final String desc = this.c.getString(this.c.getColumnIndex(Const.ANDROID_COL_DESCRIPTION));
36        int type = this.c.getInt(this.c.getColumnIndex(Const.ANDROID_COL_DISPLAY_TYPE));
37        DisplayType displayType = DisplayType.get(type);
38
39        ImageView icon = (ImageView) v.findViewById(R.id.icon1);
40        TextView d = (TextView) v.findViewById(R.id.text2);
41        d.setText(desc);
42
43        switch (displayType) {
44            case  Category: {
45                icon.setImageResource(R.drawable.aquasmoothfoldersitesicon48);
46                icon.setTag(Const.PARAM_CATEGORY);
47                break;
48            }
49
50            case Point: {
51                icon.setImageResource(R.drawable.aquaballgreenicon32);
52                icon.setTag(Const.PARAM_POINT);
53                break;
54            }
55            case HighAlarm: {
56                icon.setImageResource(R.drawable.aquaballredicon32);
57                icon.setTag(Const.PARAM_POINT);
58                break;
59            }
60            case LowAlarm: {
61                icon.setImageResource(R.drawable.aquaballicon32);
62                icon.setTag(Const.PARAM_POINT);
63                break;
64            }
65            case IdleAlarm:{
66                icon.setImageResource(R.drawable.aquapause);
67                icon.setTag(Const.PARAM_POINT);
68                break;
69            }
70            case Diagram: {
71                icon.setImageResource(R.drawable.diagram);
72                icon.setTag(Const.PARAM_DIAGRAM);
73                break;
74            }
75
76            default: {
77                icon.setImageResource(R.drawable.diagram);
78            }
79        }
80
81
82        TextView bTitle = (TextView) v.findViewById(R.id.text1);
83        bTitle.setText(name);
84        return(v);
85    }
86}