1 package com.introlab.rtabmap;
3 import android.content.Context;
4 import android.database.Cursor;
5 import android.database.sqlite.SQLiteDatabase;
6 import android.graphics.Bitmap;
7 import android.graphics.BitmapFactory;
8 import android.graphics.drawable.Drawable;
9 import android.util.Log;
10 import android.view.LayoutInflater;
11 import android.view.View;
12 import android.view.ViewGroup;
13 import android.widget.BaseAdapter;
14 import android.widget.ImageView;
15 import android.widget.LinearLayout;
16 import android.widget.SimpleAdapter;
18 import java.io.ByteArrayInputStream;
19 import java.io.InputStream;
20 import java.util.ArrayList;
21 import java.util.HashMap;
24 LayoutInflater inflater;
26 ArrayList<HashMap<String, String>> arrayList;
29 public DatabaseListArrayAdapter(Context context, ArrayList<HashMap<String, String>> data,
int resource, String[] from,
int[] to) {
30 super(context,
data, resource, from, to);
31 this.context = context;
32 this.arrayList =
data;
33 this.imageWidth = (
int)context.getResources().getDimension(
R.dimen.image_width);
34 inflater.from(context);
38 public View
getView(
final int position, View convertView, ViewGroup parent) {
39 View
view = super.getView(
position, convertView, parent);
40 ImageView imageView = (ImageView)
view.findViewById(
R.id.imageView);
42 boolean imageSet =
false;
46 SQLiteDatabase db =
null;
48 db = SQLiteDatabase.openDatabase(
path,
null, SQLiteDatabase.OPEN_READONLY);
51 Cursor c1 = db.rawQuery(
"SELECT version FROM Admin",
null);
52 if(c1.moveToFirst()) {
53 String
version = c1.getString(c1.getColumnIndex(
"version"));
56 Cursor c2 = db.rawQuery(
"SELECT preview_image FROM Admin WHERE preview_image is not null",
null);
57 if(c2.moveToFirst()) {
60 byte[]
bytes = c2.getBlob(c2.getColumnIndex(
"preview_image"));
61 ByteArrayInputStream inputStream =
new ByteArrayInputStream(
bytes);
62 Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
63 imageView.setImageBitmap(bitmap);
78 }
catch (Exception
e) {
82 if(db !=
null && db.isOpen()) {
94 Drawable myDrawable = context.getResources().getDrawable(
R.drawable.ic_launcher);
95 imageView.setImageDrawable(myDrawable);
97 LinearLayout.LayoutParams layoutParams =
new LinearLayout.LayoutParams(imageWidth,imageWidth/(!imageSet?2:1));
98 imageView.setLayoutParams(layoutParams);