Project Ne10
An Open Optimized Software Library Project for the ARM Architecture
MainActivity.java
1 /*
2  * Copyright 2013-15 ARM Limited and Contributors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ARM Limited nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 package com.arm.ne10.demo;
28 
29 
30 import com.arm.ne10.demo.R;
31 
32 import android.os.Bundle;
33 import android.annotation.SuppressLint;
34 import android.app.Activity;
35 import android.webkit.JavascriptInterface;
36 import android.webkit.WebSettings;
37 import android.webkit.WebView;
38 
39 /* suppress warning of setJavaScriptEnabled */
40 @SuppressLint("SetJavaScriptEnabled")
41 public class MainActivity extends Activity {
42 
43  public class MyJavaInterface {
44  MainActivity mParent;
46  mParent = parent;
47  }
48  @JavascriptInterface
49  public String NE10RunTest() {
50  return mParent.NE10RunTest();
51  }
52  }
53 
54  @Override
55  protected void onCreate(Bundle savedInstanceState) {
56  super.onCreate(savedInstanceState);
57  setContentView(R.layout.activity_main);
58 
59  WebView myWebView = (WebView) findViewById(R.id.webview);
60  WebSettings webSettings = myWebView.getSettings();
61  webSettings.setJavaScriptEnabled(true);
62 
63  myWebView.addJavascriptInterface(new MyJavaInterface(this), "MyJavaClass");
64 
65  myWebView.loadUrl("file:///android_asset/demo.html");
66 
67  }
68 
69  /* A native method that is implemented by native library, which is packaged
70  * with this application.
71  */
72  public native String NE10RunTest();
73 
74  /* this is used to load the native library on application
75  * startup. The library has already been unpacked into
76  * /data/data/com.example.demo/lib/libNE10_test_demo.so at
77  * installation time by the package manager.
78  * it's under libs/armeabi/ directory under project dir
79  */
80  static {
81  System.loadLibrary("NE10_test_demo");
82  }
83 }