use of com.codename1.rad.models.Tag in project CodenameOne by codenameone.
the class Security method verify.
/**
* Verifies that the signature from the server matches the computed
* signature on the data. Returns true if the data is correctly signed.
*
* @param publicKey public key associated with the developer account
* @param signedData signed data from server
* @param signature server signature
* @return true if the data and signature match
*/
public static boolean verify(PublicKey publicKey, String signedData, String signature) {
Signature sig;
try {
sig = Signature.getInstance(SIGNATURE_ALGORITHM);
sig.initVerify(publicKey);
sig.update(signedData.getBytes());
if (!sig.verify(Base64.decode(signature))) {
Log.e(TAG, "Signature verification failed.");
return false;
}
return true;
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "NoSuchAlgorithmException.");
} catch (InvalidKeyException e) {
Log.e(TAG, "Invalid key specification.");
} catch (SignatureException e) {
Log.e(TAG, "Signature exception.");
} catch (Base64DecoderException e) {
Log.e(TAG, "Base64 decoding failed.");
}
return false;
}
use of com.codename1.rad.models.Tag in project CodenameOne by codenameone.
the class RADActionBoundUIIDSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Toggled Actions Sample", new BorderLayout());
// Create a tag fo the online status property.
Tag TAG_ONLINE = new Tag("online");
// Create an action that will indicte the online/offline status
ActionNode status = UI.action(// on state of TAG_ONLINE property.
UI.label(person -> {
if (person.isFalsey(TAG_ONLINE)) {
return "Offline";
} else {
return "Online";
}
}), // Depending on state of TAG_ONLINE property
UI.uiid(person -> {
if (person.isFalsey(TAG_ONLINE)) {
return "LoggedOutStatusButton";
} else {
return "LoggedInStatusButton";
}
}), // Icon for the action
UI.icon(FontImage.MATERIAL_PERSON), // define it to always return true so action is always visible.
UI.condition(person -> {
return true;
}));
// A User entity we use for the models.
class User extends Entity {
}
entityTypeBuilder(User.class).Boolean(TAG_ONLINE).string(Thing.name).factory(cls -> {
return new User();
}).build();
// Create an entity list that will hold several users.
EntityList el = new EntityList();
for (int i = 0; i < 200; i++) {
User u = new User();
u.set(Thing.name, "User " + i);
u.set(TAG_ONLINE, i % 2 == 0);
el.add(u);
}
// The ListNode is a wrapper that will be passed to our View so that
// they can access our action.
ListNode node = new ListNode(// for each row.
UI.actions(ProfileListView.ACCOUNT_LIST_ROW_ACTIONS, status));
// Use a ProfileListView to display all of the users
// https://shannah.github.io/CodeRAD/javadoc/com/codename1/rad/ui/entityviews/ProfileListView.html
ProfileListView plv = new ProfileListView(el, node, 8);
plv.setScrollableY(true);
// In order to respond to events raised by the action, our view needs to be wrapped
// in a controller. Normally our form would have a FormViewController so we could
// just use FormController, but this sample is compressed to be inside
// a single method here so we'll create a dedicated ViewController for the list
ViewController ctrl = new ViewController(null);
ctrl.setView(plv);
ctrl.addActionListener(status, evt -> {
// The action was pressed by the user
// Update the model's online status
User u = (User) evt.getEntity();
u.set(TAG_ONLINE, u.isFalsey(TAG_ONLINE));
// This will trigger a property change in the model which will update the view.
});
hi.add(CENTER, plv);
hi.show();
}
use of com.codename1.rad.models.Tag in project CodenameOne by codenameone.
the class RADStatusViewSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", BoxLayout.y());
Tag TAG_ONLINE = new Tag("online");
class User extends Entity {
}
entityTypeBuilder(User.class).Boolean(TAG_ONLINE).string(Thing.name).factory(cls -> {
return new User();
}).build();
/**
* A view that displays the status (online/offline) of an entity using
* the TAG_ONLINE tag.
*/
class StatusView extends AbstractEntityView {
// ViewNode. Not used;
ViewNode node;
// Flag to indicate the current state online/offline of the view
private boolean online;
// Label used
private Label label = new Label();
/**
* Creates a new StatusView for user model.
*/
StatusView(User user) {
super(user);
this.node = new ViewNode(new Attribute[] {});
setLayout(new BorderLayout());
$(this).setMargin(0).setPadding(0);
this.add(CENTER, label);
update();
}
@Override
public void update() {
// Check to see if the model is online.
boolean modelOnline = !getEntity().isFalsey(TAG_ONLINE);
if (modelOnline != online) {
// Model state has changed since last update
online = modelOnline;
if (online) {
label.setText("Online");
label.setUIID("OnlineLabel");
FontImage.setMaterialIcon(label, FontImage.MATERIAL_CONNECTED_TV);
} else {
label.setText("Offline");
label.setUIID("OfflineLabel");
FontImage.setMaterialIcon(label, FontImage.MATERIAL_OFFLINE_BOLT);
}
Form f = getComponentForm();
if (f != null) {
// Changing the text in this case may change the layout size
// of the status view here, so it is best to just issue a revalidate
// for the whole form. If the status change didn't change
// the layout size, then we could have just skipped this step.
f.revalidateWithAnimationSafety();
}
}
}
@Override
public void commit() {
// Don't need to implement commit() because this view doesn't
// "update" the model - it only shows model stats.
}
@Override
public Node getViewNode() {
return node;
}
}
// Create a new user
User user = new User();
// Create a status view for the user
StatusView statusView = new StatusView(user);
// Add a UI switch to toggle user state between online and offline
Switch onlineSwitch = new Switch("Online");
onlineSwitch.addChangeListener(e -> {
// Set the user TAG_ONLINE status. This will trigger a property
// change in the model and update the view.
user.set(TAG_ONLINE, onlineSwitch.isOn());
});
hi.add(onlineSwitch);
hi.add(statusView);
hi.show();
}
use of com.codename1.rad.models.Tag in project CodenameOne by codenameone.
the class RSSService method readResponse.
/**
* {@inheritDoc}
*/
protected void readResponse(InputStream input) throws IOException {
results = new Vector();
class FinishParsing extends RuntimeException {
}
XMLParser p = new XMLParser() {
private String lastTag;
private Hashtable current;
private String url;
protected boolean startTag(String tag) {
if ("item".equalsIgnoreCase(tag) || "entry".equalsIgnoreCase(tag)) {
if (startOffset > 0) {
return true;
}
current = new Hashtable();
if (iconPlaceholder != null) {
current.put("icon", iconPlaceholder);
}
}
lastTag = tag;
return true;
}
protected void attribute(String tag, String attributeName, String value) {
if (current != null) {
if ("media:thumbnail".equalsIgnoreCase(tag) && "url".equalsIgnoreCase(attributeName)) {
current.put("thumb", value);
} else {
if ("media:player".equalsIgnoreCase(tag) && "url".equalsIgnoreCase(attributeName)) {
current.put("player", value);
}
}
}
}
protected void textElement(String text) {
if (lastTag != null && current != null) {
// make "ATOM" seem like RSS
if ("summary".equals(lastTag)) {
current.put("details", text);
} else {
if ("content".equals(lastTag)) {
current.put("description", text);
} else {
current.put(lastTag, text);
}
}
}
}
protected void endTag(String tag) {
if ("item".equalsIgnoreCase(tag) || "entry".equalsIgnoreCase(tag)) {
if (startOffset > 0) {
startOffset--;
return;
}
results.addElement(current);
current = null;
if (limit > -1 && results.size() >= limit) {
throw new FinishParsing();
}
}
if (tag.equals(lastTag)) {
lastTag = null;
}
}
};
p.setParserCallback(this);
input.mark(10);
// Skip the bom marking UTF-8 in some streams
while (input.read() != '<') {
// input.mark(4);
}
int question = input.read();
String cType = "UTF-8";
if (question == '?') {
// we are in an XML header, check if the encoding section exists
StringBuilder cs = new StringBuilder();
question = input.read();
while (question != '>') {
cs.append((char) question);
question = input.read();
}
String str = cs.toString();
int index = str.indexOf("encoding=\"") + 10;
if (index > -1) {
cType = str.substring(index, Math.max(str.indexOf("\"", index), str.indexOf("'", index)));
}
} else {
// oops, continue as usual
input.reset();
}
String resultType = getResponseContentType();
if (resultType != null && resultType.indexOf("charset=") > -1) {
cType = resultType.substring(resultType.indexOf("charset=") + 8);
}
try {
int pos2 = cType.indexOf(';');
if (pos2 > 0) {
cType = cType.substring(0, pos2);
}
p.eventParser(new InputStreamReader(input, cType));
} catch (FinishParsing ignor) {
hasMore = true;
}
if (isCreatePlainTextDetails()) {
int elementCount = results.size();
for (int iter = 0; iter < elementCount; iter++) {
Hashtable h = (Hashtable) results.elementAt(iter);
String s = (String) h.get("description");
if (s != null && !h.containsKey("details")) {
XMLParser x = new XMLParser();
Element e = x.parse(new CharArrayReader(("<xml>" + s + "</xml>").toCharArray()));
Vector results = e.getTextDescendants(null, false);
StringBuilder endResult = new StringBuilder();
for (int i = 0; i < results.size(); i++) {
endResult.append(((Element) results.elementAt(i)).getText());
}
h.put("details", endResult.toString());
}
}
}
fireResponseListener(new NetworkEvent(this, results));
}
use of com.codename1.rad.models.Tag in project CodenameOne by codenameone.
the class HTMLComponent method cleanup.
/**
* Rebuilds the HTMLComponent, this is called usually after a new page was loaded.
*/
private void cleanup() {
if (document != null) {
cleanElementUI(document);
}
if (eventsListener != null) {
eventsListener.deregisterAll();
}
displayWidth = Display.getInstance().getDisplayWidth();
// reset all building process values
leftIndent = 0;
x = 0;
containers = new Vector();
// embeddedCSS=null; // Shouldn't nullify as embedded style tag is collected in the head phase which is before..
marqueeComponents = new Vector();
marqueeMotion = null;
anchors = new Hashtable();
anchor = null;
accesskey = '\0';
for (Enumeration e = accessKeys.keys(); e.hasMoreElements(); ) {
int keyCode = ((Integer) e.nextElement()).intValue();
getComponentForm().removeKeyListener(keyCode, this);
}
// =new Hashtable();
accessKeys.clear();
fieldsets = new Vector();
curTable = null;
tables = new Vector();
tableCells = new Vector();
ulLevel = 0;
olIndex = Integer.MIN_VALUE;
olUpperLevelIndex = new Vector();
listType = HTMLListIndex.LIST_NUMERIC;
underlineCount = 0;
strikethruCount = 0;
textDecoration = 0;
imageMapComponents = null;
imageMapData = null;
curImageMap = null;
superscript = 0;
maxSuperscript = 0;
counters = null;
font = defaultFont;
labelForID = null;
inputFields = new Hashtable();
link = null;
linkVisited = false;
mainLink = null;
firstFocusable = null;
curForm = null;
curTextArea = null;
curComboBox = null;
textfieldsToForms = new Hashtable();
optionTag = false;
optionSelected = false;
preTagCount = 0;
quoteTagCount = 0;
mainContainer = new Container();
if (pageUIID != null) {
mainContainer.setUIID(pageUIID);
}
if (pageStyle != null) {
applyPageStyle();
}
mainContainer.setScrollableX(false);
mainContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
curContainer = mainContainer;
curLine = new Container();
lastWasEmpty = false;
width = Display.getInstance().getDisplayWidth() - getStyle().getMargin(Component.LEFT) - getStyle().getPadding(Component.LEFT) - getStyle().getMargin(Component.RIGHT) - getStyle().getPadding(Component.RIGHT) - // The -10 is arbitrary to avoid edge cases
10;
textColor = DEFAULT_TEXT_COLOR;
}
Aggregations