adding some widget fetching code
This commit is contained in:
parent
6ad5fc7b0d
commit
f154b444cc
4 changed files with 79 additions and 1 deletions
|
@ -30,9 +30,9 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : RelativeLa
|
|||
@SuppressLint("ClickableViewAccessibility")
|
||||
fun setupFragment(activity: MainActivity) {
|
||||
this.activity = activity
|
||||
getLaunchers()
|
||||
background.applyColorFilter(activity.getProperBackgroundColor())
|
||||
setPadding(0, activity.statusBarHeight, 0, 0)
|
||||
getLaunchers()
|
||||
|
||||
all_apps_grid.setOnTouchListener { v, event ->
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.simplemobiletools.launcher.fragments
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.getProperBackgroundColor
|
||||
import com.simplemobiletools.commons.extensions.statusBarHeight
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.launcher.activities.MainActivity
|
||||
import com.simplemobiletools.launcher.models.AppWidget
|
||||
|
||||
class WidgetsFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||
private var activity: MainActivity? = null
|
||||
|
||||
fun setupFragment(activity: MainActivity) {
|
||||
this.activity = activity
|
||||
background.applyColorFilter(activity.getProperBackgroundColor())
|
||||
setPadding(0, activity.statusBarHeight, 0, 0)
|
||||
getWidgets()
|
||||
}
|
||||
|
||||
private fun getWidgets() {
|
||||
ensureBackgroundThread {
|
||||
var widgets = ArrayList<AppWidget>()
|
||||
val manager = AppWidgetManager.getInstance(context)
|
||||
val infoList = manager.installedProviders
|
||||
for (info in infoList) {
|
||||
val appPackageName = info.provider.packageName
|
||||
val appTitle = getAppNameFromPackage(appPackageName) ?: continue
|
||||
val widgetTitle = info.loadLabel(activity?.packageManager)
|
||||
val width = info.minWidth
|
||||
val height = info.minHeight
|
||||
val widget = AppWidget(appPackageName, appTitle, widgetTitle, width, height)
|
||||
widgets.add(widget)
|
||||
}
|
||||
|
||||
widgets = widgets.sortedWith(compareBy({ it.appTitle }, { it.widgetTitle })).toMutableList() as ArrayList<AppWidget>
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAppNameFromPackage(packageName: String): String? {
|
||||
try {
|
||||
val appInfo = activity!!.packageManager.getApplicationInfo(packageName, 0)
|
||||
return activity!!.packageManager.getApplicationLabel(appInfo).toString()
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package com.simplemobiletools.launcher.models
|
||||
|
||||
data class AppWidget(var appPackageName: String, var appTitle: String, val widgetTitle: String, var width: Int, val height: Int)
|
23
app/src/main/res/layout/widgets_fragment.xml
Normal file
23
app/src/main/res/layout/widgets_fragment.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.launcher.fragments.AllAppsFragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/widgets_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/all_apps_background">
|
||||
|
||||
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||
android:id="@+id/widgets_fastscroller"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:fastScrollEnabled="false">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/widgets_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||
|
||||
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
|
||||
</com.simplemobiletools.launcher.fragments.AllAppsFragment>
|
Loading…
Reference in a new issue