Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lulululbj committed Jan 1, 2019
1 parent d1d4847 commit ce80300
Show file tree
Hide file tree
Showing 77 changed files with 1,799 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

.idea/
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
40 changes: 40 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
defaultConfig {
applicationId "luyao.box"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}


dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.40'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
implementation 'com.afollestad.material-dialogs:core:2.0.0-rc5'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0"
implementation project(':common')
}
21 changes: 21 additions & 0 deletions app/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
24 changes: 24 additions & 0 deletions app/src/androidTest/java/luyao/box/ExampleInstrumentedTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package luyao.box

import androidx.test.InstrumentationRegistry
import androidx.test.runner.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.getTargetContext()
assertEquals("luyao.box", appContext.packageName)
}
}
33 changes: 33 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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="luyao.box">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:name=".App"
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=".ui.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

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

<activity android:name=".ui.appManager.AppListActivity"/>
<activity android:name=".ui.appManager.AppDetailActivity"/>
</application>

</manifest>
13 changes: 13 additions & 0 deletions app/src/main/java/luyao/box/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package luyao.box

import android.app.Application

/**
* Created by luyao
* on 2018/12/29 13:33
*/
class App : Application() {
override fun onCreate() {
super.onCreate()
}
}
102 changes: 102 additions & 0 deletions app/src/main/java/luyao/box/adapter/AppAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package luyao.box.adapter

import android.content.Context
import android.content.Intent
import android.opengl.Visibility
import android.os.Environment
import android.util.Log
import android.view.View
import android.widget.ImageButton
import android.widget.PopupMenu
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import luyao.box.R
import luyao.box.bean.AppBean
import luyao.box.common.util.AppUtils
import luyao.box.ui.appManager.AppDetailActivity
import luyao.box.util.AppManager
import luyao.box.view.SectorProgressView
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream

/**
* Created by luyao
* on 2018/12/29 10:44
*/
class AppAdapter(layoutResId: Int = R.layout.item_app) : BaseQuickAdapter<AppBean, BaseViewHolder>(layoutResId) {

override fun convert(helper: BaseViewHolder, item: AppBean) {
helper.run {
setImageDrawable(R.id.appIcon, item.icon)
setText(R.id.appName, item.appName)

getView<ImageButton>(R.id.appPop).setOnClickListener {
showPopMenu(helper,helper.itemView.context, it, item)
}
}
}

private fun showPopMenu(helper: BaseViewHolder,context: Context, view: View, appBean: AppBean) {
val popupMenu = PopupMenu(context, view)
popupMenu.menuInflater.inflate(R.menu.menu_app, popupMenu.menu)
popupMenu.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.menu_open_app -> AppUtils.openApp(context, appBean.packageName)
R.id.menu_uninstall_app -> AppUtils.uninstallApp(context, appBean.packageName)
R.id.menu_app_properties -> AppUtils.openAppProperties(context, appBean.packageName)
R.id.menu_app_detail -> context.startActivity(Intent(context, AppDetailActivity::class.java))
R.id.menu_save_apk -> saveApk(helper,context, appBean)
R.id.menu_share_apk -> shareApk()
R.id.menu_open_in_store -> AppUtils.openInStore(context, appBean.packageName)
}
true
}
popupMenu.show()
}

private fun saveApk(helper: BaseViewHolder,context: Context, appBean: AppBean) {
GlobalScope.launch(Dispatchers.Main) {
val progressView = helper.getView<SectorProgressView>(R.id.appProgressView)
val applicationInfo = context.packageManager.getApplicationInfo(appBean.packageName,0)
val apkFile=File(applicationInfo.sourceDir)
val destFile=File("${Environment.getExternalStorageDirectory().path}/${apkFile.name}")
if (!destFile.exists()) destFile.createNewFile()
Log.e("box",apkFile.path)
progressView.visibility=View.VISIBLE
val channel = Channel<Float>()
launch(Dispatchers.IO) {
val input=FileInputStream(apkFile)
val output=FileOutputStream(destFile)
val b = ByteArray(1024)
var hasRead=0f
var count=0
while ((input.read(b)) >0){
output.write(b)
hasRead+=1024f
count++
if (count%10==0)channel.send(hasRead/apkFile.length())
}
channel.send(-1f)
channel.close()
}
for (x in channel) {
Log.e("box","$x")

progressView.percent=x*100
if (x==-1f) progressView.visibility=View.GONE
}
}
}

private fun shareApk() {

}

}

14 changes: 14 additions & 0 deletions app/src/main/java/luyao/box/bean/AppBean.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package luyao.box.bean

import android.graphics.drawable.Drawable

/**
* Created by luyao
* on 2018/12/28 16:32
*/
data class AppBean(
val appName: String,
val packageName: String,
val versionName: String,
val icon: Drawable
)
91 changes: 91 additions & 0 deletions app/src/main/java/luyao/box/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package luyao.box.ui

import com.google.android.material.navigation.NavigationView
import com.google.android.material.snackbar.Snackbar
import androidx.core.view.GravityCompat
import androidx.appcompat.app.ActionBarDrawerToggle
import android.view.Menu
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*
import kotlinx.android.synthetic.main.title_layout.*
import luyao.box.R
import luyao.box.common.base.BaseActivity
import luyao.box.ui.appManager.AppListActivity

class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedListener {

override fun getLayoutResId() = R.layout.activity_main

override fun initView() {
setSupportActionBar(mToolbar)

fab.setOnClickListener {
startActivity(AppListActivity::class.java)
}

val toggle = ActionBarDrawerToggle(
this, drawer_layout, mToolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)
drawer_layout.addDrawerListener(toggle)
toggle.syncState()

nav_view.setNavigationItemSelectedListener(this)
}

override fun initData() {
}

override fun onBackPressed() {
if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
drawer_layout.closeDrawer(GravityCompat.START)
} else {
super.onBackPressed()
}
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
when (item.itemId) {
R.id.action_settings -> return true
else -> return super.onOptionsItemSelected(item)
}
}

override fun onNavigationItemSelected(item: MenuItem): Boolean {
// Handle navigation view item clicks here.
when (item.itemId) {
R.id.nav_camera -> {
// Handle the camera action
}
R.id.nav_gallery -> {

}
R.id.nav_slideshow -> {

}
R.id.nav_manage -> {

}
R.id.nav_share -> {

}
R.id.nav_send -> {

}
}

drawer_layout.closeDrawer(GravityCompat.START)
return true
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/luyao/box/ui/appManager/AppDetailActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package luyao.box.ui.appManager

import kotlinx.android.synthetic.main.title_layout.*
import luyao.box.R
import luyao.box.common.base.BaseActivity

/**
* Created by luyao
* on 2018/12/29 16:35
*/
class AppDetailActivity : BaseActivity() {
override fun getLayoutResId() = R.layout.activity_app_detail

override fun initView() {
mToolbar.title="应用详情"
}

override fun initData() {
}
}
Loading

0 comments on commit ce80300

Please sign in to comment.