DatabaseListArrayAdapter.java
Go to the documentation of this file.
1 package com.introlab.rtabmap;
2 
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;
17 
18 import java.io.ByteArrayInputStream;
19 import java.io.InputStream;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 
23 public class DatabaseListArrayAdapter extends SimpleAdapter {
24  LayoutInflater inflater;
25  Context context;
26  ArrayList<HashMap<String, String>> arrayList;
27  int imageWidth;
28 
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);
35  }
36 
37  @Override
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);
41 
42  boolean imageSet = false;
43  String path = this.arrayList.get(position).get("path");
44  if(!path.isEmpty())
45  {
46  SQLiteDatabase db = null;
47  try {
48  db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
49 
50  // get version
51  Cursor c1 = db.rawQuery("SELECT version FROM Admin", null);
52  if(c1.moveToFirst()) {
53  String version = c1.getString(c1.getColumnIndex("version"));
54  Log.i(RTABMapActivity.TAG, "Version="+version);
55  if(Util.versionCompare(version, "0.12.0") >= 0) {
56  Cursor c2 = db.rawQuery("SELECT preview_image FROM Admin WHERE preview_image is not null", null);
57  if(c2.moveToFirst()) {
58  Log.i(RTABMapActivity.TAG, "Found image preview for db " + path);
59 
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);
64  imageSet = true;
65  }
66  else {
67  Log.i(RTABMapActivity.TAG, "Not found image preview for db " + path);
68  }
69  }
70  else {
71  Log.i(RTABMapActivity.TAG, "Too old database for preview image, path = " + path);
72  }
73  }
74  else {
75  Log.e(RTABMapActivity.TAG, "Failed getting version from database");
76  }
77 
78  } catch (Exception e) {
79  Log.e(RTABMapActivity.TAG, e.getMessage());
80  }
81  finally {
82  if(db != null && db.isOpen()) {
83  db.close();
84  }
85  }
86  }
87  else
88  {
89  Log.e(RTABMapActivity.TAG, "Database path empty for item " + position);
90  }
91 
92  if(!imageSet)
93  {
94  Drawable myDrawable = context.getResources().getDrawable(R.drawable.ic_launcher);
95  imageView.setImageDrawable(myDrawable);
96  }
97  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(imageWidth,imageWidth/(!imageSet?2:1));
98  imageView.setLayoutParams(layoutParams);
99  return view;
100  }
101 
102 }
DatabaseListArrayAdapter(Context context, ArrayList< HashMap< String, String >> data, int resource, String[] from, int[] to)
GLM_FUNC_DECL genType e()
View getView(final int position, View convertView, ViewGroup parent)
const int c1
Definition: SuperPoint.cc:15
const int c2
Definition: SuperPoint.cc:16
unsigned char byte
static int versionCompare(String str1, String str2)
Definition: Util.java:108


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:58