Skip to content

Commit 0300c52

Browse files
authored
[tizen_bundle] Add tizen_bundle package (#428)
Signed-off-by: Hwankyu Jhun <[email protected]>
1 parent ccd824c commit 0300c52

20 files changed

+1077
-0
lines changed

.github/labeler.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
- packages/tizen_app_manager/**/*
4646
'p: tizen_audio_manager':
4747
- packages/tizen_audio_manager/**/*
48+
'p: tizen_bundle':
49+
- packages/tizen_bundle/**/*
4850
'p: tizen_log':
4951
- packages/tizen_log/**/*
5052
'p: tizen_notification':

.github/recipe.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ plugins:
1515
sqflite: ["wearable-5.5", "tv-6.5"]
1616
tizen_app_manager: ["wearable-5.5", "tv-6.5"]
1717
tizen_audio_manager: ["wearable-5.5", "tv-6.5"]
18+
tizen_bundle: ["wearable-5.5", "tv-6.5"]
1819
tizen_package_manager: ["wearable-5.5", "tv-6.5"]
1920
url_launcher: ["wearable-5.5", "tv-6.5"]
2021
wakelock: ["wearable-5.5"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
3737
| [**tizen_app_control**](packages/tizen_app_control) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_app_control.svg)](https://pub.dev/packages/tizen_app_control) | N/A |
3838
| [**tizen_app_manager**](packages/tizen_app_manager) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_app_manager.svg)](https://pub.dev/packages/tizen_app_manager) | N/A |
3939
| [**tizen_audio_manager**](packages/tizen_audio_manager) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_audio_manager.svg)](https://pub.dev/packages/tizen_audio_manager) | N/A |
40+
| [**tizen_bundle**](packages/tizen_bundle) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_bundle.svg)](https://pub.dev/packages/tizen_bundle) | N/A |
4041
| [**tizen_log**](packages/tizen_log) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_log.svg)](https://pub.dev/packages/tizen_log) | N/A |
4142
| [**tizen_notification**](packages/tizen_notification) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_notification.svg)](https://pub.dev/packages/tizen_notification) | N/A |
4243
| [**tizen_package_manager**](packages/tizen_package_manager) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/tizen_package_manager.svg)](https://pub.dev/packages/tizen_package_manager) | N/A |
@@ -73,6 +74,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
7374
| [**tizen_app_control**](packages/tizen_app_control) | ✔️ | ✔️ | ✔️ | ✔️ |
7475
| [**tizen_app_manager**](packages/tizen_app_manager) | ✔️ | ✔️ | ✔️ | ✔️ |
7576
| [**tizen_audio_manager**](packages/tizen_audio_manager) | ✔️ | ✔️ | ✔️ | ✔️ |
77+
| [**tizen_bundle**](packages/tizen_bundle) | ✔️ | ✔️ | ✔️ | ✔️ |
7678
| [**tizen_log**](packages/tizen_log) | ✔️ | ✔️ ||| Not applicable for TV |
7779
| [**tizen_notification**](packages/tizen_notification) || ✔️ | ✔️ | ✔️ | API not supported |
7880
| [**tizen_package_manager**](packages/tizen_package_manager) | ✔️ | ✔️ | ✔️ | ✔️ |

packages/tizen_bundle/.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
.packages
30+
build/

packages/tizen_bundle/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0
2+
3+
* Initial release.

packages/tizen_bundle/LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2022 Samsung Electronics Co., Ltd. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of the copyright holder nor the names of the
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/tizen_bundle/README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# tizen_bundle
2+
3+
[![pub package](https://img.shields.io/pub/v/tizen_bundle.svg)](https://pub.dev/packages/tizen_bundle)
4+
5+
Tizen bundle APIs.
6+
7+
## Usage
8+
9+
To use this package, add `tizen_bundle` as a dependency in your `pubspec.yaml` file.
10+
11+
```yaml
12+
depenedencies:
13+
tizen_bundle: ^0.1.0
14+
```
15+
16+
### Adding Content to a Bundle
17+
18+
The bundle content is in the from of key-value pairs. The key is always a string. The value can be of the following types:
19+
20+
**Table: Bundle value types**
21+
| Type enum | Dart type |
22+
|--------------------------|-------------------|
23+
| `BundleType.string` | String |
24+
| `BundleType.strings` | List<String> |
25+
| `BundleType.bytes` | Uint8List |
26+
27+
To add content to a bundle, use following methods or `operator [](String key, Object value)` you want to add:
28+
29+
- `Bundle.addAll()`
30+
- `Bundle.addEntries()`
31+
32+
```dart
33+
import 'package:tizen_bundle/tizen_bundle.dart';
34+
35+
var bundle = Bundle();
36+
bundle['string'] = 'stringValue';
37+
38+
List<String> values = ['stringValue1', 'stringValue2', 'stringValue3'];
39+
bundle['strings'] = values;
40+
41+
Uint8List bytes = Uint8List(3);
42+
bytes[0] = 0x01;
43+
bytes[1] = 0x02;
44+
bytes[2] = 0x03;
45+
bundle['bytes'] = bytes;
46+
```
47+
48+
When you no longer needed the bundle object, release it using the `Bundle.dispose()` method as below:
49+
50+
``` dart
51+
bundle.dispose();
52+
```
53+
54+
## Managing the Bundle Content
55+
56+
To manage the bundle content:
57+
58+
1. Gets values from the bundle object using `operator [](String key)` you want to get :
59+
You can also get the number of the bundle items with the `Bundle.length` property, and check whether the value is the type or not with `is` keyword as below:
60+
61+
```dart
62+
import 'package:tizen_log/tizen_log.dart';
63+
64+
String logTag = 'BundleTest';
65+
Log.info(logTag, 'length: ${bundle.length}');
66+
var stringValue = bundle['string'];
67+
if (stringValue is String) {
68+
Log.info(logTag, 'string: $stringValue');
69+
}
70+
71+
var stringsValue = bundle['strings'];
72+
if (stringsValue is List<String>) {
73+
Log.info(logTag, 'strings: $stringsValue');
74+
}
75+
76+
var bytesValue = bundle['bytes'];
77+
if (bytesValue is Uint8List) {
78+
Log.info(logTag, 'bytes: $bytesValue');
79+
}
80+
```
81+
82+
2. Deletes a key-value pair from the bundle content using the `Bundle.remove()` method:
83+
84+
```dart
85+
if (bundle.containsKey('string'))
86+
bundle.remove('string');
87+
88+
if (bundle.containsKey('strings'))
89+
bundle.remove('strings');
90+
91+
if (bundle.containsKey('bytes'))
92+
bundle.remove('bytes');
93+
```
94+
95+
## Iterating the Bundle Content
96+
97+
To iterate through the bundle records, use the 'Bundle.keys' property:
98+
99+
```dart
100+
final keys = bundle.keys;
101+
keys.asMap().forEach((index, key) {
102+
Log.info(logTag, 'key: ${keyInfo.name}');
103+
}
104+
105+
```
106+
107+
## Encoding and Decoding the Bundle
108+
109+
To store or send a bundle over a connection, encode it to `String` with the `Bundle.toRaw()` method.
110+
111+
To open the encoded bundle, use the `Bundle.fromRaw()` method.
112+
113+
```dart
114+
var bundle = Bundle();
115+
bundle.addString('key1', 'value1');
116+
117+
var raw = bundle.toRaw();
118+
bundle.dispose();
119+
120+
var newBundle = Bundle.fromRaw(raw);
121+
Log.info(logTag, 'value: ${newBundle.getString('key')}');
122+
newBundle.dispose();
123+
```
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# VS Code related
20+
.vscode/
21+
22+
# Flutter/Dart/Pub related
23+
**/doc/api/
24+
**/ios/Flutter/.last_build_id
25+
.dart_tool/
26+
.flutter-plugins
27+
.flutter-plugins-dependencies
28+
.packages
29+
.pub-cache/
30+
.pub/
31+
/build/
32+
33+
# Web related
34+
lib/generated_plugin_registrant.dart
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Android Studio will place build artifacts here
43+
/android/app/debug
44+
/android/app/profile
45+
/android/app/release
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# tizen_bundle_example
2+
3+
Demonstrates how to use the tizen_bundle plugin.

0 commit comments

Comments
 (0)