Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core / src / org / xwalk / core / SharedXWalkView.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;
6
7 import android.app.Activity;
8 import android.content.Context;
9 import android.util.AttributeSet;
10
11 /**
12  * The XWalkView that allows to use Crosswalk's shared library.
13  */
14 public class SharedXWalkView extends XWalkView {
15
16     private static boolean initialized = false;
17
18     public SharedXWalkView(XWalkActivity context, AttributeSet attrs,
19             SharedXWalkExceptionHandler handler) {
20         super(verifyActivity(context), attrs);
21     }
22
23     public SharedXWalkView(Context context, XWalkActivity activity) {
24         super(context, verifyActivity(activity));
25     }
26
27     private static Activity verifyActivity(XWalkActivity context) {
28         if (!initialized) initialize(context, null);
29         return context;
30     }
31
32     public static void initialize(Context context, SharedXWalkExceptionHandler handler) {
33         if (initialized) return;
34
35         assert context.getApplicationContext() instanceof XWalkApplication;
36         ReflectionHelper.allowCrossPackage();
37         if (handler != null) ReflectionHelper.setExceptionHandler(handler);
38         initialized = true;
39     }
40
41     public static boolean containsLibrary() {
42         return !ReflectionHelper.shouldUseLibrary();
43     }
44
45     public static boolean isUsingLibrary() {
46         return ReflectionHelper.isUsingLibrary();
47     }
48 }