use of com.codename1.rad.ui.Actions in project CodenameOne by codenameone.
the class RADEntityListAddRemoveInvalidateSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
// An entity for the rows our our list view.
class Person extends Entity {
}
entityTypeBuilder(Person.class).string(Thing.name).factory(cls -> {
return new Person();
}).build();
// A remove row action that will be added to each row
ActionNode removeRow = UI.action(UI.icon(FontImage.MATERIAL_DELETE));
// An internal list we will use to store the rows of the entitylist
ArrayList internalList = new ArrayList();
EntityList profileList = new EntityList() {
/**
* Override createInternalList() so that we can use our own data structure
* for storing this list. This is contrived to allow us to test the
* invalidate() method.
*/
@Override
protected List createInternalList() {
return internalList;
}
};
// A list node to wrap our action and pass it to our view
ListNode node = new ListNode(// of the list.
UI.actions(ProfileListView.ACCOUNT_LIST_ROW_ACTIONS, removeRow));
// A ProfileListView to render the list.
// See https://shannah.github.io/CodeRAD/javadoc/com/codename1/rad/ui/entityviews/ProfileListView.html
ProfileListView listView = new ProfileListView(profileList, node, 10);
listView.setScrollableY(true);
// Create a controller for the ProfileListView so that we can handle actions fired by the view.
// Normally we'd do this in the FormController but since this sample doesn't have one
// we create a ViewController for the ProfileListView directly.
ViewController controller = new ViewController(null);
controller.setView(listView);
// Button to add rows to the list
Button addRow = new Button(FontImage.MATERIAL_ADD);
// Button to clear the list
Button clear = new Button("Clear");
addRow.addActionListener(evt -> {
// "Add" button clicked.
// Create new person and add to the list
Person p = new Person();
p.set(Thing.name, "Row " + profileList.size());
profileList.add(p);
// This will trigger an EntityAddedEvent which will allow
// the ProfileListView to synchronize
});
clear.addActionListener(evt -> {
// "Clear" button clicked
// We could have called profileList.clear()
// but this would send EntityRemoved events for each row removed
// which is inefficient. Instead we'll clear the elements in
// the internal list directly, and then call invalidate()
// so that the ProfileListView knows to resynchronize its state.
internalList.clear();
profileList.invalidate();
});
controller.addActionListener(removeRow, evt -> {
// The "Remove" button was clicked on a row.
profileList.remove(evt.getEntity());
});
Form hi = new Form("Hi World", new BorderLayout());
hi.add(NORTH, GridLayout.encloseIn(2, clear, addRow));
hi.add(CENTER, listView);
hi.show();
}
use of com.codename1.rad.ui.Actions in project CodenameOne by codenameone.
the class AndroidImplementation method getInstalledPushActionCategories.
/**
* Retrieves the app's available push action categories from the XML file in which they
* should have been installed on the first load.
* @param context
* @return
* @throws IOException
*/
private static PushActionCategory[] getInstalledPushActionCategories(Context context) throws IOException {
// NOTE: This method may be called from the PushReceiver when the app isn't running so we can't access
// the main activity context, display properties, or any CN1 stuff. Just native android
File categoriesFile = new File(context.getFilesDir().getAbsolutePath() + "/" + FILE_NAME_NOTIFICATION_CATEGORIES);
if (!categoriesFile.exists()) {
return new PushActionCategory[0];
}
javax.xml.parsers.DocumentBuilderFactory docFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder docBuilder;
try {
docBuilder = docFactory.newDocumentBuilder();
} catch (ParserConfigurationException ex) {
Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
throw new IOException("Faield to create document builder for creating notification categories XML document", ex);
}
org.w3c.dom.Document doc;
try {
doc = docBuilder.parse(context.openFileInput(FILE_NAME_NOTIFICATION_CATEGORIES));
} catch (SAXException ex) {
Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
throw new IOException("Failed to parse instaled push action categories", ex);
}
org.w3c.dom.Element root = doc.getDocumentElement();
java.util.List<PushActionCategory> out = new ArrayList<PushActionCategory>();
org.w3c.dom.NodeList l = root.getElementsByTagName("category");
int len = l.getLength();
for (int i = 0; i < len; i++) {
org.w3c.dom.Element el = (org.w3c.dom.Element) l.item(i);
java.util.List<PushAction> actions = new ArrayList<PushAction>();
org.w3c.dom.NodeList al = el.getElementsByTagName("action");
int alen = al.getLength();
for (int j = 0; j < alen; j++) {
org.w3c.dom.Element actionEl = (org.w3c.dom.Element) al.item(j);
String textInputPlaceholder = actionEl.hasAttribute("textInputPlaceholder") ? actionEl.getAttribute("textInputPlaceholder") : null;
String textInputButtonText = actionEl.hasAttribute("textInputButtonText") ? actionEl.getAttribute("textInputButtonText") : null;
PushAction action = new PushAction(actionEl.getAttribute("id"), actionEl.getAttribute("title"), actionEl.getAttribute("icon"), textInputPlaceholder, textInputButtonText);
actions.add(action);
}
PushActionCategory cat = new PushActionCategory((String) el.getAttribute("id"), actions.toArray(new PushAction[actions.size()]));
out.add(cat);
}
return out.toArray(new PushActionCategory[out.size()]);
}
use of com.codename1.rad.ui.Actions in project CodeRAD by shannah.
the class Controller method extendAction.
/**
* Extends an existing action from one of the parent controllers, and registers it as an action
* on this controller.
* @param category The category to register the action to.
* @param overwriteAttributes Whether to overwrite existing attributes of the action. If false, attributes
* provided will be ignored when extending actions that already have those attributes
* defined.
* @param attributes Attributes to add to the action.
* @return The action that was added.
* @since 2.0
*/
public ActionNode extendAction(ActionNode.Category category, boolean overwriteAttributes, Attribute... attributes) {
ActionNode action = getInheritedAction(category);
if (action == null) {
action = UI.action(attributes);
} else {
action = (ActionNode) action.createProxy(action.getParent());
action.setAttributes(overwriteAttributes, attributes);
}
addActions(category, action);
return action;
}
use of com.codename1.rad.ui.Actions in project CodeRAD by shannah.
the class DefaultEntityListCellRenderer method makeSwipeable.
private EntityView makeSwipeable(Entity entity, ViewNode node, Component view) {
// Check for swipeable container
SwipeContainer swipe = (SwipeContainer) node.findAttribute(SwipeContainer.class);
if (swipe != null) {
EntityView leftCnt = null;
EntityView rightCnt = null;
ViewNode leftNode = swipe.getLeft();
if (leftNode != null) {
leftCnt = leftNode.createView(entity);
}
ViewNode rightNode = swipe.getRight();
if (rightNode != null) {
rightCnt = rightNode.createView(entity);
}
SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
return new WrapperEntityView(swipeWrapper, entity, node);
}
ActionNode deleteAction = node.getInheritedAction(ActionCategories.LIST_REMOVE_ACTION);
Actions leftSwipeActions = node.getActions(ActionCategories.LEFT_SWIPE_MENU);
if (deleteAction != null) {
leftSwipeActions.add(deleteAction);
}
Actions rightSwipeActions = node.getActions(ActionCategories.RIGHT_SWIPE_MENU);
if (!leftSwipeActions.isEmpty() || !rightSwipeActions.isEmpty()) {
Container leftCnt = null;
Container rightCnt = null;
if (!leftSwipeActions.isEmpty()) {
leftCnt = new Container(new GridLayout(leftSwipeActions.size()));
for (ActionNode action : leftSwipeActions) {
leftCnt.add(action.getViewFactory().createActionView(entity, action));
}
}
if (!rightSwipeActions.isEmpty()) {
rightCnt = new Container(new GridLayout(rightSwipeActions.size()));
for (ActionNode action : rightSwipeActions) {
rightCnt.add(action.getViewFactory().createActionView(entity, action));
}
}
SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
return new WrapperEntityView(swipeWrapper, entity, node);
} else {
// System.out.println("Swipe actions not present");
}
return (EntityView) view;
}
use of com.codename1.rad.ui.Actions in project CodeRAD by shannah.
the class DefaultEntityViewFactory method makeSwipeable.
private EntityView makeSwipeable(Entity entity, ViewNode node, Component view) {
// Check for swipeable container
SwipeContainer swipe = (SwipeContainer) node.findAttribute(SwipeContainer.class);
if (swipe != null) {
EntityView leftCnt = null;
EntityView rightCnt = null;
ViewNode leftNode = swipe.getLeft();
if (leftNode != null) {
leftCnt = leftNode.createView(entity, this);
}
ViewNode rightNode = swipe.getRight();
if (rightNode != null) {
rightCnt = rightNode.createView(entity, this);
}
SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
return new WrapperEntityView(swipeWrapper, entity, node);
}
Actions leftSwipeActions = node.getActions(ActionCategories.LEFT_SWIPE_MENU);
Actions rightSwipeActions = node.getActions(ActionCategories.RIGHT_SWIPE_MENU);
if (!leftSwipeActions.isEmpty() || !rightSwipeActions.isEmpty()) {
Container leftCnt = null;
Container rightCnt = null;
if (!leftSwipeActions.isEmpty()) {
leftCnt = new Container(BoxLayout.y());
NodeUtilFunctions.buildActionsBar(node, leftCnt, entity, null, leftSwipeActions, null);
}
if (!rightSwipeActions.isEmpty()) {
rightCnt = new Container(BoxLayout.y());
NodeUtilFunctions.buildActionsBar(node, leftCnt, entity, rightSwipeActions, null, null);
}
SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
return new WrapperEntityView(swipeWrapper, entity, node);
}
return (EntityView) view;
}
Aggregations