Example usage for android.content ContentValues ContentValues

List of usage examples for android.content ContentValues ContentValues

Introduction

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

Prototype

public ContentValues() 

Source Link

Document

Creates an empty set of values using the default initial size

Usage

From source file:com.android.server.MaybeDatabaseHelper.java

public long setUrl(String packagename, String url) {
    Log.v(DBTAG, "packagename=" + packagename + " url=" + url);
    if (packagename == null || url == null) {
        return 0;
    }/* w w w .  jav  a 2s.  com*/
    Log.v(DBTAG, "packagename=" + packagename + " url=" + url);
    if (rowExists(packagename)) {
        Log.v(DBTAG, "Row exists");
        listTableContents(); //TODO: test- remove in final code
        return 0;
    }
    Log.v(DBTAG, "Row does not exist");
    listTableContents();
    long ret;

    synchronized (sAppTableLock) {
        final ContentValues c = new ContentValues();
        c.put(PACKAGE_COL, packagename);
        c.put(URL_COL, url);
        ret = sDatabase.insert(APP_TABLE_NAME, URL_COL, c);
    }
    Log.v(DBTAG, "Database value inserted" + getAppDataFromDb(URL_COL, packagename));
    return ret;
}

From source file:com.sourceallies.android.zonebeacon.data.DataSource.java

/**
 * Insert a new gateway into the database
 *
 * @param name Gateway name//from w w  w.  j a va  2s . com
 * @param ip   ip address for the gateway
 * @param port port number for the gateway
 * @return id of the inserted row
 */
public long insertNewGateway(String name, String ip, int port) {
    ContentValues values = new ContentValues();
    values.put(Gateway.COLUMN_NAME, name);
    values.put(Gateway.COLUMN_IP_ADDRESS, ip);
    values.put(Gateway.COLUMN_PORT_NUMBER, port);
    values.put(Gateway.COLUMN_SYSTEM_TYPE_ID, 1); // just one for now. Since there is only elegance.

    return database.insert(Gateway.TABLE, null, values);
}

From source file:name.zurell.kirk.apps.android.rhetolog.RhetologApplication.java

/** Data management support routines */

public Uri insertContactIntoParticipants(Uri contact, Uri session) {

    String[] contactProjection = { ContactsContract.Contacts.DISPLAY_NAME,
            ContactsContract.Contacts.PHOTO_THUMBNAIL_URI };

    Cursor contactQuery = getContentResolver().query(contact, contactProjection, null, null, null);

    if ((contactQuery == null) || (!contactQuery.moveToFirst())) {
        return null;
    }//w ww  .j a  v a2s .  c om

    int nameCol = contactQuery.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
    int photoCol = contactQuery.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI);

    String participantName = null;
    String participantPhoto = null;

    if (contactQuery.getType(nameCol) == Cursor.FIELD_TYPE_STRING)
        participantName = contactQuery.getString(nameCol);
    else
        participantName = getResources().getString(R.string.defaultParticipantCaption);

    if (contactQuery.getType(photoCol) == Cursor.FIELD_TYPE_STRING) {
        participantPhoto = contactQuery.getString(photoCol);
    } else {
        participantPhoto = "android.resource://" + this.getPackageName() + "/"
                + Integer.toString(R.drawable.rhetolog_participant);
    }

    contactQuery.close();

    ContentValues values = new ContentValues();
    values.put(RhetologContract.ParticipantsColumns.NAME, participantName);
    values.put(RhetologContract.ParticipantsColumns.PHOTO, participantPhoto);
    values.put(RhetologContract.ParticipantsColumns.LOOKUP, contact.toString());

    // Learn session id, use in participants/session/id
    //      String sessionId = session.getLastPathSegment();
    //      long currentSessionId;
    //      if (sessionId.contentEquals("currentsession")) {
    //         Bundle currentSessionBundle = getContentResolver().call(RhetologContract.PROVIDER_URI, "getCurrentSession", null, null);
    //         currentSessionId = currentSessionBundle.getLong(RhetologContentProvider.CURRENTSESSIONEXTRA);
    //      } else {
    //         currentSessionId = Long.valueOf(sessionId);
    //      }
    //      
    //      // Ugly, not sure how to make less so.
    //      values.put(RhetologContract.ParticipantsColumns.SESSION, currentSessionId);

    Uri newParticipant = getContentResolver().insert(session, values);

    return newParticipant;

}

From source file:com.example.shutapp.DatabaseHandler.java

/**
 * @param chatroom/*from w  w  w .  j  a v  a 2 s.  com*/
 * @return 
 */
public int updateChatrooms(Chatroom chatroom) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, chatroom.getName()); // Chatroom Name
    values.put(KEY_LATITUDE, chatroom.getLatitude()); // Chatroom Latitude
    values.put(KEY_LONGITUDE, chatroom.getLongitude()); // Chatroom Longitude
    values.put(KEY_RADIUS, chatroom.getRadius()); // Chatroom Radius

    // updating row
    return db.update(TABLE_CHATROOMS, values, KEY_NAME + " = ?", new String[] { chatroom.getName() });
}

From source file:com.github.michalbednarski.intentslab.Utils.java

public static ContentValues jsonObjectToContentValues(JSONObject jsonObject) throws JSONException {
    if (jsonObject == null) {
        return null;
    }/*  w  ww .ja v a2s.  co m*/
    ContentValues contentValues = new ContentValues();
    @SuppressWarnings("unchecked")
    final Iterator<String> iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        contentValues.put(key, jsonObject.getString(key));
    }
    return contentValues;
}

From source file:com.android.xbrowser.DownloadTouchIcon.java

private void storeIcon(Bitmap icon) {
    // Do this first in case the download failed.
    if (mTab != null) {
        // Remove the touch icon loader from the BrowserActivity.
        mTab.mTouchIconLoader = null;//from   w w  w  .j  a v  a 2  s  . c  o  m
    }

    if (icon == null || mCursor == null || isCancelled()) {
        return;
    }

    if (mCursor.moveToFirst()) {
        final ByteArrayOutputStream os = new ByteArrayOutputStream();
        icon.compress(Bitmap.CompressFormat.PNG, 100, os);

        ContentValues values = new ContentValues();
        values.put(Images.TOUCH_ICON, os.toByteArray());

        do {
            values.put(Images.URL, mCursor.getString(0));
            mContentResolver.update(Images.CONTENT_URI, values, null, null);
        } while (mCursor.moveToNext());
    }
}

From source file:at.bitfire.davdroid.resource.LocalTaskList.java

@Override
public void updateMetaData(WebDavResource.Properties properties) throws LocalStorageException {
    ContentValues values = new ContentValues();

    final String displayName = properties.getDisplayName();
    if (displayName != null)
        values.put(TaskContract.TaskLists.LIST_NAME, displayName);

    final Integer color = properties.getColor();
    if (color != null)
        values.put(TaskContract.TaskLists.LIST_COLOR, color);

    try {/*from   w  w  w . j a  v a  2  s .  c  o  m*/
        if (values.size() > 0)
            providerClient.update(ContentUris.withAppendedId(taskListsURI(account), id), values, null, null);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

/**
 * ??//from w  w  w  . j  a  va2  s.co  m
 *
 * @param message ?
 * @param boxType ??
 *                tableName ??a
 * @return ?ID
 */
public static long insertIMessage(ECMessage message, int boxType) {
    long ownThreadId = 0;
    long row = 0L;
    try {
        if (!TextUtils.isEmpty(message.getSessionId())) {
            String contactIds = message.getSessionId();
            if (contactIds.toUpperCase().startsWith("G")) {
                GroupSqlManager.checkGroup(contactIds);
            }
            checkContact(message.getForm(), message.getNickName());
            ownThreadId = ConversationSqlManager.querySessionIdForBySessionId(contactIds);
            if (ownThreadId == 0) {
                try {
                    ownThreadId = ConversationSqlManager.insertSessionRecord(message);
                } catch (Exception e) {
                    LogUtil.e(TAG + " " + e.toString());
                }
            }
            if (ownThreadId > 0) {
                int isread = IMESSENGER_TYPE_UNREAD;
                if (boxType == IMESSENGER_BOX_TYPE_OUTBOX || boxType == IMESSENGER_BOX_TYPE_DRAFT) {
                    isread = IMESSENGER_TYPE_READ;
                }
                ContentValues values = new ContentValues();
                if (boxType == IMESSENGER_BOX_TYPE_DRAFT) {
                    try { // ???
                        values.put(IMessageColumn.OWN_THREAD_ID, ownThreadId);
                        values.put(IMessageColumn.sender, message.getForm());
                        values.put(IMessageColumn.MESSAGE_ID, message.getMsgId());
                        values.put(IMessageColumn.MESSAGE_TYPE, message.getType().ordinal());
                        values.put(IMessageColumn.SEND_STATUS, message.getMsgStatus().ordinal());
                        values.put(IMessageColumn.READ_STATUS, isread);
                        values.put(IMessageColumn.BOX_TYPE, boxType);
                        values.put(IMessageColumn.BODY, ((ECTextMessageBody) message.getBody()).getMessage());
                        values.put(IMessageColumn.USER_DATA, message.getUserData());
                        values.put(IMessageColumn.RECEIVE_DATE, System.currentTimeMillis());
                        values.put(IMessageColumn.CREATE_DATE, message.getMsgTime());

                        row = getInstance().sqliteDB().insertOrThrow(DatabaseHelper.TABLES_NAME_IM_MESSAGE,
                                null, values);
                    } catch (SQLException e) {
                        LogUtil.e(TAG + " " + e.toString());
                    } finally {
                        ChattingFragment.isFireMsg = false;
                        values.clear();
                    }
                } else {
                    try {
                        values.put(IMessageColumn.OWN_THREAD_ID, ownThreadId);
                        values.put(IMessageColumn.MESSAGE_ID, message.getMsgId());
                        values.put(IMessageColumn.SEND_STATUS, message.getMsgStatus().ordinal());
                        values.put(IMessageColumn.READ_STATUS, isread);
                        values.put(IMessageColumn.BOX_TYPE, boxType);
                        // values.put(IMessageColumn.VERSION,
                        // message.getVersion());
                        values.put(IMessageColumn.USER_DATA, message.getUserData());
                        values.put(IMessageColumn.RECEIVE_DATE, System.currentTimeMillis());
                        values.put(IMessageColumn.CREATE_DATE, message.getMsgTime());
                        values.put(IMessageColumn.sender, message.getForm());
                        values.put(IMessageColumn.MESSAGE_TYPE, message.getType().ordinal());

                        if (message.getType() == Type.VIDEO && message.getDirection() == Direction.RECEIVE) {

                            ECVideoMessageBody videoBody = (ECVideoMessageBody) message.getBody();
                            values.put(IMessageColumn.BODY, videoBody.getLength() + "");
                        }

                        if (message.getType() == Type.RICH_TEXT) {
                            ECPreviewMessageBody body = (ECPreviewMessageBody) message.getBody();
                            values.put(IMessageColumn.FILE_URL, body.getUrl());
                            values.put(IMessageColumn.BODY, body.getTitle());
                            values.put(IMessageColumn.FILE_PATH, body.getLocalUrl());
                        }
                        if (message.getType() == Type.IMAGE && message.getDirection() == Direction.RECEIVE) {
                            values.put(IMessageColumn.BODY, message.getUserData());
                        }
                        if (message.getType() == Type.IMAGE && message.getDirection() == Direction.SEND
                                && ChattingFragment.isFireMsg) {
                            values.put(IMessageColumn.BODY, "fireMessage");
                        }

                        // ?
                        putValues(message, values);
                        LogUtil.d(TAG, "[insertIMessage] " + values.toString());
                        row = getInstance().sqliteDB().insertOrThrow(DatabaseHelper.TABLES_NAME_IM_MESSAGE,
                                null, values);
                    } catch (SQLException e) {
                        e.printStackTrace();
                        LogUtil.e(TAG + " " + e.toString());
                    } finally {
                        ChattingFragment.isFireMsg = false;
                        values.clear();
                    }
                }
                getInstance().notifyChanged(contactIds);
            }
        }
    } catch (Exception e) {
        LogUtil.e(e.getMessage());
    }
    return row;
}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public void insertImg(int id, String link) {
    Log.d("INSERT IMGDB", "Inserting images...");

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(IMG_ID, id);/*  w w  w .  j a  va 2s. co m*/
    values.put(LINK, link);
    long info = db.insert(RIP_TABLE, null, values);
}

From source file:edu.cwru.apo.Home.java

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.phone) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE)
                            .edit();//from   w  w  w .j ava2s . c  o  m
                    editor.putLong("updateTime", result.getLong("updateTime"));
                    editor.commit();
                    int numbros = result.getInt("numBros");
                    JSONArray caseID = result.getJSONArray("caseID");
                    JSONArray first = result.getJSONArray("first");
                    JSONArray last = result.getJSONArray("last");
                    JSONArray phone = result.getJSONArray("phone");
                    JSONArray family = result.getJSONArray("family");
                    ContentValues values;
                    for (int i = 0; i < numbros; i++) {
                        values = new ContentValues();
                        values.put("_id", caseID.getString(i));
                        values.put("first", first.getString(i));
                        values.put("last", last.getString(i));
                        values.put("phone", phone.getString(i));
                        values.put("family", family.getString(i));
                        database.replace("phoneDB", null, values);
                    }
                } else if (requestStatus.compareTo("timestamp invalid") == 0) {
                    Toast msg = Toast.makeText(this, "Invalid timestamp.  Please try again.",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("HMAC invalid") == 0) {
                    Auth.loggedIn = false;
                    Toast msg = Toast.makeText(this,
                            "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
                    msg.show();
                    finish();
                } else {
                    Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else if (method == Methods.checkAppVersion) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    String appVersion = result.getString("version");
                    String appDate = result.getString("date");
                    final String appUrl = result.getString("url");
                    PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
                    ;
                    if (appVersion.compareTo(pinfo.versionName) != 0) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Upgrade");
                        builder.setMessage("Update available, ready to upgrade?");
                        builder.setIcon(R.drawable.icon);
                        builder.setCancelable(false);
                        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent promptInstall = new Intent("android.intent.action.VIEW",
                                        Uri.parse("https://apo.case.edu:8090/app/" + appUrl));
                                startActivity(promptInstall);
                            }
                        });
                        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        Toast msg = Toast.makeText(this, "No updates found", Toast.LENGTH_LONG);
                        msg.show();
                    }
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NameNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}