Example usage for android.content ContentValues getAsString

List of usage examples for android.content ContentValues getAsString

Introduction

In this page you can find the example usage for android.content ContentValues getAsString.

Prototype

public String getAsString(String key) 

Source Link

Document

Gets a value and converts it to a String.

Usage

From source file:org.opendatakit.services.forms.provider.FormsProvider.java

@Override
public synchronized int update(@NonNull Uri uri, ContentValues values, String where, String[] whereArgs) {
    possiblyWaitForContentProviderDebugger();

    List<String> segments = uri.getPathSegments();

    PatchedFilter pf = extractUriFeatures(uri, segments, where, whereArgs);
    WebLoggerIf logger = WebLogger.getLogger(pf.appName);

    /*/* w ww .  j av  a2  s.c  om*/
     * First, find out what records match this query. Replicate the 
     * ContentValues if there are multiple tableIds/formIds involved
     * and the contentValues do not have formId and tableId specified.
     * 
     * Otherwise, it is an error to specify the tableId or formId in
     * the ContentValues and have those not match the where results.
     * 
     */
    String contentTableId = (values != null && values.containsKey(FormsColumns.TABLE_ID))
            ? values.getAsString(FormsColumns.TABLE_ID)
            : null;
    String contentFormId = (values != null && values.containsKey(FormsColumns.FORM_ID))
            ? values.getAsString(FormsColumns.FORM_ID)
            : null;

    HashMap<FormSpec, HashMap<String, Object>> matchedValues = new HashMap<FormSpec, HashMap<String, Object>>();

    DbHandle dbHandleName = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface()
            .generateInternalUseDbHandle();
    OdkConnectionInterface db = null;
    try {
        // +1 referenceCount if db is returned (non-null)
        db = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface().getConnection(pf.appName,
                dbHandleName);
        db.beginTransactionNonExclusive();
        Cursor c = null;
        try {
            c = db.query(DatabaseConstants.FORMS_TABLE_NAME, null, pf.whereId, pf.whereIdArgs, null, null, null,
                    null);

            if (c == null) {
                throw new SQLException(
                        "FAILED Update of " + uri + " -- query for existing row did not return a cursor");
            }
            if (c.moveToFirst()) {
                int idxId = c.getColumnIndex(FormsColumns._ID);
                int idxTableId = c.getColumnIndex(FormsColumns.TABLE_ID);
                int idxFormId = c.getColumnIndex(FormsColumns.FORM_ID);

                Integer idValue = null;
                String tableIdValue = null;
                String formIdValue = null;

                do {
                    idValue = CursorUtils.getIndexAsType(c, Integer.class, idxId);
                    tableIdValue = CursorUtils.getIndexAsString(c, idxTableId);
                    formIdValue = CursorUtils.getIndexAsString(c, idxFormId);

                    if (contentTableId != null && !contentTableId.equals(tableIdValue)) {
                        throw new SQLException("Modification of tableId for an existing form is prohibited");
                    }
                    if (contentFormId != null && !contentFormId.equals(formIdValue)) {
                        throw new SQLException("Modification of formId for an existing form is prohibited");
                    }

                    HashMap<String, Object> cv = new HashMap<String, Object>();
                    if (values != null) {
                        for (String key : values.keySet()) {
                            cv.put(key, values.get(key));
                        }
                    }
                    cv.put(FormsColumns.TABLE_ID, tableIdValue);
                    cv.put(FormsColumns.FORM_ID, formIdValue);
                    for (int idx = 0; idx < c.getColumnCount(); ++idx) {
                        String colName = c.getColumnName(idx);
                        if (colName.equals(FormsColumns._ID)) {
                            // don't insert the PK
                            continue;
                        }

                        if (c.isNull(idx)) {
                            cv.put(colName, null);
                        } else {
                            // everything else, we control...
                            Class<?> dataType = CursorUtils.getIndexDataType(c, idx);
                            if (dataType == String.class) {
                                cv.put(colName, CursorUtils.getIndexAsString(c, idx));
                            } else if (dataType == Long.class) {
                                cv.put(colName, CursorUtils.getIndexAsType(c, Long.class, idx));
                            } else if (dataType == Double.class) {
                                cv.put(colName, CursorUtils.getIndexAsType(c, Double.class, idx));
                            }
                        }
                    }

                    FormSpec formSpec = patchUpValues(pf.appName, cv);
                    formSpec._id = idValue.toString();
                    formSpec.success = false;
                    matchedValues.put(formSpec, cv);

                } while (c.moveToNext());
            } else {
                // no match on where clause...
                return 0;
            }
        } finally {
            if (c != null && !c.isClosed()) {
                c.close();
            }
        }

        // go through the entries and update the database with these patched-up values...

        for (Entry<FormSpec, HashMap<String, Object>> e : matchedValues.entrySet()) {
            FormSpec fs = e.getKey();
            HashMap<String, Object> cv = e.getValue();

            if (db.update(DatabaseConstants.FORMS_TABLE_NAME, cv, FormsColumns._ID + "=?",
                    new String[] { fs._id }) > 0) {
                fs.success = true;
            }
        }
        db.setTransactionSuccessful();

    } catch (Exception e) {
        logger.w(t, "FAILED Update of " + uri + " -- query for existing row failed: " + e.toString());

        if (e instanceof SQLException) {
            throw (SQLException) e;
        } else {
            throw new SQLException(
                    "FAILED Update of " + uri + " -- query for existing row failed: " + e.toString());
        }
    } finally {
        if (db != null) {
            try {
                if (db.inTransaction()) {
                    db.endTransaction();
                }
            } finally {
                try {
                    db.releaseReference();
                } finally {
                    // this closes the connection
                    OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface()
                            .removeConnection(pf.appName, dbHandleName);
                }
            }
        }
    }

    int failureCount = 0;
    for (FormSpec fs : matchedValues.keySet()) {
        if (fs.success) {
            Uri formUri = Uri
                    .withAppendedPath(
                            Uri.withAppendedPath(Uri.withAppendedPath(
                                    Uri.parse("content://" + getFormsAuthority()), pf.appName), fs.tableId),
                            fs.formId);
            getContext().getContentResolver().notifyChange(formUri, null);
            Uri idUri = Uri.withAppendedPath(
                    Uri.withAppendedPath(Uri.parse("content://" + getFormsAuthority()), pf.appName), fs._id);
            getContext().getContentResolver().notifyChange(idUri, null);
        } else {
            ++failureCount;
        }
    }
    getContext().getContentResolver().notifyChange(uri, null);

    int count = matchedValues.size();
    if (failureCount != 0) {
        throw new SQLiteException(
                "Unable to update all forms (" + (count - failureCount) + " of " + count + " updated)");
    }
    return count;
}

From source file:com.money.manager.ex.common.AllDataListFragment.java

private Money getTotalFromCursor(Cursor cursor) {
    Money total = MoneyFactory.fromString("0");
    int originalPosition = cursor.getPosition();
    AllDataAdapter adapter = getAllDataAdapter();
    CurrencyService currencyService = new CurrencyService(getContext());
    int baseCurrencyId = currencyService.getBaseCurrencyId();
    ContentValues values = new ContentValues();

    int currencyId;
    Money amount;//  w w w.j a  v  a 2s .c  o m
    Money converted;
    String transType;
    TransactionTypes transactionType;

    cursor.moveToPosition(Constants.NOT_SET);

    while (cursor.moveToNext()) {
        values.clear();

        // Read needed data.
        DatabaseUtils.cursorStringToContentValues(cursor, adapter.TRANSACTIONTYPE, values);
        DatabaseUtils.cursorIntToContentValues(cursor, adapter.CURRENCYID, values);
        DatabaseUtils.cursorIntToContentValues(cursor, adapter.TOCURRENCYID, values);
        DatabaseUtils.cursorDoubleToCursorValues(cursor, adapter.AMOUNT, values);
        DatabaseUtils.cursorDoubleToCursorValues(cursor, adapter.TOAMOUNT, values);

        transType = values.getAsString(adapter.TRANSACTIONTYPE);
        transactionType = TransactionTypes.valueOf(transType);

        if (transactionType.equals(TransactionTypes.Transfer)) {
            currencyId = values.getAsInteger(adapter.TOCURRENCYID);
            amount = MoneyFactory.fromString(values.getAsString(adapter.TOAMOUNT));
        } else {
            currencyId = values.getAsInteger(adapter.CURRENCYID);
            amount = MoneyFactory.fromString(values.getAsString(adapter.AMOUNT));
        }

        converted = currencyService.doCurrencyExchange(baseCurrencyId, amount, currencyId);
        total = total.add(converted);
    }

    cursor.moveToPosition(originalPosition);

    return total;
}

From source file:org.frc836.database.DBSyncService.java

private void processPositions(JSONArray positions) {
    try {/*from ww  w .j  a va  2s  . c om*/
        for (int i = 0; i < positions.length(); i++) {
            JSONObject row = positions.getJSONObject(i);
            Action action = Action.UPDATE;
            if (row.getInt(POSITION_LU_Entry.COLUMN_NAME_INVALID) != 0) {
                action = Action.DELETE;
            }
            ContentValues vals = new ContentValues();
            vals.put(POSITION_LU_Entry.COLUMN_NAME_ID, row.getInt(POSITION_LU_Entry.COLUMN_NAME_ID));
            vals.put(POSITION_LU_Entry.COLUMN_NAME_POSITION,
                    row.getString(POSITION_LU_Entry.COLUMN_NAME_POSITION));
            vals.put(POSITION_LU_Entry.COLUMN_NAME_TIMESTAMP, DB.dateParser
                    .format(new Date(row.getLong(POSITION_LU_Entry.COLUMN_NAME_TIMESTAMP) * 1000)));

            // check if this entry exists already
            String[] projection = { POSITION_LU_Entry.COLUMN_NAME_POSITION };
            String[] where = { vals.getAsString(POSITION_LU_Entry.COLUMN_NAME_ID) };

            synchronized (ScoutingDBHelper.lock) {

                SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase();

                Cursor c = db.query(POSITION_LU_Entry.TABLE_NAME, projection, // select
                        POSITION_LU_Entry.COLUMN_NAME_ID + "=?", where, null, // don't
                        // group
                        null, // don't filter
                        null, // don't order
                        "0,1"); // limit to 1
                try {
                    if (!c.moveToFirst()) {
                        if (action == Action.UPDATE)
                            action = Action.INSERT;
                        else if (action == Action.DELETE)
                            action = Action.NOTHING;
                    }

                    switch (action) {
                    case UPDATE:
                        db.update(POSITION_LU_Entry.TABLE_NAME, vals, POSITION_LU_Entry.COLUMN_NAME_ID + " = ?",
                                where);
                        break;
                    case INSERT:
                        db.insert(POSITION_LU_Entry.TABLE_NAME, null, vals);
                        break;
                    case DELETE:
                        db.delete(POSITION_LU_Entry.TABLE_NAME, POSITION_LU_Entry.COLUMN_NAME_ID + " = ?",
                                where);
                        break;
                    default:
                    }
                } finally {
                    if (c != null)
                        c.close();
                    ScoutingDBHelper.getInstance().close();
                }
            }
        }
    } catch (JSONException e) {
        // TODO handle error
    }
}

From source file:th.in.ffc.person.visit.VisitAncPregnancyActivity.java

private void doSave() {
    EditTransaction et = beginTransaction();
    et.retrieveData(VisitAncPregnancy._PREGNO, PregNo, false, mMinPregNo, 99, mMinPregNo + "-99");
    if (et.canCommit()) {
        ContentValues cv = et.getContentValues();
        cv.put(VisitAncPregnancy._PCUCODEPERSON, getPcucodePerson());
        cv.put(VisitAncPregnancy._PID, getPid());
        cv.put(VisitAncPregnancy.LMP, lmp.getDate().toString());
        cv.put(VisitAncPregnancy.EDC, edc.getDate().toString());
        cv.put(VisitAncPregnancy.FP_BEFORE, FpBefore.getSelectionId());
        cv.put(VisitAncPregnancy.FIRST_ABNORMAL, FirstAbNormal.getSelectionId());
        cv.put(VisitAncPregnancy._DATEUPDATE, DateTime.getCurrentDateTime());

        Uri uri = null;//  ww  w .  ja  v a2 s.  c om
        Intent data = new Intent();
        if (mAction.equals(Action.INSERT)) {
            cv.put(VisitAncPregnancy.FIRST_DATE_CHECK, DateTime.getCurrentDate());
            uri = et.commit(VisitAncPregnancy.CONTENT_URI);
            Log.d("FFC", uri.toString());

            data.setAction(Action.INSERT);
            mAction = Action.EDIT;

        } else if (mAction.equals(Action.EDIT)) {
            uri = VisitAncPregnancy.getContentUri(getPid(), mPregNo);
            int count = et.commit(uri, null, null);
            Log.d(TAG, "edit=" + count);

            data.setAction(Action.EDIT);
        }

        data.setData(uri);
        data.putExtra(PregnancyColumns._PREGNO, cv.getAsString(VisitAncPregnancy._PREGNO));

        boolean success = doSaveRiskFragment();
        if (success) {
            this.setResult(RESULT_OK, data);
            this.finish();
        } else {
            this.mPregNo = PregNo.getText().toString();
            this.PregNo.setEnabled(false);
        }
    }
}

From source file:org.frc836.database.DBSyncService.java

private void processNotes(JSONArray notes) {
    try {//from  ww  w . j av  a 2s .com
        for (int i = 0; i < notes.length(); i++) {
            JSONObject row = notes.getJSONObject(i);
            Action action = Action.UPDATE;
            if (row.getInt(NOTES_OPTIONS_Entry.COLUMN_NAME_INVALID) != 0) {
                action = Action.DELETE;
            }
            ContentValues vals = new ContentValues();
            vals.put(NOTES_OPTIONS_Entry.COLUMN_NAME_ID, row.getInt(NOTES_OPTIONS_Entry.COLUMN_NAME_ID));
            vals.put(NOTES_OPTIONS_Entry.COLUMN_NAME_OPTION_TEXT,
                    row.getString(NOTES_OPTIONS_Entry.COLUMN_NAME_OPTION_TEXT));
            vals.put(NOTES_OPTIONS_Entry.COLUMN_NAME_TIMESTAMP, DB.dateParser
                    .format(new Date(row.getLong(NOTES_OPTIONS_Entry.COLUMN_NAME_TIMESTAMP) * 1000)));

            // check if this entry exists already
            String[] projection = { NOTES_OPTIONS_Entry.COLUMN_NAME_OPTION_TEXT };
            String[] where = { vals.getAsString(NOTES_OPTIONS_Entry.COLUMN_NAME_ID) };

            synchronized (ScoutingDBHelper.lock) {

                SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase();

                Cursor c = db.query(NOTES_OPTIONS_Entry.TABLE_NAME, projection, // select
                        NOTES_OPTIONS_Entry.COLUMN_NAME_ID + "=?", where, null, // don't
                        // group
                        null, // don't filter
                        null, // don't order
                        "0,1"); // limit to 1
                try {
                    if (!c.moveToFirst()) {
                        if (action == Action.UPDATE)
                            action = Action.INSERT;
                        else if (action == Action.DELETE)
                            action = Action.NOTHING;
                    }

                    switch (action) {
                    case UPDATE:
                        db.update(NOTES_OPTIONS_Entry.TABLE_NAME, vals,
                                NOTES_OPTIONS_Entry.COLUMN_NAME_ID + " = ?", where);
                        break;
                    case INSERT:
                        db.insert(NOTES_OPTIONS_Entry.TABLE_NAME, null, vals);
                        break;
                    case DELETE:
                        db.delete(NOTES_OPTIONS_Entry.TABLE_NAME, NOTES_OPTIONS_Entry.COLUMN_NAME_ID + " = ?",
                                where);
                        break;
                    default:
                    }
                } finally {
                    if (c != null)
                        c.close();
                    ScoutingDBHelper.getInstance().close();
                }
            }
        }
    } catch (JSONException e) {
        // TODO handle error
    }
}

From source file:th.in.ffc.person.visit.VisitDiagActivity.java

public void doSave() {

    boolean finishable = true;

    for (String code : getDeleteList()) {
        Uri uri = VisitDiag.getContentUriId(Long.parseLong(getVisitNo()), code);
        ContentResolver cr = getContentResolver();
        int count = cr.delete(uri, null, null);
        Log.d(TAG, "deleted diag count=" + count + " uri=" + uri.toString());
    }// ww w  .  j ava  2  s  .c  o m

    ArrayList<String> codeList = new ArrayList<String>();
    boolean check = mCheck.isChecked();
    for (String tag : getEditList()) {
        Log.d(TAG, "tag=" + tag);
        DiagFragment f = (DiagFragment) getSupportFragmentManager().findFragmentByTag(tag);
        if (f != null) {
            EditTransaction et = beginTransaction();
            f.onSave(et);

            if (!et.canCommit()) {
                finishable = false;
                break;
            }
            System.out.println("do add code");
            String code = et.getContentValues().getAsString(VisitDiag.CODE);
            if (isAddedCode(codeList, code)) {
                finishable = false;
                Toast.makeText(this, R.string.duplicate_drug, Toast.LENGTH_SHORT).show();
                break;
            } else
                codeList.add(code);

            ContentValues cv = et.getContentValues();
            cv.put(VisitDiag.NO, getVisitNo());
            cv.put(VisitDiag.CLINIC, mClinic.getSelectId());
            cv.put(VisitDiag.PCUCODE, getPcuCode());
            cv.put(VisitDiag.DATEUPDATE, DateTime.getCurrentDateTime());
            cv.put(VisitDiag.DOCTOR, getUser());
            if (check) {
                cv.put(VisitDiag.APPOINT_DATE, mAppoint.getDate().toString());
                cv.put(VisitDiag.APPOINT_TYPE, mAppointType.getSelectedItemPosition());
                check = false;
            }

            String action = f.action;
            if (action.equals(Action.INSERT)) {
                Uri insert = et.commit(VisitDiag.CONTENT_URI);
                f.action = Action.EDIT;
                f.key = code;
                Log.d(TAG, "insert diag=" + insert.toString());

                Answers.getInstance()
                        .logCustom(new CustomEvent("Diagnosis").putCustomAttribute("code", code)
                                .putCustomAttribute("type", cv.getAsString(VisitDiag.TYPE))
                                .putCustomAttribute("continue", f.conti ? "yes" : "no")
                                .putCustomAttribute("pcu", getPcuCode()).putCustomAttribute("user", getUser()));
            } else if (action.equals(Action.EDIT)) {
                Uri updateUri = VisitDiag.getContentUriId(Long.parseLong(getVisitNo()), f.key);
                int update = et.commit(updateUri, null, null);
                Log.d(TAG, "update drug=" + update + " uri=" + updateUri.toString());
            }
        }
    }
    if (finishable) {
        checkVisit506();
    }
}

From source file:org.frc836.database.DBSyncService.java

private void processWheelBase(JSONArray wheelBase) {
    try {//from www  .j  a v a2  s  .com
        for (int i = 0; i < wheelBase.length(); i++) {
            JSONObject row = wheelBase.getJSONObject(i);
            Action action = Action.UPDATE;
            if (row.getInt(WHEEL_BASE_LU_Entry.COLUMN_NAME_INVALID) != 0) {
                action = Action.DELETE;
            }
            ContentValues vals = new ContentValues();
            vals.put(WHEEL_BASE_LU_Entry.COLUMN_NAME_ID, row.getInt(WHEEL_BASE_LU_Entry.COLUMN_NAME_ID));
            vals.put(WHEEL_BASE_LU_Entry.COLUMN_NAME_WHEEL_BASE_DESC,
                    row.getString(WHEEL_BASE_LU_Entry.COLUMN_NAME_WHEEL_BASE_DESC));
            vals.put(WHEEL_BASE_LU_Entry.COLUMN_NAME_TIMESTAMP, DB.dateParser
                    .format(new Date(row.getLong(WHEEL_BASE_LU_Entry.COLUMN_NAME_TIMESTAMP) * 1000)));

            // check if this entry exists already
            String[] projection = { WHEEL_BASE_LU_Entry.COLUMN_NAME_WHEEL_BASE_DESC };
            String[] where = { vals.getAsString(WHEEL_BASE_LU_Entry.COLUMN_NAME_ID) };

            synchronized (ScoutingDBHelper.lock) {

                SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase();

                Cursor c = db.query(WHEEL_BASE_LU_Entry.TABLE_NAME, projection, // select
                        WHEEL_BASE_LU_Entry.COLUMN_NAME_ID + "=?", where, null, // don't
                        // group
                        null, // don't filter
                        null, // don't order
                        "0,1"); // limit to 1
                try {
                    if (!c.moveToFirst()) {
                        if (action == Action.UPDATE)
                            action = Action.INSERT;
                        else if (action == Action.DELETE)
                            action = Action.NOTHING;
                    }

                    switch (action) {
                    case UPDATE:
                        db.update(WHEEL_BASE_LU_Entry.TABLE_NAME, vals,
                                WHEEL_BASE_LU_Entry.COLUMN_NAME_ID + " = ?", where);
                        break;
                    case INSERT:
                        db.insert(WHEEL_BASE_LU_Entry.TABLE_NAME, null, vals);
                        break;
                    case DELETE:
                        db.delete(WHEEL_BASE_LU_Entry.TABLE_NAME, WHEEL_BASE_LU_Entry.COLUMN_NAME_ID + " = ?",
                                where);
                        break;
                    default:
                    }
                } finally {
                    if (c != null)
                        c.close();
                    ScoutingDBHelper.getInstance().close();
                }
            }
        }
    } catch (JSONException e) {
        // TODO handle error
    }
}

From source file:org.frc836.database.DBSyncService.java

private void processWheelType(JSONArray wheelType) {
    try {//w  w  w  . j ava 2  s .c  o  m
        for (int i = 0; i < wheelType.length(); i++) {
            JSONObject row = wheelType.getJSONObject(i);
            Action action = Action.UPDATE;
            if (row.getInt(WHEEL_TYPE_LU_Entry.COLUMN_NAME_INVALID) != 0) {
                action = Action.DELETE;
            }
            ContentValues vals = new ContentValues();
            vals.put(WHEEL_TYPE_LU_Entry.COLUMN_NAME_ID, row.getInt(WHEEL_TYPE_LU_Entry.COLUMN_NAME_ID));
            vals.put(WHEEL_TYPE_LU_Entry.COLUMN_NAME_WHEEL_TYPE_DESC,
                    row.getString(WHEEL_TYPE_LU_Entry.COLUMN_NAME_WHEEL_TYPE_DESC));
            vals.put(WHEEL_TYPE_LU_Entry.COLUMN_NAME_TIMESTAMP, DB.dateParser
                    .format(new Date(row.getLong(WHEEL_TYPE_LU_Entry.COLUMN_NAME_TIMESTAMP) * 1000)));

            // check if this entry exists already
            String[] projection = { WHEEL_TYPE_LU_Entry.COLUMN_NAME_WHEEL_TYPE_DESC };
            String[] where = { vals.getAsString(WHEEL_TYPE_LU_Entry.COLUMN_NAME_ID) };

            synchronized (ScoutingDBHelper.lock) {

                SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase();

                Cursor c = db.query(WHEEL_TYPE_LU_Entry.TABLE_NAME, projection, // select
                        WHEEL_TYPE_LU_Entry.COLUMN_NAME_ID + "=?", where, null, // don't
                        // group
                        null, // don't filter
                        null, // don't order
                        "0,1"); // limit to 1
                try {
                    if (!c.moveToFirst()) {
                        if (action == Action.UPDATE)
                            action = Action.INSERT;
                        else if (action == Action.DELETE)
                            action = Action.NOTHING;
                    }

                    switch (action) {
                    case UPDATE:
                        db.update(WHEEL_TYPE_LU_Entry.TABLE_NAME, vals,
                                WHEEL_TYPE_LU_Entry.COLUMN_NAME_ID + " = ?", where);
                        break;
                    case INSERT:
                        db.insert(WHEEL_TYPE_LU_Entry.TABLE_NAME, null, vals);
                        break;
                    case DELETE:
                        db.delete(WHEEL_TYPE_LU_Entry.TABLE_NAME, WHEEL_TYPE_LU_Entry.COLUMN_NAME_ID + " = ?",
                                where);
                        break;
                    default:
                    }
                } finally {
                    if (c != null)
                        c.close();
                    ScoutingDBHelper.getInstance().close();
                }
            }
        }
    } catch (JSONException e) {
        // TODO handle error
    }
}

From source file:com.roamprocess1.roaming4world.service.SipNotifications.java

public void showNotificationForMissedCall(ContentValues callLog) {
    int icon = android.R.drawable.stat_notify_missed_call;
    CharSequence tickerText = context.getText(R.string.missed_call);
    long when = System.currentTimeMillis();

    if (missedCallNotification == null) {
        missedCallNotification = new NotificationCompat.Builder(context);
        missedCallNotification.setSmallIcon(icon);
        missedCallNotification.setTicker(tickerText);
        missedCallNotification.setWhen(when);
        missedCallNotification.setOnlyAlertOnce(true);
        missedCallNotification.setAutoCancel(true);
        missedCallNotification.setDefaults(Notification.DEFAULT_ALL);
    }//from   w w w .ja  v  a2  s . c o  m

    System.out.println("showNotificationForMissedCall");
    Intent notificationIntent = new Intent("com.roamprocess1.roaming4world.R4wHome.R4w_ACTIVITY");

    //   Intent notificationIntent = new Intent(SipManager.ACTION_SIP_CALLLOG);
    System.out.println("Misscall Notification");
    //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    String remoteContact = callLog.getAsString(CallLog.Calls.NUMBER);
    System.out.println("remoteContact  vlaue " + remoteContact);

    String[] parts = remoteContact.split("@");
    String part1 = parts[0]; // 004
    String[] part3 = part1.split(":");
    String part5 = part3[1];
    System.out.println("part5 ==" + part5);

    long accId = callLog.getAsLong(SipManager.CALLLOG_PROFILE_ID_FIELD);
    missedCallNotification.setContentTitle(formatNotificationTitle(R.string.missed_call, accId));
    missedCallNotification.setContentText(formatRemoteContactString(part5));
    System.out.println("remoteContact  vlaue ==" + remoteContact);
    missedCallNotification.setContentIntent(contentIntent);

    notificationManager.notify(CALLLOG_NOTIF_ID, missedCallNotification.build());
}

From source file:com.openerp.orm.ORM.java

/**
 * Creates the./* w w  w . j  ava2s . co m*/
 * 
 * @param dbHelper
 *            the db helper
 * @param values
 *            the values
 * @return the int
 */
public int create(BaseDBHelper dbHelper, ContentValues data_values) {
    int newId = 0;
    ContentValues values = new ContentValues();
    if (data_values.containsKey("id")) {
        newId = data_values.getAsInteger("id");
    } else {
        newId = createRecordOnserver(dbHelper, data_values);
        data_values.put("id", newId);
    }

    for (Fields field : dbHelper.getColumns()) {
        values.put(field.getName(), data_values.getAsString(field.getName()));
    }

    values.put("oea_name", OpenERPAccountManager.currentUser(context).getAndroidName());

    // Handling Many2Many Records
    HashMap<String, Object> many2manycols = dbHelper.getMany2ManyColumns();
    for (String key : many2manycols.keySet()) {
        try {
            JSONArray m2mArray = new JSONArray(values.getAsString(key));
            Many2Many m2m = (Many2Many) many2manycols.get(key);
            createM2MRecords(values.getAsString("id"), m2mArray, key, dbHelper, m2m, values);
        } catch (Exception e) {
        }
        values.remove(key);
    }

    // Handling Many2One Record
    HashMap<String, Object> many2onecols = dbHelper.getMany2OneColumns();
    for (String key : many2onecols.keySet()) {
        try {
            if (!values.getAsString(key).equals("false")) {
                JSONArray m2oArray = new JSONArray(values.getAsString(key));
                values.put(key, many2oneRecord(m2oArray));
                List<Integer> list = new ArrayList<Integer>();
                int m2o_id = Integer.parseInt(many2oneRecord(m2oArray));
                list.add(m2o_id);
                BaseDBHelper m2oDb = ((Many2One) many2onecols.get(key)).getM2OObject();
                if (!m2oDb.hasRecord(m2oDb, m2o_id)) {
                    oe_obj.syncReferenceTables(m2oDb, list, false);
                }
            }
        } catch (Exception e) {
        }

    }

    SQLiteDatabase db = getWritableDatabase();
    db.insert(modelToTable(dbHelper.getModelName()), null, values);
    db.close();
    return newId;
}