show a popup menu at long pressing the home screen
This commit is contained in:
parent
37dedae951
commit
f6f81212db
4 changed files with 49 additions and 4 deletions
|
@ -4,13 +4,14 @@ import android.animation.ObjectAnimator
|
|||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.ContextThemeWrapper
|
||||
import android.view.GestureDetector
|
||||
import android.view.Gravity
|
||||
import android.view.MotionEvent
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import android.widget.PopupMenu
|
||||
import androidx.core.view.GestureDetectorCompat
|
||||
import com.simplemobiletools.commons.extensions.appLaunched
|
||||
import com.simplemobiletools.commons.extensions.beVisible
|
||||
import com.simplemobiletools.commons.extensions.realScreenSize
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.launcher.BuildConfig
|
||||
import com.simplemobiletools.launcher.R
|
||||
import com.simplemobiletools.launcher.fragments.AllAppsFragment
|
||||
|
@ -105,6 +106,30 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
}
|
||||
}
|
||||
|
||||
fun homeScreenLongPressed(x: Float, y: Float) {
|
||||
main_holder.performHapticFeedback()
|
||||
|
||||
popup_menu_anchor.x = x
|
||||
popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y)
|
||||
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||
PopupMenu(contextTheme, popup_menu_anchor, Gravity.TOP or Gravity.END).apply {
|
||||
inflate(R.menu.menu_home_screen)
|
||||
setOnMenuItemClickListener { item ->
|
||||
when (item.itemId) {
|
||||
R.id.widgets -> {
|
||||
showWidgetsFragment()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showWidgetsFragment() {
|
||||
|
||||
}
|
||||
|
||||
private class MyGestureListener(private val flingListener: FlingListener) : GestureDetector.SimpleOnGestureListener() {
|
||||
override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
||||
if (velocityY > 0) {
|
||||
|
@ -114,6 +139,10 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onLongPress(event: MotionEvent) {
|
||||
(flingListener as MainActivity).homeScreenLongPressed(event.x, event.y)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFlingUp() {
|
||||
|
|
|
@ -2,11 +2,17 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/main_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include
|
||||
android:id="@+id/all_apps_fragment"
|
||||
layout="@layout/all_apps_fragment"
|
||||
android:visibility="gone" />
|
||||
|
||||
<View
|
||||
android:id="@+id/popup_menu_anchor"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="1dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
9
app/src/main/res/menu/menu_home_screen.xml
Normal file
9
app/src/main/res/menu/menu_home_screen.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/widgets"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:title="@string/widgets"
|
||||
app:showAsAction="always" />
|
||||
</menu>
|
|
@ -1,3 +1,4 @@
|
|||
<resources>
|
||||
<dimen name="launcher_icon_size">55dp</dimen>
|
||||
<dimen name="long_press_anchor_offset_y">70dp</dimen>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue