show the widget preview images
This commit is contained in:
parent
a78374ee59
commit
93b46339cc
|
@ -3,7 +3,10 @@ package com.simplemobiletools.launcher.adapters
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||
import com.simplemobiletools.launcher.R
|
||||
import com.simplemobiletools.launcher.activities.SimpleActivity
|
||||
|
@ -12,6 +15,7 @@ import com.simplemobiletools.launcher.helpers.WIDGET_LIST_SECTION
|
|||
import com.simplemobiletools.launcher.models.WidgetsListItem
|
||||
import com.simplemobiletools.launcher.models.WidgetsListItemsHolder
|
||||
import com.simplemobiletools.launcher.models.WidgetsListSection
|
||||
import kotlinx.android.synthetic.main.item_widget_list_items_holder.view.*
|
||||
import kotlinx.android.synthetic.main.item_widget_list_section.view.*
|
||||
|
||||
class WidgetsAdapter(
|
||||
|
@ -57,7 +61,32 @@ class WidgetsAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupListItemsHolder(view: View, listItem: WidgetsListItem) {}
|
||||
private fun setupListItemsHolder(view: View, listItem: WidgetsListItemsHolder) {
|
||||
view.widget_list_items_holder.removeAllViews()
|
||||
listItem.widgets.forEachIndexed { index, widget ->
|
||||
val imageSize = activity.resources.getDimension(R.dimen.widget_preview_size).toInt()
|
||||
val widgetPreview = LayoutInflater.from(activity).inflate(R.layout.item_widget_preview, null) as ImageView
|
||||
view.widget_list_items_holder.addView(widgetPreview)
|
||||
|
||||
val endMargin = if (index == listItem.widgets.size - 1) {
|
||||
activity.resources.getDimension(R.dimen.medium_margin).toInt()
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
||||
(widgetPreview.layoutParams as LinearLayout.LayoutParams).apply {
|
||||
marginStart = activity.resources.getDimension(R.dimen.activity_margin).toInt()
|
||||
marginEnd = endMargin
|
||||
width = imageSize
|
||||
height = imageSize
|
||||
}
|
||||
|
||||
Glide.with(activity)
|
||||
.load(widget.widgetPreviewImage)
|
||||
.fitCenter()
|
||||
.into(widgetPreview)
|
||||
}
|
||||
}
|
||||
|
||||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bindView(widgetListItem: WidgetsListItem, callback: (itemView: View, adapterPosition: Int) -> Unit) {
|
||||
|
|
|
@ -7,12 +7,12 @@ import android.content.pm.LauncherApps
|
|||
import android.content.pm.PackageManager
|
||||
import android.os.Process
|
||||
import android.util.AttributeSet
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.Surface
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.helpers.isRPlus
|
||||
import com.simplemobiletools.launcher.R
|
||||
import com.simplemobiletools.launcher.activities.MainActivity
|
||||
import com.simplemobiletools.launcher.adapters.WidgetsAdapter
|
||||
import com.simplemobiletools.launcher.models.AppWidget
|
||||
|
@ -49,13 +49,14 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
val appTitle = appMetadata.appTitle
|
||||
val appIcon = appMetadata.appIcon
|
||||
val widgetTitle = info.loadLabel(context.packageManager)
|
||||
val widgetPreviewImage = info.loadPreviewImage(context, DisplayMetrics.DENSITY_MEDIUM)
|
||||
val width = info.minWidth
|
||||
val height = info.minHeight
|
||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, width, height)
|
||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, width, height)
|
||||
appWidgets.add(widget)
|
||||
}
|
||||
|
||||
// list also the widgets that are technically shortcuts
|
||||
// show also the widgets that are technically shortcuts
|
||||
val intent = Intent(Intent.ACTION_CREATE_SHORTCUT, null)
|
||||
val list = context.packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||
for (info in list) {
|
||||
|
@ -65,7 +66,8 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
val appMetadata = getAppMetadataFromPackage(appPackageName) ?: continue
|
||||
val appIcon = appMetadata.appIcon
|
||||
val widgetTitle = info.loadLabel(context.packageManager).toString()
|
||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, 0, 0)
|
||||
val widgetPreviewImage = info.loadIcon(context.packageManager)
|
||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0)
|
||||
appWidgets.add(widget)
|
||||
}
|
||||
|
||||
|
@ -138,7 +140,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
}
|
||||
}
|
||||
|
||||
widgets_list.setPadding(0, 0, resources.getDimension(R.dimen.medium_margin).toInt(), bottomListPadding)
|
||||
widgets_list.setPadding(0, 0, 0, bottomListPadding)
|
||||
widgets_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,5 +2,5 @@ package com.simplemobiletools.launcher.models
|
|||
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
data class AppWidget(var appPackageName: String, var appTitle: String, val appIcon: Drawable, val widgetTitle: String, var width: Int, val height: Int) :
|
||||
data class AppWidget(var appPackageName: String, var appTitle: String, val appIcon: Drawable, val widgetTitle: String, val widgetPreviewImage: Drawable?, var width: Int, val height: Int) :
|
||||
WidgetsListItem()
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/widget_preview_background">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/divider_grey" />
|
||||
<corners android:radius="@dimen/activity_margin" />
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -1,8 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_list_items_holder"
|
||||
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_list_items_scroll_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/medium_margin">
|
||||
android:scrollbars="none">
|
||||
|
||||
</RelativeLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_list_items_holder"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" />
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/widget_preview"
|
||||
android:layout_width="@dimen/widget_preview_size"
|
||||
android:layout_height="@dimen/widget_preview_size"
|
||||
android:layout_gravity="center"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@drawable/widget_preview_background"
|
||||
android:padding="@dimen/normal_margin"
|
||||
tools:src="@mipmap/ic_launcher" />
|
|
@ -1,4 +1,5 @@
|
|||
<resources>
|
||||
<dimen name="launcher_icon_size">55dp</dimen>
|
||||
<dimen name="long_press_anchor_offset_y">70dp</dimen>
|
||||
<dimen name="widget_preview_size">140dp</dimen>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue