add a Wallpapers menu button at Widgets too

This commit is contained in:
tibbi 2022-10-05 12:24:48 +02:00
parent 647b1cce18
commit 4b9c235750
2 changed files with 19 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import android.app.Activity
import android.appwidget.AppWidgetHost
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProviderInfo
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
@ -346,13 +347,14 @@ class MainActivity : SimpleActivity(), FlingListener {
private fun showMainLongPressMenu(x: Float, y: Float) {
home_screen_grid.hideResizeLines()
home_screen_popup_menu_anchor.x = x
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_button_offset_y)
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * 2
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
PopupMenu(contextTheme, home_screen_popup_menu_anchor, Gravity.TOP or Gravity.END).apply {
inflate(R.menu.menu_home_screen)
setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.widgets -> showWidgetsFragment()
R.id.wallpapers -> launchWallpapersIntent()
}
true
}
@ -409,6 +411,18 @@ class MainActivity : SimpleActivity(), FlingListener {
showFragment(widgets_fragment)
}
private fun launchWallpapersIntent() {
try {
Intent(Intent.ACTION_SET_WALLPAPER).apply {
startActivity(this)
}
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found)
} catch (e: Exception) {
showErrorToast(e)
}
}
private class MyGestureListener(private val flingListener: FlingListener) : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapUp(event: MotionEvent): Boolean {
(flingListener as MainActivity).homeScreenClicked(event.x, event.y)

View File

@ -5,4 +5,8 @@
android:id="@+id/widgets"
android:title="@string/widgets"
app:showAsAction="always" />
<item
android:id="@+id/wallpapers"
android:title="@string/wallpapers"
app:showAsAction="always" />
</menu>