android 多用戶切換賬號(hào)

當(dāng)前項(xiàng)目中有一個(gè)需求查排,就是需要在當(dāng)前app中不退出直接切換賬號(hào)闹伪,一般這種需求大多都是測(cè)試或者手機(jī)用戶比較多的吁讨,所以在現(xiàn)有項(xiàng)目中添加一個(gè)不算過(guò)分的需求,實(shí)現(xiàn)起來(lái)也很簡(jiǎn)單旱易,就是在登錄成功之后用數(shù)據(jù)庫(kù)實(shí)現(xiàn)保存用戶名和密碼禁偎,然后適配器切換賬號(hào)的時(shí)候調(diào)用數(shù)據(jù)庫(kù)保存的信息,直接把相關(guān)的用戶名和密碼填入輸入框阀坏,實(shí)現(xiàn)登錄如暖。

具體實(shí)現(xiàn)方法如下:

mOptionsDBHelper.open();

if (!mOptionsDBHelper.isOneExist(mEditText1.getText().toString())) { mUserNames.add(mEditText1.getText().toString());

mOptionsAdapter.notifyDataSetChanged();

}mOptionsDBHelper.close();

storeAccount();


用到了適配器和數(shù)據(jù)庫(kù):

/** * @ClassName OptionsAdapter *

@Description TODO 可選擇下拉列表適配器 *

@Version 1.0 * @Author jairkong *

@Creation 2013-8-1 下午4:00:11 *

@Mender jairkong *

@Modification 2013-8-1 下午4:00:11 **/

public class OptionsAdapter extends BaseAdapter {

? private List list = new ArrayList();

? ? private Context mContext;

? ? public OptionsAdapter(Context context, List list){

? ? ? this.mContext = context;

? ? ? this.list = list;

}

? @Override

? public int getCount() {

? ? ? return list.size();

}

? @Override

? public Object getItem(int position) {

? ? ? return list.get(position);

}

? @Override

? public long getItemId(int position) {

? ? ? return position;

}

? @Override

? public View getView(final int position, View convertView, ViewGroup parent) {

? ? ? ViewHolder holder= null;

? ? ? ? if (convertView == null) {

? ? ? ? ? ? holder= new ViewHolder();

? ? ? ? ? ? //下拉項(xiàng)布局

? ? ? ? ? ? convertView = LayoutInflater.from(mContext).inflate(R.layout.option_item, null);

? ? ? ? ? ? holder.relativeLayout=(RelativeLayout)convertView.findViewById(R.id.option_item_layout);

? ? ? ? ? ? holder.textView = (TextView) convertView.findViewById(R.id.option_item_text);

? ? ? ? ? ? holder.delBtn = (ImageView) convertView.findViewById(R.id.option_item_del);

? ? ? ? ? ? convertView.setTag(holder);

? ? ? ? } else {

? ? ? ? ? ? holder= (ViewHolder) convertView.getTag();

}

? ? ? ? holder.textView.setText(list.get(position));

? ? ? ? //為下拉框選項(xiàng)文字部分設(shè)置事件,最終效果是點(diǎn)擊將其文字填充到文本框

? ? ? ? holder.relativeLayout.setOnClickListener(new View.OnClickListener() {

? ? ? ? @Override

? ? ? ? public void onClick(View v) {

? ? ? ? ? ? mOnClicked.onItemSelected(position);

}

? ? ? });

? ? ? ? //為下拉框選項(xiàng)刪除圖標(biāo)部分設(shè)置事件忌堂,最終效果是點(diǎn)擊將該選項(xiàng)刪除

? ? ? ? holder.delBtn.setOnClickListener(new View.OnClickListener() {

? ? ? ? @Override

? ? ? ? public void onClick(View v) {

? ? ? ? ? ? mOnClicked.onItemDelete(position);

}

? ? ? });

? ? ? ? return convertView;

}

? public OnClicked mOnClicked;

? public void setOnClicked(OnClicked onClicked)

? {

? ? ? mOnClicked=onClicked;

}

? public interface OnClicked

? {

? ? ? void onItemDelete(int index);

? ? ? void onItemSelected(int index);

}

}

class ViewHolder {

? RelativeLayout relativeLayout;

? ? TextView textView;

? ? ImageView delBtn;

}




/**

* @ClassNameOptionsDBHelper

* @DescriptionTODO 數(shù)據(jù)庫(kù)操作輔助類

* @Version1.0

* @Authorjairkong

* @Creation2013-8-2 上午10:41:50

* @Menderjairkong

* @Modification2013-8-2 上午10:41:50

**/

public class OptionsDBHelper {

? private static final boolean D=true;

? private static final String TAG="---OptionsDBHelper---";//LogCat

? ? private static final String DB_NAME="options.db";//數(shù)據(jù)庫(kù)名

? ? private static final String DB_TABLE="accounts";//數(shù)據(jù)庫(kù)表名

? ? private static final int? ? DB_VERSION=1;//數(shù)據(jù)庫(kù)版本號(hào)

? ? private Context mContext;

? ? private DBHelper dbHelper;

? ? private SQLiteDatabase database;

? ? public OptionsDBHelper(Context context) {

? ? ? // TODO Auto-generated constructor stub

? ? ? this.mContext=context;

}

? ? public boolean isOpen()

? ? {

? ? ? if (database.isOpen())

? ? ? {

? ? ? ? return true;

? ? ? } else {

? ? ? ? return false;

}

}

? ? /**

? ? * @功能 打開(kāi)數(shù)據(jù)庫(kù)

? ? * 空間不夠存儲(chǔ)的時(shí)候設(shè)為只讀

? ? * @throwsSQLiteException

? ? **/

? ? public boolean open() throws SQLiteException{

? ? ? dbHelper = new DBHelper(mContext, DB_NAME, null,DB_VERSION);

? ? ? ? try

? ? ? ? {

? ? ? ? ? database = dbHelper.getWritableDatabase();

? ? ? ? ? return true;

}

? ? ? ? catch (SQLiteException e)

? ? ? ? {

? ? ? ? ? database = dbHelper.getReadableDatabase();

? ? ? ? ? return false;

}

}

? ? /**

? ? * @功能 關(guān)閉數(shù)據(jù)庫(kù)

? ? *

**/

? ? public void close() {

? ? ? if (database!=null) {

? ? ? ? database.close();

? ? ? ? database=null;

}

? ? ? Log.e(TAG, "close()");

}

? ? /**

? ? * @功能? 更新選中賬號(hào)記錄

? ? * @return

**/

? ? public void updateState(String name) {

? ? ? if (name!=null)

? ? ? {

? ? ? ? ? database.execSQL("UPDATE "+DB_TABLE+" SET "+DBHelper.KEY_LAST_ACC+

? ? ? ? ? ? ? " = 1 WHERE "+DBHelper.KEY_USERNAME+" = "+"\""+name+"\";");

? ? ? ? ? database.execSQL("UPDATE "+DB_TABLE+" SET "+DBHelper.KEY_LAST_ACC+

? ? ? ? ? ? ? ? " = 0 WHERE "+DBHelper.KEY_USERNAME+" <> "+"\""+name+"\";");//將其它的置為0

? ? ? }

? ? ? else

? ? ? {

? ? ? ? ? database.execSQL("UPDATE "+DB_TABLE+" SET "+DBHelper.KEY_LAST_ACC+

? ? ? ? ? ? ? ? " = 0 ;");//將其它的置為0

? ? ? }

}

? ? /**

? ? * @功能 向表中添加一條數(shù)據(jù)

? ? * @return

**/

? ? public long insert( UserAccount userAccount) {

? ? ? ContentValues contentValues=new ContentValues();

? ? ? contentValues.put(DBHelper.KEY_USERNAME, userAccount.getUserName());

? ? ? contentValues.put(DBHelper.KEY_PASSWORD, userAccount.getPassWord());

? ? ? contentValues.put(DBHelper.KEY_REMB_PWD, (userAccount.getRembPwd())?1:0);

? ? ? contentValues.put(DBHelper.KEY_AUTO_LOG, (userAccount.getAutoLog())?1:0);

? ? ? contentValues.put(DBHelper.KEY_LAST_ACC, (userAccount.getLastAcc())?1:0);

? ? ? return database.insert(DB_TABLE, null, contentValues);

}

? ? /**

? ? * @功能 向表中刪除一條數(shù)據(jù)

? ? * @return

**/

? ? public long deleteOne(String name) {

? ? ? return database.delete(DB_TABLE, DBHelper.KEY_USERNAME+"="+"\""+name+"\"", null);

}

? ? /**

? ? * @功能 刪除數(shù)據(jù)表

? ? * @return

**/

? ? public long deleteAllData() {

? ? ? return database.delete(DB_TABLE,null,null);

}

? ? /**

? ? * @功能? 獲得上一次登錄的賬號(hào)

? ? * @param

* @return

**/

? ? public UserAccount queryLastAcc() {

? ? ? UserAccount userAccount=null;

? ? ? Cursor result=database.query(DB_TABLE, null, DBHelper.KEY_LAST_ACC+"="+"\""+String.valueOf(1)+"\"", null, null, null, null);

? ? ? Log.e(TAG, "queryOneData()---result:"+result.getColumnCount());

? ? ? if (result.getCount()>0)

? ? ? {

? ? ? ? ? userAccount=ConvertAll(result)[0];

}

? ? ? result.close();

? ? ? return userAccount;

}

? ? /**

? ? * @功能? 根據(jù)包名查詢一條數(shù)據(jù)

? ? * @param

* @return

**/

? ? public UserAccount queryOne(String name) {

? ? ? UserAccount userAccount;

? ? ? Cursor result=database.query(DB_TABLE, null, DBHelper.KEY_USERNAME+"="+"\""+name+"\"", null, null, null, null);

? ? ? Log.e(TAG, "queryOneData()---result:"+result.getColumnCount());

? ? ? userAccount=ConvertAll(result)[0];

? ? ? result.close();

? ? ? return userAccount;

}

? ? /**

? ? * @功能? 查詢?nèi)繑?shù)據(jù)記錄數(shù)量

? ? * @return

**/

? ? public int queryDataCount(){

? ? ? int count=0;

? ? ? ? Cursor result= database.query(DB_TABLE, null, null, null, null, null, null);

? ? ? ? count=result.getCount();

? ? ? result.close();

? ? ? return count;

}

? ? /**

? ? * @功能? 查詢?nèi)繑?shù)據(jù)

? ? * @return

**/

? ? public UserAccount[] queryAllData(){

? ? ? UserAccount[] userAccounts;

? ? ? ? Cursor result= database.query(DB_TABLE, null, null, null, null, null, null);

? ? ? ? userAccounts=ConvertAll(result);

? ? ? result.close();

? ? ? return userAccounts;

}

? ? /**

? ? * @功能? 根據(jù)包名更新一條數(shù)據(jù)

? ? * @param

* @returnlong

**/

? ? public long updateOne(String name,UserAccount userAccount){

? ? ? ContentValues contentValues=new ContentValues();

? ? ? contentValues.put(DBHelper.KEY_USERNAME, userAccount.getUserName());

? ? ? contentValues.put(DBHelper.KEY_PASSWORD, userAccount.getPassWord());

? ? ? contentValues.put(DBHelper.KEY_REMB_PWD, (userAccount.getRembPwd())?1:0);

? ? ? contentValues.put(DBHelper.KEY_AUTO_LOG, (userAccount.getAutoLog())?1:0);

? ? ? contentValues.put(DBHelper.KEY_LAST_ACC, (userAccount.getLastAcc())?1:0);

? ? ? ? return database.update(DB_TABLE, contentValues, DBHelper.KEY_USERNAME+"="+"\""+name+"\"",null);

}

? ? /**

? ? * @功能? 根據(jù)包名查詢一條數(shù)據(jù)是否存在

? ? * @param

* @return

**/

? ? public boolean isOneExist(String name) {

? ? ? Cursor result=database.query(DB_TABLE, null, DBHelper.KEY_USERNAME+"="+"\""+name+"\"", null, null, null, null);

? ? ? ? if(result.getCount() == 0 || !result.moveToFirst())

? ? ? ? {

? ? ? ? ? result.close();

? ? ? ? ? return false ;

? ? ? ? }else {

? ? ? ? ? result.close();

? ? ? ? return true;

}

}

? ? private UserAccount[] ConvertAll(Cursor cursor){

? ? ? ? int resultCounts= cursor.getCount();

? ? ? ? if (D)Log.e(TAG, "ConvertToAppInfo()---resultCounts:"+resultCounts);

? ? ? ? if(resultCounts== 0 || !cursor.moveToFirst())

? ? ? ? {

? ? ? ? ? ? return null ;

}

? ? ? ? UserAccount[] userAccounts= new UserAccount[resultCounts];

? ? ? ? Log.i(TAG, "AppInfo length:"+userAccounts.length);

? ? ? ? for (int i= 0; i< resultCounts; i++)

? ? ? ? {

? ? ? ? ? userAccounts[i] = new UserAccount();

? ? ? ? ? userAccounts[i].setUserName(cursor.getString(cursor.getColumnIndex(DBHelper.KEY_USERNAME)));

? ? ? ? ? userAccounts[i].setPassWord(cursor.getString(cursor.getColumnIndex(DBHelper.KEY_PASSWORD)));

? ? ? ? ? userAccounts[i].setRembPwd(((byte)(cursor.getInt(cursor.getColumnIndex(DBHelper.KEY_REMB_PWD)))==1)?true:false);

? ? ? ? ? userAccounts[i].setAutoLog(((byte)(cursor.getInt(cursor.getColumnIndex(DBHelper.KEY_AUTO_LOG)))==1)?true:false);

? ? ? ? ? userAccounts[i].setLastAcc(((byte)(cursor.getInt(cursor.getColumnIndex(DBHelper.KEY_LAST_ACC)))==1)?true:false);

? ? ? ? ? ? cursor.moveToNext();

}

? ? ? ? cursor.close();

? ? ? ? return userAccounts;

}

? ? public class UserAccount {

? ? ? ? private String mUserName="", mPassWord="";

? ? ? ? private boolean mLastAcc=false, mRembPwd=true, mAutoLog=false;

? ? ? ? /**

? ? ? * @NameOptionsDBHelper.UserAccounts

? ? ? * @DescriptionTODO

? ? ? * @Date2013-8-2 下午1:01:42

**/

? ? ? public UserAccount()

? ? ? ? {

? ? ? ? // TODO Auto-generated constructor stub

? ? ? }

? ? ? ? public UserAccount(String username, String password, boolean lastacc, boolean rempwd, boolean autolog)

? ? ? ? {

? ? ? ? this.mUserName=username;

? ? ? ? this.mPassWord=password;

? ? ? ? this.mRembPwd=rempwd;

? ? ? ? this.mAutoLog=autolog;

? ? ? ? this.mLastAcc=lastacc;

}

? ? ? ? public void setUserName(String un)

? ? ? ? {

? ? ? ? ? this.mUserName=un;

}

? ? ? ? public String getUserName()

? ? ? ? {

? ? ? ? ? return this.mUserName;

}

? ? ? ? public void setPassWord(String pwd)

? ? ? ? {

? ? ? ? ? this.mPassWord=pwd;

}

? ? ? ? public String getPassWord()

? ? ? ? {

? ? ? ? ? return this.mPassWord;

}

? ? ? ? public void setRembPwd(boolean rem)

? ? ? ? {

? ? ? ? ? this.mRembPwd=rem;

}

? ? ? ? public boolean getRembPwd()

? ? ? ? {

? ? ? ? ? return this.mRembPwd;

}

? ? ? ? public void setAutoLog(boolean auto)

? ? ? ? {

? ? ? ? ? this.mAutoLog=auto;

}

? ? ? ? public boolean getAutoLog()

? ? ? ? {

? ? ? ? ? return this.mAutoLog;

}

? ? ? ? public void setLastAcc(boolean la)

? ? ? ? {

? ? ? ? ? this.mLastAcc=la;

}

? ? ? ? public boolean getLastAcc()

? ? ? ? {

? ? ? ? ? return this.mLastAcc;

}

? ? ? ? @Override

? ? ? ? public String toString(){

? ? ? ? ? ? String str=

? ? ? ? ? ? "賬號(hào):"+this.mUserName+","

? ? ? ? ? ? +"密碼:"+this.mPassWord+","

? ? ? ? ? ? +"記住密碼:"+this.mRembPwd+","

? ? ? ? ? ? +"自動(dòng)登錄:"+this.mAutoLog+","

? ? ? ? ? ? +"是否為上次賬號(hào):"+this.mLastAcc;

? ? ? ? ? ? return str;

}

}

? ? public class DBHelper extends SQLiteOpenHelper {

? ? ? public static final boolean D=true;

? ? ? public static final String TAG="---DBHelper---";//LogCat

? ? ? ? private static final String DB_TABLE="accounts";//數(shù)據(jù)庫(kù)表名

? ? ? ? private static final int? ? DB_VERSION=1;//數(shù)據(jù)庫(kù)版本號(hào)

? ? ? ? private static final String KEY_USERNAME? ? ? ? = "UserName";

? ? ? ? private static final String KEY_PASSWORD? ? ? ? = "PassWord";

? ? ? ? private static final String KEY_REMB_PWD? ? ? ? = "RembPwd";

? ? ? ? private static final String KEY_AUTO_LOG? ? ? ? = "AutoLog";

? ? ? ? private static final String KEY_LAST_ACC? ? ? ? = "LastAcc";

? ? ? ? private static final String CREATE_TABLE_SQL=

? ? ? ? ? ? ? ? "CREATE TABLE "+DB_TABLE

? ? ? ? ? ? ? ? +" ("+KEY_USERNAME+" VARCHAR(32) NOT NULL PRIMARY KEY, "

? ? ? ? ? ? ? ? +KEY_PASSWORD+" VARCHAR(32) NOT NULL, "

? ? ? ? ? ? ? ? +KEY_REMB_PWD+" BIT(1) DEFAULT 1, "

? ? ? ? ? ? ? ? +KEY_AUTO_LOG+" BIT(1) DEFAULT 0, "

? ? ? ? ? ? ? ? +KEY_LAST_ACC+" BIT(1) DEFAULT 0);";

? ? ? ? public DBHelper(Context context, String name,CursorFactory factory, int version)

? ? ? ? {

? ? ? ? ? super(context, name, factory, version);

}

? ? ? @Override

? ? ? public void onCreate(SQLiteDatabase db){

? ? ? ? ? // 第一個(gè)使用數(shù)據(jù)庫(kù)時(shí)自動(dòng)建表

? ? ? ? ? ? db.execSQL(CREATE_TABLE_SQL);

}

? ? ? /**

*

? ? ? ? * 函數(shù)在數(shù)據(jù)庫(kù)需要升級(jí)時(shí)被調(diào)用盒至, 一般用來(lái)刪除舊的數(shù)據(jù)庫(kù)表,并將數(shù)據(jù)轉(zhuǎn)移到新版本的數(shù)據(jù)庫(kù)表中

? ? ? ? *

**/

? ? ? @Override

? ? ? public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){

? ? ? ? db.execSQL("DROP TABLE IF EXISTS "+CREATE_TABLE_SQL);

? ? ? ? ? ? onCreate(db);

? ? ? ? ? ? if (D)Log.i(TAG, "Upgrade");

}

}

}


在登錄的Activity里面條用的方法如下:

/**

? ? * @returnvoid

? ? * @NameinitData

? ? * @DescriptionTODO? 初始化數(shù)據(jù)

? ? * @Authorfzq

? ? * @Date2018-5-2 下午8:18:43

**/

? ? public void initData() {

? ? ? ? mCount = restoreAccounts();

? ? ? ? OptionsDBHelper.UserAccount userAccount= restoreLastAccount();

? ? ? ? if (mCount > 0 && userAccount!= null) {

? ? ? ? ? ? mEditText1.setText(userAccount.getUserName());

? ? ? ? ? ? mEditText2.setText(userAccount.getPassWord());

}

? ? ? ? //PopupWindow浮動(dòng)下拉框布局

? ? ? ? layout_option = (View) this.getLayoutInflater().inflate(R.layout.layout_options, null);

? ? ? ? ListView listView= (ListView) layout_option.findViewById(R.id.layout_options_list);

? ? ? ? //設(shè)置自定義Adapter

? ? ? ? mOptionsAdapter = new OptionsAdapter(LoginActivity.this, mUserNames);

? ? ? ? mOptionsAdapter.setOnClicked(onItemClicked);

? ? ? ? listView.setAdapter(mOptionsAdapter);

}

? ? /**

? ? * @returnvoid

? ? * @NamestoreAccount

? ? * @DescriptionTODO? 保存用戶登陸信息

? ? * @Authorfzq

? ? * @Date2018-5-2 下午3:28:06

**/

? ? public void storeAccount() {

? ? ? ? OptionsDBHelper.UserAccount userAccount= mOptionsDBHelper.new UserAccount();

? ? ? ? userAccount.setUserName(mEditText1.getText().toString());

? ? ? ? userAccount.setPassWord(mEditText2.getText().toString());

? ? ? ? userAccount.setLastAcc(true);

? ? ? ? mOptionsDBHelper.open();

? ? ? ? mOptionsDBHelper.updateState(mEditText1.getText().toString());

? ? ? ? if (mOptionsDBHelper.isOneExist(mEditText1.getText().toString())) {

? ? ? ? ? ? mOptionsDBHelper.updateOne(userAccount.getUserName(), userAccount);

? ? ? ? } else {

? ? ? ? ? ? mOptionsDBHelper.insert(userAccount);

}

? ? ? ? mOptionsDBHelper.close();

}

? ? /**

? ? * @returnvoid

? ? * @NamestoreUserInfo

? ? * @DescriptionTODO? 移除指定用戶信息

? ? * @Authorfzq

? ? * @Date2018-5-2 下午3:28:06

**/

? ? public void removeAccount(String username) {

? ? ? ? mOptionsDBHelper.open();

? ? ? ? mOptionsDBHelper.deleteOne(username);

? ? ? ? mOptionsDBHelper.close();

}

? ? /**

? ? * @returnvoid

? ? * @NamerestoreAccounts

? ? * @DescriptionTODO? 還原登錄賬號(hào)信息

? ? * @Authorfzq

? ? * @Date2018-5-2 上午10:59:02

**/

? ? public int restoreAccounts() {

? ? ? ? mOptionsDBHelper.open();

? ? ? ? int count= mOptionsDBHelper.queryDataCount();

? ? ? ? Log.d("restoreAccounts", "count:" + count);

? ? ? ? if (count> 0) {

? ? ? ? ? ? OptionsDBHelper.UserAccount[] userAccounts= new OptionsDBHelper.UserAccount[count];

? ? ? ? ? ? userAccounts= mOptionsDBHelper.queryAllData();

? ? ? ? ? ? mUserNames.clear();

? ? ? ? ? ? for (OptionsDBHelper.UserAccount userAccount: userAccounts) {

? ? ? ? ? ? ? ? mUserNames.add(userAccount.getUserName());

}

? ? ? ? ? ? mOptionsDBHelper.close();

? ? ? ? } else {

}

? ? ? ? return count;

}

? ? /**

? ? * @returnvoid

? ? * @NamestoreSelectedAccount

? ? * @DescriptionTODO 保存當(dāng)前用戶賬號(hào)

? ? * @Authorfzq

? ? * @Date2018-5-2 下午8:00:59

**/

? ? public void storeSelectedAccount(String name) {

? ? ? ? mOptionsDBHelper.open();

? ? ? ? mOptionsDBHelper.updateState(name);

? ? ? ? mOptionsDBHelper.close();

}

? ? /**

? ? * @paramname

? ? * @returnvoid

? ? * @NameupdateState

? ? * @DescriptionTODO 更新選中賬號(hào)狀態(tài)

? ? * @Authorfzq

? ? * @Date2018-5-2 下午5:17:06

**/

? ? public void updateState(String name) {

? ? ? ? OptionsDBHelper.UserAccount userAccount= mOptionsDBHelper.new UserAccount();

? ? ? ? mOptionsDBHelper.open();

? ? ? ? userAccount= mOptionsDBHelper.queryOne(name);

? ? ? ? mOptionsDBHelper.close();

? ? ? ? mEditText1.setText(userAccount.getUserName());

? ? ? ? mEditText2.setText(userAccount.getPassWord());

}

? ? /**

? ? * @returnvoid

? ? * @NamerestoreLastAccount

? ? * @DescriptionTODO? 恢復(fù)上次記住用戶賬號(hào)信息

? ? * @Authorfzq

? ? * @Date2018-5-2 下午8:11:26

**/

? ? public OptionsDBHelper.UserAccount restoreLastAccount() {

? ? ? ? OptionsDBHelper.UserAccount userAccount= mOptionsDBHelper.new UserAccount();

? ? ? ? mOptionsDBHelper.open();

? ? ? ? userAccount= mOptionsDBHelper.queryLastAcc();

? ? ? ? mOptionsDBHelper.close();

? ? ? ? return userAccount;

}

? ? /**

? ? * @returnboolean

? ? * @NamejudgeLoginInfo

? ? * @DescriptionTODO 檢查登錄信息是否符合要求

? ? * @Data2018-5-2

**/

? ? protected boolean judgeLoginInfo() {

? ? ? ? // TODO Auto-generated method stub

? ? ? ? Animation shakeAnimY, shakeAnimX;

? ? ? ? boolean isUserOK= false, isPwdOK= false;

? ? ? ? shakeAnimX= AnimationUtils.loadAnimation(LoginActivity.this, R.anim.shake_x);

? ? ? ? shakeAnimY= AnimationUtils.loadAnimation(LoginActivity.this, R.anim.shake_y);

? ? ? ? if (mEditText1.getText().toString().length() == 0 || mEditText2.getText().toString().length() == 0) {

? ? ? ? ? ? Toast.makeText(LoginActivity.this, getResources().getString(R.string.login_input_blank), Toast.LENGTH_SHORT).show();

? ? ? ? ? ? mEditText1.startAnimation(shakeAnimY);

? ? ? ? ? ? mEditText2.startAnimation(shakeAnimY);

? ? ? ? ? ? isUserOK= false;

? ? ? ? ? ? isPwdOK= false;

? ? ? ? } else {

? ? ? ? ? ? if (mEditText1.getText().toString().length() > 32 || mEditText1.getText().toString().length() < 4) {//4字符?

? ? ? ? ? ? ? ? Toast.makeText(LoginActivity.this, getResources().getString(R.string.login_username_length), Toast.LENGTH_SHORT).show();

? ? ? ? ? ? ? ? mEditText1.startAnimation(shakeAnimY);

//? ? ? ? ? et_userName.setText("");

? ? ? ? ? ? ? ? isUserOK= false;

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? isUserOK= true;

}

? ? ? ? ? ? if (mEditText2.getText().toString().length() > 32 || mEditText2.getText().toString().length() < 6) {//6字符

? ? ? ? ? ? ? ? Toast.makeText(LoginActivity.this, getResources().getString(R.string.login_password_length), Toast.LENGTH_SHORT).show();

? ? ? ? ? ? ? ? mEditText2.startAnimation(shakeAnimY);

? ? ? ? ? ? ? ? mEditText2.setText("");

? ? ? ? ? ? ? ? isPwdOK= false;

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? isPwdOK= true;

}

}

? ? ? ? if (isPwdOK& isUserOK) {

? ? ? ? ? ? return true;

? ? ? ? } else {

? ? ? ? ? ? return false;

}

}

? ? /**

? ? * @returnvoid

? ? * @NameuploadOptionPop

? ? * @DescriptionTODO? 打開(kāi)賬號(hào)選擇Popupwindow

? ? * @Authorfzq

? ? * @Date2018-5-2 下午9:47:05

**/

? ? private void uploadOptionPop(boolean show_flag) {

? ? ? ? if (show_flag) {

? ? ? ? ? ? if (selectPopupWindow != null) {

? ? ? ? ? ? ? ? if (selectPopupWindow.isShowing()) {

? ? ? ? ? ? ? ? ? ? selectPopupWindow.dismiss();

}

? ? ? ? ? ? ? ? selectPopupWindow = null;

}

? ? ? ? ? ? selectPopupWindow = new PopupWindow(layout_option, linear.getWidth(), LinearLayout.LayoutParams.FILL_PARENT, true);

? ? ? ? ? ? selectPopupWindow.setBackgroundDrawable(new BitmapDrawable());// 設(shè)置允許在外點(diǎn)擊消失

? ? ? ? ? ? selectPopupWindow.showAsDropDown(linear, 0, 0);

? ? ? ? ? ? selectPopupWindow.setAnimationStyle(R.style.PopupAnimation);

? ? ? ? ? ? selectPopupWindow.setFocusable(true);

? ? ? ? ? ? selectPopupWindow.setOutsideTouchable(true);

? ? ? ? ? ? selectPopupWindow.update();

? ? ? ? } else {

? ? ? ? ? ? if (selectPopupWindow != null) {

? ? ? ? ? ? ? ? selectPopupWindow.dismiss();

? ? ? ? ? ? ? ? selectPopupWindow.setFocusable(false);

}

}

? ? }


在初始化的時(shí)候別忘了加上:

mOptionsDBHelper = new OptionsDBHelper(LoginActivity.this);

initData();


還有就是布局文件士修,很簡(jiǎn)單的枷遂,我就不一一貼出來(lái)了,有需要的話聯(lián)系我棋嘲!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末酒唉,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子沸移,更是在濱河造成了極大的恐慌痪伦,老刑警劉巖侄榴,帶你破解...
    沈念sama閱讀 216,544評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異网沾,居然都是意外死亡癞蚕,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門辉哥,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)桦山,“玉大人,你說(shuō)我怎么就攤上這事证薇《忍Γ” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 162,764評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵浑度,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我鸦概,道長(zhǎng),這世上最難降的妖魔是什么窗市? 我笑而不...
    開(kāi)封第一講書人閱讀 58,193評(píng)論 1 292
  • 正文 為了忘掉前任咨察,我火速辦了婚禮论熙,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘摄狱。我一直安慰自己,他們只是感情好祝谚,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著酣衷,像睡著了一般交惯。 火紅的嫁衣襯著肌膚如雪穿仪。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 51,182評(píng)論 1 299
  • 那天只锻,我揣著相機(jī)與錄音炬藤,去河邊找鬼。 笑死沈矿,一個(gè)胖子當(dāng)著我的面吹牛羹膳,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播就珠,決...
    沈念sama閱讀 40,063評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼醒颖,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼泞歉!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起榛丢,我...
    開(kāi)封第一講書人閱讀 38,917評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤挺庞,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后掖鱼,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體侵俗,經(jīng)...
    沈念sama閱讀 45,329評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡隘谣,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評(píng)論 2 332
  • 正文 我和宋清朗相戀三年寻歧,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片猾封。...
    茶點(diǎn)故事閱讀 39,722評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡噪珊,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出磷箕,到底是詐尸還是另有隱情岳枷,我是刑警寧澤,帶...
    沈念sama閱讀 35,425評(píng)論 5 343
  • 正文 年R本政府宣布殿衰,位于F島的核電站盛泡,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏蜀踏。R本人自食惡果不足惜掰吕,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評(píng)論 3 326
  • 文/蒙蒙 一殖熟、第九天 我趴在偏房一處隱蔽的房頂上張望斑响。 院中可真熱鬧舰罚,春花似錦、人聲如沸营罢。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,671評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)吃型。三九已至僚楞,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間赐写,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,825評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留悠夯,地道東北人沦补。 一個(gè)月前我還...
    沈念sama閱讀 47,729評(píng)論 2 368
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像虚倒,于是被迫代替她去往敵國(guó)和親产舞。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容