0

I am creating an actionbar with greendroid. I managed to create the actionbar and then put a quick action. My problem is just about the quickaction because I do not know how to insert actions for each of the buttons quick action. Could anyone help me? This picture explains better what I do:

http://s7.postimage.org/iavbl44mj/greendroid09.png

And this my code of quickActionBar

private void initQuickActionBar() {
        quickActions = new QuickActionBar(this);

        quickActions.addQuickAction(new QuickAction(this, R.drawable.buscar, "Buscar"));
        quickActions.addQuickAction(new QuickAction(this, R.drawable.tags, "Tags"));
        quickActions.addQuickAction(new QuickAction(this, R.drawable.mail, "Email"));

        quickActions.setOnQuickActionClickListener(new OnQuickActionClickListener() {

            @Override
            public void onQuickActionClicked(QuickActionWidget widget, int position) {



            }
        });

Thks!

DROIDzilla
  • 23
  • 3
  • you need to add quickaction when you click on action bar buttons or what? – K_Anas Jun 02 '12 at 15:29
  • Friend, I need to insert an action button to quickActionBar. As explained in the picture, when I click the "Share" (which is in actionbar) quickActionBar will open with three options (Buscar, Tags, and Email). What I want is to put an action on the BUSCAR button. you get the idea? – DROIDzilla Jun 02 '12 at 15:53
  • hi did u succed on creating action bar use green droid? is so tell me that's so simple i have tutorial for you but written in french language did u understand french? – K_Anas Jun 02 '12 at 16:10
  • ys sir. pass me the link pls! but friend ... I want to know is very simple. I wonder how I, eg, call the login function on facebook when the User clicks a button on my quickAction. you know answer me? – DROIDzilla Jun 02 '12 at 20:37

1 Answers1

1

You have to use the method onHandleActionBarItemClick

@Override
    public boolean onHandleActionBarItemClick(ActionBarItem item, int position) {
    switch (item.getItemId()) {
    case LOCATE:
          //show toast
        Toast.makeText(getApplicationContext(),
            "Vous avez cliquez sur le bouton LOCATE",
            Toast.LENGTH_SHORT).show();
        break;

    case REFRESH:
          //show toast
        Toast.makeText(getApplicationContext(),
            "Vous avez cliquez sur le bouton REFRESH",
            Toast.LENGTH_SHORT).show();
        break;

    case SHARE:
         // show quicAction and then a toas
         quickActions.show(item.getItemView());
        Toast.makeText(getApplicationContext(),
            "Vous avez cliquez sur le bouton SHARE",
            Toast.LENGTH_SHORT).show();
        break;
    default:
        return super.onHandleActionBarItemClick(item, position);
    }

    return true;
    }

in your activity you should have something simular to this

import greendroid.app.GDActivity;
import android.os.Bundle;

public class GDIntroActivity extends GDActivity {

   private QuickActionWidget quickActions;

    /** Called when the activity is first created. */
@Override
   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);

   setActionBarContentView(R.layout.main);
   initActionBar();
   initQuickActionBar();
   }

private void initQuickActionBar() {
    quickActions = new QuickActionBar(this);
    quickActions.addQuickAction(new QuickAction(this, R.drawable.facebook,
        "Facebook"));
    quickActions.addQuickAction(new QuickAction(this, R.drawable.twitter, "Twitter"));
    quickActions.addQuickAction(new QuickAction(this, R.drawable.mail, "Email"));
    quickActions.setOnQuickActionClickListener(new OnQuickActionClickListener() {
        public void onQuickActionClicked(QuickActionWidget widget,
            int position) {
         Toast.makeText(GDIntroActivity.this,
         "Item " + position + " clicked", Toast.LENGTH_SHORT)
         .show();
        }
    });
    }
}

Check this link if you want to lunch facebook login you can use this

Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);

But the facebook app must be installed on your device or your emulator to trigger it

you can use it in your QuickAction Like this

private void initQuickActionBar() {
        quickActions = new QuickActionBar(this);
        quickActions.addQuickAction(new QuickAction(this, R.drawable.facebook,
            "Facebook"));
        quickActions.addQuickAction(new QuickAction(this, R.drawable.twitter, "Twitter"));
        quickActions.addQuickAction(new QuickAction(this, R.drawable.mail, "Email"));
        quickActions.setOnQuickActionClickListener(new OnQuickActionClickListener() {
            public void onQuickActionClicked(QuickActionWidget widget,
                int position) {
             switch(position){
              case facebook_position:
                   Intent intent = new Intent("android.intent.category.LAUNCHER");
                   intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
                   startActivity(intent);
                   break;
              case twitter_position:
                //do stuff

             }
            }
    });
    }
K_Anas
  • 31,226
  • 9
  • 68
  • 81
  • Ok but that does not answer my question. I want to know, e.g., inside the method "initQuickAction," how do I click on the facebook he calls the login method facebook. you know how to do it? – DROIDzilla Jun 02 '12 at 20:34
  • you want when user cliks on item of QuicAction do some stuff? – K_Anas Jun 02 '12 at 20:37
  • if he clicks on facebbok icon you lunch facebook app for exemple? – K_Anas Jun 02 '12 at 20:39
  • ys. I want that when clicked, opens the facebook login. I already have the method for this. I just need to know how to invoke it within the quickAction. – DROIDzilla Jun 02 '12 at 20:59
  • use a switch inside the ononQuickActionClicked of your initQuickActionBar() switch(clicked-position){ case 1: //do something case 2: //do something else – K_Anas Jun 02 '12 at 21:02
  • but I have to call an intent? Because I have a method called (init) that he used to log into facebook. I just want to grab this button, put it inside the quickAction and set his action when clicked, or when they click the button "Login" he must call the "init". – DROIDzilla Jun 03 '12 at 03:00
  • bro, my biggest problem is because he rides a quickActionBar you through a drawable. Only the button I want to put in quickAction is a login button that has a dual behavior. (If you are not logged in facebook button appears "Login" if you're logged in it says "Logout." For that I use "R. id.login." As I call it within the quickaction? – DROIDzilla Jun 03 '12 at 03:34