Commit 3f42a423 by 王涛55

feat:添加依赖

parent 7b94bd95
......@@ -9,6 +9,7 @@
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/app_common" />
<option value="$PROJECT_DIR$/app_login" />
<option value="$PROJECT_DIR$/app_passport" />
<option value="$PROJECT_DIR$/buildsrc" />
......
......@@ -11,7 +11,7 @@
tools:ignore="GoogleAppIndexingWarning,HardcodedDebugMode"
tools:replace="android:icon,android:roundIcon,android:theme,android:label,android:allowBackup">
<activity android:name="com.main.testActivity">
<activity android:name="com.passport.testActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
......
package com.main;
package com.passport;
import android.app.Activity;
import android.content.Intent;
......@@ -19,8 +19,13 @@ public class testActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_test);
findViewById(R.id.mBtnLogin).setOnClickListener(v -> {
Intent mIntent = new Intent(testActivity.this,testLoginActivity.class);
startActivity(mIntent);
// Intent mIntent = new Intent(testActivity.this,testLoginActivity.class);
// startActivity(mIntent);
});
findViewById(R.id.mBtnPassport).setOnClickListener(v -> {
// Intent mIntent = new Intent(testActivity.this,testLoginActivity.class);
// startActivity(mIntent);
});
// getFragmentManager().beginTransaction().add(R.id.test_passport,);
}
}
......@@ -19,11 +19,15 @@
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="去通行证模块"
android:text="给通行证模块发送信息"
android:layout_marginTop="10dp"
android:id="@+id/mBtnPassport"
/>
<FrameLayout
android:layout_width="match_parent"
android:id="@+id/test_passport"
android:layout_height="300dp"/>
......
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
minSdkVersion build_config.min_sdk
targetSdkVersion build_config.target_sdk
versionCode build_config.version_code
versionName build_config.version_name
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
# 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
package info.hook.com.app_common;
import android.content.Context;
import androidx.test.InstrumentationRegistry;
import androidx.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("info.hook.com.app_common.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.hook.com.app_common" />
<resources>
<string name="app_name">app_common</string>
</resources>
package info.hook.com.app_common;
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);
}
}
\ No newline at end of file
......@@ -53,7 +53,6 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
if (build_module == build_module_app) {
api project(':lib_app_common')
}
api project(':lib_app_common')
api project(':app_common')
}
......@@ -4,7 +4,7 @@
<application>
<activity
android:name="com.main.testLoginActivity"
android:name="com.passport.testLoginActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" />
......
......@@ -9,9 +9,10 @@
android:theme="@android:style/Theme.NoTitleBar"
android:icon="@mipmap/lg_ic_launcher"
android:label="@string/lg_app_name_test"
tools:ignore="GoogleAppIndexingWarning">
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:icon,android:roundIcon,android:theme,android:label,android:allowBackup">
<activity android:name="com.main.testLoginActivity">
<activity android:name="com.passport.testLoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
......
......@@ -29,4 +29,6 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api project(':lib_app_common')
api project(':app_common')
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.passport" />
xmlns:tools="http://schemas.android.com/tools"
package="com.app.passport">
<application>
</application>
</manifest>
\ No newline at end of file
package com.passport;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.app.passport.R;
/**
* 类说明
*
* @author wangtao55
* @date 2019/9/20
* @mail wangtao55@hikcreate.com
*/
public class TestFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//通过参数中的布局填充获取对应布局
View view =inflater.inflate(R.layout.passport_test_fragment,container,false);
return view;
}
@Override
public void onPause() {
super.onPause();
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.app.login">
<application
android:roundIcon="@mipmap/lg_ic_launcher"
android:allowBackup="false"
android:theme="@android:style/Theme.NoTitleBar"
android:icon="@mipmap/lg_ic_launcher"
android:label="@string/lg_app_name_test"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:icon,android:roundIcon,android:theme,android:label,android:allowBackup">
<activity android:name="com.passport.testLoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="20dp"
android:orientation="vertical"
android:background="@android:color/white"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我来自于哪里:"
android:id="@+id/tv_from"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="消息内容为"
android:layout_marginTop="10dp"
android:id="@+id/tv_message_info"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="name:"
android:layout_marginTop="10dp"
android:id="@+id/tv_value"
/>
</LinearLayout>
......@@ -3,6 +3,7 @@
buildscript {
apply from: 'config/app_module_config.gradle'
apply from: 'config/app_config.gradle'
apply from: 'config/build_config.gradle'
repositories {
google()
jcenter()
......
//build_config 配置
def build_config = [:]
//android
build_config.classpath_gradle = "com.android.tools.build:gradle:3.1.2"
build_config.min_sdk = 19
build_config.compile_sdk = 28
build_config.build_tool = "27.0.3"
build_config.target_sdk = 28
build_config.classpath_kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.41"
build_config.classpath_kotlin_extension = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.41"
//需要每次发版休息的版本信息
build_config.version_code = 162
build_config.version_name = "1.6.2"
ext.build_config = build_config
def versions = [:]
// Support library
versions.supportLibraryVersion = "28.0.0"
......
//build_config 配置
def build_config = [:]
//android
build_config.classpath_gradle = "com.android.tools.build:gradle:3.1.2"
build_config.min_sdk = 19
build_config.compile_sdk = 28
build_config.build_tool = "27.0.3"
build_config.target_sdk = 28
build_config.classpath_kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.41"
build_config.classpath_kotlin_extension = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.41"
//需要每次发版休息的版本信息
build_config.version_code = 162
build_config.version_name = "1.6.2"
ext.build_config = build_config
......@@ -33,4 +33,5 @@ dependencies {
implementation files('libs/ocr-sdk.jar')
implementation files('libs/license.jar')
implementation deps.appcompat
// implementation deps.retrofit2_converter_gson
}
......@@ -18,6 +18,7 @@ import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.baidu.idl.util.FileUtil;
import com.baidu.ocr.sdk.OCR;
import com.baidu.ocr.sdk.OnResultListener;
import com.baidu.ocr.sdk.exception.OCRError;
......@@ -26,7 +27,8 @@ import com.baidu.ocr.sdk.model.IDCardResult;
import com.baidu.ocr.ui.camera.CameraActivity;
import com.baidu.ocr.ui.camera.CameraNativeHelper;
import com.baidu.ocr.ui.camera.CameraView;
import com.hikcreate.library.util.FileUtil;
import com.hikcreate.baidutextdect.util.TextDecFileUtil;
import java.io.File;
......@@ -115,7 +117,7 @@ public class IDCardActivity extends AppCompatActivity {
public void onClick(View v) {
Intent intent = new Intent(IDCardActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
FileUtil.getImageCacheFilePath());
TextDecFileUtil.getImageCacheFilePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_FRONT);
startActivityForResult(intent, REQUEST_CODE_CAMERA);
}
......@@ -127,7 +129,7 @@ public class IDCardActivity extends AppCompatActivity {
public void onClick(View v) {
Intent intent = new Intent(IDCardActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
FileUtil.getImageCacheFilePath());
TextDecFileUtil.getImageCacheFilePath());
intent.putExtra(CameraActivity.KEY_NATIVE_ENABLE,
true);
// KEY_NATIVE_MANUAL设置了之后CameraActivity中不再自动初始化和释放模型
......@@ -146,7 +148,7 @@ public class IDCardActivity extends AppCompatActivity {
public void onClick(View v) {
Intent intent = new Intent(IDCardActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
FileUtil.getImageCacheFilePath());
TextDecFileUtil.getImageCacheFilePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_BACK);
startActivityForResult(intent, REQUEST_CODE_CAMERA);
}
......@@ -158,7 +160,7 @@ public class IDCardActivity extends AppCompatActivity {
public void onClick(View v) {
Intent intent = new Intent(IDCardActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
FileUtil.getImageCacheFilePath());
TextDecFileUtil.getImageCacheFilePath());
intent.putExtra(CameraActivity.KEY_NATIVE_ENABLE,
true);
// KEY_NATIVE_MANUAL设置了之后CameraActivity中不再自动初始化和释放模型
......@@ -215,7 +217,7 @@ public class IDCardActivity extends AppCompatActivity {
if (requestCode == REQUEST_CODE_CAMERA && resultCode == Activity.RESULT_OK) {
if (data != null) {
String contentType = data.getStringExtra(CameraActivity.KEY_CONTENT_TYPE);
String filePath = FileUtil.getImageCacheFilePath();
String filePath = TextDecFileUtil.getImageCacheFilePath();
if (!TextUtils.isEmpty(contentType)) {
if (CameraActivity.CONTENT_TYPE_ID_CARD_FRONT.equals(contentType)) {
recIDCard(IDCardParams.ID_CARD_SIDE_FRONT, filePath);
......
package com.hikcreate.baidutextdect;
import com.hikcreate.library.util.ClassTypeEntity;
import com.hikcreate.library.util.GenericsUtils;
import com.hikcreate.baidutextdect.util.TextDecClassTypeEntity;
import com.hikcreate.baidutextdect.util.TextDecGenericsUtils;
/**
* to do
......@@ -12,11 +13,11 @@ import com.hikcreate.library.util.GenericsUtils;
*/
public class TextDectCallbackAdapter<T> implements ITextDectManager.TextDectCallback<T> {
private Class<T> mClazzType;
private ClassTypeEntity mClassTypeEntity;
private TextDecClassTypeEntity mClassTypeEntity;
public TextDectCallbackAdapter(){
mClassTypeEntity = new ClassTypeEntity();
mClazzType = GenericsUtils.getSuperClassGenericType(getClass(), mClassTypeEntity);
mClassTypeEntity = new TextDecClassTypeEntity();
mClazzType = TextDecGenericsUtils.getSuperClassGenericType(getClass(), mClassTypeEntity);
}
public Class<T> getClazzType() {
......
......@@ -34,7 +34,7 @@ import com.baidu.ocr.ui.camera.OCRCameraLayout;
import com.baidu.ocr.ui.camera.PermissionCallback;
import com.baidu.ocr.ui.crop.CropView;
import com.baidu.ocr.ui.crop.FrameOverlayView;
import com.hikcreate.library.util.FileUtil;
import com.hikcreate.baidutextdect.util.TextDecFileUtil;
import java.io.File;
import java.io.FileOutputStream;
......@@ -100,7 +100,7 @@ public class TextDectCameraFragment extends Fragment {
* @return
*/
public static TextDectCameraFragment newIdCardFrontInstance(boolean useNative) {
return newIdCardInstance(FileUtil.getImageCacheFilePath(), useNative, useNative, TextDectEnum.ID_CARD_DETECT_FRONT);
return newIdCardInstance(TextDecFileUtil.getImageCacheFilePath(), useNative, useNative, TextDectEnum.ID_CARD_DETECT_FRONT);
}
/**
......@@ -110,7 +110,7 @@ public class TextDectCameraFragment extends Fragment {
* @return
*/
public static TextDectCameraFragment newIdCardBackInstance(boolean useNative) {
return newIdCardInstance(FileUtil.getImageCacheFilePath(), useNative, useNative, TextDectEnum.ID_CARD_DETECT_BACK);
return newIdCardInstance(TextDecFileUtil.getImageCacheFilePath(), useNative, useNative, TextDectEnum.ID_CARD_DETECT_BACK);
}
/**
......@@ -141,7 +141,7 @@ public class TextDectCameraFragment extends Fragment {
* @return
*/
public static TextDectCameraFragment newGeneralInstance(TextDectEnum textDectEnum) {
return newGeneralInstance(FileUtil.getImageCacheFilePath(), textDectEnum);
return newGeneralInstance(TextDecFileUtil.getImageCacheFilePath(), textDectEnum);
}
/**
......
......@@ -24,9 +24,9 @@ import com.hikcreate.baidutextdect.bean.DriveLicenseSub;
import com.hikcreate.baidutextdect.bean.IDCardEntity;
import com.hikcreate.baidutextdect.bean.LicenseConstant;
import com.hikcreate.baidutextdect.bean.VehicleLicenseMain;
import com.hikcreate.library.util.FileUtil;
import com.hikcreate.library.util.LogCat;
import com.hikcreate.library.util.Tools;
import com.hikcreate.baidutextdect.util.TextDecFileUtil;
import com.hikcreate.baidutextdect.util.TextDecTools;
import java.io.File;
import java.util.ArrayList;
......@@ -63,6 +63,8 @@ public class TextDectManager implements ITextDectManager {
}
public void initTextDect(Context context, List<TextDectEnum> textDectEnumList, TextDectInitCallback callback) {
TextDecFileUtil.initAppRootFilePath(context);
BaiDuTextAccessTokenHelper.initAccessTokenLicenseFile(context, new BaiDuTextAccessTokenHelper.ITextAccessTokenInitCallback() {
@Override
......@@ -79,7 +81,7 @@ public class TextDectManager implements ITextDectManager {
@Override
public void onTextTokenGetError(String message) {
LogCat.e(TAG, "init token error:" + message);
Log.e(TAG, "init token error:" + message);
if (callback != null) {
callback.onInitError("网络跑偏了,请重试");
}
......@@ -106,7 +108,7 @@ public class TextDectManager implements ITextDectManager {
case ID_CARD_DETECT_FRONT:
intent = new Intent(mActivity, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
FileUtil.getImageCacheFilePath());
TextDecFileUtil.getImageCacheFilePath());
intent.putExtra(CameraActivity.KEY_NATIVE_ENABLE,
true);
intent.putExtra(CameraActivity.KEY_CONTENT_TITLE, title);
......@@ -121,7 +123,7 @@ public class TextDectManager implements ITextDectManager {
case ID_CARD_DETECT_BACK:
intent = new Intent(mActivity, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
FileUtil.getImageCacheFilePath());
TextDecFileUtil.getImageCacheFilePath());
intent.putExtra(CameraActivity.KEY_NATIVE_ENABLE,
true);
intent.putExtra(CameraActivity.KEY_CONTENT_TITLE, title);
......@@ -139,7 +141,7 @@ public class TextDectManager implements ITextDectManager {
case VEHICLE_LICENSE_DETECT_SUB:
intent = new Intent(mActivity, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
FileUtil.getImageCacheFilePath());
TextDecFileUtil.getImageCacheFilePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE,
CameraActivity.CONTENT_TYPE_GENERAL);
intent.putExtra(CameraActivity.KEY_CONTENT_TITLE, title);
......@@ -154,7 +156,7 @@ public class TextDectManager implements ITextDectManager {
case ID_CARD_DETECT_FRONT:
case ID_CARD_DETECT_BACK:
String contentType = data != null ? data.getStringExtra(CameraActivity.KEY_CONTENT_TYPE) : CameraActivity.CONTENT_TYPE_ID_CARD_FRONT;
String filePath = FileUtil.getImageCacheFilePath();
String filePath = TextDecFileUtil.getImageCacheFilePath();
if (!TextUtils.isEmpty(contentType)) {
if (CameraActivity.CONTENT_TYPE_ID_CARD_FRONT.equals(contentType)) {
recIDCardFront(filePath, callback);
......@@ -164,7 +166,7 @@ public class TextDectManager implements ITextDectManager {
}
break;
case DRIVING_LICENSE_DETECT_SUN:
RecognizeService.recDriveSub(mActivity, DriveLicenseSubSin, FileUtil.getImageCacheFilePath(),
RecognizeService.recDriveSub(mActivity, DriveLicenseSubSin, TextDecFileUtil.getImageCacheFilePath(),
result -> {
if (callback.getClazzType().isAssignableFrom(DriveLicenseSub.class)) {
callback.onResult(recDriveLicenseSub(result));
......@@ -174,7 +176,7 @@ public class TextDectManager implements ITextDectManager {
});
break;
case DRIVING_LICENSE_DETECT_MAIN:
RecognizeService.recDrivingLicense(mActivity, FileUtil.getImageCacheFilePath(),
RecognizeService.recDrivingLicense(mActivity, TextDecFileUtil.getImageCacheFilePath(),
result -> {
if (callback.getClazzType().isAssignableFrom(DriveLicenseMain.class)) {
callback.onResult(recDriveLicenseMain(result));
......@@ -184,7 +186,7 @@ public class TextDectManager implements ITextDectManager {
});
break;
case VEHICLE_LICENSE_DETECT_MAIN:
RecognizeService.recVehicleLicense(mActivity, FileUtil.getImageCacheFilePath(),
RecognizeService.recVehicleLicense(mActivity, TextDecFileUtil.getImageCacheFilePath(),
result -> {
if (callback.getClazzType().isAssignableFrom(VehicleLicenseMain.class)) {
callback.onResult(recVehicleLicenseMain(result));
......@@ -241,7 +243,7 @@ public class TextDectManager implements ITextDectManager {
}
public void recIDCardFront(TextDectCallbackAdapter callback) {
recIDCardFront(FileUtil.getImageCacheFilePath(), callback);
recIDCardFront(TextDecFileUtil.getImageCacheFilePath(), callback);
}
public void recIDCardFront(String filePath, TextDectCallbackAdapter callback) {
......@@ -249,7 +251,7 @@ public class TextDectManager implements ITextDectManager {
}
public void recIDCardBack(TextDectCallbackAdapter callback) {
recIDCardBack(FileUtil.getImageCacheFilePath(), callback);
recIDCardBack(TextDecFileUtil.getImageCacheFilePath(), callback);
}
public void recIDCardBack(String filePath, TextDectCallbackAdapter callback) {
......@@ -305,7 +307,7 @@ public class TextDectManager implements ITextDectManager {
}
public DriveLicenseSub recDriveLicenseSub(String result) {
if (Tools.isJsonForGsonValid(result)) {
if (TextDecTools.isJsonForGsonValid(result)) {
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(result).getAsJsonObject();
JsonObject dataJO = jsonObject.get("data").getAsJsonObject();
......@@ -335,7 +337,7 @@ public class TextDectManager implements ITextDectManager {
}
public DriveLicenseMain recDriveLicenseMain(String result) {
if (Tools.isJsonForGsonValid(result)) {
if (TextDecTools.isJsonForGsonValid(result)) {
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(result).getAsJsonObject();
if (jsonObject != null && jsonObject.has("words_result")) {
......@@ -359,7 +361,7 @@ public class TextDectManager implements ITextDectManager {
}
public VehicleLicenseMain recVehicleLicenseMain(String result) {
if (Tools.isJsonForGsonValid(result)) {
if (TextDecTools.isJsonForGsonValid(result)) {
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(result).getAsJsonObject();
if (jsonObject != null && jsonObject.has("words_result")) {
......
package com.hikcreate.baidutextdect.bean;
import com.hikcreate.baidutextdect.TextDectEnum;
import com.hikcreate.library.util.FileUtil;
import com.hikcreate.baidutextdect.util.TextDecFileUtil;
import java.io.Serializable;
......@@ -22,7 +22,7 @@ public class TextScanResult implements Serializable {
private VehicleLicenseMain mVehicleLicenseMain;
public TextScanResult(TextDectEnum type) {
mImagePath = FileUtil.getImageCacheFilePath();
mImagePath = TextDecFileUtil.getImageCacheFilePath();
mType = type;
}
......
package com.hikcreate.baidutextdect.util;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
/**
* @author yslei
* @data 2019/3/8
* @email leiyongsheng@hikcreate.com
*/
public class TextDecClassTypeEntity {
private List<Type> classType;
private TextDecClassTypeEntity childTypeEntity;
public List<Type> getClassType() {
return classType;
}
public void setClassType(List<Type> classType) {
this.classType = classType;
}
public void addClassTyep(Type type){
if(classType == null){
classType = new ArrayList<>();
}
classType.add(type);
}
public TextDecClassTypeEntity getChildTypeEntity() {
return childTypeEntity;
}
public void setChildTypeEntity(TextDecClassTypeEntity childTypeEntity) {
this.childTypeEntity = childTypeEntity;
}
@Override
public boolean equals(Object obj) {
TextDecClassTypeEntity entity = (TextDecClassTypeEntity) obj;
return super.equals(obj);
}
@Override
public String toString() {
return "ClassTypeEntity{" +
"classType=" + classType +
", childTypeEntity=" + childTypeEntity +
'}';
}
}
package com.hikcreate.baidutextdect.util;
import android.content.Context;
import android.content.res.AssetManager;
import android.os.Environment;
import android.text.TextUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by fujiayi on 2017/5/19.
*/
public class TextDecFileUtil {
private static final String sAudioDir = "baiduTTS";
public static String IMAGE_CACHE ;//图片缓存路径
public static final String APP_ROOT_FILE = "/hikcreate/";//app文件根路径
// 创建一个临时目录,用于复制临时文件,如assets目录下的离线资源文件
public static String createTmpDir(Context context) {
String tmpDir = Environment.getExternalStorageDirectory().toString() + "/" + sAudioDir;
if (!TextDecFileUtil.makeDir(tmpDir)) {
tmpDir = context.getExternalFilesDir(sAudioDir).getAbsolutePath();
if (!TextDecFileUtil.makeDir(sAudioDir)) {
throw new RuntimeException("create model resources dir failed :" + tmpDir);
}
}
return tmpDir;
}
public static boolean fileCanRead(String filename) {
File f = new File(filename);
return f.canRead();
}
public static boolean makeDir(String dirPath) {
File file = new File(dirPath);
if (!file.exists()) {
return file.mkdirs();
} else {
return true;
}
}
public static void copyFromAssets(AssetManager assets, String source, String dest, boolean isCover)
throws IOException {
File file = new File(dest);
if (isCover || (!isCover && !file.exists())) {
InputStream is = null;
FileOutputStream fos = null;
try {
is = assets.open(source);
String path = dest;
fos = new FileOutputStream(path);
byte[] buffer = new byte[1024];
int size = 0;
while ((size = is.read(buffer, 0, 1024)) >= 0) {
fos.write(buffer, 0, size);
}
} finally {
if (fos != null) {
try {
fos.close();
} finally {
if (is != null) {
is.close();
}
}
}
}
}
}
/**
* 创建目录
*
* @param path 目录路径
*/
public static void createDirFile(String path) {
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}
}
public static String getImageCacheFilePath() {
return getImageCacheFilePath("pic.jpg");
}
public static String getImageCacheFilePath(String fileName) {
createDirFile(TextDecFileUtil.getImgCachePath());
return TextDecFileUtil.getImgCachePath() + File.separator + fileName;
}
public static String getImgCachePath() {
return getImagePath();
}
private static String getImagePath(){
if(TextUtils.isEmpty(IMAGE_CACHE)){
}
return IMAGE_CACHE;
}
/**
* 初始化App根路径
*/
public static void initAppRootFilePath(Context mContext) {
try {
String appRootFilePath;
if (Environment.MEDIA_MOUNTED.equalsIgnoreCase(Environment.getExternalStorageState())) {
appRootFilePath = Environment.getExternalStorageDirectory().toString() + APP_ROOT_FILE;
} else {
appRootFilePath = mContext.getCacheDir().getAbsolutePath() + APP_ROOT_FILE;
}
initCachePath(appRootFilePath);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void initCachePath(String appRootFilePath) {
IMAGE_CACHE = appRootFilePath + APP_ROOT_FILE + "/cache/image/";
createDirFile(IMAGE_CACHE + ".nomedia");
}
}
package com.hikcreate.baidutextdect.util;
import android.util.Log;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
/**
* @author yslei
* @data 2019/3/8
* @email leiyongsheng@hikcreate.com
*/
public class TextDecGenericsUtils {
private static final String TAG = "GenericsUtils";
/**
* 通过反射,获得定义Class时声明的父类的范型参数的类型.
* 如public BookManager extends GenricManager<Book>
*
* @param clazz The class to introspect
* @return the first generic declaration, or <code>Object.class</code> if cannot be determined
*/
public static Class getSuperClassGenericType(Class clazz, TextDecClassTypeEntity entity) {
return getSuperClassGenericType(clazz, entity, 0);
}
/**
* 通过反射,获得定义Class时声明的父类的范型参数的类型.
* 如public BookManager extends GenricManager<Book>
*
* @param clazz clazz The class to introspect
* @param index the Index of the generic ddeclaration,start from 0.
*/
public static Class getSuperClassGenericType(Class clazz, TextDecClassTypeEntity entity, int index) throws IndexOutOfBoundsException {
//返回表示此 Class 所表示的实体(类、接口、基本类型或 void)的直接超类的 Type,然后将其转换ParameterizedType。
Type genType = clazz.getGenericSuperclass();
if (!(genType instanceof ParameterizedType)) {
return Object.class;
}
if (entity == null) {
entity = new TextDecClassTypeEntity();
}
//返回表示此类型实际类型参数的 Type 对象的数组。[0]就是这个数组中第一个了。简而言之就是获得超类的泛型参数的实际类型。
Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
if (index >= params.length || index < 0) {
return Object.class;
}
if (!(params[index] instanceof Class)) {
Log.d(TAG, "getSuperClassGenricType type:" + params[index]);
if (params[index] instanceof ParameterizedType) {
createClassTypeEntity(entity, params[index]);
Log.d(TAG, "getSuperClassGenricType entity:" + entity);
return (Class) ((ParameterizedType) params[index]).getRawType();
}
entity.addClassTyep(Object.class);
return Object.class;
}
entity.addClassTyep(params[index]);
return (Class) params[index];
}
/**
* 创建类型实例,用于收纳复合类型
*
* @param entity
* @param type
*/
private static void createClassTypeEntity(TextDecClassTypeEntity entity, Type type) {
if (type instanceof ParameterizedType) {
if (List.class.isAssignableFrom((Class) ((ParameterizedType) type).getRawType())) {
entity.addClassTyep(List.class);
Type[] tparams = ((ParameterizedType) type).getActualTypeArguments();
if (tparams != null) {
for (Type ttparam : tparams) {
TextDecClassTypeEntity tentity = new TextDecClassTypeEntity();
entity.setChildTypeEntity(tentity);
tentity.addClassTyep(ttparam);
createClassTypeEntity(tentity, ttparam);
}
}
}
}
}
/**
* class类别比较
*
* @param obj class类型实例
* @param entity 类型entity
* @return
*/
public static boolean classTypeCompare(Object obj, TextDecClassTypeEntity entity) {
if (obj != null && entity != null) {
if (obj instanceof List) {
Log.d(TAG, "classTypeCompare obj is list:" + obj.getClass());
if (entity.getClassType() != null && entity.getClassType().size() == 1
&& List.class.isAssignableFrom((Class) (entity.getClassType().get(0)))) {
if (((List) obj).size() > 0) {
return classTypeCompare(((List) obj).get(0), entity.getChildTypeEntity());
}
}
} else {
Log.d(TAG, "classTypeCompare obj is object:" + obj.getClass());
if (entity.getClassType() != null && entity.getClassType().size() == 1
&& obj.getClass().isAssignableFrom((Class) (entity.getClassType().get(0)))) {
return true;
}
}
}
return false;
}
}
package com.hikcreate.baidutextdect.util;
import android.studio.plugins.GsonUtils;
import android.view.ViewTreeObserver;
import android.webkit.URLUtil;
import android.widget.TextView;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.hikcreate.library.plugin.netbase.scheduler.SchedulerProvider;
import java.io.File;
import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
/**
* 常用工具方法
*
* @author gongwei
* @date 2019/3/6
*/
public class TextDecTools {
/**
* 判断是否是本地的图片地址
*
* @param str
* @return
*/
public static boolean isLocalImageUrl(String str) {
if (str == null) {
return false;
}
File file = new File(str);
return file.exists();
}
/**
* 判断是否是网络图片地址(不带http前缀)
*
* @param str
* @return
*/
public static boolean isOnlineImageUrl(String str) {
if (str == null) {
return false;
}
File file = new File(str);
return !file.exists() && !URLUtil.isNetworkUrl(str);
}
/**
* TextView的文字是否是否超过行数
*
* @param textView
* @param maxLines
* @param callBack
*/
public static void isOverFlowed(final TextView textView, final int maxLines, final TextOverFlowedCallBack callBack) {
if (callBack == null) return;
textView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
//这个回调会调用多次,获取完行数记得注销监听
textView.getViewTreeObserver().removeOnPreDrawListener(this);
int lines = textView.getLineCount();
LogCat.e("xwm", textView.getText() + "--" + lines);
if (lines > maxLines) {
callBack.overFlowed(true);
} else {
callBack.overFlowed(false);
}
return true;
}
});
// ViewTreeObserver viewTreeObserver = textView.getViewTreeObserver();
// viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
// @Override
// public void onGlobalLayout() {
// Layout l = textView.getLayout();
// if (l != null) {
// int lines = l.getLineCount();
// LogCat.e("xwm", textView.getText() + "--" + lines);
// if (lines > maxLines) {
// callBack.overFlowed(true);
// } else {
// callBack.overFlowed(false);
// }
// }
// }
// });
}
/**
* Google Gson
*
* @param jsonInString
* @return
*/
public final static boolean isJsonForGsonValid(String jsonInString) {
try {
new Gson().fromJson(jsonInString, Object.class);
return true;
} catch (JsonSyntaxException ex) {
return false;
}
}
/**
* 比较两个对象是否相等
*
* @param obj1
* @param obj2
* @return
*/
public static void objectEquals(Object obj1, Object obj2, ObjectEqualsCallBack callBack) {
Observable.create((ObservableOnSubscribe<Boolean>) e -> {
if (obj1 == obj2) {
e.onNext(true);
} else {
String json1 = GsonUtils.jsonSerializer(obj1);
String json2 = GsonUtils.jsonSerializer(obj2);
e.onNext(json1.equals(json2));
}
}).compose(SchedulerProvider.applySchedulers())
.subscribe(equals -> {
if (callBack != null) {
callBack.result(equals);
}
}, throwable -> {
if (callBack != null) {
callBack.result(false);
}
});
}
public interface ObjectEqualsCallBack {
void result(boolean equals);
}
public interface TextOverFlowedCallBack {
void overFlowed(boolean isOverFlowed);
}
}
include ':app', ':lib_common_ui', ':lib_data_drive',":lib_network", ':lib_app_common', ':app_passport', ':app_login', ':lib_baidu_audiodect',':buildsrc',":lib_baidu_facedect",":lib_baidu_textdect"
include ':app', ':lib_common_ui', ':lib_data_drive', ':app_common',":lib_network", ':lib_app_common', ':app_passport', ':app_login', ':lib_baidu_audiodect',':buildsrc',":lib_baidu_facedect",":lib_baidu_textdect"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment