Skip to content

Commit

Permalink
[opt] remove mmkv/glide from libusbc
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangdg committed Aug 30, 2022
1 parent ae5d289 commit 8d4851a
Show file tree
Hide file tree
Showing 21 changed files with 207 additions and 62 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ dependencies {
implementation "com.tencent.bugly:crashreport:$bugly_version"
implementation "com.tencent.bugly:nativecrashreport:$bugly_native_version"

implementation project(':libutils')

// For debug online
// implementation project(':libausbc')
implementation project(':libausbc')

// demo
implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.2.7'
// implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.2.7'
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/jiangdg/demo/DemoApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.jiangdg.demo
import android.content.Context
import androidx.multidex.MultiDex
import com.jiangdg.ausbc.base.BaseApplication
import com.jiangdg.utils.MMKVUtils
import com.tencent.bugly.crashreport.CrashReport

/**
Expand All @@ -35,5 +36,6 @@ class DemoApplication: BaseApplication() {
super.onCreate()
// init bugly library
CrashReport.initCrashReport(this, "165c46d5b1", true)
MMKVUtils.init(this)
}
}
19 changes: 12 additions & 7 deletions app/src/main/java/com/jiangdg/demo/DemoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ import com.jiangdg.ausbc.render.effect.bean.CameraEffect
import com.jiangdg.ausbc.utils.*
import com.jiangdg.ausbc.utils.bus.BusKey
import com.jiangdg.ausbc.utils.bus.EventBus
import com.jiangdg.ausbc.utils.imageloader.ILoader
import com.jiangdg.ausbc.utils.imageloader.ImageLoaders
import com.jiangdg.utils.imageloader.ILoader
import com.jiangdg.utils.imageloader.ImageLoaders
import com.jiangdg.ausbc.widget.*
import com.jiangdg.demo.EffectListDialog.Companion.KEY_ANIMATION
import com.jiangdg.demo.EffectListDialog.Companion.KEY_FILTER
import com.jiangdg.demo.databinding.DialogMoreBinding
import com.jiangdg.utils.MMKVUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.*
Expand Down Expand Up @@ -631,11 +632,15 @@ class DemoFragment : CameraFragment(), View.OnClickListener, CaptureMediaView.On
}

private fun goToGalley() {
Intent(
Intent.ACTION_VIEW,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI
).apply {
startActivity(this)
try {
Intent(
Intent.ACTION_VIEW,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI
).apply {
startActivity(this)
}
} catch (e: Exception) {
ToastUtils.show("open error: ${e.localizedMessage}")
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/jiangdg/demo/EffectListDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jiangdg.ausbc.base.BaseDialog
import com.jiangdg.ausbc.render.effect.bean.CameraEffect
import com.jiangdg.ausbc.utils.MMKVUtils
import com.jiangdg.utils.MMKVUtils
import com.jiangdg.ausbc.utils.Utils
import com.jiangdg.ausbc.utils.imageloader.ImageLoaders
import com.jiangdg.utils.imageloader.ImageLoaders

/** Effect list dialog
*
Expand Down
7 changes: 0 additions & 7 deletions libausbc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,8 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:${androidXVersion}"
implementation "androidx.core:core-ktx:${kotlinCoreVersion}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${kotlinCoroutines}"
implementation "androidx.constraintlayout:constraintlayout:${constraintlayoutVersion}"
implementation "com.google.android.material:material:${materialVersion}"
api 'com.gyf.immersionbar:immersionbar:3.0.0'
implementation "com.github.bumptech.glide:glide:4.10.0"
implementation "com.github.bumptech.glide:okhttp3-integration:4.10.0"
implementation "com.zlc.glide:webpdecoder:1.6.4.9.0"
implementation 'com.tencent:mmkv:1.2.12'

// For debug online
implementation project(path: ':libuvc')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.jiangdg.ausbc.base
import android.app.Application
import com.jiangdg.ausbc.utils.CrashUtils
import com.jiangdg.ausbc.utils.Logger
import com.jiangdg.ausbc.utils.MMKVUtils
import com.jiangdg.ausbc.utils.ToastUtils

/** Base Application
Expand All @@ -32,6 +31,5 @@ open class BaseApplication: Application() {
CrashUtils.init(this)
Logger.init(this)
ToastUtils.init(this)
MMKVUtils.init(this)
}
}
1 change: 1 addition & 0 deletions libutils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
49 changes: 49 additions & 0 deletions libutils/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
}

android {
compileSdkVersion rootProject.ext.versionCompiler

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.versionTarget
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionNameString

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

// utils
api 'com.gyf.immersionbar:immersionbar:3.0.0'
implementation "com.github.bumptech.glide:glide:4.10.0"
implementation "com.github.bumptech.glide:okhttp3-integration:4.10.0"
implementation "com.zlc.glide:webpdecoder:1.6.4.9.0"
implementation 'com.tencent:mmkv:1.2.12'
}
Empty file added libutils/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions libutils/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.jiangdg.utils

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.jiangdg.utils.test", appContext.packageName)
}
}
5 changes: 5 additions & 0 deletions libutils/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jiangdg.utils">

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jiangdg.ausbc.utils
package com.jiangdg.utils

import android.content.Context
import android.os.Parcelable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jiangdg.ausbc.utils.imageloader
package com.jiangdg.utils.imageloader

import android.annotation.SuppressLint
import android.app.Activity
Expand All @@ -38,8 +38,7 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.jiangdg.ausbc.R
import com.jiangdg.ausbc.utils.Utils
import com.jiangdg.utils.R
import java.lang.IllegalArgumentException

/**GlideImageLoader by glide
Expand Down Expand Up @@ -104,9 +103,9 @@ class GlideLoader<T>(target: T) : ILoader<ImageView> {
override fun loadRounded(imageView: ImageView, url: String?, placeHolder: Int, radius: Float) {
RequestOptions().apply {
if (radius >= 0) {
transform(CenterCrop(), RoundedCorners(Utils.dp2px(imageView.context, radius)))
transform(CenterCrop(), RoundedCorners(dp2px(imageView.context, radius)))
} else {
transform(RoundedCorners(Utils.dp2px(imageView.context, radius)))
transform(RoundedCorners(dp2px(imageView.context, radius)))
}
}.also { options ->
mRequestManager!!.load(url)
Expand All @@ -125,9 +124,9 @@ class GlideLoader<T>(target: T) : ILoader<ImageView> {
) {
RequestOptions().apply {
if (radius >= 0) {
transform(CenterCrop(), RoundedCorners(Utils.dp2px(imageView.context, radius)))
transform(CenterCrop(), RoundedCorners(dp2px(imageView.context, radius)))
} else {
transform(RoundedCorners(Utils.dp2px(imageView.context, radius)))
transform(RoundedCorners(dp2px(imageView.context, radius)))
}
}.also { options ->
mRequestManager!!.load(url)
Expand Down Expand Up @@ -177,35 +176,45 @@ class GlideLoader<T>(target: T) : ILoader<ImageView> {
}
}

override fun loadAsBitmap(url: String?, width: Int, height: Int, listener: ILoader.OnLoadedResultListener) {
override fun loadAsBitmap(
url: String?,
width: Int,
height: Int,
listener: ILoader.OnLoadedResultListener
) {
mRequestManager?.apply {
this.asBitmap()
.centerCrop()
.load(url)
.listener(object : RequestListener<Bitmap> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Bitmap>?,
isFirstResource: Boolean
): Boolean {
listener.onLoadedFailed(e)
return true
}

override fun onResourceReady(
resource: Bitmap?,
model: Any?,
target: Target<Bitmap>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
listener.onLoadedSuccess(resource)
return true
}

})
.submit(width, height)
.centerCrop()
.load(url)
.listener(object : RequestListener<Bitmap> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Bitmap>?,
isFirstResource: Boolean
): Boolean {
listener.onLoadedFailed(e)
return true
}

override fun onResourceReady(
resource: Bitmap?,
model: Any?,
target: Target<Bitmap>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
listener.onLoadedSuccess(resource)
return true
}

})
.submit(width, height)
}
}

private fun dp2px(context: Context, dpValue: Float): Int {
val scale: Float = context.resources.displayMetrics.density
return (dpValue * scale + 0.5f).toInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jiangdg.ausbc.utils.imageloader
package com.jiangdg.utils.imageloader

import android.graphics.Bitmap
import android.graphics.drawable.Drawable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jiangdg.ausbc.utils.imageloader
package com.jiangdg.utils.imageloader

import android.app.Activity
import android.content.Context
Expand Down
13 changes: 13 additions & 0 deletions libutils/src/main/res/drawable/effect_none.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:gravity="center">
<shape>
<solid android:color="#e6e6e6" />
<size android:width="100dp" android:height="100dp"/>
</shape>
</item>

<item android:gravity="center">
<bitmap android:src="@drawable/ic_none"/>
</item>
</layer-list>
Binary file added libutils/src/main/res/drawable/ic_none.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#D7DAE1"/>
</shape>
Loading

0 comments on commit 8d4851a

Please sign in to comment.