/** 登录IM */ public void loginIMTask(final User user) { if (IMUtil.isLogin()) { return; } AbDialogUtil.showProgressDialog(MainActivity.this, R.drawable.ic_load, "登录到IM"); AbTask task = new AbTask(); final AbTaskItem item = new AbTaskItem(); item.setListener( new AbTaskObjectListener() { @Override public <T> void update(T entity) { AbDialogUtil.removeDialog(MainActivity.this); Log.d("TAG", "登录执行完成"); int code = (Integer) entity; if (code == IMUtil.SUCCESS_CODE || code == IMUtil.LOGGED_CODE) { AbToastUtil.showToast(MainActivity.this, "IM登录成功"); // 启动IM服务 startIMService(); // 要跳转到哪里 toByIntent(getIntent()); } else if (code == IMUtil.FAIL_CODE) { AbToastUtil.showToast(MainActivity.this, "IM登录失败"); } } @SuppressWarnings("unchecked") @Override public Integer getObject() { int code = IMUtil.FAIL_CODE; try { // 设置用户名与密码 code = IMUtil.loginIM(user.getUserName(), user.getPassword()); } catch (Exception e) { e.printStackTrace(); } return code; } }); task.execute(item); }
/** 显示刷新弹出框有背景层 */ public void showRefreshDialog() { // 显示重新刷新的框 final AbRefreshDialogFragment mDialogFragment = AbDialogUtil.showRefreshDialog(this, R.drawable.ic_refresh, "请求出错,请重试"); mDialogFragment.setAbDialogOnLoadListener( new AbDialogOnLoadListener() { @Override public void onLoad() { // 下载网络数据 downRss(mDialogFragment); } }); // 取消的监听 mDialogFragment.setOnCancelListener( new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { AbToastUtil.showToast(DialogActivity.this, "refresh框被取消"); } }); }
/** 显示刷新弹出框有背景层 */ public void showLoadDialog() { final AbLoadDialogFragment mDialogFragment = AbDialogUtil.showLoadDialog(this, R.drawable.ic_load, "正在查询,请稍候"); mDialogFragment.setAbDialogOnLoadListener( new AbDialogOnLoadListener() { @Override public void onLoad() { // 下载网络数据 downRss(mDialogFragment); } }); // 取消的监听 mDialogFragment.setOnCancelListener( new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { AbToastUtil.showToast(DialogActivity.this, "Load框被取消"); } }); }
@Override public void onClick(View v) { mStr_name = userName.getText().toString().trim(); mStr_email = email.getText().toString().trim(); if (TextUtils.isEmpty(mStr_name)) { AbToastUtil.showToast(FindPwdActivity.this, R.string.error_name); userName.setFocusable(true); userName.requestFocus(); return; } if (!AbStrUtil.isNumberLetter(mStr_name)) { AbToastUtil.showToast(FindPwdActivity.this, R.string.error_name_expr); userName.setFocusable(true); userName.requestFocus(); return; } if (AbStrUtil.strLength(mStr_name) < 3) { AbToastUtil.showToast(FindPwdActivity.this, R.string.error_name_length1); userName.setFocusable(true); userName.requestFocus(); return; } if (AbStrUtil.strLength(mStr_name) > 20) { AbToastUtil.showToast(FindPwdActivity.this, R.string.error_name_length2); userName.setFocusable(true); userName.requestFocus(); return; } if (!TextUtils.isEmpty(mStr_email)) { if (!AbStrUtil.isEmail(mStr_email)) { AbToastUtil.showToast(FindPwdActivity.this, R.string.error_email_expr); email.setFocusable(true); email.requestFocus(); return; } } else { AbToastUtil.showToast(FindPwdActivity.this, R.string.error_email); email.setFocusable(true); email.requestFocus(); } AbDialogUtil.showProgressDialog( FindPwdActivity.this, R.drawable.progress_circular, "正在找回..."); final AbTaskItem item = new AbTaskItem(); item.setListener( new AbTaskObjectListener() { @Override public void update(Object obj) { AbDialogUtil.removeDialog(FindPwdActivity.this); AbResult mAbResult = (AbResult) obj; if (mAbResult != null) { AbToastUtil.showToast(FindPwdActivity.this, mAbResult.getResultMessage()); if (mAbResult.getResultCode() == AbResult.RESULR_OK) { finish(); } } } @Override public Object getObject() { AbResult mAbResult = null; try { mAbResult = new AbResult(); mAbResult.setResultMessage("ok"); } catch (Exception e) { AbToastUtil.showToastInThread(FindPwdActivity.this, e.getMessage()); } return mAbResult; }; }); mAbTaskPool.execute(item); }
public void btnClick(View v) { View mView = null; switch (v.getId()) { case R.id.button2: mView = mInflater.inflate(R.layout.dialog_custom_view, null); AbDialogUtil.showDialog( mView, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { AbToastUtil.showToast(DialogActivity.this, "弹出框被取消"); } }); break; case R.id.button3: mView = mInflater.inflate(R.layout.dialog_custom_view, null); AbDialogUtil.showDialog( mView, AbDialogUtil.ThemeLightPanel, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { AbToastUtil.showToast(DialogActivity.this, "弹出框被取消"); } }); break; case R.id.button4: // 显示有背景层的加载的弹出框 showLoadDialog(); break; case R.id.button5: // 显示无背景层的加载的弹出框 showLoadPanel(); break; case R.id.button6: // 显示有背景层的刷新的弹出框 showRefreshDialog(); break; case R.id.button7: // 显示无背景层的刷新的弹出框 showRefreshPanel(); break; case R.id.button8: AbDialogUtil.showAlertDialog( DialogActivity.this, R.drawable.ic_alert, "这里是标题", "这里写一些描述", new AbDialogOnClickListener() { @Override public void onPositiveClick() { AbToastUtil.showToast(DialogActivity.this, "点击了确认"); } @Override public void onNegativeClick() { AbToastUtil.showToast(DialogActivity.this, "点击了取消"); } }); break; case R.id.button9: AbDialogUtil.showAlertDialog( DialogActivity.this, R.drawable.ic_alert, "这里是标题", "这里写一些描述", null); break; case R.id.button10: mView = mInflater.inflate(R.layout.dialog_custom_view, null); AbDialogUtil.showAlertDialog(mView); break; case R.id.button11: // 无按钮+动画 mView = mInflater.inflate(R.layout.dialog_text, null); AbDialogUtil.showDialog( mView, R.animator.fragment_top_enter, R.animator.fragment_top_exit, R.animator.fragment_pop_top_enter, R.animator.fragment_pop_top_exit); break; case R.id.button12: // 按钮+列表 mView = mInflater.inflate(R.layout.dialog_button_listview, null); AbDialogUtil.showDialog( mView, R.animator.fragment_top_enter, R.animator.fragment_top_exit, R.animator.fragment_pop_top_enter, R.animator.fragment_pop_top_exit); ListView listView = (ListView) mView.findViewById(R.id.list); String[] mStrings = {"对话框选项item1", "对话框选项item2", "对话框选项item3", "对话框选项item4"}; listView.setAdapter(new ArrayAdapter<String>(this, R.layout.dialog_list_item_1, mStrings)); Button leftBtn = (Button) mView.findViewById(R.id.left_btn); Button rightBtn = (Button) mView.findViewById(R.id.right_btn); leftBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { AbDialogUtil.removeDialog(DialogActivity.this); } }); rightBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { AbDialogUtil.removeDialog(DialogActivity.this); } }); break; case R.id.button13: // 按钮+文本 // 动画未生效 mView = mInflater.inflate(R.layout.dialog_text_button, null); AbDialogUtil.showDialog( mView, R.animator.fragment_top_enter, R.animator.fragment_top_exit, R.animator.fragment_pop_top_enter, R.animator.fragment_pop_top_exit); Button leftBtn1 = (Button) mView.findViewById(R.id.left_btn); Button rightBtn1 = (Button) mView.findViewById(R.id.right_btn); leftBtn1.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { AbDialogUtil.removeDialog(DialogActivity.this); } }); rightBtn1.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { AbDialogUtil.removeDialog(DialogActivity.this); } }); break; case R.id.button14: // 上 mView = mInflater.inflate(R.layout.dialog_custom_view, null); AbDialogUtil.showDialog(mView, Gravity.TOP); break; case R.id.button15: // 中 mView = mInflater.inflate(R.layout.dialog_custom_view, null); AbDialogUtil.showDialog(mView, Gravity.CENTER); break; case R.id.button16: // 下 mView = mInflater.inflate(R.layout.dialog_custom_view, null); AbDialogUtil.showDialog(mView, Gravity.BOTTOM); break; case R.id.button17: // 全屏 mView = mInflater.inflate(R.layout.dialog_custom_view, null); AbDialogUtil.showFullScreenDialog(mView); break; case R.id.button18: AbDialogUtil.showProgressDialog(DialogActivity.this, 0, "查询中..."); new Handler() .postDelayed( new Runnable() { @Override public void run() { AbDialogUtil.removeDialog(DialogActivity.this); } }, 2000); break; case R.id.button19: AbToastUtil.showToast(DialogActivity.this, "Toast提示框"); break; default: break; } }