List of usage examples for android.content ContentResolver update
public final int update(@RequiresPermission.Write @NonNull Uri uri, @Nullable ContentValues values, @Nullable String where, @Nullable String[] selectionArgs)
From source file:com.roamprocess1.roaming4world.ui.account.AccountsEditListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use custom drag and drop view View v = inflater.inflate(R.layout.accounts_edit_list, container, false); final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list); lv.setGrabberId(R.id.grabber);// w w w . j av a 2s.c o m // Setup the drop listener lv.setOnDropListener(new DropListener() { @Override public void drop(int from, int to) { Log.d(THIS_FILE, "Drop from " + from + " to " + to); int hvC = lv.getHeaderViewsCount(); from = Math.max(0, from - hvC); to = Math.max(0, to - hvC); int i; // First of all, compute what we get before move ArrayList<Long> orderedList = new ArrayList<Long>(); CursorAdapter ad = (CursorAdapter) getListAdapter(); for (i = 0; i < ad.getCount(); i++) { orderedList.add(ad.getItemId(i)); } // Then, invert in the current list the two items ids Long moved = orderedList.remove(from); orderedList.add(to, moved); // Finally save that in db if (getActivity() != null) { ContentResolver cr = getActivity().getContentResolver(); for (i = 0; i < orderedList.size(); i++) { Uri uri = ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, orderedList.get(i)); ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_PRIORITY, i); cr.update(uri, cv, null, null); } } } }); // OnClickListener addClickButtonListener = new OnClickListener() { // @Override // public void onClick(View v) { //onClickAddAccount(); // } // }; // Header view //mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false); //mHeaderView.setOnClickListener(addClickButtonListener); // Empty view //Button bt = (Button) v.findViewById(android.R.id.empty); //bt.setOnClickListener(addClickButtonListener); return v; }
From source file:com.sip.pwc.sipphone.ui.account.AccountsEditListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use custom drag and drop view View v = inflater.inflate(R.layout.accounts_edit_list, container, false); final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list); lv.setGrabberId(R.id.grabber);/*from w w w . j a v a2 s . c o m*/ // Setup the drop listener lv.setOnDropListener(new DragnDropListView.DropListener() { @Override public void drop(int from, int to) { Log.d(THIS_FILE, "Drop from " + from + " to " + to); int hvC = lv.getHeaderViewsCount(); from = Math.max(0, from - hvC); to = Math.max(0, to - hvC); int i; // First of all, compute what we get before move ArrayList<Long> orderedList = new ArrayList<Long>(); CursorAdapter ad = (CursorAdapter) getListAdapter(); for (i = 0; i < ad.getCount(); i++) { orderedList.add(ad.getItemId(i)); } // Then, invert in the current list the two items ids Long moved = orderedList.remove(from); orderedList.add(to, moved); // Finally save that in db if (getActivity() != null) { ContentResolver cr = getActivity().getContentResolver(); for (i = 0; i < orderedList.size(); i++) { Uri uri = ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, orderedList.get(i)); ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_PRIORITY, i); cr.update(uri, cv, null, null); } } } }); OnClickListener addClickButtonListener = new OnClickListener() { @Override public void onClick(View v) { onClickAddAccount(); } }; // Header view mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false); mHeaderView.setOnClickListener(addClickButtonListener); // Empty view Button bt = (Button) v.findViewById(android.R.id.empty); bt.setOnClickListener(addClickButtonListener); return v; }
From source file:org.ohmage.db.DbHelper.java
/** * Flags a response as having been uploaded. This is used exclusively by the * upload service./*from ww w . j av a 2s . c o m*/ * * @param _id * the ID of the response row to set as uploaded * @return true if the operation succeeded, false otherwise */ public boolean setResponseRowUploaded(long _id) { ContentValues values = new ContentValues(); ContentResolver cr = mContext.getContentResolver(); values.put(Responses.RESPONSE_STATUS, Response.STATUS_UPLOADED); return cr.update(Responses.CONTENT_URI, values, Responses._ID + "=" + _id, null) > 0; }
From source file:com.csipsimple.ui.account.AccountsEditListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use custom drag and drop view View v = inflater.inflate(R.layout.accounts_edit_list, container, false); final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list); lv.setGrabberId(R.id.grabber);//from w w w. j a va2 s. c o m // Setup the drop listener lv.setOnDropListener(new DropListener() { @Override public void drop(int from, int to) { Log.d(THIS_FILE, "Drop from " + from + " to " + to); int hvC = lv.getHeaderViewsCount(); from = Math.max(0, from - hvC); to = Math.max(0, to - hvC); int i; // First of all, compute what we get before move ArrayList<Long> orderedList = new ArrayList<Long>(); CursorAdapter ad = (CursorAdapter) getListAdapter(); for (i = 0; i < ad.getCount(); i++) { orderedList.add(ad.getItemId(i)); } // Then, invert in the current list the two items ids Long moved = orderedList.remove(from); orderedList.add(to, moved); // Finally save that in db if (getActivity() != null) { ContentResolver cr = getActivity().getContentResolver(); for (i = 0; i < orderedList.size(); i++) { Uri uri = ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, orderedList.get(i)); ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_PRIORITY, i); cr.update(uri, cv, null, null); } } } }); OnClickListener addClickButtonListener = new OnClickListener() { @Override public void onClick(View v) { onClickAddAccount(); } }; // Header view mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false); mHeaderView.setOnClickListener(addClickButtonListener); // Empty view Button bt = (Button) v.findViewById(android.R.id.empty); bt.setOnClickListener(addClickButtonListener); return v; }
From source file:com.fututel.ui.account.AccountsEditListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use custom drag and drop view View v = inflater.inflate(R.layout.accounts_edit_list, container, false); final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list); lv.setGrabberId(R.id.grabber);//from w ww .j a v a 2 s .c om // Setup the drop listener lv.setOnDropListener(new DropListener() { @Override public void drop(int from, int to) { Log.d(THIS_FILE, "Drop from " + from + " to " + to); int hvC = lv.getHeaderViewsCount(); from = Math.max(0, from - hvC); to = Math.max(0, to - hvC); int i; // First of all, compute what we get before move ArrayList<Long> orderedList = new ArrayList<Long>(); CursorAdapter ad = (CursorAdapter) getListAdapter(); for (i = 0; i < ad.getCount(); i++) { orderedList.add(ad.getItemId(i)); } // Then, invert in the current list the two items ids Long moved = orderedList.remove(from); orderedList.add(to, moved); // Finally save that in db if (getActivity() != null) { ContentResolver cr = getActivity().getContentResolver(); for (i = 0; i < orderedList.size(); i++) { Uri uri = ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, orderedList.get(i)); ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_PRIORITY, i); cr.update(uri, cv, null, null); } } } }); OnClickListener addClickButtonListener = new OnClickListener() { @Override public void onClick(View v) { onClickAddAccount(); } }; // Header view //mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false); //mHeaderView.setOnClickListener(addClickButtonListener); //rangdong // Empty view Button bt = (Button) v.findViewById(android.R.id.empty); bt.setOnClickListener(addClickButtonListener); return v; }
From source file:spit.matrix2017.Activities.EventDetails.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_event_details); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w ww . j av a 2s. co m getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(""); final AppCompatTextView textViews[] = { (AppCompatTextView) findViewById(R.id.tv_event_description), (AppCompatTextView) findViewById(R.id.tv_event_venue_time), (AppCompatTextView) findViewById(R.id.tv_event_registration), (AppCompatTextView) findViewById(R.id.tv_event_prizes), (AppCompatTextView) findViewById(R.id.tv_event_organizers) }; collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbar_event); organizers_card = (CardView) findViewById(R.id.organizers_card); prizes_card = (CardView) findViewById(R.id.prizes_card); registration_card = (CardView) findViewById(R.id.registration_card); visitedCalendar = false; isFirstLaunch = true; //get intent from eventlist adapter if (getIntent().getStringExtra("name") != null && getSupportActionBar() != null) { event_name = getIntent().getStringExtra("name"); this.setTitle(event_name); } else this.setTitle("Some event"); setDescription(getIntent().getStringExtra("description")); setVenueAndTime(getIntent().getStringExtra("venue"), getIntent().getStringExtra("time")); setRegistration(getIntent().getStringExtra("registration")); setPrizes(getIntent().getStringExtra("prizes")); setContacts(getIntent().getStringExtra("contact1name"), getIntent().getStringExtra("contact1no"), getIntent().getStringExtra("contact2name"), getIntent().getStringExtra("contact2no")); isFavouriteEvent = getIntent().getIntExtra("favorite", 0) == 1; isReminderSet = getIntent().getIntExtra("reminder", 0) == 1; mainImageView = (ImageView) findViewById(R.id.main_imageView); assert mainImageView != null; mainImageView.setImageResource(getIntent().getIntExtra("image", R.drawable.event_vsm)); fab = (FloatingActionButton) findViewById(R.id.fab); assert fab != null; if (isFavouriteEvent) fab.setImageResource(R.drawable.svg_favorite_white_48px); Bitmap bitmap = ((BitmapDrawable) mainImageView.getDrawable()).getBitmap(); Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch swatch = palette.getVibrantSwatch(); if (swatch == null) swatch = palette.getMutedSwatch(); if (swatch != null) { int color = swatch.getRgb(); if (Color.red(color) + Color.green(color) + Color.green(color) > 420) color = Color.rgb((int) (Color.red(color) * 0.8), (int) (Color.green(color) * 0.8), (int) (Color.blue(color) * 0.8)); fab.setBackgroundTintList(ColorStateList.valueOf(color)); fab.setRippleColor(swatch.getTitleTextColor()); collapsingToolbarLayout.setContentScrimColor(color); collapsingToolbarLayout.setBackgroundColor(color); collapsingToolbarLayout.setStatusBarScrimColor(color); if (Build.VERSION.SDK_INT >= 21) { getWindow().setStatusBarColor(color); } for (AppCompatTextView textView : textViews) textView.setTextColor(color); } } }); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isFavouriteEvent = !isFavouriteEvent; ContentResolver contentResolver = getContentResolver(); Uri uri = Uri.parse("content://spit.matrix2017.provider"); String selection = "name = ?"; String[] selectionArgs = { getIntent().getStringExtra("name") }; ContentValues cv = new ContentValues(); if (isFavouriteEvent) { cv.put("favorite", 1); contentResolver.update(uri, cv, selection, selectionArgs); Toast.makeText(EventDetails.this, "Added to favorites", Toast.LENGTH_SHORT).show(); fab.setImageResource(R.drawable.svg_favorite_white_48px); } else { cv.put("favorite", 0); contentResolver.update(uri, cv, selection, selectionArgs); fab.setImageResource(R.drawable.svg_favorite_border_white_48px); } } }); }
From source file:net.voxcorp.voxmobile.ui.account.AccountsEditListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use custom drag and drop view View v = inflater.inflate(R.layout.accounts_edit_list, container, false); final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list); lv.setGrabberId(R.id.grabber);/*from w w w. j a v a 2 s . co m*/ // Setup the drop listener lv.setOnDropListener(new DropListener() { @Override public void drop(int from, int to) { Log.d(THIS_FILE, "Drop from " + from + " to " + to); int hvC = lv.getHeaderViewsCount(); from = Math.max(0, from - hvC); to = Math.max(0, to - hvC); int i; // First of all, compute what we get before move ArrayList<Long> orderedList = new ArrayList<Long>(); CursorAdapter ad = (CursorAdapter) getListAdapter(); for (i = 0; i < ad.getCount(); i++) { orderedList.add(ad.getItemId(i)); } // Then, invert in the current list the two items ids Long moved = orderedList.remove(from); orderedList.add(to, moved); // Finally save that in db if (getActivity() != null) { ContentResolver cr = getActivity().getContentResolver(); for (i = 0; i < orderedList.size(); i++) { Uri uri = ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, orderedList.get(i)); ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_PRIORITY, i); cr.update(uri, cv, null, null); } } } }); OnClickListener addClickButtonListener = new OnClickListener() { @Override public void onClick(View v) { onClickAddAccount(true); } }; // Header view mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false); mHeaderView.setOnClickListener(addClickButtonListener); // Empty view Button bt = (Button) v.findViewById(android.R.id.empty); bt.setOnClickListener(addClickButtonListener); return v; }
From source file:com.jefftharris.passwdsafe.sync.MainActivity.java
/** Update the sync frequency for an account */ private void updateSyncFreq(final ProviderSyncFreqPref freq, Uri acct) { new AccountUpdateTask(acct, getString(R.string.updating_account)) { @Override//from w ww . jav a 2 s .c o m protected void doAccountUpdate(ContentResolver cr) { ContentValues values = new ContentValues(); values.put(PasswdSafeContract.Providers.COL_SYNC_FREQ, freq.getFreq()); cr.update(itsAccountUri, values, null, null); } }.startTask(this, this); }
From source file:org.opendatakit.tables.utils.CollectUtil.java
/** * Insert the values existing in the file specified by * {@link DATA_FILE_PATH_AND_NAME} into the form specified by params. * <p>/*from w ww. ja v a 2s . c om*/ * If the display name is not defined in the {@code params} parameter then the * string resource is used. * <p> * The inserted row is marked as INCOMPLETE. * <p> * PRECONDITION: in order to be populated with data, the data file containing * the row's data must have been written, most likely by calling * writeRowDataToBeEdited(). * <p> * PRECONDITION: previous instances should already have been deleted by now, * or the passed in file names should be uniqued by adding timestamps, or * something. * * @param params * the identifying parameters for the form. Should be the same object * used to write the instance file. * @param rowNum * the row number of the row being edited * @param resolver * the ContentResolver of the activity making the request. * @return */ /* * This is based on the code at: http://code.google.com/p/opendatakit/source/ * browse/src/org/odk/collect/android/tasks/SaveToDiskTask.java?repo=collect * in the method updateInstanceDatabase(). */ private static Uri getUriForCollectInstanceForRowData(Context context, String appName, String tableId, CollectFormParameters params, String rowId, boolean shouldUpdate) { String instanceFilePath = getEditRowFormFile(appName, tableId, rowId).getAbsolutePath(); ContentValues values = new ContentValues(); // First we need to fill the values with various little things. values.put(COLLECT_KEY_STATUS, COLLECT_KEY_STATUS_INCOMPLETE); values.put(COLLECT_KEY_CAN_EDIT_WHEN_COMPLETE, Boolean.toString(true)); values.put(COLLECT_KEY_INSTANCE_FILE_PATH, instanceFilePath); values.put(COLLECT_KEY_JR_FORM_ID, params.getFormId()); values.put(COLLECT_KEY_DISPLAY_NAME, params.getRowDisplayName() + "_" + WebUtils.get().iso8601Date(new Date())); // only add the version if it exists (ie not null) if (params.getFormVersion() != null) { values.put(COLLECT_KEY_JR_VERSION, params.getFormVersion()); } ContentResolver resolver = context.getContentResolver(); Uri uriOfForm; if (shouldUpdate) { int count = resolver.update(CONTENT_INSTANCE_URI, values, COLLECT_KEY_INSTANCE_FILE_PATH + "=?", new String[] { instanceFilePath }); if (count == 0) { uriOfForm = resolver.insert(CONTENT_INSTANCE_URI, values); } else { Cursor c = null; try { c = resolver.query(CONTENT_INSTANCE_URI, null, COLLECT_KEY_INSTANCE_FILE_PATH + "=?", new String[] { instanceFilePath }, COLLECT_INSTANCE_ORDER_BY); if (c.moveToFirst()) { // we got a result, meaning that the form exists in collect. // so we just need to set the URI. int collectInstanceKey; // this is the primary key of the form in // Collect's // database. collectInstanceKey = ODKDatabaseUtils.get().getIndexAsType(c, Integer.class, c.getColumnIndexOrThrow(BaseColumns._ID)); uriOfForm = (Uri.parse(CONTENT_INSTANCE_URI + "/" + collectInstanceKey)); c.close(); } else { c.close(); throw new IllegalStateException("it was updated we should have found the record!"); } } finally { if (c != null && !c.isClosed()) { c.close(); } } } } else { // now we want to get the uri for the insertion. uriOfForm = resolver.insert(CONTENT_INSTANCE_URI, values); } return uriOfForm; }
From source file:com.ichi2.anki.tests.ContentProviderTest.java
/** * Check that updating the flds column works as expected */// w ww .j a v a 2 s . c om public void testUpdateNoteFields() { final ContentResolver cr = getContext().getContentResolver(); ContentValues cv = new ContentValues(); // Change the fields so that the first field is now "newTestValue" String[] dummyFields2 = mDummyFields.clone(); dummyFields2[0] = TEST_FIELD_VALUE; for (Uri uri : mCreatedNotes) { // Update the flds cv.put(FlashCardsContract.Note.FLDS, Utils.joinFields(dummyFields2)); cr.update(uri, cv, null, null); // Query the table again Cursor noteCursor = cr.query(uri, FlashCardsContract.Note.DEFAULT_PROJECTION, null, null, null); try { assertNotNull("Check that there is a valid cursor for detail data after update", noteCursor); assertEquals("Check that there is one and only one entry after update", 1, noteCursor.getCount()); assertTrue("Move to first item in cursor", noteCursor.moveToFirst()); String[] newFlds = Utils .splitFields(noteCursor.getString(noteCursor.getColumnIndex(FlashCardsContract.Note.FLDS))); assertTrue("Check that the flds have been updated correctly", Arrays.equals(newFlds, dummyFields2)); } finally { noteCursor.close(); } } }