use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class BlackBerryOS5Implementation method openOutputStream.
/**
* (non-Javadoc)
*
* @see
* com.codename1.impl.blackberry.BlackBerryImplementation#openOutputStream(java.lang.Object)
*/
public OutputStream openOutputStream(Object connection) throws IOException {
if (connection instanceof String) {
return super.openOutputStream(connection);
}
OutputStream os = ((HttpConnection) connection).openOutputStream();
// getSoftwareVersion() not available in legacy port,introduced at API 4.3.0
int majorVersion = DeviceInfo.getSoftwareVersion().charAt(0) - '0';
// in version 7, BBOS started supporting HTTP 1.1, so facade not required.
if (majorVersion < 7) {
os = new BlackBerryOutputStream(os);
}
return new BufferedOutputStream(os, ((HttpConnection) connection).getURL());
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class Util method readObject.
/**
* <p>Reads an object from the stream, notice that this is the inverse of the
* {@link #writeObject(java.lang.Object, java.io.DataOutputStream)}.</p>
*
* <p>
* The sample below demonstrates the usage and registration of the {@link com.codename1.io.Externalizable} interface:
* </p>
* <script src="https://gist.github.com/codenameone/858d8634e3cf1a82a1eb.js"></script>
*
* @param input the source input stream
* @throws IOException thrown by the stream
*/
public static Object readObject(DataInputStream input) throws IOException {
try {
if (!input.readBoolean()) {
return null;
}
String type = input.readUTF();
if ("int".equals(type)) {
return new Integer(input.readInt());
}
if ("byte".equals(type)) {
return new Byte(input.readByte());
}
if ("short".equals(type)) {
return new Short(input.readShort());
}
if ("long".equals(type)) {
return new Long(input.readLong());
}
if ("float".equals(type)) {
return new Float(input.readFloat());
}
if ("double".equals(type)) {
return new Double(input.readDouble());
}
if ("bool".equals(type)) {
return new Boolean(input.readBoolean());
}
if ("String".equals(type)) {
return input.readUTF();
}
if ("Date".equals(type)) {
return new Date(input.readLong());
}
if ("ObjectArray".equals(type)) {
Object[] v = new Object[input.readInt()];
int vlen = v.length;
for (int iter = 0; iter < vlen; iter++) {
v[iter] = readObject(input);
}
return v;
}
if ("ByteArray".equals(type)) {
byte[] v = new byte[input.readInt()];
input.readFully(v);
return v;
}
if ("LongArray".equals(type)) {
long[] v = new long[input.readInt()];
int vlen = v.length;
for (int iter = 0; iter < vlen; iter++) {
v[iter] = input.readLong();
}
return v;
}
if ("ShortArray".equals(type)) {
short[] v = new short[input.readInt()];
int vlen = v.length;
for (int iter = 0; iter < vlen; iter++) {
v[iter] = input.readShort();
}
return v;
}
if ("DoubleArray".equals(type)) {
double[] v = new double[input.readInt()];
int vlen = v.length;
for (int iter = 0; iter < vlen; iter++) {
v[iter] = input.readDouble();
}
return v;
}
if ("FloatArray".equals(type)) {
float[] v = new float[input.readInt()];
int vlen = v.length;
for (int iter = 0; iter < vlen; iter++) {
v[iter] = input.readFloat();
}
return v;
}
if ("IntArray".equals(type)) {
int[] v = new int[input.readInt()];
int vlen = v.length;
for (int iter = 0; iter < vlen; iter++) {
v[iter] = input.readInt();
}
return v;
}
if ("java.util.Vector".equals(type)) {
Vector v = new Vector();
int size = input.readInt();
for (int iter = 0; iter < size; iter++) {
v.addElement(readObject(input));
}
return v;
}
if ("java.util.Hashtable".equals(type)) {
Hashtable v = new Hashtable();
int size = input.readInt();
for (int iter = 0; iter < size; iter++) {
v.put(readObject(input), readObject(input));
}
return v;
}
if ("java.util.Set".equals(type)) {
Collection v = new HashSet();
int size = input.readInt();
for (int iter = 0; iter < size; iter++) {
v.add(readObject(input));
}
return v;
}
if ("java.util.Collection".equals(type)) {
Collection v = new ArrayList();
int size = input.readInt();
for (int iter = 0; iter < size; iter++) {
v.add(readObject(input));
}
return v;
}
if ("java.util.Map".equals(type)) {
Map v = new HashMap();
int size = input.readInt();
for (int iter = 0; iter < size; iter++) {
v.put(readObject(input), readObject(input));
}
return v;
}
if ("EncodedImage".equals(type)) {
int width = input.readInt();
int height = input.readInt();
boolean op = input.readBoolean();
byte[] data = new byte[input.readInt()];
input.readFully(data);
return EncodedImage.create(data, width, height, op);
}
Class cls = (Class) externalizables.get(type);
if (cls != null) {
Object o = cls.newInstance();
if (o instanceof Externalizable) {
Externalizable ex = (Externalizable) o;
ex.internalize(input.readInt(), input);
return ex;
} else {
PropertyBusinessObject pb = (PropertyBusinessObject) o;
pb.getPropertyIndex().asExternalizable().internalize(input.readInt(), input);
return pb;
}
}
throw new IOException("Object type not supported: " + type);
} catch (InstantiationException ex1) {
Log.e(ex1);
throw new IOException(ex1.getClass().getName() + ": " + ex1.getMessage());
} catch (IllegalAccessException ex1) {
Log.e(ex1);
throw new IOException(ex1.getClass().getName() + ": " + ex1.getMessage());
}
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class CodenameOneImplementation method downloadImageToCache.
/**
* Downloads an image from a URL to the cache. Platforms
* that support a native image cache {@link #supportsNativeImageCache() } (e.g. Javascript) override this method to defer to the
* platform's handling of cached images. Platforms that have a caches directory ({@link FileSystemStorage#hasCachesDir() }
* will use that directory to cache the image. Other platforms will just download to storage.
*
* @param url The URL of the image to download.
* @param onSuccess Callback on success.
* @param onFail Callback on fail.
*
* @see URLImage#createToCache(com.codename1.ui.EncodedImage, java.lang.String, com.codename1.ui.URLImage.ImageAdapter)
*/
public void downloadImageToCache(String url, SuccessCallback<Image> onSuccess, final FailureCallback<Image> onFail) {
FileSystemStorage fs = FileSystemStorage.getInstance();
if (fs.hasCachesDir()) {
String name = "cn1_image_cache[" + url + "]";
name = StringUtil.replaceAll(name, "/", "_");
name = StringUtil.replaceAll(name, "\\", "_");
name = StringUtil.replaceAll(name, "%", "_");
name = StringUtil.replaceAll(name, "?", "_");
name = StringUtil.replaceAll(name, "*", "_");
name = StringUtil.replaceAll(name, ":", "_");
name = StringUtil.replaceAll(name, "=", "_");
String filePath = fs.getCachesDir() + fs.getFileSystemSeparator() + name;
// We use Util.downloadImageToFileSystem rather than CodenameOneImplementation.downloadImageToFileSystem
// because we want it to try to load from file system first.
Util.downloadImageToFileSystem(url, filePath, onSuccess, onFail);
} else {
// We use Util.downloadImageToStorage rather than CodenameOneImplementation.downloadImageToStorage
// because we want it to try to load from storage first.
Util.downloadImageToStorage(url, "cn1_image_cache[" + url + "]", onSuccess, onFail);
}
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class IOSImplementation method createAlphaMask.
// -------------------------------------------------------------------------
// METHODS FOR DRAWING SHAPES AND TRANSFORMATIONS
// -------------------------------------------------------------------------
/**
* Creates a platform-specific alpha mask for a shape. This is used to cache
* masks in the {@link com.codename1.ui.GeneralPath} class. On iOS the alpha
* mask is an OpenGL texture ID (not a raster of alpha pixels), but other platforms
* may use different representations if they like.
*
* <p>The {@link com.codename1.ui.Graphics#drawAlphaMask} method
* is used to draw a mask on the graphics context and this will ultimately call {@link #drawAlphaMask}
* which can be platform specific also.
* </p>
* @param shape The shape that will have an alpha mask created.
* @param stroke The stroke settings for stroking the outline of the mask. Leave null to produce a fill
* mask.
* @return The platform specific alpha mask object or null if it is not supported or failed.
* @see #deleteAlphaMask
* @see #drawAlphaMask
* @see #isAlphaMaskSupported
* @see com.codename1.ui.Graphics#drawAlphaMask
* @see com.codename1.ui.GeneralPath#getAlphaMask
*/
public TextureAlphaMask createAlphaMask(Shape shape, Stroke stroke) {
int[] bounds = new int[] { 0, 0, 0, 0 };
long tex = nativeCreateAlphaMaskForShape(shape, stroke, bounds);
Rectangle shapeBounds = shape.getBounds();
int[] padding = new int[] { // top
shapeBounds.getY() - bounds[1], // right
bounds[2] - (shapeBounds.getX() + shapeBounds.getWidth()), // bottom
bounds[3] - (shapeBounds.getY() + shapeBounds.getHeight()), // left
shapeBounds.getX() - bounds[0] };
if (tex == 0) {
return null;
}
return new TextureAlphaMask(tex, new Rectangle(bounds[0], bounds[1], bounds[2] - bounds[0], bounds[3] - bounds[1]), padding);
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class TestRecorder method eventPointerReleased.
void eventPointerReleased(int x, int y) {
if (isRecording()) {
com.codename1.ui.Component cmp = Display.getInstance().getCurrent().getComponentAt(x, y);
if (isListComponent(cmp)) {
return;
}
if (dragged) {
if (dragToScroll.isSelected()) {
com.codename1.ui.Component scrollTo;
if (y > pointerPressedY) {
scrollTo = findLowestVisibleComponent();
} else {
scrollTo = findHighestVisibleComponent();
}
if (scrollTo != null && scrollTo != Display.getInstance().getCurrent() && scrollTo != Display.getInstance().getCurrent().getContentPane()) {
String name = scrollTo.getName();
if (name != null) {
generatedCode += " ensureVisible(\"" + name + "\");\n";
} else {
String pp = getPathToComponent(scrollTo);
if (pp == null) {
return;
}
generatedCode += " ensureVisible(" + pp + ");\n";
}
updateTestCode();
}
} else {
addWaitStatement();
generatedCode += " pointerRelease" + generatePointerEventArguments(x, y);
updateTestCode();
}
} else {
if (isToolbarComponent(cmp)) {
if (cmp instanceof com.codename1.ui.Button) {
Command cmd = ((com.codename1.ui.Button) cmp).getCommand();
if (cmd != null) {
int offset = 0;
Command[] commands = TestUtils.getToolbarCommands();
for (Command c : commands) {
if (c == cmd) {
generatedCode += " assertEqual(getToolbarCommands().length, " + commands.length + ");\n";
generatedCode += " executeToolbarCommandAtOffset(" + offset + ");\n";
updateTestCode();
return;
}
offset++;
}
} else {
if (cmp.getUIID().equals("MenuButton")) {
// side menu button
generatedCode += " showSidemenu();\n";
updateTestCode();
return;
}
}
}
}
if (cmp instanceof com.codename1.ui.Button) {
com.codename1.ui.Button btn = (com.codename1.ui.Button) cmp;
// special case for back command on iOS
if (btn.getCommand() != null && btn.getCommand() == Display.getInstance().getCurrent().getBackCommand()) {
generatedCode += " goBack();\n";
} else {
if (btn.getName() != null && btn.getName().length() > 0) {
generatedCode += " clickButtonByName(\"" + btn.getName() + "\");\n";
} else {
if (btn.getText() != null && btn.getText().length() > 0) {
generatedCode += " clickButtonByLabel(\"" + btn.getText() + "\");\n";
} else {
String pp = getPathToComponent(cmp);
if (pp == null || pp.equals("(String)null")) {
return;
}
generatedCode += " clickButtonByPath(" + pp + ");\n";
}
}
}
updateTestCode();
return;
}
if (cmp instanceof com.codename1.ui.TextArea) {
// ignore this, its probably initiating edit which we will capture soon
return;
}
generatedCode += " pointerPress" + generatePointerEventArguments(pointerPressedX, pointerPressedY);
addWaitStatement();
generatedCode += " pointerRelease" + generatePointerEventArguments(x, y);
updateTestCode();
}
}
}
Aggregations