One of my unlicensed projects required a pop-up screen, although this was not necessary. Perhaps this may be useful for your project, as it is based on dialogue, not on activity. If the splash screen is displayed or gestured, it will be fired, as well as after the animation is completed (timeout). Modifications can be made to the class, so you check some kind of “ready state logical” before allowing the tap or gestures to reject the image.
class file: AppIntro.java
import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; public class AppIntro extends Dialog { protected int mLayoutRes = 0; protected int mAnimRes = 0; protected Animation mIntroAnim = null; protected View mLayout = null; public AppIntro(Context aContext, int aLayoutRes, int aAnimRes) { super(aContext); mLayoutRes = aLayoutRes; mAnimRes = aAnimRes; } @Override protected void onCreate(Bundle aSavedState) { super.onCreate(aSavedState); mLayout = LayoutInflater.from(getContext()).inflate(mLayoutRes,null); mLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AppIntro.this.dismiss(); } }); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(mLayout); mIntroAnim = AnimationUtils.loadAnimation(getContext(),mAnimRes); mIntroAnim.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) {
Then we determine that our animation disappears (change the duration to what you need to load your application) in the file "res / anim / intro_anim.xml". 4200 = 4.2 seconds.
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="4200" android:repeatCount="0" > </alpha> </set>
Finally, we define our splash screen layout (using any image (s) you want) in "layout / intro.xml". In my specific screen saver, the name of the application was displayed with an image along with 3 logos from different funding sources.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_intro" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/intro_Text_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:gravity="center" android:text="@string/title_intro" android:textAppearance="?android:attr/textAppearanceLarge" /> <ImageView android:id="@+id/intro_Image_myproject" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/intro_Text_title" android:layout_centerHorizontal="true" android:src="@drawable/intro_image" /> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/intro_Image_myproject" android:layout_alignRight="@id/intro_Image_myproject" android:layout_alignLeft="@id/intro_Image_myproject"> <ImageView android:id="@+id/intro_Image_logo1" android:layout_width="80dp" android:layout_height="50dp" android:scaleType="fitXY" android:src="@drawable/logo1" android:layout_gravity="left|center_vertical"/> <ImageView android:id="@+id/intro_Image_logo2" android:layout_width="150dp" android:layout_height="wrap_content" android:src="@drawable/logo2" android:layout_gravity="center" android:scaleType="centerInside"/> <ImageView android:id="@+id/intro_Image_logo3" android:layout_width="70dp" android:layout_height="70dp" android:scaleType="fitXY" android:src="@drawable/logo3" android:layout_gravity="right|center_vertical"/> </FrameLayout> </RelativeLayout>
The code used to pop up the dialog box:
@Override protected void onCreate(Bundle aSavedState) { super.onCreate(aSavedState); if (aSavedState==null) { //only show splash screen at app start, not on rotate screen new AppIntro(this,R.layout.intro,R.anim.intro_anim).show(); } setContentView(R.layout.main); //...rest of onCreate() }
My application displayed my main view at the same time as the splash screen, so ensure that this dialog does not appear as soon as you call .show ().