Skip to content

Commit f26c11a

Browse files
authored
Merge pull request #17 from codenameone/master
update
2 parents eff5eb4 + 4aca54c commit f26c11a

File tree

32 files changed

+1758
-156
lines changed

32 files changed

+1758
-156
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
* This code is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License version 2 only, as
6+
* published by the Free Software Foundation. Codename One designates this
7+
* particular file as subject to the "Classpath" exception as provided
8+
* by Oracle in the LICENSE file that accompanied this code.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Codename One through http://www.codenameone.com/ if you
21+
* need additional information or have any questions.
22+
*
23+
* This code was adapted from TeaVM's class library.
24+
*/
25+
26+
package com.codename1.compat.java.util;
27+
28+
import java.util.Arrays;
29+
import java.util.Comparator;
30+
31+
/**
32+
* This is a compatibility class which supports the java.util.Objects API. On platforms that don't support this class (e.g. Android)
33+
* the build server will automatically remap all uses of java.util.Objects to use this implementation instead.
34+
*
35+
* This class consists of static utility methods for operating on objects. These utilities include null-safe or null-tolerant methods for computing the hash code of an object, returning a string for an object, and comparing two objects.
36+
* @author shannah
37+
*/
38+
public final class Objects {
39+
/**
40+
* Returns true if the arguments are equal to each other and false otherwise. Consequently, if both arguments are null, true is returned and if exactly one argument is null, false is returned. Otherwise, equality is determined by using the equals method of the first argument.
41+
* @param a
42+
* @param b
43+
* @return
44+
*/
45+
public static boolean equals(Object a, Object b) {
46+
if (a == b) {
47+
return true;
48+
}
49+
return a == null ? b == null : a.equals(b);
50+
}
51+
52+
/**
53+
* Returns the hash code of a non-null argument and 0 for a null argument.
54+
* @param o
55+
* @return
56+
*/
57+
public static int hashCode(Object o) {
58+
return o == null ? 0 : o.hashCode();
59+
}
60+
61+
public static String toString(Object o) {
62+
return toString(o, "null");
63+
}
64+
65+
public static String toString(Object o, String nullDefault) {
66+
return o != null ? o.toString() : nullDefault;
67+
}
68+
69+
public static <T> int compare(T a, T b, Comparator<? super T> c) {
70+
return a == null && b == null ? 0 : c.compare(a, b);
71+
}
72+
73+
public static <T> T requireNonNull(T obj) {
74+
return requireNonNull(obj, "");
75+
}
76+
77+
public static <T> T requireNonNull(T obj, String message) {
78+
if (obj == null) {
79+
throw new NullPointerException(message);
80+
}
81+
return obj;
82+
}
83+
84+
public static boolean nonNull(Object obj) {
85+
return obj != null;
86+
}
87+
88+
public static boolean deepEquals(Object a, Object b) {
89+
if (a == b) {
90+
return true;
91+
}
92+
if (a == null) {
93+
return b == null;
94+
}
95+
if (a instanceof boolean[]) {
96+
return b instanceof boolean[] && Arrays.equals((boolean[]) a, (boolean[]) b);
97+
} else if (b instanceof boolean[]) {
98+
return false;
99+
} else if (a instanceof byte[]) {
100+
return b instanceof byte[] && Arrays.equals((byte[]) a, (byte[]) b);
101+
} else if (b instanceof byte[]) {
102+
return false;
103+
} else if (a instanceof short[]) {
104+
return b instanceof short[] && Arrays.equals((short[]) a, (short[]) b);
105+
} else if (b instanceof short[]) {
106+
return false;
107+
} else if (a instanceof int[]) {
108+
return b instanceof int[] && Arrays.equals((int[]) a, (int[]) b);
109+
} else if (b instanceof int[]) {
110+
return false;
111+
} else if (a instanceof char[]) {
112+
return b instanceof char[] && Arrays.equals((char[]) a, (char[]) b);
113+
} else if (b instanceof char[]) {
114+
return false;
115+
} else if (a instanceof float[]) {
116+
return b instanceof float[] && Arrays.equals((float[]) a, (float[]) b);
117+
} else if (b instanceof float[]) {
118+
return false;
119+
} else if (a instanceof double[]) {
120+
return b instanceof double[] && Arrays.equals((double[]) a, (double[]) b);
121+
} else if (b instanceof double[]) {
122+
return false;
123+
} else if (a instanceof Object[]) {
124+
return b instanceof Object[] && Arrays.deepEquals((Object[]) a, (Object[]) b);
125+
} else if (b instanceof Object[]) {
126+
return false;
127+
} else {
128+
return a.equals(b);
129+
}
130+
}
131+
132+
public static int hash(Object... values) {
133+
return Arrays.hashCode(values);
134+
}
135+
}
136+

CodenameOne/src/com/codename1/components/InteractionDialog.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,11 @@ protected void deinitialize() {
289289
Container pp = getLayeredPane(f);
290290
Container p = getParent();
291291
remove();
292-
p.remove();
293-
pp.removeAll();
294-
pp.revalidate();
292+
if (p.getComponentCount() == 0) {
293+
p.remove();
294+
}
295+
//pp.removeAll();
296+
pp.revalidateWithAnimationSafety();
295297
cleanupLayer(f);
296298
}
297299
}
@@ -422,8 +424,12 @@ public void dispose() {
422424
}
423425
Container pp = getLayeredPane(f);
424426
remove();
425-
p.remove();
426-
pp.removeAll();
427+
if (p.getComponentCount() == 0) {
428+
p.remove();
429+
}
430+
//p.remove();
431+
//pp.removeAll();
432+
427433
pp.revalidate();
428434
cleanupLayer(f);
429435
} else {
@@ -610,9 +616,9 @@ public void actionPerformed(ActionEvent evt) {
610616

611617

612618
/**
613-
* A popup dialog is shown with the context of a component and its selection, it is disposed seamlessly if the back button is pressed
614-
* or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
615-
* dialog has the PopupDialog style by default.
619+
* A popup dialog is shown with the context of a component and its selection. You should use {@link #setDisposeWhenPointerOutOfBounds(boolean)} to make it dispose
620+
* when the user clicks outside the bounds of the popup. It can optionally provide an arrow in the theme to point at the context component. The popup
621+
* dialog has the {@literal PopupDialog} style by default.
616622
*
617623
* @param c the context component which is used to position the dialog and can also be pointed at
618624
*/
@@ -627,9 +633,9 @@ public void showPopupDialog(Component c) {
627633
}
628634

629635
/**
630-
* A popup dialog is shown with the context of a component and its selection, it is disposed seamlessly if the back button is pressed
631-
* or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
632-
* dialog has the PopupDialog style by default.
636+
* A popup dialog is shown with the context of a component and its selection. You should use {@link #setDisposeWhenPointerOutOfBounds(boolean)} to make it dispose
637+
* when the user clicks outside the bounds of the popup. It can optionally provide an arrow in the theme to point at the context component. The popup
638+
* dialog has the {@literal PopupDialog} style by default.
633639
*
634640
* @param rect the screen rectangle to which the popup should point
635641
*/

CodenameOne/src/com/codename1/io/Storage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public OutputStream createOutputStream(String name) throws IOException {
168168
* @return the input stream
169169
*/
170170
public InputStream createInputStream(String name) throws IOException {
171+
if (!exists(name)) {
172+
throw new IOException("Storage key "+name+" does not exist");
173+
}
171174
name = fixFileName(name);
172175
return Util.getImplementation().createStorageInputStream(name);
173176
}

CodenameOne/src/com/codename1/io/Util.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,11 @@ public static int toIntValue(Object number) {
14661466
return ((Integer)number).intValue();
14671467
}
14681468
if(number instanceof String) {
1469-
return Integer.parseInt((String)number);
1469+
String n = (String)number;
1470+
if(n.length() == 0 || n.equals(" ")) {
1471+
return 0;
1472+
}
1473+
return Integer.parseInt(n);
14701474
}
14711475
if(number instanceof Double) {
14721476
return ((Double)number).intValue();

CodenameOne/src/com/codename1/ui/CN.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,9 @@ public static void sendSMS(String phoneNumber, String message, boolean interacti
768768
* This method is implemented if isNativeShareSupported() returned true for
769769
* a specific platform.
770770
*
771+
* <p>Since 6.0, there is native sharing support in the Javascript port using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share">navigator.share</a>
772+
* API. Currently (2019) this is only supported on Chrome for Android, and will only work if the app is accessed over https:.</p>
773+
*
771774
* @param text String to share.
772775
* @param image file path to the image or null
773776
* @param mimeType type of the image or null if no image to share
@@ -778,6 +781,10 @@ public static void share(String text, String image, String mimeType){
778781

779782
/**
780783
* Indicates if the underlying platform supports sharing capabilities
784+
*
785+
* <p>Since 6.0, there is native sharing support in the Javascript port using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share">navigator.share</a>
786+
* API. Currently (2019) this is only supported on Chrome for Android, and will only work if the app is accessed over https:.</p>
787+
*
781788
* @return true if the underlying platform handles share.
782789
*/
783790
public static boolean isNativeShareSupported(){

CodenameOne/src/com/codename1/ui/ComboBox.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public void pointerDragged(int x, int y) {
473473
* {@inheritDoc}
474474
*/
475475
public void pointerReleased(int x, int y) {
476-
if(isEnabled()) {
476+
if(isEnabled() && !Display.impl.isScrollWheeling()) {
477477
fireClicked();
478478
}
479479
}

CodenameOne/src/com/codename1/ui/Component.java

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
* @see Container
6262
* @author Chen Fishbein
6363
*/
64-
public class Component implements Animation, StyleListener {
64+
public class Component implements Animation, StyleListener, Editable {
6565

6666
private int tabIndex;
6767
// -1 = the element should be focusable, but should not be reachable via sequential keyboard navigation. Mostly useful to create accessible widgets
@@ -214,6 +214,8 @@ public class Component implements Animation, StyleListener {
214214
private Component nextFocusDown;
215215
private Component nextFocusUp;
216216

217+
private Editable editingDelegate;
218+
217219
/**
218220
* Indicates whether component is enabled or disabled
219221
*/
@@ -449,6 +451,28 @@ public class Component implements Animation, StyleListener {
449451
boolean isDragAndDropInitialized() {
450452
return dragAndDropInitialized;
451453
}
454+
455+
/**
456+
* Sets the editing delegate for this component. The editing delegate allows you to define the
457+
* editing workflow for a component. If a delegate is registered, then editing methods such as
458+
* {@link #isEditable() }, {@link #isEditing() }, {@link #startEditingAsync() }, and {@link #stopEditing(java.lang.Runnable) }
459+
* will be delegated to the delegate object.
460+
* @param editable An editable delegate.
461+
* @since 6.0
462+
*/
463+
public void setEditingDelegate(Editable editable) {
464+
this.editingDelegate = editable;
465+
}
466+
467+
/**
468+
* Gets the delegate that handles the editing of this component.
469+
* @return The editing delegate for this component.
470+
* @since 6.0
471+
*/
472+
public Editable getEditingDelegate() {
473+
return this.editingDelegate;
474+
}
475+
452476

453477
/**
454478
* Sets a custom mouse cursor for this component if the platform supports mouse cursors, notice that this isn't applicable for touch devices.
@@ -4576,13 +4600,15 @@ public boolean isTensileDragEnabled() {
45764600
}
45774601

45784602
boolean isScrollDecelerationMotionInProgress() {
4579-
if (draggedMotionY != null) {
4580-
if (draggedMotionY == decelerationMotion && !draggedMotionY.isFinished()) {
4603+
Motion dmY = draggedMotionY;
4604+
if (dmY != null) {
4605+
if (dmY == decelerationMotion && !dmY.isFinished()) {
45814606
return true;
45824607
}
45834608
}
4584-
if (draggedMotionX != null) {
4585-
if (draggedMotionX == decelerationMotion && !draggedMotionX.isFinished()) {
4609+
Motion dmX = draggedMotionX;
4610+
if (dmX != null) {
4611+
if (dmX == decelerationMotion && !dmX.isFinished()) {
45864612
return true;
45874613
}
45884614
}
@@ -5860,9 +5886,14 @@ void deinitializeImpl() {
58605886
* @see #stopEditing(java.lang.Runnable)
58615887
* @see #isEditing()
58625888
* @see #isEditable()
5889+
* @see #getEditingDelegate()
5890+
* @see #setEditingDelegate(com.codename1.ui.Editable)
58635891
*/
58645892
public void startEditingAsync() {
58655893
// Empty implementation overridden by subclass
5894+
if (editingDelegate != null) {
5895+
editingDelegate.startEditingAsync();
5896+
}
58665897
}
58675898

58685899
/**
@@ -5871,9 +5902,13 @@ public void startEditingAsync() {
58715902
* @see #startEditingAsync()
58725903
* @see #isEditing()
58735904
* @see #isEditable()
5905+
* @see #getEditingDelegate()
5906+
* @see #setEditingDelegate(com.codename1.ui.Editable)
58745907
*/
58755908
public void stopEditing(Runnable onFinish) {
5876-
5909+
if (editingDelegate != null) {
5910+
editingDelegate.stopEditing(onFinish);
5911+
}
58775912
}
58785913

58795914
/**
@@ -5883,17 +5918,30 @@ public void stopEditing(Runnable onFinish) {
58835918
* @see #startEditingAsync()
58845919
* @see #stopEditing(java.lang.Runnable)
58855920
* @see #isEditable()
5921+
* @see #getEditingDelegate()
5922+
* @see #setEditingDelegate(com.codename1.ui.Editable)
58865923
*/
58875924
public boolean isEditing() {
5925+
if (editingDelegate != null) {
5926+
return editingDelegate.isEditing();
5927+
}
58885928
return false;
58895929
}
58905930

58915931
/**
58925932
* Checks to see if the component is editable. This is used for next/previous
58935933
* focus traversal on forms.
58945934
* @return
5935+
* @see #getEditingDelegate()
5936+
* @see #setEditingDelegate(com.codename1.ui.Editable)
5937+
* @see #isEditing()
5938+
* @see #startEditingAsync()
5939+
* @see #stopEditing(java.lang.Runnable)
58955940
*/
58965941
public boolean isEditable() {
5942+
if (editingDelegate != null) {
5943+
return editingDelegate.isEditable();
5944+
}
58975945
return false;
58985946
}
58995947

0 commit comments

Comments
 (0)