List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java
private Transformation cursorToTransformation(Cursor cursor, int position) { if (cursor.moveToPosition(position)) { Transformation transformation = new Transformation( cursor.getLong(cursor.getColumnIndex(LocalTransformationDB.COLUMN_BUNDLE_ID)), cursor.getString(cursor.getColumnIndex(LocalTransformationDB.COLUMN_TRANSFORMATION_NAME)), cursor.getString(cursor.getColumnIndex(LocalTransformationDB.COLUMN_PRODUCED_EVENT_TYPE)), cursor.getInt(cursor.getColumnIndex(LocalTransformationDB.COLUMN_TRANSFORMATION_COSTS))); String requiredEventTypes = cursor .getString(cursor.getColumnIndex(LocalTransformationDB.COLUMN_REQUIRED_EVENT_TYPES)); String[] types = requiredEventTypes.split(";"); for (String type : types) { if (D) Log.d(TAG, "required event type: " + type); transformation.addRequiredEvent(type); }/*from w w w . j a v a2 s. c o m*/ return transformation; } else return null; }
From source file:br.com.oromar.dev.android.sunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city * @param lon the longitude of the city * @return the row ID of the added location. *//*from ww w . j a va 2s. co m*/ public long addLocation(String locationSetting, String cityName, double lat, double lon) { long id = 0; // Students: First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, // Uri null, //projection WeatherContract.LocationEntry.CITY_NAME + " = ?", //selection new String[] { cityName }, //selectionArgs null);//sortBy // If it exists, return the current ID if (cursor.moveToFirst()) { id = cursor.getInt(cursor.getColumnIndex("_id")); // Otherwise, insert it using the content resolver and the base URI } else { ContentValues contentValues = new ContentValues(); contentValues.put(WeatherContract.LocationEntry.LOCATION_SETTING, locationSetting); contentValues.put(WeatherContract.LocationEntry.CITY_NAME, cityName); contentValues.put(WeatherContract.LocationEntry.COORD_LAT, lat); contentValues.put(WeatherContract.LocationEntry.COORD_LONG, lon); Uri uri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues); id = Integer.valueOf(uri.getPathSegments().get(1)); } return id; }
From source file:fi.mikuz.boarder.gui.internet.InternetMenu.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.internet_menu); setTitle("Internet Menu"); this.setVolumeControlStream(AudioManager.STREAM_MUSIC); mWaitDialog = new TimeoutProgressDialog(this, "Waiting for response", TAG, true); mInternetDownload = (Button) findViewById(R.id.internet_download); mInternetRegisterSettings = (Button) findViewById(R.id.internet_register_settings); mInternetLoginLogout = (Button) findViewById(R.id.internet_login_logout); mInternetUploads = (Button) findViewById(R.id.internet_uploads); mInternetFavorites = (Button) findViewById(R.id.internet_favorites); mAccountMessage = (TextView) findViewById(R.id.account_message_text); mDbHelper = new LoginDbAdapter(this); mDbHelper.open();//from w ww . j av a 2 s . com mGlobalVariableDbHelper = new GlobalVariablesDbAdapter(this); mGlobalVariableDbHelper.open(); int dbTosVersion = 0; try { Cursor variableCursor = mGlobalVariableDbHelper.fetchVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY); startManagingCursor(variableCursor); dbTosVersion = variableCursor.getInt(variableCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA)); } catch (SQLException e) { mGlobalVariableDbHelper.createIntVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY, 0); Log.d(TAG, "Couldn't get tosVersion", e); } catch (CursorIndexOutOfBoundsException e) { mGlobalVariableDbHelper.createIntVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY, 0); Log.d(TAG, "Couldn't get tosVersion", e); } if (dbTosVersion < mTosVersion) { AlertDialog.Builder builder = new AlertDialog.Builder(InternetMenu.this); builder.setTitle("Terms of service"); builder.setMessage("Excited to get your hands on those sweet boards? - Good.\n\n" + "There are some terms you must agree to and follow to get things rolling smoothly;\n\n" + "You may only communicate in English in the Boarder Internet service.\n\n" + "An uploaded board may contain any languages. However, if the board is not 'in English' that must be visibly stated in the description.\n\n" + "You agree to always follow applicable laws when using Boarder.\n\n" + "Pornographic and other adult only material is not allowed.\n\n" + "You must be at least 13 years old to register to the Boarder Internet service.\n\n" + "You may never transmit anything or communicate a way that can be deemed offensive.\n\n" + "Don't make cheap copies of another users boards.\n\n" + "We can use material(s) publicly shared by you as promotional material.\n\n" + "We will suspend your Boarder releated accounts and/or remove your material from the Boarder service if you behave badly."); builder.setPositiveButton("Agree", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mGlobalVariableDbHelper.updateIntVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY, mTosVersion); } }); builder.setNegativeButton("Disagree", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { InternetMenu.this.finish(); } }); builder.setCancelable(false); builder.show(); } if (mLoginInfo == null) { try { String userId; String sessionToken; Cursor loginCursor = mDbHelper.fetchLogin(USER_ID_KEY); startManagingCursor(loginCursor); userId = loginCursor.getString(loginCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA)); loginCursor = mDbHelper.fetchLogin(SESSION_TOKEN_KEY); startManagingCursor(loginCursor); sessionToken = loginCursor.getString(loginCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA)); mLoginInfo = new HashMap<String, String>(); mLoginInfo.put(USER_ID_KEY, userId); mLoginInfo.put(SESSION_TOKEN_KEY, sessionToken); sendDonationInfo(); mSessionValidityChecked = false; checkSessionValidity(); } catch (CursorIndexOutOfBoundsException e) { Log.d(TAG, "Couldn't get database session info", e); mSessionValidityChecked = true; } } getVersionInfo(); // Keep under login stuff mInternetDownload.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(InternetMenu.this, DownloadBoardList.class); i.putExtra(LOGIN_KEY, mLoginInfo); startActivity(i); } }); mInternetRegisterSettings.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (mInternetRegisterSettings.getText().toString().equals(SETTINGS_TEXT)) { Intent i = new Intent(InternetMenu.this, Settings.class); i.putExtra(LOGIN_KEY, mLoginInfo); startActivityForResult(i, LOGIN_RETURN); } else { Intent i = new Intent(InternetMenu.this, Register.class); startActivity(i); } } }); mInternetLoginLogout.setOnClickListener(new OnClickListener() { public void onClick(View v) { startLogin(); } }); mInternetUploads.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(InternetMenu.this, Uploads.class); i.putExtra(LOGIN_KEY, mLoginInfo); startActivityForResult(i, LOGIN_RETURN); } }); mInternetFavorites.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(InternetMenu.this, Favorites.class); i.putExtra(LOGIN_KEY, mLoginInfo); startActivityForResult(i, LOGIN_RETURN); } }); }
From source file:com.dileepindia.cordova.sms.SMSPlugin.java
private PluginResult deleteSMS(JSONObject filter, CallbackContext callbackContext) { Log.d("SMSPlugin", "deleteSMS"); String uri_filter = filter.has("box") ? filter.optString("box") : "inbox"; int fread = filter.has("read") ? filter.optInt("read") : -1; int fid = filter.has("_id") ? filter.optInt("_id") : -1; String faddress = filter.optString("address"); String fcontent = filter.optString("body"); Context ctx = this.cordova.getActivity(); int n = 0;//from w ww. j a v a 2s .c o m try { Uri uri = Uri.parse("content://sms/" + uri_filter); Cursor cur = ctx.getContentResolver().query(uri, null, "", null, null); while (cur.moveToNext()) { int id = cur.getInt(cur.getColumnIndex("_id")); boolean matchId = (fid > -1) && (fid == id); int read = cur.getInt(cur.getColumnIndex("read")); boolean matchRead = (fread > -1) && (fread == read); String address = cur.getString(cur.getColumnIndex("address")).trim(); boolean matchAddr = (faddress.length() > 0) && (address.equals(faddress)); String body = cur.getString(cur.getColumnIndex("body")).trim(); boolean matchContent = (fcontent.length() > 0) && (body.equals(fcontent)); if ((matchId) || (matchRead) || (matchAddr) || (matchContent)) { ctx.getContentResolver().delete(uri, "_id=" + id, null); n++; } } callbackContext.success(n); } catch (Exception e) { callbackContext.error(e.toString()); } return null; }
From source file:com.zsxj.pda.ui.client.LoginActivity.java
private boolean downloading() { DownloadManager.Query query = new DownloadManager.Query(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); long downloadId = prefs.getLong(PrefKeys.DOWNLOAD_ID, 0); query.setFilterById(downloadId);/*from w w w . j a v a2 s .co m*/ DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = dm.query(query); if (c.moveToNext()) { int statusIdx = c.getColumnIndex(DownloadManager.COLUMN_STATUS); int status = c.getInt(statusIdx); if (DownloadManager.STATUS_RUNNING == status) { return true; } } return false; }
From source file:com.onesignal.GenerateNotification.java
static void createSummaryNotification(Context inContext, boolean updateSummary, JSONObject gcmBundle) { if (updateSummary) setStatics(inContext);/*from www . j a v a 2 s .c om*/ String group = null; try { group = gcmBundle.getString("grp"); } catch (Throwable t) { } Random random = new Random(); PendingIntent summaryDeleteIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseDeleteIntent(0).putExtra("summary", group)); OneSignalDbHelper dbHelper = new OneSignalDbHelper(currentContext); SQLiteDatabase writableDb = dbHelper.getWritableDatabase(); String[] retColumn = { NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, NotificationTable.COLUMN_NAME_FULL_DATA, NotificationTable.COLUMN_NAME_IS_SUMMARY, NotificationTable.COLUMN_NAME_TITLE, NotificationTable.COLUMN_NAME_MESSAGE }; String[] whereArgs = { group }; Cursor cursor = writableDb.query(NotificationTable.TABLE_NAME, retColumn, NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + // Where String NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED + " = 0", whereArgs, null, // group by null, // filter by row groups NotificationTable._ID + " DESC" // sort order, new to old ); Notification summaryNotification; int summaryNotificationId = random.nextInt(); String firstFullData = null; Collection<SpannableString> summeryList = null; if (cursor.moveToFirst()) { SpannableString spannableString; summeryList = new ArrayList<SpannableString>(); do { if (cursor.getInt(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_IS_SUMMARY)) == 1) summaryNotificationId = cursor .getInt(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID)); else { String title = cursor.getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_TITLE)); if (title == null) title = ""; else title += " "; // Html.fromHtml("<strong>" + line1Title + "</strong> " + gcmBundle.getString("alert")); String msg = cursor.getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_MESSAGE)); spannableString = new SpannableString(title + msg); if (title.length() > 0) spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, title.length(), 0); summeryList.add(spannableString); if (firstFullData == null) firstFullData = cursor .getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_FULL_DATA)); } } while (cursor.moveToNext()); if (updateSummary) { try { gcmBundle = new JSONObject(firstFullData); } catch (JSONException e) { e.printStackTrace(); } } } if (summeryList != null && (!updateSummary || summeryList.size() > 1)) { int notificationCount = summeryList.size() + (updateSummary ? 0 : 1); String summaryMessage = null; if (gcmBundle.has("grp_msg")) { try { summaryMessage = gcmBundle.getString("grp_msg").replace("$[notif_count]", "" + notificationCount); } catch (Throwable t) { } } if (summaryMessage == null) summaryMessage = notificationCount + " new messages"; JSONObject summaryDataBundle = new JSONObject(); try { summaryDataBundle.put("alert", summaryMessage); } catch (JSONException e) { e.printStackTrace(); } Intent summaryIntent = getNewBaseIntent(summaryNotificationId).putExtra("summary", group) .putExtra("onesignal_data", summaryDataBundle.toString()); PendingIntent summaryContentIntent = getNewActionPendingIntent(random.nextInt(), summaryIntent); NotificationCompat.Builder summeryBuilder = getBaseNotificationCompatBuilder(gcmBundle, !updateSummary); summeryBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent) .setContentTitle(currentContext.getPackageManager() .getApplicationLabel(currentContext.getApplicationInfo())) .setContentText(summaryMessage).setNumber(notificationCount).setOnlyAlertOnce(updateSummary) .setGroup(group).setGroupSummary(true); if (!updateSummary) summeryBuilder.setTicker(summaryMessage); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String line1Title = null; // Add the latest notification to the summary if (!updateSummary) { try { line1Title = gcmBundle.getString("title"); } catch (Throwable t) { } if (line1Title == null) line1Title = ""; else line1Title += " "; String message = ""; try { message = gcmBundle.getString("alert"); } catch (Throwable t) { } SpannableString spannableString = new SpannableString(line1Title + message); if (line1Title.length() > 0) spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, line1Title.length(), 0); inboxStyle.addLine(spannableString); } for (SpannableString line : summeryList) inboxStyle.addLine(line); inboxStyle.setBigContentTitle(summaryMessage); summeryBuilder.setStyle(inboxStyle); summaryNotification = summeryBuilder.build(); } else { // There currently isn't a visible notification from this group, save the group summary notification id and post it so it looks like a normal notification. ContentValues values = new ContentValues(); values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, summaryNotificationId); values.put(NotificationTable.COLUMN_NAME_GROUP_ID, group); values.put(NotificationTable.COLUMN_NAME_IS_SUMMARY, 1); writableDb.insert(NotificationTable.TABLE_NAME, null, values); NotificationCompat.Builder notifBuilder = getBaseNotificationCompatBuilder(gcmBundle, !updateSummary); PendingIntent summaryContentIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseIntent(summaryNotificationId).putExtra("onesignal_data", gcmBundle.toString()) .putExtra("summary", group)); addNotificationActionButtons(gcmBundle, notifBuilder, summaryNotificationId, group); notifBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent) .setOnlyAlertOnce(updateSummary).setGroup(group).setGroupSummary(true); summaryNotification = notifBuilder.build(); } NotificationManagerCompat.from(currentContext).notify(summaryNotificationId, summaryNotification); cursor.close(); writableDb.close(); }
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testInsert() throws Exception { Date currentDate = new Date(); GroupAccess groupAccess = new GroupAccess(1, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); groupAccess.setLastTokenRequest(currentDate); groupAccess.setLastUpdateFromServer(currentDate); groupAccess.setSynchronize(true);// w w w.j av a 2 s. c om groupAccess.setInterrupted(false); assertEquals(IGroupAuthAccessDbController.INSERTION_CODE.CORRECT, mGroupAuthAccessDbController.insert(groupAccess)); SQLiteDatabase db = mDbHelper.getReadableDatabase(); 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(false, interrupted); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastTokenRequestDate)); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastUpdateDate)); assertEquals("fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds.", token); }
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testUpdateToken() 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); assertTrue(mGroupAuthAccessDbController.updateToken(1, "fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds.")); 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();// w ww . ja v a2s . c om 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(false, interrupted); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastTokenRequestDate)); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastUpdateDate)); assertEquals("fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds.", token); }
From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java
private void openInNewWindow(BrowserBookmarksAdapter adapter, int position) { Cursor c = adapter.getItem(position); boolean isFolder = c.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) == 1; if (isFolder) { long id = c.getLong(BookmarksLoader.COLUMN_INDEX_ID); new OpenAllInTabsTask(id).execute(); } else {//from ww w . ja v a 2 s .c om onOpenInNewWindow(BrowserBookmarksPage.getUrl(c)); } }
From source file:com.seneca.android.senfitbeta.DbHelper.java
public ArrayList<Muscle> getMuscles() { Log.d("MUSCLE_GET", "Geting muscles"); String fetchMus = "select * from " + RIP_TABLE + " ORDER BY " + RIP_NAME + " ASC"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(fetchMus, null); cursor.moveToFirst();// w w w . j a v a2 s . c o m if (cursor == null) { Log.d("exiting", "NOTHING"); } if (cursor.getCount() == 0) { Log.d("NOTHING", "0 nothing"); } ArrayList<Muscle> temp = new ArrayList<Muscle>(); cursor.moveToFirst(); do { Muscle ex = new Muscle(); ex.setId(cursor.getInt(cursor.getColumnIndex(RIP_ID))); ex.setName(cursor.getString(cursor.getColumnIndex(RIP_NAME))); temp.add(ex); } while (cursor.moveToNext()); cursor.close(); getReadableDatabase().close(); return temp; }