List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:fr.enst.igr201.kanmogne.iconvert.ConvertTabFragment.java
private double queryCurrencyTable(Uri uri) { Log.wtf(TAG, "URI : -> " + CurrencyContract.Currency.getCurrencyNameFromURI(uri)); double rate = 0.0; String[] projection = { CurrencyContract.Currency.COLUMN_RATE }; String selection = String.format("%s.%s = ?", CurrencyContract.Currency.TABLE_CURRENCY, CurrencyContract.Currency.COLUMN_NAME); // Log.wtf(TAG, "getNameFromURI : -> " + CurrencyContract.Currency.getCurrencyNameFromURI(uri)); String[] selectionArgs = { CurrencyContract.Currency.getCurrencyNameFromURI(uri) }; Cursor cursor = mResolver.query(uri, projection, selection, selectionArgs, null); try {//from w w w . j a v a 2 s. co m if (cursor.moveToFirst()) { int rateIndex = cursor.getColumnIndex(CurrencyContract.Currency.COLUMN_RATE); rate = cursor.getDouble(rateIndex); } } finally { cursor.close(); } // Log.wtf(TAG, "Rate : -->>" + rate); return rate; }
From source file:net.naonedbus.manager.impl.FavoriManager.java
@Override public Favori getSingleFromCursor(final Cursor c) { mBuilder.setId(c.getInt(c.getColumnIndex(FavoriTable._ID))); mBuilder.setCodeLigne(c.getString(c.getColumnIndex(FavoriTable.CODE_LIGNE))); mBuilder.setCodeSens(c.getString(c.getColumnIndex(FavoriTable.CODE_SENS))); mBuilder.setCodeArret(c.getString(c.getColumnIndex(FavoriTable.CODE_ARRET))); mBuilder.setNomArret(c.getString(c.getColumnIndex(FavoriTable.NOM))); mBuilder.setNomFavori(null);/* ww w . j a va 2s .c o m*/ mBuilder.setCouleurBackground(0); mBuilder.setCouleurTexte(0); mBuilder.setNomSens(null); mBuilder.setLettre(null); return mBuilder.build(); }
From source file:net.naonedbus.manager.impl.FavoriManager.java
public Favori getSingleFromCursorFull(final Cursor c) { mBuilder.setId(c.getInt(c.getColumnIndex(FavoriTable._ID))); mBuilder.setCodeLigne(c.getString(c.getColumnIndex(FavoriTable.CODE_LIGNE))); mBuilder.setCodeSens(c.getString(c.getColumnIndex(FavoriTable.CODE_SENS))); mBuilder.setCodeArret(c.getString(c.getColumnIndex(FavoriTable.CODE_ARRET))); mBuilder.setNomFavori(c.getString(c.getColumnIndex(FavoriTable.NOM))); mBuilder.setNomArret(c.getString(c.getColumnIndex(EquipementTable.NOM))); final int couleurBackground = c.getInt(c.getColumnIndex(LigneTable.COULEUR_BACK)); final int couleurFront = c.getInt(c.getColumnIndex(LigneTable.COULEUR_FRONT)); mBuilder.setCouleurBackground(couleurBackground); mBuilder.setCouleurTexte(couleurFront); mBuilder.setNomSens(c.getString(c.getColumnIndex(SensTable.NOM))); mBuilder.setLettre(c.getString(c.getColumnIndex(LigneTable.LETTRE))); return mBuilder.build(); }
From source file:edu.htl3r.schoolplanner.backend.database.AutoSelectDatabase.java
@Override public AutoSelectSet getAutoSelect() { AutoSelectSet autoSelectSet = new AutoSelectSet(); SQLiteDatabase database = this.database.openDatabase(false); Cursor query = this.database.queryWithLoginSetKey(database, DatabaseAutoSelectConstants.TABLE_AUTO_SELECT_NAME); Assert.isTrue(query.getCount() <= 1, "More than one auto-select entry for " + this.database.getLoginSetKeyForTable() + "."); int indexEnabled = query.getColumnIndex(DatabaseAutoSelectConstants.ENABLED); int indexType = query.getColumnIndex(DatabaseAutoSelectConstants.TYPE); int indexValue = query.getColumnIndex(DatabaseAutoSelectConstants.VALUE); while (query.moveToNext()) { boolean enabled = query.getInt(indexEnabled) > 0; String type = query.getString(indexType); int value = query.getInt(indexValue); autoSelectSet.setEnabled(enabled); autoSelectSet.setAutoSelectType(type); autoSelectSet.setAutoSelectValue(value); }/*from w ww . ja va 2s . c o m*/ query.close(); this.database.closeDatabase(database); return autoSelectSet; }
From source file:com.jaspersoft.android.jaspermobile.activities.profile.fragment.ServersFragment.java
@Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == cursor.getColumnIndex(ServerProfilesTable._ID)) { ImageView imageView = (ImageView) view; if (mServerProfile == null) { imageView.setImageResource(R.drawable.ic_composed_server); } else {/*from w w w. j a v a 2 s. co m*/ long entryId = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID)); imageView.setImageResource((mServerProfileId == entryId) ? R.drawable.ic_composed_active_server : R.drawable.ic_composed_server); } return true; } if (columnIndex == cursor.getColumnIndex(ServerProfilesTable.ALIAS)) { TextView textView = (TextView) view; String alias = cursor.getString(columnIndex); if (mServerProfile == null) { textView.setText(alias); } else { long entryId = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID)); boolean isItemActive = (mServerProfileId == entryId); textView.setText(isItemActive ? getString(R.string.sp_active_item, alias) : alias); } return true; } return false; }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java
public JSONArray getAlljsonData() { JSONArray jArray = new JSONArray(); String q = "SELECT * FROM " + LocalTransformationDB.TABLE_JSON_DATA_EXCHANGE + " ORDER BY " + LocalTransformationDB.COLUMN_JSON_ID + ";"; Cursor cursor = database.rawQuery(q, null); if (cursor.moveToFirst()) { do {// w w w. j a v a 2 s .c o m String contents = cursor.getString(cursor.getColumnIndex(LocalTransformationDB.COUMN_JSON_CONTENT)); int id = cursor.getInt(cursor.getColumnIndex(LocalTransformationDB.COLUMN_JSON_ID)); try { JSONObject jObj = new JSONObject(contents); jObj.put(JSONDataExchange.JSON_CONTENT_ID, id); jArray.put(jObj); } catch (JSONException e) { e.printStackTrace(); } } while (cursor.moveToNext()); } cursor.close(); return jArray; }
From source file:com.panoskrt.dbadapter.DBAdapter.java
public String getStringEntry(String column, String table, String match) { String text = null;/*from w ww.ja v a 2s . c o m*/ Cursor c = database.rawQuery( "SELECT " + column + " FROM " + table + " WHERE " + column + "=" + "'" + match + "'", null); if (c != null) { if (c.moveToFirst()) { text = c.getString(c.getColumnIndex(column)); } } return text; }
From source file:com.pureexe.calinoius.environment.camera.fragment.MainFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); dataManager = new DataManager(getActivity()); try {// w w w . ja v a 2 s.c om // Use Try catch Exception to avoid force close with CM's Privacy Guard Cursor c = getActivity().getApplication().getContentResolver() .query(ContactsContract.Profile.CONTENT_URI, null, null, null, null); c.moveToFirst(); dataManager.setString("Researcher", c.getString(c.getColumnIndex("display_name"))); } catch (Exception e) { dataManager.setString("Researcher", "Unknown"); } GridView gridview = (GridView) rootView.findViewById(R.id.gridView1); gridview.setAdapter(new HomePageAdapter(getActivity())); gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { if (position == 0) { Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class); beepActivity.setAction(Intent.ACTION_SEND); beepActivity.putExtra(Intent.EXTRA_TEXT, "UserFragment"); beepActivity.setType("beepActivity"); startActivity(beepActivity); } if (position == 1) { Intent intent = new Intent(getActivity(), EnvironmentCameraActivity.class); startActivity(intent); } if (position == 2) { Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class); beepActivity.setAction(Intent.ACTION_SEND); beepActivity.putExtra(Intent.EXTRA_TEXT, "EXIFreadFragment"); beepActivity.setType("beepActivity"); startActivity(beepActivity); } if (position == 3) { Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class); beepActivity.setAction(Intent.ACTION_SEND); beepActivity.putExtra(Intent.EXTRA_TEXT, "SettingPreferenceFragment"); beepActivity.setType("beepActivity"); startActivity(beepActivity); } if (position == 4) { Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class); beepActivity.setAction(Intent.ACTION_SEND); beepActivity.putExtra(Intent.EXTRA_TEXT, "HelpFragment"); beepActivity.setType("beepActivity"); startActivity(beepActivity); } if (position == 5) { Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class); beepActivity.setAction(Intent.ACTION_SEND); beepActivity.putExtra(Intent.EXTRA_TEXT, "AboutFragment"); beepActivity.setType("beepActivity"); startActivity(beepActivity); } } }); return rootView; }
From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.database.SignDAO.java
private Sign cursorToSign(Cursor cursor) { final Sign.Builder signBuilder = new Sign.Builder(); signBuilder.setId(cursor.getInt(cursor.getColumnIndex(DbContract.SignTable._ID))); signBuilder.setName(cursor.getString(cursor.getColumnIndex(DbContract.SignTable.COLUMN_NAME_SIGN_NAME))); signBuilder.setNameLocaleDe(/* w ww.j av a2 s . c om*/ cursor.getString(cursor.getColumnIndex(DbContract.SignTable.COLUMN_NAME_SIGN_NAME_DE))); signBuilder.setMnemonic(cursor.getString(cursor.getColumnIndex(DbContract.SignTable.COLUMN_NAME_MNEMONIC))); signBuilder.setLearningProgress( cursor.getInt(cursor.getColumnIndex(DbContract.SignTable.COLUMN_NAME_LEARNING_PROGRESS))); final int starred = cursor.getInt(cursor.getColumnIndex(DbContract.SignTable.COLUMN_NAME_STARRED)); if (1 == starred) { signBuilder.setStarred(true); } else { signBuilder.setStarred(false); } return signBuilder.create(); }
From source file:com.acrutiapps.browser.tasks.HistoryBookmarksExportTask.java
private String writeAsJSON(Cursor... params) { try {// ww w. j a v a 2 s . c o m String fileName = mContext.getString(R.string.ApplicationName) + "-" + getNowForFileName() + ".json"; File file = new File(Environment.getExternalStorageDirectory(), fileName); FileWriter writer = new FileWriter(file); FoldersJSONArray foldersArray = new FoldersJSONArray(); BookmarksJSONArray bookmarksArray = new BookmarksJSONArray(); HistoryJSONArray historyArray = new HistoryJSONArray(); Cursor c = params[0]; if (c.moveToFirst()) { int current = 0; int total = c.getCount(); int idIndex = c.getColumnIndex(BookmarksProvider.Columns._ID); int titleIndex = c.getColumnIndex(BookmarksProvider.Columns.TITLE); int urlIndex = c.getColumnIndex(BookmarksProvider.Columns.URL); int creationDateIndex = c.getColumnIndex(BookmarksProvider.Columns.CREATION_DATE); int visitedDateIndex = c.getColumnIndex(BookmarksProvider.Columns.VISITED_DATE); int visitsIndex = c.getColumnIndex(BookmarksProvider.Columns.VISITS); int bookmarkIndex = c.getColumnIndex(BookmarksProvider.Columns.BOOKMARK); int folderIndex = c.getColumnIndex(BookmarksProvider.Columns.IS_FOLDER); int parentfolderIdIndex = c.getColumnIndex(BookmarksProvider.Columns.PARENT_FOLDER_ID); while (!c.isAfterLast()) { publishProgress(1, current, total); boolean isFolder = c.getInt(folderIndex) > 0 ? true : false; if (isFolder) { String title = c.getString(titleIndex); title = title != null ? URLEncoder.encode(title, "UTF-8") : ""; foldersArray.add(title, c.getLong(idIndex), c.getLong(parentfolderIdIndex)); } else { boolean isBookmark = c.getInt(bookmarkIndex) > 0 ? true : false; String title = c.getString(titleIndex); title = title != null ? URLEncoder.encode(title, "UTF-8") : ""; String url = c.getString(urlIndex); url = url != null ? URLEncoder.encode(url, "UTF-8") : ""; if (isBookmark) { bookmarksArray.add(c.getLong(parentfolderIdIndex), title, url, c.getLong(creationDateIndex), c.getLong(visitedDateIndex), c.getInt(visitsIndex)); } else { historyArray.add(title, url, c.getLong(visitedDateIndex), c.getInt(visitsIndex)); } } current++; c.moveToNext(); } } JSONObject output = new JSONObject(); output.put("folders", foldersArray); output.put("bookmarks", bookmarksArray); output.put("history", historyArray); writer.write(output.toString(1)); writer.flush(); writer.close(); } catch (JSONException e) { e.printStackTrace(); return e.getMessage(); } catch (IOException e) { e.printStackTrace(); return e.getMessage(); } return null; }