Skip to content

Commit

Permalink
module 整合
Browse files Browse the repository at this point in the history
  • Loading branch information
android-ext committed Oct 28, 2018
1 parent 176ff0b commit ea691a4
Show file tree
Hide file tree
Showing 215 changed files with 5,306 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
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

2 changes: 2 additions & 0 deletions android_h5/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build

28 changes: 28 additions & 0 deletions android_h5/build.gradle
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'
}
21 changes: 21 additions & 0 deletions android_h5/proguard-rules.pro
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
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());
}
}
24 changes: 24 additions & 0 deletions android_h5/src/main/AndroidManifest.xml
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>
14 changes: 14 additions & 0 deletions android_h5/src/main/assets/error.html
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>
50 changes: 50 additions & 0 deletions android_h5/src/main/assets/form.html
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>
43 changes: 43 additions & 0 deletions android_h5/src/main/assets/index.html
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>
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;
}
}
}
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);
}
}
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);
}
Loading

0 comments on commit ea691a4

Please sign in to comment.