@ -0,0 +1,14 @@ |
|||||||
|
*.iml |
||||||
|
.gradle |
||||||
|
/local.properties |
||||||
|
/.idea/caches |
||||||
|
/.idea/libraries |
||||||
|
/.idea/modules.xml |
||||||
|
/.idea/workspace.xml |
||||||
|
/.idea/navEditor.xml |
||||||
|
/.idea/assetWizardSettings.xml |
||||||
|
.DS_Store |
||||||
|
/build |
||||||
|
/captures |
||||||
|
.externalNativeBuild |
||||||
|
.cxx |
@ -0,0 +1,122 @@ |
|||||||
|
<component name="ProjectCodeStyleConfiguration"> |
||||||
|
<code_scheme name="Project" version="173"> |
||||||
|
<JetCodeStyleSettings> |
||||||
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> |
||||||
|
</JetCodeStyleSettings> |
||||||
|
<codeStyleSettings language="XML"> |
||||||
|
<indentOptions> |
||||||
|
<option name="CONTINUATION_INDENT_SIZE" value="4" /> |
||||||
|
</indentOptions> |
||||||
|
<arrangement> |
||||||
|
<rules> |
||||||
|
<section> |
||||||
|
<rule> |
||||||
|
<match> |
||||||
|
<AND> |
||||||
|
<NAME>xmlns:android</NAME> |
||||||
|
<XML_ATTRIBUTE /> |
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE> |
||||||
|
</AND> |
||||||
|
</match> |
||||||
|
</rule> |
||||||
|
</section> |
||||||
|
<section> |
||||||
|
<rule> |
||||||
|
<match> |
||||||
|
<AND> |
||||||
|
<NAME>xmlns:.*</NAME> |
||||||
|
<XML_ATTRIBUTE /> |
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE> |
||||||
|
</AND> |
||||||
|
</match> |
||||||
|
<order>BY_NAME</order> |
||||||
|
</rule> |
||||||
|
</section> |
||||||
|
<section> |
||||||
|
<rule> |
||||||
|
<match> |
||||||
|
<AND> |
||||||
|
<NAME>.*:id</NAME> |
||||||
|
<XML_ATTRIBUTE /> |
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> |
||||||
|
</AND> |
||||||
|
</match> |
||||||
|
</rule> |
||||||
|
</section> |
||||||
|
<section> |
||||||
|
<rule> |
||||||
|
<match> |
||||||
|
<AND> |
||||||
|
<NAME>.*:name</NAME> |
||||||
|
<XML_ATTRIBUTE /> |
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> |
||||||
|
</AND> |
||||||
|
</match> |
||||||
|
</rule> |
||||||
|
</section> |
||||||
|
<section> |
||||||
|
<rule> |
||||||
|
<match> |
||||||
|
<AND> |
||||||
|
<NAME>name</NAME> |
||||||
|
<XML_ATTRIBUTE /> |
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE> |
||||||
|
</AND> |
||||||
|
</match> |
||||||
|
</rule> |
||||||
|
</section> |
||||||
|
<section> |
||||||
|
<rule> |
||||||
|
<match> |
||||||
|
<AND> |
||||||
|
<NAME>style</NAME> |
||||||
|
<XML_ATTRIBUTE /> |
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE> |
||||||
|
</AND> |
||||||
|
</match> |
||||||
|
</rule> |
||||||
|
</section> |
||||||
|
<section> |
||||||
|
<rule> |
||||||
|
<match> |
||||||
|
<AND> |
||||||
|
<NAME>.*</NAME> |
||||||
|
<XML_ATTRIBUTE /> |
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE> |
||||||
|
</AND> |
||||||
|
</match> |
||||||
|
<order>BY_NAME</order> |
||||||
|
</rule> |
||||||
|
</section> |
||||||
|
<section> |
||||||
|
<rule> |
||||||
|
<match> |
||||||
|
<AND> |
||||||
|
<NAME>.*</NAME> |
||||||
|
<XML_ATTRIBUTE /> |
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> |
||||||
|
</AND> |
||||||
|
</match> |
||||||
|
<order>ANDROID_ATTRIBUTE_ORDER</order> |
||||||
|
</rule> |
||||||
|
</section> |
||||||
|
<section> |
||||||
|
<rule> |
||||||
|
<match> |
||||||
|
<AND> |
||||||
|
<NAME>.*</NAME> |
||||||
|
<XML_ATTRIBUTE /> |
||||||
|
<XML_NAMESPACE>.*</XML_NAMESPACE> |
||||||
|
</AND> |
||||||
|
</match> |
||||||
|
<order>BY_NAME</order> |
||||||
|
</rule> |
||||||
|
</section> |
||||||
|
</rules> |
||||||
|
</arrangement> |
||||||
|
</codeStyleSettings> |
||||||
|
<codeStyleSettings language="kotlin"> |
||||||
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> |
||||||
|
</codeStyleSettings> |
||||||
|
</code_scheme> |
||||||
|
</component> |
@ -0,0 +1,5 @@ |
|||||||
|
<component name="ProjectCodeStyleConfiguration"> |
||||||
|
<state> |
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" /> |
||||||
|
</state> |
||||||
|
</component> |
@ -0,0 +1,4 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project version="4"> |
||||||
|
<component name="Encoding" addBOMForNewFiles="with NO BOM" /> |
||||||
|
</project> |
@ -0,0 +1,21 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project version="4"> |
||||||
|
<component name="GradleSettings"> |
||||||
|
<option name="linkedExternalProjectsSettings"> |
||||||
|
<GradleProjectSettings> |
||||||
|
<option name="distributionType" value="DEFAULT_WRAPPED" /> |
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" /> |
||||||
|
<option name="modules"> |
||||||
|
<set> |
||||||
|
<option value="$PROJECT_DIR$" /> |
||||||
|
<option value="$PROJECT_DIR$/app" /> |
||||||
|
<option value="$PROJECT_DIR$/common_lib" /> |
||||||
|
<option value="$PROJECT_DIR$/net_serivce" /> |
||||||
|
</set> |
||||||
|
</option> |
||||||
|
<option name="resolveModulePerSourceSet" value="false" /> |
||||||
|
<option name="testRunner" value="PLATFORM" /> |
||||||
|
</GradleProjectSettings> |
||||||
|
</option> |
||||||
|
</component> |
||||||
|
</project> |
@ -0,0 +1,14 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project version="4"> |
||||||
|
<component name="CMakeSettings"> |
||||||
|
<configurations> |
||||||
|
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" /> |
||||||
|
</configurations> |
||||||
|
</component> |
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK"> |
||||||
|
<output url="file://$PROJECT_DIR$/build/classes" /> |
||||||
|
</component> |
||||||
|
<component name="ProjectType"> |
||||||
|
<option name="id" value="Android" /> |
||||||
|
</component> |
||||||
|
</project> |
@ -0,0 +1,12 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project version="4"> |
||||||
|
<component name="RunConfigurationProducerService"> |
||||||
|
<option name="ignoredProducers"> |
||||||
|
<set> |
||||||
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" /> |
||||||
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" /> |
||||||
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" /> |
||||||
|
</set> |
||||||
|
</option> |
||||||
|
</component> |
||||||
|
</project> |
@ -0,0 +1,7 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project version="4"> |
||||||
|
<component name="VcsDirectoryMappings"> |
||||||
|
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" /> |
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" /> |
||||||
|
</component> |
||||||
|
</project> |
@ -0,0 +1 @@ |
|||||||
|
/build |
@ -0,0 +1,37 @@ |
|||||||
|
apply plugin: 'com.android.application' |
||||||
|
|
||||||
|
apply plugin: 'kotlin-android' |
||||||
|
|
||||||
|
apply plugin: 'kotlin-android-extensions' |
||||||
|
|
||||||
|
android { |
||||||
|
compileSdkVersion rootProject.ext.android.compileSdkVersion |
||||||
|
defaultConfig { |
||||||
|
applicationId rootProject.ext.android.applicationId |
||||||
|
minSdkVersion rootProject.ext.android.minSdkVersion |
||||||
|
targetSdkVersion rootProject.ext.android.targetSdkVersion |
||||||
|
versionCode rootProject.ext.android.versionCode |
||||||
|
versionName rootProject.ext.android.versionName |
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
||||||
|
} |
||||||
|
buildTypes { |
||||||
|
release { |
||||||
|
minifyEnabled false |
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
||||||
|
} |
||||||
|
} |
||||||
|
compileOptions { |
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8 |
||||||
|
targetCompatibility JavaVersion.VERSION_1_8 |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
dependencies { |
||||||
|
implementation fileTree(dir: 'libs', include: ['*.jar']) |
||||||
|
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" |
||||||
|
testImplementation rootProject.ext.dependencies["junit"] |
||||||
|
androidTestImplementation rootProject.ext.dependencies["runner"] |
||||||
|
androidTestImplementation rootProject.ext.dependencies["espresso_core"] |
||||||
|
implementation project(path: ':net_serivce') |
||||||
|
implementation project(path: ':common_lib') |
||||||
|
} |
@ -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 |
@ -0,0 +1,24 @@ |
|||||||
|
package com.novel.read |
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry |
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
||||||
|
|
||||||
|
import org.junit.Test |
||||||
|
import org.junit.runner.RunWith |
||||||
|
|
||||||
|
import org.junit.Assert.* |
||||||
|
|
||||||
|
/** |
||||||
|
* Instrumented test, which will execute on an Android device. |
||||||
|
* |
||||||
|
* See [testing documentation](http://d.android.com/tools/testing). |
||||||
|
*/ |
||||||
|
@RunWith(AndroidJUnit4::class) |
||||||
|
class ExampleInstrumentedTest { |
||||||
|
@Test |
||||||
|
fun useAppContext() { |
||||||
|
// Context of the app under test. |
||||||
|
val appContext = InstrumentationRegistry.getInstrumentation().targetContext |
||||||
|
assertEquals("com.zlj.base_libaray", appContext.packageName) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
package="com.novel.read"> |
||||||
|
|
||||||
|
<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" |
||||||
|
tools:ignore="GoogleAppIndexingWarning"> |
||||||
|
<activity android:name="com.novel.read.MainActivity"> |
||||||
|
<intent-filter> |
||||||
|
<action android:name="android.intent.action.MAIN" /> |
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" /> |
||||||
|
</intent-filter> |
||||||
|
</activity> |
||||||
|
</application> |
||||||
|
|
||||||
|
</manifest> |
@ -0,0 +1,12 @@ |
|||||||
|
package com.novel.read |
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity |
||||||
|
import android.os.Bundle |
||||||
|
|
||||||
|
class MainActivity : AppCompatActivity() { |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
setContentView(R.layout.activity_main) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:aapt="http://schemas.android.com/aapt" |
||||||
|
android:width="108dp" |
||||||
|
android:height="108dp" |
||||||
|
android:viewportWidth="108" |
||||||
|
android:viewportHeight="108"> |
||||||
|
<path |
||||||
|
android:fillType="evenOdd" |
||||||
|
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z" |
||||||
|
android:strokeWidth="1" |
||||||
|
android:strokeColor="#00000000"> |
||||||
|
<aapt:attr name="android:fillColor"> |
||||||
|
<gradient |
||||||
|
android:endX="78.5885" |
||||||
|
android:endY="90.9159" |
||||||
|
android:startX="48.7653" |
||||||
|
android:startY="61.0927" |
||||||
|
android:type="linear"> |
||||||
|
<item |
||||||
|
android:color="#44000000" |
||||||
|
android:offset="0.0" /> |
||||||
|
<item |
||||||
|
android:color="#00000000" |
||||||
|
android:offset="1.0" /> |
||||||
|
</gradient> |
||||||
|
</aapt:attr> |
||||||
|
</path> |
||||||
|
<path |
||||||
|
android:fillColor="#FFFFFF" |
||||||
|
android:fillType="nonZero" |
||||||
|
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z" |
||||||
|
android:strokeWidth="1" |
||||||
|
android:strokeColor="#00000000" /> |
||||||
|
</vector> |
@ -0,0 +1,170 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:width="108dp" |
||||||
|
android:height="108dp" |
||||||
|
android:viewportWidth="108" |
||||||
|
android:viewportHeight="108"> |
||||||
|
<path |
||||||
|
android:fillColor="#008577" |
||||||
|
android:pathData="M0,0h108v108h-108z" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M9,0L9,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M19,0L19,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M29,0L29,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M39,0L39,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M49,0L49,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M59,0L59,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M69,0L69,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M79,0L79,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M89,0L89,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M99,0L99,108" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,9L108,9" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,19L108,19" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,29L108,29" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,39L108,39" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,49L108,49" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,59L108,59" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,69L108,69" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,79L108,79" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,89L108,89" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M0,99L108,99" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M19,29L89,29" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M19,39L89,39" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M19,49L89,49" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M19,59L89,59" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M19,69L89,69" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M19,79L89,79" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M29,19L29,89" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M39,19L39,89" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M49,19L49,89" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M59,19L59,89" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M69,19L69,89" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
<path |
||||||
|
android:fillColor="#00000000" |
||||||
|
android:pathData="M79,19L79,89" |
||||||
|
android:strokeWidth="0.8" |
||||||
|
android:strokeColor="#33FFFFFF" /> |
||||||
|
</vector> |
@ -0,0 +1,18 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
tools:context=".MainActivity"> |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:text="Hello World!" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintLeft_toLeftOf="parent" |
||||||
|
app:layout_constraintRight_toRightOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" /> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -0,0 +1,5 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> |
||||||
|
<background android:drawable="@drawable/ic_launcher_background" /> |
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" /> |
||||||
|
</adaptive-icon> |
@ -0,0 +1,5 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> |
||||||
|
<background android:drawable="@drawable/ic_launcher_background" /> |
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" /> |
||||||
|
</adaptive-icon> |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 15 KiB |
@ -0,0 +1,6 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<resources> |
||||||
|
<color name="colorPrimary">#008577</color> |
||||||
|
<color name="colorPrimaryDark">#00574B</color> |
||||||
|
<color name="colorAccent">#D81B60</color> |
||||||
|
</resources> |
@ -0,0 +1,3 @@ |
|||||||
|
<resources> |
||||||
|
<string name="app_name">小说阅读</string> |
||||||
|
</resources> |
@ -0,0 +1,11 @@ |
|||||||
|
<resources> |
||||||
|
|
||||||
|
<!-- Base application theme. --> |
||||||
|
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> |
||||||
|
<!-- Customize your theme here. --> |
||||||
|
<item name="colorPrimary">@color/colorPrimary</item> |
||||||
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> |
||||||
|
<item name="colorAccent">@color/colorAccent</item> |
||||||
|
</style> |
||||||
|
|
||||||
|
</resources> |
@ -0,0 +1,17 @@ |
|||||||
|
package com.novel.read |
||||||
|
|
||||||
|
import org.junit.Test |
||||||
|
|
||||||
|
import org.junit.Assert.* |
||||||
|
|
||||||
|
/** |
||||||
|
* Example local unit test, which will execute on the development machine (host). |
||||||
|
* |
||||||
|
* See [testing documentation](http://d.android.com/tools/testing). |
||||||
|
*/ |
||||||
|
class ExampleUnitTest { |
||||||
|
@Test |
||||||
|
fun addition_isCorrect() { |
||||||
|
assertEquals(4, 2 + 2) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
apply from: "config.gradle" |
||||||
|
|
||||||
|
buildscript { |
||||||
|
ext.kotlin_version = '1.3.41' |
||||||
|
repositories { |
||||||
|
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } |
||||||
|
google() |
||||||
|
jcenter() |
||||||
|
} |
||||||
|
dependencies { |
||||||
|
classpath 'com.android.tools.build:gradle:3.5.0' |
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
||||||
|
// NOTE: Do not place your application dependencies here; they belong |
||||||
|
// in the individual module build.gradle files |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
allprojects { |
||||||
|
repositories { |
||||||
|
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } |
||||||
|
google() |
||||||
|
jcenter() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
task clean(type: Delete) { |
||||||
|
delete rootProject.buildDir |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
/build |
@ -0,0 +1,46 @@ |
|||||||
|
apply plugin: 'com.android.library' |
||||||
|
apply plugin: 'kotlin-android' |
||||||
|
apply plugin: 'kotlin-android-extensions' |
||||||
|
android { |
||||||
|
compileSdkVersion rootProject.ext.android.compileSdkVersion |
||||||
|
|
||||||
|
defaultConfig { |
||||||
|
minSdkVersion rootProject.ext.android.minSdkVersion |
||||||
|
targetSdkVersion rootProject.ext.android.targetSdkVersion |
||||||
|
versionCode rootProject.ext.android.versionCode |
||||||
|
versionName rootProject.ext.android.versionName |
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
||||||
|
consumerProguardFiles 'consumer-rules.pro' |
||||||
|
} |
||||||
|
|
||||||
|
buildTypes { |
||||||
|
release { |
||||||
|
minifyEnabled false |
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
dependencies { |
||||||
|
api fileTree(include: ['*.jar'], dir: 'libs') |
||||||
|
testImplementation rootProject.ext.dependencies["junit"] |
||||||
|
androidTestImplementation rootProject.ext.dependencies["runner"] |
||||||
|
androidTestImplementation rootProject.ext.dependencies["espresso_core"] |
||||||
|
api rootProject.ext.dependencies["appcompat"] |
||||||
|
api rootProject.ext.dependencies["constraint_layout"] |
||||||
|
api rootProject.ext.dependencies["recyclerview"] |
||||||
|
api rootProject.ext.dependencies["material"] |
||||||
|
|
||||||
|
api rootProject.ext.dependencies["kotlin"] |
||||||
|
api rootProject.ext.dependencies["ktx"] |
||||||
|
|
||||||
|
api rootProject.ext.dependencies["gson"] |
||||||
|
api rootProject.ext.dependencies["glide"] |
||||||
|
|
||||||
|
api 'com.google.zxing:core:3.3.0' |
||||||
|
|
||||||
|
//密码输入 |
||||||
|
api 'com.jungly:gridPasswordView:0.3' |
||||||
|
} |
@ -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 |
@ -0,0 +1,24 @@ |
|||||||
|
package com.common_lib.common_lib |
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry |
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
||||||
|
|
||||||
|
import org.junit.Test |
||||||
|
import org.junit.runner.RunWith |
||||||
|
|
||||||
|
import org.junit.Assert.* |
||||||
|
|
||||||
|
/** |
||||||
|
* Instrumented test, which will execute on an Android device. |
||||||
|
* |
||||||
|
* See [testing documentation](http://d.android.com/tools/testing). |
||||||
|
*/ |
||||||
|
@RunWith(AndroidJUnit4::class) |
||||||
|
class ExampleInstrumentedTest { |
||||||
|
@Test |
||||||
|
fun useAppContext() { |
||||||
|
// Context of the app under test. |
||||||
|
val appContext = InstrumentationRegistry.getInstrumentation().targetContext |
||||||
|
assertEquals("com.book.common_lib.test", appContext.packageName) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
package="com.common_lib.common_lib" > |
||||||
|
|
||||||
|
|
||||||
|
</manifest> |
@ -0,0 +1,14 @@ |
|||||||
|
package com.common_lib.base |
||||||
|
|
||||||
|
/** |
||||||
|
* create by 赵利君 on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
object BaseConstants { |
||||||
|
const val Picture_Folder = "MangeRobot/imgCache" |
||||||
|
|
||||||
|
const val No_Internet = "当前网络不可用" |
||||||
|
|
||||||
|
//用于展示群组列表上的提示 |
||||||
|
const val EMPTY_STRING = " " |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
package com.common_lib.base |
||||||
|
|
||||||
|
import com.google.gson.Gson |
||||||
|
import com.google.gson.GsonBuilder |
||||||
|
|
||||||
|
/** |
||||||
|
* create by 赵利君 on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class GsonManager private constructor() { |
||||||
|
|
||||||
|
fun format(obj: Any): String? { |
||||||
|
var res: String? |
||||||
|
try { |
||||||
|
res = gson!!.toJson(obj) |
||||||
|
} catch (e: Exception) { |
||||||
|
res = null |
||||||
|
} |
||||||
|
|
||||||
|
return res |
||||||
|
} |
||||||
|
|
||||||
|
fun getGson(): Gson? { |
||||||
|
return gson |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
private var gson: Gson? = null |
||||||
|
|
||||||
|
private var instance: GsonManager? = null |
||||||
|
|
||||||
|
@Synchronized |
||||||
|
fun getInstance(): GsonManager { |
||||||
|
if (instance == null) { |
||||||
|
instance = GsonManager() |
||||||
|
if (gson == null) { |
||||||
|
gson = GsonBuilder().create() |
||||||
|
} |
||||||
|
} |
||||||
|
return instance as GsonManager |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,109 @@ |
|||||||
|
package com.common_lib.base |
||||||
|
|
||||||
|
import android.app.Activity |
||||||
|
import android.content.Context |
||||||
|
import android.graphics.Bitmap |
||||||
|
import android.util.DisplayMetrics |
||||||
|
import kotlin.math.abs |
||||||
|
|
||||||
|
/** |
||||||
|
* create by 赵利君 on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class ScreenManager private constructor() { |
||||||
|
//this is the screen width dpi the max value is 1200 |
||||||
|
|
||||||
|
private var screenWidth = -1 |
||||||
|
private var screenHeight = -1 |
||||||
|
private var dm: DisplayMetrics? = null |
||||||
|
private var density: Float = 0.toFloat() |
||||||
|
private var isScreenSetup = false |
||||||
|
|
||||||
|
val margin: Int |
||||||
|
get() = (30.0 / 750 * ScreenManager.instance!!.getScreenWidth()).toInt() |
||||||
|
|
||||||
|
fun setUpScreen(activity: Activity) { |
||||||
|
if (!isScreenSetup) { |
||||||
|
dm = DisplayMetrics() |
||||||
|
activity.windowManager.defaultDisplay.getMetrics(dm) |
||||||
|
dm?.let { |
||||||
|
density = it.density |
||||||
|
screenWidth = abs(it.widthPixels) |
||||||
|
screenHeight = abs(it.heightPixels) |
||||||
|
} |
||||||
|
|
||||||
|
isScreenSetup = true |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private fun getScreenWidth(): Int { |
||||||
|
assert(isScreenSetup) |
||||||
|
return screenWidth |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
fun getScreenHeight(): Int { |
||||||
|
assert(isScreenSetup) |
||||||
|
return screenHeight |
||||||
|
} |
||||||
|
|
||||||
|
fun getDensity(): Float { |
||||||
|
assert(isScreenSetup) |
||||||
|
return density |
||||||
|
} |
||||||
|
|
||||||
|
fun getPxFromDp(dp: Int): Int { |
||||||
|
return (dp * density + 0.5).toInt() |
||||||
|
} |
||||||
|
|
||||||
|
fun getDpFromPx(px: Int): Int { |
||||||
|
return (px / density + 0.5).toInt() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param number 每行显示的控件个数 |
||||||
|
* @param normalSplit 控件之间的间距 |
||||||
|
* @param leftMargin 控件左侧和container的距离 |
||||||
|
* @param rightMargin 控件右侧和container的距离 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
fun getViewSize(number: Int, normalSplit: Int, leftMargin: Int, rightMargin: Int): Int { |
||||||
|
var sp = 0 |
||||||
|
if (number > 1) { |
||||||
|
sp = number - 1 |
||||||
|
} |
||||||
|
// int totalSplit=Math.round(sp*normalSplit*density+(leftMargin+rightMargin)*density); |
||||||
|
val totalSplit = |
||||||
|
getScreenWidth() - (number - 1) * getPxFromDp(normalSplit) - getPxFromDp(rightMargin) - getPxFromDp( |
||||||
|
leftMargin |
||||||
|
) |
||||||
|
return totalSplit / number |
||||||
|
} |
||||||
|
|
||||||
|
fun getPxFromSp(sp: Int, context: Context): Int { |
||||||
|
val fontScale = context.resources.displayMetrics.scaledDensity |
||||||
|
return (sp * fontScale + 0.5f).toInt() |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
@get:Synchronized |
||||||
|
var instance: ScreenManager? = null |
||||||
|
private set |
||||||
|
|
||||||
|
init { |
||||||
|
instance = ScreenManager() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 屏幕截图 |
||||||
|
* @param activity |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
fun captureScreen(activity: Activity): Bitmap { |
||||||
|
activity.window.decorView.isDrawingCacheEnabled = true |
||||||
|
return activity.window.decorView.drawingCache |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,122 @@ |
|||||||
|
package com.common_lib.base.camera; |
||||||
|
|
||||||
|
import android.annotation.SuppressLint; |
||||||
|
import android.content.Context; |
||||||
|
import android.content.SharedPreferences; |
||||||
|
import android.hardware.Camera; |
||||||
|
import android.os.AsyncTask; |
||||||
|
import android.preference.PreferenceManager; |
||||||
|
import android.util.Log; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.concurrent.RejectedExecutionException; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 2016/11/28. |
||||||
|
*/ |
||||||
|
|
||||||
|
public class AutoFocusManager implements Camera.AutoFocusCallback { |
||||||
|
public static final String KEY_AUTO_FOCUS = "preferences_auto_focus"; |
||||||
|
|
||||||
|
private static final String TAG = AutoFocusManager.class.getSimpleName(); |
||||||
|
|
||||||
|
private static final long AUTO_FOCUS_INTERVAL_MS = 2000L; |
||||||
|
private static final Collection<String> FOCUS_MODES_CALLING_AF; |
||||||
|
private boolean canceled = false; |
||||||
|
|
||||||
|
static { |
||||||
|
FOCUS_MODES_CALLING_AF = new ArrayList<String>(2); |
||||||
|
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_AUTO); |
||||||
|
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_MACRO); |
||||||
|
} |
||||||
|
|
||||||
|
private boolean stopped; |
||||||
|
private boolean focusing; |
||||||
|
private final boolean useAutoFocus; |
||||||
|
private final Camera camera; |
||||||
|
private AsyncTask<?, ?, ?> outstandingTask; |
||||||
|
|
||||||
|
public AutoFocusManager(Context context, Camera camera) { |
||||||
|
this.camera = camera; |
||||||
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); |
||||||
|
String currentFocusMode = camera.getParameters().getFocusMode(); |
||||||
|
useAutoFocus = |
||||||
|
sharedPrefs.getBoolean(KEY_AUTO_FOCUS, true) && |
||||||
|
FOCUS_MODES_CALLING_AF.contains(currentFocusMode); |
||||||
|
start(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public synchronized void onAutoFocus(boolean success, Camera theCamera) { |
||||||
|
focusing = false; |
||||||
|
autoFocusAgainLater(); |
||||||
|
} |
||||||
|
|
||||||
|
@SuppressLint("NewApi") |
||||||
|
private synchronized void autoFocusAgainLater() { |
||||||
|
if (!stopped && outstandingTask == null) { |
||||||
|
AutoFocusTask newTask = new AutoFocusTask(); |
||||||
|
try { |
||||||
|
newTask.execute(); |
||||||
|
outstandingTask = newTask; |
||||||
|
} catch (RejectedExecutionException ree) { |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
synchronized void start() { |
||||||
|
if (useAutoFocus) { |
||||||
|
outstandingTask = null; |
||||||
|
if (!stopped && !focusing) { |
||||||
|
try { |
||||||
|
camera.autoFocus(this); |
||||||
|
focusing = true; |
||||||
|
} catch (RuntimeException re) { |
||||||
|
// Have heard RuntimeException reported in Android 4.0.x+; continue?
|
||||||
|
// Try again later to keep cycle going
|
||||||
|
autoFocusAgainLater(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private synchronized void cancelOutstandingTask() { |
||||||
|
if (outstandingTask != null) { |
||||||
|
if (outstandingTask.getStatus() != AsyncTask.Status.FINISHED) { |
||||||
|
outstandingTask.cancel(true); |
||||||
|
} |
||||||
|
outstandingTask = null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized void stop() { |
||||||
|
stopped = true; |
||||||
|
if (useAutoFocus) { |
||||||
|
cancelOutstandingTask(); |
||||||
|
// Doesn't hurt to call this even if not focusing
|
||||||
|
try { |
||||||
|
camera.cancelAutoFocus(); |
||||||
|
canceled = false; |
||||||
|
} catch (RuntimeException re) { |
||||||
|
// Have heard RuntimeException reported in Android 4.0.x+; continue?
|
||||||
|
Log.w(TAG, "Unexpected exception while cancelling focusing", re); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private final class AutoFocusTask extends AsyncTask<Object, Object, Object> { |
||||||
|
@Override |
||||||
|
protected Object doInBackground(Object... voids) { |
||||||
|
try { |
||||||
|
Thread.sleep(AUTO_FOCUS_INTERVAL_MS); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
// continue
|
||||||
|
} |
||||||
|
start(); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,154 @@ |
|||||||
|
package com.common_lib.base.picture; |
||||||
|
|
||||||
|
import android.content.ContentUris; |
||||||
|
import android.content.Context; |
||||||
|
import android.database.Cursor; |
||||||
|
import android.net.Uri; |
||||||
|
import android.os.Build; |
||||||
|
import android.os.Environment; |
||||||
|
import android.provider.DocumentsContract; |
||||||
|
import android.provider.MediaStore; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 2016/11/28. |
||||||
|
*/ |
||||||
|
|
||||||
|
public class ImageFilePath { |
||||||
|
/** |
||||||
|
* Method for return file path of Gallery image |
||||||
|
* |
||||||
|
* @param context |
||||||
|
* @param uri |
||||||
|
* @return path of the selected image file from gallery |
||||||
|
*/ |
||||||
|
public static String getPath(final Context context, final Uri uri) { |
||||||
|
|
||||||
|
//check here to KITKAT or new version
|
||||||
|
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; |
||||||
|
// DocumentProvider
|
||||||
|
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { |
||||||
|
|
||||||
|
// ExternalStorageProvider
|
||||||
|
if (isExternalStorageDocument(uri)) { |
||||||
|
final String docId = DocumentsContract.getDocumentId(uri); |
||||||
|
final String[] split = docId.split(":"); |
||||||
|
final String type = split[0]; |
||||||
|
|
||||||
|
if ("primary".equalsIgnoreCase(type)) { |
||||||
|
return Environment.getExternalStorageDirectory() + "/" + split[1]; |
||||||
|
} |
||||||
|
} |
||||||
|
// DownloadsProvider
|
||||||
|
else if (isDownloadsDocument(uri)) { |
||||||
|
|
||||||
|
final String id = DocumentsContract.getDocumentId(uri); |
||||||
|
final Uri contentUri = ContentUris.withAppendedId( |
||||||
|
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); |
||||||
|
|
||||||
|
return getDataColumn(context, contentUri, null, null); |
||||||
|
} |
||||||
|
// MediaProvider
|
||||||
|
else if (isMediaDocument(uri)) { |
||||||
|
final String docId = DocumentsContract.getDocumentId(uri); |
||||||
|
final String[] split = docId.split(":"); |
||||||
|
final String type = split[0]; |
||||||
|
|
||||||
|
Uri contentUri = null; |
||||||
|
if ("image".equals(type)) { |
||||||
|
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; |
||||||
|
} else if ("video".equals(type)) { |
||||||
|
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; |
||||||
|
} else if ("audio".equals(type)) { |
||||||
|
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; |
||||||
|
} |
||||||
|
|
||||||
|
final String selection = "_id=?"; |
||||||
|
final String[] selectionArgs = new String[]{ |
||||||
|
split[1] |
||||||
|
}; |
||||||
|
|
||||||
|
return getDataColumn(context, contentUri, selection, selectionArgs); |
||||||
|
} |
||||||
|
} |
||||||
|
// MediaStore (and general)
|
||||||
|
else if ("content".equalsIgnoreCase(uri.getScheme())) { |
||||||
|
|
||||||
|
// Return the remote address
|
||||||
|
if (isGooglePhotosUri(uri)) |
||||||
|
return uri.getLastPathSegment(); |
||||||
|
|
||||||
|
return getDataColumn(context, uri, null, null); |
||||||
|
} |
||||||
|
// File
|
||||||
|
else if ("file".equalsIgnoreCase(uri.getScheme())) { |
||||||
|
return uri.getPath(); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the value of the data column for this Uri. This is useful for |
||||||
|
* MediaStore Uris, and other file-based ContentProviders. |
||||||
|
* |
||||||
|
* @param context The context. |
||||||
|
* @param uri The Uri to query. |
||||||
|
* @param selection (Optional) Filter used in the query. |
||||||
|
* @param selectionArgs (Optional) Selection arguments used in the query. |
||||||
|
* @return The value of the _data column, which is typically a file path. |
||||||
|
*/ |
||||||
|
public static String getDataColumn(Context context, Uri uri, String selection, |
||||||
|
String[] selectionArgs) { |
||||||
|
|
||||||
|
Cursor cursor = null; |
||||||
|
final String column = "_data"; |
||||||
|
final String[] projection = { |
||||||
|
column |
||||||
|
}; |
||||||
|
|
||||||
|
try { |
||||||
|
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, |
||||||
|
null); |
||||||
|
if (cursor != null && cursor.moveToFirst()) { |
||||||
|
final int index = cursor.getColumnIndexOrThrow(column); |
||||||
|
return cursor.getString(index); |
||||||
|
} |
||||||
|
} finally { |
||||||
|
if (cursor != null) |
||||||
|
cursor.close(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param uri The Uri to check. |
||||||
|
* @return Whether the Uri authority is ExternalStorageProvider. |
||||||
|
*/ |
||||||
|
public static boolean isExternalStorageDocument(Uri uri) { |
||||||
|
return "com.android.externalstorage.documents".equals(uri.getAuthority()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param uri The Uri to check. |
||||||
|
* @return Whether the Uri authority is DownloadsProvider. |
||||||
|
*/ |
||||||
|
public static boolean isDownloadsDocument(Uri uri) { |
||||||
|
return "com.android.providers.downloads.documents".equals(uri.getAuthority()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param uri The Uri to check. |
||||||
|
* @return Whether the Uri authority is MediaProvider. |
||||||
|
*/ |
||||||
|
public static boolean isMediaDocument(Uri uri) { |
||||||
|
return "com.android.providers.media.documents".equals(uri.getAuthority()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param uri The Uri to check. |
||||||
|
* @return Whether the Uri authority is Google Photos. |
||||||
|
*/ |
||||||
|
public static boolean isGooglePhotosUri(Uri uri) { |
||||||
|
return "com.google.android.apps.photos.content".equals(uri.getAuthority()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,283 @@ |
|||||||
|
package com.common_lib.base.picture; |
||||||
|
|
||||||
|
|
||||||
|
import android.graphics.Bitmap; |
||||||
|
import android.graphics.BitmapFactory; |
||||||
|
import android.graphics.Matrix; |
||||||
|
import android.media.ExifInterface; |
||||||
|
import android.os.Environment; |
||||||
|
import android.util.Base64; |
||||||
|
|
||||||
|
import com.common_lib.base.BaseConstants; |
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream; |
||||||
|
import java.io.ByteArrayOutputStream; |
||||||
|
import java.io.File; |
||||||
|
import java.io.IOException; |
||||||
|
import java.security.MessageDigest; |
||||||
|
import java.security.NoSuchAlgorithmException; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 2016/3/16. |
||||||
|
*/ |
||||||
|
public class PictureUtil { |
||||||
|
/** |
||||||
|
* convert bitmap to right size and send it to service |
||||||
|
* |
||||||
|
* @param filePath ; square |
||||||
|
* @return byte[] |
||||||
|
*/ |
||||||
|
public static byte[] bitmapToByte(String filePath, boolean square) { |
||||||
|
Bitmap bm; |
||||||
|
byte[] b=null; |
||||||
|
try { |
||||||
|
if (square) { |
||||||
|
bm = getSmallBitmap(filePath, 1200f, 1200f, filePath,0); |
||||||
|
} else { |
||||||
|
bm = getSmallBitmap(filePath, 2400f, 2400f, filePath,0); |
||||||
|
} |
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||||
|
bm.compress(Bitmap.CompressFormat.JPEG, 40, baos); |
||||||
|
//这个视情况而定吧
|
||||||
|
bm.recycle(); |
||||||
|
b = baos.toByteArray(); |
||||||
|
baos.close(); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return b; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* convert bitmap to right size and send it to service |
||||||
|
* |
||||||
|
* @param filePath ; square |
||||||
|
* @return byte[] |
||||||
|
*/ |
||||||
|
public static byte[] bitmapToByte(String filePath, int fixedDegree, boolean square) { |
||||||
|
Bitmap bm; |
||||||
|
byte[] b=null; |
||||||
|
try { |
||||||
|
if (square) { |
||||||
|
bm = getSmallBitmap(filePath, 1200f, 1200f, filePath,fixedDegree); |
||||||
|
} else { |
||||||
|
bm = getSmallBitmap(filePath, 2400f, 2400f, filePath,fixedDegree); |
||||||
|
} |
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||||
|
bm.compress(Bitmap.CompressFormat.JPEG, 40, baos); |
||||||
|
//这个视情况而定吧
|
||||||
|
bm.recycle(); |
||||||
|
b = baos.toByteArray(); |
||||||
|
baos.close(); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return b; |
||||||
|
} |
||||||
|
|
||||||
|
public static byte[] bitmapToByte(Bitmap bitmap, boolean needRecycle) { |
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||||
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, baos); |
||||||
|
if (needRecycle) { |
||||||
|
bitmap.recycle(); |
||||||
|
} |
||||||
|
byte[] b = baos.toByteArray(); |
||||||
|
try { |
||||||
|
baos.close(); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return b; |
||||||
|
} |
||||||
|
|
||||||
|
public static byte[] logoBitmapToByte(Bitmap bitmap, boolean needRecycle) { |
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||||
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); |
||||||
|
if (needRecycle) { |
||||||
|
bitmap.recycle(); |
||||||
|
} |
||||||
|
byte[] b = baos.toByteArray(); |
||||||
|
try { |
||||||
|
baos.close(); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return b; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据路径获得突破并压缩返回bitmap用于显示 |
||||||
|
* |
||||||
|
* @param srcPath |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Bitmap getSmallBitmap(String srcPath, float maxHeight, float maxWidth, String filePath, int fixedDegree) throws IOException { |
||||||
|
BitmapFactory.Options newOpts = new BitmapFactory.Options(); |
||||||
|
// 开始读入图片,此时把options.inJustDecodeBounds 设回true了
|
||||||
|
newOpts.inJustDecodeBounds = true; |
||||||
|
BitmapFactory.decodeFile(srcPath, newOpts);// 此时返回bm为空
|
||||||
|
// Calculate inSampleSize
|
||||||
|
newOpts.inSampleSize = computeSampleSize(newOpts, maxWidth, maxHeight); |
||||||
|
// Decode bitmap with inSampleSize set
|
||||||
|
newOpts.inJustDecodeBounds = false; |
||||||
|
Bitmap bitmap = BitmapFactory.decodeFile(srcPath, newOpts); |
||||||
|
// bitmap = ThumbnailUtils.extractThumbnail(bitmap, 480, 800,
|
||||||
|
// ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
|
||||||
|
Bitmap bitmap1 = compressImage(bitmap); |
||||||
|
bitmap.recycle(); |
||||||
|
return rotateBitMap(bitmap1, filePath,fixedDegree);// 压缩好比例大小后再进行质量压缩
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static Bitmap rotateBitMap(Bitmap bp, String filePath, int fixedDegree) throws IOException { |
||||||
|
ExifInterface exif = new ExifInterface(filePath); |
||||||
|
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)+fixedDegree; |
||||||
|
int rotationInDegrees = exifToDegrees(rotation)+fixedDegree; |
||||||
|
Matrix matrix = new Matrix(); |
||||||
|
Bitmap nowBp=null; |
||||||
|
if (rotation != 0f) { |
||||||
|
matrix.preRotate(rotationInDegrees); |
||||||
|
nowBp = Bitmap.createBitmap(bp, 0, 0, bp.getWidth(), |
||||||
|
bp.getHeight(), matrix, true); |
||||||
|
if (bp.isRecycled()) { |
||||||
|
bp.recycle(); |
||||||
|
} |
||||||
|
} |
||||||
|
if (nowBp!=null){ |
||||||
|
return nowBp; |
||||||
|
}else{ |
||||||
|
return bp; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static int exifToDegrees(int exifOrientation) { |
||||||
|
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { |
||||||
|
return 90; |
||||||
|
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { |
||||||
|
return 180; |
||||||
|
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { |
||||||
|
return 270; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private static Bitmap compressImage(Bitmap image) { |
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||||
|
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);// 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
|
||||||
|
int options = 100; |
||||||
|
while (baos.toByteArray().length / 1024 > 1024 * 5) { // 循环判断如果压缩后图片是否大于500kb,大于继续压缩
|
||||||
|
baos.reset();// 重置baos即清空baos
|
||||||
|
options -= 10;// 每次都减少10
|
||||||
|
image.compress(Bitmap.CompressFormat.JPEG, options, baos);// 这里压缩options%,把压缩后的数据存放到baos中
|
||||||
|
} |
||||||
|
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());// 把压缩后的数据baos存放到ByteArrayInputStream中
|
||||||
|
Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);// 把ByteArrayInputStream数据生成图片
|
||||||
|
return bitmap; |
||||||
|
} |
||||||
|
|
||||||
|
/* |
||||||
|
* 这个方法可以把base64转换的字符串转换成bitmap |
||||||
|
*/ |
||||||
|
public static Bitmap StringToBitmap(String string) { |
||||||
|
//将字符串转换成Bitmap类型
|
||||||
|
Bitmap bitmap = null; |
||||||
|
try { |
||||||
|
byte[] bitmapArray; |
||||||
|
bitmapArray = Base64.decode(string, Base64.DEFAULT); |
||||||
|
bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return bitmap; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static File getStorageFile() { |
||||||
|
// File file = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
|
// Environment.DIRECTORY_PICTURES), "JustBig/"+TimeUtils.GetTodayTime());
|
||||||
|
File file = new File(Environment.getExternalStoragePublicDirectory( |
||||||
|
Environment.DIRECTORY_PICTURES), BaseConstants.Picture_Folder); |
||||||
|
if (!file.exists()) { |
||||||
|
file.mkdirs(); |
||||||
|
} |
||||||
|
return file; |
||||||
|
} |
||||||
|
|
||||||
|
public static String md5HashBytes(byte[] bytes) { |
||||||
|
MessageDigest m = null; |
||||||
|
try { |
||||||
|
m = MessageDigest.getInstance("MD5"); |
||||||
|
} catch (NoSuchAlgorithmException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
m.update(bytes); |
||||||
|
byte[] hashedBytes = m.digest(); |
||||||
|
|
||||||
|
StringBuffer stringBuffer = new StringBuffer(); |
||||||
|
for (int i = 0; i < hashedBytes.length; i++) { |
||||||
|
stringBuffer.append(Integer.toString((hashedBytes[i] & 0xff) + 0x100, 16) |
||||||
|
.substring(1)); |
||||||
|
} |
||||||
|
return stringBuffer.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
public static int computeSampleSize(BitmapFactory.Options options, float reqWidth, float reqHeight) { |
||||||
|
// Raw height and width of image
|
||||||
|
final int height = options.outHeight; |
||||||
|
final int width = options.outWidth; |
||||||
|
int inSampleSize = 1; |
||||||
|
|
||||||
|
if (height > reqHeight || width > reqWidth) { |
||||||
|
double scaleHeight = Math.ceil(height / reqHeight); |
||||||
|
double scaleWidth = Math.ceil(width / reqWidth); |
||||||
|
if (scaleHeight > scaleWidth) { |
||||||
|
inSampleSize = (int) scaleHeight + 1; |
||||||
|
} else if (scaleHeight < scaleWidth) { |
||||||
|
inSampleSize = (int) scaleWidth + 1; |
||||||
|
} else { |
||||||
|
inSampleSize = (int) scaleHeight + 1; |
||||||
|
} |
||||||
|
} |
||||||
|
return inSampleSize; |
||||||
|
} |
||||||
|
|
||||||
|
public static boolean isSquareImage(String path) { |
||||||
|
boolean res = false; |
||||||
|
BitmapFactory.Options options = new BitmapFactory.Options(); |
||||||
|
options.inJustDecodeBounds = true; |
||||||
|
BitmapFactory.decodeFile((path), options); |
||||||
|
int imageHeight = options.outHeight; |
||||||
|
int imageWidth = options.outWidth; |
||||||
|
if (imageHeight == imageWidth) { |
||||||
|
res = true; |
||||||
|
} |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
public static boolean isSquareImage(Bitmap bitmap) { |
||||||
|
boolean res = false; |
||||||
|
int width = bitmap.getWidth(); |
||||||
|
int height = bitmap.getHeight(); |
||||||
|
if (width == height) { |
||||||
|
res = true; |
||||||
|
} |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
public static int getSquareCropDimensionForBitmap(Bitmap bitmap) { |
||||||
|
int dimension; |
||||||
|
//If the bitmap is wider than it is tall
|
||||||
|
//use the height as the square crop dimension
|
||||||
|
if (bitmap.getWidth() >= bitmap.getHeight()) { |
||||||
|
dimension = bitmap.getHeight(); |
||||||
|
} |
||||||
|
//If the bitmap is taller than it is wide
|
||||||
|
//use the width as the square crop dimension
|
||||||
|
else { |
||||||
|
dimension = bitmap.getWidth(); |
||||||
|
} |
||||||
|
return dimension; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
package com.common_lib.base.picture; |
||||||
|
|
||||||
|
import android.os.AsyncTask; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 2016/11/28. |
||||||
|
*/ |
||||||
|
|
||||||
|
public class TransformNormalImageTask extends AsyncTask<String,Void,byte[]> { |
||||||
|
@Override |
||||||
|
protected byte[] doInBackground(String... params) { |
||||||
|
return PictureUtil.bitmapToByte(params[0],false); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void onPostExecute(byte[] bytes) { |
||||||
|
super.onPostExecute(bytes); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
package com.common_lib.base.picture; |
||||||
|
|
||||||
|
import android.os.AsyncTask; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 2016/11/28. |
||||||
|
*/ |
||||||
|
|
||||||
|
public class TransformSurfaceImageTask extends AsyncTask<Void,Void,byte[]> { |
||||||
|
private String path; |
||||||
|
private int fixedDegree; |
||||||
|
|
||||||
|
public TransformSurfaceImageTask(String path, int fixedDegree){ |
||||||
|
this.path=path; |
||||||
|
this.fixedDegree=fixedDegree; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected byte[] doInBackground(Void... params) { |
||||||
|
return PictureUtil.bitmapToByte(path,fixedDegree,false); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
protected void onPostExecute(byte[] bytes) { |
||||||
|
super.onPostExecute(bytes); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,78 @@ |
|||||||
|
package com.common_lib.base.utils; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
import android.os.Build; |
||||||
|
import android.provider.Settings; |
||||||
|
import android.telephony.TelephonyManager; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStreamReader; |
||||||
|
import java.io.LineNumberReader; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 2017/2/8. |
||||||
|
*/ |
||||||
|
|
||||||
|
public class DeviceInfoUtil { |
||||||
|
public static String getDeviceInfo(Context context){ |
||||||
|
String A_ID = Settings.System.getString(context.getContentResolver(), Settings.System.ANDROID_ID); |
||||||
|
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId()); |
||||||
|
sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion()); |
||||||
|
sb.append("\nLine1Number = " + tm.getLine1Number()); |
||||||
|
sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso()); |
||||||
|
sb.append("\nNetworkOperator = " + tm.getNetworkOperator()); |
||||||
|
sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName()); |
||||||
|
sb.append("\nNetworkType = " + tm.getNetworkType()); |
||||||
|
sb.append("\nPhoneType = " + tm.getPhoneType()); |
||||||
|
sb.append("\nSimCountryIso = " + tm.getSimCountryIso()); |
||||||
|
sb.append("\nSimOperator = " + tm.getSimOperator()); |
||||||
|
sb.append("\nSimOperatorName = " + tm.getSimOperatorName()); |
||||||
|
sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber()); |
||||||
|
sb.append("\nSimState = " + tm.getSimState()); |
||||||
|
sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId()); |
||||||
|
sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber()); |
||||||
|
sb.append("\nSoftwareVersion=" + tm.getDeviceSoftwareVersion()); |
||||||
|
sb.append("\nCPU="+getCPUSerial()); |
||||||
|
sb.append("\nBoard="+ Build.BOARD); |
||||||
|
sb.append("\nCPU1="+ Build.CPU_ABI); |
||||||
|
sb.append("\nDEVICE="+ Build.DEVICE); |
||||||
|
sb.append("\nHARDWARE="+ Build.HARDWARE); |
||||||
|
sb.append("\nANDROID_ID = " + A_ID); |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取CPU序列号 |
||||||
|
* |
||||||
|
* @return CPU序列号(16位) |
||||||
|
* 读取失败为"0000000000000000" |
||||||
|
*/ |
||||||
|
private static String getCPUSerial() { |
||||||
|
String str = "", strCPU = "", cpuAddress = "0000000000000000"; |
||||||
|
try { |
||||||
|
//读取CPU信息
|
||||||
|
Process pp = Runtime.getRuntime().exec("cat /proc/cpuinfo"); |
||||||
|
InputStreamReader ir = new InputStreamReader(pp.getInputStream()); |
||||||
|
LineNumberReader input = new LineNumberReader(ir); |
||||||
|
//查找CPU序列号
|
||||||
|
str = input.readLine(); |
||||||
|
if (str != null) { |
||||||
|
//查找到序列号所在行
|
||||||
|
if (str.indexOf("Serial") > -1) { |
||||||
|
//提取序列号
|
||||||
|
strCPU = str.substring(str.indexOf(":") + 1, |
||||||
|
str.length()); |
||||||
|
//去空格
|
||||||
|
cpuAddress = strCPU.trim(); |
||||||
|
} |
||||||
|
} else { |
||||||
|
} |
||||||
|
} catch (IOException ex) { |
||||||
|
//赋予默认值
|
||||||
|
ex.printStackTrace(); |
||||||
|
} |
||||||
|
return cpuAddress; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,116 @@ |
|||||||
|
package com.common_lib.base.utils; |
||||||
|
|
||||||
|
import android.net.Uri; |
||||||
|
import android.os.Environment; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Random; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 16/7/2. |
||||||
|
*/ |
||||||
|
public class FileUtils { |
||||||
|
private List<File> myFile; |
||||||
|
|
||||||
|
//get the size of picassio picture cache file size
|
||||||
|
public long getFileDir(String filePath) { |
||||||
|
long mySpace = 0; |
||||||
|
try { |
||||||
|
File f = new File(filePath); |
||||||
|
File[] files = f.listFiles();// 列出所有文件
|
||||||
|
// 将所有文件存入list中
|
||||||
|
if (files != null) { |
||||||
|
int count = files.length;// 文件个数
|
||||||
|
myFile = new ArrayList<>(); |
||||||
|
for (File file : files) { |
||||||
|
if ("KuKu".contains(file.getName())) { |
||||||
|
mySpace += file.length(); |
||||||
|
myFile.add(file); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (Exception ex) { |
||||||
|
ex.printStackTrace(); |
||||||
|
} finally { |
||||||
|
return mySpace; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//clear picassio cache file
|
||||||
|
public boolean clearCatch() { |
||||||
|
boolean res = false; |
||||||
|
if (myFile == null || myFile.size() == 0) { |
||||||
|
return true; |
||||||
|
} else { |
||||||
|
for (File f : myFile) { |
||||||
|
f.delete(); |
||||||
|
} |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static Uri getOutputMediaFileUri(String fileName) { |
||||||
|
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "KuKu"); |
||||||
|
if (!mediaStorageDir.exists()) { |
||||||
|
if (!mediaStorageDir.mkdirs()) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
File mediaFile = new File(mediaStorageDir.getPath() + File.separator + fileName); |
||||||
|
return Uri.fromFile(mediaFile); |
||||||
|
} |
||||||
|
|
||||||
|
public static File getOutPutMediaFile(String fileName) { |
||||||
|
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "KuKu"); |
||||||
|
if (!mediaStorageDir.exists()) { |
||||||
|
if (!mediaStorageDir.mkdirs()) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
return new File(mediaStorageDir.getPath() + File.separator + fileName); |
||||||
|
} |
||||||
|
|
||||||
|
public static String getOutputMediaFileName() { |
||||||
|
long time = System.currentTimeMillis() / 1000; |
||||||
|
Random random = new Random(); |
||||||
|
int number = random.nextInt(10000) % (10000 - 1000 + 1) + 1000; |
||||||
|
return time + "" + number + ".jpg"; |
||||||
|
} |
||||||
|
|
||||||
|
public static String getOutputMediaFileNameWithoutFormat() { |
||||||
|
long time = System.currentTimeMillis() / 1000; |
||||||
|
Random random = new Random(); |
||||||
|
int number = random.nextInt(10000) % (10000 - 1000 + 1) + 1000; |
||||||
|
return time + "" + number; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//This is the method to get taking picture out put url
|
||||||
|
public static File getOutputMediaFile() { |
||||||
|
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "KuKu"); |
||||||
|
if (!mediaStorageDir.exists()) { |
||||||
|
if (!mediaStorageDir.mkdirs()) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
long time = System.currentTimeMillis() / 1000; |
||||||
|
Random random = new Random(); |
||||||
|
int number = random.nextInt(10000) % (10000 - 1000 + 1) + 1000; |
||||||
|
String timeStamp = time + "" + number; |
||||||
|
return new File(mediaStorageDir.getPath() + File.separator + timeStamp + ".jpg"); |
||||||
|
} |
||||||
|
|
||||||
|
//This is the method to get taking picture out put url
|
||||||
|
public static File getOutputMediaFile(String name) { |
||||||
|
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "KuKu"); |
||||||
|
if (!mediaStorageDir.exists()) { |
||||||
|
if (!mediaStorageDir.mkdirs()) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
return new File(mediaStorageDir.getPath() + File.separator + name + ".jpg"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
package com.common_lib.base.utils; |
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException; |
||||||
|
import java.security.MessageDigest; |
||||||
|
import java.security.NoSuchAlgorithmException; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 16/7/4. |
||||||
|
*/ |
||||||
|
public class MD5Utils { |
||||||
|
private static MD5Utils instance = null; |
||||||
|
|
||||||
|
private MD5Utils() { |
||||||
|
} |
||||||
|
|
||||||
|
public static synchronized MD5Utils getInstance() { |
||||||
|
if (instance == null) { |
||||||
|
instance = new MD5Utils(); |
||||||
|
} |
||||||
|
return instance; |
||||||
|
} |
||||||
|
|
||||||
|
public String getMD5Result(String info){ |
||||||
|
try { |
||||||
|
// Create MD5 Hash
|
||||||
|
MessageDigest digest = MessageDigest.getInstance("MD5"); |
||||||
|
digest.reset(); |
||||||
|
digest.update(info.getBytes("UTF-8")); |
||||||
|
byte messageDigest[] = digest.digest(); |
||||||
|
// Create Hex String
|
||||||
|
StringBuffer hexString = new StringBuffer(); |
||||||
|
for (int i=0; i<messageDigest.length; i++){ |
||||||
|
if (Integer.toHexString(0xFF & messageDigest[i]).length() == 1) |
||||||
|
hexString.append("0").append(Integer.toHexString(0xFF & messageDigest[i])); |
||||||
|
else |
||||||
|
hexString.append(Integer.toHexString(0xFF & messageDigest[i])); |
||||||
|
} |
||||||
|
return hexString.toString(); |
||||||
|
} catch (NoSuchAlgorithmException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
}catch (UnsupportedEncodingException e){ |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
package com.common_lib.base.utils; |
||||||
|
|
||||||
|
import android.annotation.TargetApi; |
||||||
|
import android.content.Context; |
||||||
|
import android.net.ConnectivityManager; |
||||||
|
import android.net.NetworkInfo; |
||||||
|
import android.os.Build; |
||||||
|
import android.provider.Settings; |
||||||
|
|
||||||
|
import com.common_lib.base.BaseConstants; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 2016/3/2. |
||||||
|
*/ |
||||||
|
public class NetworkUtils { |
||||||
|
public static final int TYPE_UNKNOWN = -1; |
||||||
|
|
||||||
|
private static NetworkInfo getActiveNetworkInfo(Context context) { |
||||||
|
if (context == null) { |
||||||
|
return null; |
||||||
|
} else { |
||||||
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
||||||
|
return cm == null ? null : cm.getActiveNetworkInfo(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static int getActiveNetworkType(Context context) { |
||||||
|
NetworkInfo info = getActiveNetworkInfo(context); |
||||||
|
return info != null && info.isConnected() ? info.getType() : -1; |
||||||
|
} |
||||||
|
|
||||||
|
public static boolean isNetworkAvailable(Context context) { |
||||||
|
NetworkInfo info = getActiveNetworkInfo(context); |
||||||
|
return info != null && info.isConnected(); |
||||||
|
} |
||||||
|
|
||||||
|
public static boolean isWiFiConnected(Context context) { |
||||||
|
return getActiveNetworkType(context) == 1; |
||||||
|
} |
||||||
|
|
||||||
|
@TargetApi(17) |
||||||
|
public static boolean isAirplaneModeOn(Context context) { |
||||||
|
return Build.VERSION.SDK_INT < 17 ? Settings.System.getInt(context.getContentResolver(), "airplane_mode_on", 0) != 0 : Settings.Global.getInt(context.getContentResolver(), "airplane_mode_on", 0) != 0; |
||||||
|
} |
||||||
|
|
||||||
|
public static boolean checkConnection(Context context) { |
||||||
|
if (isNetworkAvailable(context)) { |
||||||
|
return true; |
||||||
|
} else { |
||||||
|
ToastUtils.showNormalToast(context, BaseConstants.No_Internet); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,307 @@ |
|||||||
|
package com.common_lib.base.utils; |
||||||
|
|
||||||
|
|
||||||
|
import android.util.Log; |
||||||
|
|
||||||
|
import com.common_lib.base.GsonManager; |
||||||
|
import com.google.gson.Gson; |
||||||
|
|
||||||
|
import java.lang.reflect.Field; |
||||||
|
import java.lang.reflect.InvocationTargetException; |
||||||
|
import java.lang.reflect.Method; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 这个类是用来解析Object属性的 |
||||||
|
* Created by alex on 16/7/4. |
||||||
|
*/ |
||||||
|
public class ObjectAnalysisUtils { |
||||||
|
private static ObjectAnalysisUtils instance = null; |
||||||
|
|
||||||
|
private ObjectAnalysisUtils() { |
||||||
|
} |
||||||
|
|
||||||
|
public static synchronized ObjectAnalysisUtils getInstance() { |
||||||
|
if (instance == null) { |
||||||
|
instance = new ObjectAnalysisUtils(); |
||||||
|
} |
||||||
|
return instance; |
||||||
|
} |
||||||
|
|
||||||
|
public HashMap<String, String> analysObject(Object obj, boolean needUId) { |
||||||
|
try { |
||||||
|
HashMap<String, String> result; |
||||||
|
if (needUId) { |
||||||
|
result = getClassInfo(obj, needUId); |
||||||
|
} else { |
||||||
|
result = getClassInfo(obj); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} catch (SecurityException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} catch (IllegalArgumentException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} catch (NoSuchMethodException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} catch (IllegalAccessException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} catch (InvocationTargetException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} catch (InstantiationException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
private HashMap<String, String> getClassInfo(Object model) throws SecurityException, |
||||||
|
NoSuchMethodException, IllegalArgumentException, |
||||||
|
IllegalAccessException, InvocationTargetException, InstantiationException { |
||||||
|
HashMap<String, String> valueMap = new HashMap<>(); |
||||||
|
// 获取实体类的所有属性,返回Field数组
|
||||||
|
Field[] field = model.getClass().getDeclaredFields(); |
||||||
|
// 获取属性的名字
|
||||||
|
String[] modelName = new String[field.length]; |
||||||
|
String[] modelType = new String[field.length]; |
||||||
|
for (int i = 0; i < field.length; i++) { |
||||||
|
// 获取属性的名字
|
||||||
|
String realName = field[i].getName(); |
||||||
|
//这个是svn偷偷加上去的方法
|
||||||
|
if (realName.startsWith("$")||realName.contains("serialVersionUID")){ |
||||||
|
continue; |
||||||
|
} |
||||||
|
//这个方法就是为了获取security,这里就不对其进行处理啦,但是所有的带加密的类,其加密属性的名称都必修为security
|
||||||
|
if (realName.equals("sign")) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
//请求中的userId没有放在body里面.所以不需要用来计算签名
|
||||||
|
if (realName.equals("userId")) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
modelName[i] = realName; |
||||||
|
// 获取属性类型
|
||||||
|
String type = field[i].getGenericType().toString(); |
||||||
|
modelType[i] = type; |
||||||
|
//关键。。。可访问私有变量
|
||||||
|
field[i].setAccessible(true); |
||||||
|
// 将属性的首字母大写
|
||||||
|
String laterName = realName.replaceFirst(realName.substring(0, 1), realName.substring(0, 1) |
||||||
|
.toUpperCase()); |
||||||
|
Log.e("name",realName); |
||||||
|
Method m = model.getClass().getMethod("get" + laterName); |
||||||
|
switch (type) { |
||||||
|
case "class java.lang.String": |
||||||
|
// 调用getter方法获取属性值
|
||||||
|
String valueString = (String) m.invoke(model); |
||||||
|
if (valueString != null) { |
||||||
|
valueMap.put(realName, valueString); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "int": |
||||||
|
int valueInt = (int) m.invoke(model); |
||||||
|
if (valueInt != -1) { |
||||||
|
valueMap.put(realName, valueInt + ""); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Integer": |
||||||
|
Integer valueInteger = (Integer) m.invoke(model); |
||||||
|
if (valueInteger != null && valueInteger != -1) { |
||||||
|
valueMap.put(realName, valueInteger.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Long": |
||||||
|
Long valueLong = (Long) m.invoke(model); |
||||||
|
if (valueLong != null && valueLong != -1) { |
||||||
|
valueMap.put(realName, valueLong.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Short": |
||||||
|
Short valueShort = (Short) m.invoke(model); |
||||||
|
if (valueShort != null) { |
||||||
|
valueMap.put(realName, valueShort.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Double": |
||||||
|
Double valueDouble = (Double) m.invoke(model); |
||||||
|
if (valueDouble != null) { |
||||||
|
valueMap.put(realName, valueDouble.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Boolean": |
||||||
|
Boolean valueBoolean = (Boolean) m.invoke(model); |
||||||
|
if (valueBoolean != null) { |
||||||
|
valueMap.put(realName, valueBoolean.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.util.Date": |
||||||
|
Date valueData = (Date) m.invoke(model); |
||||||
|
if (valueData != null) { |
||||||
|
valueMap.put(realName, valueData.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "java.util.ArrayList<java.lang.String>": |
||||||
|
ArrayList<String> valueAList = (ArrayList<String>) m.invoke(model); |
||||||
|
if (valueAList != null) { |
||||||
|
valueMap.put(realName, getListValue(valueAList)); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "java.util.List<java.lang.String>": |
||||||
|
List<String> valueList = (List<String>) m.invoke(model); |
||||||
|
if (valueList != null) { |
||||||
|
valueMap.put(realName, getListValue(valueList)); |
||||||
|
} |
||||||
|
break; |
||||||
|
default: |
||||||
|
if (m.invoke(model)==null){ |
||||||
|
continue; |
||||||
|
}else{ |
||||||
|
Gson gson = GsonManager.Companion.getInstance().getGson(); |
||||||
|
String value = gson.toJson(m.invoke(model)); |
||||||
|
valueMap.put(realName, value); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
return valueMap; |
||||||
|
} |
||||||
|
|
||||||
|
private HashMap<String, String> getClassInfo(Object model, boolean needUId) throws SecurityException, |
||||||
|
NoSuchMethodException, IllegalArgumentException, |
||||||
|
IllegalAccessException, InvocationTargetException, InstantiationException { |
||||||
|
HashMap<String, String> valueMap = new HashMap<>(); |
||||||
|
// 获取实体类的所有属性,返回Field数组
|
||||||
|
Field[] field = model.getClass().getDeclaredFields(); |
||||||
|
// 获取属性的名字
|
||||||
|
String[] modelName = new String[field.length]; |
||||||
|
String[] modelType = new String[field.length]; |
||||||
|
for (int i = 0; i < field.length; i++) { |
||||||
|
// 获取属性的名字
|
||||||
|
String realName = field[i].getName(); |
||||||
|
//这个是svn偷偷加上去的方法
|
||||||
|
//这个是svn偷偷加上去的方法
|
||||||
|
if (realName.startsWith("$")||realName.contains("serialVersionUID")){ |
||||||
|
continue; |
||||||
|
} |
||||||
|
//这个方法就是为了获取security,这里就不对其进行处理啦,但是所有的带加密的类,其加密属性的名称都必修为security
|
||||||
|
if (realName.equals("sign")) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
//请求中的userId没有放在body里面.所以不需要用来计算签名
|
||||||
|
if (!needUId && realName.equals("userId")) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
modelName[i] = realName; |
||||||
|
// 获取属性类型
|
||||||
|
String type = field[i].getGenericType().toString(); |
||||||
|
modelType[i] = type; |
||||||
|
//关键。。。可访问私有变量
|
||||||
|
field[i].setAccessible(true); |
||||||
|
// 将属性的首字母大写
|
||||||
|
String laterName = realName.replaceFirst(realName.substring(0, 1), realName.substring(0, 1) |
||||||
|
.toUpperCase()); |
||||||
|
Method m = model.getClass().getMethod("get" + laterName); |
||||||
|
switch (type) { |
||||||
|
case "class java.lang.String": |
||||||
|
// 调用getter方法获取属性值
|
||||||
|
String valueString = (String) m.invoke(model); |
||||||
|
if (valueString != null) { |
||||||
|
valueMap.put(realName, valueString); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "int": |
||||||
|
int valueInt = (int) m.invoke(model); |
||||||
|
if (valueInt != -1) { |
||||||
|
valueMap.put(realName, valueInt + ""); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Integer": |
||||||
|
Integer valueInteger = (Integer) m.invoke(model); |
||||||
|
if (valueInteger != null && valueInteger != -1) { |
||||||
|
valueMap.put(realName, valueInteger.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Long": |
||||||
|
Long valueLong = (Long) m.invoke(model); |
||||||
|
if (valueLong != null && valueLong != -1) { |
||||||
|
valueMap.put(realName, valueLong.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Short": |
||||||
|
Short valueShort = (Short) m.invoke(model); |
||||||
|
if (valueShort != null) { |
||||||
|
valueMap.put(realName, valueShort.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Double": |
||||||
|
Double valueDouble = (Double) m.invoke(model); |
||||||
|
if (valueDouble != null) { |
||||||
|
valueMap.put(realName, valueDouble.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.lang.Boolean": |
||||||
|
Boolean valueBoolean = (Boolean) m.invoke(model); |
||||||
|
if (valueBoolean != null) { |
||||||
|
valueMap.put(realName, valueBoolean.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "class java.util.Date": |
||||||
|
Date valueData = (Date) m.invoke(model); |
||||||
|
if (valueData != null) { |
||||||
|
valueMap.put(realName, valueData.toString()); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "java.util.ArrayList<java.lang.String>": |
||||||
|
ArrayList<String> valueAList = (ArrayList<String>) m.invoke(model); |
||||||
|
if (valueAList != null) { |
||||||
|
valueMap.put(realName, getListValue(valueAList)); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "java.util.List<java.lang.String>": |
||||||
|
List<String> valueList = (List<String>) m.invoke(model); |
||||||
|
if (valueList != null) { |
||||||
|
valueMap.put(realName, getListValue(valueList)); |
||||||
|
} |
||||||
|
break; |
||||||
|
default: |
||||||
|
Gson gson = GsonManager.Companion.getInstance().getGson(); |
||||||
|
String value = gson.toJson(m.invoke(model)); |
||||||
|
valueMap.put(realName, value); |
||||||
|
} |
||||||
|
} |
||||||
|
return valueMap; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private String getListValue(List<String> info) { |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
for (String s : info) { |
||||||
|
sb.append(s); |
||||||
|
sb.append(","); |
||||||
|
} |
||||||
|
sb.deleteCharAt(sb.length() - 1); |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
private String getListValue(ArrayList<String> info) { |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
for (String s : info) { |
||||||
|
sb.append(s); |
||||||
|
sb.append(","); |
||||||
|
} |
||||||
|
sb.deleteCharAt(sb.length() - 1); |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
// private String getListValue(ArrayList<String> info) {
|
||||||
|
// Gson gson=GsonManager.getInstance().getGson();
|
||||||
|
// return gson.toJson(info);
|
||||||
|
// }
|
||||||
|
|
||||||
|
private String getObjectValue(Object obj) { |
||||||
|
Gson gson = GsonManager.Companion.getInstance().getGson(); |
||||||
|
return gson.toJson(obj); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,109 @@ |
|||||||
|
package com.common_lib.base.utils; |
||||||
|
|
||||||
|
|
||||||
|
import android.util.Log; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 16/7/2. |
||||||
|
*/ |
||||||
|
public class SecurityUtils { |
||||||
|
private static final String securityKey = "2E8PObAj8HI45Qu9"; |
||||||
|
private MD5Utils md5Utils; |
||||||
|
private ObjectAnalysisUtils objUtils; |
||||||
|
|
||||||
|
private static SecurityUtils instance = null; |
||||||
|
|
||||||
|
private SecurityUtils() { |
||||||
|
md5Utils = MD5Utils.getInstance(); |
||||||
|
objUtils = ObjectAnalysisUtils.getInstance(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static synchronized SecurityUtils getInstance() { |
||||||
|
if (instance == null) { |
||||||
|
instance = new SecurityUtils(); |
||||||
|
} |
||||||
|
return instance; |
||||||
|
} |
||||||
|
|
||||||
|
public String getSecurity(String itemName, String itemValue) { |
||||||
|
return MD5Decode(itemName + "=" + itemValue); |
||||||
|
} |
||||||
|
|
||||||
|
public String getSecurity(Object obj) { |
||||||
|
HashMap<String, String> attributeMap = objUtils.analysObject(obj, false); |
||||||
|
String sortedInfo = sortMap(attributeMap); |
||||||
|
Log.e("securit", sortedInfo); |
||||||
|
if (isEmpty(sortedInfo)) { |
||||||
|
return null; |
||||||
|
} else { |
||||||
|
return MD5Decode(sortedInfo); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public String getSecurity(Object obj, Boolean needUserId) { |
||||||
|
HashMap<String, String> attributeMap = objUtils.analysObject(obj, needUserId); |
||||||
|
String sortedInfo = sortMap(attributeMap); |
||||||
|
if (isEmpty(sortedInfo)) { |
||||||
|
return null; |
||||||
|
} else { |
||||||
|
return MD5Decode(sortedInfo); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public String getSecurity(HashMap<String, String> map) { |
||||||
|
if (map == null || map.size() == 0) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
String sortedInfo = sortMap(map); |
||||||
|
if (isEmpty(sortedInfo)) { |
||||||
|
return null; |
||||||
|
} else { |
||||||
|
return MD5Decode(sortedInfo); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private String sortMap(HashMap<String, String> map) { |
||||||
|
if (map == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
Collection<String> keyset = map.keySet(); |
||||||
|
List<String> list = new ArrayList<>(keyset); |
||||||
|
//对key键值按字典升序排序
|
||||||
|
Collections.sort(list); |
||||||
|
|
||||||
|
for (String s : list) { |
||||||
|
sb.append(s); |
||||||
|
sb.append("="); |
||||||
|
sb.append(map.get(s)); |
||||||
|
sb.append("&"); |
||||||
|
} |
||||||
|
sb.deleteCharAt(sb.length() - 1); |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public String MD5Decode(String info) { |
||||||
|
String s1 = md5Utils.getMD5Result(info + securityKey); |
||||||
|
// if (isEmpty(s1)) {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// s1 = md5Utils.getMD5Result(s1 + securityKey);
|
||||||
|
return s1; |
||||||
|
} |
||||||
|
|
||||||
|
private boolean isEmpty(String info) { |
||||||
|
if (info == null || info.isEmpty()) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
package com.common_lib.base.utils; |
||||||
|
|
||||||
|
import android.annotation.TargetApi; |
||||||
|
import android.app.Activity; |
||||||
|
import android.content.Context; |
||||||
|
import android.graphics.Color; |
||||||
|
import android.os.Build; |
||||||
|
import android.view.View; |
||||||
|
import android.view.ViewGroup; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by JillFung on 16/12/14. |
||||||
|
*/ |
||||||
|
public class StatusBarCompatUtil { |
||||||
|
private static final int INVALID_VAL = -1; |
||||||
|
private static final int COLOR_DEFAULT = Color.parseColor("#20000000"); |
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP) |
||||||
|
public static void compat(Activity activity, int statusColor) { |
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
||||||
|
if (statusColor != INVALID_VAL) { |
||||||
|
activity.getWindow().setStatusBarColor(statusColor); |
||||||
|
} |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
||||||
|
int color = COLOR_DEFAULT; |
||||||
|
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); |
||||||
|
if (statusColor != INVALID_VAL) { |
||||||
|
color = statusColor; |
||||||
|
} |
||||||
|
View statusBarView = contentView.getChildAt(0); |
||||||
|
//改变颜色时避免重复添加statusBarView
|
||||||
|
if (statusBarView != null && statusBarView.getMeasuredHeight() == getStatusBarHeight(activity)) { |
||||||
|
statusBarView.setBackgroundColor(color); |
||||||
|
return; |
||||||
|
} |
||||||
|
statusBarView = new View(activity); |
||||||
|
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, |
||||||
|
getStatusBarHeight(activity)); |
||||||
|
statusBarView.setBackgroundColor(color); |
||||||
|
contentView.addView(statusBarView, lp); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public static void compat(Activity activity) { |
||||||
|
compat(activity, INVALID_VAL); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private static int getStatusBarHeight(Context context) { |
||||||
|
int result = 0; |
||||||
|
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); |
||||||
|
if (resourceId > 0) { |
||||||
|
result = context.getResources().getDimensionPixelSize(resourceId); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,94 @@ |
|||||||
|
package com.common_lib.base.utils; |
||||||
|
|
||||||
|
import com.common_lib.base.BaseConstants; |
||||||
|
import com.common_lib.base.GsonManager; |
||||||
|
import com.google.gson.Gson; |
||||||
|
import com.google.gson.reflect.TypeToken; |
||||||
|
|
||||||
|
import java.lang.reflect.Type; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用于处理一些奇奇怪怪的String类型转换的工具类 |
||||||
|
* Created by alex on 16/7/20. |
||||||
|
*/ |
||||||
|
public class StringUtils { |
||||||
|
//这个方法是用来处理服务端返回的url列表的
|
||||||
|
public static List<String> formatStringUrl(String imageContent) { |
||||||
|
List<String> res = null; |
||||||
|
if (imageContent == null || imageContent.isEmpty()) { |
||||||
|
return res; |
||||||
|
} |
||||||
|
Gson gson = GsonManager.Companion.getInstance().getGson(); |
||||||
|
Type listType = new TypeToken<ArrayList<String>>() { |
||||||
|
}.getType(); |
||||||
|
res = gson.fromJson(imageContent, listType); |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//这个方法是获取url列表的方法,这个方法就是
|
||||||
|
public static List<String> formatStringUrl(String imageContent, boolean addHead, int maxLength) { |
||||||
|
List<String> res; |
||||||
|
if (imageContent == null || imageContent.isEmpty()) { |
||||||
|
res = new ArrayList<>(); |
||||||
|
res.add(null); |
||||||
|
return res; |
||||||
|
} |
||||||
|
Gson gson = GsonManager.Companion.getInstance().getGson(); |
||||||
|
Type listType = new TypeToken<ArrayList<String>>() { |
||||||
|
}.getType(); |
||||||
|
res = gson.fromJson(imageContent, listType); |
||||||
|
if (res.size() > 0 && res.size() < maxLength) { |
||||||
|
if (addHead && res.get(res.size()-1) != null) { |
||||||
|
res.add(res.size(), null); |
||||||
|
} |
||||||
|
} else if(res.size()==maxLength){ |
||||||
|
return res; |
||||||
|
}else{ |
||||||
|
res = new ArrayList<>(); |
||||||
|
res.add(null); |
||||||
|
} |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
//这是将一个字符串的长度增大
|
||||||
|
public static String increaseGroupMessage(String msg) { |
||||||
|
StringBuilder builder = new StringBuilder(); |
||||||
|
builder.append(msg); |
||||||
|
while (builder.length() < 100) { |
||||||
|
builder.append(BaseConstants.EMPTY_STRING); |
||||||
|
} |
||||||
|
return builder.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
public static String formatList(List<String> info) { |
||||||
|
String res = null; |
||||||
|
List<String> infoList = new ArrayList<>(); |
||||||
|
for (int i = 0; i < info.size(); i++) { |
||||||
|
if (info.get(i) != null) { |
||||||
|
infoList.add(info.get(i)); |
||||||
|
} |
||||||
|
} |
||||||
|
if (infoList.size() > -1) { |
||||||
|
Gson gson = GsonManager.Companion.getInstance().getGson(); |
||||||
|
res = gson.toJson(infoList); |
||||||
|
} |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
//从图片的路径当中获取图片的名称
|
||||||
|
public static String getFileNameFromPath(String path) { |
||||||
|
String res; |
||||||
|
String[] s = path.split("/"); |
||||||
|
res = s[s.length - 1]; |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
package com.common_lib.base.utils; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
import android.widget.Toast; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Created by alex on 2016/3/2. |
||||||
|
*/ |
||||||
|
public class ToastUtils { |
||||||
|
public enum Duration {SHORT, LONG} |
||||||
|
|
||||||
|
private ToastUtils() { |
||||||
|
throw new AssertionError(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void showNormalToast(Context context, int stringResId) { |
||||||
|
showToast(context, stringResId, Duration.SHORT); |
||||||
|
} |
||||||
|
|
||||||
|
public static void showNormalToast(Context context, String text) { |
||||||
|
showToast(context, text, Duration.SHORT); |
||||||
|
} |
||||||
|
|
||||||
|
public static void showLongDurationToast(Context context, int stringResId) { |
||||||
|
showToast(context, stringResId, Duration.LONG); |
||||||
|
} |
||||||
|
|
||||||
|
public static void showLongDurationToast(Context context, String text) { |
||||||
|
showToast(context, text, Duration.LONG); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private static void showToast(Context context, int text, Duration duration) { |
||||||
|
Toast toast = Toast.makeText(context, text, |
||||||
|
(duration == Duration.SHORT ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG)); |
||||||
|
// toast.setGravity(Gravity.CENTER, 0, 0);
|
||||||
|
toast.show(); |
||||||
|
} |
||||||
|
|
||||||
|
private static void showToast(Context context, String text, Duration duration) { |
||||||
|
Toast toast = Toast.makeText(context, text, |
||||||
|
(duration == Duration.SHORT ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG)); |
||||||
|
// toast.setGravity(Gravity.BOTTOM, 0, 0);
|
||||||
|
toast.show(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,330 @@ |
|||||||
|
|
||||||
|
package com.common_lib.base.zxing.activity; |
||||||
|
|
||||||
|
import android.Manifest; |
||||||
|
import android.app.Activity; |
||||||
|
import android.app.AlertDialog; |
||||||
|
import android.content.DialogInterface; |
||||||
|
import android.content.Intent; |
||||||
|
import android.content.pm.PackageManager; |
||||||
|
import android.graphics.Rect; |
||||||
|
import android.os.Build; |
||||||
|
import android.os.Bundle; |
||||||
|
import android.os.Handler; |
||||||
|
import android.util.Log; |
||||||
|
import android.view.SurfaceHolder; |
||||||
|
import android.view.SurfaceView; |
||||||
|
import android.view.View; |
||||||
|
import android.view.Window; |
||||||
|
import android.view.WindowManager; |
||||||
|
import android.view.animation.Animation; |
||||||
|
import android.view.animation.TranslateAnimation; |
||||||
|
import android.widget.ImageView; |
||||||
|
import android.widget.RelativeLayout; |
||||||
|
|
||||||
|
import androidx.core.content.ContextCompat; |
||||||
|
|
||||||
|
import com.common_lib.base.utils.StatusBarCompatUtil; |
||||||
|
import com.common_lib.base.zxing.camera.CameraManager; |
||||||
|
import com.common_lib.base.zxing.decode.DecodeThread; |
||||||
|
import com.common_lib.common_lib.R; |
||||||
|
import com.google.zxing.Result; |
||||||
|
import com.common_lib.base.zxing.utils.BeepManager; |
||||||
|
import com.common_lib.base.zxing.utils.CaptureActivityHandler; |
||||||
|
import com.common_lib.base.zxing.utils.InactivityTimer; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.lang.reflect.Field; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public final class CaptureActivity extends Activity implements SurfaceHolder.Callback { |
||||||
|
|
||||||
|
private static final String TAG = CaptureActivity.class.getSimpleName(); |
||||||
|
private final int REQUEST_PERMISSIONS = 0; |
||||||
|
private CameraManager cameraManager; |
||||||
|
private CaptureActivityHandler handler; |
||||||
|
private InactivityTimer inactivityTimer; |
||||||
|
private BeepManager beepManager; |
||||||
|
|
||||||
|
private SurfaceView scanPreview = null; |
||||||
|
private RelativeLayout scanContainer; |
||||||
|
private RelativeLayout scanCropView; |
||||||
|
private ImageView scanLine; |
||||||
|
|
||||||
|
private Rect mCropRect = null; |
||||||
|
private boolean isHasSurface = false; |
||||||
|
|
||||||
|
public Handler getHandler() { |
||||||
|
return handler; |
||||||
|
} |
||||||
|
|
||||||
|
public CameraManager getCameraManager() { |
||||||
|
return cameraManager; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onCreate(Bundle icicle) { |
||||||
|
super.onCreate(icicle); |
||||||
|
Window window = getWindow(); |
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
||||||
|
StatusBarCompatUtil.compat(this, ContextCompat.getColor(this, R.color.half_transparent)); |
||||||
|
setContentView(R.layout.activity_capture); |
||||||
|
|
||||||
|
scanPreview = findViewById(R.id.capture_preview); |
||||||
|
scanContainer = findViewById(R.id.capture_container); |
||||||
|
scanCropView = findViewById(R.id.capture_crop_view); |
||||||
|
scanLine = findViewById(R.id.capture_scan_line); |
||||||
|
|
||||||
|
inactivityTimer = new InactivityTimer(this); |
||||||
|
beepManager = new BeepManager(this); |
||||||
|
|
||||||
|
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation |
||||||
|
.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f); |
||||||
|
animation.setDuration(4500); |
||||||
|
animation.setRepeatCount(-1); |
||||||
|
animation.setRepeatMode(Animation.RESTART); |
||||||
|
scanLine.startAnimation(animation); |
||||||
|
|
||||||
|
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() { |
||||||
|
@Override |
||||||
|
public void onClick(View v) { |
||||||
|
finish(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void onResume() { |
||||||
|
super.onResume(); |
||||||
|
checkPermission(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void onPause() { |
||||||
|
if (handler != null) { |
||||||
|
handler.quitSynchronously(); |
||||||
|
handler = null; |
||||||
|
} |
||||||
|
inactivityTimer.onPause(); |
||||||
|
beepManager.close(); |
||||||
|
cameraManager.closeDriver(); |
||||||
|
if (!isHasSurface) { |
||||||
|
scanPreview.getHolder().removeCallback(this); |
||||||
|
} |
||||||
|
super.onPause(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void onDestroy() { |
||||||
|
inactivityTimer.shutdown(); |
||||||
|
super.onDestroy(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void surfaceCreated(SurfaceHolder holder) { |
||||||
|
if (holder == null) { |
||||||
|
Log.e(TAG, "*** WARNING *** surfaceCreated() gave us a null surface!"); |
||||||
|
} |
||||||
|
if (!isHasSurface) { |
||||||
|
isHasSurface = true; |
||||||
|
initCamera(holder); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void surfaceDestroyed(SurfaceHolder holder) { |
||||||
|
isHasSurface = false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* A valid barcode has been found, so give an indication of success and show |
||||||
|
* the results. |
||||||
|
* |
||||||
|
* @param rawResult The contents of the barcode. |
||||||
|
* @param bundle The extras |
||||||
|
*/ |
||||||
|
public void handleDecode(Result rawResult, Bundle bundle) { |
||||||
|
inactivityTimer.onActivity(); |
||||||
|
beepManager.playBeepSoundAndVibrate(); |
||||||
|
|
||||||
|
Intent resultIntent = new Intent(); |
||||||
|
bundle.putInt("width", mCropRect.width()); |
||||||
|
bundle.putInt("height", mCropRect.height()); |
||||||
|
bundle.putString("result", rawResult.getText()); |
||||||
|
resultIntent.putExtras(bundle); |
||||||
|
this.setResult(RESULT_OK, resultIntent); |
||||||
|
// Toast.makeText(this, rawResult.getText(), Toast.LENGTH_SHORT).show();
|
||||||
|
// CaptureActivity.this.finish();
|
||||||
|
} |
||||||
|
|
||||||
|
private void initCamera(SurfaceHolder surfaceHolder) { |
||||||
|
if (surfaceHolder == null) { |
||||||
|
throw new IllegalStateException("No SurfaceHolder provided"); |
||||||
|
} |
||||||
|
if (cameraManager.isOpen()) { |
||||||
|
Log.w(TAG, "initCamera() while already open -- late SurfaceView callback?"); |
||||||
|
return; |
||||||
|
} |
||||||
|
try { |
||||||
|
cameraManager.openDriver(surfaceHolder); |
||||||
|
// Creating the handler starts the preview, which can also throw a
|
||||||
|
// RuntimeException.
|
||||||
|
if (handler == null) { |
||||||
|
handler = new CaptureActivityHandler(this, cameraManager, DecodeThread.ALL_MODE); |
||||||
|
} |
||||||
|
|
||||||
|
initCrop(); |
||||||
|
} catch (IOException ioe) { |
||||||
|
Log.w(TAG, ioe); |
||||||
|
displayFrameworkBugMessageAndExit(); |
||||||
|
} catch (RuntimeException e) { |
||||||
|
// Barcode Scanner has seen crashes in the wild of this variety:
|
||||||
|
// java.?lang.?RuntimeException: Fail to connect to camera service
|
||||||
|
Log.w(TAG, "Unexpected error initializing camera", e); |
||||||
|
displayFrameworkBugMessageAndExit(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void displayFrameworkBugMessageAndExit() { |
||||||
|
// camera error
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
||||||
|
builder.setTitle(getString(R.string.app_name)); |
||||||
|
builder.setMessage("Camera error"); |
||||||
|
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onClick(DialogInterface dialog, int which) { |
||||||
|
finish(); |
||||||
|
} |
||||||
|
|
||||||
|
}); |
||||||
|
builder.setOnCancelListener(new DialogInterface.OnCancelListener() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onCancel(DialogInterface dialog) { |
||||||
|
finish(); |
||||||
|
} |
||||||
|
}); |
||||||
|
builder.show(); |
||||||
|
} |
||||||
|
|
||||||
|
public void restartPreviewAfterDelay(long delayMS) { |
||||||
|
if (handler != null) { |
||||||
|
handler.sendEmptyMessageDelayed(R.id.restart_preview, delayMS); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public Rect getCropRect() { |
||||||
|
return mCropRect; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化截取的矩形区域 |
||||||
|
*/ |
||||||
|
private void initCrop() { |
||||||
|
int cameraWidth = cameraManager.getCameraResolution().y; |
||||||
|
int cameraHeight = cameraManager.getCameraResolution().x; |
||||||
|
|
||||||
|
/** 获取布局中扫描框的位置信息 */ |
||||||
|
int[] location = new int[2]; |
||||||
|
scanCropView.getLocationInWindow(location); |
||||||
|
|
||||||
|
int cropLeft = location[0]; |
||||||
|
int cropTop = location[1] - getStatusBarHeight(); |
||||||
|
|
||||||
|
int cropWidth = scanCropView.getWidth(); |
||||||
|
int cropHeight = scanCropView.getHeight(); |
||||||
|
|
||||||
|
/** 获取布局容器的宽高 */ |
||||||
|
int containerWidth = scanContainer.getWidth(); |
||||||
|
int containerHeight = scanContainer.getHeight(); |
||||||
|
|
||||||
|
/** 计算最终截取的矩形的左上角顶点x坐标 */ |
||||||
|
int x = cropLeft * cameraWidth / containerWidth; |
||||||
|
/** 计算最终截取的矩形的左上角顶点y坐标 */ |
||||||
|
int y = cropTop * cameraHeight / containerHeight; |
||||||
|
|
||||||
|
/** 计算最终截取的矩形的宽度 */ |
||||||
|
int width = cropWidth * cameraWidth / containerWidth; |
||||||
|
/** 计算最终截取的矩形的高度 */ |
||||||
|
int height = cropHeight * cameraHeight / containerHeight; |
||||||
|
|
||||||
|
/** 生成最终的截取的矩形 */ |
||||||
|
mCropRect = new Rect(x, y, width + x, height + y); |
||||||
|
} |
||||||
|
|
||||||
|
private int getStatusBarHeight() { |
||||||
|
try { |
||||||
|
Class<?> c = Class.forName("com.android.internal.R$dimen"); |
||||||
|
Object obj = c.newInstance(); |
||||||
|
Field field = c.getField("status_bar_height"); |
||||||
|
int x = Integer.parseInt(field.get(obj).toString()); |
||||||
|
return getResources().getDimensionPixelSize(x); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
private void checkPermission() { |
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
||||||
|
List<String> requestList = new ArrayList<>(); |
||||||
|
List<String> permissionsList = new ArrayList<>(); |
||||||
|
permissionsList.add(Manifest.permission.CAMERA); |
||||||
|
for (String permission : permissionsList) { |
||||||
|
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { |
||||||
|
requestList.add(permission); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (requestList.size() == 0) { |
||||||
|
lookCamera(); |
||||||
|
} else { |
||||||
|
requestPermissions(permissionsList.toArray(new String[permissionsList.size()]), |
||||||
|
REQUEST_PERMISSIONS); |
||||||
|
} |
||||||
|
} else { |
||||||
|
lookCamera(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void lookCamera() { |
||||||
|
cameraManager = new CameraManager(getApplication()); |
||||||
|
|
||||||
|
handler = null; |
||||||
|
|
||||||
|
if (isHasSurface) { |
||||||
|
// The activity was paused but not stopped, so the surface still
|
||||||
|
// exists. Therefore
|
||||||
|
// surfaceCreated() won't be called, so init the camera here.
|
||||||
|
initCamera(scanPreview.getHolder()); |
||||||
|
} else { |
||||||
|
// Install the callback and wait for surfaceCreated() to init the
|
||||||
|
// camera.
|
||||||
|
scanPreview.getHolder().addCallback(this); |
||||||
|
} |
||||||
|
|
||||||
|
inactivityTimer.onResume(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { |
||||||
|
switch (requestCode) { |
||||||
|
case REQUEST_PERMISSIONS: |
||||||
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
||||||
|
lookCamera(); |
||||||
|
} else { |
||||||
|
lookCamera(); |
||||||
|
} |
||||||
|
break; |
||||||
|
default: |
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,135 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2012 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.common_lib.base.zxing.camera; |
||||||
|
|
||||||
|
import android.annotation.SuppressLint; |
||||||
|
import android.content.Context; |
||||||
|
import android.hardware.Camera; |
||||||
|
import android.os.AsyncTask; |
||||||
|
import android.os.Build; |
||||||
|
import android.util.Log; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.concurrent.RejectedExecutionException; |
||||||
|
|
||||||
|
public class AutoFocusManager implements Camera.AutoFocusCallback { |
||||||
|
|
||||||
|
private static final String TAG = AutoFocusManager.class.getSimpleName(); |
||||||
|
|
||||||
|
private static final long AUTO_FOCUS_INTERVAL_MS = 2000L; |
||||||
|
private static final Collection<String> FOCUS_MODES_CALLING_AF; |
||||||
|
|
||||||
|
static { |
||||||
|
FOCUS_MODES_CALLING_AF = new ArrayList<String>(2); |
||||||
|
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_AUTO); |
||||||
|
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_MACRO); |
||||||
|
} |
||||||
|
|
||||||
|
private final boolean useAutoFocus; |
||||||
|
private final Camera camera; |
||||||
|
private boolean stopped; |
||||||
|
private boolean focusing; |
||||||
|
private AsyncTask<?, ?, ?> outstandingTask; |
||||||
|
|
||||||
|
public AutoFocusManager(Context context, Camera camera) { |
||||||
|
this.camera = camera; |
||||||
|
String currentFocusMode = camera.getParameters().getFocusMode(); |
||||||
|
useAutoFocus = FOCUS_MODES_CALLING_AF.contains(currentFocusMode); |
||||||
|
Log.i(TAG, "Current focus mode '" + currentFocusMode + "'; use auto focus? " + useAutoFocus); |
||||||
|
start(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public synchronized void onAutoFocus(boolean success, Camera theCamera) { |
||||||
|
focusing = false; |
||||||
|
autoFocusAgainLater(); |
||||||
|
} |
||||||
|
|
||||||
|
@SuppressLint("NewApi") |
||||||
|
private synchronized void autoFocusAgainLater() { |
||||||
|
if (!stopped && outstandingTask == null) { |
||||||
|
AutoFocusTask newTask = new AutoFocusTask(); |
||||||
|
try { |
||||||
|
if (Build.VERSION.SDK_INT >= 11) { |
||||||
|
newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
||||||
|
} else { |
||||||
|
newTask.execute(); |
||||||
|
} |
||||||
|
outstandingTask = newTask; |
||||||
|
} catch (RejectedExecutionException ree) { |
||||||
|
Log.w(TAG, "Could not request auto focus", ree); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized void start() { |
||||||
|
if (useAutoFocus) { |
||||||
|
outstandingTask = null; |
||||||
|
if (!stopped && !focusing) { |
||||||
|
try { |
||||||
|
camera.autoFocus(this); |
||||||
|
focusing = true; |
||||||
|
} catch (RuntimeException re) { |
||||||
|
// Have heard RuntimeException reported in Android 4.0.x+;
|
||||||
|
// continue?
|
||||||
|
Log.w(TAG, "Unexpected exception while focusing", re); |
||||||
|
// Try again later to keep cycle going
|
||||||
|
autoFocusAgainLater(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private synchronized void cancelOutstandingTask() { |
||||||
|
if (outstandingTask != null) { |
||||||
|
if (outstandingTask.getStatus() != AsyncTask.Status.FINISHED) { |
||||||
|
outstandingTask.cancel(true); |
||||||
|
} |
||||||
|
outstandingTask = null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized void stop() { |
||||||
|
stopped = true; |
||||||
|
if (useAutoFocus) { |
||||||
|
cancelOutstandingTask(); |
||||||
|
// Doesn't hurt to call this even if not focusing
|
||||||
|
try { |
||||||
|
camera.cancelAutoFocus(); |
||||||
|
} catch (RuntimeException re) { |
||||||
|
// Have heard RuntimeException reported in Android 4.0.x+;
|
||||||
|
// continue?
|
||||||
|
Log.w(TAG, "Unexpected exception while cancelling focusing", re); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private final class AutoFocusTask extends AsyncTask<Object, Object, Object> { |
||||||
|
@Override |
||||||
|
protected Object doInBackground(Object... voids) { |
||||||
|
try { |
||||||
|
Thread.sleep(AUTO_FOCUS_INTERVAL_MS); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
// continue
|
||||||
|
} |
||||||
|
start(); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,219 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2008 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.common_lib.base.zxing.camera; |
||||||
|
|
||||||
|
import android.annotation.SuppressLint; |
||||||
|
import android.content.Context; |
||||||
|
import android.graphics.Point; |
||||||
|
import android.hardware.Camera; |
||||||
|
import android.util.Log; |
||||||
|
import android.view.Display; |
||||||
|
import android.view.WindowManager; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.Comparator; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public final class CameraConfigurationManager { |
||||||
|
|
||||||
|
private static final String TAG = "CameraConfiguration"; |
||||||
|
|
||||||
|
private static final int MIN_PREVIEW_PIXELS = 480 * 320; |
||||||
|
private static final double MAX_ASPECT_DISTORTION = 0.15; |
||||||
|
|
||||||
|
private final Context context; |
||||||
|
|
||||||
|
// 屏幕分辨率
|
||||||
|
private Point screenResolution; |
||||||
|
// 相机分辨率
|
||||||
|
private Point cameraResolution; |
||||||
|
|
||||||
|
public CameraConfigurationManager(Context context) { |
||||||
|
this.context = context; |
||||||
|
} |
||||||
|
|
||||||
|
public void initFromCameraParameters(Camera camera) { |
||||||
|
Camera.Parameters parameters = camera.getParameters(); |
||||||
|
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
||||||
|
Display display = manager.getDefaultDisplay(); |
||||||
|
Point theScreenResolution = new Point(); |
||||||
|
theScreenResolution = getDisplaySize(display); |
||||||
|
|
||||||
|
screenResolution = theScreenResolution; |
||||||
|
Log.i(TAG, "Screen resolution: " + screenResolution); |
||||||
|
|
||||||
|
/** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */ |
||||||
|
Point screenResolutionForCamera = new Point(); |
||||||
|
screenResolutionForCamera.x = screenResolution.x; |
||||||
|
screenResolutionForCamera.y = screenResolution.y; |
||||||
|
|
||||||
|
if (screenResolution.x < screenResolution.y) { |
||||||
|
screenResolutionForCamera.x = screenResolution.y; |
||||||
|
screenResolutionForCamera.y = screenResolution.x; |
||||||
|
} |
||||||
|
|
||||||
|
cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera); |
||||||
|
Log.i(TAG, "Camera resolution x: " + cameraResolution.x); |
||||||
|
Log.i(TAG, "Camera resolution y: " + cameraResolution.y); |
||||||
|
} |
||||||
|
|
||||||
|
@SuppressWarnings("deprecation") |
||||||
|
@SuppressLint("NewApi") |
||||||
|
private Point getDisplaySize(final Display display) { |
||||||
|
final Point point = new Point(); |
||||||
|
try { |
||||||
|
display.getSize(point); |
||||||
|
} catch (NoSuchMethodError ignore) { |
||||||
|
point.x = display.getWidth(); |
||||||
|
point.y = display.getHeight(); |
||||||
|
} |
||||||
|
return point; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDesiredCameraParameters(Camera camera, boolean safeMode) { |
||||||
|
Camera.Parameters parameters = camera.getParameters(); |
||||||
|
|
||||||
|
if (parameters == null) { |
||||||
|
Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
Log.i(TAG, "Initial camera parameters: " + parameters.flatten()); |
||||||
|
|
||||||
|
if (safeMode) { |
||||||
|
Log.w(TAG, "In camera config safe mode -- most settings will not be honored"); |
||||||
|
} |
||||||
|
|
||||||
|
parameters.setPreviewSize(cameraResolution.x, cameraResolution.y); |
||||||
|
camera.setParameters(parameters); |
||||||
|
|
||||||
|
Camera.Parameters afterParameters = camera.getParameters(); |
||||||
|
Camera.Size afterSize = afterParameters.getPreviewSize(); |
||||||
|
if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize |
||||||
|
.height)) { |
||||||
|
Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + |
||||||
|
cameraResolution.y + ", but after setting it, preview size is " + afterSize.width + 'x' |
||||||
|
+ afterSize.height); |
||||||
|
cameraResolution.x = afterSize.width; |
||||||
|
cameraResolution.y = afterSize.height; |
||||||
|
} |
||||||
|
|
||||||
|
/** 设置相机预览为竖屏 */ |
||||||
|
camera.setDisplayOrientation(90); |
||||||
|
} |
||||||
|
|
||||||
|
public Point getCameraResolution() { |
||||||
|
return cameraResolution; |
||||||
|
} |
||||||
|
|
||||||
|
public Point getScreenResolution() { |
||||||
|
return screenResolution; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 从相机支持的分辨率中计算出最适合的预览界面尺寸 |
||||||
|
* |
||||||
|
* @param parameters |
||||||
|
* @param screenResolution |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { |
||||||
|
List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes(); |
||||||
|
if (rawSupportedSizes == null) { |
||||||
|
Log.w(TAG, "Device returned no supported preview sizes; using default"); |
||||||
|
Camera.Size defaultSize = parameters.getPreviewSize(); |
||||||
|
return new Point(defaultSize.width, defaultSize.height); |
||||||
|
} |
||||||
|
|
||||||
|
// Sort by size, descending
|
||||||
|
List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(rawSupportedSizes); |
||||||
|
Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() { |
||||||
|
@Override |
||||||
|
public int compare(Camera.Size a, Camera.Size b) { |
||||||
|
int aPixels = a.height * a.width; |
||||||
|
int bPixels = b.height * b.width; |
||||||
|
if (bPixels < aPixels) { |
||||||
|
return -1; |
||||||
|
} |
||||||
|
if (bPixels > aPixels) { |
||||||
|
return 1; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
if (Log.isLoggable(TAG, Log.INFO)) { |
||||||
|
StringBuilder previewSizesString = new StringBuilder(); |
||||||
|
for (Camera.Size supportedPreviewSize : supportedPreviewSizes) { |
||||||
|
previewSizesString.append(supportedPreviewSize.width).append('x').append |
||||||
|
(supportedPreviewSize.height).append(' '); |
||||||
|
} |
||||||
|
Log.i(TAG, "Supported preview sizes: " + previewSizesString); |
||||||
|
} |
||||||
|
|
||||||
|
double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y; |
||||||
|
|
||||||
|
// Remove sizes that are unsuitable
|
||||||
|
Iterator<Camera.Size> it = supportedPreviewSizes.iterator(); |
||||||
|
while (it.hasNext()) { |
||||||
|
Camera.Size supportedPreviewSize = it.next(); |
||||||
|
int realWidth = supportedPreviewSize.width; |
||||||
|
int realHeight = supportedPreviewSize.height; |
||||||
|
if (realWidth * realHeight < MIN_PREVIEW_PIXELS) { |
||||||
|
it.remove(); |
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
boolean isCandidatePortrait = realWidth < realHeight; |
||||||
|
int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth; |
||||||
|
int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight; |
||||||
|
|
||||||
|
double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight; |
||||||
|
double distortion = Math.abs(aspectRatio - screenAspectRatio); |
||||||
|
if (distortion > MAX_ASPECT_DISTORTION) { |
||||||
|
it.remove(); |
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { |
||||||
|
Point exactPoint = new Point(realWidth, realHeight); |
||||||
|
Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint); |
||||||
|
return exactPoint; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// If no exact match, use largest preview size. This was not a great
|
||||||
|
// idea on older devices because
|
||||||
|
// of the additional computation needed. We're likely to get here on
|
||||||
|
// newer Android 4+ devices, where
|
||||||
|
// the CPU is much more powerful.
|
||||||
|
if (!supportedPreviewSizes.isEmpty()) { |
||||||
|
Camera.Size largestPreview = supportedPreviewSizes.get(0); |
||||||
|
Point largestSize = new Point(largestPreview.width, largestPreview.height); |
||||||
|
Log.i(TAG, "Using largest suitable preview size: " + largestSize); |
||||||
|
return largestSize; |
||||||
|
} |
||||||
|
|
||||||
|
// If there is nothing at all suitable, return current preview size
|
||||||
|
Camera.Size defaultPreview = parameters.getPreviewSize(); |
||||||
|
Point defaultSize = new Point(defaultPreview.width, defaultPreview.height); |
||||||
|
Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize); |
||||||
|
|
||||||
|
return defaultSize; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,204 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2008 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.common_lib.base.zxing.camera; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
import android.graphics.Point; |
||||||
|
import android.hardware.Camera; |
||||||
|
import android.hardware.Camera.Size; |
||||||
|
import android.os.Handler; |
||||||
|
import android.util.Log; |
||||||
|
import android.view.SurfaceHolder; |
||||||
|
|
||||||
|
|
||||||
|
import com.common_lib.base.zxing.camera.open.OpenCameraInterface; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
/** |
||||||
|
* This object wraps the Camera service object and expects to be the only one |
||||||
|
* talking to it. The implementation encapsulates the steps needed to take |
||||||
|
* preview-sized images, which are used for both preview and decoding. |
||||||
|
* |
||||||
|
* @author dswitkin@google.com (Daniel Switkin) |
||||||
|
*/ |
||||||
|
public class CameraManager { |
||||||
|
|
||||||
|
private static final String TAG = CameraManager.class.getSimpleName(); |
||||||
|
|
||||||
|
private final Context context; |
||||||
|
private final CameraConfigurationManager configManager; |
||||||
|
/** |
||||||
|
* Preview frames are delivered here, which we pass on to the registered |
||||||
|
* handler. Make sure to clear the handler so it will only receive one |
||||||
|
* message. |
||||||
|
*/ |
||||||
|
private final PreviewCallback previewCallback; |
||||||
|
private Camera camera; |
||||||
|
private AutoFocusManager autoFocusManager; |
||||||
|
private boolean initialized; |
||||||
|
private boolean previewing; |
||||||
|
private int requestedCameraId = -1; |
||||||
|
|
||||||
|
public CameraManager(Context context) { |
||||||
|
this.context = context; |
||||||
|
this.configManager = new CameraConfigurationManager(context); |
||||||
|
previewCallback = new PreviewCallback(configManager); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Opens the camera driver and initializes the hardware parameters. |
||||||
|
* |
||||||
|
* @param holder The surface object which the camera will draw preview frames |
||||||
|
* into. |
||||||
|
* @throws IOException Indicates the camera driver failed to open. |
||||||
|
*/ |
||||||
|
public synchronized void openDriver(SurfaceHolder holder) throws IOException { |
||||||
|
Camera theCamera = camera; |
||||||
|
if (theCamera == null) { |
||||||
|
|
||||||
|
if (requestedCameraId >= 0) { |
||||||
|
theCamera = OpenCameraInterface.open(requestedCameraId); |
||||||
|
} else { |
||||||
|
theCamera = OpenCameraInterface.open(); |
||||||
|
} |
||||||
|
|
||||||
|
if (theCamera == null) { |
||||||
|
throw new IOException(); |
||||||
|
} |
||||||
|
camera = theCamera; |
||||||
|
} |
||||||
|
theCamera.setPreviewDisplay(holder); |
||||||
|
|
||||||
|
if (!initialized) { |
||||||
|
initialized = true; |
||||||
|
configManager.initFromCameraParameters(theCamera); |
||||||
|
} |
||||||
|
|
||||||
|
Camera.Parameters parameters = theCamera.getParameters(); |
||||||
|
String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
|
||||||
|
// these,
|
||||||
|
// temporarily
|
||||||
|
try { |
||||||
|
configManager.setDesiredCameraParameters(theCamera, false); |
||||||
|
} catch (RuntimeException re) { |
||||||
|
// Driver failed
|
||||||
|
Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters"); |
||||||
|
Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened); |
||||||
|
// Reset:
|
||||||
|
if (parametersFlattened != null) { |
||||||
|
parameters = theCamera.getParameters(); |
||||||
|
parameters.unflatten(parametersFlattened); |
||||||
|
try { |
||||||
|
theCamera.setParameters(parameters); |
||||||
|
configManager.setDesiredCameraParameters(theCamera, true); |
||||||
|
} catch (RuntimeException re2) { |
||||||
|
// Well, darn. Give up
|
||||||
|
Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public synchronized boolean isOpen() { |
||||||
|
return camera != null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Closes the camera driver if still in use. |
||||||
|
*/ |
||||||
|
public synchronized void closeDriver() { |
||||||
|
if (camera != null) { |
||||||
|
camera.release(); |
||||||
|
camera = null; |
||||||
|
// Make sure to clear these each time we close the camera, so that
|
||||||
|
// any scanning rect
|
||||||
|
// requested by intent is forgotten.
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Asks the camera hardware to begin drawing preview frames to the screen. |
||||||
|
*/ |
||||||
|
public synchronized void startPreview() { |
||||||
|
Camera theCamera = camera; |
||||||
|
if (theCamera != null && !previewing) { |
||||||
|
theCamera.startPreview(); |
||||||
|
previewing = true; |
||||||
|
autoFocusManager = new AutoFocusManager(context, camera); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Tells the camera to stop drawing preview frames. |
||||||
|
*/ |
||||||
|
public synchronized void stopPreview() { |
||||||
|
if (autoFocusManager != null) { |
||||||
|
autoFocusManager.stop(); |
||||||
|
autoFocusManager = null; |
||||||
|
} |
||||||
|
if (camera != null && previewing) { |
||||||
|
camera.stopPreview(); |
||||||
|
previewCallback.setHandler(null, 0); |
||||||
|
previewing = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* A single preview frame will be returned to the handler supplied. The data |
||||||
|
* will arrive as byte[] in the message.obj field, with width and height |
||||||
|
* encoded as message.arg1 and message.arg2, respectively. |
||||||
|
* |
||||||
|
* @param handler The handler to send the message to. |
||||||
|
* @param message The what field of the message to be sent. |
||||||
|
*/ |
||||||
|
public synchronized void requestPreviewFrame(Handler handler, int message) { |
||||||
|
Camera theCamera = camera; |
||||||
|
if (theCamera != null && previewing) { |
||||||
|
previewCallback.setHandler(handler, message); |
||||||
|
theCamera.setOneShotPreviewCallback(previewCallback); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Allows third party apps to specify the camera ID, rather than determine |
||||||
|
* it automatically based on available cameras and their orientation. |
||||||
|
* |
||||||
|
* @param cameraId camera ID of the camera to use. A negative value means |
||||||
|
* "no preference". |
||||||
|
*/ |
||||||
|
public synchronized void setManualCameraId(int cameraId) { |
||||||
|
requestedCameraId = cameraId; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取相机分辨率 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Point getCameraResolution() { |
||||||
|
return configManager.getCameraResolution(); |
||||||
|
} |
||||||
|
|
||||||
|
public Size getPreviewSize() { |
||||||
|
if (null != camera) { |
||||||
|
return camera.getParameters().getPreviewSize(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,56 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2010 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.common_lib.base.zxing.camera; |
||||||
|
|
||||||
|
import android.graphics.Point; |
||||||
|
import android.hardware.Camera; |
||||||
|
import android.os.Handler; |
||||||
|
import android.os.Message; |
||||||
|
import android.util.Log; |
||||||
|
|
||||||
|
public class PreviewCallback implements Camera.PreviewCallback { |
||||||
|
|
||||||
|
private static final String TAG = PreviewCallback.class.getSimpleName(); |
||||||
|
|
||||||
|
private final CameraConfigurationManager configManager; |
||||||
|
private Handler previewHandler; |
||||||
|
private int previewMessage; |
||||||
|
|
||||||
|
public PreviewCallback(CameraConfigurationManager configManager) { |
||||||
|
this.configManager = configManager; |
||||||
|
} |
||||||
|
|
||||||
|
public void setHandler(Handler previewHandler, int previewMessage) { |
||||||
|
this.previewHandler = previewHandler; |
||||||
|
this.previewMessage = previewMessage; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onPreviewFrame(byte[] data, Camera camera) { |
||||||
|
Point cameraResolution = configManager.getCameraResolution(); |
||||||
|
Handler thePreviewHandler = previewHandler; |
||||||
|
if (cameraResolution != null && thePreviewHandler != null) { |
||||||
|
Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x, |
||||||
|
cameraResolution.y, data); |
||||||
|
message.sendToTarget(); |
||||||
|
previewHandler = null; |
||||||
|
} else { |
||||||
|
Log.d(TAG, "Got preview callback, but no handler or resolution available"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,85 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2012 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.common_lib.base.zxing.camera.open; |
||||||
|
|
||||||
|
import android.hardware.Camera; |
||||||
|
import android.util.Log; |
||||||
|
|
||||||
|
public class OpenCameraInterface { |
||||||
|
|
||||||
|
private static final String TAG = OpenCameraInterface.class.getName(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Opens the requested camera with {@link Camera#open(int)}, if one exists. |
||||||
|
* |
||||||
|
* @param cameraId camera ID of the camera to use. A negative value means |
||||||
|
* "no preference" |
||||||
|
* @return handle to {@link Camera} that was opened |
||||||
|
*/ |
||||||
|
public static Camera open(int cameraId) { |
||||||
|
|
||||||
|
int numCameras = Camera.getNumberOfCameras(); |
||||||
|
if (numCameras == 0) { |
||||||
|
Log.w(TAG, "No cameras!"); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
boolean explicitRequest = cameraId >= 0; |
||||||
|
|
||||||
|
if (!explicitRequest) { |
||||||
|
// Select a camera if no explicit camera requested
|
||||||
|
int index = 0; |
||||||
|
while (index < numCameras) { |
||||||
|
Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); |
||||||
|
Camera.getCameraInfo(index, cameraInfo); |
||||||
|
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { |
||||||
|
break; |
||||||
|
} |
||||||
|
index++; |
||||||
|
} |
||||||
|
|
||||||
|
cameraId = index; |
||||||
|
} |
||||||
|
|
||||||
|
Camera camera; |
||||||
|
if (cameraId < numCameras) { |
||||||
|
Log.i(TAG, "Opening camera #" + cameraId); |
||||||
|
camera = Camera.open(cameraId); |
||||||
|
} else { |
||||||
|
if (explicitRequest) { |
||||||
|
Log.w(TAG, "Requested camera does not exist: " + cameraId); |
||||||
|
camera = null; |
||||||
|
} else { |
||||||
|
Log.i(TAG, "No camera facing back; returning camera #0"); |
||||||
|
camera = Camera.open(0); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return camera; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Opens a rear-facing camera with {@link Camera#open(int)}, if one exists, |
||||||
|
* or opens camera 0. |
||||||
|
* |
||||||
|
* @return handle to {@link Camera} that was opened |
||||||
|
*/ |
||||||
|
public static Camera open() { |
||||||
|
return open(-1); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2010 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.common_lib.base.zxing.decode; |
||||||
|
|
||||||
|
import com.google.zxing.BarcodeFormat; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
import java.util.EnumSet; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
public class DecodeFormatManager { |
||||||
|
|
||||||
|
// 1D解码
|
||||||
|
private static final Set<BarcodeFormat> PRODUCT_FORMATS; |
||||||
|
private static final Set<BarcodeFormat> INDUSTRIAL_FORMATS; |
||||||
|
private static final Set<BarcodeFormat> ONE_D_FORMATS; |
||||||
|
|
||||||
|
// 二维码解码
|
||||||
|
private static final Set<BarcodeFormat> QR_CODE_FORMATS; |
||||||
|
|
||||||
|
static { |
||||||
|
PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A, BarcodeFormat.UPC_E, BarcodeFormat.EAN_13, |
||||||
|
BarcodeFormat.EAN_8, BarcodeFormat.RSS_14, BarcodeFormat.RSS_EXPANDED); |
||||||
|
INDUSTRIAL_FORMATS = EnumSet.of(BarcodeFormat.CODE_39, BarcodeFormat.CODE_93, BarcodeFormat |
||||||
|
.CODE_128, BarcodeFormat.ITF, BarcodeFormat.CODABAR); |
||||||
|
ONE_D_FORMATS = EnumSet.copyOf(PRODUCT_FORMATS); |
||||||
|
ONE_D_FORMATS.addAll(INDUSTRIAL_FORMATS); |
||||||
|
|
||||||
|
QR_CODE_FORMATS = EnumSet.of(BarcodeFormat.QR_CODE); |
||||||
|
} |
||||||
|
|
||||||
|
public static Collection<BarcodeFormat> getQrCodeFormats() { |
||||||
|
return QR_CODE_FORMATS; |
||||||
|
} |
||||||
|
|
||||||
|
public static Collection<BarcodeFormat> getBarCodeFormats() { |
||||||
|
return ONE_D_FORMATS; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,137 @@ |
|||||||
|
|
||||||
|
package com.common_lib.base.zxing.decode; |
||||||
|
|
||||||
|
import android.graphics.Bitmap; |
||||||
|
import android.graphics.Rect; |
||||||
|
import android.hardware.Camera.Size; |
||||||
|
import android.os.Bundle; |
||||||
|
import android.os.Handler; |
||||||
|
import android.os.Looper; |
||||||
|
import android.os.Message; |
||||||
|
|
||||||
|
import com.common_lib.common_lib.R; |
||||||
|
import com.google.zxing.BinaryBitmap; |
||||||
|
import com.google.zxing.DecodeHintType; |
||||||
|
import com.google.zxing.MultiFormatReader; |
||||||
|
import com.google.zxing.PlanarYUVLuminanceSource; |
||||||
|
import com.google.zxing.ReaderException; |
||||||
|
import com.google.zxing.Result; |
||||||
|
import com.google.zxing.common.HybridBinarizer; |
||||||
|
import com.common_lib.base.zxing.activity.CaptureActivity; |
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class DecodeHandler extends Handler { |
||||||
|
|
||||||
|
private final CaptureActivity activity; |
||||||
|
private final MultiFormatReader multiFormatReader; |
||||||
|
private boolean running = true; |
||||||
|
|
||||||
|
public DecodeHandler(CaptureActivity activity, Map<DecodeHintType, Object> hints) { |
||||||
|
multiFormatReader = new MultiFormatReader(); |
||||||
|
multiFormatReader.setHints(hints); |
||||||
|
this.activity = activity; |
||||||
|
} |
||||||
|
|
||||||
|
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) { |
||||||
|
int[] pixels = source.renderThumbnail(); |
||||||
|
int width = source.getThumbnailWidth(); |
||||||
|
int height = source.getThumbnailHeight(); |
||||||
|
Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888); |
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
||||||
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out); |
||||||
|
bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handleMessage(Message message) { |
||||||
|
if (!running) { |
||||||
|
return; |
||||||
|
} |
||||||
|
if (message.what == R.id.decode) { |
||||||
|
decode((byte[]) message.obj, message.arg1, message.arg2); |
||||||
|
|
||||||
|
} else if (message.what == R.id.quit) { |
||||||
|
running = false; |
||||||
|
Looper.myLooper().quit(); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Decode the data within the viewfinder rectangle, and time how long it |
||||||
|
* took. For efficiency, reuse the same reader objects from one decode to |
||||||
|
* the next. |
||||||
|
* |
||||||
|
* @param data The YUV preview frame. |
||||||
|
* @param width The width of the preview frame. |
||||||
|
* @param height The height of the preview frame. |
||||||
|
*/ |
||||||
|
private void decode(byte[] data, int width, int height) { |
||||||
|
Size size = activity.getCameraManager().getPreviewSize(); |
||||||
|
|
||||||
|
// 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据
|
||||||
|
byte[] rotatedData = new byte[data.length]; |
||||||
|
for (int y = 0; y < size.height; y++) { |
||||||
|
for (int x = 0; x < size.width; x++) |
||||||
|
rotatedData[x * size.height + size.height - y - 1] = data[x + y * size.width]; |
||||||
|
} |
||||||
|
|
||||||
|
// 宽高也要调整
|
||||||
|
int tmp = size.width; |
||||||
|
size.width = size.height; |
||||||
|
size.height = tmp; |
||||||
|
|
||||||
|
Result rawResult = null; |
||||||
|
PlanarYUVLuminanceSource source = buildLuminanceSource(rotatedData, size.width, size.height); |
||||||
|
if (source != null) { |
||||||
|
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); |
||||||
|
try { |
||||||
|
rawResult = multiFormatReader.decodeWithState(bitmap); |
||||||
|
} catch (ReaderException re) { |
||||||
|
// continue
|
||||||
|
} finally { |
||||||
|
multiFormatReader.reset(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
Handler handler = activity.getHandler(); |
||||||
|
if (rawResult != null) { |
||||||
|
// Don't log the barcode contents for security.
|
||||||
|
if (handler != null) { |
||||||
|
Message message = Message.obtain(handler, R.id.decode_succeeded, rawResult); |
||||||
|
Bundle bundle = new Bundle(); |
||||||
|
bundleThumbnail(source, bundle); |
||||||
|
message.setData(bundle); |
||||||
|
message.sendToTarget(); |
||||||
|
} |
||||||
|
} else { |
||||||
|
if (handler != null) { |
||||||
|
Message message = Message.obtain(handler, R.id.decode_failed); |
||||||
|
message.sendToTarget(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* A factory method to build the appropriate LuminanceSource object based on |
||||||
|
* the format of the preview buffers, as described by Camera.Parameters. |
||||||
|
* |
||||||
|
* @param data A preview frame. |
||||||
|
* @param width The width of the image. |
||||||
|
* @param height The height of the image. |
||||||
|
* @return A PlanarYUVLuminanceSource instance. |
||||||
|
*/ |
||||||
|
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) { |
||||||
|
Rect rect = activity.getCropRect(); |
||||||
|
if (rect == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
// Go ahead and assume it's YUV rather than die.
|
||||||
|
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect |
||||||
|
.height(), false); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2008 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.common_lib.base.zxing.decode; |
||||||
|
|
||||||
|
import android.os.Handler; |
||||||
|
import android.os.Looper; |
||||||
|
|
||||||
|
import com.google.zxing.BarcodeFormat; |
||||||
|
import com.google.zxing.DecodeHintType; |
||||||
|
import com.common_lib.base.zxing.activity.CaptureActivity; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.EnumMap; |
||||||
|
import java.util.EnumSet; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.CountDownLatch; |
||||||
|
|
||||||
|
|
||||||
|
public class DecodeThread extends Thread { |
||||||
|
|
||||||
|
public static final String BARCODE_BITMAP = "barcode_bitmap"; |
||||||
|
|
||||||
|
public static final int BARCODE_MODE = 0X100; |
||||||
|
public static final int QRCODE_MODE = 0X200; |
||||||
|
public static final int ALL_MODE = 0X300; |
||||||
|
|
||||||
|
private final CaptureActivity activity; |
||||||
|
private final Map<DecodeHintType, Object> hints; |
||||||
|
private final CountDownLatch handlerInitLatch; |
||||||
|
private Handler handler; |
||||||
|
|
||||||
|
public DecodeThread(CaptureActivity activity, int decodeMode) { |
||||||
|
|
||||||
|
this.activity = activity; |
||||||
|
handlerInitLatch = new CountDownLatch(1); |
||||||
|
|
||||||
|
hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class); |
||||||
|
|
||||||
|
Collection<BarcodeFormat> decodeFormats = new ArrayList<BarcodeFormat>(); |
||||||
|
decodeFormats.addAll(EnumSet.of(BarcodeFormat.AZTEC)); |
||||||
|
decodeFormats.addAll(EnumSet.of(BarcodeFormat.PDF_417)); |
||||||
|
|
||||||
|
switch (decodeMode) { |
||||||
|
case BARCODE_MODE: |
||||||
|
decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats()); |
||||||
|
break; |
||||||
|
|
||||||
|
case QRCODE_MODE: |
||||||
|
decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats()); |
||||||
|
break; |
||||||
|
|
||||||
|
case ALL_MODE: |
||||||
|
decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats()); |
||||||
|
decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats()); |
||||||
|
break; |
||||||
|
|
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); |
||||||
|
} |
||||||
|
|
||||||
|
public Handler getHandler() { |
||||||
|
try { |
||||||
|
handlerInitLatch.await(); |
||||||
|
} catch (InterruptedException ie) { |
||||||
|
// continue?
|
||||||
|
} |
||||||
|
return handler; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
Looper.prepare(); |
||||||
|
handler = new DecodeHandler(activity, hints); |
||||||
|
handlerInitLatch.countDown(); |
||||||
|
Looper.loop(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,229 @@ |
|||||||
|
package com.common_lib.base.zxing.encoding; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
import android.graphics.Bitmap; |
||||||
|
import android.graphics.Canvas; |
||||||
|
import android.graphics.Color; |
||||||
|
import android.graphics.PointF; |
||||||
|
import android.view.Gravity; |
||||||
|
import android.view.View; |
||||||
|
import android.widget.LinearLayout; |
||||||
|
import android.widget.TextView; |
||||||
|
|
||||||
|
import com.google.zxing.BarcodeFormat; |
||||||
|
import com.google.zxing.EncodeHintType; |
||||||
|
import com.google.zxing.MultiFormatWriter; |
||||||
|
import com.google.zxing.WriterException; |
||||||
|
import com.google.zxing.common.BitMatrix; |
||||||
|
import com.google.zxing.qrcode.QRCodeWriter; |
||||||
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 二维码生成工具类 |
||||||
|
*/ |
||||||
|
public class EncodingUtils { |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建二维码 |
||||||
|
* |
||||||
|
* @param content content |
||||||
|
* @param widthPix widthPix |
||||||
|
* @param heightPix heightPix |
||||||
|
* @param logoBm logoBm |
||||||
|
* @return 二维码 |
||||||
|
*/ |
||||||
|
public static Bitmap createQRCode(String content, int widthPix, int heightPix, Bitmap logoBm) { |
||||||
|
try { |
||||||
|
if (content == null || "".equals(content)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
// 配置参数
|
||||||
|
Map<EncodeHintType, Object> hints = new HashMap<>(); |
||||||
|
hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); |
||||||
|
// 容错级别
|
||||||
|
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); |
||||||
|
// 图像数据转换,使用了矩阵转换
|
||||||
|
BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix, |
||||||
|
heightPix, hints); |
||||||
|
int[] pixels = new int[widthPix * heightPix]; |
||||||
|
// 下面这里按照二维码的算法,逐个生成二维码的图片,
|
||||||
|
// 两个for循环是图片横列扫描的结果
|
||||||
|
for (int y = 0; y < heightPix; y++) { |
||||||
|
for (int x = 0; x < widthPix; x++) { |
||||||
|
if (bitMatrix.get(x, y)) { |
||||||
|
pixels[y * widthPix + x] = 0xff000000; |
||||||
|
} else { |
||||||
|
pixels[y * widthPix + x] = 0xffffffff; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
// 生成二维码图片的格式,使用ARGB_8888
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888); |
||||||
|
bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix); |
||||||
|
if (logoBm != null) { |
||||||
|
bitmap = addLogo(bitmap, logoBm); |
||||||
|
} |
||||||
|
//必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的,内存消耗巨大!
|
||||||
|
return bitmap; |
||||||
|
} catch (WriterException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 在二维码中间添加Logo图案 |
||||||
|
*/ |
||||||
|
private static Bitmap addLogo(Bitmap src, Bitmap logo) { |
||||||
|
if (src == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
if (logo == null) { |
||||||
|
return src; |
||||||
|
} |
||||||
|
//获取图片的宽高
|
||||||
|
int srcWidth = src.getWidth(); |
||||||
|
int srcHeight = src.getHeight(); |
||||||
|
int logoWidth = logo.getWidth(); |
||||||
|
int logoHeight = logo.getHeight(); |
||||||
|
if (srcWidth == 0 || srcHeight == 0) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
if (logoWidth == 0 || logoHeight == 0) { |
||||||
|
return src; |
||||||
|
} |
||||||
|
//logo大小为二维码整体大小的1/5
|
||||||
|
float scaleFactor = srcWidth * 1.0f / 5 / logoWidth; |
||||||
|
Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888); |
||||||
|
try { |
||||||
|
Canvas canvas = new Canvas(bitmap); |
||||||
|
canvas.drawBitmap(src, 0, 0, null); |
||||||
|
canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2); |
||||||
|
canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null); |
||||||
|
canvas.save(); |
||||||
|
canvas.restore(); |
||||||
|
} catch (Exception e) { |
||||||
|
bitmap = null; |
||||||
|
e.getStackTrace(); |
||||||
|
} |
||||||
|
return bitmap; |
||||||
|
} |
||||||
|
/* |
||||||
|
* 创建条形码 |
||||||
|
* @param content 内容 |
||||||
|
* @param width1 宽度 |
||||||
|
* @param height1 高度 |
||||||
|
* @param displayCode 是否显示内容 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Bitmap createBarcode(Context context, String contents, |
||||||
|
int desiredWidth, int desiredHeight, boolean displayCode) { |
||||||
|
Bitmap ruseltBitmap = null; |
||||||
|
BarcodeFormat barcodeFormat = BarcodeFormat.CODE_128; |
||||||
|
if (displayCode) { |
||||||
|
Bitmap barcodeBitmap = encodeAsBitmap(contents,barcodeFormat, |
||||||
|
desiredWidth, desiredHeight); |
||||||
|
Bitmap codeBitmap = creatCodeBitmap(contents, 13.0f,desiredWidth, context); |
||||||
|
ruseltBitmap = mixtureBitmap(barcodeBitmap, codeBitmap, new PointF( |
||||||
|
0, desiredHeight)); |
||||||
|
} else { |
||||||
|
ruseltBitmap = encodeAsBitmap(contents,barcodeFormat, |
||||||
|
desiredWidth, desiredHeight); |
||||||
|
} |
||||||
|
|
||||||
|
return ruseltBitmap; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建普通条形码 |
||||||
|
* @param contents |
||||||
|
* @param format |
||||||
|
* @param desiredWidth |
||||||
|
* @param desiredHeight |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
protected static Bitmap encodeAsBitmap(String contents, |
||||||
|
BarcodeFormat format, int desiredWidth, int desiredHeight) { |
||||||
|
final int WHITE = 0xFFFFFFFF; |
||||||
|
final int BLACK = 0xFF000000; |
||||||
|
|
||||||
|
MultiFormatWriter writer = new MultiFormatWriter(); |
||||||
|
BitMatrix result = null; |
||||||
|
try { |
||||||
|
result = writer.encode(contents, format, desiredWidth, |
||||||
|
desiredHeight, null); |
||||||
|
} catch (WriterException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
int width = result.getWidth(); |
||||||
|
int height = result.getHeight(); |
||||||
|
int[] pixels = new int[width * height]; |
||||||
|
// All are 0, or black, by default
|
||||||
|
for (int y = 0; y < height; y++) { |
||||||
|
int offset = y * width; |
||||||
|
for (int x = 0; x < width; x++) { |
||||||
|
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(width, height, |
||||||
|
Bitmap.Config.ARGB_8888); |
||||||
|
bitmap.setPixels(pixels, 0, width, 0, 0, width, height); |
||||||
|
return bitmap; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 显示内容 |
||||||
|
* @param contents |
||||||
|
* @param textsize |
||||||
|
* @param width |
||||||
|
* @param context |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
protected static Bitmap creatCodeBitmap(String contents, float textsize,int width, Context context) { |
||||||
|
TextView tv = new TextView(context); |
||||||
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( |
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
||||||
|
tv.setLayoutParams(layoutParams); |
||||||
|
tv.setText(contents); |
||||||
|
tv.setWidth(width); |
||||||
|
tv.setGravity(Gravity.CENTER_HORIZONTAL); |
||||||
|
tv.setTextSize(textsize); |
||||||
|
tv.setDrawingCacheEnabled(true); |
||||||
|
tv.setTextColor(Color.BLACK); |
||||||
|
tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), |
||||||
|
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); |
||||||
|
tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); |
||||||
|
tv.buildDrawingCache(); |
||||||
|
Bitmap bitmapCode = tv.getDrawingCache(); |
||||||
|
return bitmapCode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 混合条形码 |
||||||
|
* @param first |
||||||
|
* @param second |
||||||
|
* @param fromPoint |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
protected static Bitmap mixtureBitmap(Bitmap first, Bitmap second, |
||||||
|
PointF fromPoint) { |
||||||
|
if (first == null || second == null || fromPoint == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
Bitmap newBitmap = Bitmap.createBitmap( |
||||||
|
first.getWidth() , |
||||||
|
first.getHeight() + second.getHeight(), Bitmap.Config.ARGB_4444); |
||||||
|
Canvas cv = new Canvas(newBitmap); |
||||||
|
cv.drawBitmap(first, 0, 0, null); |
||||||
|
cv.drawBitmap(second, fromPoint.x, fromPoint.y, null); |
||||||
|
cv.save(); |
||||||
|
cv.restore(); |
||||||
|
|
||||||
|
return newBitmap; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,139 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2010 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.common_lib.base.zxing.utils; |
||||||
|
|
||||||
|
import android.app.Activity; |
||||||
|
import android.content.Context; |
||||||
|
import android.content.SharedPreferences; |
||||||
|
import android.content.res.AssetFileDescriptor; |
||||||
|
import android.media.AudioManager; |
||||||
|
import android.media.MediaPlayer; |
||||||
|
import android.os.Vibrator; |
||||||
|
import android.preference.PreferenceManager; |
||||||
|
import android.util.Log; |
||||||
|
|
||||||
|
|
||||||
|
import com.common_lib.common_lib.R; |
||||||
|
|
||||||
|
import java.io.Closeable; |
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
public class BeepManager implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, Closeable { |
||||||
|
|
||||||
|
private static final String TAG = BeepManager.class.getSimpleName(); |
||||||
|
|
||||||
|
private static final float BEEP_VOLUME = 0.10f; |
||||||
|
private static final long VIBRATE_DURATION = 200L; |
||||||
|
|
||||||
|
private final Activity activity; |
||||||
|
private MediaPlayer mediaPlayer; |
||||||
|
private boolean playBeep; |
||||||
|
private boolean vibrate; |
||||||
|
|
||||||
|
public BeepManager(Activity activity) { |
||||||
|
this.activity = activity; |
||||||
|
this.mediaPlayer = null; |
||||||
|
updatePrefs(); |
||||||
|
} |
||||||
|
|
||||||
|
private static boolean shouldBeep(SharedPreferences prefs, Context activity) { |
||||||
|
boolean shouldPlayBeep = true; |
||||||
|
if (shouldPlayBeep) { |
||||||
|
// See if sound settings overrides this
|
||||||
|
AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); |
||||||
|
if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { |
||||||
|
shouldPlayBeep = false; |
||||||
|
} |
||||||
|
} |
||||||
|
return shouldPlayBeep; |
||||||
|
} |
||||||
|
|
||||||
|
private synchronized void updatePrefs() { |
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); |
||||||
|
playBeep = shouldBeep(prefs, activity); |
||||||
|
vibrate = true; |
||||||
|
if (playBeep && mediaPlayer == null) { |
||||||
|
// The volume on STREAM_SYSTEM is not adjustable, and users found it
|
||||||
|
// too loud,
|
||||||
|
// so we now play on the music stream.
|
||||||
|
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); |
||||||
|
mediaPlayer = buildMediaPlayer(activity); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized void playBeepSoundAndVibrate() { |
||||||
|
if (playBeep && mediaPlayer != null) { |
||||||
|
mediaPlayer.start(); |
||||||
|
} |
||||||
|
if (vibrate) { |
||||||
|
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); |
||||||
|
vibrator.vibrate(VIBRATE_DURATION); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private MediaPlayer buildMediaPlayer(Context activity) { |
||||||
|
MediaPlayer mediaPlayer = new MediaPlayer(); |
||||||
|
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); |
||||||
|
mediaPlayer.setOnCompletionListener(this); |
||||||
|
mediaPlayer.setOnErrorListener(this); |
||||||
|
try { |
||||||
|
AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep); |
||||||
|
try { |
||||||
|
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength()); |
||||||
|
} finally { |
||||||
|
file.close(); |
||||||
|
} |
||||||
|
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); |
||||||
|
mediaPlayer.prepare(); |
||||||
|
return mediaPlayer; |
||||||
|
} catch (IOException ioe) { |
||||||
|
Log.w(TAG, ioe); |
||||||
|
mediaPlayer.release(); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onCompletion(MediaPlayer mp) { |
||||||
|
// When the beep has finished playing, rewind to queue up another one.
|
||||||
|
mp.seekTo(0); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public synchronized boolean onError(MediaPlayer mp, int what, int extra) { |
||||||
|
if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) { |
||||||
|
// we are finished, so put up an appropriate error toast if required
|
||||||
|
// and finish
|
||||||
|
activity.finish(); |
||||||
|
} else { |
||||||
|
// possibly media player error, so release and recreate
|
||||||
|
mp.release(); |
||||||
|
mediaPlayer = null; |
||||||
|
updatePrefs(); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public synchronized void close() { |
||||||
|
if (mediaPlayer != null) { |
||||||
|
mediaPlayer.release(); |
||||||
|
mediaPlayer = null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,103 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2008 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.common_lib.base.zxing.utils; |
||||||
|
|
||||||
|
import android.app.Activity; |
||||||
|
import android.content.Intent; |
||||||
|
import android.os.Bundle; |
||||||
|
import android.os.Handler; |
||||||
|
import android.os.Message; |
||||||
|
|
||||||
|
import com.common_lib.base.zxing.activity.CaptureActivity; |
||||||
|
import com.common_lib.base.zxing.camera.CameraManager; |
||||||
|
import com.common_lib.base.zxing.decode.DecodeThread; |
||||||
|
import com.common_lib.common_lib.R; |
||||||
|
import com.google.zxing.Result; |
||||||
|
|
||||||
|
public class CaptureActivityHandler extends Handler { |
||||||
|
|
||||||
|
private final CaptureActivity activity; |
||||||
|
private final DecodeThread decodeThread; |
||||||
|
private final CameraManager cameraManager; |
||||||
|
private State state; |
||||||
|
|
||||||
|
public CaptureActivityHandler(CaptureActivity activity, CameraManager cameraManager, int decodeMode) { |
||||||
|
this.activity = activity; |
||||||
|
decodeThread = new DecodeThread(activity, decodeMode); |
||||||
|
decodeThread.start(); |
||||||
|
state = State.SUCCESS; |
||||||
|
|
||||||
|
// Start ourselves capturing previews and decoding.
|
||||||
|
this.cameraManager = cameraManager; |
||||||
|
cameraManager.startPreview(); |
||||||
|
restartPreviewAndDecode(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handleMessage(Message message) { |
||||||
|
if (message.what == R.id.restart_preview) { |
||||||
|
restartPreviewAndDecode(); |
||||||
|
|
||||||
|
} else if (message.what == R.id.decode_succeeded) { |
||||||
|
state = State.SUCCESS; |
||||||
|
Bundle bundle = message.getData(); |
||||||
|
|
||||||
|
activity.handleDecode((Result) message.obj, bundle); |
||||||
|
|
||||||
|
} else if (message.what == R.id.decode_failed) {// We're decoding as fast as possible, so when one
|
||||||
|
// decode fails,
|
||||||
|
// start another.
|
||||||
|
state = State.PREVIEW; |
||||||
|
cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode); |
||||||
|
|
||||||
|
} else if (message.what == R.id.return_scan_result) { |
||||||
|
activity.setResult(Activity.RESULT_OK, (Intent) message.obj); |
||||||
|
activity.finish(); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void quitSynchronously() { |
||||||
|
state = State.DONE; |
||||||
|
cameraManager.stopPreview(); |
||||||
|
Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit); |
||||||
|
quit.sendToTarget(); |
||||||
|
try { |
||||||
|
// Wait at most half a second; should be enough time, and onPause()
|
||||||
|
// will timeout quickly
|
||||||
|
decodeThread.join(500L); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
// continue
|
||||||
|
} |
||||||
|
|
||||||
|
// Be absolutely sure we don't send any queued up messages
|
||||||
|
removeMessages(R.id.decode_succeeded); |
||||||
|
removeMessages(R.id.decode_failed); |
||||||
|
} |
||||||
|
|
||||||
|
private void restartPreviewAndDecode() { |
||||||
|
if (state == State.SUCCESS) { |
||||||
|
state = State.PREVIEW; |
||||||
|
cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private enum State { |
||||||
|
PREVIEW, SUCCESS, DONE |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,124 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2010 ZXing authors |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.common_lib.base.zxing.utils; |
||||||
|
|
||||||
|
import android.annotation.SuppressLint; |
||||||
|
import android.app.Activity; |
||||||
|
import android.content.BroadcastReceiver; |
||||||
|
import android.content.Context; |
||||||
|
import android.content.Intent; |
||||||
|
import android.content.IntentFilter; |
||||||
|
import android.os.AsyncTask; |
||||||
|
import android.os.BatteryManager; |
||||||
|
import android.os.Build; |
||||||
|
import android.util.Log; |
||||||
|
|
||||||
|
/** |
||||||
|
* Finishes an activity after a period of inactivity if the device is on battery |
||||||
|
* power. |
||||||
|
*/ |
||||||
|
public class InactivityTimer { |
||||||
|
|
||||||
|
private static final String TAG = InactivityTimer.class.getSimpleName(); |
||||||
|
|
||||||
|
private static final long INACTIVITY_DELAY_MS = 5 * 60 * 1000L; |
||||||
|
|
||||||
|
private Activity activity; |
||||||
|
private BroadcastReceiver powerStatusReceiver; |
||||||
|
private boolean registered; |
||||||
|
private AsyncTask<Object, Object, Object> inactivityTask; |
||||||
|
|
||||||
|
public InactivityTimer(Activity activity) { |
||||||
|
this.activity = activity; |
||||||
|
powerStatusReceiver = new PowerStatusReceiver(); |
||||||
|
registered = false; |
||||||
|
onActivity(); |
||||||
|
} |
||||||
|
|
||||||
|
@SuppressLint("NewApi") |
||||||
|
public synchronized void onActivity() { |
||||||
|
cancel(); |
||||||
|
inactivityTask = new InactivityAsyncTask(); |
||||||
|
if (Build.VERSION.SDK_INT >= 11) { |
||||||
|
inactivityTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
||||||
|
} else { |
||||||
|
inactivityTask.execute(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized void onPause() { |
||||||
|
cancel(); |
||||||
|
if (registered) { |
||||||
|
activity.unregisterReceiver(powerStatusReceiver); |
||||||
|
registered = false; |
||||||
|
} else { |
||||||
|
Log.w(TAG, "PowerStatusReceiver was never registered?"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized void onResume() { |
||||||
|
if (registered) { |
||||||
|
Log.w(TAG, "PowerStatusReceiver was already registered?"); |
||||||
|
} else { |
||||||
|
activity.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
||||||
|
registered = true; |
||||||
|
} |
||||||
|
onActivity(); |
||||||
|
} |
||||||
|
|
||||||
|
private synchronized void cancel() { |
||||||
|
AsyncTask<?, ?, ?> task = inactivityTask; |
||||||
|
if (task != null) { |
||||||
|
task.cancel(true); |
||||||
|
inactivityTask = null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void shutdown() { |
||||||
|
cancel(); |
||||||
|
} |
||||||
|
|
||||||
|
private class PowerStatusReceiver extends BroadcastReceiver { |
||||||
|
@Override |
||||||
|
public void onReceive(Context context, Intent intent) { |
||||||
|
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) { |
||||||
|
// 0 indicates that we're on battery
|
||||||
|
boolean onBatteryNow = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <= 0; |
||||||
|
if (onBatteryNow) { |
||||||
|
InactivityTimer.this.onActivity(); |
||||||
|
} else { |
||||||
|
InactivityTimer.this.cancel(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private class InactivityAsyncTask extends AsyncTask<Object, Object, Object> { |
||||||
|
@Override |
||||||
|
protected Object doInBackground(Object... objects) { |
||||||
|
try { |
||||||
|
Thread.sleep(INACTIVITY_DELAY_MS); |
||||||
|
Log.i(TAG, "Finishing activity due to inactivity"); |
||||||
|
activity.finish(); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
// continue without killing
|
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:background="@android:color/transparent" |
||||||
|
android:orientation="vertical"> |
||||||
|
|
||||||
|
<SurfaceView |
||||||
|
android:id="@+id/capture_preview" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" /> |
||||||
|
|
||||||
|
<RelativeLayout |
||||||
|
android:id="@+id/capture_container" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:background="@mipmap/home_scan_pic"> |
||||||
|
|
||||||
|
<ImageView |
||||||
|
android:id="@+id/back" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:layout_marginLeft="15dp" |
||||||
|
android:layout_marginTop="20dp" |
||||||
|
android:src="@mipmap/home_scan_icon_back" /> |
||||||
|
|
||||||
|
<RelativeLayout |
||||||
|
android:id="@+id/capture_crop_view" |
||||||
|
android:layout_width="200dp" |
||||||
|
android:layout_height="200dp" |
||||||
|
android:layout_centerInParent="true"> |
||||||
|
|
||||||
|
<ImageView |
||||||
|
android:id="@+id/capture_scan_line" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:layout_alignParentTop="true" |
||||||
|
android:layout_marginBottom="5dp" |
||||||
|
android:layout_marginTop="5dp" /> |
||||||
|
|
||||||
|
</RelativeLayout> |
||||||
|
|
||||||
|
</RelativeLayout> |
||||||
|
|
||||||
|
</RelativeLayout> |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 14 KiB |
@ -0,0 +1,12 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<resources> |
||||||
|
<color name="titleBg">#DD2727</color> |
||||||
|
<color name="viewfinder_mask">#60000000</color> |
||||||
|
<color name="result_view">#b0000000</color> |
||||||
|
<color name="viewfinder_laser">#ffcc0000</color> |
||||||
|
<color name="possible_result_points">#c0ffbd21</color> |
||||||
|
<color name="status_text">#ffffffff</color> |
||||||
|
<color name="viewfinder_frame">#ff000000</color> |
||||||
|
|
||||||
|
<color name="half_transparent">#e0000000</color> |
||||||
|
</resources> |
@ -0,0 +1,26 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<!-- |
||||||
|
Copyright (C) 2008 ZXing authors |
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
you may not use this file except in compliance with the License. |
||||||
|
You may obtain a copy of the License at |
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software |
||||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
See the License for the specific language governing permissions and |
||||||
|
limitations under the License. |
||||||
|
--> |
||||||
|
<resources> |
||||||
|
<item type="id" name="decode"/> |
||||||
|
<item type="id" name="decode_failed"/> |
||||||
|
<item type="id" name="decode_succeeded"/> |
||||||
|
<item type="id" name="launch_product_query"/> |
||||||
|
<item type="id" name="quit"/> |
||||||
|
<item type="id" name="restart_preview"/> |
||||||
|
<item type="id" name="return_scan_result"/> |
||||||
|
|
||||||
|
</resources> |
@ -0,0 +1,3 @@ |
|||||||
|
<resources> |
||||||
|
<string name="app_name">common_lib</string> |
||||||
|
</resources> |
@ -0,0 +1,17 @@ |
|||||||
|
package com.common_lib.common_lib |
||||||
|
|
||||||
|
import org.junit.Test |
||||||
|
|
||||||
|
import org.junit.Assert.* |
||||||
|
|
||||||
|
/** |
||||||
|
* Example local unit test, which will execute on the development machine (host). |
||||||
|
* |
||||||
|
* See [testing documentation](http://d.android.com/tools/testing). |
||||||
|
*/ |
||||||
|
class ExampleUnitTest { |
||||||
|
@Test |
||||||
|
fun addition_isCorrect() { |
||||||
|
assertEquals(4, 2 + 2) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
ext { |
||||||
|
android = [ |
||||||
|
compileSdkVersion : 28, |
||||||
|
buildToolsVersion : '28.0.3', |
||||||
|
minSdkVersion : 19, |
||||||
|
targetSdkVersion : 28, |
||||||
|
versionCode : 1, |
||||||
|
versionName : "1.0.0", |
||||||
|
applicationId : "com.novel.read", |
||||||
|
|
||||||
|
androidSupportSdkVersion: "28.0.0", |
||||||
|
litepal_version : "3.0.0", |
||||||
|
glide_version : "4.8.0", |
||||||
|
retrofitVersion : '2.3.0', |
||||||
|
gsonVersion : '2.8.5' |
||||||
|
] |
||||||
|
dependencies = [ |
||||||
|
|
||||||
|
"runner" : 'com.android.support.test:runner:1.0.1', |
||||||
|
"espresso_core" : 'com.android.support.test.espresso:espresso-core:3.0.1', |
||||||
|
"junit" : 'junit:junit:4.12', |
||||||
|
|
||||||
|
"appcompat" : "androidx.appcompat:appcompat:1.0.2", |
||||||
|
"constraint_layout": 'androidx.constraintlayout:constraintlayout:1.1.3', |
||||||
|
"recyclerview" : "androidx.recyclerview:recyclerview:1.0.0", |
||||||
|
"material" : "com.google.android.material:material:1.0.0", |
||||||
|
|
||||||
|
"ktx" : "androidx.core:core-ktx:1.0.2", |
||||||
|
"kotlin" : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41", |
||||||
|
|
||||||
|
"litepal" : "org.litepal.android:java:${android["litepal_version"]}", |
||||||
|
|
||||||
|
"gson" : "com.google.code.gson:gson:${android["gsonVersion"]}", |
||||||
|
|
||||||
|
"glide" : "com.github.bumptech.glide:glide:${android["glide_version"]}", |
||||||
|
"glide-compiler" : "com.github.bumptech.glide:compiler:${android["glide_version"]}", |
||||||
|
|
||||||
|
"rxjava2:rxandroid": 'io.reactivex.rxjava2:rxandroid:2.0.1', |
||||||
|
"rxjava2" : 'io.reactivex.rxjava2:rxjava:2.1.8', |
||||||
|
|
||||||
|
"okhttp" : "com.squareup.okhttp3:okhttp:3.13.1", |
||||||
|
"okio" : 'com.squareup.okio:okio:1.14.0', |
||||||
|
"otto" : 'com.squareup:otto:1.3.8', |
||||||
|
|
||||||
|
"retrofit2" : "com.squareup.retrofit2:retrofit:${android["retrofitVersion"]}", |
||||||
|
"retrofit2_gson" : "com.squareup.retrofit2:converter-gson:${android["retrofitVersion"]}", |
||||||
|
"retrofit2_adapter": "com.squareup.retrofit2:adapter-rxjava:${android["retrofitVersion"]}", |
||||||
|
|
||||||
|
] |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
# Project-wide Gradle settings. |
||||||
|
# IDE (e.g. Android Studio) users: |
||||||
|
# Gradle settings configured through the IDE *will override* |
||||||
|
# any settings specified in this file. |
||||||
|
# For more details on how to configure your build environment visit |
||||||
|
# http://www.gradle.org/docs/current/userguide/build_environment.html |
||||||
|
# Specifies the JVM arguments used for the daemon process. |
||||||
|
# The setting is particularly useful for tweaking memory settings. |
||||||
|
org.gradle.jvmargs=-Xmx1536m |
||||||
|
# When configured, Gradle will run in incubating parallel mode. |
||||||
|
# This option should only be used with decoupled projects. More details, visit |
||||||
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects |
||||||
|
# org.gradle.parallel=true |
||||||
|
# AndroidX package structure to make it clearer which packages are bundled with the |
||||||
|
# Android operating system, and which are packaged with your app's APK |
||||||
|
# https://developer.android.com/topic/libraries/support-library/androidx-rn |
||||||
|
android.useAndroidX=true |
||||||
|
# Automatically convert third-party libraries to use AndroidX |
||||||
|
android.enableJetifier=true |
||||||
|
# Kotlin code style for this project: "official" or "obsolete": |
||||||
|
kotlin.code.style=official |
@ -0,0 +1,6 @@ |
|||||||
|
#Mon Aug 26 16:25:31 CST 2019 |
||||||
|
distributionBase=GRADLE_USER_HOME |
||||||
|
distributionPath=wrapper/dists |
||||||
|
zipStoreBase=GRADLE_USER_HOME |
||||||
|
zipStorePath=wrapper/dists |
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip |
@ -0,0 +1,172 @@ |
|||||||
|
#!/usr/bin/env sh |
||||||
|
|
||||||
|
############################################################################## |
||||||
|
## |
||||||
|
## Gradle start up script for UN*X |
||||||
|
## |
||||||
|
############################################################################## |
||||||
|
|
||||||
|
# Attempt to set APP_HOME |
||||||
|
# Resolve links: $0 may be a link |
||||||
|
PRG="$0" |
||||||
|
# Need this for relative symlinks. |
||||||
|
while [ -h "$PRG" ] ; do |
||||||
|
ls=`ls -ld "$PRG"` |
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'` |
||||||
|
if expr "$link" : '/.*' > /dev/null; then |
||||||
|
PRG="$link" |
||||||
|
else |
||||||
|
PRG=`dirname "$PRG"`"/$link" |
||||||
|
fi |
||||||
|
done |
||||||
|
SAVED="`pwd`" |
||||||
|
cd "`dirname \"$PRG\"`/" >/dev/null |
||||||
|
APP_HOME="`pwd -P`" |
||||||
|
cd "$SAVED" >/dev/null |
||||||
|
|
||||||
|
APP_NAME="Gradle" |
||||||
|
APP_BASE_NAME=`basename "$0"` |
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. |
||||||
|
DEFAULT_JVM_OPTS="" |
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value. |
||||||
|
MAX_FD="maximum" |
||||||
|
|
||||||
|
warn () { |
||||||
|
echo "$*" |
||||||
|
} |
||||||
|
|
||||||
|
die () { |
||||||
|
echo |
||||||
|
echo "$*" |
||||||
|
echo |
||||||
|
exit 1 |
||||||
|
} |
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false'). |
||||||
|
cygwin=false |
||||||
|
msys=false |
||||||
|
darwin=false |
||||||
|
nonstop=false |
||||||
|
case "`uname`" in |
||||||
|
CYGWIN* ) |
||||||
|
cygwin=true |
||||||
|
;; |
||||||
|
Darwin* ) |
||||||
|
darwin=true |
||||||
|
;; |
||||||
|
MINGW* ) |
||||||
|
msys=true |
||||||
|
;; |
||||||
|
NONSTOP* ) |
||||||
|
nonstop=true |
||||||
|
;; |
||||||
|
esac |
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar |
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM. |
||||||
|
if [ -n "$JAVA_HOME" ] ; then |
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then |
||||||
|
# IBM's JDK on AIX uses strange locations for the executables |
||||||
|
JAVACMD="$JAVA_HOME/jre/sh/java" |
||||||
|
else |
||||||
|
JAVACMD="$JAVA_HOME/bin/java" |
||||||
|
fi |
||||||
|
if [ ! -x "$JAVACMD" ] ; then |
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME |
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the |
||||||
|
location of your Java installation." |
||||||
|
fi |
||||||
|
else |
||||||
|
JAVACMD="java" |
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the |
||||||
|
location of your Java installation." |
||||||
|
fi |
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can. |
||||||
|
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then |
||||||
|
MAX_FD_LIMIT=`ulimit -H -n` |
||||||
|
if [ $? -eq 0 ] ; then |
||||||
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then |
||||||
|
MAX_FD="$MAX_FD_LIMIT" |
||||||
|
fi |
||||||
|
ulimit -n $MAX_FD |
||||||
|
if [ $? -ne 0 ] ; then |
||||||
|
warn "Could not set maximum file descriptor limit: $MAX_FD" |
||||||
|
fi |
||||||
|
else |
||||||
|
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
# For Darwin, add options to specify how the application appears in the dock |
||||||
|
if $darwin; then |
||||||
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" |
||||||
|
fi |
||||||
|
|
||||||
|
# For Cygwin, switch paths to Windows format before running java |
||||||
|
if $cygwin ; then |
||||||
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"` |
||||||
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` |
||||||
|
JAVACMD=`cygpath --unix "$JAVACMD"` |
||||||
|
|
||||||
|
# We build the pattern for arguments to be converted via cygpath |
||||||
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` |
||||||
|
SEP="" |
||||||
|
for dir in $ROOTDIRSRAW ; do |
||||||
|
ROOTDIRS="$ROOTDIRS$SEP$dir" |
||||||
|
SEP="|" |
||||||
|
done |
||||||
|
OURCYGPATTERN="(^($ROOTDIRS))" |
||||||
|
# Add a user-defined pattern to the cygpath arguments |
||||||
|
if [ "$GRADLE_CYGPATTERN" != "" ] ; then |
||||||
|
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" |
||||||
|
fi |
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh |
||||||
|
i=0 |
||||||
|
for arg in "$@" ; do |
||||||
|
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` |
||||||
|
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option |
||||||
|
|
||||||
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition |
||||||
|
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` |
||||||
|
else |
||||||
|
eval `echo args$i`="\"$arg\"" |
||||||
|
fi |
||||||
|
i=$((i+1)) |
||||||
|
done |
||||||
|
case $i in |
||||||
|
(0) set -- ;; |
||||||
|
(1) set -- "$args0" ;; |
||||||
|
(2) set -- "$args0" "$args1" ;; |
||||||
|
(3) set -- "$args0" "$args1" "$args2" ;; |
||||||
|
(4) set -- "$args0" "$args1" "$args2" "$args3" ;; |
||||||
|
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; |
||||||
|
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; |
||||||
|
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; |
||||||
|
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; |
||||||
|
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; |
||||||
|
esac |
||||||
|
fi |
||||||
|
|
||||||
|
# Escape application args |
||||||
|
save () { |
||||||
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done |
||||||
|
echo " " |
||||||
|
} |
||||||
|
APP_ARGS=$(save "$@") |
||||||
|
|
||||||
|
# Collect all arguments for the java command, following the shell quoting and substitution rules |
||||||
|
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" |
||||||
|
|
||||||
|
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong |
||||||
|
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then |
||||||
|
cd "$(dirname "$0")" |
||||||
|
fi |
||||||
|
|
||||||
|
exec "$JAVACMD" "$@" |
@ -0,0 +1,84 @@ |
|||||||
|
@if "%DEBUG%" == "" @echo off |
||||||
|
@rem ########################################################################## |
||||||
|
@rem |
||||||
|
@rem Gradle startup script for Windows |
||||||
|
@rem |
||||||
|
@rem ########################################################################## |
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell |
||||||
|
if "%OS%"=="Windows_NT" setlocal |
||||||
|
|
||||||
|
set DIRNAME=%~dp0 |
||||||
|
if "%DIRNAME%" == "" set DIRNAME=. |
||||||
|
set APP_BASE_NAME=%~n0 |
||||||
|
set APP_HOME=%DIRNAME% |
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. |
||||||
|
set DEFAULT_JVM_OPTS= |
||||||
|
|
||||||
|
@rem Find java.exe |
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome |
||||||
|
|
||||||
|
set JAVA_EXE=java.exe |
||||||
|
%JAVA_EXE% -version >NUL 2>&1 |
||||||
|
if "%ERRORLEVEL%" == "0" goto init |
||||||
|
|
||||||
|
echo. |
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
||||||
|
echo. |
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the |
||||||
|
echo location of your Java installation. |
||||||
|
|
||||||
|
goto fail |
||||||
|
|
||||||
|
:findJavaFromJavaHome |
||||||
|
set JAVA_HOME=%JAVA_HOME:"=% |
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe |
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto init |
||||||
|
|
||||||
|
echo. |
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% |
||||||
|
echo. |
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the |
||||||
|
echo location of your Java installation. |
||||||
|
|
||||||
|
goto fail |
||||||
|
|
||||||
|
:init |
||||||
|
@rem Get command-line arguments, handling Windows variants |
||||||
|
|
||||||
|
if not "%OS%" == "Windows_NT" goto win9xME_args |
||||||
|
|
||||||
|
:win9xME_args |
||||||
|
@rem Slurp the command line arguments. |
||||||
|
set CMD_LINE_ARGS= |
||||||
|
set _SKIP=2 |
||||||
|
|
||||||
|
:win9xME_args_slurp |
||||||
|
if "x%~1" == "x" goto execute |
||||||
|
|
||||||
|
set CMD_LINE_ARGS=%* |
||||||
|
|
||||||
|
:execute |
||||||
|
@rem Setup the command line |
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar |
||||||
|
|
||||||
|
@rem Execute Gradle |
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% |
||||||
|
|
||||||
|
:end |
||||||
|
@rem End local scope for the variables with windows NT shell |
||||||
|
if "%ERRORLEVEL%"=="0" goto mainEnd |
||||||
|
|
||||||
|
:fail |
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of |
||||||
|
rem the _cmd.exe /c_ return code! |
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 |
||||||
|
exit /b 1 |
||||||
|
|
||||||
|
:mainEnd |
||||||
|
if "%OS%"=="Windows_NT" endlocal |
||||||
|
|
||||||
|
:omega |
@ -0,0 +1 @@ |
|||||||
|
/build |
@ -0,0 +1,43 @@ |
|||||||
|
apply plugin: 'com.android.library' |
||||||
|
apply plugin: 'kotlin-android-extensions' |
||||||
|
apply plugin: 'kotlin-android' |
||||||
|
|
||||||
|
android { |
||||||
|
compileSdkVersion rootProject.ext.android.compileSdkVersion |
||||||
|
|
||||||
|
defaultConfig { |
||||||
|
minSdkVersion rootProject.ext.android.minSdkVersion |
||||||
|
targetSdkVersion rootProject.ext.android.targetSdkVersion |
||||||
|
versionCode rootProject.ext.android.versionCode |
||||||
|
versionName rootProject.ext.android.versionName |
||||||
|
|
||||||
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
||||||
|
|
||||||
|
} |
||||||
|
buildTypes { |
||||||
|
release { |
||||||
|
minifyEnabled false |
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
dependencies { |
||||||
|
api fileTree(include: ['*.jar'], dir: 'libs') |
||||||
|
testImplementation rootProject.ext.dependencies["junit"] |
||||||
|
androidTestImplementation rootProject.ext.dependencies["runner"] |
||||||
|
androidTestImplementation rootProject.ext.dependencies["espresso_core"] |
||||||
|
implementation project(path: ':common_lib') |
||||||
|
|
||||||
|
//网络请求 |
||||||
|
api rootProject.ext.dependencies["okhttp"] |
||||||
|
//上传文件 监听进度 配合okHttp使用 |
||||||
|
api 'io.github.lizhangqu:coreprogress:1.0.2' |
||||||
|
|
||||||
|
api rootProject.ext.dependencies["retrofit2"] |
||||||
|
api rootProject.ext.dependencies["retrofit2_gson"] |
||||||
|
api rootProject.ext.dependencies["retrofit2_adapter"] |
||||||
|
|
||||||
|
//消息分发 |
||||||
|
api rootProject.ext.dependencies["otto"] |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
# Add project specific ProGuard rules here. |
||||||
|
# By default, the flags in this file are appended to flags specified |
||||||
|
# in /Users/demon/Library/Android/sdk/tools/proguard/proguard-android.txt |
||||||
|
# You can edit the include path and order by changing the proguardFiles |
||||||
|
# directive in build.gradle. |
||||||
|
# |
||||||
|
# For more details, see |
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html |
||||||
|
|
||||||
|
# Add any project specific keep options here: |
||||||
|
|
||||||
|
# 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 *; |
||||||
|
#} |
@ -0,0 +1,26 @@ |
|||||||
|
package com.mango.mangolib; |
||||||
|
|
||||||
|
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.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* Instrumentation 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() throws Exception { |
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext(); |
||||||
|
|
||||||
|
assertEquals("com.mango.mangolib.test", appContext.getPackageName()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
package="com.mango.mangolib"> |
||||||
|
|
||||||
|
<!-- 用于访问网络,网络定位需要上网 --> |
||||||
|
<uses-permission android:name="android.permission.INTERNET" /> |
||||||
|
|
||||||
|
<application |
||||||
|
android:allowBackup="true" |
||||||
|
android:label="@string/app_name" |
||||||
|
android:supportsRtl="true"> |
||||||
|
</application> |
||||||
|
|
||||||
|
</manifest> |
@ -0,0 +1,33 @@ |
|||||||
|
package com.mango.mangolib.event |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import com.mango.mangolib.http.ErrorResponse |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
open class BaseEvent<T> : OttoEventInterface { |
||||||
|
|
||||||
|
var result: T? = null |
||||||
|
|
||||||
|
open var er: ErrorResponse? = null |
||||||
|
set(er) { |
||||||
|
this.isFail = true |
||||||
|
field = er |
||||||
|
} |
||||||
|
|
||||||
|
private var isFail = false |
||||||
|
|
||||||
|
private var extras: Bundle? = null |
||||||
|
|
||||||
|
constructor(result: T) { |
||||||
|
this.result = result |
||||||
|
} |
||||||
|
|
||||||
|
constructor() { |
||||||
|
this.extras = Bundle() |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,79 @@ |
|||||||
|
package com.mango.mangolib.event |
||||||
|
|
||||||
|
import android.os.Handler |
||||||
|
import android.os.Looper |
||||||
|
import com.squareup.otto.Bus |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class EventManager private constructor() { |
||||||
|
|
||||||
|
private val bus: MainThreadBus |
||||||
|
|
||||||
|
init { |
||||||
|
bus = MainThreadBus() |
||||||
|
} |
||||||
|
|
||||||
|
fun registerSubscriber(subscriber: Any) { |
||||||
|
try { |
||||||
|
bus.register(subscriber) |
||||||
|
} catch (e: Exception) { |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
fun unregisterSubscriber(subscriber: Any) { |
||||||
|
try { |
||||||
|
bus.unregister(subscriber) |
||||||
|
} catch (e: Exception) { |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
fun postEvent(event: OttoEventInterface) { |
||||||
|
bus.post(event) |
||||||
|
} |
||||||
|
|
||||||
|
internal inner class MainThreadBus : Bus() { |
||||||
|
private val mHandler = Handler(Looper.getMainLooper()) |
||||||
|
|
||||||
|
override fun post(event: Any) { |
||||||
|
if (Looper.myLooper() == Looper.getMainLooper()) { |
||||||
|
super.post(event) |
||||||
|
} else { |
||||||
|
mHandler.post { super@MainThreadBus.post(event) } |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun register(`object`: Any) { |
||||||
|
if (Looper.myLooper() == Looper.getMainLooper()) { |
||||||
|
super.register(`object`) |
||||||
|
} else { |
||||||
|
mHandler.post { super@MainThreadBus.register(`object`) } |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun unregister(`object`: Any) { |
||||||
|
if (Looper.myLooper() == Looper.getMainLooper()) { |
||||||
|
super.unregister(`object`) |
||||||
|
} else { |
||||||
|
mHandler.post { super@MainThreadBus.unregister(`object`) } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
private var instance: EventManager? = null |
||||||
|
|
||||||
|
@Synchronized |
||||||
|
fun getInstance(): EventManager { |
||||||
|
if (instance == null) { |
||||||
|
instance = EventManager() |
||||||
|
} |
||||||
|
return instance as EventManager |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.mango.mangolib.event |
||||||
|
|
||||||
|
import com.mango.mangolib.http.ErrorResponse |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class GenericBaseEvent(er: ErrorResponse) : BaseEvent<Any>() { |
||||||
|
|
||||||
|
init { |
||||||
|
this.er = er |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.mango.mangolib.event |
||||||
|
|
||||||
|
import com.mango.mangolib.http.ErrorResponse |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class HTTPReponseErrorEvent : OttoEventInterface { |
||||||
|
|
||||||
|
var errorResponse: ErrorResponse? = null |
||||||
|
|
||||||
|
constructor(response: ErrorResponse) { |
||||||
|
this.errorResponse = response |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
package com.mango.mangolib.event |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
interface OttoEventInterface |
@ -0,0 +1,7 @@ |
|||||||
|
package com.mango.mangolib.event |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class PermissionReqResultEvent(location: Boolean?) : BaseEvent<Boolean>(location!!) |
@ -0,0 +1,9 @@ |
|||||||
|
package com.mango.mangolib.event.picture |
||||||
|
|
||||||
|
import com.mango.mangolib.event.BaseEvent |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class OnPhotoSendEvent(url: String) : BaseEvent<String>(url) |
@ -0,0 +1,13 @@ |
|||||||
|
package com.mango.mangolib.http |
||||||
|
|
||||||
|
/** |
||||||
|
* create by zlj on 2019/10/12 |
||||||
|
* describe: |
||||||
|
*/ |
||||||
|
class ErrorResponse (){ |
||||||
|
var code: Int = 0 |
||||||
|
var msg: String = "" |
||||||
|
var time: String = "" |
||||||
|
var data: Any? = null |
||||||
|
} |
||||||
|
|