-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
176ff0b
commit ea691a4
Showing
215 changed files
with
5,306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.idea/ | ||
gradlew | ||
gradlew.bat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion rootProject.compileVersion | ||
defaultConfig { | ||
applicationId "com.lianjia.devext.androidh5" | ||
minSdkVersion rootProject.minSdkVersion | ||
targetSdkVersion rootProject.targetSdkVersion | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:26.1.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
android_h5/src/androidTest/java/com/lianjia/devext/androidh5/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.lianjia.devext.androidh5; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.lianjia.devext.androidh5", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.lianjia.devext.androidh5"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity" | ||
android:windowSoftInputMode="adjustPan"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".WebViewActivity" /> | ||
<activity android:name=".FormActivity"></activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<title></title> | ||
</head> | ||
<body> | ||
|
||
|
||
<div id="content">错误页面</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<title></title> | ||
</head> | ||
<body> | ||
|
||
<div> | ||
<input type="text" name="user_name" id="user_name"/> | ||
<button id="transform_native">从native获取姓名</button> | ||
</div> | ||
|
||
<div> | ||
<input type="text" name="user_favorite" id="user_favorite"/> | ||
<button id="btn1">调用android有参参数</button> | ||
</div> | ||
<div> | ||
<input type="button" id="submit_form" value="提交"> | ||
</div> | ||
|
||
<div id="content"></div> | ||
|
||
</body> | ||
|
||
<script type="text/javascript"> | ||
// 跳转到 native 页面 | ||
document.getElementById("transform_native").onclick = function(){ | ||
// android对象名称,transformNative是android中的方法 | ||
window.location.href="protocol://android?code=transformNative"; | ||
}; | ||
|
||
// 从 native 页面输入的用户姓名 | ||
function inflateUserNameInput(value){ | ||
document.getElementById("user_name").value = value; | ||
}; | ||
|
||
// 回传给 android 表单界面的数据 | ||
document.getElementById("submit_form").onclick = function(){ | ||
var name = document.getElementById("user_name").value; | ||
var favorite = document.getElementById("user_favorite").value; | ||
var json = { | ||
user_name: name, | ||
user_favorite: favorite | ||
}; | ||
window.location.href="protocol://android?code=submitForm&data="+encodeURI(JSON.stringify(json),"utf-8"); | ||
}; | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>WebView</title> | ||
<style type="text/css"> | ||
body { | ||
background:#cbcc1a | ||
} | ||
.btn { | ||
line-height: 40px; | ||
margin: 10px; | ||
background: #cccccc; | ||
padding: 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h2>WebView</h2> | ||
<div> | ||
<span>请输入要传递的值:</span><input type="text" id="input"> | ||
</div> | ||
<div id="btn"> | ||
<span class="btn">点我</span> | ||
</div> | ||
<script type="text/javascript"> | ||
var btnEle = document.getElementById("btn"); | ||
var inputEle = document.getElementById("input"); | ||
btnEle.addEventListener("click", function() { | ||
var str = inputEle.value; | ||
if (window.imoocBridge) { | ||
imoocBridge.setHtmlValue(str); | ||
} else { | ||
alert("imoocBridge not found!"); | ||
} | ||
}); | ||
|
||
var remote = function (str) { | ||
inputEle.value = str; | ||
return "此处可以返回值给android"; | ||
} | ||
</script> | ||
</body> | ||
</html> |
40 changes: 40 additions & 0 deletions
40
android_h5/src/main/java/com/lianjia/devext/androidh5/FormActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.lianjia.devext.androidh5; | ||
|
||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
|
||
import static com.lianjia.devext.androidh5.MainActivity.NAME_KEY; | ||
|
||
public class FormActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
public static final int FROM_RESULT_CODE = 2; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_form); | ||
|
||
findViewById(R.id.form_btn).setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
switch (v.getId()) { | ||
case R.id.form_btn: | ||
EditText editText = findViewById(R.id.form_name); | ||
String result = editText.getText().toString(); | ||
if (TextUtils.isEmpty(result)) { | ||
return; | ||
} | ||
Intent intent = new Intent(); | ||
intent.putExtra(NAME_KEY, result.trim()); | ||
setResult(FROM_RESULT_CODE, intent); | ||
finish(); | ||
break; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
android_h5/src/main/java/com/lianjia/devext/androidh5/ImoocJsInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.lianjia.devext.androidh5; | ||
|
||
import android.webkit.JavascriptInterface; | ||
|
||
public class ImoocJsInterface { | ||
|
||
private JsBridge mJsBridge; | ||
|
||
public ImoocJsInterface(JsBridge jsBridge) { | ||
mJsBridge = jsBridge; | ||
} | ||
|
||
@JavascriptInterface | ||
public void setHtmlValue(String value) { | ||
mJsBridge.setTextViewValue(value); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
android_h5/src/main/java/com/lianjia/devext/androidh5/JsBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.lianjia.devext.androidh5; | ||
|
||
public interface JsBridge { | ||
|
||
void setTextViewValue(String value); | ||
} |
Oops, something went wrong.