private void loginApiSuccess(Object obj) { if (obj instanceof User) { final User user = (User) obj; if (user.getCode() == 200) { if (DemoContext.getInstance() != null && user.getResult() != null) { SharedPreferences.Editor edit = DemoContext.getInstance().getSharedPreferences().edit(); edit.putString("DEMO_USER_ID", user.getResult().getId()); edit.putString("DEMO_USER_NAME", user.getResult().getUsername()); edit.putString("DEMO_USER_PORTRAIT", user.getResult().getPortrait()); edit.apply(); Log.e(TAG, "-------login success------"); httpLoginSuccess(user); } } else if (user.getCode() == 103) { if (mDialog != null) mDialog.dismiss(); WinToast.toast(LoginActivity.this, "密码错误"); } else if (user.getCode() == 104) { if (mDialog != null) mDialog.dismiss(); WinToast.toast(LoginActivity.this, "账号错误"); } } }
@Override public boolean handleMessage(Message msg) { if (msg.what == HANDLER_LOGIN_FAILURE) { if (mDialog != null) mDialog.dismiss(); WinToast.toast(LoginActivity.this, R.string.login_failure); startActivity(new Intent(this, MainActivity.class)); finish(); } else if (msg.what == HANDLER_LOGIN_SUCCESS) { if (mDialog != null) mDialog.dismiss(); WinToast.toast(LoginActivity.this, R.string.login_success); startActivity(new Intent(this, MainActivity.class)); finish(); } else if (msg.what == HANDLER_LOGIN_HAS_FOCUS) { mLoginImg.setVisibility(View.GONE); mRegister.setVisibility(View.GONE); mFogotPassWord.setVisibility(View.GONE); mIsShowTitle.setVisibility(View.VISIBLE); mLeftTitle.setText(R.string.app_sign_up); mRightTitle.setText(R.string.app_fogot_password); } else if (msg.what == HANDLER_LOGIN_HAS_NO_FOCUS) { mLoginImg.setVisibility(View.VISIBLE); mRegister.setVisibility(View.VISIBLE); mFogotPassWord.setVisibility(View.VISIBLE); mIsShowTitle.setVisibility(View.GONE); } return false; }
private void getTokenApiSuccess(Object obj) { if (obj instanceof User) { final User user = (User) obj; if (user.getCode() == 200) { httpGetTokenSuccess(user.getResult().getToken()); SharedPreferences.Editor edit = DemoContext.getInstance().getSharedPreferences().edit(); edit.putString("DEMO_TOKEN", user.getResult().getToken()); edit.putBoolean("DEMO_ISFIRST", false); edit.apply(); Log.e(TAG, "------getTokenHttpRequest -success--" + user.getResult().getToken()); } else if (user.getCode() == 110) { WinToast.toast(LoginActivity.this, "请先登陆"); } else if (user.getCode() == 111) { WinToast.toast(LoginActivity.this, "cookie 为空"); } } }
/** 根据 targetid 和 ConversationType 进入到设置页面 */ private void enterSettingActivity() { if (mConversationType == Conversation.ConversationType.PUBLIC_SERVICE || mConversationType == Conversation.ConversationType.APP_PUBLIC_SERVICE) { RongIM.getInstance().startPublicServiceProfile(this, mConversationType, targetId); } else { // 通过targetId 和 会话类型 打开指定的设置页面 if (!TextUtils.isEmpty(targetId)) { Uri uri = Uri.parse("demo://" + getApplicationInfo().packageName) .buildUpon() .appendPath("conversationSetting") .appendPath(mConversationType.getName()) .appendQueryParameter("targetId", targetId) .build(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); startActivity(intent); // 当你刚刚创建完讨论组以后获得的是 targetIds } else if (!TextUtils.isEmpty(targetIds)) { UriFragment fragment = (UriFragment) getSupportFragmentManager().getFragments().get(0); fragment.getUri(); // 得到讨论组的 targetId targetId = fragment.getUri().getQueryParameter("targetId"); if (!TextUtils.isEmpty(targetId)) { Uri uri = Uri.parse("demo://" + getApplicationInfo().packageName) .buildUpon() .appendPath("conversationSetting") .appendPath(mConversationType.getName()) .appendQueryParameter("targetId", targetId) .build(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); startActivity(intent); } else { WinToast.toast(RongActivity.this, "讨论组尚未创建成功"); } } } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.app_sign_in_bt: // 登录 userName = mUserNameEt.getEditableText().toString(); String passWord = mPassWordEt.getEditableText().toString(); String name = null; if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(passWord)) { WinToast.toast(this, R.string.login_erro_is_null); return; } if (mDialog != null && !mDialog.isShowing()) { mDialog.show(); } // 发起登录 http请求 (注:非融云SDK接口,是demo接口) if (DemoContext.getInstance() != null) { // 如果切换了一个用户,token和 cookie 都需要重新获取 if (DemoContext.getInstance() != null) { name = DemoContext.getInstance() .getSharedPreferences() .getString("DEMO_USERNAME", "DEFAULT"); } if (!userName.equals(name)) { loginHttpRequest = DemoContext.getInstance().getDemoApi().login(userName, passWord, this); isFirst = true; } else { isFirst = false; String cookie = DemoContext.getInstance() .getSharedPreferences() .getString("DEMO_COOKIE", "DEFAULT"); String token = DemoContext.getInstance().getSharedPreferences().getString("DEMO_TOKEN", "DEFAULT"); if (!cookie.equals("DEFAULT") && !token.equals("DEFAULT")) { httpGetTokenSuccess(token); } else { loginHttpRequest = DemoContext.getInstance().getDemoApi().login(userName, passWord, this); } } } break; case R.id.de_left: // 注册 case R.id.de_login_register: // 注册 Intent intent = new Intent(this, RegisterActivity.class); startActivityForResult(intent, REQUEST_CODE_REGISTER); break; case R.id.de_login_forgot: // 忘记密码 WinToast.toast(this, "忘记密码"); break; case R.id.de_right: // 忘记密码 Intent intent1 = new Intent(this, RegisterActivity.class); startActivityForResult(intent1, REQUEST_CODE_REGISTER); break; case R.id.app_username_et: case R.id.app_password_et: Message mess = Message.obtain(); mess.what = HANDLER_LOGIN_HAS_FOCUS; mHandler.sendMessage(mess); break; } }