protected void send(ParseObject message) { message.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { // success! Toast.makeText(RecipientsActivity.this, R.string.success_message, Toast.LENGTH_LONG).show(); sendPushNotifications(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(RecipientsActivity.this); builder.setMessage(R.string.error_sending_message) .setTitle(R.string.error_selecting_file_title) .setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); }
private void saveMethod(){ //will save the data if(dateText.getText().toString().equals("") || dateText.getText().toString().equals(" ") || dateText.getText() == null){ //but before saving we will make sure that date is there Toast.makeText(getApplicationContext(), "Attendance date is required",Toast.LENGTH_SHORT).show(); // Snackbar.make(findViewById(R.id.activity_add_attendance), // "Attendance date is required", Snackbar.LENGTH_SHORT).show(); }else{ List<String> kidsIds = new ArrayList<>(); for (int i = 0; i < adapter.map.size() ; i++) { if (adapter.map.get(kidArrayList.get(i))){ kidsIds.add(kidArrayList.get(i).getObjectId()); } } attendance.setDate(dateText.getText().toString()); attendance.setKidsIds(kidsIds); attendance.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null){ Toast.makeText(getApplicationContext(),"Saved successfully.",Toast.LENGTH_LONG).show(); end(); } } }); } }
private void incrementNumberOfVisits(){ int i; if(myKid.getNumberOfVisits() == null){ i = 0; }else{ i = Integer.parseInt(myKid.getNumberOfVisits());} i++; myKid.setNumberOfVisits(String.valueOf(i)); myKid.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null){ Toast.makeText(getApplicationContext(),"Saved successfully",Toast.LENGTH_LONG).show(); }else { Toast.makeText(getApplicationContext(),"Error calculating the number of visits!",Toast.LENGTH_LONG).show(); } } }); }
@Kroll.method public void start() { setState(STATE_RUNNING); // App opens analytics ParseAnalytics.trackAppOpenedInBackground(TiApplication.getAppRootOrCurrentActivity().getIntent()); ParseInstallation.getCurrentInstallation().put("androidId", getAndroidId()); ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() { public void done(ParseException e) { if (e != null) { Log.e(TAG, "Installation initialization failed: " + e.getMessage()); } // fire event try { JSONObject pnData = new JSONObject(); pnData.put("objectId", getObjectId()); pnData.put("installationId", getCurrentInstallationId()); KrollDict data = new KrollDict(pnData); module.fireEvent("installationId", data); } catch (JSONException e1) { Log.e(TAG, "InstallationId event failed: " + e1.getMessage()); } } }); }
public static void setUpParse(Context context) { Parse.enableLocalDatastore(context); Parse.initialize(context, "SUA_APPLICATION_ID", "SUA CLIENT_KEY"); ParseInstallation.getCurrentInstallation().saveInBackground(); ParseUser.enableAutomaticUser(); ParseACL defaultACL = new ParseACL(); defaultACL.setPublicReadAccess(true); defaultACL.setPublicWriteAccess(true); ParsePush.subscribeInBackground(Constants.CHANNEL, new SaveCallback() { @Override public void done(ParseException error) { if (error == null) { Log.i(Constants.TAG, "Successfully subscribed to Parse!"); }else{ Log.i(Constants.TAG, "Error subscribed to Parse!"); } } }); }
private void runUpdate(final Event event, ArrayList<String> locations, String tag) { Log.d("FAC", tag); for (String location : locations) { String venue = event.getVenue(); venue = venue.replaceAll("\n", " "); event.setVenue(venue); if (venue.toLowerCase().contains(location)) { event.setFacultyTag(tag); event.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { Log.e("Saved:", event.getType()); } }); break; } } }
private void userAcceptedGroup(Object org){ if(org instanceof String){ final Organization newOrg = new Organization((String)org); newOrg.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e == null){ //save worked saveAndContinue(newOrg); }else{ Toast.makeText(CreateOrganization.this, "Error creating organization, please try again", Toast.LENGTH_SHORT).show(); } } }); }else{ saveAndContinue((Organization)org); } }
@Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); Parse.initialize(this, "b6M7rAxtdYoUgGMgGkzmYmpDWiN2T6M8c2RTJ5Zg", "Xsqyd44kUtgiOMMvwP8gyVjmdZLvXLxuynmGqqNX"); ParsePush.subscribeInBackground("Apro_2016", new SaveCallback() { @Override public void done(ParseException e) { Log.e(TAG, "Successfully subscribed to Parse!"); } }); Log.d(TAG, "not rgtd."); }
private void getFacebookInfo() { Bundle parameters = new Bundle(); parameters.putString("fields", "picture, first_name, id"); new GraphRequest(AccessToken.getCurrentAccessToken(), "/me", parameters, HttpMethod.GET, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse graphResponse) { JSONObject user = graphResponse.getJSONObject(); ParseUser currentUser = ParseUser.getCurrentUser(); currentUser.put("firstName", user.optString("first_name")); currentUser.put("facebookId", user.optString("id")); currentUser.put("pictureURL", user.optJSONObject("picture").optJSONObject("data").optString("url")); currentUser.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e == null) { Log.i(TAG, "User saved"); setResult(RESULT_OK); finish(); } } }); } }).executeAsync(); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ImageView checkImageView = (ImageView)view.findViewById(R.id.checkImageView); if (mGridView.isItemChecked(position)) { // add the friend mFriendsRelation.add(mUsers.get(position)); checkImageView.setVisibility(View.VISIBLE); } else { // remove the friend mFriendsRelation.remove(mUsers.get(position)); checkImageView.setVisibility(View.INVISIBLE); } mCurrentUser.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e != null) { Log.e(TAG, e.getMessage()); } } }); }
private void activateEvent() { new AlertDialog.Builder(this) .setTitle(getString(R.string.activate)) .setMessage(getString(R.string.activateConfirm)) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { final ProgressDialog pd = ViewUtils.showProgressDialog(EventDetailActivity.this, getString(R.string.activatingEvent), false); ParseObject eventParseObject = new ParseObject(Event.EVENT); eventParseObject.setObjectId(event.getObjectId()); eventParseObject.put(Event.ENABLED, true); eventParseObject.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) {ViewUtils.hideProgressDialog(pd); Toast.makeText(EventDetailActivity.this, EventDetailActivity.this.getString(R.string.eventActivatedSuccessfully), Toast.LENGTH_LONG).show(); finish(); } }); } }) .setNegativeButton(android.R.string.no, null) .setIcon(android.R.drawable.ic_dialog_alert) .show(); }
private void deactivateEvent() { new AlertDialog.Builder(this) .setTitle(getString(R.string.deactivate)) .setMessage(getString(R.string.deactivateConfirm)) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { final ProgressDialog pd = ViewUtils.showProgressDialog(EventDetailActivity.this, getString(R.string.deactivatingEvent), false); ParseObject eventParseObject = new ParseObject(Event.EVENT); eventParseObject.setObjectId(event.getObjectId()); eventParseObject.put(Event.ENABLED, false); eventParseObject.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) {ViewUtils.hideProgressDialog(pd); Toast.makeText(EventDetailActivity.this, EventDetailActivity.this.getString(R.string.eventDeactivatedSuccessfully), Toast.LENGTH_LONG).show(); finish(); } }); } }) .setNegativeButton(android.R.string.no, null) .setIcon(android.R.drawable.ic_dialog_alert) .show(); }
private void setupParse() { Parse.initialize(this, getString(R.string.parse_app_id), getString(R.string.parse_client_key)); ParseFacebookUtils.initialize(this); if(ParseUser.getCurrentUser() != null && !UserPreferences.isUserAssociatedWithInstallation()) { // This should be done only once ParseInstallation currentInstallation = ParseInstallation.getCurrentInstallation(); currentInstallation.put("user", ParseUser.getCurrentUser()); currentInstallation.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e != null) { Timber.d("Error when trying to associate user with installation: " + e.getLocalizedMessage()); } else { Timber.d("User successfully associated with installation"); UserPreferences.setUserAssociatedWithInstallation(); } } }); } }
private void removeUserFromRoom() { mRoom.getUsers().remove(mCurrentUser); mRoom.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { setNotRegisteredVisibilityAndStyle(); } else { NotificationHelper.alert(getContext(), getContext().getString(R.string.dialog_error_title), e.getMessage()); } } }); }
private void addUserToRoom() { mRoom.getUsers().add(mCurrentUser); mRoom.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { setRegisteredVisibilityAndStyle(); } else { setNotRegisteredVisibilityAndStyle(); NotificationHelper.alert(getContext(), getContext().getString(R.string.dialog_error_title), e.getMessage()); } } }); }
@Override public void onCreate() { super.onCreate(); ParseCrashReporting.enable(this); Parse.initialize(this, BuildConfig.PARSE_APPKEY, BuildConfig.PARSE_TOKEN); ParsePush.subscribeInBackground("wc", new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Log.e("push", "successfully subscribed to the broadcast channel."); } else { Log.e("push", "failed to subscribe for push", e); } } }); }
@Kroll.method public void createObject(String className, final HashMap data, final KrollFunction applicationCallback) { SaveCallback parseCallback = new SaveCallback() { public void done(ParseException e) { HashMap result = new HashMap(); if (e == null) { result.put("object", data); } else { // There was an error result.put("error", e.toString()); } if (applicationCallback != null) { applicationCallback.callAsync(getKrollObject(), result); } } }; parseSingleton.CreateDataObject(className, data, parseCallback); }
@Kroll.method public void updateObject(final HashMap data, final KrollFunction applicationCallback) { final ParseObject convertedObject = (ParseObject)ParseDataConversions.ConvertToParseObjectIfNecessary(data); SaveCallback parseCallback = new SaveCallback() { public void done(ParseException e) { HashMap result = new HashMap(); HashMap returnObject = ParseDataConversions.ObjectToHashMap(convertedObject); if (e == null) { result.put("object", returnObject); } else { // There was an error result.put("error", e.toString()); } if (applicationCallback != null) { applicationCallback.callAsync(getKrollObject(), result); } } }; parseSingleton.UpdateDataObject(convertedObject, parseCallback); }
private void joinEvent() { showLoadingDialog(getString(R.string.submitting)); ParseRelation<ParseObject> attendees = mEvent.getRelation("attendees"); attendees.add(ParseUser.getCurrentUser()); mEvent.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { dismissDialog(); if(e!=null){ new AlertDialog.Builder(getActivity()).setMessage(e.getMessage()).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { getActivity().finish(); } }).setCancelable(false).show(); } else{ Toast.makeText(getActivity(), "You're going!", Toast.LENGTH_SHORT).show(); aq.id(R.id.btn_submit).enabled(false); mHasJoined=true; } } }); }
@Override public void onItemClicked(final View v, int position) { User userToFollow = mAdapter.get(position); User user = (User) ParseUser.createWithoutData(ParseUser.class, ParseUser.getCurrentUser().getObjectId()); user.add("followersIds", userToFollow.getObjectId()); user.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { v.setVisibility(View.INVISIBLE); } else { e.printStackTrace(); } } }); }
public void populate() { user = new SimpleUser(); user.setPhoneNumber("555-555-5555"); user.setName("Mickey Mouse"); user.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { // Saved successfully. Log.d("DEBUG", "User update saved!"); String id = user.getObjectId(); Log.d("DEBUG", "The object id is: " + id); instantiateAddress(); instantiateTrainer(); instantiateGym(); } else { // The save failed. Log.d("DEBUG", "User update error: " + e); } } }); }
private void instantiateGym() { gym = new Gym(); gym.setName("24 Hour Fitness"); gym.setAddress(address); gym.setLocation(37.404324, -122.108046); ArrayList<Trainer> trainers = new ArrayList<>(); trainers.add(trainer); gym.setTrainers(trainers); gym.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e != null) { e.printStackTrace(); } else { instantiateReview(); } } }); }
/** * Saves a SnackEntry to Parse and adds it to the SnackList. * * @param entry The SnackEntry to add * @param callback Optional. The callback to invoke after completion. */ public void addSnack(final SnackEntry entry, @Nullable final SaveCallback callback){ if(entry.isDirty()){ notifyUpdateStart(); entry.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e == null){ snacks.add(0, entry); } notifyUpdateComplete(e); if(callback != null){ callback.done(e); } } }); } else if(!snacks.contains(entry)){ snacks.add(0, entry); notifyUpdateComplete(null); if(callback != null){ callback.done(null); } } }
/** * Saves a SnackEntry and its photo to Parse and adds the SnackEntry to the SnackList. * * @param entry The SnackEntry to add * @param photo The SnackEntry's photo * @param callback Optional. The callback to invoke after completion. */ public void addSnack(final SnackEntry entry, final ParseFile photo, @Nullable final SaveCallback callback){ if(photo.isDirty()){ notifyUpdateStart(); photo.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { entry.setPhoto(photo); addSnack(entry, callback); } else if(callback != null){ callback.done(e); } } }); } else { entry.setPhoto(photo); addSnack(entry, callback); } }
private void ensureUserIsLoggedInToFacebookAndPresentFriendPicker() { Session fbSession = Session.getActiveSession(); if (fbSession == null || !fbSession.isOpened() || !ParseFacebookUtils.isLinked(ParseUser.getCurrentUser())) { mProgressDialog = CatProgressDialog.show(SendCatMessageActivity.this, getString(R.string.logging_in)); final List<String> permissions = Utils.getFBPermissions(); ParseFacebookUtils.link(ParseUser.getCurrentUser(), permissions, SendCatMessageActivity.this, new SaveCallback() { @Override public void done(ParseException e) { SendCatMessageActivity.this.mProgressDialog.dismiss(); presentFriendPicker(); } }); } else { presentFriendPicker(); } }
public void saveWithPermissions() { ParseACL chirpACL = new ParseACL(); chirpACL.setPublicReadAccess(true); //chirpACL.setRoleWriteAccess(Admin.ADMIN_ROLE, true); //chirpACL.setWriteAccess(getUser(), true); chirpACL.setPublicWriteAccess(true); // Allows the current user to read/modify its own objects. ParseACL.setDefaultACL(chirpACL, true); this.setACL(chirpACL); this.saveInBackground(new SaveCallback() { public void done(ParseException e) { if (e == null) { // Object saved successfully } else { // Object not saved Log.e("Saving chirp: ", e.getMessage()); } } }); }
Task<Void> pinAsync() { logger.log(Level.INFO, "Pinning Surge with start=" + getString("start") + ", end=" + getString("end")); final Task<Void>.TaskCompletionSource tcs = Task.create(); pinInBackground(PIN_SURGES, new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { logger.log(Level.INFO, "Pinned successfully."); tcs.setResult(null); } else { logger.log(Level.SEVERE, "Unable to pin Surge.", e); tcs.setError(e); } } }); return tcs.getTask(); }
Task<Void> saveAsync() { final Task<Void>.TaskCompletionSource tcs = Task.create(); saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { logger.log(Level.INFO, "Saved successfully."); tcs.setResult(null); } else { logger.log(Level.SEVERE, "Unable to save Surge.", e); tcs.setError(e); } } }); return tcs.getTask(); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ImageView checkImageView = (ImageView) view.findViewById(R.id.checkImageView); if (mGridView.isItemChecked(position)) { // add the friend mFriendsRelation.add(mUsers.get(position)); checkImageView.setVisibility(View.VISIBLE); } else { // remove the friend mFriendsRelation.remove(mUsers.get(position)); checkImageView.setVisibility(View.INVISIBLE); } mCurrentUser.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e != null) { Log.e(TAG, e.getMessage()); } } }); }
protected void send(ParseObject message) { message.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { // success! Toast.makeText(RecipientsActivity.this, R.string.success_message, Toast.LENGTH_LONG).show(); sendPushNotifications(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(RecipientsActivity.this); builder.setMessage(R.string.error_sending_message) .setTitle(R.string.error_title) .setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); if (getListView().isItemChecked(position)) { // add the friend mFriendsRelation.add(mUsers.get(position)); } else { // remove the friend mFriendsRelation.remove(mUsers.get(position)); } mCurrentUser.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e != null) { Log.e(TAG, e.getMessage()); } } }); }
public static void putRating(final Rating ratingIn, final long userId, final float value, final Async.Block<Boolean> completion) { Rating rating = null; if (ratingIn == null) { rating = new Rating(); rating.put(Rating.FACEBOOK_ID_KEY, User.meId()); rating.put(Rating.RATED_FACEBOOK_ID_KEY, userId); } else { rating = ratingIn; } rating.put(Rating.RATING_KEY, value); rating.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (completion != null) { completion.call(e == null); } } }); }
@Override public void requestCreateStory(Story story) { setSupportProgressBarIndeterminateVisibility(true); final ParseObject newStoryParseObject = new ParseObject(Story.STORY_KEY); newStoryParseObject.put(Story.TITLE_KEY, story.getTitle()); newStoryParseObject.put(Story.CONTENT_KEY, story.getContent()); newStoryParseObject.put(Story.AUTHOR_KEY, story.getAuthor()); newStoryParseObject.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Story newStory = new Story(newStoryParseObject); mStoryDataLayer.insertOrUpdateStory(newStory); mLoaderManager.restartLoader(LOADER_ID, null, MainActivity.this); mLeftFragment.onStorySuccessfulCreated(); Toast.makeText(MainActivity.this, R.string.story_saved_correctly, Toast.LENGTH_SHORT).show(); } else { Log.e(TAG, "Error saving the parse object", e); Toast.makeText(MainActivity.this, R.string.error_saving_story, Toast.LENGTH_LONG).show(); setSupportProgressBarIndeterminateVisibility(false); } } }); }
private void send(ParseObject message) { // TODO Auto-generated method stub message.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { // TODO Auto-generated method stub if (e == null) { mNotifyMgr.notify(mNotificationId, mNotifBuilder.build()); sendPushNotifications(); } else { // if(!isFinishing()){ AlertDialog.Builder builder = new AlertDialog.Builder( RecipientsActivity.this); builder.setMessage(R.string.message_error); builder.setTitle(R.string.signup_error_title); builder.setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } // } }); }
/** */ public void clickedChange() { if(isSignUpValid()) { ParseUser user = ParseUser.getCurrentUser(); user.setPassword(mNewPass.getText().toString()); user.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { Toast.makeText(mContext, "Password Updated Successfully", Toast.LENGTH_SHORT).show(); mDialog.dismiss(); } }); } }
/** * Called when the user clicks Save button. * * You can get the current ParseFile photo by calling allPhotos.get(currentPhotoIndex) * @param topText text from top input box * @param bottomText text from bottom input box */ private void handleSave(String topText, String bottomText) { ParseObject meme = new ParseObject("Meme"); meme.put("top", topText); meme.put("bottom", bottomText); meme.put("photo", allPhotos.get(currentPhotoIndex)); meme.put("user", ParseUser.getCurrentUser()); meme.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { showMemeSavedToast(); } else { Log.d(TAG, "Failed to save meme: " + e.getMessage()); } } }); }