Skip to content

Commit 5796a7b

Browse files
author
ZIP
committed
initsz
0 parents  commit 5796a7b

36 files changed

+694
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

.idea/compiler.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.2"
6+
defaultConfig {
7+
applicationId "com.yokara.javascriptcalljava"
8+
minSdkVersion 15
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:25.3.1'
28+
compile 'com.android.support.constraint:constraint-layout:1.0.2'
29+
testCompile 'junit:junit:4.12'
30+
}

app/proguard-rules.pro

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/zip/Android/Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.yokara.javascriptcalljava;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.yokara.javascriptcalljava", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.yokara.javascriptcalljava">
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>

app/src/main/assets/a.html

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>just tesst</title>
6+
<script>
7+
function myFunction() {
8+
document.getElementById("huu").innerHTML = "New from asstes folder tee23xt2!";
9+
document.getElementById("huu").style.color = "green";
10+
11+
12+
}
13+
function myFunction2() {
14+
document.getElementById("huu2").innerHTML = "New text3!z2";
15+
alert("Hello! I am an alert box!!");
16+
17+
18+
}
19+
20+
</script>
21+
</head>
22+
<body>
23+
<button onclick="myFunction()">Copy Text</button>
24+
<button onclick="myFunction2()">Copy Text</button>
25+
26+
<h1 id="huu">a</h1>
27+
<h1 id="huu2">a</h1>
28+
29+
30+
31+
32+
</body>
33+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.yokara.javascriptcalljava;
2+
3+
import android.annotation.SuppressLint;
4+
import android.app.Activity;
5+
import android.content.Intent;
6+
import android.net.Uri;
7+
import android.os.Bundle;
8+
import android.support.v7.app.AppCompatActivity;
9+
import android.util.Log;
10+
import android.webkit.JavascriptInterface;
11+
import android.webkit.WebView;
12+
import android.webkit.WebViewClient;
13+
14+
public class MainActivity extends AppCompatActivity {
15+
private WebView webView;
16+
private String TAG = "ccc";
17+
18+
@SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled", "AddJavascriptInterface"})
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
setContentView(R.layout.activity_main);
23+
webView = (WebView) findViewById(R.id.videoview);
24+
25+
setupWebView("file:///android_asset/a.html");
26+
// setupWebView("http://192.168.1.140/html/a.html");
27+
}
28+
29+
public class JavaScriptInterface {
30+
private Activity activity;
31+
32+
public JavaScriptInterface(Activity activiy) {
33+
this.activity = activiy;
34+
}
35+
36+
public void startVideo(String videoAddress) {
37+
Intent intent = new Intent(Intent.ACTION_VIEW);
38+
intent.setDataAndType(Uri.parse(videoAddress), "video/3gpp");
39+
activity.startActivity(intent);
40+
}
41+
}
42+
43+
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
44+
private void setupWebView(String webLink) {
45+
webView.getSettings().setJavaScriptEnabled(true);
46+
webView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
47+
webView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT2"); // add new JSInterFace rồi
48+
webView.setWebViewClient(new WebViewClient() {
49+
public void onPageFinished(WebView view, String url) {
50+
setMyJavascripts();
51+
}
52+
});
53+
webView.loadUrl(webLink);
54+
55+
}
56+
57+
class MyJavaScriptInterface {
58+
@SuppressLint("LongLogTag")
59+
@JavascriptInterface
60+
public void gotPairingCode(String jsResult) {
61+
Log.d(TAG + "realParingCode", jsResult);
62+
}
63+
64+
@SuppressLint("LongLogTag")
65+
@JavascriptInterface
66+
public void jsQueryName2(String jsResult) {
67+
Log.d(TAG + "jsQueryName2", jsResult);
68+
}
69+
}
70+
71+
private void setMyJavascripts() {
72+
webView.loadUrl("javascript:window.HTMLOUT.gotPairingCode(document.getElementById('pairing_code').innerHTML);");
73+
webView.loadUrl("javascript:window.HTMLOUT2.jsQueryName2(document.getElementById('queueLabel').innerHTML);");
74+
}
75+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context="com.yokara.javascriptcalljava.MainActivity">
8+
9+
<WebView
10+
android:id="@+id/videoview"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent" />
13+
</RelativeLayout>
3.34 KB
Loading
Loading
2.15 KB
Loading
Loading
4.73 KB
Loading
Loading
7.54 KB
Loading
Loading
10.2 KB
Loading
Loading

app/src/main/res/values/colors.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>

app/src/main/res/values/strings.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">javascript Call Java</string>
3+
</resources>

0 commit comments

Comments
 (0)