List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testUpdate() throws Exception { Date currentDate = new Date(); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(GroupAccess.COLUMN.GROUP_ID, 1); cv.put(GroupAccess.COLUMN.INTERRUPTED, false); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); GroupAccess groupAccess = new GroupAccess(1, "fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds."); groupAccess.setLastTokenRequest(currentDate); groupAccess.setLastUpdateFromServer(currentDate); groupAccess.setSynchronize(true);/*from w ww . j av a2s .co m*/ groupAccess.setInterrupted(true); assertTrue(mGroupAuthAccessDbController.update(groupAccess)); Cursor cursor = db.query(GroupAccess.TABLE_NAME, GroupAccess.COLUMN.ALL_COLUMNS, GroupAccess.COLUMN.GROUP_ID + " = ? ", new String[] { String.valueOf(1) }, null, null, null); int count = cursor.getCount(); if (count == 0) cursor.close(); assertTrue(cursor.moveToFirst()); int groupId = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.GROUP_ID)); boolean synchronize = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.SYNCHRONIZE)) == 1; boolean interrupted = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.INTERRUPTED)) == 1; Date lastTokenRequestDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_TOKEN_REQUEST)), new ParsePosition(0)); Date lastUpdateDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER)), new ParsePosition(0)); String token = cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.TOKEN)); cursor.close(); assertEquals(1, groupId); assertEquals(true, synchronize); assertEquals(true, interrupted); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastTokenRequestDate)); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastUpdateDate)); assertEquals("fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds.", token); }
From source file:com.android.browser.BookmarksPageCallbacks.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { BookmarkContextMenuInfo info = (BookmarkContextMenuInfo) menuInfo; BrowserBookmarksAdapter adapter = getChildAdapter(info.groupPosition); Cursor cursor = adapter.getItem(info.childPosition); if (!canEdit(cursor)) { return;/*from www . java2 s.c o m*/ } boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; final Activity activity = getActivity(); MenuInflater inflater = activity.getMenuInflater(); inflater.inflate(R.menu.bookmarkscontext, menu); if (isFolder) { menu.setGroupVisible(R.id.FOLDER_CONTEXT_MENU, true); } else { menu.setGroupVisible(R.id.BOOKMARK_CONTEXT_MENU, true); if (mDisableNewWindow) { menu.findItem(R.id.new_window_context_menu_id).setVisible(false); } } BookmarkItem header = new BookmarkItem(activity); header.setEnableScrolling(true); populateBookmarkItem(cursor, header, isFolder); menu.setHeaderView(header); int count = menu.size(); for (int i = 0; i < count; i++) { menu.getItem(i).setOnMenuItemClickListener(mContextItemClickListener); } }
From source file:com.android.emailcommon.provider.HostAuth.java
@Override public void restore(Cursor cursor) { mBaseUri = CONTENT_URI;//from ww w . j ava 2 s.c o m mId = cursor.getLong(CONTENT_ID_COLUMN); mProtocol = cursor.getString(CONTENT_PROTOCOL_COLUMN); mAddress = cursor.getString(CONTENT_ADDRESS_COLUMN); mPort = cursor.getInt(CONTENT_PORT_COLUMN); mFlags = cursor.getInt(CONTENT_FLAGS_COLUMN); mLogin = cursor.getString(CONTENT_LOGIN_COLUMN); mPassword = cursor.getString(CONTENT_PASSWORD_COLUMN); mDomain = cursor.getString(CONTENT_DOMAIN_COLUMN); mClientCertAlias = cursor.getString(CONTENT_CLIENT_CERT_ALIAS_COLUMN); mCredentialKey = cursor.getLong(CONTENT_CREDENTIAL_KEY_COLUMN); if (mCredentialKey != -1) { mFlags |= FLAG_OAUTH; } }
From source file:com.baohume.browser.BookmarksPageCallbacks.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { BookmarkExpandableView.BookmarkContextMenuInfo info = (BookmarkExpandableView.BookmarkContextMenuInfo) menuInfo; BrowserBookmarksAdapter adapter = getChildAdapter(info.groupPosition); Cursor cursor = adapter.getItem(info.childPosition); if (!canEdit(cursor)) { return;/* w w w. j a v a 2s . c o m*/ } boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; final Activity activity = getActivity(); MenuInflater inflater = activity.getMenuInflater(); inflater.inflate(R.menu.bookmarkscontext, menu); if (isFolder) { menu.setGroupVisible(R.id.FOLDER_CONTEXT_MENU, true); } else { menu.setGroupVisible(R.id.BOOKMARK_CONTEXT_MENU, true); if (mDisableNewWindow) { menu.findItem(R.id.new_window_context_menu_id).setVisible(false); } } BookmarkItem header = new BookmarkItem(activity); header.setEnableScrolling(true); populateBookmarkItem(cursor, header, isFolder); menu.setHeaderView(header); int count = menu.size(); for (int i = 0; i < count; i++) { menu.getItem(i).setOnMenuItemClickListener(mContextItemClickListener); } }
From source file:fr.free.nrw.commons.contributions.ContributionDao.java
public Contribution fromCursor(Cursor cursor) { // Hardcoding column positions! //Check that cursor has a value to avoid CursorIndexOutOfBoundsException if (cursor.getCount() > 0) { int index; if (cursor.getColumnIndex(Table.COLUMN_LICENSE) == -1) { index = 15;/* ww w. j a v a2 s.c o m*/ } else { index = cursor.getColumnIndex(Table.COLUMN_LICENSE); } Contribution contribution = new Contribution( uriForId(cursor.getInt(cursor.getColumnIndex(Table.COLUMN_ID))), cursor.getString(cursor.getColumnIndex(Table.COLUMN_FILENAME)), parseUri(cursor.getString(cursor.getColumnIndex(Table.COLUMN_LOCAL_URI))), cursor.getString(cursor.getColumnIndex(Table.COLUMN_IMAGE_URL)), parseTimestamp(cursor.getLong(cursor.getColumnIndex(Table.COLUMN_TIMESTAMP))), cursor.getInt(cursor.getColumnIndex(Table.COLUMN_STATE)), cursor.getLong(cursor.getColumnIndex(Table.COLUMN_LENGTH)), parseTimestamp(cursor.getLong(cursor.getColumnIndex(Table.COLUMN_UPLOADED))), cursor.getLong(cursor.getColumnIndex(Table.COLUMN_TRANSFERRED)), cursor.getString(cursor.getColumnIndex(Table.COLUMN_SOURCE)), cursor.getString(cursor.getColumnIndex(Table.COLUMN_DESCRIPTION)), cursor.getString(cursor.getColumnIndex(Table.COLUMN_CREATOR)), cursor.getInt(cursor.getColumnIndex(Table.COLUMN_MULTIPLE)) == 1, cursor.getInt(cursor.getColumnIndex(Table.COLUMN_WIDTH)), cursor.getInt(cursor.getColumnIndex(Table.COLUMN_HEIGHT)), cursor.getString(index)); String wikidataEntityId = cursor.getString(cursor.getColumnIndex(COLUMN_WIKI_DATA_ENTITY_ID)); if (!StringUtils.isBlank(wikidataEntityId)) { contribution.setWikiDataEntityId(wikidataEntityId); } return contribution; } return null; }
From source file:gov.wa.wsdot.android.wsdot.service.MountainPassesSyncService.java
/** * Check the mountain pass table for any starred entries. If we find some, save them * to a list so we can re-star those passes after we flush the database. *//*from www . j av a 2s. c o m*/ private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(MountainPasses.CONTENT_URI, new String[] { MountainPasses.MOUNTAIN_PASS_ID }, MountainPasses.MOUNTAIN_PASS_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:com.zoterodroid.activity.BrowseCitations.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.browse_bookmarks); mAccountManager = AccountManager.get(this); mAccount = mAccountManager.getAccountsByType(Constants.ACCOUNT_TYPE)[0]; mContext = this; Log.d("browse bookmarks", getIntent().getDataString()); Uri data = getIntent().getData();// ww w.j a v a 2 s . com String scheme = data.getScheme(); String path = data.getPath(); Log.d("path", path); String username = data.getQueryParameter("username"); String tagname = data.getQueryParameter("tagname"); String recent = data.getQueryParameter("recent"); myself = mAccount.name.equals(username); ArrayList<Citation> citationList = new ArrayList<Citation>(); if (scheme.equals("content") && path.equals("/citations") && myself) { try { String[] projection = new String[] { Citation._ID, Citation.Title, Citation.Key, Citation.Creator_Summary, Citation.Item_Type }; String selection = null; String sortorder = null; selection = Citation.Account + " = '" + username + "'"; Uri citations = Citation.CONTENT_URI; Cursor c = managedQuery(citations, projection, selection, null, sortorder); if (c.moveToFirst()) { int idColumn = c.getColumnIndex(Citation._ID); int titleColumn = c.getColumnIndex(Citation.Title); int keyColumn = c.getColumnIndex(Citation.Key); int creatorSummaryColumn = c.getColumnIndex(Citation.Creator_Summary); int itemTypeColumn = c.getColumnIndex(Citation.Item_Type); do { Citation b = new Citation(c.getInt(idColumn), c.getString(titleColumn), c.getString(keyColumn), c.getString(creatorSummaryColumn), c.getString(itemTypeColumn)); citationList.add(b); } while (c.moveToNext()); } setListAdapter(new CitationListAdapter(this, R.layout.bookmark_view, citationList)); } catch (Exception e) { } } lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } }); /* Add Context-Menu listener to the ListView. */ lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.setHeaderTitle("Actions"); if (myself) { menu.add(Menu.NONE, 0, Menu.NONE, "Delete"); } else { menu.add(Menu.NONE, 1, Menu.NONE, "Add"); } } }); }
From source file:com.cryart.sabbathschool.util.SSCore.java
public String ssTodaysDate() { if (SSCore.ssTodayDate == null) { String ssTodayTmp = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date()); SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery("SELECT COUNT(1) FROM ss_days, ss_lessons, ss_quarters " + "WHERE ss_days.day_date = ? AND ss_days.day_lesson_serial = ss_lessons.serial " + " AND ss_lessons.lesson_quarter_serial = ss_quarters.serial " + " AND ss_quarters.quarter_lang = ?", new String[] { ssTodayTmp, LANGUAGE }); c.moveToFirst();/* w ww .j ava 2s. c om*/ int count = c.getInt(0); c.close(); if (count < 1) { c = db.rawQuery( "SELECT ss_days.day_date " + "FROM ss_days, ss_lessons, ss_quarters " + "WHERE ss_days.day_lesson_serial = ss_lessons.serial " + " AND ss_lessons.lesson_quarter_serial = ss_quarters.serial " + " AND ss_quarters.quarter_lang = ? " + "ORDER BY ss_days.day_date DESC LIMIT 1", new String[] { LANGUAGE }); c.moveToFirst(); ssTodayTmp = c.getString(0); c.close(); } SSCore.ssTodayDate = ssTodayTmp; } return SSCore.ssTodayDate; }
From source file:com.flowzr.export.FlowzrIntegrationTest.java
public void test_push_attributes() throws Exception { if (dba.getAllCategories().getCount() == 2) { //only system categories Map<String, Category> categories = CategoryBuilder.createDefaultHierarchy(dba); FlowzrSyncEngine.fixCreatedEntities(); }/*from ww w . j av a2s. co m*/ FlowzrSyncEngine.pushUpdate("attributes", Attribute.class); JSONObject json = getJsonResponse( FlowzrSyncEngine.FLOWZR_API_URL + "admin_example.com/attributes/?last_sync_ts=0"); JSONArray arr = json.getJSONArray("attributes"); Cursor cursor = dba.getAllAttributes(); //minus two system attributes ??? assertEquals(valueOf(cursor.getCount()), valueOf(arr.length())); if (cursor.moveToFirst()) { do { Log.i("flowzr", "attr:" + cursor.getInt(0) + " " + cursor.getString(cursor.getColumnIndex("name")) + " " + cursor.getInt(cursor.getColumnIndex("remote_key"))); // the view doesn't contains remote_key, the test is unoptimized Attribute c = dba.getAttribute(cursor.getInt(cursor.getColumnIndex("_id"))); //em.load(Attribute.class, cursor.getInt(cursor.getColumnIndex("_id"))); boolean gotIt = false; for (int i = 0; i < arr.length(); i++) { if (c.remoteKey.equals(arr.getJSONObject(i).getString("key"))) { Log.i("flowzr", "got attribute " + c.name); assertEquals(c.name, arr.getJSONObject(i).getString("name")); assertEquals(c.type, arr.getJSONObject(i).getInt("type")); if (c.listValues != null) { assertEquals(c.listValues, arr.getJSONObject(i).getString("list_values")); } if (c.defaultValue != null) { assertEquals(c.defaultValue, arr.getJSONObject(i).getString("default_value")); } gotIt = true; } } //is the object find ? assertTrue(gotIt); } while (cursor.moveToNext()); } cursor.close(); }
From source file:me.myatminsoe.myansms.Message.java
/** * Update {@link Message}./*from w w w.j a v a 2 s. co m*/ * * @param cursor {@link Cursor} to read from */ public void update(final Cursor cursor) { read = cursor.getInt(INDEX_READ); type = cursor.getInt(INDEX_TYPE); try { if (cursor.getColumnCount() > INDEX_MTYPE) { final int t = cursor.getInt(INDEX_MTYPE); if (t != 0) { type = t; } } } catch (IllegalStateException e) { Log.e(TAG, "wrong projection?", e); } }