Android realizes the switch between the splash screen and the registration and login interface _android

Source: Internet
Author: User
Tags gettext object object trim stringbuffer

Before we introduce the text to everyone to say the realization of ideas:

First, respectively, the implementation of the splash screen, registration interface, login interface activities, and then use intent related activities connected to achieve the jump between different activities. This trial code more, I only listed the main code, detailed code can be downloaded from the bottom of the download link.

First, the Experiment Effect chart:

Second, the main code:

(1) Welcomeactivity.java (this part of the code to achieve the first page of the Welcome page)

Package Com.example.flashscreendemo; 
Import android.app.Activity; 
Import android.content.Intent; 
Import Android.os.Bundle; 
Import android.view.animation.AlphaAnimation; 
Import android.view.animation.Animation; 
Import Android.view.animation.Animation.AnimationListener; 
Import android.view.animation.RotateAnimation; 
Import Android.widget.ImageView; 
Import Android.widget.RelativeLayout; 
public class Weclomeactivity extends activity {private relativelayout layoutwecome; 
Private ImageView Ivmonkey; 
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); * * * requestwindowfeature (Window.feature_no_title); Cancel the Power status bar * This.getwindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, * 
WindowManager.LayoutParams.FLAG_FULLSCREEN); 
* * Setcontentview (r.layout.activity_weclome); 
Layoutwecome = (relativelayout) Findviewbyid (r.id.layoutwelcome); 
Alphaanimation alphaanimation = new Alphaanimation (0.0f, 1.0f); Alphaanimation.setdUration (1000); 
Layoutwecome.startanimation (alphaanimation); 
Ivmonkey = (ImageView) Findviewbyid (R.id.ivmonkey); 
Rotateanimation rotateanimation = new Rotateanimation (0, 360); 
Rotateanimation.setduration (2000); 
Rotateanimation.setrepeatcount (2); 
Ivmonkey.startanimation (rotateanimation); Rotateanimation.setanimationlistener (New Animationlistener () {@Override public void Onanimationstart (Animation Animation) {} @Override public void Onanimationrepeat (animation animation) {} @Override public void Onanimationend (Animation Animation) 
{Intent Intent = new Intent (weclomeactivity.this, Guideactivity.class); 
StartActivity (Intent); 
Finish (); 
} 
}); } 
}

(2) Guideactivity.java (this part of the code implements the functionality of the four boot interfaces)

Package Com.example.flashscreendemo; 
Import java.util.ArrayList; 
Import java.util.List; 
Import Com.example.flashscreendemo.adapter.GuideAdapter; 
Import android.app.Activity; 
Import android.content.Intent; 
Import Android.os.Bundle; 
Import Android.support.v4.view.ViewPager; 
Import Android.support.v4.view.ViewPager.OnPageChangeListener; 
Import Android.view.LayoutInflater; 
Import Android.view.Menu; 
Import Android.view.View; 
Import Android.widget.ImageView; 
public class Guideactivity extends activity {private Viewpager vpguide; 
Private ImageView ivdots[]; 
Private int[] dots_id; 
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 
Setcontentview (R.layout.activity_guide); 
Initguideviews (); 
Initdots (); Vpguide.setonpagechangelistener (New Onpagechangelistener () {@Override public void onpageselected (int position) {for ( int i = 0; i < ivdots.length; i++) {if (position = = i) {ivdots[i]. Setimageresource (r.drawable.bg_point_selected); 
else {ivdots[i].setimageresource (r.drawable.bg_point_normal); @Override public void onpagescrolled (int position, float arg1, int arg2) {} @Override public void Onpagescro 
llstatechanged (int postion) {}}); public void Jumpmain (view view) {Intent Intent = new Intent (This, Com.example.minitwittersimulate.LoginActivity.clas 
s); 
StartActivity (Intent); 
Finish (); 
} private void Initdots () {dots_id = new int[] {r.id.ivdots1, r.id.ivdots2, R.id.ivdots3, R.ID.IVDOTS4}; 
Ivdots = new Imageview[dots_id.length]; 
for (int i = 0; i < ivdots.length i++) {ivdots[i] = (ImageView) Findviewbyid (dots_id[i)); 
} private void Initguideviews () {vpguide = (Viewpager) Findviewbyid (r.id.vpguide); 
list<view> views = new arraylist<view> (); 
Layoutinflater layoutinflater = Getlayoutinflater (); 
View view1 = layoutinflater.inflate (R.layout.view1ofpager, NULL); 
Views.add (View1); View view2 = layoutinflater.inflate (R.LAYOUT.VIEW2OFPAGER, NULL); 
Views.add (VIEW2); 
View view3 = layoutinflater.inflate (R.layout.view3ofpager, NULL); 
Views.add (VIEW3); 
View view4 = layoutinflater.inflate (R.layout.view4ofpager, NULL); 
Views.add (VIEW4); 
Guideadapter guideadapter = new Guideadapter (views); 
Vpguide.setadapter (Guideadapter); @Override public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds the items to the action bar if I 
T is present. 
Getmenuinflater (). Inflate (r.menu.guide, menu); 
return true; } 
}

(3) Guideadapter.java (this part of the code to achieve the function of data adaptation)

Package com.example.flashscreendemo.adapter; 
Import java.util.List; 
Import Android.support.v4.view.PagerAdapter; 
Import Android.view.View; 
Import Android.view.ViewGroup; 
public class Guideadapter extends Pageradapter { 
private list<view> views; 
Public Guideadapter (list<view> views) { 
super (); 
This.views = views; 
} 
@Override public 
int GetCount () {return 
views.size (); 
} 
@Override Public 
Boolean isviewfromobject (View view, Object object) {return 
view = = object; 
} 
@Override public 
Object instantiateitem (viewgroup container, int position) { 
Container.addview views.get ( position)); 
return Views.get (position); 
} 
@Override public 
void Destroyitem (ViewGroup container, int position, object object) { 
Container.removeview ( Views.get (position)); 
} 

(4) Loginactivity.java (this part of the code is the implementation of the login interface)

Package com.example.minitwittersimulate; 
Import android.app.Activity; 
Import android.content.Intent; 
Import android.content.SharedPreferences; 
Import Android.os.Bundle; 
Import Android.preference.PreferenceManager; 
Import Android.view.View; 
Import Android.view.View.OnClickListener; 
Import Android.widget.Button; 
Import Android.widget.CheckBox; 
Import Android.widget.EditText; 
Import Android.widget.TextView; 
Import Android.widget.Toast; 
Import COM.EXAMPLE.FLASHSCREENDEMO.R; 
public class Loginactivity extends activity {private sharedpreferences pref; 
Private Sharedpreferences.editor Editor; 
Private EditText Etusername; 
Private EditText Etpassword; 
Private Button Btnlogin; 
Private CheckBox Cbrememberpass; 
Private TextView Tvre; 
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 
Setcontentview (R.layout.activity_login); 
Pref = Preferencemanager.getdefaultsharedpreferences (this); Etusername = (edittext) Findviewbyid (R.Id.etusername); 
Etpassword = (edittext) Findviewbyid (R.id.etpassword); 
Cbrememberpass = (CheckBox) Findviewbyid (R.id.cbrememberpass); 
Btnlogin = (Button) Findviewbyid (R.id.btnlogin); 
Tvre = (TextView) Findviewbyid (R.id.tvre); 
Boolean isremember = Pref.getboolean ("Remember_password", false); 
if (isremember) {//The account number and password are set to the text box = pref.getstring ("Accounts", ""); 
String Password = pref.getstring ("Password", ""); 
Etusername.settext (account); 
Etpassword.settext (password); 
Cbrememberpass.setchecked (TRUE); Btnlogin.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {String account = Etusern 
Ame.gettext (). toString (); 
String password = Etpassword.gettext (). toString (); if (Account.trim (). Equals ("")) {Toast.maketext (loginactivity.this, "Please enter your username!") 
", Toast.length_short). Show (); 
Return } if (Password.trim (). Equals ("")) {Toast.maketext (loginactivity.this, "Please enter your password!") 
", Toast.length_short). Show (); 
Return } if (Account.equals ("Admin ") && password.equals (" 123456 ")) {editor = Pref.edit (); 
if (cbrememberpass.ischecked ()) {//Check check box is selected Editor.putboolean ("Remember_password", true); 
Editor.putstring ("account", account); 
Editor.putstring ("password", password); 
else {editor.clear (); 
} editor.commit (); 
Intent Intent = new Intent (loginactivity.this, Mainactivity.class); 
StartActivity (Intent); 
Finish (); 
else {toast.maketext (loginactivity.this, "account or password be invalid", Toast.length_short). Show (); 
} 
} 
}); Tvre.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {//TODO auto-generated method s 
Tub Intent Intent = new Intent (loginactivity.this, Register.class); 
StartActivity (Intent); 
Finish (); 
} 
}); } 
}

(5) User.java (this part of the code implements data entered into user input to the registration interface)

Package com.example.minitwittersimulate; 
public class User {private String userName; 
Private String PassWord; 
private char sex; 
Private String City; 
Private String hobby; 
Public String GetUserName () {return userName; 
} public void Setusername (String userName) {this.username = UserName; 
Public String GetPassword () {return passWord; 
} public void SetPassword (String passWord) {This.password = PassWord; 
Public Char Getsex () {return sex; 
The public void setsex (char sex) {this.sex = sex; 
Public String getcity () {return city; 
public void Setcity (String city) {this.city = city; 
Public String Gethobby () {return hobby; 
} public void Sethobby (String hobby) {this.hobby = hobby; 
Public User (String userName, string passWord, char sex, String city, String hobby) {super (); 
This.username = UserName; 
This.password = PassWord; 
This.sex = sex; 
this.city = City; 
This.hobby = hobby; @Override public String toString () {//TODO Auto-genErated method stubs return this.username + "," + This.password + "," + This.sex + "," + this.city + "," + this.hobby; } 
}

(6) Register.java (this part of the code is the implementation of the registration Interface)

Package com.example.minitwittersimulate; 
Import COM.EXAMPLE.FLASHSCREENDEMO.R; 
Import android.app.Activity; 
Import android.content.Intent; 
Import Android.os.Bundle; 
Import Android.text.TextUtils; 
Import Android.view.View; 
Import Android.widget.CheckBox; 
Import Android.widget.EditText; 
Import Android.widget.RadioButton; 
Import Android.widget.Spinner; 
Import Android.widget.Toast; 
public class Register extends activity {edittext etuser, ETPASSW, ETREPASSW; 
RadioButton Rbmale, Rbfamale; 
CheckBox cbread, Cbtourist, Cbplaygame; 
Spinner spcity; 
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 
Setcontentview (R.layout.activity_register); 
Init (); 
private void Init () {//TODO auto-generated method Stub etuser = (EditText) Findviewbyid (R.id.etuser); 
ETPASSW = (edittext) Findviewbyid (R.ID.ETPASSW); 
ETREPASSW = (edittext) Findviewbyid (R.ID.ETREPASSW); 
Rbmale = (RadioButton) Findviewbyid (R.id.rbmale); Rbfamale = (RadiObutton) Findviewbyid (R.id.rbfamale); 
Cbread = (CheckBox) Findviewbyid (R.id.cbread); 
Cbtourist = (CheckBox) Findviewbyid (r.id.cbtourist); 
Cbplaygame = (CheckBox) Findviewbyid (r.id.cbplaygame); 
Spcity = (Spinner) Findviewbyid (r.id.spcity); public void onclick (view view) {switch (View.getid ()) {case R.id.btregister:string userName = Etuser.gettext (). To 
String (); 
if (Textutils.isempty (UserName)) {Toast.maketext (this, "User name cannot be empty", \ n). Show (); 
Return 
String PASSW = Etpassw.gettext (). toString (); 
if (Textutils.isempty (PASSW)) {etpassw.seterror ("Password cannot be blank"); 
Return 
String REPASSW = Etrepassw.gettext (). toString (); 
if (Textutils.isempty (REPASSW)) {etrepassw.seterror ("Confirm password cannot be blank"); 
Return 
} if (!passw.equals (REPASSW)) {Toast.maketext (this, "two times password inconsistency,"). Show (); 
Return 
} char sex; 
if (rbmale.ischecked ()) {sex = Rbmale.gettext (). charAt (0); 
else {sex = Rbfamale.gettext (). charAt (0); 
} stringbuffer s = new StringBuffer (); 
if (cbread.ischecked ()) {S.append (Cbread.gettext (). toString () + ","); 
} if (cbtourist.ischecked ()) {S.append (Cbtourist.gettext (). toString () + ","); 
} if (cbplaygame.ischecked ()) {S.append (Cbplaygame.gettext (). toString () + ","); 
String city = Spcity.getselecteditem (). toString (); 
User user = new User (userName, PASSW, Sex, s.tostring (). Equals ("")? ": s.tostring (). substring (0, s.length ()), city); 
Toast.maketext (This, "User registration information:" + user.tostring (), 100000). Show (); 
Intent Intent = new Intent (register.this, Loginactivity.class); 
StartActivity (Intent); 
Finish (); 
Break 
Case R.id.bteixt:finish (); 
Break 
Case R.id.btreturn:intent intent1 = new Intent (register.this, Loginactivity.class); 
StartActivity (INTENT1); 
Finish (); 
Break } 
} 
}

(7) Mainactivity.java (this part of the code to achieve the click "Login" button to jump to the interface)

Package com.example.minitwittersimulate; 
Import android.app.Activity; 
Import Android.os.Bundle; 
Import Android.view.Menu; 
Import COM.EXAMPLE.FLASHSCREENDEMO.R; 
public class Mainactivity extends activity { 
@Override 
protected void onCreate (Bundle savedinstancestate) { 
super.oncreate (savedinstancestate); 
Setcontentview (R.layout.activity_main); 
} 
@Override Public 
Boolean oncreateoptionsmenu (Menu menu) { 
getmenuinflater (). Inflate (R.menu.main, menu); 
return true; 
} 

The above is a small set of Android to introduce the screen and registration and login interface between the switch effect, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.