Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

Commit 353ee5b

Browse files
committed
Added HOW-TO's for animation and connectivity.
1 parent 56a8fb4 commit 353ee5b

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
nav-title: "connectivity How-To"
3+
title: "How-To"
4+
description: "Examples for using connectivity"
5+
---
6+
# Connectivity
7+
Obtaining connectivity information requires the "connectivity" module.
8+
``` JavaScript
9+
var connectivity = require("connectivity");
10+
```
11+
### Getting connection type
12+
``` JavaScript
13+
var connectionType = connectivity.getConnectionType();
14+
switch (connectionType) {
15+
case connectivity.connectionType.none:
16+
//console.log("No connection");
17+
break;
18+
case connectivity.connectionType.wifi:
19+
//console.log("WiFi connection");
20+
break;
21+
case connectivity.connectionType.mobile:
22+
//console.log("Mobile connection");
23+
break;
24+
}
25+
```
26+
### Monitoring connection type.
27+
``` JavaScript
28+
connectivity.starMonitoring(function onConnectionTypeChanged(newConnectionType) {
29+
switch (newConnectionType) {
30+
case connectivity.connectionType.none:
31+
//console.log("Connection type changed to none.");
32+
break;
33+
case connectivity.connectionType.wifi:
34+
//console.log("Connection type changed to WiFi.");
35+
break;
36+
case connectivity.connectionType.mobile:
37+
//console.log("Connection type changed to mobile.");
38+
break;
39+
}
40+
});
41+
//...
42+
connectivity.stopMonitoring();
43+
```
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
nav-title: "animation How-To"
3+
title: "How-To"
4+
description: "Examples for using animation"
5+
---
6+
# Animation
7+
Animating view properties requires the "ui/animation" module.
8+
``` JavaScript
9+
var animation = require("ui/animation");
10+
```
11+
# Animating properties
12+
``` JavaScript
13+
label.animate({
14+
opacity: 0.75,
15+
backgroundColor: new colorModule.Color("Red"),
16+
translate: { x: 100, y: 100 },
17+
scale: { x: 2, y: 2 },
18+
rotate: 180,
19+
duration: 1000,
20+
delay: 100,
21+
iterations: 3,
22+
curve: label.ios ? UIViewAnimationCurve.UIViewAnimationCurveEaseIn : new android.view.animation.AccelerateInterpolator(1),
23+
})
24+
.then(function () {
25+
//console.log("Animation finished.");
26+
})
27+
.catch(function (e) {
28+
console.log(e.message);
29+
});
30+
```
31+
# Cancelling animation
32+
``` JavaScript
33+
var animation1 = label.createAnimation({ translate: { x: 100, y: 100 } });
34+
animation1.play().finished
35+
.then(function () {
36+
//console.log("Animation finished");
37+
})
38+
.catch(function (e) {
39+
//console.log("Animation cancelled");
40+
});
41+
animation1.cancel();
42+
```
43+
# Chaining animations
44+
``` JavaScript
45+
label.animate({ opacity: 0 })
46+
.then(function () { return label.animate({ opacity: 1 }); })
47+
.then(function () { return label.animate({ translate: { x: 200, y: 200 } }); })
48+
.then(function () { return label.animate({ translate: { x: 0, y: 0 } }); })
49+
.then(function () { return label.animate({ scale: { x: 5, y: 5 } }); })
50+
.then(function () { return label.animate({ scale: { x: 1, y: 1 } }); })
51+
.then(function () { return label.animate({ rotate: 180 }); })
52+
.then(function () { return label.animate({ rotate: 0 }); })
53+
.then(function () {
54+
//console.log("Animation finished");
55+
})
56+
.catch(function (e) {
57+
console.log(e.message);
58+
});
59+
```
60+
# Reusing animations
61+
``` JavaScript
62+
var animation1 = label.createAnimation({ translate: { x: 100, y: 100 } });
63+
var animation2 = label.createAnimation({ translate: { x: 0, y: 0 } });
64+
animation1.play().finished
65+
.then(function () { return animation1.play().finished; })
66+
.then(function () { return animation1.play().finished; })
67+
.then(function () { return animation2.play().finished; })
68+
.then(function () { return animation1.play().finished; })
69+
.then(function () { return animation2.play().finished; })
70+
.then(function () {
71+
//console.log("Animation finished");
72+
})
73+
.catch(function (e) {
74+
console.log(e.message);
75+
});
76+
```
77+
# Animating multiple views simultaneously
78+
``` JavaScript
79+
var animations = [
80+
{ target: label1, translate: { x: 200, y: 200 }, duration: 1000, delay: 0 },
81+
{ target: label2, translate: { x: 200, y: 200 }, duration: 1000, delay: 333 },
82+
{ target: label3, translate: { x: 200, y: 200 }, duration: 1000, delay: 666 },
83+
];
84+
var a = new animation.Animation(animations);
85+
a.play().finished
86+
.then(function () {
87+
//console.log("Animations finished");
88+
})
89+
.catch(function (e) {
90+
console.log(e.message);
91+
});
92+
```

modules.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ In your project, the files for each module reside in a dedicated subdirectory in
3434
+ [timer](./ApiReference/timer/HOW-TO.md): Lets you to create, start, stop and react to timers.
3535
+ [trace](./ApiReference/trace/HOW-TO.md): Lets you trace and print specific information based on categories.
3636
+ [ui/image-cache](./ApiReference/ui/image-cache/HOW-TO.md): Provides the `Cache` class which handles image download requests and caches the already downloaded images.
37+
+ [connectivity](./ApiReference/connectivity/HOW-TO.md): Let's you check the type of internet connection and monitor its state changes.
3738

3839
### Device Functionality Modules
3940

@@ -59,6 +60,8 @@ In your project, the files for each module reside in a dedicated subdirectory in
5960
+ [text/formatted-string](./ApiReference/text/formatted-string/HOW-TO.md): Provides the `FormattedString` and `Span` classes which you can use to create rich text formatted strings.
6061
+ [xml](./ApiReference/xml/HOW-TO.md): Provides the `XmlParser` class which is a SAX parser using the easysax implementation.
6162
+ [ui/styling](./ApiReference/ui/styling/HOW-TO.md): Provides the `Style` class which is responsible for the visual appearance of elements.
63+
+ [ui/animation](./ApiReference/ui/animation/HOW-TO.md): Provides the `Animation` class which lets you animate view properties.
64+
6265

6366
#### Layouts
6467

0 commit comments

Comments
 (0)