List of usage examples for android.database Cursor isFirst
boolean isFirst();
From source file:com.cw.litenote.tabs.TabsHost.java
/** * delete page//from w w w . j a v a 2 s.co m * */ public static void deletePage(int tabPos, final AppCompatActivity activity) { final DB_folder mDbFolder = mTabsPagerAdapter.dbFolder; int pageId = mDbFolder.getPageId(tabPos, true); mDbFolder.open(); // check if only one page left int pagesCount = mDbFolder.getPagesCount(false); int mFirstPos_PageId = 0; Cursor mPageCursor = mDbFolder.getPageCursor(); if (mPageCursor.isFirst()) mFirstPos_PageId = pageId; if (pagesCount > 0) { //if current page is the first page and will be delete, //try to get next existence of note page System.out.println("TabsHost / deletePage / tabPos = " + tabPos); System.out.println("TabsHost / deletePage / mFirstPos_PageId = " + mFirstPos_PageId); if (pageId == mFirstPos_PageId) { int cGetNextExistIndex = getFocus_tabPos() + 1; boolean bGotNext = false; while (!bGotNext) { try { mFirstPos_PageId = mDbFolder.getPageId(cGetNextExistIndex, false); bGotNext = true; } catch (Exception e) { bGotNext = false; cGetNextExistIndex++; } } } //change to first existing page int newFirstPageTblId = 0; for (int i = 0; i < pagesCount; i++) { if (mDbFolder.getPageId(i, false) == mFirstPos_PageId) { newFirstPageTblId = mDbFolder.getPageTableId(i, false); System.out.println("TabsHost / deletePage / newFirstPageTblId = " + newFirstPageTblId); } } System.out .println("TabsHost / deletePage / --- after delete / newFirstPageTblId = " + newFirstPageTblId); Pref.setPref_focusView_page_tableId(activity, newFirstPageTblId);//todo Could be 0? } // else // { // Toast.makeText(activity, R.string.toast_keep_one_page , Toast.LENGTH_SHORT).show(); // return; // } mDbFolder.close(); // get page table Id for dropping int pageTableId = mDbFolder.getPageTableId(tabPos, true); System.out.println("TabsHost / _deletePage / pageTableId = " + pageTableId); // delete tab name mDbFolder.dropPageTable(pageTableId, true); mDbFolder.deletePage(DB_folder.getFocusFolder_tableName(), pageId, true); // mPagesCount--; // After Delete page, update highlight tab if (getFocus_tabPos() < MainAct.mPlaying_pagePos) { MainAct.mPlaying_pagePos--; } else if ((getFocus_tabPos() == MainAct.mPlaying_pagePos) && (MainAct.mPlaying_folderPos == FolderUi.getFocus_folderPos())) { if (BackgroundAudioService.mMediaPlayer != null) { Audio_manager.stopAudioPlayer(); Audio_manager.mAudioPos = 0; Audio_manager.setPlayerState(Audio_manager.PLAYER_AT_STOP); } } // update change after deleting tab FolderUi.startTabsHostRun(); }
From source file:org.alfresco.mobile.android.application.fragments.operation.OperationsFragment.java
protected void cancelAll() { Cursor cursor = ((CursorAdapter) adapter).getCursor(); Uri uri = null;// w w w.jav a 2 s .c om if (!cursor.isFirst()) { cursor.moveToPosition(-1); } for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); uri = Uri.parse( OperationsContentProvider.CONTENT_URI + "/" + cursor.getInt(OperationSchema.COLUMN_ID_ID)); Operator.with(getActivity()).cancel(uri.toString()); } cancelAll.setVisibility(View.GONE); dismissAll.setVisibility(View.GONE); }
From source file:org.alfresco.mobile.android.application.fragments.operation.OperationsFragment.java
protected void dismissAll() { Cursor cursor = ((CursorAdapter) adapter).getCursor(); Uri uri = null;//w ww. java 2s .com if (!cursor.isFirst()) { cursor.moveToPosition(-1); } for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); uri = Uri.parse( OperationsContentProvider.CONTENT_URI + "/" + cursor.getInt(OperationSchema.COLUMN_ID_ID)); getActivity().getContentResolver().delete(uri, null, null); } cancelAll.setVisibility(View.GONE); dismissAll.setVisibility(View.GONE); }
From source file:com.cw.litenote.operation.delete.DeletePages.java
void doDeletePages() { DB_folder mDbFolder = new DB_folder(MainAct.mAct, DB_folder.getFocusFolder_tableId()); mDbFolder.open();/*from w ww . j a va2 s . co m*/ for (int i = 0; i < list_selPage.count; i++) { if (list_selPage.mCheckedTabs.get(i)) { int pageTableId = mDbFolder.getPageTableId(i, false); mDbFolder.dropPageTable(pageTableId, false); int pageId = mDbFolder.getPageId(i, false); // delete page row mDbFolder.deletePage(DB_folder.getFocusFolder_tableName(), pageId, false); } } mDbFolder.close(); mDbFolder.open(); // check if only one page left int pgsCnt = mDbFolder.getPagesCount(false); if (pgsCnt > 0) { int newFirstPageTblId = 0; int i = 0; Cursor mPageCursor = mDbFolder.getPageCursor(); while (i < pgsCnt) { mPageCursor.moveToPosition(i); if (mPageCursor.isFirst()) newFirstPageTblId = mDbFolder.getPageTableId(i, false); i++; } System.out.println("TabsHost / _postDeletePage / newFirstPageTblId = " + newFirstPageTblId); Pref.setPref_focusView_page_tableId(act, newFirstPageTblId); } else if (pgsCnt == 0) Pref.setPref_focusView_page_tableId(act, 0);//todo 0 OK? mDbFolder.close(); // set scroll X // int scrollX = 0; //over the last scroll X // Pref.setPref_focusView_scrollX_byFolderTableId(act, scrollX ); if (BackgroundAudioService.mMediaPlayer != null) { Audio_manager.stopAudioPlayer(); Audio_manager.mAudioPos = 0; Audio_manager.setPlayerState(Audio_manager.PLAYER_AT_STOP); } list_selPage = new List_selectPage(act, rootView, mListView); }
From source file:com.cw.litenote.operation.delete.DeleteFolders.java
/** * Do delete folders//w ww . jav a 2 s. c o m */ void doDeleteFolders() { DB_drawer dbDrawer = new DB_drawer(act); // drawer DB check boolean doDB_check = true; if (doDB_check) { dbDrawer.open(); for (int i = 0; i < list_selFolder.count; i++) { int folderTableId = dbDrawer.getFolderTableId(i, false); System.out.println("DeleteFolders / folderTableId = " + folderTableId); int folderId = (int) dbDrawer.getFolderId(i, false); System.out.println("DeleteFolders / folderId = " + folderId); } dbDrawer.close(); } dbDrawer.open(); for (int i = 0; i < list_selFolder.count; i++) { if (list_selFolder.mCheckedArr.get(i)) { // get folder table id int folderTableId = dbDrawer.getFolderTableId(i, false); // 1) delete related page tables DB_folder dbFolder = new DB_folder(act, folderTableId); int pgsCnt = dbFolder.getPagesCount(true); for (int j = 0; j < pgsCnt; j++) { int pageTableId = dbFolder.getPageTableId(j, true); dbFolder.dropPageTable(folderTableId, pageTableId); } // 2) delete folder table dbDrawer.dropFolderTable(folderTableId, false); // 3) delete folder Id int folderId = (int) dbDrawer.getFolderId(i, false); dbDrawer.deleteFolderId(folderId, false); // change focus FolderUi.setFocus_folderPos(0); } } dbDrawer.close(); // check if only one folder left int foldersCnt = dbDrawer.getFoldersCount(true); // set focus folder table Id dbDrawer.open(); if (foldersCnt > 0) { int newFirstFolderTblId = 0; int i = 0; Cursor folderCursor = dbDrawer.getFolderCursor(); while (i < foldersCnt) { folderCursor.moveToPosition(i); if (folderCursor.isFirst()) newFirstFolderTblId = dbDrawer.getFolderTableId(i, false); i++; } Pref.setPref_focusView_folder_tableId(act, newFirstFolderTblId); } else if (foldersCnt == 0) Pref.setPref_focusView_folder_tableId(act, 1); dbDrawer.close(); // set scroll X // int scrollX = 0; //over the last scroll X // Pref.setPref_focusView_scrollX_byFolderTableId(act, scrollX ); if (BackgroundAudioService.mMediaPlayer != null) { Audio_manager.stopAudioPlayer(); Audio_manager.mAudioPos = 0; Audio_manager.setPlayerState(Audio_manager.PLAYER_AT_STOP); } list_selFolder = new List_selectFolder(act, rootView, mListView); }
From source file:org.alfresco.mobile.android.application.fragments.operation.OperationsFragment.java
@Override public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) { super.onLoadFinished(arg0, cursor); if (cursor.getCount() == 0) { dismissAll.setVisibility(View.GONE); ev.setVisibility(View.VISIBLE); displayEmptyView();// www.ja v a 2 s . c om } else { dismissAll.setVisibility(View.VISIBLE); if (!cursor.isFirst()) { cursor.moveToPosition(-1); } boolean isVisible = false; while (cursor.moveToNext()) { if (cursor.getInt(OperationSchema.COLUMN_STATUS_ID) == Operation.STATUS_RUNNING || cursor.getInt(OperationSchema.COLUMN_STATUS_ID) == Operation.STATUS_PENDING) { isVisible = true; break; } } cancelAll.setVisibility(View.GONE); if (isVisible) { cancelAll.setVisibility(View.VISIBLE); } } refreshHelper.setRefreshComplete(); }
From source file:util.CalendarExporter.java
/** * Asks user for Calendar to be exported to ONLY if there are more than one calendar instances available * @return/*from w w w . jav a2 s. co m*/ */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void requireCalendarID() { if (fragmentManager == null) { return; } Cursor calendarCursor = null; try { String[] projection = new String[] { CalendarContract.Calendars._ID, CalendarContract.Calendars.ACCOUNT_NAME, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CalendarContract.Calendars.NAME, CalendarContract.Calendars.CALENDAR_COLOR }; calendarCursor = contentResolver.query(CalendarContract.Calendars.CONTENT_URI, projection, null, null, null); calendarCursor.moveToFirst(); if (calendarCursor.isFirst() && calendarCursor.isLast()) { //Only one calendar available... nothing to be selected... Log.d("CalendarCursor", "ONLY ONE calendar instance available"); return; } else { final List<Integer> ids = new ArrayList<Integer>(); final List<StringBuilder> sb = new ArrayList<StringBuilder>(); final StringBuilder[] sbArray = new StringBuilder[1]; while (!calendarCursor.isLast()) { //only add calendars with different ids if (!ids.contains(calendarCursor.getInt(0))) { sb.add(new StringBuilder(calendarCursor.getString(3))); ids.add(Integer.parseInt(calendarCursor.getString(0))); } calendarCursor.moveToNext(); } final CalendarPickerDialog cpd = CalendarPickerDialog.newInstance(sb.toArray(sbArray), new CalendarChosenListener() { public void selected(int id) { calendarID = ids.get(id); Thread t = new Thread() { public void run() { doUpdate(); } }; t.start(); } public void canceled() { return; } }); cpd.show(fragmentManager, "chooser"); } } catch (Exception ex) { Log.d("Require Calendar ID", "Error", ex); if (calendarCursor != null) { calendarCursor.close(); } } }
From source file:org.sufficientlysecure.keychain.ui.MultiUserIdsFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { MatrixCursor matrix = new MatrixCursor(new String[] { "_id", "user_data", "grouped" }) { @Override//from w w w .j a va2 s . c om public byte[] getBlob(int column) { return super.getBlob(column); } }; data.moveToFirst(); long lastMasterKeyId = 0; String lastName = ""; ArrayList<String> uids = new ArrayList<>(); boolean header = true; // Iterate over all rows while (!data.isAfterLast()) { long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID); String userId = data.getString(INDEX_USER_ID); OpenPgpUtils.UserId pieces = KeyRing.splitUserId(userId); // Two cases: boolean grouped = masterKeyId == lastMasterKeyId; boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces.name); // Remember for next loop lastName = pieces.name; Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped")); if (!subGrouped) { // 1. This name should NOT be grouped with the previous, so we flush the buffer Parcel p = Parcel.obtain(); p.writeStringList(uids); byte[] d = p.marshall(); p.recycle(); matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 }); // indicate that we have a header for this masterKeyId header = false; // Now clear the buffer, and add the new user id, for the next round uids.clear(); } // 2. This name should be grouped with the previous, just add to buffer uids.add(userId); lastMasterKeyId = masterKeyId; // If this one wasn't grouped, the next one's gotta be a header if (!grouped) { header = true; } // Regardless of the outcome, move to next entry data.moveToNext(); } // If there is anything left in the buffer, flush it one last time if (!uids.isEmpty()) { Parcel p = Parcel.obtain(); p.writeStringList(uids); byte[] d = p.marshall(); p.recycle(); matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 }); } mUserIdsAdapter.swapCursor(matrix); }
From source file:net.smart_json_database.JSONDatabase.java
public Collection<String> getPropertyKeys() { ArrayList<String> arrayList = new ArrayList<String>(); SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = db.rawQuery("SELECT * FROM " + TABLE_Meta, new String[] {}); if (c.getCount() > 0) { int key_col = c.getColumnIndex("key"); c.moveToFirst();//from ww w .ja va 2 s . co m if (c != null) { if (c.isFirst()) { do { arrayList.add(c.getString(key_col)); } while (c.moveToNext()); } } } c.close(); return arrayList; }
From source file:net.smart_json_database.JSONDatabase.java
private String getPropterty(SQLiteDatabase db, String key, String defaultValue) { String returnValue = defaultValue; Cursor c = db.rawQuery("SELECT * FROM " + TABLE_Meta + " WHERE key = ?", new String[] { key }); if (c.getCount() > 0) { //int key_col = c.getColumnIndex("key"); int value_col = c.getColumnIndex("value"); c.moveToFirst();//from w ww.j a v a2s . com if (c != null) { if (c.isFirst()) { do { returnValue = c.getString(value_col); if (Util.IsNullOrEmpty(returnValue)) { returnValue = defaultValue; } break; } while (c.moveToNext()); } } } c.close(); return returnValue; }