2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.System
22 /// Class for event arguments of the media key.
24 public class MediaKeyEventArgs : EventArgs
27 /// Enumeration for Key value.
29 /// <since_tizen>3</since_tizen>
73 /// Media key for earjack.
84 /// Enumeration for Key status.
86 /// <since_tizen>3</since_tizen>
108 /// <since_tizen>3</since_tizen>
109 public KeyValue Value { get; internal set; }
114 /// <since_tizen>3</since_tizen>
115 public KeyStatus Status { get; internal set; }
119 /// Class for receiving events of media keys.
121 public static class MediaKey
123 private static EventHandler<MediaKeyEventArgs> s_eventHandler;
124 private static Interop.MediaKey.EventCallback s_callback;
126 private static void OnEvent(Interop.MediaKey.KeyValue value, Interop.MediaKey.KeyStatus status, IntPtr userData)
128 s_eventHandler?.Invoke(null, new MediaKeyEventArgs()
130 Value = (MediaKeyEventArgs.KeyValue)value,
131 Status = (MediaKeyEventArgs.KeyStatus)status
136 /// Adds or removes events for all media keys.
138 /// <since_tizen>3</since_tizen>
139 /// <exception cref="InvalidOperationException">Failed to reserve or release key.</exception>
140 public static event EventHandler<MediaKeyEventArgs> Event
144 if (s_eventHandler == null)
146 if (s_callback == null)
147 s_callback = new Interop.MediaKey.EventCallback(OnEvent);
148 Interop.MediaKey.ErrorCode err = Interop.MediaKey.Reserve(s_callback, IntPtr.Zero);
150 if (err != Interop.MediaKey.ErrorCode.None)
152 throw new InvalidOperationException("Failed to reserve key. err = " + err);
156 s_eventHandler += value;
161 s_eventHandler -= value;
162 if (s_eventHandler == null)
164 Interop.MediaKey.ErrorCode err = Interop.MediaKey.Release();
166 if (err != Interop.MediaKey.ErrorCode.None)
168 throw new InvalidOperationException("Failed to release key. err = " + err);