List of usage examples for android.database Cursor getColumnCount
int getColumnCount();
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public List<String> getStatistics() { SQLiteDatabase db = DatabaseHelper.this.getWritableDatabase(); List<String> result = new ArrayList(); Cursor c = db.rawQuery("SELECT * FROM " + TABLE_STATISTICS + " WHERE " + KEY_ID + " = 1", null); if (c.moveToFirst()) { for (int i = 1; i < c.getColumnCount(); i++) { //omit column 0 result.add(filterName(c.getColumnName(i)) + ": " + c.getInt(i) + (c.getInt(i) == 1 ? " time." : " times.")); }//from ww w . j a v a2s .c o m } return result; }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java
private static JSONObject cursorToDict(String tableName, Cursor c) { int totalColumn = c.getColumnCount(); JSONObject rowObject = new JSONObject(); if (c.getColumnIndex("_id") != -1) { try {//ww w .ja va2s . co m rowObject.put("_id", c.getInt(c.getColumnIndex("_id"))); } catch (JSONException e) { e.printStackTrace(); } } for (int i = 0; i < totalColumn; i++) { if (c.getColumnName(i) != null) { String colName = c.getColumnName(i); try { if (c.getString(i) != null) { if (colName.endsWith("_id") || colName.equals("parent")) { if (tableName.equals(DatabaseHelper.BUDGET_TABLE)) { if (colName.equals("parent_budget_id")) { rowObject.put(colName, c.getInt(i)); } else if (!colName.equals("_id")) { String[] entities = c.getString(c.getColumnIndex(colName)).split(","); String keys = ""; for (String entity_id2 : entities) { keys += getRemoteKey(getTableForColName(colName), entity_id2) + ","; } if (keys.endsWith(",")) { keys = keys.substring(0, keys.length() - 1); } rowObject.put(colName, keys); } } else { if (!colName.equals("_id")) { String k = getRemoteKey(getTableForColName(colName), c.getString(i)); if (k != null) { rowObject.put(colName, k); } else { rowObject.put(colName, c.getInt(i)); } } } } else { rowObject.put(colName, c.getString(c.getColumnIndex(colName))); } /****/ if (tableName.equals(DatabaseHelper.ACCOUNT_TABLE)) { String sql = "select max(dateTime) as maxDate, min(dateTime) as minDate from " + DatabaseHelper.TRANSACTION_TABLE + " where from_account_id=" + c.getInt(c.getColumnIndex("_id")); Cursor c2 = db.rawQuery(sql, null); c2.moveToFirst(); rowObject.put("dateOfFirstTransaction", c2.getString(1)); rowObject.put("dateOfLastTransaction", c2.getString(0)); //each account can have a timezone so you can have a balance at closing day rowObject.put("tz", String.valueOf(TimeZone.getDefault().getRawOffset())); } else if (tableName.equals(DatabaseHelper.CATEGORY_TABLE)) { //load parent id Category cat = dba.getCategory(c.getInt(0)); // sql build/load parentId if (cat.getParentId() > 0) { Category pcat = em.load(Category.class, cat.getParentId()); rowObject.put("parent", pcat.remoteKey); rowObject.put("parent_id", pcat.id); } String attrPushString = ""; for (Attribute attr : dba.getAttributesForCategory(c.getInt(0))) { attrPushString = attrPushString + attr.remoteKey + ";"; } if (attrPushString != "") { rowObject.put("attributes", attrPushString); } } else if (tableName.equals(DatabaseHelper.TRANSACTION_TABLE)) { Map<Long, String> attributesMap = dba.getAllAttributesForTransaction(c.getInt(0)); String transaction_attribute = ""; for (long attributeId : attributesMap.keySet()) { transaction_attribute += dba.getAttribute(attributeId).remoteKey + "=" + attributesMap.get(attributeId) + ";"; } rowObject.put("transaction_attribute", transaction_attribute); } /****/ } else { rowObject.put(colName, ""); } } catch (JSONException e) { Log.d(TAG, e.getMessage()); } } } return rowObject; }
From source file:com.ichi2.anki.tests.ContentProviderTest.java
/** * Test that a query for all the notes added in setup() looks correct */// w w w . j av a 2 s.c o m public void testQueryNoteIds() { final ContentResolver cr = getContext().getContentResolver(); // Query all available notes final Cursor allNotesCursor = cr.query(FlashCardsContract.Note.CONTENT_URI, null, "tag:" + TEST_TAG, null, null); assertNotNull(allNotesCursor); try { assertEquals("Check number of results", mCreatedNotes.size(), allNotesCursor.getCount()); while (allNotesCursor.moveToNext()) { // Check that it's possible to leave out columns from the projection for (int i = 0; i < FlashCardsContract.Note.DEFAULT_PROJECTION.length; i++) { String[] projection = removeFromProjection(FlashCardsContract.Note.DEFAULT_PROJECTION, i); String noteId = allNotesCursor .getString(allNotesCursor.getColumnIndex(FlashCardsContract.Note._ID)); Uri noteUri = Uri.withAppendedPath(FlashCardsContract.Note.CONTENT_URI, noteId); final Cursor singleNoteCursor = cr.query(noteUri, projection, null, null, null); assertNotNull("Check that there is a valid cursor for detail data", singleNoteCursor); try { assertEquals("Check that there is exactly one result", 1, singleNoteCursor.getCount()); assertTrue("Move to beginning of cursor after querying for detail data", singleNoteCursor.moveToFirst()); // Check columns assertEquals("Check column count", projection.length, singleNoteCursor.getColumnCount()); for (int j = 0; j < projection.length; j++) { assertEquals("Check column name " + j, projection[j], singleNoteCursor.getColumnName(j)); } } finally { singleNoteCursor.close(); } } } } finally { allNotesCursor.close(); } }
From source file:hu.fnf.devel.atlas.Atlas.java
private void setViewCategoryProperties(int page) { /*//from www.j a va 2s . co m * List LABEL */ TextView header = (TextView) findViewById(R.id.header_text_view); TextView newe = (TextView) findViewById(R.id.new_etwas_text); EditText newc = (EditText) findViewById(R.id.new_etwas); ContentResolver cr = getContentResolver(); Uri.Builder builder = new Builder(); builder.scheme("content"); builder.authority(AtlasData.DB_AUTHORITY); Cursor list = null; String[] projection = null; switch (page) { case AtlasData.PINCOME: newe.setText(getResources().getString(R.string.category) + ":"); newc.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS); builder.appendPath(AtlasData.TABLE_DATA); builder.appendPath("guess"); list = cr.query(builder.build(), AtlasData.DATA_COLUMNS, null, null, null); header.setText(getResources().getString(R.string.guess) + "(" + String.valueOf(list.getCount()) + ")"); list.close(); builder = new Builder(); builder.scheme("content"); builder.authority(AtlasData.DB_AUTHORITY); builder.appendPath(AtlasData.TABLE_DATA); projection = AtlasData.DATA_COLUMNS; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { Log.d("onCreate", "only toptask"); builder.appendPath("topguess"); } else { Log.d("onCreate", "all tasks"); builder.appendPath("guess"); } break; case AtlasData.PSUMMARY: newe.setText(getResources().getString(R.string.amount) + ":"); newc.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); builder.appendPath(AtlasData.TABLE_TRANSACTIONS); builder.appendPath("tasks"); list = cr.query(builder.build(), AtlasData.TRANSACTIONS_COLUMNS, null, null, null); header.setText(getResources().getString(R.string.tasks) + "(" + String.valueOf(list.getCount()) + ")"); list.close(); builder = new Builder(); builder.scheme("content"); builder.authority(AtlasData.DB_AUTHORITY); builder.appendPath(AtlasData.TABLE_TRANSACTIONS); projection = AtlasData.TRANSACTIONS_COLUMNS; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { Log.d("onCreate", "only toptask"); builder.appendPath("toptask"); } else { Log.d("onCreate", "all tasks"); builder.appendPath("tasks"); } break; case AtlasData.POUTCOME: newe.setText(getResources().getString(R.string.category) + ":"); newc.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS); builder.appendPath(AtlasData.TABLE_DATA); builder.appendPath("data"); list = cr.query(builder.build(), AtlasData.DATA_COLUMNS, null, null, null); header.setText(getResources().getString(R.string.data) + "(" + String.valueOf(list.getCount()) + ")"); list.close(); builder = new Builder(); builder.scheme("content"); builder.authority(AtlasData.DB_AUTHORITY); builder.appendPath(AtlasData.TABLE_DATA); projection = AtlasData.DATA_COLUMNS; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { Log.d("onCreate", "only toptask"); builder.appendPath("topdata"); } else { Log.d("onCreate", "all tasks"); builder.appendPath("data"); } break; default: Log.e("onPageSelected", "page?!: " + page); break; } header.setOnClickListener(onHeaderClickListener); Cursor tasks_result = cr.query(builder.build(), projection, null, null, null); DatabaseQueryAdapter ta = new DatabaseQueryAdapter(this, tasks_result, 0, builder.build().getPathSegments().get(0)); Log.d("onCreate", "result count: " + tasks_result.getColumnCount()); ListView lv = (ListView) findViewById(R.id.tasklist); lv.setAdapter(ta); }
From source file:com.clough.android.androiddbviewer.ADBVApplication.java
@Override public void onCreate() { super.onCreate(); // Getting user configured(custom) SQLiteOpenHelper instance. sqliteOpenHelper = getDataBase();/*www . j av a2s . c o m*/ // getDataBase() could return a null if (sqliteOpenHelper != null) { // Background operation of creating the server socket. new Thread(new Runnable() { @Override public void run() { try { // Server socket re create when device is being disconnected or // when AndroidDBViewer desktop application is being closed. // Creating server socket will exit when // android application runs in low memory or when // android application being terminated due some reasons. l1: while (flag) { serverSocket = new ServerSocket(1993); socket = serverSocket.accept(); br = new BufferedReader(new InputStreamReader(socket.getInputStream())); pw = new PrintWriter(socket.getOutputStream(), true); // Keeps a continuous communication between android application and // AndroidDBViewer desktop application through IO streams of the accepted socket connection. // There will be continuous data parsing between desktop application and android application. // Identification of device being disconnected or desktop application being closed will be determined // only when there is a NULL data being received. l2: while (flag) { // Format of the parsing data string is JSON, a content of a 'Data' instance String requestJSONString = br.readLine(); if (requestJSONString == null) { // Received a null response from desktop application, due to disconnecting the // device or closing the AndroidDBViewer desktop application. // Therefore, closing all current connections and streams to re create the server // socket so that desktop application can connect in it's next run. // Device disconnection doesn't produce an IOException. // Also, even after calling // socket.close(), socket.shutdownInput() and socket.shutdownOutput() // within a shutdown hook in desktop application, the socket connection // in this async task always gives // socket.isConnected() as 'true' , // socket.isClosed() as 'false' , // socket.isInputShutdown() as 'false' and // socket.isOutputShutdown() as 'false' . // But, bufferedReader.readLine() starts returning 'null' continuously. // So, inorder to desktop application to connect with the device again, // there should be a ServerSocket waiting to accept a socket connection, in device. closeConnection(); continue l1; } else { // Received a valid response from the desktop application. Data data; try { // Converting received request to a 'Data' instance. data = new Data(new JSONObject(requestJSONString)); int status = data.getStatus(); if (status == Data.CONNECTION_REQUEST) { // Very first request from desktop application to // establish the connection and setting the response as // connection being accepted. data.setStatus(Data.CONNECTION_ACCEPTED); } else if (status == Data.LIVE_CONNECTION) { // When there is no user interaction in desktop application, // data being passed from desktop application to android // application with the status of LIVE_CONNECTION, and the // same data send again to the desktop application from android application, // to notify that connection is still alive. // This exchange won't change until there is a request from // desktop application with a different status. } else if (status == Data.QUERY) { // Requesting to perform a query execution. String result = "No result"; try { // Performing select, insert, delete and update queries. Cursor cursor = sqliteOpenHelper.getWritableDatabase() .rawQuery(data.getQuery(), null); // Flag to identify the firs move of the cursor boolean firstTime = true; int columnCount = 0; // JSONArray to hold the all JSONObjects, created per every row // of the result returned, executing the given query. JSONArray jsonArray = new JSONArray(); // Moving the cursor to the next row of retrieved result // after executing the requested query. while (cursor.moveToNext()) { if (firstTime) { // Column count of the result returned, executing the given query. columnCount = cursor.getColumnCount(); firstTime = false; } // JOSNObject to hold the values of a single row JSONObject jsonObject = new JSONObject(); for (int i = 0; i < columnCount; i++) { int columnType = cursor.getType(i); String columnName = cursor.getColumnName(i); if (columnType == Cursor.FIELD_TYPE_STRING) { jsonObject.put(columnName, cursor.getString(i)); } else if (columnType == Cursor.FIELD_TYPE_BLOB) { jsonObject.put(columnName, cursor.getBlob(i).toString()); } else if (columnType == Cursor.FIELD_TYPE_FLOAT) { jsonObject.put(columnName, String.valueOf(cursor.getFloat(i))); } else if (columnType == Cursor.FIELD_TYPE_INTEGER) { jsonObject.put(columnName, String.valueOf(cursor.getInt(i))); } else if (columnType == Cursor.FIELD_TYPE_NULL) { jsonObject.put(columnName, "NULL"); } else { jsonObject.put(columnName, "invalid type"); } } jsonArray.put(jsonObject); } result = jsonArray.toString(); cursor.close(); } catch (Exception e) { // If SQL error is occurred when executing the requested query, // error content will be the response to the desktop application. StringWriter sw = new StringWriter(); PrintWriter epw = new PrintWriter(sw); e.printStackTrace(epw); result = sw.toString(); epw.close(); sw.close(); } finally { data.setResult(result); } } else if (status == Data.DEVICE_NAME) { // Requesting device information data.setResult(Build.BRAND + " " + Build.MODEL); } else if (status == Data.APPLICATION_ID) { // Requesting application id (package name) data.setResult(getPackageName()); } else if (status == Data.DATABASE_NAME) { // Requesting application database name. // Will provide the database name according // to the SQLiteOpenHelper user provided data.setResult(sqliteOpenHelper.getDatabaseName()); } else { // Unidentified request state. closeConnection(); continue l1; } String responseJSONString = data.toJSON().toString(); pw.println(responseJSONString); } catch (JSONException e) { // Response couldn't convert to a 'Data' instance. // Desktop application will be notified to close the application. closeConnection(); continue l1; } } } } } catch (IOException e) { // Cannot create a server socket. Letting background process to end. } } }).start(); } }
From source file:com.android.contacts.common.list.ContactListItemView.java
/** * Shows search snippet./*w ww . j a va 2 s . c o m*/ */ public void showSnippet(Cursor cursor, int summarySnippetColumnIndex) { if (cursor.getColumnCount() <= summarySnippetColumnIndex || !SearchSnippets.SNIPPET.equals(cursor.getColumnName(summarySnippetColumnIndex))) { setSnippet(null); return; } String snippet = cursor.getString(summarySnippetColumnIndex); // Do client side snippeting if provider didn't do it final Bundle extras = cursor.getExtras(); if (extras.getBoolean(ContactsContract.DEFERRED_SNIPPETING)) { final String query = extras.getString(ContactsContract.DEFERRED_SNIPPETING_QUERY); String displayName = null; int displayNameIndex = cursor.getColumnIndex(Contacts.DISPLAY_NAME); if (displayNameIndex >= 0) { displayName = cursor.getString(displayNameIndex); } snippet = updateSnippet(snippet, query, displayName); } else { if (snippet != null) { int from = 0; int to = snippet.length(); int start = snippet.indexOf(DefaultContactListAdapter.SNIPPET_START_MATCH); if (start == -1) { snippet = null; } else { int firstNl = snippet.lastIndexOf('\n', start); if (firstNl != -1) { from = firstNl + 1; } int end = snippet.lastIndexOf(DefaultContactListAdapter.SNIPPET_END_MATCH); if (end != -1) { int lastNl = snippet.indexOf('\n', end); if (lastNl != -1) { to = lastNl; } } StringBuilder sb = new StringBuilder(); for (int i = from; i < to; i++) { char c = snippet.charAt(i); if (c != DefaultContactListAdapter.SNIPPET_START_MATCH && c != DefaultContactListAdapter.SNIPPET_END_MATCH) { sb.append(c); } } snippet = sb.toString(); } } } setSnippet(snippet); }
From source file:me.myatminsoe.myansms.Message.java
/** * Default constructor./*from ww w. ja v a 2s . c o m*/ * * @param context {@link Context} to spawn the {@link SmileyParser}. * @param cursor {@link Cursor} to read the data */ private Message(final Context context, final Cursor cursor) { id = cursor.getLong(INDEX_ID); threadId = cursor.getLong(INDEX_THREADID); date = cursor.getLong(INDEX_DATE); if (date < ConversationListActivity.MIN_DATE) { date *= ConversationListActivity.MILLIS; } if (cursor.getColumnIndex(PROJECTION_JOIN[INDEX_TYPE]) >= 0) { address = cursor.getString(INDEX_ADDRESS); body = cursor.getString(INDEX_BODY); } else { body = null; address = null; } type = cursor.getInt(INDEX_TYPE); read = cursor.getInt(INDEX_READ); if (body == null) { isMms = true; try { fetchMmsParts(context); } catch (OutOfMemoryError e) { Log.e(TAG, "error loading parts", e); try { Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); } catch (Exception e1) { Log.e(TAG, "error creating Toast", e1); } } } else { isMms = false; } try { subject = cursor.getString(INDEX_SUBJECT); } catch (IllegalStateException e) { subject = null; } try { if (cursor.getColumnCount() > INDEX_MTYPE) { final int t = cursor.getInt(INDEX_MTYPE); if (t != 0) { type = t; } } } catch (IllegalStateException e) { subject = null; } // Log.d(TAG, "subject: ", subject); // Log.d(TAG, "body: ", body); // Log.d(TAG, "type: ", type); }
From source file:com.roamprocess1.roaming4world.ui.messages.MessageAdapter.java
@SuppressLint("SdCardPath") @Override//w w w. j a va 2 s. c om public void bindView(View view, Context context, Cursor cursor) { System.out.println("MessageAdapter.java in bindView() "); final MessageListItemViews tagView = (MessageListItemViews) view.getTag(); v = view; this.context = context; SipMessage msg = new SipMessage(cursor); // System.out.println("msg:"+msg); System.out.println("Cursor row count:" + cursor.getCount()); String number = msg.getRemoteNumber(); long date = msg.getDate(); String message = msg.getBodyContent(); subject = message; System.out.println("subject--" + subject); if (message.contains("[Offline message -") && !number.equals("sip:registrar@kamailio.org")) { System.out.println("offline message"); String[] finalMessage = message.split("]"); subject = finalMessage[finalMessage.length - 1]; } else { subject = message; } String errorTxt = msg.getErrorContent(); String mimeType = msg.getMimeType(); int type = msg.getType(); Log.setLogLevel(6); Log.d("Col count", cursor.getColumnCount() + " @"); String[] columnname = cursor.getColumnNames(); for (int i = 0; i < columnname.length; i++) { Log.d("columnname " + i, columnname[i] + " @"); Log.d(columnname[i], cursor.getString(cursor.getColumnIndex(columnname[i])) + " @"); } tv_msg_info = (TextView) view.findViewById(R.id.tv_msg_info); pb_uploading = (ProgressBar) view.findViewById(R.id.pb_uploading); String timestamp = ""; if (System.currentTimeMillis() - date > 1000 * 60 * 60 * 24) { // If it was recieved one day ago or more display relative // timestamp - SMS like behavior int flags = DateUtils.FORMAT_ABBREV_RELATIVE; timestamp = (String) DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags); } else { // If it has been recieved recently show time of reception - IM // like behavior timestamp = dateFormatter.format(new Date(date)); } tagView.dateView.setText(timestamp); // Delivery state if (type == SipMessage.MESSAGE_TYPE_QUEUED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.error_watch_not_send); tagView.deliveredIndicator.setContentDescription(""); } else if (type == SipMessage.MESSAGE_TYPE_FAILED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.error_watch_not_send); tagView.deliveredIndicator.setContentDescription(""); } else { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.todo_send); tagView.deliveredIndicator.setContentDescription(""); } if (TextUtils.isEmpty(errorTxt)) { tagView.errorView.setVisibility(View.GONE); } else { tagView.errorView.setVisibility(View.GONE); tagView.errorView.setText(errorTxt); } // Subject tagView.contentView.setText(formatMessage(number, subject, mimeType)); if (msg.isOutgoing()) { setPhotoSide(tagView, ArrowPosition.LEFT); LinearLayout linerLayout = (LinearLayout) view.findViewById(R.id.message_block); linerLayout.setBackgroundResource(R.drawable.chatedittextdesign); text_view = (TextView) view.findViewById(R.id.text_view); text_view.setTextColor(Color.BLACK); // Photo tagView.quickContactView.assignContactUri(personalInfo.contactContentUri); /* ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); */ System.out.println("msg adp out - 0"); String path = "/sdcard/R4W/ProfilePic/ProfilePic.png"; File user_imageFile = new File(path); if (user_imageFile.exists()) { try { if (bm != null) { // bm = null; } bm = BitmapFactory.decodeFile(path); bm = ImageHelperCircular.getRoundedCornerBitmap(bm, bm.getWidth()); tagView.quickContactView.getImageView().setImageBitmap(bm); } catch (Exception e) { // TODO: handle exception try { tagView.quickContactView.getImageView().setImageURI(Uri.parse(path)); } catch (Exception e2) { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); // TODO: handle exception } } } else { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); } outgoingImage(number); } else { setPhotoSide(tagView, ArrowPosition.RIGHT); LinearLayout linerLayout = (LinearLayout) view.findViewById(R.id.message_block); linerLayout.setBackgroundResource(R.drawable.messagebodyleft); // Contact CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, msg.getFullFrom()); text_view = (TextView) view.findViewById(R.id.text_view); text_view.setTextColor(Color.BLACK); pb_uploading.setVisibility(ProgressBar.GONE); // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); /* ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); */ System.out.println("msg adp in - 1"); String nu = stripNumber(number); String path = "/sdcard/R4W/ProfilePic/" + nu + ".png"; System.out.println("msg adp out - path=" + path); File user_imageFile = new File(path); if (user_imageFile.exists()) { try { if (bm != null) { // bm = null; } bm = BitmapFactory.decodeFile(path); bm = ImageHelperCircular.getRoundedCornerBitmap(bm, bm.getWidth()); tagView.quickContactView.getImageView().setImageBitmap(bm); } catch (Exception e) { // TODO: handle exception try { tagView.quickContactView.getImageView().setImageURI(Uri.parse(path)); } catch (Exception e2) { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); // TODO: handle exception } } } else { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); } incomingImage(); } }
From source file:ru.orangesoftware.financisto2.export.flowzr.FlowzrSyncEngine.java
private JSONObject cursorToDict(String tableName, Cursor c) { int totalColumn = c.getColumnCount(); JSONObject rowObject = new JSONObject(); if (c.getColumnIndex("_id") != -1) { try {// w w w. j a v a2 s .c o m rowObject.put("_id", c.getInt(c.getColumnIndex("_id"))); } catch (JSONException e) { e.printStackTrace(); } } for (int i = 0; i < totalColumn; i++) { if (c.getColumnName(i) != null) { String colName = c.getColumnName(i); try { if (c.getString(i) != null) { if (colName.endsWith("_id") || colName.equals("parent")) { if (tableName.equals(DatabaseHelper.BUDGET_TABLE)) { if (colName.equals("parent_budget_id")) { rowObject.put(colName, c.getInt(i)); } else if (!colName.equals("_id")) { String[] entities = c.getString(c.getColumnIndex(colName)).split(","); String keys = ""; for (String entity_id2 : entities) { keys += getRemoteKey(getTableForColName(colName), entity_id2) + ","; } if (keys.endsWith(",")) { keys = keys.substring(0, keys.length() - 1); } rowObject.put(colName, keys); } } else { if (!colName.equals("_id")) { String k = getRemoteKey(getTableForColName(colName), c.getString(i)); if (k != null) { rowObject.put(colName, k); } else { rowObject.put(colName, c.getInt(i)); } } } } else { rowObject.put(colName, c.getString(c.getColumnIndex(colName))); } /****/ if (tableName.equals(DatabaseHelper.ACCOUNT_TABLE)) { String sql = "select max(dateTime) as maxDate, min(dateTime) as minDate from " + DatabaseHelper.TRANSACTION_TABLE + " where from_account_id=" + c.getInt(c.getColumnIndex("_id")); Cursor c2 = db.rawQuery(sql, null); c2.moveToFirst(); rowObject.put("dateOfFirstTransaction", c2.getString(1)); rowObject.put("dateOfLastTransaction", c2.getString(0)); //each account can have a timezone so you can have a balance at closing day rowObject.put("tz", String.valueOf(TimeZone.getDefault().getRawOffset())); } else if (tableName.equals(DatabaseHelper.CATEGORY_TABLE)) { //load parent id Category cat = dba.getCategory(c.getInt(0)); // sql build/load parentId if (cat.getParentId() > KEY_CREATE) { Category pcat = dba.load(Category.class, cat.getParentId()); rowObject.put("parent", pcat.remoteKey); rowObject.put("parent_id", pcat.id); } String attrPushString = ""; for (Attribute attr : dba.getAttributesForCategory(c.getInt(0))) { attrPushString = attrPushString + attr.remoteKey + ";"; } if (attrPushString != "") { rowObject.put("attributes", attrPushString); } } else if (tableName.equals(DatabaseHelper.TRANSACTION_TABLE)) { Map<Long, String> attributesMap = dba.getAllAttributesForTransaction(c.getInt(0)); String transaction_attribute = ""; for (long attributeId : attributesMap.keySet()) { transaction_attribute += dba.get(Attribute.class, attributeId).remoteKey + "=" + attributesMap.get(attributeId) + ";"; } rowObject.put("transaction_attribute", transaction_attribute); } /****/ } else { rowObject.put(colName, ""); } } catch (JSONException e) { Log.d(TAG, e.getMessage()); } } } return rowObject; }
From source file:com.nnm.smsviet.Message.java
/** * Default constructor./*from www.j a va 2 s . c om*/ * * @param context * {@link Context} to spawn the {@link SmileyParser}. * @param cursor * {@link Cursor} to read the data */ private Message(final Context context, final Cursor cursor) { this.id = cursor.getLong(INDEX_ID); this.threadId = cursor.getLong(INDEX_THREADID); this.date = cursor.getLong(INDEX_DATE); if (this.date < ConversationListActivity.MIN_DATE) { this.date *= ConversationListActivity.MILLIS; } if (cursor.getColumnIndex(PROJECTION_JOIN[INDEX_TYPE]) >= 0) { this.address = cursor.getString(INDEX_ADDRESS); this.body = cursor.getString(INDEX_BODY); if (ConversationListActivity.showEmoticons && this.body != null) { this.body = SmileyParser.getInstance(context).addSmileySpans(this.body); } } else { this.body = null; this.address = null; } this.type = cursor.getInt(INDEX_TYPE); this.read = cursor.getInt(INDEX_READ); if (this.body == null) { this.isMms = true; try { this.fetchMmsParts(context); } catch (OutOfMemoryError e) { Log.e(TAG, "error loading parts", e); try { Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); } catch (Exception e1) { Log.e(TAG, "error creating Toast", e1); } } } else { this.isMms = false; } try { this.subject = cursor.getString(INDEX_SUBJECT); } catch (IllegalStateException e) { this.subject = null; } try { if (cursor.getColumnCount() > INDEX_MTYPE) { final int t = cursor.getInt(INDEX_MTYPE); if (t != 0) { this.type = t; } } } catch (IllegalStateException e) { this.subject = null; } Log.d(TAG, "threadId: " + this.threadId); Log.d(TAG, "address: " + this.address); // Log.d(TAG, "subject: " + this.subject); // Log.d(TAG, "body: " + this.body); // Log.d(TAG, "type: " + this.type); }