Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animated splash screen with Phonegap

Is that possible to add animated splash screens for Android and iOS Phonegap apps? I tried to add animated .gif as splash screen file for Android but it doesn't work. I.e. there is no animation, the only thing I can see is first frame of the .gif.

And also is there a way to add dynamic text somewhere at splash screen? Actually this is what I want. And to use .gif is just my assumption how can I do it in the easiest way. So, if you can give me example of working cod for iOS and Android dynamic splash screens with Phonegap it will be even better.

like image 416
SergeyT Avatar asked Sep 20 '11 07:09

SergeyT


2 Answers

gif animations are not supported on Android. Animations are possible using jQuery. This is what you can do

  1. Create a data-role="page" div which contains your splash screen view
  2. register a event listener for "pageshow" event for this page and start your animation using jQuery
  3. In the same eventlistener call javascript's timeout function

setTimeout('functionToLoadNewPage', 2000); //functionToLoadNewPage - function name which will load a new page using $.mobile.changePage and 2000 - number of milliseconds for splash screen to be visible

like image 200
Rahul Choudhary Avatar answered Oct 12 '22 23:10

Rahul Choudhary


I've been searching, and I think that you should create a javascript-android interface and do something like Cordova does.

This is the Cordova code:

public class SplashScreen extends Plugin {

    @Override
    public PluginResult execute(String action, JSONArray args, String callbackId) {
        PluginResult.Status status = PluginResult.Status.OK;
        String result = "";

         if (action.equals("hide")) {
             this.webView.postMessage("splashscreen", "hide");
         } else if (action.equals("show")){
             this.webView.postMessage("splashscreen", "show");
         }
         else {
             status = PluginResult.Status.INVALID_ACTION;
         }
         return new PluginResult(status, result);
     }

And it is invoked throught javascript like this:

 exec(null, null, "SplashScreen", "show", []);

Also you will need to do it for iOS too, see this link: ios fade out splash screen (iphone 5 friendly)

like image 23
rafinskipg Avatar answered Oct 13 '22 00:10

rafinskipg