Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LongClick extension #57

Open
andrewsleeman24 opened this issue Jan 29, 2012 · 0 comments
Open

LongClick extension #57

andrewsleeman24 opened this issue Jan 29, 2012 · 0 comments

Comments

@andrewsleeman24
Copy link

I found the ActionBar project yesterday and have found it to be wonderful.

One of the problems I have will Android application is that the purpose of icon buttons is not always clean (eg. some of the Gmail icons).

For this reason I needed adapted ActionBar of the user can use a LongClick to get a textual description of the Action's purposes.

I am not Git skilled and my Eclipse has completely reformatted the source code so I cannot easily generated a short list of differences.

If you are interested in the feature then the to ActionBar.java are quite trivial and outlined below.

  1. There is an extended ActionBar.Action interface called "ActionBar.ActionPlus".
    public interface ActionPlus extends Action {
    public void performLongClickAction(View pView);
    }

  2. the class now implements "android.view.View.OnLongClickListener" and the supporting code is
    @OverRide
    public boolean onLongClick(View view) {
    final Object tag = view.getTag();
    if (tag instanceof ActionPlus) {
    final ActionPlus action = (ActionPlus) tag;
    action.performLongClickAction(view);
    return true;
    }
    return false;
    }

  3. Last peice of the ActionBar code change is addition of the following 4 lines in the inflateAction() method.

    labelView.setImageResource(action.getDrawable());
  •    if (action instanceof ActionPlus) {
    
  •        labelView.setLongClickable(true);
    
  •        labelView.setOnLongClickListener(this);
    
  •    }
    

A example to how I have used this is my application is :

        actionBar.addAction(new ActionBar.ActionPlus() {
            public void performAction(View view) {
                doOpenDrawer();
            }

            public int getDrawable() {
                return R.drawable.drawer_open;
            }

            public void performLongClickAction(View view) {
                UtilsNotify.show(MainMenu.this, R.string.action_open_drawer_description);
            }
        });

I'm not sure if this is a Best Practice implementation of how to extended the ActionBar functionality.

  1. A better solution may have been to use a function "public int getStringId();" instead of the long "performLongClickAction()" and then use "Toast" directly to display the text message.

  2. Also if it was a private library module (where I did not care about backward compatibility), I would have just extended the definition of the "Action"/"ActionAbstract" implementations to handle the mStringId member (as is currently done for the mDrawable member.

NB. for my own local copy I have now implement both the above suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant