public void saveNewBikeSpot() { SessionManager sessionManager = new SessionManager(getApplicationContext()); HashMap<String, String> userSession = sessionManager.getUserDetails(); String userCredential = userSession.get(sessionManager.KEY_REGISTRATION); String pwdVerified = userSession.get(sessionManager.KEY_PASSWORD); String emailCredential = userSession.get(sessionManager.KEY_EMAIL); if (pwdVerified.equalsIgnoreCase("FBPWD")) { saveFacebookUser(userCredential, pwdVerified, emailCredential); } final String fullAddressNewBikeSpot = edtTextAddressName .getText() .toString() .trim() .concat(", ") .concat(edtTextNumber.getText().toString().trim().concat(" - ").concat(cityState)); BikeSpot bikeSpot = new BikeSpot(); Date date = new Date(); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); FORMAT.format(date); parseGeoPoint = new ParseGeoPoint(); parseGeoPoint.setLatitude(location.getLatitude()); parseGeoPoint.setLongitude(location.getLongitude()); bikeSpot.setLocation(parseGeoPoint); bikeSpot.setName(edtTextReference.getText().toString().trim()); bikeSpot.setLocation(parseGeoPoint); bikeSpot.setDescription(edtTextReference.getText().toString().trim()); bikeSpot.setFullAddress(fullAddressNewBikeSpot); bikeSpot.setAddressNumber(edtTextNumber.getText().toString().trim()); bikeSpot.setUsername(userCredential); bikeSpot.setLocalDate(FORMAT.format(date)); bikeSpot.setPlattaform("ANDROID"); bikeSpot.setStatus(true); bikeSpot.setRate(0); bikeSpot.setCathegory(transformCathegoryToChar(spnrCathegory.getSelectedItem().toString())); bikeSpot.setCapacity(capacity = (capacity > 0) ? capacity : 0); ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (bitmap != null) { bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] bitmapBytes = stream.toByteArray(); StringBuilder strBuilder = new StringBuilder(); String fileName = strBuilder.replaceSpecialCharacters(edtTextReference.getText().toString().trim()); ParseFile pic = new ParseFile(strBuilder.removeAllSpaces(fileName), bitmapBytes); try { pic.save(); } catch (ParseException e) { e.printStackTrace(); } bikeSpot.setPicture(pic); } final ProgressDialog dialog = new ProgressDialog(NewBikeSpotActivity.this); dialog.setMessage(getString(R.string.progress_new_bikespot)); dialog.show(); bikeSpot.saveInBackground( new SaveCallback() { @Override public void done(ParseException p) { dialog.dismiss(); Toast.makeText( getApplicationContext(), MESSAGE_OF_SUCCESS.toString(), Toast.LENGTH_SHORT) .show(); } }); }
public void logout() { session.logoutUser(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_bike_spot); configToolBar(); session = new SessionManager(getApplicationContext()); HashMap<String, String> user = session.getUserDetails(); sessionUser = user.get(session.KEY_REGISTRATION); edtTextAddressName = (EditText) findViewById(R.id.editTextAddressBikeSpot); edtTextNumber = (EditText) findViewById(R.id.editTextAddressNumber); edtTextReference = (EditText) findViewById(R.id.editTextReference); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); String provider = getBestProvider(); addListenerOnNumberPickerCapacity(); loadBikeSpotCathegory(); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } location = locationManager.getLastKnownLocation(provider); // LocationManager.GPS_PROVIDER if (location == null) { location = getCurrentLocationFromUser(); } if (location != null) { this.onLocationChanged(location); } Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault()); try { List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); Address address = addresses.get(0); street = address.getAddressLine(0); cityState = address.getAddressLine(1); String[] parts = street.split(","); street = parts[0]; number = address.getFeatureName(); city = address.getLocality(); country = address.getCountryName(); postalCode = address.getPostalCode(); edtTextAddressName.setText(street.toString()); edtTextNumber.setText(number.toString()); } catch (Exception e) { AlertDialog.Builder dialogo = new AlertDialog.Builder(NewBikeSpotActivity.this); dialogo.setTitle("Aviso!"); dialogo.setMessage(MESSAGE_EMPTY_ADDRESS); dialogo.setNeutralButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showMapActivity(); } }); dialogo.show(); } addEditTextOnEditorActionListener(); btnSaveBikeSpotLocal = (Button) findViewById(R.id.btnSaveBikeSpot); btnSaveBikeSpotLocal.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if ((edtTextReference.getText().toString().trim().length() == 0) || (edtTextAddressName.getText().toString().trim().length() == 0) || (edtTextNumber.getText().toString().trim().length() == 0)) { Toast.makeText(getApplicationContext(), MESSAGE_ERROR_NOFILLED, Toast.LENGTH_LONG) .show(); } else { final String fullAddressNewBikeSpot = edtTextAddressName .getText() .toString() .trim() .concat(", ") .concat( edtTextNumber .getText() .toString() .trim() .concat(" - ") .concat(cityState)); boolean check = isBikeSpotExists(convertLocationToParseGeoPoint(location)); boolean check2 = isBikeSpotExists(fullAddressNewBikeSpot); if (check || check2) { Toast.makeText(getApplicationContext(), MESSAGE_BIKESPOT_EXISTS, Toast.LENGTH_LONG) .show(); } else { saveNewBikeSpot(); showMapActivity(); } } } }); imgBikeSpotPic = (ImageButton) findViewById(R.id.imageButtonPicture); ivBikeSpot = (ImageView) findViewById(R.id.imageViewBikeSpot); imgBikeSpotPic.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { try { if (isDeviceSupportCamera()) captureImage(); } catch (Exception ex) { openDialogCamera(); } } }); }