Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tizen_notification] Bump version to 0.2.0 #481

Merged
merged 5 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/tizen_notification/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.2.0

* Clean up the API.
* Rename `NotificationImage` to `NotificationIcons`.
* Rename `Property` to `NotificationProperty`.
* Rename `DisplayApplist` to `NotificationStyle`.
* Rename some members of the above classes.
* Update the documentation.
* Code refactoring and bug fixes.

## 0.1.1

* Update the example app.
Expand Down
4 changes: 2 additions & 2 deletions packages/tizen_notification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Tizen notification APIs. Used to show and delete notifications on a Tizen device

## Usage

To use this plugin, add `tizen_notification` as a dependency in your pubspec.yaml file:
To use this plugin, add `tizen_notification` as a dependency in your `pubspec.yaml` file:

```yaml
dependencies:
tizen_notification: ^0.1.1
tizen_notification: ^0.2.0
```

Then you can import `tizen_notification` in your Dart code:
Expand Down
20 changes: 12 additions & 8 deletions packages/tizen_notification/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ class MyApp extends StatelessWidget {

final TizenNotificationPlugin _tizenNotificationPlugin =
TizenNotificationPlugin();
final int notificationId = 1;
final int _notificationId = 1;

Future<void> _showNotification() async {
final TizenNotificationDetails details = TizenNotificationDetails(
image: NotificationImage(iconPath: 'test.png'),
properties: Property.disableAutoDelete | Property.disableAppLaunch,
vibration: NotificationVibration(type: VibrationType.builtIn),
icons: NotificationIcons(icon: 'test.png'),
sound: NotificationSound(type: SoundType.builtIn),
vibration: NotificationVibration(type: VibrationType.builtIn),
properties: NotificationProperty.disableAutoDelete,
appControl: AppControl(appId: 'org.tizen.tizen_notification_example'),
);
await _tizenNotificationPlugin.show(
notificationId,
title: 'show Notification Title',
body: 'show Notification Body',
_notificationId,
title: 'Notification title',
body: 'Notification body',
notificationDetails: details,
);
}

Future<void> _cancelNotification() async {
await _tizenNotificationPlugin.cancel(notificationId);
await _tizenNotificationPlugin.cancel(_notificationId);
}

Future<void> _cancelAllNotifications() async {
Expand All @@ -45,6 +46,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Tizen Notification Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -53,10 +55,12 @@ class MyApp extends StatelessWidget {
onPressed: _showNotification,
child: const Text('Show notification'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _cancelNotification,
child: const Text('Cancel notification'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _cancelAllNotifications,
child: const Text('Cancel all notifications'),
Expand Down
27 changes: 0 additions & 27 deletions packages/tizen_notification/lib/src/enums.dart

This file was deleted.

219 changes: 158 additions & 61 deletions packages/tizen_notification/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,199 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs
import 'package:tizen_app_control/tizen_app_control.dart';

import 'enums.dart';
export 'package:tizen_app_control/tizen_app_control.dart';

/// Properties that configure how the system handles notification at
/// certain scenarios.
class Property {
/// Display only SIM card inserted.
static const int displayOnlySimMode = 1 << 0;
/// How the system handles the notification in certain scenarios.
class NotificationProperty {
bbrto21 marked this conversation as resolved.
Show resolved Hide resolved
// The constants below are originally defined in notification_type.h as
// the enum type _notification_property.
NotificationProperty._();

/// Disable application launch when notification is selected.
static const int disableAppLaunch = 1 << 1;
/// Display only if a SIM card is inserted.
static const int onlySimMode = 0x00000001;

/// Disable auto delete when notification is selected.
static const int disableAutoDelete = 1 << 2;
/// Do not perform any operation when the notification is clicked.
static const int disableAppLaunch = 0x00000002;

/// Delete notification when device is rebooted.
static const int volatileDisplay = 1 << 8;
/// Do not dismiss the notification when clicked.
static const int disableAutoDelete = 0x00000004;

/// Dismiss the notification when the device is rebooted.
static const int volatile = 0x00000100;
}

/// The destination app that displays notification.
class DisplayApplist {
/// Notification Tray(Quickpanel).
static const int tray = 1 << 0;
/// Where and how the notification should be presented.
class NotificationStyle {
// The constants below are originally defined in notification_type.h as
// the enum type _notification_display_applist.
NotificationStyle._();

/// Ticker notification.
static const int ticker = 1 << 1;
/// Display in the notification area of the quick panel.
static const int tray = 0x00000001;

/// Lock screen.
static const int lock = 1 << 2;
/// Display in the lock screen.
static const int lock = 0x00000004;

/// Indicator.
static const int indicator = 1 << 3;
/// Display in the indicator area (the top of the screen).
static const int indicator = 0x00000002 | 0x00000008;

/// All display application.
static const int all = (1 << 4) - 1;
/// All of the above.
static const int all = tray | lock | indicator;
}

class NotificationImage {
/// [NotificationImage] specifies image options for notifications.
NotificationImage({
this.iconPath,
this.indicatorPath,
this.lockPath,
/// A set of icons to be shown in the notification layouts.
class NotificationIcons {
/// Creates a [NotificationIcons] with the given icon paths.
NotificationIcons({
this.icon,
this.indicatorIcon,
this.lockIcon,
});

/// The path of icon.
final String? iconPath;
/// The path to the icon file.
String? icon;

/// The path of indicator icon.
final String? indicatorPath;
/// The path to the indicator icon file.
String? indicatorIcon;

/// The path of lock screen icon.
final String? lockPath;
/// The path to the lock screen icon file.
String? lockIcon;

/// Returns [NotificationImage] member fields in a map format.
Map<String, dynamic> toMap() => <String, dynamic>{
'icon': iconPath,
'iconForIndicator': indicatorPath,
'iconForLock': lockPath,
/// Converts to a map.
Map<String, String?> toMap() => <String, String?>{
'icon': icon,
'iconForIndicator': indicatorIcon,
'iconForLock': lockIcon,
};
}

/// The type of sound.
enum SoundType {
/// No sound.
none,

/// Default sound.
builtIn,

/// User sound data.
userData,
}

/// The sound to play when the notification is presented.
class NotificationSound {
/// [NotificationSound] specifies sound options for notifications.
///
/// [path] refers to a file path to custom sound data played on notification,
/// this value is ignored When [type] is not [SoundType.userData].
NotificationSound({
required this.type,
this.path,
});
/// Creates a [NotificationSound] with the given [type] and [path].
NotificationSound({required this.type, this.path});

/// The type of sound.
SoundType type;

final SoundType type;
/// The path to the user sound data file.
///
/// Only applicable if the [type] is [SoundType.userData].
String? path;

/// Returns [NotificationSound] member fields in a map format.
Map<String, dynamic> toMap() => <String, dynamic>{
/// Converts to a map.
Map<String, String?> toMap() => <String, String?>{
'type': type.name,
'path': path,
};
}

/// The type of vibration.
enum VibrationType {
/// No vibration.
none,

/// Default vibration pattern.
builtIn,

/// User vibration data.
userData,
}

/// The notification vibration options.
class NotificationVibration {
/// [NotificationVibration] specifies vibration options for notifications.
NotificationVibration({
required this.type,
this.path,
});
/// Creates a [NotificationVibration] with the given [type] and [path].
NotificationVibration({required this.type, this.path});

final VibrationType type;
/// The type of vibration.
VibrationType type;

/// The path to the user vibration data file.
///
/// Only applicable if the [type] is [VibrationType.userData].
String? path;

/// Returns [NotificationVibration] member fields in a map format.
Map<String, dynamic> toMap() => <String, dynamic>{
/// Converts to a map.
Map<String, String?> toMap() => <String, String?>{
'type': type.name,
bbrto21 marked this conversation as resolved.
Show resolved Hide resolved
'path': path,
};
}

extension _AppControlToMap on AppControl {
/// Converts to a map.
Map<String, Object?> toMap() => <String, Object?>{
'appId': appId,
'operation': operation,
'uri': uri,
'mime': mime,
'extraData': extraData,
};
}

/// The notification details.
class TizenNotificationDetails {
/// Constructs a [TizenNotificationDetails] from the given properties.
TizenNotificationDetails({
this.icons,
this.sound,
this.vibration,
this.properties = 0,
this.style = NotificationStyle.all,
this.ongoing = false,
this.appControl,
});

/// A set of icons to be shown in the notification layouts.
NotificationIcons? icons;

/// The sound to play when the notification is presented.
NotificationSound? sound;

/// The notification vibration options.
NotificationVibration? vibration;

/// Specifies how the system handles the notification in certain scenarios.
///
/// Multiple [NotificationProperty] values can be set using the bitwise OR
/// operator (|).
int properties;

/// Specifies where and how the notification should be presented.
///
/// Multiple [NotificationStyle] values can be set using the bitwise OR
/// operator (|).
int style;

/// Whether the notification can be dismissed by user.
///
/// Only supported on Raspberry Pi (common profile) devices.
bool ongoing;

/// A control message to be sent when the notification is clicked.
AppControl? appControl;

/// Converts to a map.
Map<String, Object?> toMap() => <String, Object?>{
'image': icons?.toMap(),
'sound': sound?.toMap(),
'vibration': vibration?.toMap(),
'properties': properties,
'displayApplist': style,
'ongoing': ongoing,
'appControl': appControl?.toMap(),
};
}
Loading