Search in sources :

Example 11 with AsyncCallback

use of com.backendless.async.callback.AsyncCallback in project Android-SDK by Backendless.

the class RegistrationActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_registration);
    TextView textEmail = (TextView) findViewById(R.id.textEmail);
    TextView textPass = (TextView) findViewById(R.id.textPass);
    TextView textName = (TextView) findViewById(R.id.textName);
    TextView textRegistration = (TextView) findViewById(R.id.textRegistration);
    Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
    textEmail.setTypeface(typeface);
    textPass.setTypeface(typeface);
    textName.setTypeface(typeface);
    textRegistration.setTypeface(typeface);
    Button registrationBtn = (Button) findViewById(R.id.registrationBtn);
    registrationBtn.setTypeface(typeface);
    registrationBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            EditText editEmailText = (EditText) findViewById(R.id.emailEdit);
            EditText editPasswordText = (EditText) findViewById(R.id.passwordEdit);
            EditText editNameText = (EditText) findViewById(R.id.editUserName);
            final String messageMail = editEmailText.getText().toString();
            final String messagePassword = editPasswordText.getText().toString();
            final String messageName = editNameText.getText().toString();
            if (TextUtils.isEmpty(messageMail) || TextUtils.isEmpty(messagePassword) || TextUtils.isEmpty(messageName)) {
                String alertMessage = "Please, fill in all fields!";
                Toast.makeText(RegistrationActivity.this, alertMessage, Toast.LENGTH_LONG).show();
                return;
            }
            progressDialog = ProgressDialog.show(RegistrationActivity.this, "", "Loading", true);
            BackendlessUser userObj = new BackendlessUser();
            userObj.setProperty("name", messageName);
            userObj.setEmail(messageMail);
            userObj.setPassword(messagePassword);
            Backendless.UserService.register(userObj, new AsyncCallback<BackendlessUser>() {

                @Override
                public void handleResponse(BackendlessUser backendlessUser) {
                    final Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
                    intent.putExtra(Default.EXTRA_PASSWORD, messagePassword);
                    intent.putExtra(Default.EXTRA_EMAIL, messageMail);
                    startActivity(intent);
                    progressDialog.cancel();
                    finish();
                    Toast.makeText(RegistrationActivity.this, "Registration was successful", Toast.LENGTH_LONG).show();
                }

                @Override
                public void handleFault(BackendlessFault backendlessFault) {
                    progressDialog.cancel();
                    Toast.makeText(RegistrationActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    Button cancelBtn = (Button) findViewById(R.id.cancelBtn);
    cancelBtn.setTypeface(typeface);
    cancelBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
            startActivity(intent);
            finish();
        }
    });
}
Also used : EditText(android.widget.EditText) BackendlessUser(com.backendless.BackendlessUser) Typeface(android.graphics.Typeface) AsyncCallback(com.backendless.async.callback.AsyncCallback) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) Button(android.widget.Button) TextView(android.widget.TextView)

Example 12 with AsyncCallback

use of com.backendless.async.callback.AsyncCallback in project Android-SDK by Backendless.

the class EndlessTaggingActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data == null)
        return;
    switch(requestCode) {
        case Default.CATEGORY_RESULT_SEARCH:
            googleMap.clear();
            googleMap.addMarker(new MarkerOptions().position(myPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_red)));
            List<String> searchCategory = Arrays.asList(data.getStringArrayExtra(Default.SEARCH_CATEGORY_NAME));
            selectedCategories = new ArrayList<String>();
            selectedCategories = searchCategory;
            searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
            break;
        case Default.ADD_NEW_CATEGORY_RESULT:
            String categoryTriger = data.getStringExtra(Default.CATEGORY_TRIGER);
            if (categoryTriger.equals("1"))
                category = data.getStringExtra(Default.NEW_CATEGORY_NAME);
            if (categoryTriger.equals("2"))
                pointCategories = Arrays.asList(data.getStringArrayExtra(Default.SEARCH_CATEGORY_NAME));
            if (categoryTriger.equals("3")) {
                category = data.getStringExtra(Default.NEW_CATEGORY_NAME);
                pointCategories = Arrays.asList(data.getStringArrayExtra(Default.SEARCH_CATEGORY_NAME));
            }
            Intent intentComment = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
            intentComment.putExtra(Default.FILE_PATH, filePath);
            startActivityForResult(intentComment, Default.ADD_NEW_POINT_RESULT);
            break;
        case Default.ADD_NEW_POINT_RESULT:
            pointNameNew = data.getStringExtra(Default.NEW_POINT_NAME);
            googleMap.clear();
            if (category != null && pointCategories.isEmpty()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
                builder.setMessage(R.string.save_data);
                builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        List<String> categories = new ArrayList<String>();
                        categories.add(category);
                        Map<String, String> metadata = new HashMap<String, String>();
                        metadata.put("pointName", pointNameNew);
                        metadata.put("pointDescription", category);
                        metadata.put("photoUrl", photoUrl);
                        metadata.put("endlessTagging", "true");
                        if (onMapClick) {
                            latitude = latitudeOnMap;
                            longitude = longitudeOnMap;
                        }
                        GeoPoint geoPoint = new GeoPoint(latitude, longitude, categories, metadata);
                        progressDialog = ProgressDialog.show(EndlessTaggingActivity.this, "", "Loading", true);
                        Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() {

                            @Override
                            public void handleResponse(GeoPoint geoPoint) {
                                adapter.add(geoPoint);
                                progressDialog.cancel();
                                selectedCategories = new ArrayList<String>();
                                selectedCategories.add(category);
                                searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
                            }

                            @Override
                            public void handleFault(BackendlessFault backendlessFault) {
                                progressDialog.cancel();
                                Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                });
                builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
                        startActivity(intent);
                        finish();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            } else if (category == null && !pointCategories.isEmpty()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
                builder.setMessage(R.string.save_data);
                builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        List<String> categories = new ArrayList<String>();
                        categories.addAll(pointCategories);
                        StringBuilder result = new StringBuilder();
                        for (int i = 0; i < pointCategories.size(); i++) {
                            result.append(pointCategories.get(i));
                            if (i < pointCategories.size() - 1)
                                result.append(", ");
                        }
                        categoryInLine = result.toString();
                        Map<String, String> metadata = new HashMap<String, String>();
                        metadata.put("pointName", pointNameNew);
                        metadata.put("pointDescription", categoryInLine);
                        metadata.put("photoUrl", photoUrl);
                        metadata.put("endlessTagging", "true");
                        if (onMapClick) {
                            latitude = latitudeOnMap;
                            longitude = longitudeOnMap;
                        }
                        GeoPoint geoPoint = new GeoPoint(latitude, longitude, categories, metadata);
                        progressDialog = ProgressDialog.show(EndlessTaggingActivity.this, "", "Loading", true);
                        Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() {

                            @Override
                            public void handleResponse(GeoPoint geoPoint) {
                                adapter.add(geoPoint);
                                selectedCategories = new ArrayList<String>();
                                selectedCategories.addAll(pointCategories);
                                searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
                                progressDialog.cancel();
                            }

                            @Override
                            public void handleFault(BackendlessFault backendlessFault) {
                                progressDialog.cancel();
                                Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                });
                builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
                        startActivity(intent);
                        finish();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            } else if (category != null && !pointCategories.isEmpty()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
                builder.setMessage(R.string.save_data);
                builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        List<String> categories = new ArrayList<String>();
                        categories.add(category);
                        categories.addAll(pointCategories);
                        StringBuilder result = new StringBuilder();
                        for (int i = 0; i < categories.size(); i++) {
                            result.append(categories.get(i));
                            if (i < categories.size() - 1)
                                result.append(", ");
                        }
                        categoryInLine = result.toString();
                        Map<String, String> metadata = new HashMap<String, String>();
                        metadata.put("pointName", pointNameNew);
                        metadata.put("pointDescription", categoryInLine);
                        metadata.put("photoUrl", photoUrl);
                        metadata.put("endlessTagging", "true");
                        if (onMapClick) {
                            latitude = latitudeOnMap;
                            longitude = longitudeOnMap;
                        }
                        GeoPoint geoPoint = new GeoPoint(latitude, longitude, categories, metadata);
                        progressDialog = ProgressDialog.show(EndlessTaggingActivity.this, "", "Loading", true);
                        Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() {

                            @Override
                            public void handleResponse(GeoPoint geoPoint) {
                                adapter.add(geoPoint);
                                progressDialog.cancel();
                                selectedCategories = new ArrayList<String>();
                                selectedCategories.add(category);
                                selectedCategories.addAll(pointCategories);
                                searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
                            }

                            @Override
                            public void handleFault(BackendlessFault backendlessFault) {
                                progressDialog.cancel();
                                Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                });
                builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
                        startActivity(intent);
                        finish();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            }
            break;
        case Default.ADD_NEW_COMMENT:
            googleMap.clear();
            googleMap.addMarker(new MarkerOptions().position(myPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_red)));
            String nameCategory = data.getStringExtra(Default.SEARCH_CATEGORY_NAME);
            selectedCategories = new ArrayList<String>();
            selectedCategories.add(nameCategory);
            searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
            break;
        case Default.ADD_NEW_PHOTO_RESULT:
            photoUrl = data.getStringExtra(Default.PHOTO_CAMERA_URL);
            if (photoUrl == null)
                photoUrl = data.getStringExtra(Default.PHOTO_BROWSE_URL);
            filePath = data.getStringExtra(Default.FILE_PATH);
            Intent intent = new Intent(EndlessTaggingActivity.this, CreateNewCategoryActivity.class);
            startActivityForResult(intent, Default.ADD_NEW_CATEGORY_RESULT);
            break;
        default:
            break;
    }
}
Also used : DialogInterface(android.content.DialogInterface) AsyncCallback(com.backendless.async.callback.AsyncCallback) GeoPoint(com.backendless.geo.GeoPoint) Intent(android.content.Intent) GeoPoint(com.backendless.geo.GeoPoint) BackendlessFault(com.backendless.exceptions.BackendlessFault) GoogleMap(com.google.android.gms.maps.GoogleMap)

Aggregations

AsyncCallback (com.backendless.async.callback.AsyncCallback)12 BackendlessFault (com.backendless.exceptions.BackendlessFault)11 View (android.view.View)5 Intent (android.content.Intent)4 TextView (android.widget.TextView)4 Typeface (android.graphics.Typeface)3 Button (android.widget.Button)3 EditText (android.widget.EditText)3 BackendlessUser (com.backendless.BackendlessUser)3 BackendlessCollection (com.backendless.BackendlessCollection)2 ResponseAsyncCallback (com.backendless.examples.endless.matchmaker.controllers.shared.ResponseAsyncCallback)2 BackendlessDataQuery (com.backendless.persistence.BackendlessDataQuery)2 List (java.util.List)2 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 Bitmap (android.graphics.Bitmap)1 KeyEvent (android.view.KeyEvent)1 CheckBox (android.widget.CheckBox)1 ImageView (android.widget.ImageView)1 Subscription (com.backendless.Subscription)1