@@ -40,6 +40,17 @@ class FeedbackManager {
40
40
kUnknownError
41
41
};
42
42
43
+ enum class FeedbackPattern {
44
+ kClick = FEEDBACK_PATTERN_TAP,
45
+ kAlert = FEEDBACK_PATTERN_GENERAL,
46
+ kSip = FEEDBACK_PATTERN_SIP
47
+ };
48
+
49
+ enum class FeedbackType {
50
+ kVibration = FEEDBACK_TYPE_VIBRATION,
51
+ kSound = FEEDBACK_TYPE_SOUND
52
+ };
53
+
43
54
static std::string GetVibrateVariantName (const char * haptic_feedback_type) {
44
55
FT_LOGD (
45
56
" Enter FeedbackManager::GetVibrateVariantName(): haptic_feedback_type: "
@@ -60,30 +71,32 @@ class FeedbackManager {
60
71
std::string{haptic_feedback_type + kPrefixToRemoveLen };
61
72
}
62
73
63
- static std::string GetErrorMessage (const std::string& method_name,
64
- ResultCode result_code) {
74
+ static std::string GetErrorMessage (ResultCode result_code,
75
+ const std::string& method_name,
76
+ const std::string& args = " " ) {
65
77
FT_LOGD (
66
- " Enter FeedbackManager::GetErrorMessage(): method_name: (%s), "
67
- " result_code: [%d]" ,
68
- method_name.c_str (), static_cast <int >(result_code));
78
+ " Enter FeedbackManager::GetErrorMessage(): result_code: [%d], "
79
+ " method_name: (%s), args: (%s)" ,
80
+ static_cast <int >(result_code), method_name.c_str (), args.c_str ());
81
+
82
+ const auto method_name_with_args = method_name + " (" + args + " )" ;
69
83
70
84
switch (result_code) {
71
85
case ResultCode::kNotSupportedError :
72
- return method_name + " () is not supported" ;
86
+ return method_name_with_args + " is not supported" ;
73
87
case ResultCode::kPermissionDeniedError :
74
- return std::string{" No permission to run " } + method_name +
75
- " () . Add "
88
+ return std::string{" No permission to run " } + method_name_with_args +
89
+ " . Add "
76
90
" \" http://tizen.org/privilege/feedback\" privilege to "
77
91
" tizen-manifest.xml "
78
92
" to use this method" ;
79
93
case ResultCode::kUnknownError :
80
94
default :
81
- return std::string{" An unknown error on " } + method_name + " () call" ;
95
+ return std::string{" An unknown error on " } + method_name_with_args +
96
+ " call" ;
82
97
}
83
98
}
84
99
85
- #if defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
86
-
87
100
static FeedbackManager& GetInstance () {
88
101
FT_LOGD (" Enter FeedbackManager::GetInstance()" );
89
102
@@ -94,17 +107,18 @@ class FeedbackManager {
94
107
FeedbackManager (const FeedbackManager&) = delete ;
95
108
FeedbackManager& operator =(const FeedbackManager&) = delete ;
96
109
97
- ResultCode Vibrate () {
98
- FT_LOGD (" Enter FeedbackManager::Vibrate()" );
110
+ ResultCode Play (FeedbackType type, FeedbackPattern pattern) {
111
+ FT_LOGD (" Enter FeedbackManager::Play(): type: [%d], pattern: [%d]" ,
112
+ static_cast <int >(type), static_cast <int >(pattern));
99
113
100
114
if (ResultCode::kOk != initialization_status_) {
101
- FT_LOGE (" Cannot run Vibrate (): initialization_status_: [%d]" ,
115
+ FT_LOGE (" Cannot run Play (): initialization_status_: [%d]" ,
102
116
static_cast <int >(initialization_status_));
103
117
return initialization_status_;
104
118
}
105
119
106
- auto ret =
107
- feedback_play_type (FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_SIP );
120
+ auto ret = feedback_play_type ( static_cast <feedback_type_e>(type),
121
+ static_cast <feedback_pattern_e>(pattern) );
108
122
if (FEEDBACK_ERROR_NONE == ret) {
109
123
FT_LOGD (" feedback_play_type() succeeded" );
110
124
return ResultCode::kOk ;
@@ -163,8 +177,6 @@ class FeedbackManager {
163
177
}
164
178
165
179
ResultCode initialization_status_ = ResultCode::kUnknownError ;
166
-
167
- #endif // defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
168
180
};
169
181
170
182
} // namespace
@@ -178,13 +190,32 @@ void PlatformChannel::HandleMethodCall(
178
190
ui_app_exit ();
179
191
result->Success ();
180
192
} else if (method == " SystemSound.play" ) {
181
- result->NotImplemented ();
193
+ FT_LOGD (" SystemSound.play() call received" );
194
+
195
+ const std::string pattern_str = call.arguments ()[0 ].GetString ();
196
+
197
+ const FeedbackManager::FeedbackPattern pattern =
198
+ (pattern_str == " SystemSoundType.click" )
199
+ ? FeedbackManager::FeedbackPattern::kClick
200
+ : FeedbackManager::FeedbackPattern::kAlert ;
201
+
202
+ auto ret = FeedbackManager::GetInstance ().Play (
203
+ FeedbackManager::FeedbackType::kSound , pattern);
204
+ if (FeedbackManager::ResultCode::kOk == ret) {
205
+ result->Success ();
206
+ return ;
207
+ }
208
+
209
+ const auto error_cause =
210
+ FeedbackManager::GetErrorMessage (ret, " SystemSound.play" , pattern_str);
211
+ const std::string error_message = " Could not play sound" ;
212
+ FT_LOGE (" %s: %s" , error_cause.c_str (), error_message.c_str ());
213
+
214
+ result->Error (error_cause, error_message);
215
+
182
216
} else if (method == " HapticFeedback.vibrate" ) {
183
217
FT_LOGD (" HapticFeedback.vibrate() call received" );
184
218
185
- const std::string error_message = " Could not vibrate" ;
186
-
187
- #if defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
188
219
/*
189
220
* We use a single type of vibration (FEEDBACK_PATTERN_SIP) to implement
190
221
* HapticFeedback's vibrate, lightImpact, mediumImpact, heavyImpact
@@ -194,7 +225,9 @@ void PlatformChannel::HandleMethodCall(
194
225
* calls.
195
226
*/
196
227
197
- auto ret = FeedbackManager::GetInstance ().Vibrate ();
228
+ auto ret = FeedbackManager::GetInstance ().Play (
229
+ FeedbackManager::FeedbackType::kVibration ,
230
+ FeedbackManager::FeedbackPattern::kSip );
198
231
if (FeedbackManager::ResultCode::kOk == ret) {
199
232
result->Success ();
200
233
return ;
@@ -203,14 +236,10 @@ void PlatformChannel::HandleMethodCall(
203
236
const auto vibrate_variant_name =
204
237
FeedbackManager::GetVibrateVariantName (call.arguments ()[0 ].GetString ());
205
238
const auto error_cause =
206
- FeedbackManager::GetErrorMessage (vibrate_variant_name, ret);
239
+ FeedbackManager::GetErrorMessage (ret, vibrate_variant_name);
240
+ const std::string error_message = " Could not vibrate" ;
241
+
207
242
FT_LOGE (" %s: %s" , error_cause.c_str (), error_message.c_str ());
208
- #else
209
- const auto vibrate_variant_name =
210
- FeedbackManager::GetVibrateVariantName (call.arguments ()[0 ].GetString ());
211
- const auto error_cause = FeedbackManager::GetErrorMessage (
212
- vibrate_variant_name, FeedbackManager::ResultCode::kNotSupportedError );
213
- #endif // defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
214
243
215
244
result->Error (error_cause, error_message);
216
245
} else if (method == " Clipboard.getData" ) {
0 commit comments