We all know that many applications will have a new feature display when they are used for the first time after installation. A good new feature display will bring a better user experience to the customer. Therefore, when we make an application, we can't ignore this issue and have to admire that we have done a good job in this regard. Today, I will simulate the display of new features and make a small application.
Source code:Http://download.csdn.net/detail/weidi1989/4562605
Not to mention nonsense. First, go:
The last one adds an animation for opening the door:
The main class structure is as follows:
Paste the following code:
Loginactivity code:
Package COM. way. viewpager; import Java. util. arraylist; import Java. util. list; import Java. util. timer; import Java. util. timertask; import android. app. activity; import android. content. context; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. support. v4.view. viewpager; import android. support. v4.view. viewpager. onpagechangelistener; import android. view. layoutinflater; import android. view. view; import android. view. view. onclicklistener; import android. view. animation. animation; import android. view. animation. animationutils; import android. view. animation. animation. animationlistener; import android. view. window; import android. widget. imageview;/***** @ author way **/public class loginactivity extends activity {Private Static final int isnew = 0x001; // whether it is Private Static final int complete = 0x002; // private context mcontext = This; private dotmarks mdotmarks; private imageview ivleftimage, ivrightimage; private handler = new handler () {public void handlemessage (Android. OS. message MSG) {Switch (MSG. what) {Case isnew: // If (whatisnewutils. isfirstuse (loginactivity. this) // {// if the application Init () is used for the first time; // Save the flag, the next time the program whatisnewutils is opened. isfirstuse (loginactivity. this) returns falsewhatisnewutils. savefirstuseflag (loginactivity. this); //} else {// setcontentview (R. layout. activity_main); //} break; Case complete: View mainview = layoutinflater. from (mcontext ). inflate (R. layout. activity_main, null); setcontentview (mainview); animation enteranim = animationutils. loadanimation (mcontext, R. anim. main_activity_enter_anim); enteranim. setfillafter (true); mainview. startanimation (enteranim); break; default: Break ;}}; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); requestwindowfeature (window. feature_no_title); setcontentview (R. layout. login); new timer (). schedule (New timertask () {@ overridepublic void run () {message MSG = message. obtain (); MSG. what = isnew; handler. sendmessage (MSG) ;}}, 2000) ;}/ *** initialize the new feature interface */private void Init () {layoutinflater = layoutinflater. from (mcontext); view what_is_new = layoutinflater. inflate (R. layout. what_is_new, null); view pageone = layoutinflater. inflate (R. layout. layout1, null); view pagetwo = layoutinflater. inflate (R. layout. layout2, null); view pagethree = layoutinflater. inflate (R. layout. layout3, null); ivleftimage = (imageview) pagethree. findviewbyid (R. id. iv_left_image01); ivrightimage = (imageview) pagethree. findviewbyid (R. id. iv_left_image02); viewpager = (viewpager) what_is_new.findviewbyid (R. id. view_pager); List <View> viewitems = new arraylist <View> (); viewitems. add (pageone); viewitems. add (pagetwo); viewitems. add (pagethree); viewpager. setadapter (New whatisnewadapter (viewitems); mdotmarks = (dotmarks) what_is_new.findviewbyid (R. id. dot_marks);/*** page flip listener event, used to update index pictures */viewpager. setonpagechangelistener (New onpagechangelistener () {/*** update the index small icon in real time based on the changes in the viewpager page **/Public void onpageselected (INT arg0) {mdotmarks. updatemark (arg0); // update} public void onpagescrolled (INT arg0, float arg1, int arg2) {// todo auto-generated method stub} public void onpagescrollstatechanged (INT arg0) {// todo auto-generated method stub});/*** adds a click event to the last view to switch the view */pagethree. setonclicklistener (New onclicklistener () {public void onclick (view v) {mdotmarks. setvisibility (view. invisible); startanimation (); // start animation}); this. setcontentview (what_is_new);}/*** animation */private void startanimation () {animation leftanim = animationutils. loadanimation (mcontext, R. anim. slide_left_anim); animation rightanim = animationutils. loadanimation (mcontext, R. anim. slide_right_anim); // final animation fadeanim = animationutils. loadanimation (mcontext, R. anim. fade_anim); leftanim. setfillafter (true); rightanim. setfillafter (true); rightanim. setanimationlistener (New animationlistener () {public void onanimationstart (animation) {// mdotmarks. startanimation (fadeanim);} public void onanimationrepeat (animation) {} public void onanimationend (animation) {// The animation ends message MSG = handler. obtainmessage (); MSG. what = complete; handler. sendmessage (MSG) ;}}); ivleftimage. startanimation (leftanim); ivrightimage. startanimation (rightanim );}}
The custom dotmarks is the following three dots to simulate the page turning effect:
Package COM. way. viewpager; import android. content. context; import android. graphics. drawable. drawable; import android. util. attributeset; import android. view. layoutinflater; import android. view. view; import android. widget. imageview; import android. widget. linearlayout;/***** @ author way **/public class dotmarks extends linearlayout {private imageview mark_one, mark_two, mark_three; // three smaller images: Private drawable guide_focus = getresources (). getdrawable (R. drawable. guide_focus); // The focus image resource private drawable guide_default = getresources (). getdrawable (R. drawable. guide_default); // non-focus image resource public dotmarks (context) {super (context); Init (context);} public dotmarks (context, attributeset attrs) {super (context, attrs); Init (context) ;}/ *** initialize * @ Param context * context object */private void Init (context) {layoutinflater = layoutinflater. from (context); view dotmarks = layoutinflater. inflate (R. layout. dot_marks, null); this. addview (dotmarks); mark_one = (imageview) dotmarks. findviewbyid (R. id. dot_mark1); mark_two = (imageview) dotmarks. findviewbyid (R. id. dot_mark2); mark_three = (imageview) dotmarks. findviewbyid (R. id. dot_mark3); // set a default value mark_one.setimageresource (R. drawable. guide_focus); mark_two.setimageresource (R. drawable. guide_default); mark_three.setimageresource (R. drawable. guide_default);}/*** switch the display of the small icon Based on the index on the passed page ***/Public void updatemark (INT index) {Switch (INDEX) {Case 0: values (guide_focus); values (guide_default); break; Case 1: mark_one.setimagedrawable (guide_default); values (guide_focus); values (guide_default); break; Case 2: mark_one.setimagedrawable (guide_default); mark_two.setimagedrawable (guide_default); mark_three.setimagedrawable (guide_focus); break; default: break ;}}}
New feature adapter whatisnewadapter
package com.way.viewpager;import java.util.List;import android.os.Parcelable;import android.support.v4.view.PagerAdapter;import android.support.v4.view.ViewPager;import android.view.View;/** * * @author way * */public class WhatIsNewAdapter extends PagerAdapter {public List<View> mListViews;public WhatIsNewAdapter(List<View> mListViews) {this.mListViews = mListViews;}@Overridepublic void destroyItem(View arg0, int arg1, Object arg2) {((ViewPager) arg0).removeView(mListViews.get(arg1));}@Overridepublic void finishUpdate(View arg0) {}@Overridepublic int getCount() {return mListViews.size();}@Overridepublic Object instantiateItem(View arg0, int arg1) {((ViewPager) arg0).addView(mListViews.get(arg1), 0);return mListViews.get(arg1);}@Overridepublic boolean isViewFromObject(View arg0, Object arg1) {return arg0 == (arg1);}@Overridepublic void restoreState(Parcelable arg0, ClassLoader arg1) {}@Overridepublic Parcelable saveState() {return null;}@Overridepublic void startUpdate(View arg0) {}}
The tool class whatisnewutils is used to determine whether a user uses the app for the first time:
Package COM. way. viewpager; import android. app. activity; import android. content. context; import android. content. sharedpreferences;/***** @ author way **/public class whatisnewutils {Private Static string what_is_new_pre_name = "success"; Private Static string first_use_flag = "first_use_flag "; /***** determine whether the application is used for the first time ***/public static Boolean isfirstuse (context) {sharedpreferences = context. getsharedpreferences (what_is_new_pre_name, activity. mode_private); Boolean flag = sharedpreferences. getboolean (first_use_flag, true); Return flag;}/*** Save the information used for the first time ***/public static void savefirstuseflag (context) {sharedpreferences = context. getsharedpreferences (what_is_new_pre_name, activity. mode_private); sharedpreferences. editor editor = sharedpreferences. edit (); Editor. putboolean (first_use_flag, false); Editor. commit ();}}
The new main layout file what_is_new.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <android.support.v4.view.ViewPager android:id="@+id/view_pager" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <com.way.viewpager.DotMarks android:id="@+id/dot_marks" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:paddingBottom="50dp" /></RelativeLayout>
The layout file dot_marks.xml contains three dots:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ImageView android:id="@+id/dot_mark1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/guide_default" /> <ImageView android:id="@+id/dot_mark2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/guide_default" /> <ImageView android:id="@+id/dot_mark3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/guide_default" /></LinearLayout>
There are other animation effects and layout files that I will not post.