b862f92ce86e04ad6ac3cd2e92e5cf6424e0dfe1
[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
20     private final static String NAME = "xwalk.launchscreen";
21     private final static String[] JS_ENTRY_POINTS = {
22         "window.screen.show"
23     };
24
25     // Command messages:
26     private final static String CMD_HIDE_LAUNCH_SCREEN = "hideLaunchScreen";
27
28     public LaunchScreenExtension(String jsApi, XWalkExtensionContext context) {
29         super(NAME, jsApi, JS_ENTRY_POINTS, context);
30     }
31
32     @Override
33     public void onMessage(int instanceId, String message) {
34         if (message.equals(CMD_HIDE_LAUNCH_SCREEN)) {
35             hideLaunchScreen();
36         }
37     }
38
39     private void hideLaunchScreen() {
40         // TODO: Considered about the performance of broadcast receiver, it will be a little delayed to hide the
41         // launch screen. Better to have an api directly to XWalkLaunchScreenManager.
42         // Need to be well designed in the future.
43         String filterStr = XWalkLaunchScreenManager.getHideLaunchScreenFilterStr();
44         Intent intent = new Intent(filterStr);
45         mExtensionContext.getActivity().sendBroadcast(intent);
46     }
47 }