Upstream version 11.40.277.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.Context;
8 import android.content.Intent;
9 import android.util.Log;
10
11 import org.xwalk.core.internal.XWalkExtensionInternal;
12 import org.xwalk.core.internal.XWalkLaunchScreenManager;
13
14 /**
15  * A XWalk extension for LaunchScreen API implementation on Android.
16  */
17 public class LaunchScreenExtension extends XWalkExtensionInternal {
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     private Context mContext;
29
30     public LaunchScreenExtension(String jsApi, Context context) {
31         super(NAME, jsApi, JS_ENTRY_POINTS);
32         mContext = context;
33     }
34
35     @Override
36     public void onMessage(int instanceId, String message) {
37         if (message.equals(CMD_HIDE_LAUNCH_SCREEN)) {
38             hideLaunchScreen();
39         }
40     }
41
42     private void hideLaunchScreen() {
43         // TODO: Considered about the performance of broadcast receiver, it will be a little delayed to hide the
44         // launch screen. Better to have an api directly to XWalkLaunchScreenManager.
45         // Need to be well designed in the future.
46         String filterStr = XWalkLaunchScreenManager.getHideLaunchScreenFilterStr();
47         Intent intent = new Intent(filterStr);
48         mContext.sendBroadcast(intent);
49     }
50
51     @Override
52     public String onSyncMessage(int instanceID, String message) {
53         return null;
54     }
55 }