Example usage for android.content ContentValues clear

List of usage examples for android.content ContentValues clear

Introduction

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

Prototype

public void clear() 

Source Link

Document

Removes all values.

Usage

From source file:company.test.Test.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    switch (id) {
    case R.id.add_item:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Add a task");
        builder.setMessage("What do you want to do?");
        final EditText inputField = new EditText(this);
        builder.setView(inputField);//  w w w.  ja va 2  s  .com
        builder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                String task = inputField.getText().toString();
                Log.d("MainActivity", task);

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

                values.clear();
                values.put(ItemContract.Columns.ITEM, task);

                db.insertWithOnConflict(ItemContract.TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE);

                activity.updateUI();
            }
        });

        builder.setNegativeButton("Cancel", null);

        builder.create().show();
        return true;
    case R.id.action_settings:
        Log.d("MainActivity", "Settings");
        return true;
    default:
        return false;
    }
}

From source file:net.sourceforge.servestream.activity.OrganizeUrlsActivity.java

private synchronized void saveChanges() {
    List<UriBean> uris = mAdapter.getItems();

    List<UriBean> urisToDelete = new ArrayList<UriBean>();

    for (int i = 0; i < mBaselineUris.size(); i++) {
        if (!uris.contains(mBaselineUris.get(i))) {
            mStreamdb.deleteUri(mBaselineUris.get(i));
            urisToDelete.add(mBaselineUris.get(i));
        }//from  ww w. ja va  2s  . com
    }

    for (int i = 0; i < urisToDelete.size(); i++) {
        mBaselineUris.remove(urisToDelete.get(i));
    }

    int listPosition = 1;

    ContentValues values = new ContentValues();

    for (int i = 0; i < uris.size(); i++) {
        values.clear();
        values.put(StreamDatabase.FIELD_STREAM_LIST_POSITION, listPosition);
        listPosition++;

        mStreamdb.updateUri(uris.get(i), values);
    }

    updateList();
}

From source file:com.hufeiya.SignIn.persistence.TopekaDatabaseHelper.java

private void fillCategory(SQLiteDatabase db, ContentValues values, JSONObject category, String categoryId)
        throws JSONException {
    values.clear();
    values.put(CategoryTable.COLUMN_ID, categoryId);
    values.put(CategoryTable.COLUMN_NAME, category.getString(JsonAttributes.NAME));
    values.put(CategoryTable.COLUMN_THEME, category.getString(JsonAttributes.THEME));
    values.put(CategoryTable.COLUMN_SOLVED, category.getString(JsonAttributes.SOLVED));
    db.insert(CategoryTable.NAME, null, values);
}

From source file:bus_vn.gena.bus_vn.com.bus_vn.List_bus_stop.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_bus_stop);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*w w w  .j  a  v a  2s .c  o m*/
    setTitle(" ?");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    Intent intent = getIntent();
    busPathId = intent.getStringExtra("busPathId");
    Context context = getApplicationContext();

    DbOpenHelper dbOpenHelper = new DbOpenHelper(context);
    SQLiteDatabase db;
    db = dbOpenHelper.getWritableDatabase();
    ContentValues cv = new ContentValues();
    // ? Type_day (,,)
    cv.clear();
    String st = "";
    st = "SELECT DISTINCT Type_day_id FROM bus_stop_path_table ";
    st = st + "INNER JOIN bus_path_table ON  bus_stop_path_table.Bus_path_id=bus_path_table.id ";
    st = st + " WHERE bus_path_table.id='" + busPathId + "'";
    Cursor c = db.rawQuery(st, null);
    kolTypeDay.clear();
    while (c.moveToNext()) {
        String st2 = "";
        st2 = c.getString(0);
        kolTypeDay.add(st2);
    }
    cv.clear();
    setupTablayout();
}

From source file:bus_vn.gena.bus_vn.com.bus_vn.List_bus_time.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_bus);//from   www .j  a v a  2 s .c  o  m
    setTitle(" ?");

    Intent intent = getIntent();
    busPathId = intent.getStringExtra("busPathId");
    busStopId = intent.getStringExtra("busStopId");
    typeDay = intent.getStringExtra("typeDay");

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    Context context = getApplicationContext();
    DbOpenHelper dbOpenHelper = new DbOpenHelper(context);
    SQLiteDatabase db;
    db = dbOpenHelper.getWritableDatabase();
    ContentValues cv = new ContentValues();
    // ? Type_day (,,)
    cv.clear();
    String st = "";
    st = "SELECT DISTINCT Type_day_id FROM bus_stop_path_table ";
    st = st + "INNER JOIN bus_path_table ON  bus_stop_path_table.Bus_path_id=bus_path_table.id ";
    st = st + " WHERE bus_path_table.id='" + busPathId + "'";
    Cursor c = db.rawQuery(st, null);
    kolTypeDay.clear();
    while (c.moveToNext()) {
        String st2 = "";
        st2 = c.getString(0);
        kolTypeDay.add(st2);
    }
    cv.clear();
    setupTablayout();
}

From source file:com.deliciousdroid.platform.ContactManager.java

/**
 * Add a list of status messages to the contacts provider.
 * //from  w  w  w  . j a v a2s.c o  m
 * @param context the context to use
 * @param accountName the username of the logged in user
 * @param statuses the list of statuses to store
 */
@TargetApi(15)
public static void insertStreamStatuses(Context context, String username) {
    final ContentValues values = new ContentValues();
    final ContentResolver resolver = context.getContentResolver();
    final BatchOperation batchOperation = new BatchOperation(context, resolver);
    List<Long> currentContacts = lookupAllContacts(resolver);

    for (long id : currentContacts) {

        String friendUsername = lookupUsername(resolver, id);
        long watermark = lookupHighWatermark(resolver, id);
        long newWatermark = watermark;

        try {
            List<Status> statuses = DeliciousFeed.fetchFriendStatuses(friendUsername);

            for (Status status : statuses) {

                if (status.getTimeStamp().getTime() > watermark) {

                    if (status.getTimeStamp().getTime() > newWatermark)
                        newWatermark = status.getTimeStamp().getTime();

                    values.clear();
                    values.put(StreamItems.RAW_CONTACT_ID, id);
                    values.put(StreamItems.TEXT, status.getStatus());
                    values.put(StreamItems.TIMESTAMP, status.getTimeStamp().getTime());
                    values.put(StreamItems.ACCOUNT_NAME, username);
                    values.put(StreamItems.ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
                    values.put(StreamItems.RES_ICON, R.drawable.ic_main);
                    values.put(StreamItems.RES_PACKAGE, context.getPackageName());
                    values.put(StreamItems.RES_LABEL, R.string.label);

                    batchOperation.add(ContactOperations.newInsertCpo(StreamItems.CONTENT_URI, false)
                            .withValues(values).build());
                    // A sync adapter should batch operations on multiple contacts,
                    // because it will make a dramatic performance difference.
                    if (batchOperation.size() >= 50) {
                        batchOperation.execute();
                    }
                }
            }

            values.clear();
            values.put(RawContacts.SYNC1, Long.toString(newWatermark));
            batchOperation.add(ContactOperations.newUpdateCpo(RawContacts.CONTENT_URI, false).withValues(values)
                    .withSelection(RawContacts._ID + "=?", new String[] { Long.toString(id) }).build());

            batchOperation.execute();

        } catch (AuthenticationException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.heneryh.aquanotes.ui.livestock.LivestockActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_add_ls:
        ContentResolver mResolver = getContentResolver();
        ContentValues values = new ContentValues();
        Uri livestockUri = Livestock.buildInsertLivestockUri();
        values.clear();
        values.put(AquaNotesDbContract.Livestock.COMMON_NAME, "Red Balloon");
        values.put(AquaNotesDbContract.Livestock.TYPE, "SPS");
        values.put(AquaNotesDbContract.Livestock.THUMBNAIL, R.drawable.red_balloon);
        values.put(AquaNotesDbContract.Livestock.TIMESTAMP, 0);
        try {//from w  w w  .j a  va  2s .c o m
            mResolver.insert(livestockUri, values);
        } catch (SQLException e) {
            Log.e("LOG_TAG", "Inserting livestock", e);
        }

        //Directory.addToCategory(0,new LivestockEntry("Blue Balloon", R.drawable.blue_balloon));
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:at.bitfire.nophonespam.CallReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(intent.getAction()) && intent
            .getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
        String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
        Log.i(TAG, "Received call: " + incomingNumber);

        Settings settings = new Settings(context);
        if (TextUtils.isEmpty(incomingNumber)) {
            // private number (no caller ID)
            if (settings.blockHiddenNumbers())
                rejectCall(context, null);

        } else {/*  w ww  .jav a2  s .com*/
            DbHelper dbHelper = new DbHelper(context);
            try {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                Cursor c = db.query(Number._TABLE, null, "? LIKE " + Number.NUMBER,
                        new String[] { incomingNumber }, null, null, null);
                if (c.moveToNext()) {
                    ContentValues values = new ContentValues();
                    DatabaseUtils.cursorRowToContentValues(c, values);
                    Number number = Number.fromValues(values);

                    rejectCall(context, number);

                    values.clear();
                    values.put(Number.LAST_CALL, System.currentTimeMillis());
                    values.put(Number.TIMES_CALLED, number.timesCalled + 1);
                    db.update(Number._TABLE, values, Number.NUMBER + "=?", new String[] { number.number });

                    BlacklistObserver.notifyUpdated();
                }
                c.close();
            } finally {
                dbHelper.close();
            }
        }
    }
}

From source file:com.pagenews.zhihudaily.service.CacheService.java

/**
 * ?/*from   w w w  . jav  a 2s . c o m*/
 * @param id id
 */
private void startGuokrCache(final int id) {
    Cursor cursor = db.query("Guokr", null, null, null, null, null, null);
    if (cursor.moveToFirst()) {
        do {
            if ((cursor.getInt(cursor.getColumnIndex("guokr_id")) == id)
                    && (cursor.getString(cursor.getColumnIndex("guokr_content")).equals(""))) {
                StringRequest request = new StringRequest(Api.GUOKR_ARTICLE_LINK_V1 + id,
                        new Response.Listener<String>() {
                            @Override
                            public void onResponse(String s) {
                                ContentValues values = new ContentValues();
                                values.put("guokr_content", s);
                                db.update("Guokr", values, "guokr_id = ?", new String[] { String.valueOf(id) });
                                values.clear();
                            }
                        }, new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError volleyError) {

                            }
                        });
                request.setTag(TAG);
                VolleySingleton.getVolleySingleton(CacheService.this).getRequestQueue().add(request);
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
}

From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java

private void fillCategory(SQLiteDatabase db, ContentValues values, JSONObject category, String categoryId)
        throws JSONException {
    values.clear();
    values.put(CategoryTable.COLUMN_ID, categoryId);
    values.put(CategoryTable.COLUMN_NAME, category.getString(JsonAttributes.NAME));
    values.put(CategoryTable.COLUMN_THEME, category.getString(JsonAttributes.THEME));
    values.put(CategoryTable.COLUMN_SOLVED, category.getString(JsonAttributes.SOLVED));
    values.put(CategoryTable.COLUMN_SCORES, category.getString(JsonAttributes.SCORES));
    db.insert(CategoryTable.NAME, null, values);
}