B4A Library Splash Screen Library with Slide & Fade Out

Added Feb 20th, 2014 - Version 1.02
This library displays a splash screen and then removes it by fading it out, just removing it or sliding it off the screen in any direction, your choice.

This new library was based on my SplashFade class, that I had posted some time back. It requires the Phone and JavaObjects libraries provided with B4A 3.2. It will work in previous versions of B4A, provided you have these libraries in the Xtralibs or Internal library folder . Supports Android 2.2+ versions. There are many improvements above the class code as to how it works and the speed. It also now includes a callback to the Activity to let the Activity know the screen slide or fade has completed. Instead of "Left", Up, etc., pass "" for the fade.

This version also includes a new Random feature. If set to True(the last parameter), it will randomly choose to fade, slide up, down, left, etc.

The library is attached.

Special thanks to Stevel05 for helping me sort this out! This library has broader support due to his work and help. Thanks Steve!

Uses Phone & JavaObjects Libraries. NOTE: You do not need to select these in the Libraries TAB, just make sure they are in your Xtralibs folder.

Code Sample:
B4X:
Sub Globals
    Dim MyFade As SplashFade
End Sub
 
Sub Activity_Create(FirstTime AsBoolean)
    Activity.LoadLayout("YourLayoutFile")
    'Place this line below the Activity.LoadLayout or after the last view you add by code.
    MyFade.Initialize(Activity, Me, "yourimage.jpg", Gravity.FILL, 3000, 100, "Left", False)
End Sub
 
Sub Splash_Complete
    'Add this sub if you need to know when the splash has completed
End Sub
 

Attachments

  • SplashFadeSlideLibrary.zip
    5 KB · Views: 1,849
Last edited:

Dadeda

Member
Licensed User
Longtime User
Got it thanks, it's working now... sorry for this noob question but i'm leaning how to use this rad tool..
 

eSolution

Member
Licensed User
Longtime User
Hi Margret, I have tried the lib and the code you provided and it works fine (well... it stretch the image all over the screen so is not quite good for different screen sizes) but the main problem that I have found is that it is initialized every time the screen orientation is changed so if I tilt the phone the splash will show again ... I'm sure that this is because the splash is initialized in the Activity_Create ... I just started using B4A so I'm not that good at coding but there must be a way to put it in an If and check if is the first time initialized or something ... can you implement something like this in the lib itself? Thank you!
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
My Splash_Complete sub seems to be getting called 2 times?

Why would this happen? How do I stop it.

I am only calling the Splashscreen once in my ActivityCreate firsttime logic.

BobVal
 

slugger

Member
Licensed User
Longtime User
Hi Margret,

is it possible to add a method to close the splash screen from code?

Ideally I'd like to show the splash screen at the start of my app when it does its own initialization things and close it when it is ready to interact with the user.

Something like this:

B4X:
Sub Activity_Create(FirstTime AsBoolean)
    'Using a 30 seconds SHOWFOR to suit also the slower devices
    MyFade.Initialize(Activity, Me, "yourimage.jpg", Gravity.FILL, 30000, 100, "Left", False)

    'Activity_Create does all of
    'its initialization things for the time it takes

    'and now at the end of Activity_Create something like
    MyFade.CloseNow
    'that starts the fading process immediately

End Sub
 

Peter Simpson

Expert
Licensed User
Longtime User

Phayao

Active Member
Licensed User
Longtime User
This saved my day since I was not able to show a splash screen and during the time the splash is displayed I want to load some data to prepare the main view. That was only possible (for me) after I detected your excellent Lib. Thanks a lot !
I did it this way:

sub Activity_create(firstTime as boolean)
Activity.LoadLayout("main")
<call sub to build the main layout, takes long time>
' hide the main layout:
pnlMain.Visible = False
MyFade.Initialize(Activity, Me, "background.jpg", Gravity.FILL, 3000, 100, "", False)
end sub

Sub Splash_Complete
' after splash:
setMenuLabels ' initialize the first panel showing a menu
showMenuPanel ' show the panel with the menu (sitting over pnlMain)
End Sub


Chris
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @margret!
First of all, my compliments for this fantastic library! :)
How to pass an "android.graphics.drawable.Drawable" obj instead of the string name of the image?

From this: MyFade.Initialize(Activity, Me, "default.png", Gravity.FILL, 3000, 100, "Left", False)
To this: MyFade.Initialize(Activity, Me, default.png, Gravity.FILL, 3000, 100, "Left", False)

Explanation:

I need this in order to get the right resolution file with AndroidResources1.GetAndroidDrawable("imagename")
 

Gunther

Active Member
Licensed User
Longtime User
+1

Hi margret,

one can use CreateScaledBitmap() than!

in addition when one chose to have the scaled image by GRAVITY.CENTER the transparent parts are white afterwards.

Can you let it keep transparent?

Cheers,

Gunther
 
Last edited:

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Margret

I tried the code posted at startup. The splash screen doesn't cover the main layout completely.
To be more specific, the upper part of the main layout shows
Any ideas?

Thank you
 

peacemaker

Expert
Licensed User
Longtime User
THanks for the lib !
It works with a backgound task while screen is active.
But found some stange: i tried to use splash screen on two activities.
1) First at the very start works OK.
2) But second the same declared (in GLOBALS) splash screen on the second activity is initialized only after user tapped some button.
But when activity is opened second time - Sub Splash_Complete is fired suddently without the user tap !

SOLVED: declaring splash object in a local sub helped to avoid it...
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
So, no author available any more ? Method .CloseNow is very needed :(
 
Top