Skip to content
13 changes: 6 additions & 7 deletions CodenameOne/src/com/codename1/charts/ChartComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -869,15 +869,14 @@ private void zoomTransition(double minX, double maxX, double minY, double maxY,
} else {
Shape currentViewPort = screenToChartShape(new Rectangle(getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight()));
float[] currentRect = currentViewPort.getBounds2D();
float[] newRect = new float[]{(float) minX, (float) (maxX - minX), (float) minY, (float) (maxY - minY)};

float currentAspect = currentRect[2] / currentRect[3];
float newAspect = 1.0f;
Rectangle newViewPort = new Rectangle((int) newRect[0], (int) newRect[1], (int) newRect[2], (int) newRect[3]);
if (newAspect != currentAspect) {
newViewPort.setHeight((int) (((double) newViewPort.getWidth()) / currentAspect));
newRect = newViewPort.getBounds2D();
newAspect = newRect[2] / newRect[3];
Rectangle newViewPort = new Rectangle((int) minX, (int) (maxX - minX), (int) minY, (int) (maxY - minY));
if (newViewPort.getHeight() != 0) {
float newAspect = (float) newViewPort.getWidth() / (float) newViewPort.getHeight();
if (newAspect != currentAspect) {
newViewPort.setHeight((int) (((double) newViewPort.getWidth()) / currentAspect));
}
}

ZoomTransition zt = new ZoomTransition(currentViewPort.getBounds(), newViewPort, duration);
Expand Down
7 changes: 4 additions & 3 deletions CodenameOne/src/com/codename1/charts/views/XYChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint
seriesRenderer.isDisplayBoundingPoints());
int startIndex = -1;

for (Double value : range.keySet()) {
double xValue = value;
Double rValue = range.get(value);
for (Map.Entry<Double, Double> entry : range.entrySet()) {
Double value = entry.getKey();
double xValue = value.doubleValue();
Double rValue = entry.getValue();
double yValue = rValue.doubleValue();
if (startIndex < 0 && (!isNullValue(yValue) || isRenderNullValues())) {
startIndex = series.getIndexForKey(xValue);
Expand Down
1 change: 1 addition & 0 deletions CodenameOne/src/com/codename1/components/Ads.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public String getAd() {
* @param ad the ad to set
*/
public void setAd(String ad) {
this.ad = ad;
HTMLComponent html = new HTMLComponent(new AsyncDocumentRequestHandlerImpl() {

protected ConnectionRequest createConnectionRequest(DocumentInfo docInfo, IOCallback callback, Object[] response) {
Expand Down
1 change: 1 addition & 0 deletions CodenameOne/src/com/codename1/components/ButtonList.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ protected void onReady(Runnable r) {
* buttons.
*/
protected void fireReady() {
ready = true;
for (Runnable r : onReady) {
r.run();
}
Expand Down
22 changes: 21 additions & 1 deletion CodenameOne/src/com/codename1/facebook/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,29 @@ private void init(Hashtable toCopy) {
email = (String) toCopy.get("email");
website = (String) toCopy.get("website");
bio = (String) toCopy.get("bio");
quotes = (String) toCopy.get("quotes");
gender = (String) toCopy.get("gender");
relationship_status = (String) toCopy.get("relationship_status");
//timezone = Long.parseLong((String) toCopy.get("timezone"));
Object tz = toCopy.get("timezone");
if (tz instanceof Integer) {
timezone = ((Integer) tz).longValue();
} else if (tz instanceof Long) {
timezone = ((Long) tz).longValue();
} else if (tz instanceof Short) {
timezone = ((Short) tz).shortValue();
} else if (tz instanceof Byte) {
timezone = ((Byte) tz).byteValue();
} else if (tz instanceof Double) {
timezone = (long) ((Double) tz).doubleValue();
} else if (tz instanceof Float) {
timezone = (long) ((Float) tz).floatValue();
} else if (tz instanceof String) {
try {
timezone = Long.parseLong((String) tz);
} catch (NumberFormatException ignore) {
timezone = 0;
}
}
last_updated = (String) toCopy.get("last_updated");
locale = (String) toCopy.get("locale");
Hashtable l = (Hashtable) toCopy.get("location");
Expand Down
37 changes: 20 additions & 17 deletions CodenameOne/src/com/codename1/io/ConnectionRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1609,19 +1609,20 @@ protected void postResponse() {
protected String createRequestURL() {
if (!post && requestArguments != null) {
StringBuilder b = new StringBuilder(url);
Iterator e = requestArguments.keySet().iterator();
if (e.hasNext()) {
Iterator entries = requestArguments.entrySet().iterator();
if (entries.hasNext()) {
b.append("?");
}
while (e.hasNext()) {
String key = (String) e.next();
Object requestVal = requestArguments.get(key);
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
String key = (String) entry.getKey();
Object requestVal = entry.getValue();
if (requestVal instanceof String) {
String value = (String) requestVal;
b.append(key);
b.append("=");
b.append(value);
if (e.hasNext()) {
if (entries.hasNext()) {
b.append("&");
}
continue;
Expand All @@ -1637,7 +1638,7 @@ protected String createRequestURL() {
b.append(key);
b.append("=");
b.append(val[vlen - 1]);
if (e.hasNext()) {
if (entries.hasNext()) {
b.append("&");
}
}
Expand All @@ -1655,16 +1656,17 @@ protected String createRequestURL() {
protected void buildRequestBody(OutputStream os) throws IOException {
if (post && requestArguments != null) {
StringBuilder val = new StringBuilder();
Iterator e = requestArguments.keySet().iterator();
while (e.hasNext()) {
String key = (String) e.next();
Object requestVal = requestArguments.get(key);
Iterator entries = requestArguments.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
String key = (String) entry.getKey();
Object requestVal = entry.getValue();
if (requestVal instanceof String) {
String value = (String) requestVal;
val.append(key);
val.append("=");
val.append(value);
if (e.hasNext()) {
if (entries.hasNext()) {
val.append("&");
}
continue;
Expand All @@ -1680,7 +1682,7 @@ protected void buildRequestBody(OutputStream os) throws IOException {
val.append(key);
val.append("=");
val.append(valArray[vlen - 1]);
if (e.hasNext()) {
if (entries.hasNext()) {
val.append("&");
}
}
Expand Down Expand Up @@ -2314,10 +2316,11 @@ public boolean equals(Object o) {
if (r.url == url) {
if (requestArguments != null) {
if (r.requestArguments != null && requestArguments.size() == r.requestArguments.size()) {
Iterator e = requestArguments.keySet().iterator();
while (e.hasNext()) {
Object key = e.next();
Object value = requestArguments.get(key);
Iterator entries = requestArguments.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
Object key = entry.getKey();
Object value = entry.getValue();
Object otherValue = r.requestArguments.get(key);
if (!value.equals(otherValue)) {
return false;
Expand Down
19 changes: 11 additions & 8 deletions CodenameOne/src/com/codename1/io/MultipartRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Vector;

/**
Expand Down Expand Up @@ -247,7 +248,7 @@ public void addArgument(String name, String value) {

protected long calculateContentLength() {
long length = 0L;
Iterator e = args.keySet().iterator();
Iterator entries = args.entrySet().iterator();

long dLength = "Content-Disposition: form-data; name=\"\"; filename=\"\"".length() + 2; // 2 = CRLF
long ctLength = "Content-Type: ".length() + 2; // 2 = CRLF
Expand All @@ -258,9 +259,10 @@ protected long calculateContentLength() {
ctLength = "Content-Type: text/plain; charset=UTF-8".length() + 4; // 4 = 2 * CRLF
long baseTextLength = dLength + ctLength + bLength + 2; // 2 = CRLF at end of part

while (e.hasNext()) {
String key = (String) e.next();
Object value = args.get(key);
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
String key = (String) entry.getKey();
Object value = entry.getValue();
if (value instanceof String) {
length += baseTextLength;
length += key.length();
Expand Down Expand Up @@ -319,13 +321,14 @@ protected long calculateContentLength() {
protected void buildRequestBody(OutputStream os) throws IOException {
Writer writer = null;
writer = new OutputStreamWriter(os, "UTF-8");
Iterator e = args.keySet().iterator();
while (e.hasNext()) {
Iterator entries = args.entrySet().iterator();
while (entries.hasNext()) {
if (shouldStop()) {
break;
}
String key = (String) e.next();
Object value = args.get(key);
Map.Entry entry = (Map.Entry) entries.next();
String key = (String) entry.getKey();
Object value = entry.getValue();

writer.write("--");
writer.write(boundary);
Expand Down
18 changes: 13 additions & 5 deletions CodenameOne/src/com/codename1/io/NetworkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,18 @@ private boolean runCurrentRequest(@Async.Execute ConnectionRequest req) {
}
pending.addElement(currentRequest);
LOCK.notify();
try {
LOCK.wait(30);
} catch (InterruptedException ex) {
ex.printStackTrace();
long end = System.currentTimeMillis() + 30;
while (true) {
long remaining = end - System.currentTimeMillis();
if (remaining <= 0) {
break;
}
try {
LOCK.wait(remaining);
break;
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
Expand Down Expand Up @@ -964,7 +972,7 @@ public void run() {
// prevent waiting when there is still a pending request
// this can occur with a race condition since the synchronize
// scope is limited to prevent blocking on add...
if (pending.size() == 0) {
while (pending.size() == 0 && running && !stopped) {
LOCK.wait();
}
} catch (InterruptedException ex) {
Expand Down
8 changes: 4 additions & 4 deletions CodenameOne/src/com/codename1/io/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
Expand Down Expand Up @@ -387,15 +388,14 @@ private <K> void selectProperties(Hashtable<K, Object> selectProperties, final b
if (defaults != null) {
defaults.selectProperties(selectProperties, isStringOnly);
}
Iterator<String> keys = keySet().iterator();
while (keys.hasNext()) {
for (Map.Entry<String, String> entry : entrySet()) {
@SuppressWarnings("unchecked")
K key = (K) keys.next();
K key = (K) entry.getKey();
if (isStringOnly && !(key instanceof String)) {
// Only select property with string key and value
continue;
}
Object value = get(key);
Object value = entry.getValue();
selectProperties.put(key, value);
}
}
Expand Down
4 changes: 2 additions & 2 deletions CodenameOne/src/com/codename1/io/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ public void connect() throws IOException {
connection = impl.connect(url, doInput, doOutput);
impl.setHttpMethod(connection, requestMethod);
if (properties != null && !properties.isEmpty()) {
for (String key : properties.keySet()) {
impl.setHeader(connection, key, properties.get(key));
for (Map.Entry<String, String> entry : properties.entrySet()) {
impl.setHeader(connection, entry.getKey(), entry.getValue());
}
}
}
Expand Down
33 changes: 24 additions & 9 deletions CodenameOne/src/com/codename1/io/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,10 @@ public static void writeObject(Object o, DataOutputStream out) throws IOExceptio
Map v = (Map) o;
out.writeUTF("java.util.Map");
out.writeInt(v.size());
for (Object key : v.keySet()) {
writeObject(key, out);
writeObject(v.get(key), out);
for (Object entryObj : v.entrySet()) {
Map.Entry entry = (Map.Entry) entryObj;
writeObject(entry.getKey(), out);
writeObject(entry.getValue(), out);
}
return;
}
Expand Down Expand Up @@ -1640,9 +1641,18 @@ public static void sleep(int t) {
*/
public static void wait(Object o, int t) {
synchronized (o) {
try {
o.wait(t);
} catch (InterruptedException e) {
long end = System.currentTimeMillis() + t;
while (true) {
long remaining = end - System.currentTimeMillis();
if (remaining <= 0) {
return;
}
try {
o.wait(remaining);
return;
} catch (InterruptedException e) {
// retry until timeout elapses
}
}
}
}
Expand All @@ -1655,9 +1665,14 @@ public static void wait(Object o, int t) {
*/
public static void wait(Object o) {
synchronized (o) {
try {
o.wait();
} catch (InterruptedException e) {
boolean waiting = true;
while (waiting) {
try {
o.wait();
waiting = false;
} catch (InterruptedException e) {
// ignore and continue waiting
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions CodenameOne/src/com/codename1/io/gzip/Adler32.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public void update(byte[] buf, int index, int len) {
int len2 = len % NMAX;
while (len1-- > 0) {
int k = NMAX;
len -= k;
while (k-- > 0) {
s1 += buf[index++] & 0xff;
s2 += s1;
Expand All @@ -102,7 +101,6 @@ public void update(byte[] buf, int index, int len) {
}

int k = len2;
len -= k;
while (k-- > 0) {
s1 += buf[index++] & 0xff;
s2 += s1;
Expand Down
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/io/gzip/Deflate.java
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ int deflate_slow(int flush) {
}

if (match_available != 0) {
bflush = _tr_tally(0, window[strstart - 1] & 0xff);
_tr_tally(0, window[strstart - 1] & 0xff);
match_available = 0;
}
flush_block_only(flush == Z_FINISH);
Expand Down
2 changes: 0 additions & 2 deletions CodenameOne/src/com/codename1/io/gzip/InfCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,6 @@ int proc(int r) {
s.write = q;
r = s.inflate_flush(r);
q = s.write;
m = q < s.read ? s.read - q - 1 : s.end - q;

if (s.read != s.write) {
s.bitb = b;
s.bitk = k;
Expand Down
4 changes: 0 additions & 4 deletions CodenameOne/src/com/codename1/io/gzip/Inflate.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ int inflate(int f) {
case DICT4:

if (z.avail_in == 0) return r;
r = f;

z.avail_in--;
z.total_in++;
this.need = ((long) (z.next_in[z.next_in_index++] & 0xff) << 24) & 0xff000000L;
Expand Down Expand Up @@ -718,15 +716,13 @@ private int readBytes(int r, int f) throws Return {
if (tmp_string == null) {
tmp_string = new java.io.ByteArrayOutputStream();
}
int b = 0;
while (this.need > 0) {
if (z.avail_in == 0) {
throw new Return(r);
}
r = f;
z.avail_in--;
z.total_in++;
b = z.next_in[z.next_in_index];
tmp_string.write(z.next_in, z.next_in_index, 1);
z.adler.update(z.next_in, z.next_in_index, 1);
z.next_in_index++;
Expand Down
Loading
Loading