Search in sources :

Example 1 with Actions

use of com.codename1.rad.ui.Actions in project CodeRAD by shannah.

the class NodeUtilFunctions method buildActionsBar.

static void buildActionsBar(Node node, Container target, Entity entity, Actions right, Actions left, Actions overflow, Actions middle) {
    Container actionsBar = new Container(new BorderLayout());
    Container actionsBarRight = new Container(new BorderLayout());
    if (middle != null && middle.size() > 0) {
        GridLayout layout = new GridLayout(middle.size());
        Container cnt = new Container(layout);
        middle.addToContainer(cnt, entity);
        actionsBar.add(BorderLayout.CENTER, cnt);
    }
    if (left != null) {
        Container cnt = new Container(BoxLayout.x());
        for (ActionNode action : left) {
            cnt.add(action.getViewFactory().createActionView(entity, action));
        }
        if (actionsBar.getComponentCount() > 0) {
            actionsBar.add(BorderLayout.WEST, cnt);
        } else {
            actionsBar.add(BorderLayout.CENTER, cnt);
        }
    }
    if (right != null) {
        Container cnt = new Container(BoxLayout.x());
        $(cnt).setAlignment(RIGHT);
        for (ActionNode action : right) {
            // System.out.println("right node "+action);
            cnt.add(action.getViewFactory().createActionView(entity, action));
        }
        // System.out.println("Adding to right "+cnt);
        actionsBarRight.add(BorderLayout.CENTER, cnt);
    }
    if (overflow != null && !overflow.isEmpty()) {
        PopupMenu popup = new PopupMenu();
        for (ActionNode action : overflow) {
            Property.Label label = action.getLabel();
            String labelStr = label != null ? label.getValue() : "";
            Command cmd = new Command(labelStr) {

                @Override
                public void actionPerformed(ActionEvent evt) {
                    action.fireEvent(entity, target);
                }
            };
            if (action.getImageIcon() != null) {
                cmd.setIcon(action.getImageIcon().getValue());
            } else if (action.getMaterialIcon() != null) {
                cmd.setMaterialIcon(action.getMaterialIcon().getValue());
            }
            popup.addCommand(cmd);
        }
        actionsBarRight.add(BorderLayout.EAST, new Button(popup.getCommand()));
    }
    if (actionsBarRight.getComponentCount() > 0) {
        actionsBar.add(BorderLayout.EAST, actionsBarRight);
    }
    if (actionsBar.getComponentCount() > 0) {
        target.add(actionsBar);
    }
}
Also used : Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) Command(com.codename1.ui.Command) Button(com.codename1.ui.Button) ActionEvent(com.codename1.ui.events.ActionEvent) ActionNode(com.codename1.rad.nodes.ActionNode) Property(com.codename1.rad.models.Property) PopupMenu(ca.weblite.shared.components.PopupMenu)

Example 2 with Actions

use of com.codename1.rad.ui.Actions in project CodeRAD by shannah.

the class ProfileAvatarsTitleComponent method createAvatar.

/**
 * Creates individual avatar component.
 * @param row
 * @return
 */
private ProfileAvatarView createAvatar(Entity row) {
    // We will intercept the individual avatar actions by inserting our own actions here.
    // We will then handle the clicks and long presses ourselves, because
    // we may need to expand the list of avatars and allow the user to
    // choose an avatar from the list.
    ViewNode childNode = new ViewNode(UI.actions(ProfileAvatarView.PROFILE_AVATAR_CLICKED, interceptAvatarClicked), UI.actions(ProfileAvatarView.PROFILE_AVATAR_LONG_PRESS, interceptAvatarLongPress));
    childNode.setParent(getViewNode());
    ProfileAvatarView v = new ProfileAvatarView(row, childNode, avatarSizeMM);
    return v;
}
Also used : ViewNode(com.codename1.rad.nodes.ViewNode)

Example 3 with Actions

use of com.codename1.rad.ui.Actions in project CodeRAD by shannah.

the class Buttons method rebuild.

private void rebuild() {
    built = true;
    requiresRefresh = false;
    removeAll();
    this.actionCategory = actionCategory;
    Actions actions = getViewNode().getInheritedActions(this.actionCategory);
    Actions overflowActions = null;
    actions = actions.proxy(getViewNode());
    if (limit >= 0 && actions.size() >= limit) {
        // Note: >= because need to fit overflow button under limit
        overflowActions = new Actions();
        Actions tempActions = new Actions();
        int len = actions.size();
        int index = -1;
        UIID uiid = null;
        for (ActionNode action : actions) {
            index++;
            if (index < limit - (overflowMenuStyle == OverflowMenuStyle.None ? 0 : 1)) {
                tempActions.add(action);
            } else {
                overflowActions.add(action);
            }
            if (uiid == null) {
                uiid = action.getUIID();
            }
        }
        actions = tempActions;
        if (overflowActions.size() > 0) {
            ActionNode overflowAction = overflowButtonAction.icon(FontImage.MATERIAL_MORE_HORIZ).build();
            // Try to match the UIID of the other actions
            if (uiid != null) {
                overflowAction.setAttributes(uiid);
            }
            overflowAction.setParent(getViewNode());
            final Actions fOverflowActions = overflowActions;
            overflowActions.copyAttributesIfNotExists(overflowActionTemplate.build());
            overflowAction.addActionListener(e -> {
                e.consume();
                showOverflowMenu(fOverflowActions);
            });
            if (overflowMenuStyle != OverflowMenuStyle.None) {
                actions.add(overflowAction);
            }
        }
    }
    actions.copyAttributesIfNotExists(actionTemplate.build());
    actions.addToContainer(this, getEntity(), buttonWrapper);
    revalidateWithAnimationSafety();
}
Also used : Actions(com.codename1.rad.ui.Actions) UIID(com.codename1.rad.attributes.UIID) ActionNode(com.codename1.rad.nodes.ActionNode)

Example 4 with Actions

use of com.codename1.rad.ui.Actions in project CodeRAD by shannah.

the class Controller method addActions.

/**
 * Adds a set of actions to this controller, registered to a given category.
 * @param category The category to register the actions under.
 * @param actions The actions to register.
 * @see #extendAction(ActionNode.Category, SuccessCallback) To extend an existing action
 * from a parent controller, and register the extended action on this controller.
 * @since 2.0
 */
public void addActions(ActionNode.Category category, ActionNode... actions) {
    if (actionMap == null) {
        actionMap = new HashMap();
    }
    Actions acts = null;
    if (!actionMap.containsKey(category)) {
        acts = new Actions();
        actionMap.put(category, acts);
    } else {
        acts = actionMap.get(category);
    }
    acts.add(actions);
}
Also used : Actions(com.codename1.rad.ui.Actions)

Example 5 with Actions

use of com.codename1.rad.ui.Actions in project CodeRAD by shannah.

the class ActionsNode method setAttributes.

@Override
public void setAttributes(Attribute... atts) {
    // super.setAttributes(atts);
    for (Attribute att : atts) {
        if (att == null)
            continue;
        if (att.getClass() == ActionNode.class) {
            ActionNode n = (ActionNode) att;
            if (actions == null) {
                actions = new ArrayList<ActionNode>();
            }
            n = (ActionNode) n.createProxy(this);
            actions.add(n);
        } else {
            super.setAttributes(att);
        }
    }
}
Also used : Attribute(com.codename1.rad.models.Attribute)

Aggregations

ActionNode (com.codename1.rad.nodes.ActionNode)6 IOException (java.io.IOException)5 PushAction (com.codename1.push.PushAction)4 PushActionCategory (com.codename1.push.PushActionCategory)4 ViewNode (com.codename1.rad.nodes.ViewNode)4 Container (com.codename1.ui.Container)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 GridLayout (com.codename1.ui.layouts.GridLayout)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ParseException (java.text.ParseException)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)2 Paint (android.graphics.Paint)2 RemoteException (android.os.RemoteException)2 Element (android.renderscript.Element)2 Log (com.codename1.io.Log)2 NetworkEvent (com.codename1.io.NetworkEvent)2 MediaException (com.codename1.media.AsyncMedia.MediaException)2 ViewController (com.codename1.rad.controllers.ViewController)2 Entity (com.codename1.rad.models.Entity)2 EntityList (com.codename1.rad.models.EntityList)2