adding an initial implementation of launcher displaying
This commit is contained in:
parent
e57f7a438d
commit
c5de82481f
|
@ -4,6 +4,10 @@
|
||||||
package="com.simplemobiletools.launcher"
|
package="com.simplemobiletools.launcher"
|
||||||
android:installLocation="auto">
|
android:installLocation="auto">
|
||||||
|
|
||||||
|
<uses-permission
|
||||||
|
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||||
|
tools:ignore="QueryAllPackagesPermission" />
|
||||||
|
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.USE_FINGERPRINT"
|
android:name="android.permission.USE_FINGERPRINT"
|
||||||
tools:node="remove" />
|
tools:node="remove" />
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
package com.simplemobiletools.launcher.activities
|
package com.simplemobiletools.launcher.activities
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.LauncherApps
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.simplemobiletools.commons.extensions.appLaunched
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
|
||||||
import com.simplemobiletools.commons.models.FAQItem
|
import com.simplemobiletools.commons.models.FAQItem
|
||||||
|
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||||
import com.simplemobiletools.launcher.BuildConfig
|
import com.simplemobiletools.launcher.BuildConfig
|
||||||
import com.simplemobiletools.launcher.R
|
import com.simplemobiletools.launcher.R
|
||||||
|
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
|
||||||
|
import com.simplemobiletools.launcher.models.AppLauncher
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity() {
|
class MainActivity : SimpleActivity() {
|
||||||
|
@ -15,11 +22,14 @@ class MainActivity : SimpleActivity() {
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
appLaunched(BuildConfig.APPLICATION_ID)
|
appLaunched(BuildConfig.APPLICATION_ID)
|
||||||
setupOptionsMenu()
|
setupOptionsMenu()
|
||||||
|
getLaunchers()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
setupToolbar(main_toolbar)
|
setupToolbar(main_toolbar)
|
||||||
|
updateTextColors(main_coordinator)
|
||||||
|
launchers_fastscroller.updateColors(getProperPrimaryColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupOptionsMenu() {
|
private fun setupOptionsMenu() {
|
||||||
|
@ -33,6 +43,62 @@ class MainActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("WrongConstant")
|
||||||
|
private fun getLaunchers() {
|
||||||
|
val allApps = ArrayList<AppLauncher>()
|
||||||
|
val allPackageNames = ArrayList<String>()
|
||||||
|
val intent = Intent(Intent.ACTION_MAIN, null)
|
||||||
|
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
|
||||||
|
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||||
|
for (info in list) {
|
||||||
|
val componentInfo = info.activityInfo.applicationInfo
|
||||||
|
val label = componentInfo.loadLabel(packageManager).toString()
|
||||||
|
val packageName = componentInfo.packageName
|
||||||
|
|
||||||
|
var drawable: Drawable? = null
|
||||||
|
try {
|
||||||
|
// try getting the properly colored launcher icons
|
||||||
|
val launcher = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||||
|
val activityList = launcher.getActivityList(packageName, android.os.Process.myUserHandle())[0]
|
||||||
|
drawable = activityList.getBadgedIcon(0)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
} catch (e: Error) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawable == null) {
|
||||||
|
drawable = try {
|
||||||
|
packageManager.getApplicationIcon(packageName)
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allPackageNames.add(packageName)
|
||||||
|
allApps.add(AppLauncher(0, label, packageName, 0, drawable))
|
||||||
|
}
|
||||||
|
|
||||||
|
val launchers = allApps.distinctBy { it.packageName } as ArrayList<AppLauncher>
|
||||||
|
launchers.sortBy { it.title.toLowerCase() }
|
||||||
|
|
||||||
|
val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager
|
||||||
|
layoutManager.spanCount = if (portrait) {
|
||||||
|
resources.getInteger(R.integer.portrait_column_count)
|
||||||
|
} else {
|
||||||
|
resources.getInteger(R.integer.landscape_column_count)
|
||||||
|
}
|
||||||
|
|
||||||
|
setupAdapter(launchers)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupAdapter(launchers: ArrayList<AppLauncher>) {
|
||||||
|
LaunchersAdapter(this, launchers) {
|
||||||
|
|
||||||
|
}.apply {
|
||||||
|
launchers_grid.adapter = this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun launchSettings() {
|
private fun launchSettings() {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.simplemobiletools.launcher.adapters
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||||
|
import com.simplemobiletools.commons.extensions.portrait
|
||||||
|
import com.simplemobiletools.commons.extensions.realScreenSize
|
||||||
|
import com.simplemobiletools.launcher.R
|
||||||
|
import com.simplemobiletools.launcher.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.launcher.models.AppLauncher
|
||||||
|
import kotlinx.android.synthetic.main.item_launcher_label.view.*
|
||||||
|
|
||||||
|
class LaunchersAdapter(
|
||||||
|
val activity: SimpleActivity,
|
||||||
|
val launchers: ArrayList<AppLauncher>,
|
||||||
|
val itemClick: (Any) -> Unit
|
||||||
|
) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>() {
|
||||||
|
private var textColor = activity.getProperTextColor()
|
||||||
|
private var iconPadding = 0
|
||||||
|
|
||||||
|
init {
|
||||||
|
calculateIconWidth()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_launcher_label, parent, false)
|
||||||
|
return ViewHolder(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
holder.bindView(launchers[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount() = launchers.size
|
||||||
|
|
||||||
|
private fun calculateIconWidth() {
|
||||||
|
val currentColumnCount = if (activity.portrait) {
|
||||||
|
activity.resources.getInteger(R.integer.portrait_column_count)
|
||||||
|
} else {
|
||||||
|
activity.resources.getInteger(R.integer.landscape_column_count)
|
||||||
|
}
|
||||||
|
|
||||||
|
val iconWidth = activity.realScreenSize.x / currentColumnCount
|
||||||
|
iconPadding = (iconWidth * 0.1f).toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
fun bindView(launcher: AppLauncher): View {
|
||||||
|
itemView.apply {
|
||||||
|
launcher_label.text = launcher.title
|
||||||
|
launcher_label.setTextColor(textColor)
|
||||||
|
launcher_icon.setImageDrawable(launcher.drawable!!)
|
||||||
|
launcher_icon.setPadding(iconPadding, iconPadding, iconPadding, 0)
|
||||||
|
setOnClickListener { itemClick(launcher) }
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemView
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.simplemobiletools.launcher.models
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_BY_TITLE
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
|
|
||||||
|
data class AppLauncher(val id: Int, var title: String, val packageName: String, var order: Int, val drawable: Drawable? = null) : Comparable<AppLauncher> {
|
||||||
|
companion object {
|
||||||
|
var sorting = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?) = packageName.equals((other as AppLauncher).packageName, true)
|
||||||
|
|
||||||
|
fun getBubbleText() = title
|
||||||
|
|
||||||
|
override fun compareTo(other: AppLauncher): Int {
|
||||||
|
var result = when {
|
||||||
|
sorting and SORT_BY_TITLE != 0 -> title.toLowerCase().compareTo(other.title.toLowerCase())
|
||||||
|
else -> {
|
||||||
|
if (order > 0 && other.order == 0) {
|
||||||
|
-1
|
||||||
|
} else if (order == 0 && other.order > 0) {
|
||||||
|
1
|
||||||
|
} else if (order > 0 && other.order > 0) {
|
||||||
|
order.compareTo(other.order)
|
||||||
|
} else {
|
||||||
|
title.toLowerCase().compareTo(other.title.toLowerCase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sorting and SORT_DESCENDING != 0) {
|
||||||
|
result *= -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/main_coordinator"
|
android:id="@+id/main_coordinator"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
@ -25,6 +26,49 @@
|
||||||
android:id="@+id/main_holder"
|
android:id="@+id/main_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
android:id="@+id/coordinator_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/launchers_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/no_items_placeholder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingStart="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingEnd="@dimen/activity_margin"
|
||||||
|
android:text="@string/no_items_found"
|
||||||
|
android:textSize="@dimen/bigger_text_size"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||||
|
android:id="@+id/launchers_fastscroller"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
android:id="@+id/launchers_grid"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager"
|
||||||
|
app:spanCount="@integer/portrait_column_count" />
|
||||||
|
|
||||||
|
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
|
||||||
|
</RelativeLayout>
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
</RelativeLayout>
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/launcher_holder"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:paddingStart="@dimen/small_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingEnd="@dimen/small_margin"
|
||||||
|
android:paddingBottom="@dimen/small_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MySquareImageView
|
||||||
|
android:id="@+id/launcher_icon"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/launcher_icon_size"
|
||||||
|
android:layout_gravity="center_horizontal|bottom" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/launcher_label"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/launcher_icon"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:gravity="center_horizontal|top"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:textSize="@dimen/smaller_text_size" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<resources>
|
||||||
|
<integer name="portrait_column_count">6</integer>
|
||||||
|
<integer name="landscape_column_count">10</integer>
|
||||||
|
</resources>
|
|
@ -1,3 +1,3 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
<dimen name="launcher_icon_size">55dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<resources>
|
||||||
|
<integer name="portrait_column_count">5</integer>
|
||||||
|
<integer name="landscape_column_count">8</integer>
|
||||||
|
</resources>
|
Loading…
Reference in New Issue