Search in sources :

Example 1 with GlideEngine

use of com.zhihu.matisse.engine.impl.GlideEngine in project Palm300Heroes by nicolite.

the class UserInfoActivity method onViewClicked.

@OnClick({ R.id.rl_user_avatar, R.id.rl_nickName, R.id.rl_user_pwd, R.id.rl_user_gender, R.id.user_logout })
public void onViewClicked(View view) {
    switch(view.getId()) {
        case R.id.rl_user_avatar:
            Matisse.from(this).choose(MimeType.of(MimeType.PNG, MimeType.JPEG)).countable(true).maxSelectable(1).restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED).thumbnailScale(0.85f).imageEngine(new GlideEngine()).forResult(REQUEST_CODE_CHOOSE_PICTURE);
            break;
        case R.id.rl_nickName:
            LinearLayout editor = (LinearLayout) getLayoutInflater().inflate(R.layout.item_single_eidtor, null, false);
            final EditText edInput = (EditText) editor.findViewById(R.id.ed_input);
            new AlertDialog.Builder(this).setTitle("请输入昵称").setView(editor).setPositiveButton("确定", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    String nickNameText = edInput.getText().toString();
                    if (TextUtils.isEmpty(nickNameText)) {
                        ToastUtils.showToastShort("昵称不能为空");
                        return;
                    }
                    nickName.setText(nickNameText);
                    user.setNickName(nickNameText);
                    saveUserInfo(user);
                }
            }).setNegativeButton("取消", null).show();
            break;
        case R.id.rl_user_pwd:
            LinearLayout changePwd = (LinearLayout) getLayoutInflater().inflate(R.layout.item_change_password, null, false);
            final EditText originPwd = (EditText) changePwd.findViewById(R.id.et_origin_pwd);
            final EditText newPwd = (EditText) changePwd.findViewById(R.id.et_new_pwd);
            final EditText newPwd2 = (EditText) changePwd.findViewById(R.id.et_new_pwd2);
            new AlertDialog.Builder(this).setTitle("修改密码").setView(changePwd).setPositiveButton("确认", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    String originPassword = originPwd.getText().toString();
                    String newPassword = newPwd.getText().toString();
                    String newPassword2 = newPwd2.getText().toString();
                    if (TextUtils.isEmpty(originPassword) || TextUtils.isEmpty(newPassword) || TextUtils.isEmpty(newPassword2)) {
                        ToastUtils.showToastShort("请填写完整");
                        return;
                    } else if (!newPassword.equals(newPassword2)) {
                        ToastUtils.showToastShort("两次输入的密码不一致");
                        return;
                    }
                    BmobUser.updateCurrentUserPassword(originPassword, newPassword, new UpdateListener() {

                        @Override
                        public void done(BmobException e) {
                            if (e == null) {
                                ToastUtils.showToastShort("修改成功!");
                                BmobUser.logOut();
                                UserInfoActivity.this.setResult(2);
                                finish();
                            } else {
                                ToastUtils.showToastShort("修改失败!");
                            }
                        }
                    });
                }
            }).setNegativeButton("取消", null).show();
            break;
        case R.id.rl_user_gender:
            final String[] items = { "男", "女" };
            selected = userData.getGender() == null ? 0 : (userData.getGender() ? 0 : 1);
            new AlertDialog.Builder(this).setTitle("请选择").setSingleChoiceItems(items, selected, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    selected = i;
                }
            }).setPositiveButton("确定", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    userGender.setImageResource(items[selected].equals("男") ? R.drawable.male : R.drawable.female);
                    user.setGender(items[selected].equals("男"));
                    saveUserInfo(user);
                }
            }).setNegativeButton("取消", null).show();
            break;
        case R.id.user_logout:
            BmobUser.logOut();
            UserInfoActivity.this.setResult(2);
            finish();
            break;
    }
}
Also used : EditText(android.widget.EditText) AlertDialog(android.support.v7.app.AlertDialog) BmobException(cn.bmob.v3.exception.BmobException) GlideEngine(com.zhihu.matisse.engine.impl.GlideEngine) DialogInterface(android.content.DialogInterface) UpdateListener(cn.bmob.v3.listener.UpdateListener) LinearLayout(android.widget.LinearLayout) OnClick(butterknife.OnClick)

Aggregations

DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 OnClick (butterknife.OnClick)1 BmobException (cn.bmob.v3.exception.BmobException)1 UpdateListener (cn.bmob.v3.listener.UpdateListener)1 GlideEngine (com.zhihu.matisse.engine.impl.GlideEngine)1