0

这是代码:

public class ProfileActivity extends Activity {

private final static int    DIALOG_PROGRESS = 0;
private final static int    DIALOG_SUCCESS  = 1;
private final static int    DIALOG_ERROR    = 2;

private EditText usernameText;
private EditText emailText;

// saves the last error occurred, so we can read it in onPrepareDialog()
String dialogErrorMsg = "";
String dialogSuccessMsg = "";


public void onResume() {
    super.onResume();

    // here we fetch the user's profile data from Scoreloop to fill in 
    // the text fields

    // first, a request observer...
    RequestControllerObserver observer = new RequestControllerObserver() {


        public void requestControllerDidReceiveResponse(RequestController requestController) {
            UserController userController = (UserController)requestController;
            dismissDialog(DIALOG_PROGRESS);

            // insert values into text fields
            User user = userController.getUser();
            usernameText.setText(user.getLogin());
            emailText.setText(user.getEmailAddress());
        }


        public void requestControllerDidFail(RequestController aRequestController, Exception anException) {
            // the profile could not be loaded :(
            dismissDialog(DIALOG_PROGRESS);

            // show some error message
            dialogErrorMsg = "خطأ في تحميل الملف الشخصي";
            showDialog(DIALOG_ERROR);
        }
    };

    // here's the UserController doing our work to update the profile data
    UserController userController = new UserController(observer);

    // show progress dialog
    showDialog(DIALOG_PROGRESS);

    // and fire the request
    userController.loadUser();
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // load the layout
    setContentView(R.layout.profile);

    // find our text fields
    usernameText = (EditText) findViewById(R.id.text_username);
    emailText = (EditText) findViewById(R.id.text_email);

    // set up click handler for the save button
    ((Button) findViewById(R.id.button_save_profile)).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            // get the current User
            User user = Session.getCurrentSession().getUser();

            // update his values
            user.setLogin(usernameText.getText().toString());
            user.setEmailAddress(emailText.getText().toString());

            // set up a request observer
            RequestControllerObserver observer = new RequestControllerObserver() {


                public void requestControllerDidReceiveResponse(RequestController aRequestController) {
                    dismissDialog(DIALOG_PROGRESS);

                    dialogSuccessMsg = "تم تحميل الملف الشخصي بنجاح";

                    showDialog(DIALOG_SUCCESS);
                }


                public void requestControllerDidFail(RequestController controller, Exception exception) {
                    dismissDialog(DIALOG_PROGRESS);

                    // Error handling has to account for many different types of
                    // failures...

                    if(exception instanceof RequestControllerException) {

                        RequestControllerException ctrlException = (RequestControllerException) exception;

                        if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_EMAIL_TAKEN)) {
                            // this case is not quite a fatal error. if the email address is already
                            // taken, an email will be sent to it to allow the user to link this device
                            // with his account. 
                            // that's why we'll show a success dialog in this case.
                            dialogSuccessMsg = "تم إستخدام الأميل من قبل شخص آخر";
                            showDialog(DIALOG_SUCCESS);
                        }
                        else {
                            // in any of these cases it's an error:

                            dialogErrorMsg= "";
                            // email may be invalid
                            if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_INVALID_EMAIL)) {
                                dialogErrorMsg += "خطأ في الأميل";
                            }

                            // username may be invalid, taken or too short
                            if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_USERNAME_TAKEN)) {
                                dialogErrorMsg += "تم إستخدام الأسم من قبل شخص آخر";
                            }
                            else if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_USERNAME_TOO_SHORT)) {
                                dialogErrorMsg += "الأسم قصير جدا";
                            }
                            else if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_INVALID_USERNAME)) {
                                dialogErrorMsg += "الأسم غير صالح للإستخدام";
                            }

                            showDialog(DIALOG_ERROR);
                        }
                    }
                    else {
                        // generic Exception
                        dialogErrorMsg = exception.getLocalizedMessage();
                        showDialog(DIALOG_ERROR);
                    }


                    // update displayed values
                    User user = ((UserController)controller).getUser();
                    usernameText.setText(user.getLogin());
                    emailText.setText(user.getEmailAddress());

                }
            };

            // with our observer, set up the request controller
            UserController userController = new  UserController(observer);

            // pass the user into the controller
            userController.setUser(user);

            showDialog(DIALOG_PROGRESS);

            // submit our changes
            userController.submitUser();

        }
    });
}



// handler to create our dialogs
@Override
protected Dialog onCreateDialog(final int id) {
    switch (id) {
    case DIALOG_PROGRESS:
        return ProgressDialog.show(ProfileActivity.this, "", "جاري التحميل");
    case DIALOG_ERROR:
        return (new AlertDialog.Builder(this))
            .setPositiveButton("إغلاق", null)
            .setMessage("")
            .create();
    case DIALOG_SUCCESS:
        return (new AlertDialog.Builder(this))
            .setPositiveButton("إغلاق", null)
            .setMessage("")
            .create();
    }
    return null;
}

// handler to update the success and error dialog with the corresponding message
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {
    case DIALOG_ERROR:
        AlertDialog errorDialog = (AlertDialog)dialog;
        errorDialog.setMessage(dialogErrorMsg);
        break;
    case DIALOG_SUCCESS:
        AlertDialog successDialog = (AlertDialog)dialog;
        successDialog.setMessage(dialogSuccessMsg);
        break;
    }
}

}

它总是无法提交新用户。没有任何理由,我已经在我的主屏幕中初始化了它。

 Client.init(this, secret, null);

我也将 socreloop.properties 复制到我的协助文件夹中。

提交新分数时也会出现同样的问题。它不会提交。谢谢。

4

1 回答 1

0

您是否在模拟器上测试它,因为在我的情况下,从模拟器测试添加新用户需要很长时间,有时甚至无法从模拟器添加新用户,尝试从 android 设备测试它。

于 2012-11-24T18:23:54.250 回答