42 changed files with 230 additions and 1189 deletions
@ -1,6 +1,6 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
<project version="4"> |
||||
<component name="CompilerConfiguration"> |
<component name="CompilerConfiguration"> |
||||
<bytecodeTargetLevel target="17" /> |
<bytecodeTargetLevel target="1.8" /> |
||||
</component> |
</component> |
||||
</project> |
</project> |
||||
Binary file not shown.
@ -1,58 +0,0 @@ |
|||||
apply plugin: 'com.android.library' |
|
||||
|
|
||||
android { |
|
||||
compileSdkVersion 29 |
|
||||
defaultConfig { |
|
||||
minSdkVersion 21 |
|
||||
targetSdkVersion 28 |
|
||||
versionCode 1 |
|
||||
versionName "1.0" |
|
||||
|
|
||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' |
|
||||
|
|
||||
} |
|
||||
|
|
||||
buildTypes { |
|
||||
release { |
|
||||
minifyEnabled false |
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
repositories { |
|
||||
flatDir { |
|
||||
dirs 'libs' |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
dependencies { |
|
||||
compileOnly fileTree(dir: 'libs', include: ['*.jar']) |
|
||||
|
|
||||
compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar','mlkit-scanner-release.aar']) |
|
||||
|
|
||||
compileOnly 'androidx.recyclerview:recyclerview:1.0.0' |
|
||||
compileOnly 'androidx.legacy:legacy-support-v4:1.0.0' |
|
||||
compileOnly 'androidx.appcompat:appcompat:1.0.0' |
|
||||
implementation 'com.alibaba:fastjson:1.2.83' |
|
||||
implementation 'com.facebook.fresco:fresco:1.13.0' |
|
||||
//添加扫码识别库 |
|
||||
//Camera核心 (*必须) |
|
||||
implementation 'com.github.jenly1314.MLKit:mlkit-camera-core:1.4.0' |
|
||||
//公共库 (可选) (1.3.0新增:当使用到MLKit下面的子库时,需依赖公共库) |
|
||||
implementation 'com.github.jenly1314.MLKit:mlkit-common:1.4.0' |
|
||||
//条码识别 (可选) |
|
||||
implementation 'com.github.jenly1314.MLKit:mlkit-barcode-scanning:1.4.0' |
|
||||
// implementation 'com.github.ITxiaoguang:MLKitScanner:1.0.0' |
|
||||
// implementation 'com.google.mlkit:barcode-scanning:17.0.2' |
|
||||
// implementation "androidx.camera:camera-core:1.0.2" |
|
||||
// implementation "androidx.camera:camera-camera2:1.0.2" |
|
||||
// implementation "androidx.camera:camera-lifecycle:1.0.2" |
|
||||
// implementation "androidx.camera:camera-view:1.0.0-alpha25" |
|
||||
|
|
||||
/*implementation 'com.android.support:appcompat-v7:28.0.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'*/ |
|
||||
} |
|
||||
@ -1,45 +0,0 @@ |
|||||
package cn.bnyer.scancode; |
|
||||
|
|
||||
import android.util.Log; |
|
||||
|
|
||||
import androidx.annotation.NonNull; |
|
||||
import androidx.annotation.Nullable; |
|
||||
|
|
||||
import com.google.mlkit.vision.barcode.common.Barcode; |
|
||||
import com.king.mlkit.vision.barcode.BarcodeCameraScanActivity; |
|
||||
import com.king.mlkit.vision.camera.AnalyzeResult; |
|
||||
import com.king.mlkit.vision.camera.CameraScan; |
|
||||
import com.king.mlkit.vision.camera.analyze.Analyzer; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
public class MainScanActivity extends BarcodeCameraScanActivity { |
|
||||
|
|
||||
@Override |
|
||||
public void initCameraScan(@NonNull CameraScan cameraScan) { |
|
||||
super.initCameraScan(cameraScan); |
|
||||
cameraScan.setPlayBeep(true).setVibrate(true); |
|
||||
} |
|
||||
|
|
||||
@Nullable |
|
||||
@Override |
|
||||
public Analyzer<List<Barcode>> createAnalyzer() { |
|
||||
Log.i("======", "开始分析数据结果:"); |
|
||||
return null; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void onScanResultCallback(@NonNull AnalyzeResult result) { |
|
||||
Log.i("======", "开始解析扫码结果:" + result); |
|
||||
Analyzer<List<Barcode>> analyzer = this.createAnalyzer(); |
|
||||
Log.i("======", "获取到的分析结果:" + analyzer); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void onScanResultFailure() { |
|
||||
Log.i("======", "扫码失败了:"); |
|
||||
super.onScanResultFailure(); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,52 +0,0 @@ |
|||||
package cn.bnyer.scancode; |
|
||||
|
|
||||
import android.content.Intent; |
|
||||
|
|
||||
import com.google.mlkit.vision.barcode.BarcodeScannerOptions; |
|
||||
import com.google.mlkit.vision.barcode.common.Barcode; |
|
||||
import com.king.mlkit.vision.camera.analyze.Analyzer; |
|
||||
import com.xiaoguang.widget.mlkitscanner.ScanManager; |
|
||||
import com.xiaoguang.widget.mlkitscanner.callback.act.ScanCallback; |
|
||||
|
|
||||
import org.json.JSONException; |
|
||||
import org.json.JSONObject; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
import io.dcloud.feature.uniapp.annotation.UniJSMethod; |
|
||||
import io.dcloud.feature.uniapp.bridge.UniJSCallback; |
|
||||
import io.dcloud.feature.uniapp.common.UniModule; |
|
||||
|
|
||||
public class scanCode extends UniModule { |
|
||||
|
|
||||
@UniJSMethod(uiThread = false) |
|
||||
public void add(JSONObject json, UniJSCallback callback) throws JSONException { |
|
||||
final int a = json.getInt("a"); |
|
||||
final int b = json.getInt("b"); |
|
||||
callback.invoke(new JSONObject(){ |
|
||||
{ |
|
||||
put("code",0); |
|
||||
put("result",a + b); |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
// @UniJSMethod(uiThread = false)
|
|
||||
// public void startScan(){
|
|
||||
// MainScanActivity activity = new MainScanActivity();
|
|
||||
// activity.initCameraScan();
|
|
||||
// }
|
|
||||
//
|
|
||||
// @UniJSMethod(uiThread = false)
|
|
||||
// public void createAnalyzer(){
|
|
||||
// MainScanActivity activity = new MainScanActivity();
|
|
||||
//
|
|
||||
// }
|
|
||||
//
|
|
||||
// @UniJSMethod(uiThread = false)
|
|
||||
// public void getScanResult(){
|
|
||||
// MainScanActivity activity = new MainScanActivity();
|
|
||||
// Analyzer<List<Barcode>> analyzer = activity.createAnalyzer();
|
|
||||
// activity.onScanResultCallback(analyzer);
|
|
||||
// }
|
|
||||
} |
|
||||
@ -0,0 +1,120 @@ |
|||||
|
//plugins { |
||||
|
// id 'com.android.library' |
||||
|
//} |
||||
|
|
||||
|
//android { |
||||
|
// namespace 'com.jiyi.jy_mlscansdk' |
||||
|
// compileSdk 32 //29 |
||||
|
// |
||||
|
// defaultConfig { |
||||
|
// minSdkVersion 21 |
||||
|
// targetSdkVersion 32 |
||||
|
// versionCode 1 |
||||
|
// versionName "1.0" |
||||
|
// |
||||
|
//// minSdk 21 |
||||
|
//// targetSdk 32 |
||||
|
// |
||||
|
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
||||
|
// consumerProguardFiles "consumer-rules.pro" |
||||
|
// } |
||||
|
// |
||||
|
// buildTypes { |
||||
|
// release { |
||||
|
// minifyEnabled false |
||||
|
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
||||
|
// } |
||||
|
// } |
||||
|
// compileOptions { |
||||
|
// sourceCompatibility JavaVersion.VERSION_1_8 |
||||
|
// targetCompatibility JavaVersion.VERSION_1_8 |
||||
|
// } |
||||
|
// buildToolsVersion '30.0.3' |
||||
|
//} |
||||
|
// |
||||
|
//dependencies { |
||||
|
// |
||||
|
//// implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) |
||||
|
//// implementation fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar']) |
||||
|
//// |
||||
|
//// implementation "com.android.support:recyclerview-v7:28.0.0" |
||||
|
//// implementation "com.android.support:support-v4:28.0.0" |
||||
|
//// implementation "com.android.support:appcompat-v7:28.0.0" |
||||
|
//// implementation 'com.alibaba:fastjson:1.1.46.android' |
||||
|
//// implementation 'com.facebook.fresco:fresco:1.13.0' |
||||
|
//// |
||||
|
//// implementation 'com.google.mlkit:barcode-scanning:16.2.0' |
||||
|
//// def camerax_version = '1.0.1'; |
||||
|
//// implementation "androidx.camera:camera-core:${camerax_version}" |
||||
|
//// implementation "androidx.camera:camera-camera2:${camerax_version}" |
||||
|
//// implementation "androidx.camera:camera-lifecycle:${camerax_version}" |
||||
|
//// implementation "androidx.camera:camera-view:1.0.0-alpha25" |
||||
|
// |
||||
|
// compileOnly fileTree(dir: 'libs', include: ['*.jar', '*.aar']) |
||||
|
// compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar','mlkit-scanner-release.aar']) |
||||
|
// |
||||
|
// compileOnly "com.android.support:recyclerview-v7:28.0.0" |
||||
|
// compileOnly "com.android.support:support-v4:28.0.0" |
||||
|
// compileOnly "com.android.support:appcompat-v7:28.0.0" |
||||
|
// compileOnly 'com.alibaba:fastjson:1.1.46.android' |
||||
|
// compileOnly 'com.facebook.fresco:fresco:1.13.0' |
||||
|
// |
||||
|
// compileOnly 'com.google.mlkit:barcode-scanning:16.2.0' |
||||
|
// def camerax_version = '1.0.1'; |
||||
|
// compileOnly "androidx.camera:camera-core:${camerax_version}" |
||||
|
// compileOnly "androidx.camera:camera-camera2:${camerax_version}" |
||||
|
// compileOnly "androidx.camera:camera-lifecycle:${camerax_version}" |
||||
|
// compileOnly "androidx.camera:camera-view:1.0.0-alpha25" |
||||
|
// |
||||
|
// |
||||
|
//} |
||||
|
apply plugin: 'com.android.library' |
||||
|
|
||||
|
android { |
||||
|
compileSdkVersion 32 |
||||
|
defaultConfig { |
||||
|
//applicationId 'com.jiyi.jy_mlscansdk' |
||||
|
minSdkVersion 21 |
||||
|
targetSdkVersion 32 |
||||
|
versionCode 1 |
||||
|
versionName "1.0" |
||||
|
|
||||
|
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' |
||||
|
|
||||
|
} |
||||
|
|
||||
|
buildTypes { |
||||
|
release { |
||||
|
minifyEnabled false |
||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
repositories { |
||||
|
flatDir { |
||||
|
dirs 'libs' |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
dependencies { |
||||
|
compileOnly fileTree(dir: 'libs', include: ['*.jar', '*.aar']) |
||||
|
compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar','mlkit-scanner-release.aar']) |
||||
|
|
||||
|
//noinspection GradleCompatible |
||||
|
compileOnly 'com.android.support:recyclerview-v7:28.0.0' |
||||
|
//noinspection GradleCompatible |
||||
|
compileOnly 'com.android.support:support-v4:28.0.0' |
||||
|
//noinspection GradleCompatible |
||||
|
compileOnly 'com.android.support:appcompat-v7:28.0.0' |
||||
|
compileOnly 'com.alibaba:fastjson:1.1.46.android' |
||||
|
compileOnly 'com.facebook.fresco:fresco:1.13.0' |
||||
|
|
||||
|
compileOnly 'com.google.mlkit:barcode-scanning:16.2.0' |
||||
|
def camerax_version = '1.0.1'; |
||||
|
compileOnly "androidx.camera:camera-core:${camerax_version}" |
||||
|
compileOnly "androidx.camera:camera-camera2:${camerax_version}" |
||||
|
compileOnly "androidx.camera:camera-lifecycle:${camerax_version}" |
||||
|
compileOnly "androidx.camera:camera-view:1.0.0-alpha25" |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
## This file must *NOT* be checked into Version Control Systems, |
||||
|
# as it contains information specific to your local configuration. |
||||
|
# |
||||
|
# Location of the SDK. This is only used by Gradle. |
||||
|
# For customization when using a Version Control System, please read the |
||||
|
# header note. |
||||
|
#Thu Aug 17 09:37:12 CST 2023 |
||||
|
sdk.dir=D\:\\andoridSdk |
||||
@ -1,4 +1,4 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.bnyer.scancode"> |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.jiyi.jy_mlscansdk"> |
||||
|
|
||||
</manifest> |
</manifest> |
||||
@ -0,0 +1,66 @@ |
|||||
|
package com.jiyi.jy_mlscansdk; |
||||
|
|
||||
|
import android.app.Activity; |
||||
|
import android.content.Intent; |
||||
|
import android.util.Log; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.taobao.weex.annotation.JSMethod; |
||||
|
import com.taobao.weex.bridge.JSCallback; |
||||
|
import com.xiaoguang.widget.mlkitscanner.ScanManager; |
||||
|
import com.xiaoguang.widget.mlkitscanner.callback.act.ScanCallback; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.util.ArrayList; |
||||
|
|
||||
|
import io.dcloud.feature.uniapp.common.UniModule; |
||||
|
|
||||
|
public class JYMLScanSDKModule extends UniModule { |
||||
|
|
||||
|
private String TAG = "JYMLScanSDKModule"; |
||||
|
|
||||
|
@JSMethod(uiThread = false) |
||||
|
public void startScan(final JSCallback callback) { |
||||
|
|
||||
|
(new Thread(new Runnable() { |
||||
|
public void run() { |
||||
|
try { |
||||
|
Activity activity = (Activity) mUniSDKInstance.getContext(); |
||||
|
ScanManager.startScan(activity, new ScanCallback() { |
||||
|
@Override |
||||
|
public void onActivityResult(int resultCode, Intent data) { |
||||
|
// handlerResult(i, intent);
|
||||
|
if (resultCode == ScanManager.RESULT_SUCCESS) { |
||||
|
ArrayList<String> results = data.getStringArrayListExtra(ScanManager.INTENT_KEY_RESULT_SUCCESS); |
||||
|
Log.d(TAG, "handlerResult: " + results.toString()); |
||||
|
|
||||
|
JSONObject result = new JSONObject(); |
||||
|
result.put("errorCode", "0"); |
||||
|
result.put("data", results.toString()); |
||||
|
|
||||
|
callback.invokeAndKeepAlive(result); |
||||
|
}else { |
||||
|
JSONObject result = new JSONObject(); |
||||
|
result.put("errorCode", "1"); |
||||
|
result.put("data", resultCode); |
||||
|
|
||||
|
callback.invokeAndKeepAlive(result); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
} catch (Exception err) { |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
})).start(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private void handlerResult(int resultCode, Intent data) { |
||||
|
if (resultCode == ScanManager.RESULT_SUCCESS) { |
||||
|
ArrayList<String> results = data.getStringArrayListExtra(ScanManager.INTENT_KEY_RESULT_SUCCESS); |
||||
|
Log.d(TAG, "handlerResult: " + results.toString()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1 +0,0 @@ |
|||||
/build |
|
||||
@ -1,46 +0,0 @@ |
|||||
apply plugin: 'com.android.library' |
|
||||
|
|
||||
android { |
|
||||
compileSdkVersion 29 |
|
||||
|
|
||||
defaultConfig { |
|
||||
minSdkVersion 16 |
|
||||
targetSdkVersion 28 |
|
||||
versionCode 1 |
|
||||
versionName "1.0" |
|
||||
|
|
||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' |
|
||||
|
|
||||
} |
|
||||
|
|
||||
buildTypes { |
|
||||
release { |
|
||||
minifyEnabled false |
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
repositories { |
|
||||
flatDir { |
|
||||
dirs 'libs' |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
dependencies { |
|
||||
compileOnly fileTree(dir: 'libs', include: ['*.jar']) |
|
||||
|
|
||||
compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar']) |
|
||||
|
|
||||
compileOnly 'androidx.recyclerview:recyclerview:1.0.0' |
|
||||
compileOnly 'androidx.legacy:legacy-support-v4:1.0.0' |
|
||||
compileOnly 'androidx.appcompat:appcompat:1.0.0' |
|
||||
implementation 'com.alibaba:fastjson:1.2.83' |
|
||||
implementation 'com.facebook.fresco:fresco:1.13.0' |
|
||||
|
|
||||
/*implementation 'com.android.support:appcompat-v7:28.0.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'*/ |
|
||||
} |
|
||||
@ -1,21 +0,0 @@ |
|||||
# 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 |
|
||||
@ -1,2 +0,0 @@ |
|||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||
package="uni.dcloud.io.uniplugin_component" /> |
|
||||
@ -1,60 +0,0 @@ |
|||||
package io.dcloud.uniplugin; |
|
||||
|
|
||||
import android.content.Context; |
|
||||
import android.graphics.Color; |
|
||||
import android.widget.TextView; |
|
||||
import java.util.HashMap; |
|
||||
import java.util.Map; |
|
||||
|
|
||||
import io.dcloud.feature.uniapp.UniSDKInstance; |
|
||||
import io.dcloud.feature.uniapp.annotation.UniJSMethod; |
|
||||
import io.dcloud.feature.uniapp.ui.action.AbsComponentData; |
|
||||
import io.dcloud.feature.uniapp.ui.component.AbsVContainer; |
|
||||
import io.dcloud.feature.uniapp.ui.component.UniComponent; |
|
||||
import io.dcloud.feature.uniapp.ui.component.UniComponentProp; |
|
||||
|
|
||||
public class TestText extends UniComponent<TextView> { |
|
||||
|
|
||||
public TestText(UniSDKInstance instance, AbsVContainer parent, AbsComponentData basicComponentData) { |
|
||||
super(instance, parent, basicComponentData); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected TextView initComponentHostView(Context context) { |
|
||||
TextView textView = new TextView(context); |
|
||||
textView.setTextSize(20); |
|
||||
textView.setTextColor(Color.BLACK); |
|
||||
return textView; |
|
||||
} |
|
||||
|
|
||||
@UniComponentProp(name = "tel") |
|
||||
public void setTel(String telNumber) { |
|
||||
getHostView().setText("tel: " + telNumber); |
|
||||
Map<String, Object> params = new HashMap<>(); |
|
||||
Map<String, Object> number = new HashMap<>(); |
|
||||
number.put("tel", telNumber); |
|
||||
//目前uni限制 参数需要放入到"detail"中 否则会被清理
|
|
||||
params.put("detail", number); |
|
||||
fireEvent("onTel", params); |
|
||||
} |
|
||||
|
|
||||
@UniJSMethod |
|
||||
public void clearTel() { |
|
||||
getHostView().setText(""); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void onActivityResume() { |
|
||||
super.onActivityResume(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void onActivityPause() { |
|
||||
super.onActivityPause(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void onActivityDestroy() { |
|
||||
super.onActivityDestroy(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,3 +0,0 @@ |
|||||
<resources> |
|
||||
<string name="app_name">uniplugin_richAlert</string> |
|
||||
</resources> |
|
||||
@ -1 +0,0 @@ |
|||||
/build |
|
||||
@ -1,45 +0,0 @@ |
|||||
apply plugin: 'com.android.library' |
|
||||
|
|
||||
android { |
|
||||
compileSdkVersion 29 |
|
||||
defaultConfig { |
|
||||
minSdkVersion 16 |
|
||||
targetSdkVersion 28 |
|
||||
versionCode 1 |
|
||||
versionName "1.0" |
|
||||
|
|
||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' |
|
||||
|
|
||||
} |
|
||||
|
|
||||
buildTypes { |
|
||||
release { |
|
||||
minifyEnabled false |
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
repositories { |
|
||||
flatDir { |
|
||||
dirs 'libs' |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
dependencies { |
|
||||
compileOnly fileTree(dir: 'libs', include: ['*.jar']) |
|
||||
|
|
||||
compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar']) |
|
||||
|
|
||||
compileOnly 'androidx.recyclerview:recyclerview:1.0.0' |
|
||||
compileOnly 'androidx.legacy:legacy-support-v4:1.0.0' |
|
||||
compileOnly 'androidx.appcompat:appcompat:1.0.0' |
|
||||
implementation 'com.alibaba:fastjson:1.2.83' |
|
||||
implementation 'com.facebook.fresco:fresco:1.13.0' |
|
||||
|
|
||||
/*implementation 'com.android.support:appcompat-v7:28.0.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'*/ |
|
||||
} |
|
||||
@ -1,21 +0,0 @@ |
|||||
# 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 |
|
||||
@ -1,7 +0,0 @@ |
|||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||
package="uni.dcloud.io.uniplugin_module" > |
|
||||
<application> |
|
||||
<activity android:name="io.dcloud.uniplugin.NativePageActivity" |
|
||||
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"></activity> |
|
||||
</application> |
|
||||
</manifest> |
|
||||
@ -1,33 +0,0 @@ |
|||||
package io.dcloud.uniplugin; |
|
||||
|
|
||||
import android.app.Activity; |
|
||||
import android.content.Intent; |
|
||||
import android.graphics.Color; |
|
||||
import android.os.Bundle; |
|
||||
import android.view.View; |
|
||||
import android.view.ViewGroup; |
|
||||
import android.widget.FrameLayout; |
|
||||
import android.widget.TextView; |
|
||||
|
|
||||
public class NativePageActivity extends Activity { |
|
||||
@Override |
|
||||
protected void onCreate(Bundle savedInstanceState) { |
|
||||
super.onCreate(savedInstanceState); |
|
||||
FrameLayout rootView = new FrameLayout(this); |
|
||||
TextView textView = new TextView(this); |
|
||||
textView.setTextColor(Color.BLACK); |
|
||||
textView.setTextSize(30); |
|
||||
textView.setText("点击我将返回 并携带参数返回"); |
|
||||
rootView.addView(textView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300)); |
|
||||
textView.setOnClickListener(new View.OnClickListener() { |
|
||||
@Override |
|
||||
public void onClick(View v) { |
|
||||
Intent intent = new Intent(); |
|
||||
intent.putExtra("respond", "我是原生页面"); |
|
||||
setResult(TestModule.REQUEST_CODE, intent); |
|
||||
finish(); |
|
||||
} |
|
||||
}); |
|
||||
setContentView(rootView); |
|
||||
} |
|
||||
} |
|
||||
@ -1,55 +0,0 @@ |
|||||
package io.dcloud.uniplugin; |
|
||||
|
|
||||
import android.app.Activity; |
|
||||
import android.content.Intent; |
|
||||
import android.util.Log; |
|
||||
|
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
|
|
||||
import io.dcloud.feature.uniapp.annotation.UniJSMethod; |
|
||||
import io.dcloud.feature.uniapp.bridge.UniJSCallback; |
|
||||
import io.dcloud.feature.uniapp.common.UniModule; |
|
||||
|
|
||||
|
|
||||
public class TestModule extends UniModule { |
|
||||
|
|
||||
String TAG = "TestModule"; |
|
||||
public static int REQUEST_CODE = 1000; |
|
||||
|
|
||||
//run ui thread
|
|
||||
@UniJSMethod(uiThread = true) |
|
||||
public void testAsyncFunc(JSONObject options, UniJSCallback callback) { |
|
||||
Log.e(TAG, "testAsyncFunc--"+options); |
|
||||
if(callback != null) { |
|
||||
JSONObject data = new JSONObject(); |
|
||||
data.put("code", "success"); |
|
||||
callback.invoke(data); |
|
||||
//callback.invokeAndKeepAlive(data);
|
|
||||
} |
|
||||
} |
|
||||
|
|
||||
//run JS thread
|
|
||||
@UniJSMethod (uiThread = false) |
|
||||
public JSONObject testSyncFunc(){ |
|
||||
JSONObject data = new JSONObject(); |
|
||||
data.put("code", "success"); |
|
||||
return data; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
|
||||
if(requestCode == REQUEST_CODE && data.hasExtra("respond")) { |
|
||||
Log.e("TestModule", "原生页面返回----"+data.getStringExtra("respond")); |
|
||||
} else { |
|
||||
super.onActivityResult(requestCode, resultCode, data); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
@UniJSMethod (uiThread = true) |
|
||||
public void gotoNativePage(){ |
|
||||
if(mUniSDKInstance != null && mUniSDKInstance.getContext() instanceof Activity) { |
|
||||
Intent intent = new Intent(mUniSDKInstance.getContext(), NativePageActivity.class); |
|
||||
((Activity)mUniSDKInstance.getContext()).startActivityForResult(intent, REQUEST_CODE); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,3 +0,0 @@ |
|||||
<resources> |
|
||||
<string name="app_name">uniplugin_richAlert</string> |
|
||||
</resources> |
|
||||
@ -1 +0,0 @@ |
|||||
/build |
|
||||
@ -1,41 +0,0 @@ |
|||||
apply plugin: 'com.android.library' |
|
||||
|
|
||||
android { |
|
||||
compileSdkVersion 29 |
|
||||
defaultConfig { |
|
||||
minSdkVersion 16 |
|
||||
targetSdkVersion 28 |
|
||||
versionCode 1 |
|
||||
versionName "1.0" |
|
||||
|
|
||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' |
|
||||
|
|
||||
} |
|
||||
|
|
||||
buildTypes { |
|
||||
release { |
|
||||
minifyEnabled false |
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
repositories { |
|
||||
flatDir { |
|
||||
dirs 'libs' |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
dependencies { |
|
||||
compileOnly fileTree(dir: 'libs', include: ['*.jar']) |
|
||||
|
|
||||
compileOnly 'androidx.recyclerview:recyclerview:1.0.0' |
|
||||
compileOnly 'androidx.legacy:legacy-support-v4:1.0.0' |
|
||||
compileOnly 'androidx.appcompat:appcompat:1.0.0' |
|
||||
compileOnly 'com.alibaba:fastjson:1.2.83' |
|
||||
|
|
||||
compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar']) |
|
||||
|
|
||||
compileOnly 'com.alibaba:fastjson:1.1.46.android' |
|
||||
} |
|
||||
@ -1,21 +0,0 @@ |
|||||
# 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 |
|
||||
@ -1,26 +0,0 @@ |
|||||
package uni.dcloud.io.uniplugin_richalert; |
|
||||
|
|
||||
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("uni.dcloud.io.uniplugin_richalert.test", appContext.getPackageName()); |
|
||||
} |
|
||||
} |
|
||||
@ -1,2 +0,0 @@ |
|||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||
package="uni.dcloud.io.uniplugin_richalert" /> |
|
||||
@ -1,9 +0,0 @@ |
|||||
package uni.dcloud.io.uniplugin_richalert.Info; |
|
||||
|
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
|
|
||||
public class Person { |
|
||||
public String label; |
|
||||
public String content; |
|
||||
public JSONObject attribute; |
|
||||
} |
|
||||
@ -1,97 +0,0 @@ |
|||||
package uni.dcloud.io.uniplugin_richalert.Info; |
|
||||
|
|
||||
import android.text.TextUtils; |
|
||||
|
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
|
|
||||
import org.xml.sax.Attributes; |
|
||||
import org.xml.sax.SAXException; |
|
||||
import org.xml.sax.helpers.DefaultHandler; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
|
|
||||
|
|
||||
public class SaxHelper extends DefaultHandler { |
|
||||
private Person person; |
|
||||
private ArrayList<Person> persons; |
|
||||
//当前解析的元素标签
|
|
||||
private String tagName = null; |
|
||||
|
|
||||
/** |
|
||||
* 当读取到文档开始标志是触发,通常在这里完成一些初始化操作 |
|
||||
*/ |
|
||||
@Override |
|
||||
public void startDocument() throws SAXException { |
|
||||
this.persons = new ArrayList<Person>(); |
|
||||
//Log.i("SAX", "读取到文档头,开始解析xml");
|
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 读到一个开始标签时调用,第二个参数为标签名,最后一个参数为属性数组 |
|
||||
*/ |
|
||||
@Override |
|
||||
public void startElement(String uri, String localName, String qName, |
|
||||
Attributes attributes) throws SAXException { |
|
||||
this.person = new Person(); |
|
||||
this.persons.add(this.person); |
|
||||
person.label = localName; |
|
||||
if(attributes != null && attributes.getLength() > 0) { |
|
||||
JSONObject attr = new JSONObject(); |
|
||||
for(int i=0;i<attributes.getLength();i++) { |
|
||||
attr.put(attributes.getLocalName(i), attributes.getValue(i)); |
|
||||
} |
|
||||
person.attribute = attr; |
|
||||
} |
|
||||
this.tagName = localName; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 读到到内容,第一个参数为字符串内容,后面依次为起始位置与长度 |
|
||||
*/ |
|
||||
@Override |
|
||||
public void characters(char[] ch, int start, int length) throws SAXException { |
|
||||
//判断当前标签是否有效
|
|
||||
String data = new String(ch, start, length); |
|
||||
if (this.tagName != null) { |
|
||||
if(TextUtils.isEmpty(this.person.content)) { |
|
||||
this.person.content = data; |
|
||||
} else { |
|
||||
this.person.content = this.person.content + data; |
|
||||
} |
|
||||
} else { |
|
||||
//补充遗漏text
|
|
||||
this.person = new Person(); |
|
||||
this.persons.add(this.person); |
|
||||
person.label = "text"; |
|
||||
person.content = data; |
|
||||
person = null; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 处理元素结束时触发,这里将对象添加到结合中 |
|
||||
*/ |
|
||||
@Override |
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException { |
|
||||
this.person = null; |
|
||||
//Log.i("SAX", "处理person元素结束~");
|
|
||||
this.tagName = null; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 读取到文档结尾时触发, |
|
||||
*/ |
|
||||
@Override |
|
||||
public void endDocument() throws SAXException { |
|
||||
super.endDocument(); |
|
||||
//Log.i("SAX", "读取到文档尾,xml解析结束");
|
|
||||
} |
|
||||
|
|
||||
//获取persons集合
|
|
||||
public ArrayList<Person> getPersons() { |
|
||||
return persons; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,391 +0,0 @@ |
|||||
package uni.dcloud.io.uniplugin_richalert; |
|
||||
|
|
||||
import android.app.AlertDialog; |
|
||||
import android.content.Context; |
|
||||
import android.content.DialogInterface; |
|
||||
import android.graphics.Color; |
|
||||
import androidx.annotation.NonNull; |
|
||||
import android.text.SpannableStringBuilder; |
|
||||
import android.text.Spanned; |
|
||||
import android.text.TextUtils; |
|
||||
import android.text.method.LinkMovementMethod; |
|
||||
import android.text.style.ClickableSpan; |
|
||||
import android.text.style.ForegroundColorSpan; |
|
||||
import android.util.TypedValue; |
|
||||
import android.view.Gravity; |
|
||||
import android.view.View; |
|
||||
import android.view.ViewGroup; |
|
||||
import android.view.Window; |
|
||||
import android.widget.Button; |
|
||||
import android.widget.CheckBox; |
|
||||
import android.widget.CompoundButton; |
|
||||
import android.widget.LinearLayout; |
|
||||
import android.widget.ScrollView; |
|
||||
import android.widget.TextView; |
|
||||
|
|
||||
import com.alibaba.fastjson.JSONArray; |
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
|
|
||||
import java.io.ByteArrayInputStream; |
|
||||
import java.io.InputStream; |
|
||||
import java.util.ArrayList; |
|
||||
|
|
||||
import javax.xml.parsers.SAXParser; |
|
||||
import javax.xml.parsers.SAXParserFactory; |
|
||||
|
|
||||
import io.dcloud.feature.uniapp.bridge.UniJSCallback; |
|
||||
import io.dcloud.feature.uniapp.utils.UniResourceUtils; |
|
||||
import uni.dcloud.io.uniplugin_richalert.Info.Person; |
|
||||
import uni.dcloud.io.uniplugin_richalert.Info.SaxHelper; |
|
||||
|
|
||||
|
|
||||
public class RichAlert { |
|
||||
|
|
||||
public static String TITLE = "title"; |
|
||||
public static String TITLE_COLOR = "titleColor"; |
|
||||
|
|
||||
int mPositiveColor = Color.BLACK; |
|
||||
int mNegativeColor = Color.BLACK; |
|
||||
int mNeutralColor = Color.BLACK; |
|
||||
int mPosition = Gravity.CENTER; |
|
||||
Context mContext; |
|
||||
LinearLayout mContentViewRootView; |
|
||||
CheckBox mCheckBox; |
|
||||
TextView mMessageView; |
|
||||
TextView mTitleView; |
|
||||
AlertDialog mAlertDialog; |
|
||||
AlertDialog.Builder mBuilder; |
|
||||
|
|
||||
String SELECTED = "isSelected"; |
|
||||
|
|
||||
public RichAlert(@NonNull Context context) { |
|
||||
mContext = context; |
|
||||
mBuilder = new AlertDialog.Builder(context); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 显示弹窗 |
|
||||
*/ |
|
||||
public void show() { |
|
||||
mAlertDialog = mBuilder.create(); |
|
||||
if(mContentViewRootView != null) { |
|
||||
mAlertDialog.setView(mContentViewRootView); |
|
||||
if(mCheckBox != null) { |
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); |
|
||||
layoutParams.leftMargin = dip2px(mContext, 11); |
|
||||
mContentViewRootView.addView(mCheckBox, layoutParams); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
mAlertDialog.setCanceledOnTouchOutside(false); |
|
||||
mAlertDialog.show(); |
|
||||
|
|
||||
setButtonColor(AlertDialog.BUTTON_POSITIVE, mPositiveColor); |
|
||||
setButtonColor(AlertDialog.BUTTON_NEGATIVE, mNegativeColor); |
|
||||
setButtonColor(AlertDialog.BUTTON_NEUTRAL, mNeutralColor); |
|
||||
|
|
||||
Window dialogWindow = mAlertDialog.getWindow();//获取window对象
|
|
||||
dialogWindow.setGravity(mPosition); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置弹窗标题 |
|
||||
* @param title |
|
||||
* @param Color |
|
||||
* @return |
|
||||
*/ |
|
||||
public RichAlert setTitle(CharSequence title, int Color, String align) { |
|
||||
// mBuilder.setTitle(title);
|
|
||||
initContentView(mContext); |
|
||||
if(mTitleView != null) { |
|
||||
mTitleView.setVisibility(View.VISIBLE); |
|
||||
mTitleView.setText(title); |
|
||||
mTitleView.setTextColor(Color); |
|
||||
mTitleView.setGravity(getAlign(align) | Gravity.CENTER_VERTICAL); |
|
||||
} |
|
||||
return this; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置弹窗主显示内容 |
|
||||
* @param content |
|
||||
* @param Color |
|
||||
* @param jsCallback |
|
||||
* @return |
|
||||
*/ |
|
||||
public RichAlert setContent(String content, int Color, String align, UniJSCallback jsCallback) { |
|
||||
try { |
|
||||
initContentView(mContext); |
|
||||
ArrayList<Person> data = readxmlForDom(content); |
|
||||
if(data != null && data.size() > 0) { |
|
||||
CharSequence ct = getContentCharSequence(data, jsCallback); |
|
||||
mMessageView.setText(ct); |
|
||||
} else { |
|
||||
mMessageView.setText(content); |
|
||||
} |
|
||||
mMessageView.setTextColor(Color); |
|
||||
mMessageView.setGravity(getAlign(align)); |
|
||||
|
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
return this; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 生成自定义内容布局 |
|
||||
* 此处使用代码编写的布局,也可以使用XML布局方式加载 |
|
||||
* @param context |
|
||||
*/ |
|
||||
private void initContentView(Context context) { |
|
||||
if(mContentViewRootView == null && context != null) { |
|
||||
mContentViewRootView = new LinearLayout(context); |
|
||||
mContentViewRootView.setOrientation(LinearLayout.VERTICAL); |
|
||||
LinearLayout titleLayout = new LinearLayout(context); |
|
||||
mTitleView = new TextView(context); |
|
||||
mTitleView.setGravity(Gravity.CENTER); |
|
||||
mTitleView.setPadding(dip2px(mContext, 16), 0, dip2px(mContext, 16), 0); |
|
||||
mTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17); |
|
||||
LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dip2px(mContext, 45)); |
|
||||
titleLayout.addView(mTitleView, titleParams); |
|
||||
mTitleView.setVisibility(View.GONE); |
|
||||
mContentViewRootView.addView(titleLayout, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); |
|
||||
ScrollView scrollView = new ScrollView(context); |
|
||||
mMessageView = new TextView(context); |
|
||||
ScrollView.LayoutParams params = new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); |
|
||||
params.topMargin = dip2px(context, 25); |
|
||||
params.bottomMargin = dip2px(context, 25); |
|
||||
params.leftMargin = dip2px(context, 16); |
|
||||
params.rightMargin = dip2px(context, 16); |
|
||||
mContentViewRootView.addView(scrollView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1)); |
|
||||
scrollView.addView(mMessageView, params); |
|
||||
mMessageView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); |
|
||||
mMessageView.setMovementMethod(LinkMovementMethod.getInstance()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置弹窗按钮 |
|
||||
* @param buttons |
|
||||
* @param jsCallback |
|
||||
* @return |
|
||||
*/ |
|
||||
public RichAlert setButtons(JSONArray buttons, final UniJSCallback jsCallback) { |
|
||||
if(buttons != null && buttons.size() > 0) { |
|
||||
for(int i = 0; i < buttons.size();i++) { |
|
||||
JSONObject button = buttons.getJSONObject(i); |
|
||||
String title = button.getString(TITLE); |
|
||||
int color = UniResourceUtils.getColor(button.getString(TITLE_COLOR), RichAlertModule.defColor); |
|
||||
if(TextUtils.isEmpty(title)) { |
|
||||
continue; |
|
||||
} |
|
||||
if(i > 2) { //buttons 最多支持三个button
|
|
||||
return this; |
|
||||
} |
|
||||
final int index = i; |
|
||||
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { |
|
||||
@Override |
|
||||
public void onClick(DialogInterface dialogInterface, int n) { |
|
||||
JSONObject result = new JSONObject(); |
|
||||
result.put("type", "button"); |
|
||||
result.put("index", index); |
|
||||
jsCallback.invoke(result); |
|
||||
} |
|
||||
}; |
|
||||
switch(i) { |
|
||||
case 0: { |
|
||||
mBuilder.setNegativeButton(title, listener); |
|
||||
mNegativeColor = color; |
|
||||
break; |
|
||||
} |
|
||||
case 1: { |
|
||||
mBuilder.setNeutralButton(title, listener); |
|
||||
mNeutralColor = color; |
|
||||
break; |
|
||||
} |
|
||||
case 2: { |
|
||||
mBuilder.setPositiveButton(title, listener); |
|
||||
mPositiveColor = color; |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return this; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 设置按钮文字颜色 |
|
||||
* 需要在show操作之后调用 |
|
||||
* @param type |
|
||||
* @param color |
|
||||
*/ |
|
||||
private void setButtonColor(int type, int color) { |
|
||||
if(mAlertDialog != null) { |
|
||||
Button button = mAlertDialog.getButton(type); |
|
||||
if(button != null) { |
|
||||
button.setTextColor(color); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 提示框位置 |
|
||||
* @param position |
|
||||
* @return |
|
||||
*/ |
|
||||
public RichAlert setPosition(String position) { |
|
||||
mPosition = getAlign(position); |
|
||||
return this; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置复选框提示 |
|
||||
* @param checkBox |
|
||||
* @param jsCallback |
|
||||
* @return |
|
||||
*/ |
|
||||
public RichAlert setCheckBox(JSONObject checkBox, final UniJSCallback jsCallback) { |
|
||||
if(checkBox == null) { |
|
||||
return this; |
|
||||
} |
|
||||
mCheckBox = new CheckBox(mContext); |
|
||||
|
|
||||
mCheckBox.setText(checkBox.getString(TITLE)); |
|
||||
int color = UniResourceUtils.getColor(checkBox.getString(TITLE_COLOR), RichAlertModule.defColor); |
|
||||
mCheckBox.setTextColor(color); |
|
||||
boolean isSelected = false; |
|
||||
if(checkBox.containsKey(SELECTED)) { |
|
||||
isSelected = checkBox.getBoolean(SELECTED); |
|
||||
} |
|
||||
mCheckBox.setChecked(isSelected); |
|
||||
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
|
||||
@Override |
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
|
||||
JSONObject result = new JSONObject(); |
|
||||
result.put("type", "checkBox"); |
|
||||
result.put("isSelected", isChecked); |
|
||||
jsCallback.invokeAndKeepAlive(result); |
|
||||
} |
|
||||
}); |
|
||||
return this; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 将Person转换对应的Span |
|
||||
* @param data |
|
||||
* @param jsCallback |
|
||||
* @return |
|
||||
*/ |
|
||||
private CharSequence getContentCharSequence(ArrayList<Person> data, UniJSCallback jsCallback) { |
|
||||
SpannableStringBuilder spannableString = new SpannableStringBuilder(); |
|
||||
for(Person person : data) { |
|
||||
if(TextUtils.isEmpty(person.content)) { |
|
||||
continue; |
|
||||
} |
|
||||
if(person.label.equalsIgnoreCase("a")) { |
|
||||
setASpan(spannableString, person, jsCallback); |
|
||||
} else { |
|
||||
spannableString.append(person.content); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return spannableString; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置A标签指定的Span 包含点击事件 |
|
||||
* @param spannableString |
|
||||
* @param person |
|
||||
* @param jsCallback |
|
||||
*/ |
|
||||
private void setASpan(SpannableStringBuilder spannableString, final Person person, final UniJSCallback jsCallback) { |
|
||||
int start = spannableString.toString().length(); |
|
||||
spannableString.append(person.content); |
|
||||
int end = spannableString.toString().length(); |
|
||||
ClickableSpan clickableSpan = new ClickableSpan() { |
|
||||
|
|
||||
public void onClick(View view) { |
|
||||
//Do something with URL here.
|
|
||||
JSONObject result = new JSONObject(); |
|
||||
result.put("type", "a"); |
|
||||
result.putAll(person.attribute); |
|
||||
jsCallback.invokeAndKeepAlive(result); |
|
||||
} |
|
||||
}; |
|
||||
spannableString.setSpan(clickableSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
|
||||
ForegroundColorSpan foregroundColorSpan=new ForegroundColorSpan(Color.BLUE); |
|
||||
spannableString.setSpan(foregroundColorSpan,start,end,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 解析XML 获取person数组 |
|
||||
* @param content |
|
||||
* @return |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
private ArrayList<Person> readxmlForDom(String content) throws Exception { |
|
||||
content = "<RichP>" + content + "</RichP>"; |
|
||||
//获取文件资源建立输入流对象
|
|
||||
InputStream is = new ByteArrayInputStream(content.getBytes()); |
|
||||
//创建一个SAXParserFactory解析器工程
|
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance(); |
|
||||
SaxHelper helper = new SaxHelper(); |
|
||||
//③创建SAX解析器
|
|
||||
SAXParser parser = factory.newSAXParser(); |
|
||||
parser.parse(is, helper); |
|
||||
return helper.getPersons(); |
|
||||
} |
|
||||
|
|
||||
public boolean isShowing() { |
|
||||
return mAlertDialog == null ? false : mAlertDialog.isShowing(); |
|
||||
} |
|
||||
|
|
||||
public void dismiss() { |
|
||||
if(mAlertDialog != null) { |
|
||||
mAlertDialog.dismiss(); |
|
||||
mAlertDialog = null; |
|
||||
mContentViewRootView.removeAllViews(); |
|
||||
mContentViewRootView = null; |
|
||||
mMessageView = null; |
|
||||
mTitleView = null; |
|
||||
mCheckBox = null; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public void setOnDismissListener(DialogInterface.OnDismissListener listener) { |
|
||||
if(mAlertDialog != null) |
|
||||
mAlertDialog.setOnDismissListener(listener); |
|
||||
} |
|
||||
|
|
||||
public void setOnCancelListener(DialogInterface.OnCancelListener listener) { |
|
||||
if(mAlertDialog != null) |
|
||||
mAlertDialog.setOnCancelListener(listener); |
|
||||
} |
|
||||
|
|
||||
private int dip2px(Context context, float dipValue) { |
|
||||
float scale = context.getResources().getDisplayMetrics().density; |
|
||||
return (int) (dipValue * scale + 0.5f); |
|
||||
} |
|
||||
|
|
||||
private int getAlign(String alignString) { |
|
||||
int align = Gravity.CENTER; |
|
||||
if(!TextUtils.isEmpty(alignString)) { |
|
||||
switch (alignString) { |
|
||||
case "left": |
|
||||
align = Gravity.LEFT; |
|
||||
break; |
|
||||
case "right" : |
|
||||
align = Gravity.RIGHT; |
|
||||
break; |
|
||||
case "bottom": |
|
||||
align = Gravity.BOTTOM; |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
return align; |
|
||||
} |
|
||||
} |
|
||||
@ -1,100 +0,0 @@ |
|||||
package uni.dcloud.io.uniplugin_richalert; |
|
||||
|
|
||||
import android.app.Activity; |
|
||||
import android.content.DialogInterface; |
|
||||
import android.graphics.Color; |
|
||||
import android.text.TextUtils; |
|
||||
|
|
||||
import com.alibaba.fastjson.JSONArray; |
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
|
|
||||
import io.dcloud.feature.uniapp.annotation.UniJSMethod; |
|
||||
import io.dcloud.feature.uniapp.bridge.UniJSCallback; |
|
||||
import io.dcloud.feature.uniapp.common.UniDestroyableModule; |
|
||||
import io.dcloud.feature.uniapp.utils.UniLogUtils; |
|
||||
import io.dcloud.feature.uniapp.utils.UniResourceUtils; |
|
||||
|
|
||||
public class RichAlertModule extends UniDestroyableModule { |
|
||||
public String CONTENT = "content"; |
|
||||
public String CONTENT_COLOR = "contentColor"; |
|
||||
public String CONTENT_ALIGN = "contentAlign"; |
|
||||
public String POSITION = "position"; |
|
||||
public String BUTTONS = "buttons"; |
|
||||
public String CHECKBOX = "checkBox"; |
|
||||
public String TITLE_ALIGN = "titleAlign"; |
|
||||
//默认黑色
|
|
||||
public static int defColor = Color.BLACK; |
|
||||
|
|
||||
RichAlert alert; |
|
||||
|
|
||||
@UniJSMethod(uiThread = true) |
|
||||
public void show(JSONObject options, UniJSCallback jsCallback) { |
|
||||
if (mUniSDKInstance.getContext() instanceof Activity) { |
|
||||
String content = options.getString(CONTENT); |
|
||||
int contentColor = UniResourceUtils.getColor(options.getString(CONTENT_COLOR), defColor); |
|
||||
String contentAlign = options.getString(CONTENT_ALIGN); |
|
||||
|
|
||||
String title = options.getString(RichAlert.TITLE); |
|
||||
int titleColor = UniResourceUtils.getColor(options.getString(RichAlert.TITLE_COLOR), defColor); |
|
||||
String titleAlign = options.getString(TITLE_ALIGN); |
|
||||
|
|
||||
String postion = options.getString(POSITION); |
|
||||
|
|
||||
RichAlert richAlert = new RichAlert(mUniSDKInstance.getContext()); |
|
||||
|
|
||||
JSONArray buttons = options.getJSONArray(BUTTONS); |
|
||||
JSONObject checkBox = options.getJSONObject(CHECKBOX); |
|
||||
|
|
||||
if(!TextUtils.isEmpty(title)) { |
|
||||
richAlert.setTitle(title, titleColor, titleAlign); |
|
||||
} |
|
||||
if(!TextUtils.isEmpty(content)) { |
|
||||
richAlert.setContent(content, contentColor, contentAlign,jsCallback); |
|
||||
} |
|
||||
if(checkBox != null) { |
|
||||
richAlert.setCheckBox(checkBox, jsCallback); |
|
||||
} |
|
||||
if(buttons != null) { |
|
||||
richAlert.setButtons(buttons, jsCallback); |
|
||||
} |
|
||||
if(!TextUtils.isEmpty(postion)) { |
|
||||
richAlert.setPosition(postion); |
|
||||
} |
|
||||
|
|
||||
richAlert.show(); |
|
||||
tracking(richAlert, jsCallback); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void tracking(RichAlert dialog, final UniJSCallback jsCallback) { |
|
||||
alert = dialog; |
|
||||
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { |
|
||||
@Override |
|
||||
public void onCancel(DialogInterface dialog) { |
|
||||
JSONObject result = new JSONObject(); |
|
||||
result.put("type", "backCancel"); |
|
||||
jsCallback.invoke(result); |
|
||||
} |
|
||||
}); |
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
|
||||
@Override |
|
||||
public void onDismiss(DialogInterface dialog) { |
|
||||
alert = null; |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
@UniJSMethod(uiThread = true) |
|
||||
public void dismiss() { |
|
||||
destroy(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void destroy() { |
|
||||
if (alert != null && alert.isShowing()) { |
|
||||
UniLogUtils.w("Dismiss the active dialog"); |
|
||||
alert.dismiss(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
package uni.dcloud.io.uniplugin_richalert; |
|
||||
|
|
||||
import android.app.Application; |
|
||||
|
|
||||
import io.dcloud.feature.uniapp.UniAppHookProxy; |
|
||||
|
|
||||
|
|
||||
public class RichAlert_AppProxy implements UniAppHookProxy { |
|
||||
@Override |
|
||||
public void onCreate(Application application) { |
|
||||
//可写初始化触发逻辑
|
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void onSubProcessCreate(Application application) { |
|
||||
//子进程初始化回调
|
|
||||
} |
|
||||
} |
|
||||
@ -1,3 +0,0 @@ |
|||||
<resources> |
|
||||
<string name="app_name">uniplugin_richAlert</string> |
|
||||
</resources> |
|
||||
@ -1,17 +0,0 @@ |
|||||
package uni.dcloud.io.uniplugin_richalert; |
|
||||
|
|
||||
import org.junit.Test; |
|
||||
|
|
||||
import static org.junit.Assert.*; |
|
||||
|
|
||||
/** |
|
||||
* Example local unit test, which will execute on the development machine (host). |
|
||||
* |
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> |
|
||||
*/ |
|
||||
public class ExampleUnitTest { |
|
||||
@Test |
|
||||
public void addition_isCorrect() { |
|
||||
assertEquals(4, 2 + 2); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue