Skip to content

Commit

Permalink
修正工程编译
Browse files Browse the repository at this point in the history
  • Loading branch information
uni-cstar committed Jul 12, 2021
1 parent c2ec2b0 commit a5bda83
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 23 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ android {
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -33,4 +34,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation project(path: ':arch')

def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".App"
android:theme="@style/AppTheme">
<activity android:name=".arch.BackpressedDemo"></activity>
<activity android:name=".MainActivity">
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/andme/sample/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package andme.sample

import androidx.multidex.MultiDexApplication

/**
* Created by Lucio on 2021/7/9.
*/
class App : MultiDexApplication() {
}
12 changes: 11 additions & 1 deletion app/src/main/java/andme/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package andme.sample

import android.content.ComponentName
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity


Expand All @@ -10,7 +13,14 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

onBackPressedDispatcher
findViewById<View>(R.id.btn).setOnClickListener {
it.requestFocus()
val it = Intent().also {
it.component = ComponentName("com.insight.hxytv", "ucux.android.tv.ui.entrance.LauncherActivity")
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(it)
}
}


Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
tools:context=".MainActivity">

<TextView
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text="打开Btn"
android:focusableInTouchMode="true"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/andme/core/app/AMApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ abstract class AMApp : Application(), AMAppManager by appManagerAM {
super.onCreate()
initCore(this)
}

fun finishAllActivity(){
activityStack.finishAll()
}
}
24 changes: 4 additions & 20 deletions core/src/main/java/andme/core/util/AMApk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,14 @@ inline fun getTargetSdkVersion(ctx: Context): Int {
/**
* 是否是主进程
*/
val Context.isMainProcess: Boolean
get() {
return packageName == processName
}
inline val Context.isMainProcess: Boolean
get() = Apps.isMainProcess(this)

/**
* 获取当前进程名字
*/
val Context.processName: String?
get() {
val pid = android.os.Process.myPid()
val am = activityManager ?: return null
val i = am.runningAppProcesses.iterator()
while (i.hasNext()) {
val info = i.next() as ActivityManager.RunningAppProcessInfo
try {
if (info.pid == pid) {
return info.processName
}
} catch (e: Exception) {
}
}
return null
}
inline val Context.processName: String?
get() = Apps.getProcessName(this)


/**
Expand Down
85 changes: 85 additions & 0 deletions core/src/main/java/andme/core/util/Apps.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package andme.core.util

import andme.core.content.activityManager
import andme.core.exception.tryCatch
import android.app.ActivityManager
import android.content.Context
import android.os.Process
import java.io.BufferedReader
import java.io.FileReader
import java.io.IOException

/**
* Created by Lucio on 2021/7/9.
*/
object Apps {

/**
* 当前是否是主进程
*/
@JvmStatic
fun isMainProcess(ctx: Context):Boolean{
val pkgName = ctx.packageName
val processName = getProcessName(ctx)
return pkgName == processName
}

/**
* 获取当前进程名字
*/
@JvmStatic
fun getProcessName(ctx: Context): String? {
val pid = Process.myPid()
val name = getProcessNameFromFile(pid)
if (!name.isNullOrEmpty())
return name
return getProcessNameFromRunningProcesses(ctx, pid)
}

/**
* 获取当前进程名字(遍历方式)
* @param pid 进程id
*/
@JvmStatic
fun getProcessNameFromRunningProcesses(ctx: Context, pid: Int): String? {
val am = ctx.activityManager ?: return null
val i = am.runningAppProcesses.iterator()
tryCatch {
while (i.hasNext()) {
val info = i.next() as ActivityManager.RunningAppProcessInfo
if (info.pid == pid) {
return info.processName
}
}
}
return null
}

/**
* 获取进程号对应的进程名(文件读取方式-bugly推荐方式)
*
* @param pid 进程号
* @return 进程名
*/
@JvmStatic
fun getProcessNameFromFile(pid: Int): String? {
var reader: BufferedReader? = null
try {
reader = BufferedReader(FileReader("/proc/$pid/cmdline"))
var processName: String = reader.readLine()
if (processName.isNotEmpty()) {
processName = processName.trim { it <= ' ' }
}
return processName
} catch (throwable: Throwable) {
throwable.printStackTrace()
} finally {
try {
reader?.close()
} catch (exception: IOException) {
exception.printStackTrace()
}
}
return null
}
}
2 changes: 1 addition & 1 deletion doc/jitpack/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ static def artifactId(name) {
}

ext {
PUBLISH_GROUP_ID = "com.github.qiushui95.MyArchitecture"
PUBLISH_GROUP_ID = "com.github.SupLuo.andme"
PUBLISH_VERSION = "0.0.1-alpha"
artifactId = this.&artifactId
}

0 comments on commit a5bda83

Please sign in to comment.