Search in sources :

Example 6 with AsyncCallback

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

the class ProfileActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.profile);
    TextView nameField = (TextView) findViewById(R.id.nameField);
    TextView genderField = (TextView) findViewById(R.id.genderField);
    TextView ageField = (TextView) findViewById(R.id.ageField);
    ImageView avatarImage = (ImageView) findViewById(R.id.avatarImage);
    ImageView genderImage = (ImageView) findViewById(R.id.genderImage);
    BackendlessUser currentUser = Backendless.UserService.CurrentUser();
    // Checking CurrentUser
    if (currentUser == null) {
        Lifecycle.runLoginActivity(ProfileActivity.this);
        finish();
    } else {
        nameField.setText((String) currentUser.getProperty(Defaults.NAME_PROPERTY));
        Gender userGender = Gender.valueOf((String) currentUser.getProperty(Defaults.GENDER_PROPERTY));
        genderField.setText(userGender.toString());
        if (userGender == Gender.male) {
            avatarImage.setImageDrawable(getResources().getDrawable(R.drawable.avatar_default_male));
            genderImage.setImageDrawable(getResources().getDrawable(R.drawable.icon_male));
        } else {
            avatarImage.setImageDrawable(getResources().getDrawable(R.drawable.avatar_default_female));
            genderImage.setImageDrawable(getResources().getDrawable(R.drawable.icon_female));
        }
        Date birthDate = (Date) currentUser.getProperty(Defaults.BIRTH_DATE_PROPERTY);
        ageField.setText(String.valueOf(SimpleMath.getAgeFromDate(birthDate)));
    }
    findViewById(R.id.findButton).setOnClickListener(findMatchesListener);
    findViewById(R.id.editFoodPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.FOOD));
    findViewById(R.id.editMusicPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.MUSIC));
    findViewById(R.id.editHobbiesPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.HOBBIES));
    findViewById(R.id.editTravelPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.TRAVEL));
    Button button_logout = (Button) findViewById(R.id.buttonLogOut);
    button_logout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            progressDialog = UIFactory.getDefaultProgressDialog(ProfileActivity.this);
            Backendless.UserService.logout(new AsyncCallback<Void>() {

                @Override
                public void handleResponse(Void aVoid) {
                    Lifecycle.runLoginActivity(ProfileActivity.this);
                    finish();
                    progressDialog.cancel();
                }

                @Override
                public void handleFault(BackendlessFault backendlessFault) {
                    progressDialog.cancel();
                    Toast.makeText(ProfileActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                }
            });
        }
    });
}
Also used : BackendlessUser(com.backendless.BackendlessUser) Button(android.widget.Button) ResponseAsyncCallback(com.backendless.examples.endless.matchmaker.controllers.shared.ResponseAsyncCallback) AsyncCallback(com.backendless.async.callback.AsyncCallback) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Gender(com.backendless.examples.endless.matchmaker.models.local.Gender) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 7 with AsyncCallback

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

the class MapDrivenDataStore method remove.

@Override
public void remove(Map entity, final AsyncCallback<Long> responder) {
    try {
        if (entity == null)
            throw new IllegalArgumentException(ExceptionMessage.NULL_ENTITY);
        AsyncCallback<Object> removalCallback = new AsyncCallback<Object>() {

            @Override
            public void handleResponse(Object response) {
                responder.handleResponse(((Number) response).longValue());
            }

            @Override
            public void handleFault(BackendlessFault fault) {
                if (responder != null)
                    responder.handleFault(fault);
            }
        };
        Object[] args = new Object[] { tableName, entity };
        Invoker.invokeAsync(Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "remove", args, removalCallback);
    } catch (Throwable e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : AsyncCallback(com.backendless.async.callback.AsyncCallback) NamedObject(weborb.reader.NamedObject) AnonymousObject(weborb.reader.AnonymousObject) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 8 with AsyncCallback

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

the class ReflectionUtil method getCallbackGenericType.

public static <T> Type getCallbackGenericType(AsyncCallback<T> callback) {
    Type[] genericInterfaces = callback.getClass().getGenericInterfaces();
    Type asyncCallbackInterface = null;
    for (Type genericInterface : genericInterfaces) {
        if (!(genericInterface instanceof ParameterizedType))
            continue;
        Type rawType = ((ParameterizedType) genericInterface).getRawType();
        if (rawType instanceof Class && AsyncCallback.class.isAssignableFrom((Class) rawType)) {
            asyncCallbackInterface = genericInterface;
            break;
        }
    }
    return ((ParameterizedType) asyncCallbackInterface).getActualTypeArguments()[0];
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) AsyncCallback(com.backendless.async.callback.AsyncCallback)

Example 9 with AsyncCallback

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

the class LoginActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_login);
    Backendless.initApp(LoginActivity.this, Default.APP_ID, Default.SECRET_KEY, Default.VERSION);
    TextView textEmail = (TextView) findViewById(R.id.textEmail);
    TextView textPass = (TextView) findViewById(R.id.textPass);
    TextView textPiar = (TextView) findViewById(R.id.textPiar);
    TextView textOr = (TextView) findViewById(R.id.textOr);
    Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
    textEmail.setTypeface(typeface);
    textPass.setTypeface(typeface);
    textPiar.setTypeface(typeface);
    textOr.setTypeface(typeface);
    final Button loginBtn = (Button) findViewById(R.id.loginBtn);
    loginBtn.setTypeface(typeface);
    loginBtn.setOnClickListener(new View.OnClickListener() {

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

                @Override
                public void handleResponse(BackendlessUser backendlessUser) {
                    progressDialog.cancel();
                    Intent intent = new Intent(LoginActivity.this, EndlessTaggingActivity.class);
                    intent.putExtra(Default.EXTRA_EMAIL, messageMail);
                    intent.putExtra(Default.EXTRA_PASSWORD, messagePassword);
                    startActivity(intent);
                }

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

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(LoginActivity.this, RegistrationActivity.class);
            startActivity(intent);
            finish();
        }
    });
    Button facebookBtn = (Button) findViewById(R.id.facebookBtn);
    facebookBtn.setTypeface(typeface);
    facebookBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Backendless.UserService.loginWithFacebook(LoginActivity.this, new AsyncCallback<BackendlessUser>() {

                @Override
                public void handleResponse(BackendlessUser response) {
                    Intent intent = new Intent(LoginActivity.this, EndlessTaggingActivity.class);
                    startActivity(intent);
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    Toast.makeText(LoginActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    Button twitterBtn = (Button) findViewById(R.id.twitterBtn);
    twitterBtn.setTypeface(typeface);
    twitterBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Backendless.UserService.loginWithTwitter(LoginActivity.this, new AsyncCallback<BackendlessUser>() {

                @Override
                public void handleResponse(BackendlessUser response) {
                    Intent intent = new Intent(LoginActivity.this, EndlessTaggingActivity.class);
                    startActivity(intent);
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    Toast.makeText(LoginActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
                }
            });
        }
    });
}
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 10 with AsyncCallback

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

the class PointCommentsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_point_comments);
    photoBtn = (Button) findViewById(R.id.photoBtn);
    photoBtn.setVisibility(View.INVISIBLE);
    final TextView textViewComment = (TextView) findViewById(R.id.textViewComment);
    TextView textPointComments = (TextView) findViewById(R.id.textPointComments);
    Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
    textPointComments.setTypeface(typeface);
    textViewComment.setTypeface(typeface);
    textViewComment.setVisibility(View.INVISIBLE);
    final EditText editComment = (EditText) findViewById(R.id.editComment);
    editComment.setVisibility(View.INVISIBLE);
    photoBtn.setTypeface(typeface);
    Intent intent = getIntent();
    geoPointId = intent.getStringExtra(Default.GEO_POINT_ID);
    userName = (String) Backendless.UserService.CurrentUser().getProperty("name");
    if (userName == null)
        userName = Backendless.UserService.CurrentUser().getEmail();
    Bitmap bitmap = intent.getParcelableExtra(Default.SEND_BITMAP);
    imageView = (ImageView) findViewById(R.id.photoView);
    imageView.setImageBitmap(bitmap);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    final Button commentsBtn = (Button) findViewById(R.id.commentsBtn);
    commentsBtn.setTypeface(typeface);
    commentsBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            imageView.setVisibility(View.INVISIBLE);
            commentsBtn.setEnabled(false);
            BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery();
            backendlessDataQuery.addProperty("name");
            backendlessDataQuery.addProperty("message");
            backendlessDataQuery.setWhereClause("geoPointId=" + "'" + geoPointId + "'");
            progressDialog = ProgressDialog.show(PointCommentsActivity.this, "", "Loading", true);
            Backendless.Persistence.of(Comment.class).find(backendlessDataQuery, new AsyncCallback<Collection<Comment>>() {

                @Override
                public void handleResponse(Collection<Comment> response) {
                    Collection<Comment> comments = response;
                    for (int i = 0; i < comments.getCurrentPage().size(); i++) {
                        Comment comment = comments.getCurrentPage().get(i);
                        String userName = comment.getName();
                        commentsPoint.add(userName + "  :  " + comment.getMessage());
                    }
                    lvMain = (ListView) findViewById(R.id.commentList);
                    lvMain.setVisibility(View.VISIBLE);
                    adapter = new ArrayAdapter<String>(PointCommentsActivity.this, android.R.layout.simple_list_item_1, commentsPoint);
                    lvMain.setAdapter(adapter);
                    progressDialog.cancel();
                    textViewComment.setVisibility(View.VISIBLE);
                    editComment.setVisibility(View.VISIBLE);
                    addCommentBtn.setVisibility(View.VISIBLE);
                    commentsBtn.setVisibility(View.INVISIBLE);
                    photoBtn.setVisibility(View.VISIBLE);
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    progressDialog.cancel();
                    Toast.makeText(PointCommentsActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
                    textViewComment.setVisibility(View.VISIBLE);
                    editComment.setVisibility(View.VISIBLE);
                    addCommentBtn.setVisibility(View.VISIBLE);
                    commentsBtn.setVisibility(View.INVISIBLE);
                    photoBtn.setVisibility(View.VISIBLE);
                }
            });
        }
    });
    addCommentBtn = (Button) findViewById(R.id.addCommentBtn);
    addCommentBtn.setTypeface(typeface);
    addCommentBtn.setVisibility(View.INVISIBLE);
    addCommentBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final String commentName = editComment.getText().toString();
            if (TextUtils.isEmpty(commentName)) {
                String alertMessage = "Please, fill in empty field!";
                Toast.makeText(PointCommentsActivity.this, alertMessage, Toast.LENGTH_LONG).show();
                return;
            }
            progressDialog = ProgressDialog.show(PointCommentsActivity.this, "", "Loading", true);
            Comment commentPoint = new Comment(userName, commentName, geoPointId);
            Backendless.Persistence.save(commentPoint, new BackendlessCallback<Comment>() {

                @Override
                public void handleResponse(Comment commentPoint) {
                    Intent categoryIntent = getIntent();
                    String name = categoryIntent.getStringExtra(Default.SEARCH_CATEGORY_NAME);
                    Intent intent = new Intent();
                    intent.putExtra(Default.SEARCH_CATEGORY_NAME, name);
                    setResult(Default.ADD_NEW_COMMENT, intent);
                    progressDialog.cancel();
                    finish();
                    Toast.makeText(PointCommentsActivity.this, "A new comment was successfully added", Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    photoBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            adapter.clear();
            lvMain.setAdapter(adapter);
            lvMain.setVisibility(View.INVISIBLE);
            textViewComment.setVisibility(View.INVISIBLE);
            editComment.setVisibility(View.INVISIBLE);
            addCommentBtn.setVisibility(View.VISIBLE);
            imageView.setVisibility(View.VISIBLE);
            photoBtn.setVisibility(View.INVISIBLE);
            commentsBtn.setVisibility(View.VISIBLE);
            commentsBtn.setEnabled(true);
        }
    });
}
Also used : Typeface(android.graphics.Typeface) AsyncCallback(com.backendless.async.callback.AsyncCallback) Intent(android.content.Intent) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) Bitmap(android.graphics.Bitmap) BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery) BackendlessCallback(com.backendless.async.callback.BackendlessCallback) BackendlessCollection(com.backendless.BackendlessCollection)

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