Skip to content

Commit

Permalink
Merge pull request #10 from wukaicheng/main
Browse files Browse the repository at this point in the history
一些新功能
  • Loading branch information
nnjun authored May 30, 2021
2 parents da16322 + e0a39bb commit 9e49e89
Show file tree
Hide file tree
Showing 21 changed files with 646 additions and 176 deletions.
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "top.niunaijun.blackdex"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -72,6 +72,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.preference:preference-ktx:1.1.1'

implementation project(':Bcore')

Expand All @@ -86,6 +87,7 @@ dependencies {
//third

implementation 'com.afollestad.material-dialogs:core:3.3.0'
implementation 'com.afollestad.material-dialogs:files:3.2.1'
//dialog
implementation 'com.github.nukc.stateview:kotlin:2.2.0'
//状态控制控件
Expand All @@ -94,6 +96,9 @@ dependencies {
implementation 'com.github.Ferfalk:SimpleSearchView:0.2.0'
//searchView

implementation 'com.umeng.umsdk:common:9.3.8'
implementation 'com.umeng.umsdk:asms:1.2.2'
//友盟

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down
25 changes: 17 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,38 @@
xmlns:tools="http://schemas.android.com/tools"
package="top.niunaijun.blackdex">

<!-- Android 11 需要 -->
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
<!-- Android 11 需要 -->
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

<application
android:name="top.niunaijun.blackboxa.app.App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".App"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/Theme.BlackDex">
<activity android:name=".view.base.WelcomeActivity"
<activity
android:name=".view.base.WelcomeActivity"
android:theme="@style/WelcomeTheme">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
<activity android:name=".view.main.MainActivity">
</activity>
<activity android:name=".view.main.MainActivity" />
<activity android:name=".view.setting.SettingActivity" />
</application>

</manifest>
26 changes: 0 additions & 26 deletions app/src/main/java/top/niunaijun/blackdex/App.kt

This file was deleted.

40 changes: 40 additions & 0 deletions app/src/main/java/top/niunaijun/blackdex/app/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package top.niunaijun.blackboxa.app

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import com.umeng.commonsdk.UMConfigure
import top.niunaijun.blackdex.app.AppManager

/**
*
* @Description:
* @Author: wukaicheng
* @CreateDate: 2021/4/29 21:21
*/
class App : Application() {

companion object {

@SuppressLint("StaticFieldLeak")
@Volatile
private lateinit var mContext: Context

@JvmStatic
fun getContext(): Context {
return mContext
}
}

override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
mContext = base!!
UMConfigure.init(base, "60b373136c421a3d97d23c29", "Github", 0, "")
AppManager.doAttachBaseContext(base)
}

override fun onCreate() {
super.onCreate()
AppManager.doOnCreate(mContext)
}
}
26 changes: 26 additions & 0 deletions app/src/main/java/top/niunaijun/blackdex/app/AppManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package top.niunaijun.blackdex.app

import android.content.Context

object AppManager {
@JvmStatic
val mBlackBoxLoader by lazy {
BlackDexLoader()
}

fun doAttachBaseContext(context: Context) {
try {
mBlackBoxLoader.attachBaseContext(context)
mBlackBoxLoader.addLifecycleCallback()
} catch (e: Exception) {
e.printStackTrace()
}
}

fun doOnCreate(context: Context) {
mBlackBoxLoader.doOnCreate(context)
initThirdService(context)
}

private fun initThirdService(context: Context) {}
}
87 changes: 87 additions & 0 deletions app/src/main/java/top/niunaijun/blackdex/app/BlackDexLoader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package top.niunaijun.blackdex.app

import android.content.Context
import top.niunaijun.blackbox.BlackDexCore
import top.niunaijun.blackbox.app.configuration.ClientConfiguration
import top.niunaijun.blackbox.utils.FileUtils
import top.niunaijun.blackbox.utils.compat.BuildCompat
import top.niunaijun.blackboxa.app.App
import top.niunaijun.blackdex.biz.cache.AppSharedPreferenceDelegate
import java.io.File

/**
*
* @Description:
* @Author: wukaicheng
* @CreateDate: 2021/5/6 23:38
*/
class BlackDexLoader {


private var mSavePath by AppSharedPreferenceDelegate(App.getContext(), "")

private var mSaveEnable by AppSharedPreferenceDelegate(App.getContext(), true)

private var mDir = if (mSaveEnable) {
getDexDumpDir(App.getContext())
} else {
mSavePath
}

fun addLifecycleCallback() {

}

fun attachBaseContext(context: Context) {
BlackDexCore.get().doAttachBaseContext(context, object : ClientConfiguration() {
override fun getHostPackageName(): String {
return context.packageName
}

override fun getDexDumpDir(): String {
return mDir
}
})
}

fun doOnCreate(context: Context) {
BlackDexCore.get().doCreate()
}

fun saveEnable(): Boolean {
return mSaveEnable
}

fun saveEnable(state: Boolean) {
this.mSaveEnable = state
}

fun getSavePath(): String {
return mSavePath
}

fun setSavePath(path: String) {
this.mSavePath = path
}


companion object {

val TAG: String = BlackDexLoader::class.java.simpleName

fun getDexDumpDir(context: Context): String {
return if (BuildCompat.isR()) {
val dump = File(
context.externalCacheDir?.parentFile?.parentFile?.parentFile?.parentFile,
"Download/dexDump"
)
FileUtils.mkdirs(dump)
dump.absolutePath
} else {
val dump = File(context.externalCacheDir?.parentFile, "dump")
FileUtils.mkdirs(dump)
dump.absolutePath
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package top.niunaijun.blackdex.biz.cache


import android.content.Context
import android.text.TextUtils
import androidx.core.content.edit
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty


/**
*
* @desc:目前只支持 5种基本数据类型,如果要支持obj,请继承该类并重写他的相关方法 findData/putData
*
* @author: mini
* @created by 2021/5/10
*/
open class AppSharedPreferenceDelegate<Data>(context: Context, private val default: Data, spName: String? = null) : ReadWriteProperty<Any, Data?> {

private val mSharedPreferences by lazy {
val tmpCacheName = if (TextUtils.isEmpty(spName)) {
AppSharedPreferenceDelegate::class.java.simpleName
} else {
spName
}
return@lazy context.getSharedPreferences(tmpCacheName, Context.MODE_PRIVATE)
}

override fun getValue(thisRef: Any, property: KProperty<*>): Data {
return findData(property.name, default)
}

override fun setValue(thisRef: Any, property: KProperty<*>, value: Data?) {
putData(property.name, value)
}

protected fun findData(key: String, default: Data): Data {
with(mSharedPreferences) {
val result: Any? = when (default) {
is Int -> getInt(key, default)
is Long -> getLong(key, default)
is Float -> getFloat(key, default)
is String -> getString(key, default)
is Boolean -> getBoolean(key, default)
else -> throw IllegalArgumentException("This type $default can not be saved into sharedPreferences")
}
return result as? Data ?: default
}
}

protected fun putData(key: String, value: Data?) {
mSharedPreferences.edit {
if (value == null) {
remove(key)
} else {
when (value) {
is Int -> putInt(key, value)
is Long -> putLong(key, value)
is Float -> putFloat(key, value)
is String -> putString(key, value)
is Boolean -> putBoolean(key, value)
else -> throw IllegalArgumentException("This type $default can not be saved into Preferences")
}
}
}
}
}

This file was deleted.

Loading

0 comments on commit 9e49e89

Please sign in to comment.