仿QQ登录(账号列表并可编辑)

/**自定义popupwindow*/
public class PopuAccountListView extends PopupWindow implements OnItemClickListener {
	private View ListPopupWindow;
	private ListView lv_loginaccount;
	private LoginAccountlistAdapter loginAccountlistAdapter;
	private ArrayList<AccountAndChild> accountAndChildinfo;
	public PopuAccountListView(Context context,ArrayList<AccountAndChild> accountAndChilds) {
		ListPopupWindow = LayoutInflater.from(context).inflate(R.layout.popu_acountlist, null);
		lv_loginaccount = (ListView) ListPopupWindow.findViewById(R.id.lv_loginaccount);
		lv_loginaccount.setOnItemClickListener(this);
		loginAccountlistAdapter = new LoginAccountlistAdapter(context,accountAndChilds);
//		loginAccountlistAdapter.updateDatas(accountAndChilds);
		lv_loginaccount.setAdapter(loginAccountlistAdapter);
		this.accountAndChildinfo = accountAndChilds;
		setBackgroundDrawable(new BitmapDrawable());
		setContentView(ListPopupWindow);
		setFocusable(true);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		AccountAndChild accountAndChild=accountAndChildinfo.get(arg2);
		if(onItemClickAndGetAccount!=null){
			onItemClickAndGetAccount.getAccountInfo(accountAndChild);
			cancelShow();
		}
	}
	public interface OnItemClickAndGetAccount{
		public void getAccountInfo(AccountAndChild accountAndChild);
	}
	private OnItemClickAndGetAccount onItemClickAndGetAccount;
	
	public void SetOnItemClickAndGetAccount(OnItemClickAndGetAccount onItemClickAndGetAccount){
		this.onItemClickAndGetAccount=onItemClickAndGetAccount;
		
	}
	/**
	 * 
	 * @param view
	 * 下拉列表所在位置的参照物
	 */
	public void showPopupWindow(View view){
		setWidth(LayoutParams.MATCH_PARENT);
		setHeight(LayoutParams.WRAP_CONTENT);
		showAsDropDown(view);
	}
	public void cancelShow() {
		if (isShowing()) {
			dismiss();
		}
	}
	public boolean IsShowing(){
		return isShowing();
	}
}

/**登录界面*/
public class LoginActivity extends BaseActivity implements OnClickListener,OnItemClickAndGetAccount{


private final String TAG = "LoginFrament";
EditText et_account, et_password;
private Button btn_login;
private TextView tv_forgetpassword, tv_account;
private boolean IsMiWen = true;
// private SharedPreferences accountsharedPreferences;
private TextView tv_register;
private ImageButton ibtn_showpw;
private ImageView ibtn_del;
// private ImageView iv_acountalter;
private ImageView iv_head;
private LoginResponeBiz loginSuccessResponeBiz;
private MenbanProgressDialog menbanProgressDialog;
private DisplayImageOptions Options;
private View view_xiala;
private View view_line;
private PopuAccountListView accountPopuListView;


public void initview() {
setContentView(R.layout.activity_login);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Options = OptionsFactory.getDisplayImageOptions(R.drawable.icon_defaut, R.drawable.icon_defaut, 360);
iv_head = (ImageView) findViewById(R.id.iv_head);
tv_register = (TextView) findViewById(R.id.tv_register);
et_account = (EditText) findViewById(R.id.et_account);
et_password = (EditText) findViewById(R.id.et_passwords);
ibtn_del = (ImageView) findViewById(R.id.ibtn_del);
btn_login = (Button) findViewById(R.id.btn_login);
tv_forgetpassword = (TextView) findViewById(R.id.tv_forgetpassword);
tv_account = (TextView) findViewById(R.id.tv_account);
ibtn_showpw = (ImageButton) findViewById(R.id.ibtn_showpw);
view_xiala = (View) findViewById(R.id.view_xiala);
view_line = (View) findViewById(R.id.view_line);
menbanProgressDialog = new MenbanProgressDialog(this);
loginSuccessResponeBiz = new LoginResponeBiz(this);
}


public void initdata() {
int Version = XmlPublicDB.getInstance(this).getKeyIntValue(XmlPublicDB.SharedPreferencesKey.LASTVERSION, 0);
int localversion = CommonUtils.getVersionCode();
if (localversion > Version) {
XmlPublicDB.getInstance(this).saveKeyIntValue(XmlPublicDB.SharedPreferencesKey.LASTVERSION, localversion);
}
ArrayList<AccountAndChild> accountAndChilds = DatacacheCenter.getInstance().publicDBUtil.getAccountList();
String useraccount = XmlPublicDB.getInstance(this).getKeyStringValue(XmlPublicDB.SharedPreferencesKey.USERACCOUNT, "");
if(!TextUtil.isTextEmpty(useraccount)){
if (accountAndChilds.size() > 0) {
AccountAndChild accountAndChild= getAccountAndChild(accountAndChilds, useraccount);
ImageLoader.getInstance().displayImage(accountAndChild.facePath, iv_head, Options);
et_account.setText(useraccount);
et_password.setText(accountAndChild.password);
accountPopuListView = new PopuAccountListView(this, accountAndChilds);
accountPopuListView.SetOnItemClickAndGetAccount(this);
view_xiala.setVisibility(View.VISIBLE);
}
}
}
    private AccountAndChild getAccountAndChild(ArrayList<AccountAndChild> accountAndChilds,String useraccount){
    AccountAndChild accountAndChild=null;
    int size=accountAndChilds.size();
    for (int i = 0; i < size; i++) {
if(accountAndChilds.get(i).useraccount.equals(useraccount)){
accountAndChild=accountAndChilds.get(i);
break;
}
}
    return accountAndChild;
    }
public void bindEvent() {
view_xiala.setOnClickListener(this);
ibtn_del.setOnClickListener(this);
tv_register.setOnClickListener(this);
btn_login.setOnClickListener(this);
tv_forgetpassword.setOnClickListener(this);
et_password.setOnEditorActionListener(EditorActionListener);
et_account.setOnFocusChangeListener(focusListener);
et_password.setOnFocusChangeListener(focusListener);
}


@Override
protected void onDestroy() {
super.onDestroy();
}


private void LoginAccount() {
if (IsRightAccount() && IsRightPassword()) {
String useraccount = et_account.getText().toString().trim();
String password = et_password.getText().toString();
loginSuccessResponeBiz.LoginAccountRequest(useraccount, password, -2, menbanProgressDialog, true);
}
}


private OnEditorActionListener EditorActionListener = new OnEditorActionListener() {


@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (null != event && event.getAction() == KeyEvent.ACTION_DOWN) {
LoginAccount();
return true;
}
return false;
}
};
private OnFocusChangeListener focusListener = new OnFocusChangeListener() {


@Override
public void onFocusChange(View v, boolean hasFocus) {
switch (v.getId()) {
case R.id.et_account: // 帐号EditText
if (!hasFocus) {
IsRightAccount();
ibtn_del.setVisibility(View.INVISIBLE);
} else {
// 隐藏提示(不正确)
ibtn_del.setVisibility(View.VISIBLE);


}
break;
case R.id.et_passwords: // 密码EditText
LogUtil.d(TAG, "输入密码获得了焦点");
if (!hasFocus) {
IsRightPassword();
} else {
// 隐藏提示(不正确)
}
break;
}


}
};


public boolean IsRightAccount() {
if (TextUtil.isTextEmpty(et_account.getText().toString())) {
ToastUtil.showToastOnUIThread(LoginActivity.this, "请输入账号");
return false;
}
if (!CommonUtils.isAccount(et_account.getText().toString().trim())) {
ToastUtil.showToastOnUIThread(LoginActivity.this, "账号为手机号/邮箱");
return false;
}
return true;
}


public boolean IsRightPassword() {
if (TextUtil.isTextEmpty(et_password.getText().toString())) {
ToastUtil.showToastOnUIThread(LoginActivity.this, "请输入密码");
return false;
}
if (!CommonUtils.isPassword(et_password.getText().toString())) {
ToastUtil.showToastOnUIThread(LoginActivity.this, "密码错误");
return false;
}
return true;
}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
MyApplication.getInstance().CancelAllRequest();
}


return super.onKeyDown(keyCode, event);
}


@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.ibtn_del:
et_account.setText("");
break;
case R.id.view_xiala:
if (accountPopuListView != null) {
if (accountPopuListView.IsShowing()) {
accountPopuListView.dismiss();
} else {
accountPopuListView.showPopupWindow(view_line);
}
}
break;
case R.id.ibtn_showpw:
break;
case R.id.tv_register:
Intent intent1 = new Intent();
intent1.setClass(LoginActivity.this, RegisterActivity.class);
startActivity(intent1);
break;
case R.id.btn_login:
LoginAccount();
break;
case R.id.tv_forgetpassword:
Intent intent2 = new Intent();
intent2.setClass(LoginActivity.this, ForgetPasswordActivity.class);
startActivity(intent2);
break;
}


}


@Override
public void getAccountInfo(AccountAndChild accountAndChild) {
et_account.setText(accountAndChild.useraccount);
et_password.setText(accountAndChild.password);
ImageLoader.getInstance().displayImage(accountAndChild.facePath, iv_head, Options);
}


// ibtn_showpw.setOnClickListener(new OnClickListener() {
//
// @Override
// public void onClick(View v) {
// if (IsMiWen) {
// IsMiWen = false;
// ibtn_showpw.setBackgroundResource(R.drawable.btn_showpw_0002);
// et_password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
// et_password.setSelection(et_password.getText().length());
// } else {
// IsMiWen = true;
// ibtn_showpw.setBackgroundResource(R.drawable.btn_showpw_0001);
// et_password.setInputType(InputType.TYPE_CLASS_TEXT |
// InputType.TYPE_TEXT_VARIATION_PASSWORD);
// et_password.setSelection(et_password.getText().length());
// }
// }
// });
}


效果图


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值