src/main/java/de/blau/android/photos/PhotoIndex.java
/**
     * Create the in-memory index from the on device database
     * 
     * @param index the current in memory index or null
     */
Create the in-memory index from the on device database

@param index the current in memory index or null
Create the in - memory index from the on device database @param index the current in memory index or null
public synchronized void fill(@Nullable RTree<Photo> index) {
        if (index == null) {
            App.resetPhotoIndex(); 
            index = App.getPhotoIndex();
        }
        try {
            SQLiteDatabase db = getReadableDatabase();
            Cursor dbresult = db.query(PHOTOS_TABLE, new String[] { LAT_COLUMN, LON_COLUMN, DIRECTION_COLUMN, URI_COLUMN, NAME_COLUMN }, null, null, null, null,
                    null, null);
            int photoCount = dbresult.getCount();
            dbresult.moveToFirst();
            Log.i(DEBUG_TAG, "Query returned " + photoCount + " photos");
            for (int i = 0; i < photoCount; i++) {
                String name = dbresult.getString(4);
                String dir = dbresult.getString(3);
                Photo newPhoto;
                if (dbresult.isNull(2)) {  no direction
                    newPhoto = new Photo(dbresult.getInt(0), dbresult.getInt(1), dir, name);
                } else {
                    newPhoto = new Photo(dbresult.getInt(0), dbresult.getInt(1), dbresult.getInt(2), dir, name);
                }
                if (!index.contains(newPhoto)) {
                    index.insert(newPhoto);
                }
                dbresult.moveToNext();
            }
            dbresult.close();
            db.close();
        } catch (SQLiteException ex) {
             shoudn't happen (getReadableDatabase failed), simply report for now
            ACRA.getErrorReporter().handleException(ex);
        }
    }
public synchronized void fill ( @ Nullable RTree < Photo > index ) { if ( index == null ) { App . resetPhotoIndex ( ) ; index = App . getPhotoIndex ( ) ; } try { SQLiteDatabase db = getReadableDatabase ( ) ; Cursor dbresult = db . query ( PHOTOS_TABLE , new String [ ] { LAT_COLUMN , LON_COLUMN , DIRECTION_COLUMN , URI_COLUMN , NAME_COLUMN } , null , null , null , null , null , null ) ; int photoCount = dbresult . getCount ( ) ; dbresult . moveToFirst ( ) ; Log . i ( DEBUG_TAG , "Query returned " + photoCount + " photos" ) ; for ( int i = 0 ; i < photoCount ; i ++ ) { String name = dbresult . getString ( 4 ) ; String dir = dbresult . getString ( 3 ) ; Photo newPhoto ; if ( dbresult . isNull ( 2 ) ) { newPhoto = new Photo ( dbresult . getInt ( 0 ) , dbresult . getInt ( 1 ) , dir , name ) ; } else { newPhoto = new Photo ( dbresult . getInt ( 0 ) , dbresult . getInt ( 1 ) , dbresult . getInt ( 2 ) , dir , name ) ; } if ( ! index . contains ( newPhoto ) ) { index . insert ( newPhoto ) ; } dbresult . moveToNext ( ) ; } dbresult . close ( ) ; db . close ( ) ; } catch ( SQLiteException ex ) { ACRA . getErrorReporter ( ) . handleException ( ex ) ; } }
Create the in-memory index from the on device database
Create the in - memory index from the on device database
// allocate r-tree // // no direction // shoudn't happen (getReadableDatabase failed), simply report for now