Package Com.anzi.jmsht.ui;import Java.util.arraylist;import Java.util.hashmap;import java.util.map;import Java.util.concurrent.executorservice;import Java.util.concurrent.executors;import Org.json.JSONObject;import Com.anzi.jmsht.appexception;import Com.anzi.jmsht.appmanager;import Com.anzi.jmsht.constant;import Com.anzi.jmsht.net.xml.api.net;import Com.anzi.jmsht.ui.r;import Com.anzi.jmsht.util.constants;import Com.anzi.jmsht.util.datacheckout;import Com.anzi.jmsht.util.preferenceshelper;import Com.anzi.jmsht.view.extdialog;import Com.anzi.jmsht.widget.appstartbgservice;import Android.os.Bundle;import Android.os.handler;import Android.os.message;import Android.text.textutils;import Android.util.Log;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.window;import Android.view.inputmethod.inputmethodmanager;import Android.widget.button;import Android.widget.EditText;import Android.widget.textview;import Android.widget.toast;import android.app.Activity;Import Android.app.progressdialog;import Android.content.context;import Android.content.intent;import Android.content.sharedpreferences;import android.content.sharedpreferences.editor;/** * Login * * @author HHH * */public cl Loginactivity extends Activity implements Onclicklistener {private Button regist, Login;private EditText Usern_et, Pw_ Etprivate TextView FORGETPW; private Executorservice fixedthreadpool;private arraylist<map<string, object>> list;//Store login Information Private ProgressDialog dialog;private preferenceshelper ph;private extdialog extdialog; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); GetWindow (). Requestfeature ( Window.feature_no_title); Setcontentview (r.layout.login_activity_layout);// Registers the default non-catching exception handling class Thread.setdefaultuncaughtexceptionhandler (Appexception.getappexceptionhandler ()); Appmanager.getappmanager (). addactivity (this);//Create a thread pool to control the maximum number of concurrent threads, and the excess threads will wait in the queue:Fixedthreadpool = Executors.newfixedthreadpool (1);ph = new Preferenceshelper (this, constants.anzidate);try {update (); Initview ();} catch (Exception e) {e.printstacktrace ();}} @Overrideprotected void OnDestroy () {//TODO auto-generated method Stubsuper.ondestroy (); if (fixedthreadpool! = null) {fi Xedthreadpool.shutdown ();}} @Overrideprotected void Onresume () {//TODO auto-generated method Stubsuper.onresume ();}private void Update (){String URL = ph.getvalue ("url"); String Note = Ph.getvalue ("note"); String size = Ph.getvalue ("size"); String type = Ph.getvalue ("type"); String Version = Ph.getvalue ("version");//Toast.maketext (Getapplicationcontext (), url+note+size+ "here __" +label,//0). Show (); if ("1". Equals (Type)) {Extdialog = new Extdialog (this, "File size:" + size, note, URL, type,version); extdialog.setcance Lable (false); Extdialog.show ();//Intent Intent = new Intent (this,updateservice.class);//Intent.putextra ("Key_app_ Name "," dry Tree ");//Intent.putextra (" Key_down_url ", URL);//This.startservice (intent);} else if ("0". Equals (Type)) {Extdialog = new Extdialog (this, "File size:" + size, note, URL, type,version); Extdialog.show ();}} }/* * Initialize control */private void Initview (){Sharedpreferences preference = getsharedpreferences ("person", context.mode_private); regist = (Button) Findviewbyid ( r.id.regist); Regist.setonclicklistener (this); login = (Button) Findviewbyid (R.id.login); Login.setonclicklistener ( this); Usern_et = (EditText) Findviewbyid (r.id.usern_et);//Usern_et.settext (preference.getstring ("PhoneNumber", "") );p W_et = (EditText) Findviewbyid (r.id.pw_et);//Pw_et.settext (preference.getstring ("Password", "")); FORGETPW = ( TextView) Findviewbyid (R.ID.FORGETPW); Forgetpw.setonclicklistener (this);} @Overridepublic voidOnClick (View v) {TODO auto-generated Method Stubswitch (V.getid ()) {Case r.id.regist://registered ((Inputmethodmanager) Getsystemservice ( Input_method_service). Hidesoftinputfromwindow (LoginActivity.this.getCurrentFocus (). Getwindowtoken (), Inputmethodmanager.hide_not_always); StartActivity (New Intent (Getapplicationcontext (), registactivity.class)); Break;case r.id.login://Login ((inputmethodmanager) Getsystemservice (Input_method_service)). HideSoftInputFromWindow ( LoginActivity.this.getCurrentFocus (). Getwindowtoken (), inputmethodmanager.hide_not_always); list = new ArrayList <map<string, object>> ();//StartActivity (New Intent (Getapplicationcontext (),//Hometabactivity.class)) ;//Appmanager.getappmanager (). finishactivity (); String PhoneNumber = Usern_et.gettext (). toString (); String password = Pw_et.gettext (). toString (); if (Textutils.isempty (PhoneNumber)) {Toast.maketext (this, "Please enter mobile number", Toast.length_short). Show ();} else if (textutils.isempty (password)) {Toast.maketext (this, "Please enter a password", Toast.length_short). Show (); else {//Login request loginreq (phonenumber, password);}break;case r.id.forgetpw://forgot Password//Input method disappears ((Inputmethodmanager) Getsystemservice (Input_method_service)). Hidesoftinputfromwindow (LoginActivity.this.getCurrentFocus (). Getwindowtoken (), inputmethodmanager.hide_not_ always); StartActivity (New Intent (Getapplicationcontext (), Resetpwdactivity.class)); break;default:break;}} /* * Processing login request */private voidLoginreq(Final string phonenumber, final string password) {//Get message from worker thread final Handler Handler = new Handler () {@Overridepublic void handlemessage (Message msg) {String s = (string) Msg.obj;if ("OK". Equals (s)) {//display content//Get status code string status = (String) list.get (0). Get ("status");//Get login information String message = (string) list.get (0). Get ("message"), if ("10000". Equals (status)) {////Login succeeded//save Check value Constant.sigen = (String) list.get (0). Get ("Sigen");//account name Constant.phone = Usern_et.gettext (). toString ();//user Idconstant.userid = (String) list.get (0). Get (" UserID ");//user Integral constant.integral = (string) list.get (0). Get (" integral ");//user picture Address constant.portrait = (string) List.get (0). Get ("Portrait");//save user name and password to sharedpreferencessharedpreferences preference = Getsharedpreferences (" Person ", context.mode_private); Editor edit = Preference.edit (); Edit.putstring ("PhoneNumber", PhoneNumber); edit.putstring ("Password", password); Edit.commit (); StartActivity (New Intent (Getapplicationcontext (), hometabactivity.class)); Appmanager.getappmaNager (). Finishactivity ();p h.setvalue ("Sigen", Constant.sigen);p h.setvalue (PhoneNumber, Constant.sigen); Ph.setvalue ("PhoneNumber", "" "+ PhoneNumber);p h.setvalue (" Password "," "+ password);p h.setvalue (" UID "," "" + Constant.userid);p h.setvalue ("Portrait", "" "+ constant.portrait);p h.setvalue (" Integral "," "+ constant.integral); Toast.maketext (Loginactivity.this, "Login Successful", 1). Show (); else if ("10001". Equals (status)) {//username or password error toast.maketext (loginactivity.this, message, 1). Show ();} else if ("10005". Equals (status)) {//System problem Toast.maketext (loginactivity.this, message, 1). Show (); Dialog.dismiss ();} else if ("No". Equals (s)) {//Network problem Dialog.dismiss (); Toast.maketext (loginactivity.this, "Network Problem", 1). Show ();}};Dialog = Progressdialog.show (this, NULL, "Logging in ... Please later ", True, True);d ialog.setcancelable (false);Fixedthreadpool.execute(New Runnable () {@Overridepublic void run () {hashmap<string, object> map = null;try {String result = Net.login (Constant.login_url, "phone", PhoneNumber, "password", password);//LOG.I ("return", result);// Parse JSON string result = result.substring (1, Result.length ()-1); LOG.I ("Login result", result); Jsonobject jsonobject = new Jsonobject (result);map = new hashmap<string, object> ();LOG.I ("Result", Jsonobject.get ("message") + "");//Login result information Map.put ("message", jsonobject.getstring ("message"));// Status Code map.put ("status", Jsonobject.getstring ("status");//If the user is logged on successfully, the ID and user ID will be saved if ("10000". Equals ( Jsonobject.getstring ("status")) {//save user Picture Constant.useric = Net.getbitmap (jsonobject.getstring ("Portrait"));// User identification Code Map.put ("Sigen", Jsonobject.getstring ("Sigen")),//upload avatar with the Keymap.put ("Key", Jsonobject.getstring ("key");// User Idmap.put ("userid", Jsonobject.getstring ("userid"));//Total integral map.put ("integral", jsonobject.getstring ("Integral")) ;//user Avatar Map.put ("Portrait", Jsonobject.getstring ("Portrait"));}list.add (map);Notify Uimessage msg = new Message (); msg.obj = "OK"; handler.sendmessage (msg);} catch (Exception e) {e.printstacktrace ();//notification Uimessage msg = new Message () Msg.obj = "No"; Handler.sendmessage (msg);}}); }}
A set of very standard templates for data requests and data presentation code