Search in sources :

Example 1 with ActionItem

use of org.adw.launcher2.quickactionbar.ActionItem in project ADWLauncher2 by boombuler.

the class Launcher method showActions.

public void showActions(ItemInfo info, View view, PopupWindow.OnDismissListener onDismissListener) {
    if (info == null || view == null)
        return;
    List<EditAction> actions = info.getAvailableActions(view, this);
    if (actions.size() <= 0)
        return;
    final View finalview = view;
    final ItemInfo finalInfo = info;
    int[] xy = new int[2];
    //fills the array with the computed coordinates
    view.getLocationInWindow(xy);
    new Rect(xy[0], xy[1], xy[0] + view.getWidth(), xy[1] + view.getHeight());
    //a new QuickActionWindow object
    final QuickAction qa = new QuickAction(view);
    view.setTag(org.adw.launcher2.R.id.TAG_PREVIEW, qa);
    if (onDismissListener != null) {
        qa.setOnDismissListener(onDismissListener);
    }
    //when the item is clicked on
    for (EditAction action : actions) {
        final EditAction finalaction = action;
        Drawable icon;
        CharSequence title;
        if (action.getIconResourceId() == 0) {
            icon = action.getIconDrawable();
        } else {
            icon = getResources().getDrawable(action.getIconResourceId());
        }
        if (action.getTitleResourceId() == 0) {
            title = action.getTitleString();
        } else {
            title = getResources().getString(action.getTitleResourceId());
        }
        ActionItem ai = new ActionItem(icon);
        if (title != null)
            ai.setTitle(title.toString());
        ai.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                qa.dismiss();
                finalInfo.executeAction(finalaction, finalview, Launcher.this);
            }
        });
        qa.addActionItem(ai);
    }
    //shows the quick action window on the screen
    qa.show();
}
Also used : QuickAction(org.adw.launcher2.quickactionbar.QuickAction) Rect(android.graphics.Rect) ActionItem(org.adw.launcher2.quickactionbar.ActionItem) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) EditAction(org.adw.launcher2.ItemInfo.EditAction) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView)

Aggregations

AppWidgetHostView (android.appwidget.AppWidgetHostView)1 Rect (android.graphics.Rect)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 EditAction (org.adw.launcher2.ItemInfo.EditAction)1 ActionItem (org.adw.launcher2.quickactionbar.ActionItem)1 QuickAction (org.adw.launcher2.quickactionbar.QuickAction)1