Sunday, September 25, 2016

Added A Splash Screen - Day 1

This is my first day and I have thought of making the app in the order of components that the user sees when he opens the app, first is my Splash screen, then the menu and so on and so forth. 

I added a splash screen and added a few animations on it, here is the code:

Splash.class : 

package com.arixeapps.zeal;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
/** * Created by aryan on 25-Sep-16. */
public class Splash extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final ImageView zealIcon = (ImageView) findViewById(R.id.imageView);
final Animation fadeIn = AnimationUtils.loadAnimation(getBaseContext(), R.anim.fadein);
final Animation fadeOut = AnimationUtils.loadAnimation(getBaseContext(), R.anim.fadeout);
final TextView mainText = (TextView) findViewById(R.id.textView);
final Animation fadeInText = AnimationUtils.loadAnimation(getBaseContext(), R.anim.fadeintext);
final Animation fadeOutText = AnimationUtils.loadAnimation(getBaseContext(), R.anim.fadeouttext);
final TextView taglineText = (TextView) findViewById(R.id.textView2);
final Animation fadeInTag = AnimationUtils.loadAnimation(getBaseContext(), R.anim.fadeintagline);
final Animation fadeOutTag = AnimationUtils.loadAnimation(getBaseContext(), R.anim.fadeouttagline);
mainText.setVisibility(View.INVISIBLE);
taglineText.setVisibility(View.INVISIBLE);
zealIcon.setVisibility(View.INVISIBLE);
zealIcon.startAnimation(fadeIn);
zealIcon.setVisibility(View.VISIBLE);


fadeIn.setAnimationListener(new Animation.AnimationListener() {
@Override public void onAnimationStart(Animation animation) {
}
@Override public void onAnimationEnd(Animation animation) {
//zealIcon.startAnimation(fadeOut); taglineText.setVisibility(View.INVISIBLE);
mainText.startAnimation(fadeInText);
mainText.setVisibility(View.VISIBLE);
//mainText.startAnimation(fadeOutText); fadeInText.setAnimationListener(new Animation.AnimationListener() {
@Override public void onAnimationStart(Animation animation) {
}
@Override public void onAnimationEnd(Animation animation) {
taglineText.startAnimation(fadeInTag);
taglineText.setVisibility(View.VISIBLE);
fadeInTag.setAnimationListener(new Animation.AnimationListener() {
@Override public void onAnimationStart(Animation animation) {
}
@Override public void onAnimationEnd(Animation animation) {
zealIcon.startAnimation(fadeOut);
mainText.startAnimation(fadeOutText);
taglineText.startAnimation(fadeOutTag);
fadeOutTag.setAnimationListener(new Animation.AnimationListener() {
@Override public void onAnimationStart(Animation animation) {
}
@Override public void onAnimationEnd(Animation animation) {
zealIcon.setVisibility(View.GONE);
mainText.setVisibility(View.GONE);
taglineText.setVisibility(View.GONE);
finish();
Intent callMain = new Intent(getBaseContext(), MainActivity.class);
startActivity(callMain);
}
@Override public void onAnimationRepeat(Animation animation) {
}
});
}
@Override public void onAnimationRepeat(Animation animation) {
}
});
}
@Override public void onAnimationRepeat(Animation animation) {
}
});

}
@Override public void onAnimationRepeat(Animation animation) {
}
});

}
}

I made the animations for them accordingly and I will be doing some code cleanup in the next day so I don't have this many animations because of duration difference.

In AndroidManifest you have to set the MainActivity as default and set Splash activity as launcher  to see the Splash before MainActivity: 

<application    android:allowBackup="true"    android:icon="@mipmap/ic_launcher"    android:label="@string/app_name"    android:supportsRtl="true"    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity android:name=".Splash">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

    </activity>
</application>