Giter Club home page Giter Club logo

powermenu's Introduction

PowerMenu


🔥 PowerMenu is a modernized and fully customizable popup menu, which can be displayed on top of layouts.


Google
License API CI AndroidWeekly Medium Profile Javadoc


Download

Maven Central

I really appreciate that 🔥 PowerMenu has been used in more than 340,000+ projects all over the world. 🌎

screenshot1903218121

Gradle

And add the dependency below to your module's build.gradle file:

dependencies {
  implementation "com.github.skydoves:powermenu:2.2.4"
}

Table of Contents

1. PowerMenu
2. Customizing Popup
3. Preference
4. Menu Effect
5. Dialogs
6. Anchor
7. Background
8. Avoid Memory leak
9. Functions
10. Lazy initialization in Kotlin

Usage

Basic example

This is a basic example on a screenshot. Here is how to create PowerMenu using PowerMenu.Builder.

PowerMenu powerMenu = new PowerMenu.Builder(context)
          .addItemList(list) // list has "Novel", "Poetry", "Art"
          .addItem(new PowerMenuItem("Journals", false)) // add an item.
          .addItem(new PowerMenuItem("Travel", false)) // aad an item list.
          .setAnimation(MenuAnimation.SHOWUP_TOP_LEFT) // Animation start point (TOP | LEFT).
          .setMenuRadius(10f) // sets the corner radius.
          .setMenuShadow(10f) // sets the shadow.
          .setTextColor(ContextCompat.getColor(context, R.color.md_grey_800))
          .setTextGravity(Gravity.CENTER)
          .setTextTypeface(Typeface.create("sans-serif-medium", Typeface.BOLD))
          .setSelectedTextColor(Color.WHITE)
          .setMenuColor(Color.WHITE)
          .setSelectedMenuColor(ContextCompat.getColor(context, R.color.colorPrimary))
          .setOnMenuItemClickListener(onMenuItemClickListener)
          .build();

We can add an item or an item list using PowerMenuItem class. This is how to initialize PowerMenuItem.

new PowerMenuItem("Travel");
new PowerMenuItem("Poetery", false); // item name, isSelected (default is false).
new PowerMenuItem("Art", R.drawable.icon_art) // item name, item menu icon.
new PowerMenuItem("Travel", R.drawable.icon_travel, true) // item name, item menu icon, isSelected .

The first argument is an item title, and the other is selected status.
If isSelected is true, the item's text and the background color will be changed by settings like below.

.setSelectedTextColor(Color.WHITE) // sets the color of the selected item text. 
.setSelectedMenuColor(ContextCompat.getColor(context, R.color.colorPrimary)) // sets the color of the selected menu item color.

OnMenuItemClickListener is for listening to the item click of the popup menu.

private OnMenuItemClickListener<PowerMenuItem> onMenuItemClickListener = new OnMenuItemClickListener<PowerMenuItem>() {
    @Override
    public void onItemClick(int position, PowerMenuItem item) {
        Toast.makeText(getBaseContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
        powerMenu.setSelectedPosition(position); // change selected item
        powerMenu.dismiss();
    }
};

After implementing the listener, we should set using setOnMenuItemClickListener method.

.setOnMenuItemClickListener(onMenuItemClickListener)

The last, show the popup! Various show & dismiss methods.

powerMenu.showAsDropDown(view); // view is an anchor

Customizing Popup

We can customize item styles using CustomPowerMenu and your customized adapter.
Here is how to customize the popup item that has an icon.

custom0 gif0

Firstly, we should create our item model class.

public class IconPowerMenuItem {
    private Drawable icon;
    private String title;

    public IconPowerMenuItem(Drawable icon, String title) {
        this.icon = icon;
        this.title = title;
    }
 // --- skipped setter and getter methods
}

And we should create our customized XML layout and an adapter.
Custom Adapter should extend MenuBaseAdapter<YOUR_ITEM_MODEL_CLASS>.

public class IconMenuAdapter extends MenuBaseAdapter<IconPowerMenuItem> {

    @Override
    public View getView(int index, View view, ViewGroup viewGroup) {
        final Context context = viewGroup.getContext();

        if(view == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.item_icon_menu, viewGroup, false);
        }

        IconPowerMenuItem item = (IconPowerMenuItem) getItem(index);
        final ImageView icon = view.findViewById(R.id.item_icon);
        icon.setImageDrawable(item.getIcon());
        final TextView title = view.findViewById(R.id.item_title);
        title.setText(item.getTitle());
        return super.getView(index, view, viewGroup);
    }
}

The last, create the CustomPowerMenu with the onMenuItemClickListener.

CustomPowerMenu customPowerMenu = new CustomPowerMenu.Builder<>(context, new IconMenuAdapter())
       .addItem(new IconPowerMenuItem(ContextCompat.getDrawable(context, R.drawable.ic_wechat), "WeChat"))
       .addItem(new IconPowerMenuItem(ContextCompat.getDrawable(context, R.drawable.ic_facebook), "Facebook"))
       .addItem(new IconPowerMenuItem(ContextCompat.getDrawable(context, R.drawable.ic_twitter), "Twitter"))
       .addItem(new IconPowerMenuItem(ContextCompat.getDrawable(context, R.drawable.ic_line), "Line"))
       .setOnMenuItemClickListener(onIconMenuItemClickListener)
       .setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT)
       .setMenuRadius(10f)
       .setMenuShadow(10f)
       .build();
private OnMenuItemClickListener<IconPowerMenuItem> onIconMenuItemClickListener = new OnMenuItemClickListener<IconPowerMenuItem>() {
    @Override
    public void onItemClick(int position, IconPowerMenuItem item) {
        Toast.makeText(getBaseContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
        iconMenu.dismiss();
    }
};

Preference

PowerMenu supports saving of the last selected menu and recovering as lifecycle.
Here is how to save and recover selected menu.

return new PowerMenu.Builder(context)
    // saves the position automatically when the menu is selected.
    // If we set the same preference name on the other PowerMenus, they will share the saving position.
   .setPreferenceName("HamburgerPowerMenu")

    // invokes the listener automatically that has the saved position arguments along the lifecycle rule.
    // lifecycle rules should be ON_CREATE, ON_START or ON_RESUME.
    // in the below codes, the onMenuClickListener will be invoked when onCreate lifecycle.
   .setLifecycleOwner(lifecycleOwner)
   .setInitializeRule(Lifecycle.Event.ON_CREATE, 0) // Lifecycle.Event and default position.
   --- skips ---

Here are the methods related to preference.

.getPreferenceName() // gets the preference name of PowerMenu.
.getPreferencePosition(int defaultPosition) // gets the saved preference position from the SharedPreferences.
.setPreferencePosition(int defaultPosition) // sets the preference position name for persistence manually.
.clearPreference() // clears the preference name of PowerMenu.

Menu Effect

We can give two types of circular revealed animation effect.

menu_effect01 menu_effect02
Here is how to create a menu effect simply.

.setCircularEffect(CircularEffect.BODY) // shows circular revealed effects for all body of the popup menu.
.setCircularEffect(CircularEffect.INNER) // Shows circular revealed effects for the content view of the popup menu.

Dialogs

We can create looks like dialogs using PowerMenu.

screenshot_2017-12-18-23-39-00 screenshot_2017-12-18-23-39-05

Here is an example of the normal dialog. Dialogs are composed of a header, footer, and body.

PowerMenu powerMenu = new PowerMenu.Builder(context)
           .setHeaderView(R.layout.layout_dialog_header) // header used for title
           .setFooterView(R.layout.layout_dialog_footer) // footer used for yes and no buttons
           .addItem(new PowerMenuItem("This is DialogPowerMenu", false)) // this is body
           .setLifecycleOwner(lifecycleOwner)
           .setAnimation(MenuAnimation.SHOW_UP_CENTER)
           .setMenuRadius(10f)
           .setMenuShadow(10f)
           .setWith(600)
           .setSelectedEffect(false)
           .build();

And we can create a customized dialog like below.

CustomPowerMenu customPowerMenu = new CustomPowerMenu.Builder<>(context, new CustomDialogMenuAdapter())
         setHeaderView(R.layout.layout_custom_dialog_header) // header used for title
        .setFooterView(R.layout.layout_custom_dialog_footer) // footer used for Read More and Close buttons
         // this is body
        .addItem(new NameCardMenuItem(ContextCompat.getDrawable(context, R.drawable.face3), "Sophie", context.getString(R.string.board3)))
        .setLifecycleOwner(lifecycleOwner)
        .setAnimation(MenuAnimation.SHOW_UP_CENTER)
        .setWith(800)
        .setMenuRadius(10f)
        .setMenuShadow(10f)
        .build();

Anchor

We can show the popup menu as drop down to the anchor.

.showAsAnchorLeftTop(view) // showing the popup menu as left-top aligns to the anchor.
.showAsAnchorLeftBottom(view) // showing the popup menu as left-bottom aligns to the anchor.
.showAsAnchorRightTop(view) // using with .setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT) looks better
.showAsAnchorRightBottom(view) // using with .setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT) looks better
.showAsAnchorCenter(view) // using with .setAnimation(MenuAnimation.SHOW_UP_CENTER) looks better

or we can control the position of the popup menu using the below methods.

.getContentViewWidth() // return popup's measured width
.getContentViewHeight() // return popup's measured height

like this :

// showing the popup menu at the center of an anchor. This is the same using .showAsAnchorCenter.
hamburgerMenu.showAsDropDown(view, 
        view.getMeasuredWidth()/2 - hamburgerMenu.getContentViewWidth(), 
       -view.getMeasuredHeight()/2 - hamburgerMenu.getContentViewHeight());

Background

These are options for the background.

.setShowBackground(false) // do not showing background.
.setTouchInterceptor(onTouchListener) // sets the touch listener for the outside of popup.
.setFocusable(true) // makes focusing only on the menu popup.

Avoid Memory leak

Dialog, PopupWindow and etc.. have memory leak issue if not dismissed before activity or fragment are destroyed.
But Lifecycles are now integrated with the Support Library since Architecture Components 1.0 Stable released.
So we can solve the memory leak issue so easily.

Just use setLifecycleOwner method. Then dismiss method will be called automatically before activity or fragment would be destroyed.

.setLifecycleOwner(lifecycleOwner)

Lazy initialization in Kotlin

We can initialize the PowerMenu property lazily using powerMenu keyword and PowerMenu.Factory abstract class.
The powerMenu extension keyword can be used in Activity and Fragment.

class MainActivity : AppCompatActivity() {

  private val moreMenu by powerMenu(MoreMenuFactory::class)
  
  //..

We should create a factory class which extends PowerMenu.Factory.
An implementation class of the factory must have a default(non-argument) constructor.

class MoreMenuFactory : PowerMenu.Factory() {

  override fun create(context: Context, lifecycle: LifecycleOwner?): PowerMenu {
    return createPowerMenu(context) {
      addItem(PowerMenuItem("Novel", true))
      addItem(PowerMenuItem("Poetry", false))
      setAutoDismiss(true)
      setLifecycleOwner(lifecycle)
      setAnimation(MenuAnimation.SHOWUP_TOP_LEFT)
      setTextColor(ContextCompat.getColor(context, R.color.md_grey_800))
      setTextSize(12)
      setTextGravity(Gravity.CENTER)
      setTextTypeface(Typeface.create("sans-serif-medium", Typeface.BOLD))
      setSelectedTextColor(Color.WHITE)
      setMenuColor(Color.WHITE)
      setInitializeRule(Lifecycle.Event.ON_CREATE, 0)
    }
  }
}

Functions

PowerMenu methods

.addItemList(list) // add a PowerMenuItem list.
.addItem(new PowerMenuItem("Journals", false)) // add a PowerMenuItem.
.addItem(3, new PowerMenuItem("Travel", false)) // add a PowerMenuItem at position 3.
.setLifecycleOwner(lifecycleOwner) // set LifecycleOwner for preventing memory leak.
.setWith(300) // sets the popup width size.
.setHeight(400) // sets the popup height size.
.setMenuRadius(10f) // sets the popup corner radius.
.setMenuShadow(10f) // sets the popup shadow.
.setDivider(new ColorDrawable(ContextCompat.getColor(context, R.color.md_blue_grey_300))) // sets a divider.
.setDividerHeight(1) // sets the divider height.
.setAnimation(MenuAnimation.FADE) // sets animations of the popup. It will start up when the popup is showing.
.setTextColor(ContextCompat.getColor(context, R.color.md_grey_800)) // sets the color of the default item text.
.setTextSize(12) // sets a text size of the item text
.setTextGravity(Gravity.CENTER) // sets a gravity of the item text.
.setTextTypeface(Typeface.create("sans-serif-medium", Typeface.BOLD)) // sets a typeface of the item text
.setSelectedTextColor(Color.WHITE) // sets the color of the selected item text.
.setMenuColor(Color.WHITE) // sets the color of the menu item color.
.setSelectedMenuColor(ContextCompat.getColor(context, R.color.colorPrimary)) // sets the color of the selected menu item color.
.setSelectedEffect(false) // sets the selected effects what changing colors of the selected menu item.
.setOnMenuItemClickListener(onMenuItemClickListener) // sets an item click listener.
.setOnDismissListener(OnDismissedListener onDismissListener) // sets a menu dismiss listener.
.setHeaderView(View view) //  sets the header view of the popup menu list.
.setHeaderView(int layout) // sets the header view of the popup menu using layout.
.setFooterView(View view) // sets the footer view of the popup menu list.
.setFooterView(int layout) // sets the footer view of the popup menu using layout.
.setSelection(int position) // sets the selected position of the popup menu. It can be used for scrolling as the position.
.getSelectedPosition() // gets the selected item position. if not selected before, returns -1 .
.getHeaderView() // gets the header view of the popup menu list.
.getFooterView() // gets the footer view of the popup menu list.
.getMenuListView() // gets the ListView of the popup menu.

Background methods

.setBackgroundAlpha(0.7f) // sets the alpha of the background.
.setBackgroundColor(Color.GRAY) // sets the color of the background.
.setShowBackground(false) // sets the background is showing or not.
.setOnBackgroundClickListener(onClickListener) // sets the background click listener of the background.

Show & Dismiss

.showAsDropDown(View anchor); // showing the popup menu as drop down to the anchor.
.showAsDropDown(View anchor, -370, 0); // showing the popup menu as drop down to the anchor with x-off and y-off.
.showAtCenter(View layout); // showing the popup menu as center aligns to the anchor.
.showAtCenter(View layout, 0, 0); // showing the popup menu as center aligns to the anchor with x-off and y-off.
.showAtLocation(View anchor, int xOff, int yOff) // showing the popup menu as center aligns to the anchor with x-off and y-off.
.showAtLocation(View anchor, int gravity, int xOff, int yOff) // showing the popup menu to the specific location to the anchor with Gravity.
.isShowing(); // gets the popup is showing or not.
.dismiss(); // dismiss the popup.

Find this library useful? ❤️

Support it by joining stargazers for this repository. ⭐
And follow me for my next creations! 🤩

License

Copyright 2017 skydoves

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.

powermenu's People

Contributors

0xflotus avatar codacy-badger avatar khoben avatar robbwatershed avatar sebastienrouif avatar skydoves avatar ssaqua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powermenu's Issues

click for menu item is not happening on Custom Power Menu

I tried integrating Power menu in my project but the click is not happening. I tried keeping an log also but its not going inside loop.
customPowerMenu = new CustomPowerMenu.Builder<>(MapsActivityNew.this, new IconMenuAdapter())
.setWith(550)
.setHeight(780)
.addItem(new MapMenuFilter(false, "XXXX"))
.addItem(new MapMenuFilter(false, "XXXX"))
.setAnimation(MenuAnimation.SHOWUP_BOTTOM_RIGHT)
.setMenuRadius(10f)
.setMenuShadow(10f)
.build();

private OnMenuItemClickListener onIconMenuItemClickListener = new OnMenuItemClickListener() {
@OverRide
public void onItemClick(int position, MapMenuFilter item) {
Log.e("Selected",item.getFilterName()+" << >> "+position);
}
};

menu can not click

i down load the demo

but can not click the menu ,is there some thing wrong?

Many selections

Is it possible to be able to select many items at once? I'm using PowerMany as a menu to filter some things.

font family

how to set specific font for the menu items, i mean is there any function like, powermenu.setTypeFace() ? please guide, thanks

in recyclerview last items the context menu isn't shown correctly

  • Library Version: 2.1.2
  • Affected Device(s): Xiaomi MI 9 With Android 10

i use following code for show context menu in every item of recyclerview:

powerMenu = new PowerMenu.Builder(BackupActivity.this) .addItem(new PowerMenuItem("بازگردانی")) .addItem(new PowerMenuItem("ارسال به سرور")) .addItem(new PowerMenuItem("اشتراک گذاری")) //.setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT) .setMenuRadius(10f) // sets the corner radius. .setMenuShadow(10f) // sets the shadow. .setDivider(new ColorDrawable(ContextCompat.getColor(BackupActivity.this, R.color.main_background))) .setDividerHeight(1) .setTextColor(ContextCompat.getColor(BackupActivity.this, R.color.text_color)) .setTextGravity(Gravity.CENTER) .setTextTypeface(ResourcesCompat.getFont(BackupActivity.this, R.font.iy_regular)) .setTextSize(15) .setSelectedTextColor(Color.WHITE) .setMenuColor(Color.WHITE) .setSelectedMenuColor(ContextCompat.getColor(BackupActivity.this, R.color.colorPrimary)) .build();

but in last items the context menu isn't shown correctly
like the picture below:
pic

i expected, detect item position and show context menu automatically in up or bottom or left or right
is it possible?

sorry for poor my english

Problem after update 2.0.5 to 2.0.7: incompatible types: android.arch.lifecycle.LifecycleOwner cannot be converted to androidx.lifecycle.LifecycleOwner

When i was updated library to 2.7.0 i have compilation error:
incompatible types: android.arch.lifecycle.LifecycleOwner cannot be converted to androidx.lifecycle.LifecycleOwner

in my method:

public static CustomPowerMenu getCustomDialogPowerMenu(Context context, LifecycleOwner lifecycleOwner, OnMenuItemClickListener onMenuItemClickListener, OnDismissedListener onMoreMenuDismissedListener) {R.drawable.ic_action_promotion);
        final Drawable prDrawable = ContextCompat.getDrawable(context, R.drawable.ic_action_pr);
        final String prTitle = context.getResources().getString(R.string.more_menu_item_pr);
        return new CustomPowerMenu.Builder<>(context, new IconMenuAdapter())
                .addItem(new IconPowerMenuItem(prDrawable, prTitle, false))
                .setAnimation(MenuAnimation.SHOWUP_BOTTOM_RIGHT)
                .setLifecycleOwner(lifecycleOwner) // <-compilation error
                .setShowBackground(false)
                .setOnMenuItemClickListener(onMenuItemClickListener)
                .setOnDismissListener(onMoreMenuDismissedListener)
                .build();
    }

My method is called from Activity:

PowerMenuUtils.getCustomDialogPowerMenu(this, this, onMoreMenuItemClickListener, onMoreMenuDismissedListener);

How to check it? Or maybe roll back to 2.5.0?

show as anchor from center

I have a view that has width of match_parent it's also my view anchor, I want toshow my pop-up from this view's center but it either show up from left or right

CustomPowerMenu setSelectedPosition() not working

I am trying to set an item as selected

powerMenu.setSelectedPosition(4);

In adapter i want to change the background color of selected item

public class DoubleTextMenuAdapter extends MenuBaseAdapter<DoubleTextMenuItem> {

    @Override
    public View getView(int index, View view, ViewGroup viewGroup) {
        final Context context = viewGroup.getContext();

        if(view == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.popup_tool_double_text, viewGroup, false);
        }

        DoubleTextMenuItem item = (DoubleTextMenuItem) getItem(index);
        final TextView title = view.findViewById(R.id.tv_item_title);
        title.setText(item.getTitle());
        final TextView value = view.findViewById(R.id.tv_item_value);
        value.setText(item.getValue());

        if(index == getSelectedPosition())
            view.setBackgroundColor(ContextCompat.getColor(context, R.color.colorAccent));
        else
            view.setBackgroundColor(Color.WHITE);

        return super.getView(index, view, viewGroup);
    }

    @Override
    public void setSelectedPosition(int position) {
        notifyDataSetChanged();
    }
}

But getSelectedPosition() always return -1 in adapter

item layout order

Hi,
Great spinner! I would like to change something, I want to put the text below the image is there a way to that?

error run app in emulator

Hi.
When I add 'implementation "com.github.skydoves:powermenu:2.0.5"' build or running app become failed with this error : "Compilation failed; see the compiler error output for details."
what should I do??
I use android studio 3.1.3 / min_sdk = 18/target_sdk=27 / buildToolsVersion= '27.0.3'
Thank you.

powerMenu.isShowing() method null pointer exeption.



public class GuestProfileFragment extends Fragment {
    PowerMenu powerMenu;

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_guest_profile, container, false);
     
       powerMenu = new PowerMenu.Builder(getContext())
                .addItem(new PowerMenuItem(getString(R.string.block), false))
                .addItem(new PowerMenuItem(getString(R.string.report), false))
                .setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT)
                .setMenuRadius(10f)
                .setMenuShadow(10f)
                .setTextColor(getResources().getColor(R.color.md_grey_800))
                .setSelectedTextColor(Color.WHITE)
                .setMenuColor(Color.WHITE)
                .setSelectedMenuColor(getResources().getColor(R.color.colorPrimary))
                .setOnMenuItemClickListener(new OnMenuItemClickListener<PowerMenuItem>() {
                    @Override
                    public void onItemClick(int position, PowerMenuItem item) {
                        Toast.makeText(getContext(),item.getTitle(),Toast.LENGTH_SHORT).show();
                        powerMenu.dismiss();
                    }
                })
                .build();
   
        return view;
    }

public void backpress(){
        if(powerMenu.isShowing()){
            powerMenu.dismiss();
        }
        else{
            getFragmentManager().popBackStack();
        }
    }

}

This code give me null pointer exception how to fix this?

I saw your code u used PowerMenuUtil class but that class doesnt show up .

one more thing

this is the only dependency i use
implementation "com.github.skydoves:powermenu:2.0.5"

Wrong position in RecyclerView

screenshot_1521524357

The menu is attached to the "Productive" TextView, it looks fine on other list items, but when clicked on the last shown item in list, it ties to expand into the space remaining below the item instead of top.

contextMenu.showAsDropDown(view, 0, 0);

Add "tag" to PowerMenuItem

This is an enhancement:

Add a "tag" member to PowerMenuItem to pass related information. Ideally, there should be an additional constructor and an inherited type-safe version (eg PowerMenuItem<TagType>

Issue is that currently you pretty much have to do a text match on the title to find which item was clicked.

invalid height

Please complete the following information:

  • Library Version :2.0.8
  • Affected Device(s) : All devices

Describe the Bug:

When list has only one child and has a header it shows only the header the list item exists under overflow part (scrolls)
setting manual height wont work at all

Expected Behavior:

menu should shows at least some items but it shows only header

*edit 1 :
setting Height wont work at all

  PowerMenu.Builder builder = new PowerMenu.Builder(this)
                .setHeaderView(R.layout.servers_header)
                .setAnimation(MenuAnimation.SHOW_UP_CENTER) // Animation start point (TOP | LEFT).
                .setMenuRadius(10f) // sets the corner radius.
                .setMenuShadow(10f) // sets the shadow.
                .setTextColor(getResources().getColor(R.color.colorAccent))
                .setSelectedTextColor(Color.WHITE)
                .setMenuColor(Color.WHITE)
                .setLifecycleOwner(this)
                .setWidth(mHomeLayout.getMeasuredWidth() - 100)
                .setHeight(mHomeLayout.getMeasuredHeight())
                .setOnMenuItemClickListener(onServerMenuClicked());
            for(int i = 0 ; i < length ; i++){
                builder.addItem(new PowerMenuItem("Server #" + String.valueOf(i),false));
            }
            mServersMenu = builder.build();
            mServersMenu.showAsAnchorCenter(mHomeLayout);

setting height to any number wont affect the height at all

image

Error when trying to use the library

The library looks fantastic and I would like to use it.
I added the following to the build.gradle

implementation 'com.github.skydoves:powermenu:2.0.3

on onCreate I have the following code -

         powerMenu = new PowerMenu.Builder(this)
                .addItem(new PowerMenuItem("Settings", false))
                .addItem(new PowerMenuItem("Travel", false))
                .addItem(new PowerMenuItem("Logout", false))
                .setAnimation(MenuAnimation.SHOWUP_TOP_LEFT) // Animation start point (TOP | LEFT)
                .setMenuRadius(0f)
                .setMenuShadow(0f)
                .setTextColor(Color.BLACK)
                .setSelectedTextColor(Color.WHITE)
                .setMenuColor(Color.WHITE)
                .setSelectedMenuColor(Color.BLACK)
                .setOnMenuItemClickListener(new OnMenuItemClickListener<PowerMenuItem>() {
                    @Override
                    public void onItemClick(int position, PowerMenuItem item) {
                        Toast.makeText(getBaseContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
                    }
                })
                .build();

        mMenuButton = (Button)findViewById(R.id.floating_menu_context);
        mMenuButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                powerMenu.showAsDropDown(view);
            }
        });

I get the following error :

Error:(339, 26) error: cannot access LifecycleObserver class file for android.arch.lifecycle.LifecycleObserver not found

any help ?
thanks !

Release File

Hi.
I can't sync gradle by adding implementation "com.github.skydoves:powermenu:2.0.5".
I searched a lot, but i wasn't successful.

Would you please place ZIP or AAR file of your library in releases?
Thanks in advance.

Prevent dismiss when touching background

Please complete the following information:

  • Library Version: 2.1.2

Describe the Bug:

I don't know if it is a bug but I tried to prevent menu from dismissing when touching background using .setsetOnBackgroundClickListener when certain condition is false:

.setOnBackgroundClickListener(v -> {
    if (condition) {
        customPowerMenu .dismiss();
    }
})

but menu is dismissing and only background stays in place.

I also wanted to try with .setTouchInterceptor(onTouchListener) but apparently this method doesn't exist.

Maybe I'm doing something wrong.

Could not find cardview-1.0.0.jar

This is compilation error when i try building project.

Could not find cardview-1.0.0.jar (androidx.cardview:cardview:1.0.0).
Searched in the following locations:
    https://dl.google.com/dl/android/maven2/androidx/cardview/cardview/1.0.0/cardview-1.0.0.jar

Crash application when dark mode

  • Library Version [v2.1.7]
  • Affected Device(s) [Samsung Galaxy s8 with Android 9.0 DarkTheme]

Description Bug:

Everything works in light UI mode (Theme.MaterialComponents.DayNight.NoActionBar.Bridge)
But when i try to open menu in Dark UI mode application is crashed

my code ->

val menu = createPowerMenu(requireContext()) {
            addItem(PowerMenuItem(getString(R.string.paid_driver_for_km), R.drawable.ic_delivery))
            addItem(PowerMenuItem(getString(R.string.paid_for_enter), R.drawable.ic_gate_black))
            addItem(PowerMenuItem(getString(R.string.paid_for_fuel), R.drawable.ic_fuel))
            addItem(PowerMenuItem(getString(R.string.paid_for_help), R.drawable.ic_person_black_24dp))
            addItem(PowerMenuItem(getString(R.string.paid_for_overload), R.drawable.ic_blur_circular_black_24dp))
            setLifecycleOwner(viewLifecycleOwner)
            setAnimation(MenuAnimation.SHOW_UP_CENTER)
            setMenuRadius(10F)
            setAutoDismiss(true)
            setWidth(1000)
            setTextSize(16)
            setTextColorResource(R.color.text_color_daynight)
            setMenuColorResource(R.color.cardview_daynight_background)
            setBackgroundColorResource(R.color.cardview_daynight_background)

            setOnMenuItemClickListener { position, item ->
                when (item.title) {
                    getString(R.string.paid_driver_for_km) -> end_day_fin_paid_forwarder_for_km?.visibility = View.VISIBLE
                    getString(R.string.paid_for_enter) -> end_day_fin_paid_for_enter?.visibility = View.VISIBLE
                    getString(R.string.paid_for_fuel) -> end_day_fin_paid_fuel?.visibility = View.VISIBLE
                    getString(R.string.paid_for_help) -> end_day_fin_paid_for_help?.visibility = View.VISIBLE
                    getString(R.string.paid_for_overload) -> end_day_fin_paid_for_overload?.visibility = View.VISIBLE
                }
            }
        }
        if (end_day_fin_add_outgo != null)
            menu.showAsDropDown(end_day_fin_add_outgo)

In Crashlytics error ->

Fatal Exception: android.content.res.Resources$NotFoundException
Resource ID #0x7f0800ab

com.skydoves.powermenu.MenuListAdapter.getView (MenuListAdapter.java:103)

in Logcat ->

android.content.res.Resources$NotFoundException: Resource ID #0x7f0800ab
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:228)
        at android.content.res.Resources.getValue(Resources.java:1346)
        at androidx.appcompat.widget.ResourceManagerInternal.createDrawableIfNeeded(ResourceManagerInternal.java:176)
        at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:141)
        at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:132)
        at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
        at androidx.appcompat.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:90)
        at androidx.appcompat.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:98)
        at com.skydoves.powermenu.MenuListAdapter.getView(MenuListAdapter.java:86)
        at android.widget.AbsListView.obtainView(AbsListView.java:3219)
        at android.widget.ListView.measureHeightOfChildren(ListView.java:1451)
        at android.widget.ListView.onMeasure(ListView.java:1358)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7139)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at androidx.cardview.widget.CardView.onMeasure(CardView.java:260)
        at com.google.android.material.card.MaterialCardView.onMeasure(MaterialCardView.java:160)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7139)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7139)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7139)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3301)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2028)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2330)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1888)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8511)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
        at android.view.Choreographer.doCallbacks(Choreographer.java:761)
        at android.view.Choreographer.doFrame(Choreographer.java:696)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7050)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

I tried to use without and with background colors. An error still exists

Menu above anchor

Hello
Great library
I am just wondering if there is a way that I can display the menu Above anchor as opposed to always being below .

Thank you

show tooltip above menu

Hello, do you know if there is an easy way to show a tooltip arrow below the anchor and above the power menu?

Why is xoffset invalid

powerMenu.showAsDropDown(view,-(view.getWidth() / 2), -(view.getHeight() / 2));
Why is xoffset invalid?

CustomPowerMenu setOnMenuItemClickListener not working

Below is the code i implemented.
private OnMenuItemClickListener onMenuItemClickListener = new OnMenuItemClickListener() {
@OverRide
public void onItemClick(int position, SwitcherItem item) {
Toast.makeText(getBaseContext(), item.getName(), Toast.LENGTH_SHORT).show();
mSwitcherMenu.dismiss();
}
};

mSwitcherMenu = new CustomPowerMenu.Builder<>(this, new PatientSwitcherAdapter())
.addItem(new SwitcherItem("", "John Appleseed"))
.addItem(new SwitcherItem("", "Evil Monster"))
.addItem(new SwitcherItem("", "New Patient"))
.addItem(new SwitcherItem("", "AAA EEE"))
.setOnMenuItemClickListener(onMenuItemClickListener)
.setFooterView(R.layout.cell_signout)
.setWidth(dm.widthPixels * 2 / 3)
.setBackgroundAlpha(0.2f)
.setAnimation(MenuAnimation.SHOWUP_TOP_LEFT)
.setMenuRadius(10f)
.setMenuShadow(10f)
.build();

But onItemClick is not calling. I appreciate your any help!

Complete list items are not visible.

Please complete the following information:

  • Library Version = 2.1.9
  • Affected Device(s) = All

Describe the Bug:

I have a list of 61 items, but menu is showing only 26 items.

Expected Behavior:

menu should show all items in the list.

Background issue in full-screen mode

Please complete the following information:

  • Library Version: 2.0.5

Describe the Bug:

When app is in a full-screen mode (no navigation bar and status bar is shown), background scrim of PowerMenu is not shown in full screen, but stops vertically at the point where bottom Android navigation bar would start normally, leaving bottom part of a screen without PowerMenu background

Expected Behavior:

Background should be drawn in full-screen

Issue with setFocusable(true)

Hi, Thanks for the library.
The problem is that the setFocusable(true) method only works when setShowBackground is set to true.
if it is set to false , the other views responds to clicks. I just want to remove the background shadow and popUp to get clicked when it is shown and not other views.

Here is my code:

powerMenu = new PowerMenu.Builder(context)
.addItemList(powerMenuItems)
.setShowBackground(false)
.setLifecycleOwner(((MainActivity)context))
.setTextColor(Color.WHITE)
.setMenuColor(context.getResources().getColor(R.color.main_color))
.setSelectedTextColor(Color.WHITE)
.setSelectedMenuColor(context.getResources().getColor(R.color.colorPrimary))
.setOnMenuItemClickListener(menuItemClickListener)
.setFocusable(true)
.build();

Cannot customize font style

Hello developer, can you give a guide on how to customize the font style? My app requires the default Android Roboto fonts. Thank you.

WRAP_CONTENT support?

CustomPowerMenu.Builder<>(context, new CustomDialogMenuAdapter())
.setHeaderView(R.layout.layout_custom_dialog_header)
.setFooterView(R.layout.layout_custom_dialog_footer)
.addItem(
new NameCardMenuItem(
context.getResources().getDrawable(R.drawable.face3),
"Sophie",
context.getString(R.string.board3)))
.setLifecycleOwner(lifecycleOwner)
.setAnimation(MenuAnimation.SHOW_UP_CENTER)
.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT)
.setShowBackground(false)
.setBackgroundColor(Color.TRANSPARENT)
.setMenuRadius(10f)
.setMenuShadow(10f)
.build();

How to set width to WRAP_CONTENT?

Menu Padding & Icon Size

Hi, thanks for this awesome library!
However, I got some question regarding to this library.

Can I know how to add padding on the menu?

CustomPowerMenu Width not set Proper

Hi @skydoves

i am using CustomPowerMenu and custom view not set Properally. Here is my code..

navOptionMenu = new CustomPowerMenu.Builder(activity, new AdapterPowerMenu(powerMenuItems)).addItemList(powerMenuItems) .setAnimation(MenuAnimation.SHOWUP_TOP_LEFT) .setMenuRadius(10f) .setMenuShadow(10f) .setWidth(550) .setOnMenuItemClickListener(onIconMenuItemClickListener).build(); navOptionMenu.showAtCenter(actionView);

and my Lister is Like..

private OnMenuItemClickListener<PowerMenuModel> onIconMenuItemClickListener = new OnMenuItemClickListener<PowerMenuModel>() { @Override public void onItemClick(int position, PowerMenuModel item) { mainMenuCommandHandler.handleMenuRequest(position); navOptionMenu.dismiss(); } };

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.