Java Code Examples for android.database.Cursor.moveToLast()

The following are Jave code examples for showing how to use moveToLast() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: siiMobilityAppKit   File: CameraLauncher.java   Source Code and License Vote up 7 votes
/**
 * Used to find out if we are in a situation where the Camera Intent adds to images
 * to the content store. If we are using a FILE_URI and the number of images in the DB
 * increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
 *
 * @param type FILE_URI or DATA_URL
 */
private void checkForDuplicateImage(int type) {
    int diff = 1;
    Uri contentStore = whichContentStore();
    Cursor cursor = queryImgDB(contentStore);
    int currentNumOfImages = cursor.getCount();

    if (type == FILE_URI && this.saveToPhotoAlbum) {
        diff = 2;
    }

    // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
    if ((currentNumOfImages - numPics) == diff) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
        if (diff == 2) {
            id--;
        }
        Uri uri = Uri.parse(contentStore + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
        cursor.close();
    }
}
 
Example 2
Project: COB   File: CameraLauncher.java   Source Code and License Vote up 6 votes
/**
 * Used to find out if we are in a situation where the Camera Intent adds to images
 * to the content store. If we are using a FILE_URI and the number of images in the DB
 * increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
 *
 * @param type FILE_URI or DATA_URL
 */
private void checkForDuplicateImage(int type) {
    int diff = 1;
    Uri contentStore = whichContentStore();
    Cursor cursor = queryImgDB(contentStore);
    int currentNumOfImages = cursor.getCount();

    if (type == FILE_URI && this.saveToPhotoAlbum) {
        diff = 2;
    }

    // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
    if ((currentNumOfImages - numPics) == diff) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
        if (diff == 2) {
            id--;
        }
        Uri uri = Uri.parse(contentStore + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
        cursor.close();
    }
}
 
Example 3
Project: FileDownloader-master   File: TasksManagerDBController.java   Source Code and License Vote up 6 votes
public List<TasksManagerModel> getAllTasks() {
    final Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME, null);

    final List<TasksManagerModel> list = new ArrayList<>();
    try {
        if (!c.moveToLast()) {
            return list;
        }

        do {
            TasksManagerModel model = new TasksManagerModel();
            model.setId(c.getInt(c.getColumnIndex(TasksManagerModel.ID)));
            model.setName(c.getString(c.getColumnIndex(TasksManagerModel.NAME)));
            model.setUrl(c.getString(c.getColumnIndex(TasksManagerModel.URL)));
            model.setPath(c.getString(c.getColumnIndex(TasksManagerModel.PATH)));
            list.add(model);
        } while (c.moveToPrevious());
    } finally {
        if (c != null) {
            c.close();
        }
    }

    return list;
}
 
Example 4
Project: QuranAndroid   File: DatabaseAccess.java   Source Code and License Vote up 6 votes
public int getPageHezb(int pageNumber) {
    int hezbNumber = 0;
    try {
        SQLiteDatabase db = openDB(MAIN_DATABASE);
        String sql = "select hezb from aya where page = " + pageNumber + " ;";
        Cursor cursor = db.rawQuery(sql, null);

        if(cursor.moveToLast()){
            hezbNumber = cursor.getInt(0);
        }
        cursor.close();
        closeDB(db);
        return hezbNumber;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return hezbNumber;
}
 
Example 5
Project: react-native-android-library-humaniq-api   File: ContactsModule.java   Source Code and License Vote up 6 votes
@Override public void onChange(boolean selfChange, Uri uri) {
  ArrayList<String> phoneNumber = new ArrayList<>();
  super.onChange(selfChange, uri);
  Log.d(LOG_TAG, "Contact has changed");

  Cursor cursor = getReactApplicationContext().getContentResolver()
      .query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

  if (!cursor.moveToFirst()) return;

  cursor.moveToLast();
  String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
  String phone =
      cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
  Log.d(LOG_TAG, "id = " + name + "\n name = " + name);
  phoneNumber.add(phone);
  synchronizePhoneNumber(phoneNumber);
}
 
Example 6
Project: MyPlace   File: RoomDbHelper.java   Source Code and License Vote up 6 votes
public Message getLastMessage(int roomID) throws Exception {
    String roomIDString = getRoomIdString(roomID);
    String query = "SELECT * FROM "+roomIDString+" ORDER BY "+ROOM_TIMESTAMP+" ASC";
    SQLiteDatabase db = getWritableDatabase();

    Cursor c = db.rawQuery(query, null);
    c.moveToLast();
    int messageID = c.getInt(c.getColumnIndex(ROOM_MESSAGEID));
    String name = c.getString(c.getColumnIndex(ROOM_SENDER));
    String text = c.getString(c.getColumnIndex(ROOM_TEXT));
    long timestamp = c.getLong(c.getColumnIndex(ROOM_TIMESTAMP));

    Message message = new Message(messageID, roomID, name, text, timestamp);
    c.close();
    db.close();
    return message;
}
 
Example 7
Project: airgram   File: DataBaseAccess.java   Source Code and License Vote up 6 votes
public AlarmResponse getLastAlarm(int versionCode) {
    String whereClause = "targetVersion = " + versionCode;
    Cursor cursor = null;
    try {
        cursor = this.openHelper.getReadableDatabase().query(DBConstants.TABLE_ALARM, null, whereClause, null, null, null, DBConstants.ID);
        if (!cursor.moveToLast()) {
            return null;
        }
        AlarmResponse alarmFromCursor = getAlarmFromCursor(cursor);
        if (cursor == null) {
            return alarmFromCursor;
        }
        cursor.close();
        return alarmFromCursor;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 8
Project: localcloud_fe   File: CameraLauncher.java   Source Code and License Vote up 6 votes
/**
 * Used to find out if we are in a situation where the Camera Intent adds to images
 * to the content store. If we are using a FILE_URI and the number of images in the DB
 * increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
 *
 * @param type FILE_URI or DATA_URL
 */
private void checkForDuplicateImage(int type) {
    int diff = 1;
    Uri contentStore = whichContentStore();
    Cursor cursor = queryImgDB(contentStore);
    int currentNumOfImages = cursor.getCount();

    if (type == FILE_URI && this.saveToPhotoAlbum) {
        diff = 2;
    }

    // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
    if ((currentNumOfImages - numPics) == diff) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
        if (diff == 2) {
            id--;
        }
        Uri uri = Uri.parse(contentStore + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
        cursor.close();
    }
}
 
Example 9
Project: localcloud_fe   File: CameraLauncher.java   Source Code and License Vote up 6 votes
/**
 * Used to find out if we are in a situation where the Camera Intent adds to images
 * to the content store. If we are using a FILE_URI and the number of images in the DB
 * increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
 *
 * @param type FILE_URI or DATA_URL
 */
private void checkForDuplicateImage(int type) {
    int diff = 1;
    Uri contentStore = whichContentStore();
    Cursor cursor = queryImgDB(contentStore);
    int currentNumOfImages = cursor.getCount();

    if (type == FILE_URI && this.saveToPhotoAlbum) {
        diff = 2;
    }

    // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
    if ((currentNumOfImages - numPics) == diff) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
        if (diff == 2) {
            id--;
        }
        Uri uri = Uri.parse(contentStore + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
        cursor.close();
    }
}
 
Example 10
Project: RoadLab-Pro   File: RoadDAO.java   Source Code and License Vote up 6 votes
public RoadModel getLastRoad(long folderId) {
    Cursor c = getAllRoadByFolderIdCursor(folderId);
    RoadModel road = null;
    try {
        if (c != null) {
            if (c.getCount() > 0) {
                c.moveToLast();
                road = cursorToRoad(c);
            }
            c.close();
        }
    } catch (Exception e) {
        Log.e(TAG, e != null && e.getMessage() != null ? e.getMessage() : "");
    }
    return road;
}
 
Example 11
Project: siiMobilityAppKit   File: CameraLauncher.java   Source Code and License Vote up 6 votes
/**
 * Used to find out if we are in a situation where the Camera Intent adds to images
 * to the content store. If we are using a FILE_URI and the number of images in the DB
 * increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
 *
 * @param type FILE_URI or DATA_URL
 */
private void checkForDuplicateImage(int type) {
    int diff = 1;
    Uri contentStore = whichContentStore();
    Cursor cursor = queryImgDB(contentStore);
    int currentNumOfImages = cursor.getCount();

    if (type == FILE_URI && this.saveToPhotoAlbum) {
        diff = 2;
    }

    // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
    if ((currentNumOfImages - numPics) == diff) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
        if (diff == 2) {
            id--;
        }
        Uri uri = Uri.parse(contentStore + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
        cursor.close();
    }
}
 
Example 12
Project: StopApp   File: AppInfoDBController.java   Source Code and License Vote up 5 votes
/**
 * 获取主页停用列表apps
 *
 * @param tableName
 * @return
 */
public List<AppInfo> getDisableApps(String tableName) {
    final Cursor cursor = mSQLiteDatabase.rawQuery("SELECT * FROM " + tableName, null);

    final List<AppInfo> list = new ArrayList<>();
    try {
        if (!cursor.moveToLast()) {
            return list;
        }
        do {
            AppInfo appInfo = new AppInfo();
            appInfo.setAppPackageName(cursor.getString(cursor.getColumnIndex(AppInfo.APP_PACKAGE_NAME)));
            appInfo.setAppName(cursor.getString(cursor.getColumnIndex(AppInfo.APP_NAME)));
            MyLogger.e(cursor.getString(cursor.getColumnIndex(AppInfo.APP_NAME)));
            appInfo.setAppIcon(CommonUtil.getImage(cursor.getBlob(cursor.getColumnIndex(AppInfo.APP_ICON))));
            appInfo.setEnable(cursor.getInt(cursor.getColumnIndex(AppInfo.IS_ENABLE)));
            appInfo.setSystemApp(cursor.getInt(cursor.getColumnIndex(AppInfo.IS_SYSTEM_APP)));
            list.add(appInfo);
        } while (cursor.moveToPrevious());
    } finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }

    return list;
}
 
Example 13
Project: FreeStreams-TVLauncher   File: MainActivity.java   Source Code and License Vote up 5 votes
private String getUrlDataFromDB() {
        Cursor cursor = mSQLiteDataBase.rawQuery("SELECT url_data FROM my_url_data", null);
        cursor.moveToLast();
        String a = cursor.getString(cursor.getColumnIndex("url_data"));
//        String s = cursor.getString(2);
        return a;
    }
 
Example 14
Project: SwolyV2   File: MaxesAdapter.java   Source Code and License Vote up 5 votes
protected static int findLastValue(DBHandler db, String tableName){
    int foundValue;
    String selectQuery = "SELECT  * FROM " + tableName;
    SQLiteDatabase db1 = db.getReadableDatabase();
    Cursor cursor = db1.rawQuery(selectQuery, null);
    cursor.moveToLast();
    foundValue = Integer.parseInt(cursor.getString(1));
    cursor.close();
    return foundValue;
}
 
Example 15
Project: leoapp-sources   File: SQLiteConnectorStundenplan.java   Source Code and License Vote up 5 votes
public Fach[] gewaehlteFaecherAnTag(int tag) {
    String table = TABLE_FAECHER + ", " + TABLE_GEWAEHLT + ", " + TABLE_STUNDEN;
    String[] columns = {TABLE_FAECHER + "." + FACH_ID,
            FACH_KURZEL,
            FACH_NAME,
            FACH_ART,
            FACH_LEHRER,
            FACH_KLASSE,
            STUNDE_RAUM,
            STUNDEN_STUNDE,
            GEWAEHLT_SCHRIFTLICH,
            STUNDE_NOTIZ};
    String selection = TABLE_FAECHER + "." + FACH_ID + " = " + TABLE_STUNDEN + "." + FACH_ID + " AND " + TABLE_FAECHER + "." + FACH_ID + " = " + TABLE_GEWAEHLT + "." + FACH_ID + " AND " + TABLE_STUNDEN + "." + STUNDEN_TAG + " = " + tag;
    Cursor cursor    = database.query(table, columns, selection, null, null, null, STUNDEN_STUNDE);
    Fach[] faecher   = new Fach[0];
    if (cursor.getCount() > 0) {
        cursor.moveToLast();
        faecher = new Fach[cursor.getInt(7)];
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            faecher[cursor.getInt(7) - 1] = new Fach(cursor.getInt(0), cursor.getString(1), cursor.getString(2) + (cursor.getString(3).equals("LK") ? " LK" : ""), cursor.getString(4), cursor.getString(5), cursor.getString(6), tag, cursor.getInt(7));
            faecher[cursor.getInt(7) - 1].setzeNotiz(cursor.getString(9));
            faecher[cursor.getInt(7) - 1].setzeSchriftlich(cursor.getInt(8) == 1);
        }
        for (int i = 0; i < faecher.length; i++) {
            if (faecher[i] == null)
                faecher[i] = new Fach(0, "", "", "", "", "", tag, i + 1);
        }
    }
    cursor.close();
    return faecher;
}
 
Example 16
Project: Sega   File: SearchHistoryTable.java   Source Code and License Vote up 5 votes
private int getLastItemId(Integer databaseKey) {
    open();
    String sql = "SELECT " + SearchHistoryDatabase.SEARCH_HISTORY_COLUMN_ID + " FROM " + SearchHistoryDatabase.SEARCH_HISTORY_TABLE;
    if (databaseKey != null)
        sql += " WHERE " + SearchHistoryDatabase.SEARCH_HISTORY_KEY + " = " + databaseKey;
    Cursor res = db.rawQuery(sql, null);
    res.moveToLast();
    int count = res.getInt(0);
    close();
    res.close();
    return count;
}
 
Example 17
Project: oma-riista-android   File: DiaryDataSource.java   Source Code and License Vote up 5 votes
/**
 * Iterates sqlite cursor and builds complete GameHarvest objects
 *
 * @param cursor           sqlite cursor
 * @param getDeletedImages
 * @return List of GameHarvest objects
 */
private List<GameHarvest> aggregateEvents(Cursor cursor, boolean getDeletedImages) {
    cursor.moveToFirst();
    List<LogImage> logImages = new ArrayList<LogImage>();
    boolean first = true;
    int lastId = 0;
    List<GameHarvest> logEvents = new ArrayList<GameHarvest>();
    while (!cursor.isAfterLast()) {
        int eventId = cursor.getInt(cursor.getColumnIndex(DiaryHelper.COLUMN_LOCALID));
        if (!first && eventId != lastId) {
            cursor.moveToPrevious();
            logEvents.add(createEvent(cursor, logImages));
            logImages = new ArrayList<LogImage>();
            cursor.moveToNext();
        }
        LogImage image = logImageFromCursor(cursor, getDeletedImages);
        if (image != null)
            logImages.add(image);
        lastId = eventId;
        cursor.moveToNext();
        first = false;
    }
    if (cursor.getCount() > 0) {
        cursor.moveToLast();
        logEvents.add(createEvent(cursor, logImages));
    }
    return logEvents;
}
 
Example 18
Project: remotedroid   File: SMSUtils.java   Source Code and License Vote up 4 votes
private List<HashMap<String,String>> getMessages(String where, String[] whereArgs, int limitStart, int limitEnd){
    Uri uri = Uri.parse("content://sms");

    Cursor c = mContext.getContentResolver().query(uri,
            null,
            where,
            whereArgs,
            "date desc LIMIT "+String.valueOf(limitStart)+", "+String.valueOf(limitEnd)
    );
    List<HashMap<String,String>> ret = new ArrayList<HashMap<String, String>>();
    if (c.getCount() > 0){
        c.moveToLast();
        for (int i = 0; i < c.getCount(); i++) {
            String msgId = c.getString(c.getColumnIndex("_id"));
            String address = c.getString(c.getColumnIndex("address")); // phone #
            String date = c.getString(c.getColumnIndex("date"));
            String body = c.getString(c.getColumnIndex("body"));
            //String seen = c.getString(c.getColumnIndex("read"));
            String type = c.getString(c.getColumnIndex("type"));
            int thread = c.getInt(c.getColumnIndexOrThrow("thread_id"));

            ContactsUtil mContacts = new ContactsUtil(mContext);
            String contactId = mContacts.getContactId(address);

            String name = address;
            if (!(contactId == null)) {
                HashMap<String, String> contact = mContacts.getContactById(Integer.parseInt(contactId));
                name = contact.get("name");
            }

            HashMap<String,String> currMsg = new HashMap<>();
            currMsg.put("address",address);
            currMsg.put("name",name);
            currMsg.put("date",date); //timestamp
            currMsg.put("content",body);
            currMsg.put("contact_id",contactId);
            currMsg.put("type",type);
            currMsg.put("msg_id", msgId);
            currMsg.put("thread_id", String.valueOf(thread));

            ret.add(currMsg);
            c.moveToPrevious();
        }
    }
    return ret;
}
 
Example 19
Project: oneKey2Alarm   File: contacts.java   Source Code and License Vote up 4 votes
protected void onActivityResult (int requestCode, int resultCode, Intent data) 
{
	super.onActivityResult(requestCode, resultCode, data);
	if (resultCode == Activity.RESULT_OK) {
           ContentResolver reContentResolverol = getContentResolver();
            Uri contactData = data.getData();
            @SuppressWarnings("deprecation")
           Cursor cursor = managedQuery(contactData, null, null, null, null);
            cursor.moveToFirst();
            name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
           String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
           Cursor phone = reContentResolverol.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                    null, 
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, 
                    null, 
                    null);
            while (phone.moveToNext()) {
                number = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));	      
                }
            isfrist=false;
          //add a contact  
            db.open(); 
            long id = db.insertContact(name, number);
    		if(isfrist !=true)
    		{	
    			//get a contact  
    	        db.open();
    	       Cursor a = db.getContact(id);
    	       
    	        if (a.moveToLast()){
     			 Map<String, Object> map = new HashMap<String, Object>();
     	            map.put("contacts_name", name);
     	            map.put("contacts_num", number);
     	            dataList.add(map);
     	            simpleadapter = new SimpleAdapter(this, dataList, R.layout.contact_text, new String[]{"contacts_name","contacts_num"}, 
     		 				new int[]{R.id.contacts_name,R.id.contacts_num});
     	            listView.setAdapter(simpleadapter);  
     	            simpleadapter.notifyDataSetChanged();
    	           // DisplayContact(a);
    	            
    	        }
    	        else 
    	            Toast.makeText(this, "No contact found!", Toast.LENGTH_SHORT).show(); 
    		}
    		db.close(); 
	}
            
 }
 
Example 20
Project: IdeaTrackerPlus   File: DatabaseHelper.java   Source Code and License Vote up 4 votes
/**
 * Get the last (and bigger) order index of the given tab item list
 *
 * @param tabNumber
 * @return
 */
public int getLastOrderIndex(int tabNumber) {

    int lastOrderIndex = -1;

    if (!DataEntry.TABLE_NAME.equals("[]")) {

        SQLiteDatabase db = this.getReadableDatabase();

        // Only the text and priority will be read
        String[] projection = {DataEntry.COLUMN_NAME_ENTRY_ID};

        // How you want the results sorted in the resulting Cursor
        String sortOrder = DataEntry.COLUMN_NAME_ENTRY_ID + " ASC";

        //Define the where condition
        String where = "";
        String[] values = {};
        switch (tabNumber) {
            case 1:
                where = "later=? and done=? and temp=?";
                values = new String[]{"0", "0", "0"};
                break;

            case 2:
                where = "later=? and temp=?";
                values = new String[]{"1", "0"};
                break;

            case 3:
                where = "done=? and temp=?";
                values = new String[]{"1", "0"};
                break;
        }

        Cursor cursor = null;
        try {
            cursor = db.query(
                    DataEntry.TABLE_NAME,  // The table to query
                    projection,                               // The columns to return
                    where,                                   // The columns for the WHERE clause
                    values,                      // The values for the WHERE clause
                    null,                                     // don't group the rows
                    null,                                     // don't filter by row groups
                    sortOrder                                 // The sort order
            );


            if (cursor.moveToLast()) {
                lastOrderIndex = cursor.getInt(cursor.getColumnIndex(DataEntry.COLUMN_NAME_ENTRY_ID));
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    return lastOrderIndex;
}