QQ login for file storage and qq login for file storage
Package com. jia. qqlogin; import java. util. map; import com. jia. qqlogin. utils. utils; import android. app. activity; import android. OS. bundle; import android. text. textUtils; import android. util. log; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. checkBox; import android. widget. editText; import android. widget. toast; public class MainActivity ext Ends Activity implements OnClickListener {private static final String TAG = "jia"; private EditText etNumber; private EditText etPassword; private CheckBox cbRemerberPWD; @ Overrideprotected void onCreate (Bundle savedInstanceState. onCreate (savedInstanceState); setContentView (R. layout. activity_main); etNumber = (EditText) findViewById (R. id. et_number); etPassword = (EditText) findViewById (R. id. et_pa Ssword); cbRemerberPWD = (CheckBox) findViewById (R. id. cb_remerber_pwd); Button btnLogin = (Button) findViewById (R. id. btn_login); btnLogin. setOnClickListener (this); // Echo Data Map <String, String> userInfoMap = Utils. getUserInfo (); if (userInfoMap! = Null) {etNumber. setText (userInfoMap. get ("number"); etPassword. setText (userInfoMap. get ("password") ;}@overridepublic void onClick (View v) {// perform the logon operation // 1. retrieve the number and password String number = etNumber. getText (). toString (); String password = etPassword. getText (). toString (); if (TextUtils. isEmpty (number) | TextUtils. isEmpty (password) {// The Toast is displayed. makeText (this, "Enter it correctly", Toast. LENGTH_SHORT ). show (); return;} // 2. determine whether the password is selected. if it is selected, save it as if (cbRemerberPWD. isChecked () {// you need to remember the password Log. I (TAG, "Remember password:" + number + "," + password); boolean isSuccess = Utils. saveUserInfo (number, password); if (isSuccess) {Toast. makeText (this, "saved successfully", 0 ). show ();} else {Toast. makeText (this, "failed to save", 0 ). show () ;}// 3. toast is successfully logged on. makeText (this, "Logon successful", 0 ). show ();}}
Package com. jia. qqlogin. utils; import java. io. bufferedReader; import java. io. fileInputStream; import java. io. fileOutputStream; import java. io. inputStreamReader; import java. util. hashMap; import java. util. map; import android. text. textUtils; public class Utils {/*** Save User Information ** @ param number * @ param password * @ return true success */public static boolean saveUserInfo (String number, String password) {String path = "/Data/com. jia. qqlogin/QQpassword.txt "; try {FileOutputStream fos = new FileOutputStream (path); // Account # password String data = number +" ## "+ password; fos. write (data. getBytes (); fos. flush (); fos. close (); return true;} catch (Exception e) {// TODO Auto-generated catch blocke. printStackTrace ();} return false;}/*****/public static Map <String, String> getUserInfo () {String path = "/data/com. jia. qqlog In/QQpassword.txt "; // java basic try {FileInputStream FCM = new FileInputStream (path); // The Stream object BufferedReader reader = new BufferedReader (new InputStreamReader (FS )); // Account # password String text = reader. readLine (); if (! TextUtils. isEmpty (text) {String [] split = text. split ("#"); Map <String, String> userInfoMap = new HashMap <String, String> (); userInfoMap. put ("number", split [0]); userInfoMap. put ("password", split [1]); return userInfoMap;} catch (Exception e) {// TODO Auto-generated catch blocke. printStackTrace ();} return null ;}}
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: orientation = "vertical"> <EditText android: id = "@ + id/et_number" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: hint = "Enter QQ number"/> <EditText android: id = "@ + id/et_password" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: hint = "enter the password" android: inputType = "textPassword"/> <CheckBox android: id = "@ + id/cb_remerber_pwd" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: checked = "true" android: hint = "Remember password"/> <Button android: id = "@ + id/btn_login" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: text = "login"/> </LinearLayout>