"Assistant App" login

Source: Internet
Author: User

Continuation of the university when the idea of curriculum design, the first is landing 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0007.gif "alt=" J_0007.gif "/>


Of course, before landing there are other interfaces, such as the first landing will have a welcome navigation interface, when the application will be launched to display the logo interface. Again in the next article.


Logo interface After the end will enter the login interface, of course, if there is no automatic login user (there is automatic login user, is to skip the login interface, directly into the main interface).


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4D/B2/wKioL1RXdIjhj-j0AADgE4Y-gmQ915.jpg "title=" capture. PNG "alt=" Wkiol1rxdijhj-j0aadge4y-gmq915.jpg "/>


The landing interface consists of two input boxes, two optional buttons and two buttons. The interface is simple, but it costs a great deal of effort, a simple list is as follows:

An avatar is displayed to the left of the input box, and the right side is a small fork with a key emptied;

Enter the study number will automatically match the user who has logged in, if the login check the remember password, select the user will automatically fill the password;

When the user name or password is empty click the login button, the empty input box will jitter, and there will be a red font hint is empty;

Tick automatic login, the next time you open the app will be directly to the user's account automatically login, and will not display the login screen.


First, the input box with the Avatar and fork

The code is as follows:

public class clearedittext extends edittext implements           OnFocusChangeListener, TextWatcher { /** *  Delete a reference to a button  */    private drawable mcleardrawable;     /**      *  whether the control has focus      */    private  boolean hasfoucs;     public clearedittext (Context context)  {     this (context, null);     }       public clearedittext (context context, attributeset attrs)  {      //here The construction method is also very important, do not add this many properties can not be defined in the XML     this (Context, attrs,  android. R.attr.edittextstyle);     }          Public cleareditteXT (Context context, attributeset attrs, int defstyle)  {         super (Context, attrs, defstyle);         init ();    }             Private void init ()  {     //get EditText drawableright, if not set we will use the default picture     mcleardrawable = getcompounddrawables () [2];          if  (mcleardrawable == null)  { //         throw new nullpointerexception ("You can add drawableright  attribute in xml ");        mcleardrawable =  Getresources (). getdrawable (r.drawable.delete_selector);          }     &nBsp;            mcleardrawable.setbounds (0, 0 ,  mcleardrawable.getintrinsicwidth (),  mcleardrawable.getintrinsicheight ());          //default settings Hide icon         setcleariconvisible ( FALSE);          //set focus change monitoring          setonfocuschangelistener (this);          // Sets the monitor         addtextchangedlistener (this) that changes the contents of the input box;      }       /**     *  Because we can't set the click event directly to EditText, we use the location we pressed to simulate the Click event      *  when we press the position   in    EditText width  -  icon to the right of the control spacing  -  icon width    and      *  EditText width  -  icon to the right of the control between the spacing we even click on the icon, vertical sideNo consideration for      */     @Override  public boolean  Ontouchevent (motionevent event)  {if  (event.getaction ()  == motionevent.action_up)  {if  (Getcompounddrawables () [2] != null)  {boolean touchable =  Event.getx ()  >  (GetWidth ()  - gettotalpaddingright ()) &&  (Event.getx ()   <  ((GetWidth ()  - getpaddingright ()));if  (touchable)  {this.settext ("");}} Return super.ontouchevent (event);}      /**     *  when the Clearedittext focus changes, Judging inside the string length setting clear icon display and hide      */     @Override       public void onfocuschange (View v, boolean hasfocus)  {      this.hasFoucs = hasFocus;        if  ( Hasfocus) &NBSP;{&NBSP;&NBSp;           setcleariconvisible (GetText (). Length ()  > 0);         } else {              setcleariconvisible (False);          }     }        /**     *  set the clear icon to be displayed and hidden, call setcompounddrawables for EditText to draw up       *  @param  visible     */    protected  Void setcleariconvisible (boolean visible)  {          Drawable right = visible ? mClearDrawable : null;          setcompounddrawables (Getcompounddrawables () [0],          &nbSp;       getcompounddrawables () [1], right, getcompounddrawables ( ) [3]);     }               /**     *  callback method when content changes in the input box      */      @Override      public void ontextchanged (charsequence  s, int start, int count,              int after)  {              if (Hasfoucs) {             Setcleariconvisible (S.length ()  > 0);             }    }       @Override       public void beforetexTchanged (charsequence s, int start, int count,              int after)  {               }       @Override       public void aftertextchanged (editable s)  {               }             /**     *  set up shaking animations      */     public void setshakeanimation () {    this.setanimation (ShakeAnimation (5));     }            /**      *  shaking animation      *  @param  counts 1 seconds shaking how much lower       *  @return      */    public static Animation  Shakeanimation (int counts) {    animation translateanimation = new  translateanimation (0, 10, 0, 0);     Translateanimation.setinterpolator (New cycleinterpolator (counts));     Translateanimation.setduration (;    return translateanimation;   )  }  }

When defining an input box:

        <cn.edu.wit.withelper.util.ClearEditText             android:id= "@+id/userid"              android:layout_weight= "1"              android:layout_width= "0dip"              android:layout_height= "Wrap_content"              android:background= "@drawable/et_userid_border"              android:drawableleft= "@drawable/users_selector"              android:drawableright= "@drawable/delete_selector"              android:hint= "Please enter your school number"           &nBsp;  android:inputtype= "Number"              android:focusableintouchmode= "true"              android:padding= "3DP"             android: Singleline= "true"             android:textsize= " 25SP " />

Jitter animations are also defined above,

The drop-down list is described below,

Ib_spinner = (ImageButton) Findviewbyid (R.id.ib_spinner);//A picture that covers the right end of the input box Ib_spinner.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {//Popup drop-down list listview listview = New ListView (Getapplicationcontext ()); Listview.setcachecolorhint (0x00000000);//Do not change color when sliding listview.setverticalscrollbarenabled (false); Listview.setbackgroundcolor (Getresources (). GetColor (R.color.white));//Set Transparency Listview.getbackground (). Setalpha ( Listview.setadapter (New Myadapter ());p op = new Popupwindow (ListView, Etuserid.getwidth () +ib_spinner.getwidth () , Layoutparams.wrap_content, true);//Pop Hidden pop.setbackgrounddrawable (new colordrawable (0x00000000)); Pop.setoutsidetouchable (True);p op.setfocusable (true);//pop.setanimationstyle (r.style.popupanimation); Pop.showasdropdown (Etuserid, 0, -8);p op.update ();});



Next thing is, remember the password and automatically log in.

if (1 = = Isauto) {//automatic login is stored in the database and written to the configuration file Sharedpreferencesutil.saveloginuser (loginactivity.this, user); Userinfoservices.insertuserinfo (user);} else if (1 = = Isremember) {//Remember password is written to database Userinfoservices.insertuserinfo (user);}

After the successful landing, according to the user's choice, the data processing


And then, how to make a landing

public static userinfo login (UserInfo loginUser)  {String URL =  "Http://www.******.com/api/android/login";final map<string,  String> params = new hashmap<string, string> ();p arams.put ("UserID",  Loginuser.getuserid ());p arams.put ("Password",  loginuser.getpassword ()); Jsonobject jsonresult = interfaceutil.getjsonobject (Url, params);if  (jsonResult  == null)  {log.i (tag,  "Result = null"); return loginuser;} &NBSP;ELSE&NBSP;{LOG.I (tag,  "result = "  + jsonresult.tostring ());return  Getuserbyjson (Jsonresult, loginuser);}} 
public static jsonobject getjsonobject (String url,  //  the parameter sequence of the requested urlmap<string, string> params //  request)  {long timestamp  = new date (). GetTime ();//timestamp params.put ("timestamp",  ""  + timestamp);// Signparams.put ("Sign",  md5util.getmd5string (Salt + timestamp)); String result = postrequesttoserver (Url, params);if  (null == result)  { LOG.I (tag,  "Result = null"); return null;} ELSE&NBSP;{LOG.I (tag,  "result = "  + result); Jsontokener jsontokener = new jsontokener (result); jsonobject json = null;try {json =  (Jsonobject)  jsonTokener.nextValue ();}  catch  (jsonexception e)  {e.printstacktrace ();}  finally {return json;}} End of else} 

This involves access to the network, parsing of the JSON, and encapsulation of the data

Public static string postrequesttoserver (string url, //  request of urlmap<string,  String> params //  parameter sequence for request) &NBSP;{LOG.I (tag,  "Access Network"); Httpentityenclosingrequestbase httprequest = new httppost (URL); List<namevaluepair> namevaluepairs = new arraylist<namevaluepair> (Params.size ( ));for  (Map.entry<string, string> entry : params.entryset ())  {//  Build form field Content Namevaluepairs.add (New basicnamevaluepair (Entry.getkey (),  entry.getvalue ()));} string strresult =  ""; Try {httprequest.setentity (New urlencodedformentity ( Namevaluepairs, "UTF-8")); Httpclient client = new defaulthttpclient (); Httpparams httpparams = client.getparams (); Httpconnectionparams.setconnectiontimeout (httpparams,7000); Httpconnectionparams.setsotimeout (httpparams,7000);//  execution Request httpresponse httpresponse =  Client.Execute (HttpRequest);//  Returns the result, and 200 indicates that the if  is returned correctly (Httpresponse.getstatusline (). Getstatuscode ()  ==  200)  {//  get content strresult = entityutils.tostring from the returned results (httpresponse.getentity (), "UTF-8 ");}  else {strresult = null;}}  catch  (exception e)  {e.printstacktrace (); Message msg = new message (); msg.what = task.error_netexception ;msg.obj  = e; MainService.handler.sendMessage (msg); strresult = null;}  finally {return strresult;}}

In this application, all network access is implemented through this function.


There is also a function to get a picture of the network, which is not used in this application and is intended to be used to obtain the user's avatar

/** * get picture by URL * @param URL * @return */public static drawable getnetimage (url url) {if (null = = URL) return null;try {Htt Purlconnection connection = (httpurlconnection) url.openconnection (); return Drawable.createfromstream ( Connection.getinputstream (), "image");} catch (IOException e) {e.printstacktrace ();} return null;}

Another is the operation of the sharedpreferences;

/** *  Save login User Information  *  @param  context *  @param  user */public  Static void saveloginuser (Context context, userinfo user)  {SharedPreferences  sp = context.getsharedpreferences (login_user, context.mode_private); Editor editor = sp.edit (); Editor.putstring (Userinfo.userid, user.getuserid ()); Editor.putstring (Userinfo.sessionid, user.getsessionid ()); Editor.putstring (userinfo.username,  User.getusername ()); Editor.commit ();} /** *  Get login user information  *  @param  context *  @return  */public static  Userinfo getloginuser (Context context)  {SharedPreferences sp =  Context.getsharedpreferences (login_user, context.mode_private); String userid = sp.getstring (userinfo.userid,  ""); String session = sp.getstring (userinfo.sessionid,  ""); String username = sp.getstring (Userinfo.username,  "");if  ("". Equals (userId)) return null; Userinfo user = new userinfo (); User.setuserid (userId); User.setsessionid (session); User.setusername (userName); return user;}



Landing pretty much something like this, and now it seems that a lot of things are too low, but still show it in the original. Tomorrow, the source of the project uploaded to GitHub, there is time to revise, hope to have interest, or have the intention of the great God guidance.

PS: Auto Get tags it sucks.

This article from the "Young Wind" blog, declined to reprint!

"Assistant App" login

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.