Upstream version 8.36.156.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core_internal / src / org / xwalk / core / internal / extension / api / launchscreen / LaunchScreenExtension.java
1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.xwalk.core.internal.extension.api.launchscreen;
6
7 import android.content.Intent;
8 import android.util.Log;
9
10 import org.xwalk.core.internal.XWalkLaunchScreenManager;
11 import org.xwalk.core.internal.extension.XWalkExtension;
12 import org.xwalk.core.internal.extension.XWalkExtensionContext;
13
14 /**
15  * A XWalk extension for LaunchScreen API implementation on Android.
16  */
17 public class LaunchScreenExtension extends XWalkExtension {
18     public final static String JS_API_PATH = "jsapi/launch_screen_api.js";
19     public final static String NAME = "xwalk.launchscreen";
20     public final static String[] JS_ENTRY_POINTS = {
21         "window.screen.show"
22     };
23
24     // Command messages:
25     private final static String CMD_HIDE_LAUNCH_SCREEN = "hideLaunchScreen";
26
27     public LaunchScreenExtension(String name, String jsApi, String[] entryPoints, XWalkExtensionContext context) {
28         super(name, jsApi, entryPoints, context);
29     }
30
31     @Override
32     public void onMessage(int instanceId, String message) {
33         if (message.equals(CMD_HIDE_LAUNCH_SCREEN)) {
34             hideLaunchScreen();
35         }
36     }
37
38     private void hideLaunchScreen() {
39         // TODO: Considered about the performance of broadcast receiver, it will be a little delayed to hide the
40         // launch screen. Better to have an api directly to XWalkLaunchScreenManager.
41         // Need to be well designed in the future.
42         String filterStr = XWalkLaunchScreenManager.getHideLaunchScreenFilterStr();
43         Intent intent = new Intent(filterStr);
44         mExtensionContext.getActivity().sendBroadcast(intent);
45     }
46 }