List of usage examples for android.content ContentProviderOperation newInsert
public static Builder newInsert(Uri uri)
From source file:com.conferenceengineer.android.iosched.io.RoomsHandler.java
private static void parseRoom(Room room, ArrayList<ContentProviderOperation> batch) { ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(ScheduleContract.addCallerIsSyncAdapterParameter(ScheduleContract.Rooms.CONTENT_URI)); builder.withValue(ScheduleContract.Rooms.ROOM_ID, room.id); builder.withValue(ScheduleContract.Rooms.ROOM_NAME, room.name); builder.withValue(ScheduleContract.Rooms.ROOM_FLOOR, room.floor); batch.add(builder.build());//from w ww .j a va 2 s. co m }
From source file:com.conferenceengineer.android.iosched.io.TracksHandler.java
private static void parseTrack(TrackResponse track, ArrayList<ContentProviderOperation> batch) { ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(ScheduleContract.addCallerIsSyncAdapterParameter(ScheduleContract.Tracks.CONTENT_URI)); builder.withValue(ScheduleContract.Tracks.TRACK_ID, track.getId()); builder.withValue(ScheduleContract.Tracks.TRACK_NAME, track.getTitle()); builder.withValue(ScheduleContract.Tracks.TRACK_COLOR, Color.parseColor(track.getColour())); builder.withValue(ScheduleContract.Tracks.TRACK_ABSTRACT, track.getDescription()); builder.withValue(ScheduleContract.Tracks.TRACK_META, track.getMeta()); builder.withValue(ScheduleContract.Tracks.TRACK_HASHTAG, ParserUtils.sanitizeId(track.getTitle())); batch.add(builder.build());//from w ww . j a v a2 s . co m }
From source file:com.conferenceengineer.android.iosched.io.SearchSuggestHandler.java
public ArrayList<ContentProviderOperation> parse(String json) throws IOException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); try {/*w w w . j ava 2 s .co m*/ JSONObject root = new JSONObject(json); JSONArray suggestions = root.getJSONArray("words"); batch.add( ContentProviderOperation .newDelete(ScheduleContract .addCallerIsSyncAdapterParameter(ScheduleContract.SearchSuggest.CONTENT_URI)) .build()); for (int i = 0; i < suggestions.length(); i++) { batch.add(ContentProviderOperation .newInsert(ScheduleContract .addCallerIsSyncAdapterParameter(ScheduleContract.SearchSuggest.CONTENT_URI)) .withValue(SearchManager.SUGGEST_COLUMN_TEXT_1, suggestions.getString(i)).build()); } } catch (JSONException e) { Log.e(Config.LOG_TAG, "Problem building word list", e); } return batch; }
From source file:com.conferenceengineer.android.iosched.io.BlocksHandler.java
private static void parseSlot(String date, TimeSlot slot, ArrayList<ContentProviderOperation> batch) { ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(ScheduleContract.addCallerIsSyncAdapterParameter(Blocks.CONTENT_URI)); //LOGD(TAG, "Inside parseSlot:" + date + ", " + slot); String start = slot.start;//from w ww. j a v a2s .co m String end = slot.end; String type = Blocks.BLOCK_TYPE_GENERIC; if (slot.type != null) { type = slot.type; } String title = "N_D"; if (slot.title != null) { title = slot.title; } String startTime = date + "T" + start + ":00.000" + Config.CONFERENCE_TIME_ZONE_OFFSET; String endTime = date + "T" + end + ":00.000" + Config.CONFERENCE_TIME_ZONE_OFFSET; LOGV(TAG, "startTime:" + startTime); long startTimeL = ParserUtils.parseTime(startTime); long endTimeL = ParserUtils.parseTime(endTime); final String blockId = Blocks.generateBlockId(startTimeL, endTimeL); LOGV(TAG, "blockId:" + blockId); LOGV(TAG, "title:" + title); LOGV(TAG, "start:" + startTimeL); builder.withValue(Blocks.BLOCK_ID, blockId); builder.withValue(Blocks.BLOCK_TITLE, title); builder.withValue(Blocks.BLOCK_START, startTimeL); builder.withValue(Blocks.BLOCK_END, endTimeL); builder.withValue(Blocks.BLOCK_TYPE, type); builder.withValue(Blocks.BLOCK_META, slot.meta); batch.add(builder.build()); }
From source file:org.xwalk.runtime.extension.api.contacts.ContactSaver.java
private Builder newInsertBuilder(String mimeType) { Builder builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(Data.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, mimeType); return builder; }
From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteSessionTypesHandler.java
@Override public ArrayList<ContentProviderOperation> parse(ArrayList<JSONArray> entries, ContentResolver resolver) throws JSONException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); final HashSet<String> typeIds = Sets.newHashSet(); int nrEntries = 0; for (JSONArray types : entries) { Log.d(TAG, "Retrieved " + types.length() + " presentation types entries."); nrEntries += types.length();// w ww . j a v a2 s . co m for (int i = 0; i < types.length(); i++) { JSONObject type = types.getJSONObject(i); String id = type.getString("id"); final String typeId = sanitizeId(id); typeIds.add(typeId); ContentProviderOperation.Builder builder; builder = ContentProviderOperation.newInsert(Types.CONTENT_URI); builder.withValue(Types.TYPE_ID, typeId); builder.withValue(Types.TYPE_NAME, type.getString("name")); builder.withValue(Types.TYPE_DESCRIPTION, type.getString("description")); batch.add(builder.build()); } } return batch; }
From source file:org.muckebox.android.net.RefreshHelper.java
public static Integer refreshTracks(long albumId) { try {/* w ww .j a v a2 s. co m*/ ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(1); JSONArray json = ApiHelper.callApiForArray("tracks", null, new String[] { "album" }, new String[] { Long.toString(albumId) }); operations.ensureCapacity(operations.size() + json.length() + 1); operations.add(ContentProviderOperation .newDelete(Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS_ALBUM, Long.toString(albumId))) .build()); for (int j = 0; j < json.length(); ++j) { JSONObject o = json.getJSONObject(j); ContentValues values = new ContentValues(); values.put(TrackEntry.SHORT_ID, o.getInt("id")); values.put(TrackEntry.SHORT_ARTIST_ID, o.getInt("artist_id")); values.put(TrackEntry.SHORT_ALBUM_ID, o.getInt("album_id")); values.put(TrackEntry.SHORT_TITLE, o.getString("title")); if (!o.isNull("tracknumber")) values.put(TrackEntry.SHORT_TRACKNUMBER, o.getInt("tracknumber")); if (!o.isNull("discnumber")) values.put(TrackEntry.SHORT_DISCNUMBER, o.getInt("discnumber")); values.put(TrackEntry.SHORT_LABEL, o.getString("label")); values.put(TrackEntry.SHORT_CATALOGNUMBER, o.getString("catalognumber")); values.put(TrackEntry.SHORT_LENGTH, o.getInt("length")); values.put(TrackEntry.SHORT_DATE, o.getString("date")); operations.add(ContentProviderOperation .newDelete( Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS, Integer.toString(o.getInt("id")))) .build()); operations.add( ContentProviderOperation.newInsert(MuckeboxProvider.URI_TRACKS).withValues(values).build()); } Log.d(LOG_TAG, "Got " + json.length() + " Tracks"); Muckebox.getAppContext().getContentResolver().applyBatch(MuckeboxProvider.AUTHORITY, operations); } catch (AuthenticationException e) { return R.string.error_authentication; } catch (SSLException e) { return R.string.error_ssl; } catch (IOException e) { Log.d(LOG_TAG, "IOException: " + e.getMessage()); return R.string.error_reload_tracks; } catch (JSONException e) { return R.string.error_json; } catch (RemoteException e) { e.printStackTrace(); return R.string.error_reload_tracks; } catch (OperationApplicationException e) { e.printStackTrace(); return R.string.error_reload_tracks; } return null; }
From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteRoomsHandler.java
@Override public ArrayList<ContentProviderOperation> parse(ArrayList<JSONArray> entries, ContentResolver resolver) throws JSONException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); final HashSet<String> roomIds = new HashSet<String>(); int nrEntries = 0; for (JSONArray rooms : entries) { Log.d(TAG, "Retrieved " + rooms.length() + " room entries."); nrEntries += rooms.length();//from w ww . ja v a2 s .co m for (int i = 0; i < rooms.length(); i++) { JSONObject room = rooms.getJSONObject(i); String id = room.getString("id"); final String roomId = sanitizeId(id); final Uri roomUri = Rooms.buildRoomUri(roomId); roomIds.add(roomId); ContentProviderOperation.Builder builder; if (isRowExisting(Rooms.buildRoomUri(roomId), RoomsQuery.PROJECTION, resolver)) { builder = ContentProviderOperation.newUpdate(roomUri); } else { builder = ContentProviderOperation.newInsert(Rooms.CONTENT_URI); builder.withValue(Rooms.ROOM_ID, roomId); } builder.withValue(Rooms.NAME, room.getString("name")); builder.withValue(Rooms.CAPACITY, room.getString("capacity")); batch.add(builder.build()); } } if (isRemoteSync() && nrEntries > 0) { for (String lostId : getLostIds(roomIds, Rooms.CONTENT_URI, RoomsQuery.PROJECTION, RoomsQuery.ROOM_ID, resolver)) { final Uri lostRoomUri = Rooms.buildRoomUri(lostId); batch.add(ContentProviderOperation.newDelete(lostRoomUri).build()); } } return batch; }
From source file:ca.mudar.parkcatcher.io.PostsHandler.java
@Override public ArrayList<ContentProviderOperation> parse(JSONTokener jsonTokener, ContentResolver resolver) throws JSONException, IOException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); ContentProviderOperation.Builder builderPosts; JSONObject jsonObject = new JSONObject(jsonTokener); final String status = jsonObject.getString(RemoteTags.STATUS); if (!RemoteValues.STATUS_OK.equals(status)) { return batch; }/*w w w .j a v a2s . c o m*/ final int nbPosts = jsonObject.getInt(RemoteTags.COUNT); // final int version = jsonObject.getInt(RemoteTags.VERSION); // final JSONArray columns = // jsonObject.getJSONArray(RemoteTags.COLUMNS); final JSONArray posts = jsonObject.getJSONArray(jsonObject.getString(RemoteTags.NAME)); if ((posts.length() != nbPosts) || (nbPosts == 0)) { return batch; } jsonObject = null; for (int i = 0; i < nbPosts; i++) { final JSONArray post = posts.getJSONArray(i); if (post == null) { continue; } builderPosts = ContentProviderOperation.newInsert(Posts.CONTENT_URI); builderPosts.withValue(Posts.ID_POST, post.getInt(0)); builderPosts.withValue(Posts.LNG, post.getDouble(1)); builderPosts.withValue(Posts.LAT, post.getDouble(2)); batch.add(builderPosts.build()); } return batch; }
From source file:ca.mudar.parkcatcher.io.PanelsHandler.java
@Override public ArrayList<ContentProviderOperation> parse(JSONTokener jsonTokener, ContentResolver resolver) throws JSONException, IOException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); ContentProviderOperation.Builder builderPanels; JSONObject jsonObject = new JSONObject(jsonTokener); final String status = jsonObject.getString(RemoteTags.STATUS); if (!RemoteValues.STATUS_OK.equals(status)) { return batch; }/*w ww. j a v a 2 s. c o m*/ final int nbPanels = jsonObject.getInt(RemoteTags.COUNT); // final int version = jsonObject.getInt(RemoteTags.VERSION); // final JSONArray columns = // jsonObject.getJSONArray(RemoteTags.COLUMNS); final JSONArray panels = jsonObject.getJSONArray(jsonObject.getString(RemoteTags.NAME)); if ((panels.length() != nbPanels) || (nbPanels == 0)) { return batch; } jsonObject = null; for (int i = 0; i < nbPanels; i++) { final JSONArray panel = panels.getJSONArray(i); if (panel == null) { continue; } builderPanels = ContentProviderOperation.newInsert(Panels.CONTENT_URI); builderPanels.withValue(Panels.ID_PANEL, panel.getInt(0)); builderPanels.withValue(Panels.ID_POST, panel.getInt(1)); builderPanels.withValue(Panels.ID_PANEL_CODE, panel.getInt(2)); batch.add(builderPanels.build()); } return batch; }