Upstream version 10.38.217.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(Context context, AttributeSet attrs,
19             SharedXWalkExceptionHandler handler) {
20         super(verifyActivity(context), attrs);
21     }
22
23     public SharedXWalkView(Context context, Activity activity) {
24         super(context, verifyActivity(activity));
25     }
26
27     private static Activity verifyActivity(Context context) {
28         assert context instanceof Activity;
29         if (!initialized) initialize(context, null);
30         return (Activity) context;
31     }
32
33     public static void initialize(Context context, SharedXWalkExceptionHandler handler) {
34         if (initialized) return;
35
36         assert context.getApplicationContext() instanceof XWalkApplication;
37         ReflectionHelper.allowCrossPackage();
38         if (handler != null) ReflectionHelper.setExceptionHandler(handler);
39         initialized = true;
40     }
41
42     public static boolean containsLibrary() {
43         return !ReflectionHelper.shouldUseLibrary();
44     }
45
46     public static boolean isUsingLibrary() {
47         return ReflectionHelper.isUsingLibrary();
48     }
49 }