dependencies {
implementation 'academy.appdev:floating-context-menu:1.0.6'
}
<dependency>
<groupId>academy.appdev</groupId>
<artifactId>floating-context-menu</artifactId>
<version>1.0.6</version>
<type>pom</type>
</dependency>
menu = floatingMenu(ArrayList<FloatingMenu.MenuItem>().apply {
(0..2).forEach { add(FloatingMenu.MenuItem(R.drawable.search_icon, "Option$it")) }
}) {
// configuration
menuItemSize = 70
menuAngleValue = 130
menuRadius = 130
animationDuration = 250L
}.lparams {
width = matchParent
height = matchParent
}
<appdev.academy.floatingcontextmenu.FloatingMenu
android:id="@+id/floating_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Configure view in your presenter class :
floating_menu.apply {
// configuration
menuItemSize = 70
menuAngleValue = 130
menuRadius = 130
animationDuration = 250L
}
Override dispatchTouchEvent
method of your activity:
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
// Let Floating menu handle event if it can
return if (FloatingMenu.interceptTouch(ev))
true
else
super.dispatchTouchEvent(ev)
}
Detect long tap event for example:
setOnItemLongClickListener { _, _, position, _ ->
menu.apply {
onItemSelected = { toast("Item $position menu option $it") }
onLongTapDetected()
}
true
}
Floating menu has many public fields that can be modified
menuItemSize
- Menu item diameter in dp
menuAngleValue
- Menu item diameter in degrees (0..360)
menuRadius
- Distance between touch position and center of menu items in dp
animationDuration
- Expand/collapse animation duration
collapseScale
- Menu items scale in collapsed state. (1.0 - normal size)
defaultScale
- Menu items scale in expanded state. (1.0 - normal size)
selectedScale
- Menu items scale while touched. (1.0 - normal size)
innerPadding
- Inner padding for icon in item in dp
defaultIconTintResource
- Menu item icon color resource in default state
selectedIconTintResource
- Menu item icon color resource in selected state
defaultBackgroundTintResource
- Menu item background color resource in default state
selectedBackgroundTintResource
- Menu item background color resource in selected state
frameBgColorResource
- Menu background frame color resource
textColorResource
- Menu item title text color resource
Copyright 2019 appdev.academy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.