Splash screen + Guide page

Source: Internet
Author: User

Implementation principle:

Implemented with Sharedpreferences.
Creates a Boolean variable with the default value of True.
When judging that this variable is true, the description is the first run, jump to another boot page, otherwise go to the main page.

When the boot page jumps to the last picture, click on a button to jump to the event, return to Mainactivity, and change the value of the variable to false.

The guide diagram effect is implemented with Viewpager.

The following code is attached:

Splash.xml:

<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:tools= "Http://schemas.android.com/tools" android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
tools:context= "Com.zn.Activity.SplashActivity" >
<imageview
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:adjustviewbounds= "true"
android:background= "@drawable/w01"
Android:scaletype= "Centercrop"/>

</RelativeLayout>

Guid.xml:

<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:paddingbottom= "@dimen/activity_vertical_margin"
tools:context= "Com.zn.Activity.GuidActivity" >
<android.support.v4.view.viewpager
Android:id= "@+id/guid_viewpager"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:layout_alignparentleft= "true"
Android:layout_alignparenttop= "true" >
</android.support.v4.view.ViewPager>
<linearlayout
Android:id= "@+id/viewgroup"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparentbottom= "true"
Android:layout_centerhorizontal= "true"
Android:layout_marginbottom= "38.0DP"
android:orientation= "Horizontal" >
<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Center_vertical"
Android:clickable= "true"
Android:padding= "15.0dip"
android:src= "@drawable/dot"/>

<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Center_vertical"
Android:clickable= "true"
Android:padding= "15.0dip"
android:src= "@drawable/dot"/>

<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Center_vertical"
Android:clickable= "true"
Android:padding= "15.0dip"
android:src= "@drawable/dot"/>
</LinearLayout>
</RelativeLayout>
Boot page layout file:
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:orientation= "Vertical" >
<imageview
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
Android:layout_centerinparent= "true"
Android:adjustviewbounds= "false"
Android:focusable= "true"
Android:scaletype= "Centercrop"
android:background= "@drawable/guide01"/>
</LinearLayout>
Splash Screen page activity:
Package com.zn.Activity;

Import android.app.Activity;
Import android.content.Intent;
Import android.content.SharedPreferences;
Import Android.os.Bundle;
Import Android.os.Handler;
Import Android.os.Message;
Import Android.view.Window;

/**
* Created by admin on 2016/8/3.
*/
public class Splashactivity extends Activity {
Boolean isfirstin = false;
private static final int go_home = 1000;
private static final int go_guide = 1001;

Private static final long splash_delay_millis = 1000;
Private Handler Mhandler = new Handler () {
@Override
public void Handlemessage (Message msg) {
Switch (msg.what) {
Case Go_home:
GoHome ();
Break
Case Go_guide:
Goguide ();
Break
}

Super.handlemessage (msg);
}
};

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Requestwindowfeature (window.feature_no_title);//go to the title bar
Setcontentview (R.layout.activity_splash);
Init ();
}

private void init () {
Read the data needed in the Sharedpreferences
Use Sharedpreferences to record the number of programs used
Sharedpreferences preferences = Getsharedpreferences (
Icontes.sharedpreferences_name, mode_private);

Gets the corresponding value, if there is no value, the description is not written, with true as the default value
Isfirstin = Preferences.getboolean ("Isfirstin", true);
Judge the program with the first run, if it is the initial run jump to the boot interface, otherwise jump to the main interface
if (!isfirstin) {
Using Handler's Postdelayed method, 1 seconds after execution jumps to mainactivity
Mhandler.sendemptymessagedelayed (Go_home, Splash_delay_millis);
} else {
Mhandler.sendemptymessagedelayed (Go_guide, Splash_delay_millis);
}

}

private void GoHome () {
Intent Intent = new Intent (splashactivity.this, Mainactivity.class);
SplashActivity.this.startActivity (Intent);
SplashActivity.this.finish ();
}

private void Goguide () {
Intent Intent = new Intent (splashactivity.this, Guidactivity.class);
SplashActivity.this.startActivity (Intent);
SplashActivity.this.finish ();
}
}
Guide page activity:
Package com.zn.Activity;

Import Android.support.v4.view.ViewPager;
Import android.support.v7.app.AppCompatActivity;
Import Android.os.Bundle;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;

Import Com.zn.Adapter.ViewPagerApter;

Import java.util.ArrayList;
Import java.util.List;

public class Guidactivity extends appcompatactivity implements viewpager.onpagechangelistener{
Private Viewpager Viewpager;
Private Viewpagerapter Viewpagerapter;
Private list<view> views;

Small dots at the bottom of the picture
Private imageview[] dots;
Record the currently selected location
private int currentindex;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.LAYOUT.ACTIVITY_GUID);

Initialize page
Initviews ();
Initialize the bottom small dot
Initdots ();

}

private void Initviews () {
Layoutinflater Inflater=layoutinflater.from (this);
Views=new arraylist<view> ();
Initialize the picture list of the boot page
Views.add (Inflater.inflate (r.layout.layout_item1,null));
Views.add (Inflater.inflate (r.layout.layout_item2,null));
Views.add (Inflater.inflate (r.layout.layout_item5,null));

Initialize Adapter
Viewpagerapter=new Viewpagerapter (views,this);

Viewpager= (Viewpager) Findviewbyid (R.id.guid_viewpager);
Viewpager.setadapter (Viewpagerapter);
Binding callbacks
Viewpager.setonpagechangelistener (this);


}

private void Initdots () {
LinearLayout linearlayout= (android.widget.LinearLayout) Findviewbyid (R.id.viewgroup);
Dots=new imageview[views.size ()];

Loop to get a picture of the dots
for (int i=0;i<views.size (); i++) {
dots[i]= (ImageView) Linearlayout.getchildat (i);
Dots[i].setenabled (TRUE);//

}
currentindex=0;
Dots[currentindex].setenabled (false);//set to white, select state

}

private void Setcurrentdot (int position) {
if (position<0| | Position>views.size () -1| | Currentindex==position) {
Return

}
Dots[position].setenabled (FALSE);
Dots[currentindex].setenabled (TRUE);
Currentindex=position;
}

Called when the current page is sliding
@Override
public void onpagescrolled (int position, float positionoffset, int positionoffsetpixels) {

}

Called when the current page is selected
@Override
public void onpageselected (int position) {
Set the bottom small dot check state
Setcurrentdot (position);

}

Called when the sliding state changes
@Override
public void onpagescrollstatechanged (int.) {

}
}
Adapter:
Package com.zn.Adapter;

Import android.app.Activity;
Import Android.content.Context;
Import android.content.Intent;
Import android.content.SharedPreferences;
Import android.os.Parcelable;
Import Android.support.v4.view.PagerAdapter;
Import Android.support.v4.view.ViewPager;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.ImageView;

Import com.zn.Activity.Icontes;
Import com.zn.Activity.MainActivity;
Import COM.ZN.ACTIVITY.R;

Import java.util.List;

/**
* Created by admin on 2016/8/3.
*/
public class Viewpagerapter extends Pageradapter {
Private list<view> views;
private activity activity;


Public Viewpagerapter (list<view> views, activity activity) {
This.views = views;
This.activity = activity;
}

Destroying the position location interface
@Override
public void Destroyitem (ViewGroup container, int position, object object) {
((Viewpager) container). Removeview (Views.get (position));
}

Get the current number of pages
@Override
public int GetCount () {
if (views! = null) {
return Views.size ();
}
return 0;
}

@Override
public void Finishupdate (ViewGroup container) {

}

Initializing the Position interface
@Override
Public Object Instantiateitem (viewgroup container, int position) {
((Viewpager) container). AddView (Views.get (position), 0);
if (position = = Views.size ()-1) {
ImageView Mstartweiboimagebutton = (ImageView) Container.findviewbyid (R.id.iv_start_weibo);
Mstartweiboimagebutton.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (view view) {
Setting has been booted
Setguided ();
Sharedpreferences preferences = Activity.getsharedpreferences (
Icontes.sharedpreferences_name, context.mode_private);
Sharedpreferences.editor Editor = Preferences.edit ();
Editor.putboolean ("Isfirstin", false);
Editor.commit ();
GoHome ();
}
});
}
return Views.get (position);
}

private void GoHome () {
Jump
Intent Intent = new Intent (activity, mainactivity.class);
Activity.startactivity (Intent);
Activity.finish ();
}

private void setguided () {
Sharedpreferences preferences = Activity.getsharedpreferences (Icontes.sharedpreferences_name, Context.MODE_PRIVATE );
Sharedpreferences.editor Editor = Preferences.edit ();
Deposit data
Editor.putboolean ("Isfirstin", false);
Submit Changes
Editor.commit ();
}

Determine whether the interface is generated by an object
@Override
public Boolean isviewfromobject (view view, Object object) {
return (view = = object);
}

@Override
public void Restorestate (parcelable state, ClassLoader loader) {

}

@Override
Public parcelable saveState () {
return null;
}

@Override
public void Startupdate (ViewGroup container) {


}
} Small dot xml:
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >

<item android:drawable= "@drawable/dark_dot" android:state_enabled= "true"/>
<item android:drawable= "@drawable/white_dot" android:state_enabled= "false"/>

</selector>

To start the experience button:
<?xml version= "1.0" encoding= "Utf-8"?>
<selector
Xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:state_pressed= "true" android:drawable= "@drawable/tiyan"/>
<item android:drawable= "@drawable/tiyan"/>
</selector>



Splash screen + Guide page

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.