private void getContacts() { ParseUser pu = ParseUser.getCurrentUser(); ArrayList<String> contactname = new ArrayList<String>(); ArrayList<String> contactnumber = new ArrayList<String>(); Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }; Cursor people = getContentResolver().query(uri, projection, null, null, null); int indexName = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); int indexNumber = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); people.moveToFirst(); do { String name = people.getString(indexName); String number = people.getString(indexNumber); contactname.add(name); pu.put("Names", contactname); pu.saveInBackground(); contactnumber.add(number); pu.put("Numbers", contactnumber); pu.saveInBackground(); } while (people.moveToNext()); }
private void finishSubmitting(ParseUser parseUser) { settings.edit().putBoolean("my_first_time", false).commit(); ParseUser mCurrentUser = parseUser; mCurrentUser.put("gender", mGender); mCurrentUser.put("age", Integer.parseInt(mAge)); mCurrentUser.put("dataPlan", Integer.parseInt(mDataPlan)); mCurrentUser.put("serviceProvider", mServiceProvider); mCurrentUser.put("phoneModel", mPhoneModel); mCurrentUser.put("dataThisMonth", Double.parseDouble(mDataThisMonth)); mCurrentUser.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { if (e != null) { AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this); builder.setMessage(e.getMessage()); builder.setTitle("Oops!"); builder.setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } else { Intent returnToMainIntent = new Intent(SignUpActivity.this, MainActivity.class); returnToMainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); returnToMainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); Toast.makeText(SignUpActivity.this, "User details updated.", Toast.LENGTH_LONG) .show(); startActivity(returnToMainIntent); } } }); }
/** * Ajout d'un nouvel utilisateur dans la base de donnees * * @param password * @param firstName * @param lastName * @param birthDay * @param gender * @throws java.text.ParseException */ private void mettreAJourUtilisateur( final String password, final String firstName, final String lastName, final String birthDay, final String gender) throws java.text.ParseException, ParseException { System.out.println(" appel a mettreAJourUtilisateur"); SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy"); final Date dBirthDay = sdf.parse(birthDay); ParseUser pUser = ParseUser.getCurrentUser(); if (password != null) { pUser.put("password", password); } pUser.put("firstname", firstName); pUser.put("lastname", lastName); pUser.put("gender", gender); if (dBirthDay != null) { pUser.put("birthday", dBirthDay); } pUser.saveInBackground(); Toast.makeText(getActivity(), "Modification enregistrée", Toast.LENGTH_SHORT).show(); Intent newActivity = new Intent(getActivity(), ProfilLoginActivity.class); startActivity(newActivity); getActivity().finish(); System.out.println(" Fin appel a mettreAJourUtilisateur"); }
@Override protected void onListItemClick(ListView l, View v, final int position, long id) { super.onListItemClick(l, v, position, id); if (getListView().isItemChecked(position)) { // add friend mFriendsRelation.add(mUsers.get(position)); } else { // remove friend mFriendsRelation.remove(mUsers.get(position)); } mCurrentUser.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { if (e != null) { // failed Log.e(TAG, e.getMessage()); } } }); }
@Override public void onConnected(Bundle bundle) { Log.i(TAG, "Location services connected."); Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (lastLocation == null) { Toast.makeText( FullScreenMapActivity.this, "There is currently no connectivity", Toast.LENGTH_LONG) .show(); } else { ParseGeoPoint point = new ParseGeoPoint(lastLocation.getLatitude(), lastLocation.getLongitude()); ParseUser currentUser = ParseUser.getCurrentUser(); currentUser.put("location", point); currentUser.saveInBackground(); mGoogleMap.animateCamera(CameraUpdateFactory.zoomIn()); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude())) .zoom(12) .bearing(90) .tilt(30) .build(); mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } }
@Override protected void onDestroy() { if (currentUser != null) { currentUser.put("isOnline", false); currentUser.saveInBackground(); } if (broadcastMain != null) { unregisterReceiver(broadcastMain); broadcastMain = null; } super.onDestroy(); }
public static void removeCommunityFromCurrentUser(final ParseObject community) { ParseUser user = ParseUser.getCurrentUser(); ParseRelation<ParseObject> relation = user.getRelation(Common.OBJECT_USER_COMMUNITY_RELATION); relation.remove(community); user.saveInBackground(); ParseRelation<ParseObject> communityUsers = community.getRelation(Common.OBJECT_COMMUNITY_USERS); communityUsers.remove(user); community.saveInBackground(); String channel = "community_" + community.getObjectId(); ParsePush.unsubscribeInBackground(channel); }
private void saveNewUser() { ParseUser parseUser = ParseUser.getCurrentUser(); parseUser.setUsername(emailId); parseUser.setEmail(emailId); parseUser.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { Intent intent = new Intent(LoginActivity.this, Facebooklogin.class); intent.putExtra(NAME, userNameText); startActivity(intent); } }); }
public static void addCommunityToUser(final ParseObject community) { ParseUser user = ParseUser.getCurrentUser(); ParseRelation<ParseObject> relation = user.getRelation(Common.OBJECT_USER_COMMUNITY_RELATION); relation.add(community); user.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { getUserCommunity(ParseUser.getCurrentUser()); } }); ParseRelation<ParseObject> communityUsers = community.getRelation(Common.OBJECT_COMMUNITY_USERS); communityUsers.add(user); community.saveInBackground(); String channel = "community_" + community.getObjectId(); ParsePush.subscribeInBackground(channel); }
@OnClick(R.id.informationSubmitButton) public void finishInfoFlow() { if (collegeField.getText().toString().trim().length() > 0 && graduationDateField.getText().toString().trim().length() > 0) { ParseUser user = ParseUser.getCurrentUser(); user.put(ParseConstants.KEY_COLLEGE_ATTENDED, collegeField.getText().toString().trim()); String string = graduationDateField.getText().toString().trim(); DateFormat formatter = new SimpleDateFormat("MM/dd/yy"); try { Date date = formatter.parse(string); user.put(ParseConstants.KEY_GRADUATION_DATE, date); Log.d(TAG, date.toString()); } catch (ParseException e) { Log.e(TAG, e.getMessage()); } if (employerNameField.getText().toString().trim().length() > 0) { user.put(ParseConstants.KEY_EMPLOYER_NAME, employerNameField.getText().toString().trim()); } if (examDateField.getText().toString().trim().length() > 0) { string = examDateField.getText().toString().trim(); try { Date date = formatter.parse(string); user.put(ParseConstants.KEY_EXAM_DATE, date); Log.d(TAG, date.toString()); } catch (ParseException e) { Log.e(TAG, e.getMessage()); } } AccountingSwipeApplication.expandCardsOnResume = true; // Gives user full access user.put(ParseConstants.KEY_HAS_FULL_ACCESS, true); user.saveInBackground(); finish(); } }
public void updateCurrentUser(String pictureUrl) { ParseUser currentUser = ParseUser.getCurrentUser(); currentUser.put("fbPictureUrl", pictureUrl); currentUser.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { setProgressBarIndeterminateVisibility(false); if (e == null) { Logger.d(MainApplication.TAG, "User info was successfully updated!"); } else { Logger.d( MainApplication.TAG, "An error occurred and it was not possible to update the user info."); } } }); }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); if (getListView().isItemChecked(position)) { // add friend mFriendRelation.add(mUsers.get(position)); } else { // remove friends mFriendRelation.remove(mUsers.get((position))); } mCurrentUser.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { if (e != null) { // there is an error Toast.makeText(EditFriendsActivity.this, android.R.string.no, Toast.LENGTH_SHORT) .show(); } } }); }
@OnClick(R.id.save) public void onClickSave() { String lecturaString = mUltimaLectura.getText().toString().trim(); String fechaString = mFechaAnterior.getText().toString().trim(); String pagoString = mUltimoPago.getText().toString().trim(); String consumoString = mUltimoConsumo.getText().toString().trim(); mUser = ParseUser.getCurrentUser(); if (lecturaString.isEmpty()) { mUltimaLectura.setError(getResources().getString(R.string.error_field_required)); mUltimaLectura.requestFocus(); return; } mUser.put(ParseConstants.KEY_LECTURA_ANTERIOR, Integer.parseInt(lecturaString)); mUser.put(ParseConstants.KEY_TARIFA, mTarifas.get(mSpinner.getSelectedItemPosition())); if (!pagoString.isEmpty()) mUser.put(ParseConstants.KEY_ULTIMO_PAGO, Float.parseFloat(pagoString)); if (!consumoString.isEmpty()) mUser.put(ParseConstants.KEY_ULTIMO_CONSUMO, Integer.parseInt(consumoString)); try { Date fecha = mDateFormatter.parse(fechaString); mUser.put(ParseConstants.KEY_FECHA_LECTURA, fecha); } catch (ParseException e) { // TODO:send error } mUser.saveInBackground( new SaveCallback() { @Override public void done(com.parse.ParseException e) { if (e == null) { NavUtils.navigateUpFromSameTask(EditRecibo.this); } } }); }
public static void addDiaryEntries( final Calendar cal, final ParseUser user, final List<DiaryEntry> entries, final String userMeal) { ParseRelation<ParseObject> pastRecipesRelation = user.getRelation("pastRecipes"); List<DiaryEntry> diaryEntriesList = new ArrayList<>(); for (DiaryEntry entry : entries) { // Add to user's past recipes pastRecipesRelation.add(entry.getRecipe()); final DiaryEntry diaryEntry = new DiaryEntry(); diaryEntry.setDate(cal.getTime()); diaryEntry.setUser(user); diaryEntry.setRecipe(entry.getRecipe()); diaryEntry.setServingsMultiplier(entry.getServingsMultiplier()); diaryEntry.saveInBackground(); diaryEntriesList.add(diaryEntry); } user.saveInBackground(); addUserMeal(cal, user, diaryEntriesList, userMeal); }
private void saveChanges(ParseUser user) { boolean hasChanged = false; if (!name.getText().toString().equals(nameBeforeChange)) { user.put("name", name.getText().toString()); hasChanged = true; } if (!website.getText().toString().equals(websiteBeforeChange)) { user.put("website", website.getText().toString()); hasChanged = true; } if (!bio.getText().toString().equals(bioBeforeChange)) { user.put("bio", bio.getText().toString()); hasChanged = true; } if (!email.getText().toString().equals(emailBeforeChange)) { user.setEmail(email.getText().toString()); hasChanged = true; } if (!phoneNumber.getText().toString().equals(phoneNumberBeforeChange)) { user.put("phone_number", phoneNumber.getText().toString()); hasChanged = true; } if (!genderSpinner.getSelectedItem().toString().equals(genederBeforeChange)) { user.put("gender", genderSpinner.getSelectedItem().toString()); hasChanged = true; } if (hasChanged) { user.saveInBackground(); } }
public static void addDiaryEntry( final Calendar cal, final ParseUser user, final Recipe recipe, float servings, final String userMeal) { // Add recipe to users past recipes ParseRelation<ParseObject> relation = user.getRelation("pastRecipes"); relation.add(recipe); user.saveInBackground(); // Create new diary entry and save to parse final DiaryEntry diaryEntry = new DiaryEntry(); diaryEntry.setDate(cal.getTime()); diaryEntry.setUser(user); diaryEntry.setRecipe(recipe); diaryEntry.setServingsMultiplier(servings); diaryEntry.saveInBackground(); List<DiaryEntry> entries = new ArrayList<>(); entries.add(diaryEntry); addUserMeal(cal, user, entries, userMeal); }