You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `fillLinearGradient()` convenience methods (with optional `repeat` flag)
85
+
provide a shorthand when you just need a two-color gradient without constructing
86
+
your own `Paint` object.
87
+
88
+
Radial gradients are equally straightforward using
89
+
`fillRadialGradient()` or `fillRectRadialGradient()`, which can render circular
90
+
and rectangular radial transitions respectively. These APIs accept the
91
+
inner/outer colors, focal point, and spread so you can combine them with linear
92
+
gradients to build sophisticated backgrounds and lighting effects.
93
+
63
94
=== Glass Pane
64
95
65
96
The `GlassPane `in Codename One is inspired by the Swing `GlassPane` & `LayeredPane` with quite a few twists.
@@ -139,9 +170,13 @@ paths and curves and caching the shape drawn in the GPU.
139
170
140
171
=== Device Support
141
172
142
-
Shapes and transforms are available on most smartphone platforms with some caveats for the current Windows Phone port.
173
+
Shapes and transforms ship with all of Codename One's actively maintained ports
174
+
(Android, iOS, JavaScript, desktop/Simulator, and UWP). Older platforms that
175
+
have reached end of life may lack these APIs, so keep the guard code shown below
176
+
if you still target them with legacy builds.
143
177
144
-
Notice that perspective transform is missing from the desktop/simulator port. Unfortunately there is no real equivalent to perspective transform in JavaSE that we could use.
178
+
Notice that perspective transform is missing from the desktop/simulator port.
179
+
Unfortunately there is no real equivalent to perspective transform in JavaSE that we could use.
145
180
146
181
=== A 2D Drawing App
147
182
@@ -316,16 +351,17 @@ NOTE: `scale()` and `rotate()` methods are only available on platforms that supp
316
351
317
352
==== Device Support
318
353
319
-
As of this writing, not all devices support transforms (i.e. `scale()` and `rotate()`). The following is a list of platforms
320
-
and their respective levels of support.
354
+
All current Codename One ports expose affine transforms (i.e. `scale()` and
355
+
`rotate()`). Use the following table as a quick reference when deciding whether
356
+
you need a fallback path.
321
357
322
358
.Transforms Device Support
323
359
[cols="2*"]
324
360
|===
325
361
|Platform
326
362
|Affine Supported
327
363
328
-
| Simulator
364
+
| Simulator/Desktop
329
365
| Yes
330
366
331
367
| iOS
@@ -337,14 +373,8 @@ and their respective levels of support.
337
373
| JavaScript
338
374
| Yes
339
375
340
-
| J2ME
341
-
| No
342
-
343
-
| BlackBerry (4.2 & 5)
344
-
| No
345
-
346
-
| Windows Phone
347
-
| No (pending)
376
+
| UWP
377
+
| Yes
348
378
|===
349
379
350
380
@@ -1002,6 +1032,24 @@ You could also use the `Graphics.setTransform()` class to apply rotations and ot
1002
1032
(including 3D perspective transforms), but I'll leave that for its own topic as it is a little bit more complex.
1003
1033
1004
1034
1035
+
==== Global Alpha & Anti-Aliasing
1036
+
1037
+
So far we have relied on the per-pixel alpha stored in images and gradients. `Graphics`
1038
+
also lets you apply a global alpha multiplier to every draw call by using
1039
+
`setAlpha(int)` or `concatenateAlpha(int)` after checking `isAlphaSupported()`.
1040
+
Both methods accept values from `0` (fully transparent) to `255` (fully opaque)
1041
+
and remain active until you change them again. `concatenateAlpha()` is
1042
+
especially handy when you need to temporarily fade a component because it
1043
+
returns the previous alpha so you can restore it later.
1044
+
1045
+
Anti-aliasing can likewise be toggled at runtime. Call `isAntiAliasingSupported()`
1046
+
and `isAntiAliasedTextSupported()` to discover which hints the current port
1047
+
exposes, then use `setAntiAliased(boolean)` and `setAntiAliasedText(boolean)` to
1048
+
opt into smoother edges for shapes and glyphs respectively. These switches make
1049
+
it easy to balance rendering quality versus speed depending on the type of
1050
+
content you draw.
1051
+
1052
+
1005
1053
==== Event Coordinates
1006
1054
1007
1055
The coordinate system and event handling are closely tied. You can listen for touch events on a component by
Copy file name to clipboardExpand all lines: docs/developer-guide/io.asciidoc
+39-3Lines changed: 39 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,19 @@ You can then read the token like this:
127
127
String token = Preferences.get("token", null);
128
128
----
129
129
130
+
The backing store filename defaults to `"codenameone.properties"`, but you can
131
+
override it by calling `Preferences.setPreferencesLocation(String)` before your
132
+
app touches the API. This is useful when you need to segregate preference
133
+
namespaces per user or plug in an encrypted storage layer.
134
+
135
+
When you have a batch of updates, prefer the `Preferences.set(Map<String,Object>)`
136
+
overload so that all values are persisted with a single disk write.
137
+
138
+
Preferences can also notify interested parties when a key changes. Register a
139
+
`PreferenceListener` via `addPreferenceListener()` to react to updates made in
140
+
other parts of your code (or even triggered remotely via `Codename One Push`).
141
+
Remember to remove listeners you no longer need to avoid leaks.
142
+
130
143
WARNING: This gets somewhat confusing with primitive numbers e.g. if you use `Preferences.set("primitiveLongValue", myLongNumber)` then invoke `Preferences.get("primitiveLongValue", 0)` you might get an exception! +
131
144
This would happen because the value is physically a `Long` object but you are trying to get an `Integer`. The workaround is to remain consistent and use code like this `Preferences.get("primitiveLongValue", (long)0)`.
132
145
@@ -250,9 +263,9 @@ In general SQL seems overly complex for most embedded device programming tasks.
250
263
251
264
.Portability Of SQLite
252
265
****
253
-
SQLite is supported on iOS, Android, RIM, Desktop & JavaScript builds. However, the JavaScript version of SQL has been deprecated and isn't supported on all platforms.
254
-
255
-
You will notice that at this time support is still missing from the Windows builds.
266
+
SQLite is supported on iOS, Android, JavaScript, Desktop/Simulator, and UWP
267
+
builds. The JavaScript port relies on the browser's WebSQL implementation, so
268
+
it may be unavailable in environments that have already removed that feature.
256
269
257
270
The biggest issue with SQLite portability is in iOS. The SQLite version for most platforms is threadsafe and as a result very stable. However, the iOS version is not!
Notice that in this case the `addToQueueAndWait` method returned after the connection completed. Also notice that this was totally legal to do on the EDT!
417
430
418
431
432
+
==== Timeouts & Retries
433
+
434
+
Each request can override the global timeout using `setTimeout(int)`, which
435
+
expects a duration in milliseconds. This is especially useful when you are
436
+
talking to endpoints that occasionally need a longer window than the default
437
+
NetworkManager setting. You can also configure how many times Codename One
438
+
should retry a failing call silently by using `setSilentRetryCount(int)`. When
439
+
the silent retry limit is reached the standard error handling kicks in (e.g.
440
+
listeners fire, fail dialogs show, etc.).
441
+
442
+
419
443
==== Threading
420
444
421
445
By default the `NetworkManager` launches with a single network thread. This is sufficient for very simple applications that don't do too much networking but if you need to fetch many images concurrently and perform web services in parallel this might be an issue.
Notice the usage of post and the body builder method. There are MANY methods in the builder class that cover pretty much everything you would expect and then some when it comes to the needs of rest services.
1298
1322
1323
+
Some highlights that are easy to miss:
1324
+
1325
+
* `.priority(byte)` lets you change the underlying `ConnectionRequest` priority
1326
+
when you need certain calls to jump the queue.
1327
+
* `.cookiesEnabled(boolean)` controls whether cookies are persisted for the
1328
+
request when you need stateless behavior.
1329
+
* `.useBoolean(boolean)` and `.useLongs(boolean)` toggle how the JSON parser
1330
+
materializes number and boolean types inside the resulting `Map`, which is
1331
+
handy when your backend is strict about data types.
1332
+
* `.cacheMode(...)` and `.postParameters(...)` expose the same knobs as
1333
+
`ConnectionRequest`, keeping you in the fluent API even for advanced tweaks.
1334
+
1299
1335
I changed the code in the kitchen sink webservice sample to use this API. I was able to make it shorter and more readable without sacrificing anything.
Copy file name to clipboardExpand all lines: docs/developer-guide/performance.asciidoc
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,11 +52,17 @@ The Performance Monitor tool can be accessible via the #Simulator# -> #Performan
52
52
.Main tab of the performance monitor: Logs and timings
53
53
image::img/developer-guide/performance-monitor-tab-1.png[Main tab of the performance monitor: Logs and timings]
54
54
55
-
The first tab of the performance monitor includes a table of the drawn components. Each entry includes the number of times it was drawn and the slowest/fastest and average drawing time.
55
+
The first tab of the performance monitor includes a table of the drawn components. Each entry includes the number of times it was drawn and the slowest/fastest and average drawing time. The toolbar across the top
56
+
includes Pause/Continue buttons so you can freeze the counters while you inspect
57
+
the current snapshot, a "Clear Data" action to reset the tables, and a "GC"
58
+
button that invokes the simulator's garbage collector so you can see how memory
59
+
usage changes.
56
60
57
61
This is useful if a `Form` is slow. You might be able to pinpoint it to a specific component using this tool.
58
62
59
-
The Log on the bottom includes debug related information. E.g. it warns about the usage of mutable images which might be slow on some platforms. This also displays warnings when an unlocked image is drawn etc.
63
+
The Log on the bottom includes debug related information. E.g. it warns about the usage of mutable images which might be slow on some platforms. This also displays warnings when an unlocked image is drawn etc. A live
64
+
"Image Memory Overhead" meter summarizes how much native image memory the
65
+
current form consumes so you can correlate spikes with your drawing code.
We normally place this in the `init(Object)` method so all future on-device errors are emailed to you. Internally this method uses the `Display.getInstance().addEdtErrorHandler()` API to bind error listeners to the EDT. When an exception is thrown there it is swallowed (using `ActionEvent.consume()`). The `Log` data is then sent using `Log.sendLog()`.
140
146
147
+
If your crash handler runs while networking is unavailable or you want to avoid
148
+
blocking the EDT, use `Log.sendLogAsync()` instead. It performs the upload in a
149
+
background thread and is what Codename One's lifecycle helper falls back to when
150
+
regular error reporting fails.
151
+
152
+
You can also plug in your own crash reporting pipeline by calling
153
+
`Display.getInstance().setCrashReporter(CrashReport)`. The
0 commit comments