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 }
com.introlab.rtabmap.RTABMapActivity.TAG
static final String TAG
Definition: RTABMapActivity.java:113
int
int
com.introlab.rtabmap.Util.versionCompare
static int versionCompare(String str1, String str2)
Definition: Util.java:131
bytes
com.introlab.rtabmap.DatabaseListArrayAdapter.DatabaseListArrayAdapter
DatabaseListArrayAdapter(Context context, ArrayList< HashMap< String, String >> data, int resource, String[] from, int[] to)
Definition: DatabaseListArrayAdapter.java:29
com.introlab.rtabmap.DatabaseListArrayAdapter.getView
View getView(final int position, View convertView, ViewGroup parent)
Definition: DatabaseListArrayAdapter.java:38
view
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set view
com.introlab.rtabmap.DatabaseListArrayAdapter
Definition: DatabaseListArrayAdapter.java:23
data
int data[]
com.introlab.rtabmap.Util
Definition: Util.java:23
version
version
path
path
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
position
Point3 position(const NavState &X, OptionalJacobian< 3, 9 > H)
R
R
com.introlab.rtabmap.RTABMapActivity
Definition: RTABMapActivity.java:107


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:08