2 * Copyright (c) 2019 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.
18 using System.Threading.Tasks;
20 namespace Tizen.Applications.ComponentBased.Common
23 /// This is a base-component class.
24 /// It provides common functions of FrameComponent and ServiceComponent.
27 /// This class cannot be registered by ComponentBased applications.
29 /// <since_tizen> 6 </since_tizen>
30 public abstract class BaseComponent
32 internal IntPtr Handle;
35 /// Occurs when the system memory is low.
37 /// <since_tizen> 6 </since_tizen>
38 public event EventHandler<LowMemoryEventArgs> LowMemory;
41 /// Occurs when the system battery is low.
43 /// <since_tizen> 6 </since_tizen>
44 public event EventHandler<LowBatteryEventArgs> LowBattery;
47 /// Occurs when the system language is chagned.
49 /// <since_tizen> 6 </since_tizen>
50 public event EventHandler<LocaleChangedEventArgs> LocaleChanged;
53 /// Occurs when the region format is changed.
55 /// <since_tizen> 6 </since_tizen>
56 public event EventHandler<RegionFormatChangedEventArgs> RegionFormatChanged;
59 /// Occurs when the device orientation is changed.
61 /// <since_tizen> 6 </since_tizen>
62 public event EventHandler<DeviceOrientationEventArgs> DeviceOrientationChanged;
65 /// Occurs when the device orientation is changed.
67 /// <since_tizen> 6 </since_tizen>
68 public event EventHandler<SuspendedStateEventArgs> SuspendedStateChanged;
71 /// A component instance ID.
72 /// It will be created after OnCreate method is invoked.
74 /// <since_tizen> 6 </since_tizen>
75 public string Id { get; private set; }
80 /// <since_tizen> 6 </since_tizen>
81 public string ComponentId { get; private set; }
86 /// <since_tizen> 6 </since_tizen>
87 public ComponentBasedApplication Parent { get; private set; }
90 /// Finish current component
92 /// <since_tizen> 6 </since_tizen>
95 Interop.CBApplication.ComponentFinish(Handle);
98 internal void Bind(IntPtr handle, string compId, string instanceId, ComponentBasedApplication parent)
102 ComponentId = compId;
107 /// Overrides this method if want to handle behavior to restore the previous status.
109 /// <param name="c">Contents. It can be used only in the callback. To use outside, make a copy. </param>
110 /// <since_tizen> 6 </since_tizen>
111 public virtual void OnRestoreContents(Bundle c)
116 /// Overrides this method if want to handle behavior to save current status.
118 /// <param name="c">Contents. It can be used only in the callback. To use outside, make a copy. </param>
119 /// <since_tizen> 6 </since_tizen>
120 public virtual void OnSaveContent(Bundle c)
124 internal void OnLanguageChangedCallback(string language)
126 LocaleChanged?.Invoke(this, new LocaleChangedEventArgs(language));
129 internal void OnDeviceOrientationChangedCallback(int orientation)
131 DeviceOrientationChanged?.Invoke(this, new DeviceOrientationEventArgs((DeviceOrientation)orientation));
134 internal void OnLowBatteryCallback(int status)
136 LowBattery?.Invoke(this, new LowBatteryEventArgs((LowBatteryStatus)status));
139 internal void OnLowMemoryCallback(int status)
141 LowMemory?.Invoke(this, new LowMemoryEventArgs((LowMemoryStatus)status));
144 internal void OnRegionFormatChangedCallback(string region)
146 RegionFormatChanged?.Invoke(this, new RegionFormatChangedEventArgs(region));
149 internal void OnSuspendedStateCallback(int state)
151 SuspendedStateChanged?.Invoke(this, new SuspendedStateEventArgs((SuspendedState)state));
155 /// Sends the launch request asynchronously.
158 /// To use group mode, you must use this function instead of SendLaunchRequestAsync().
160 /// <param name="control">appcontrol object</param>
161 /// <param name="replyAfterLaunching">The callback function to be called when the reply is delivered.</param>
162 /// <returns>A task with the result of the launch request.</returns>
163 /// <exception cref="ArgumentException">Thrown when failed because of the argument is invalid.</exception>
164 /// <exception cref="InvalidOperationException">Thrown when fail to set component information to the AppControl.</exception>
165 /// <exception cref="Exceptions.AppNotFoundException">Thrown when the application to run is not found.</exception>
166 /// <exception cref="Exceptions.LaunchRejectedException">Thrown when the launch request is rejected.</exception>
167 /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
168 /// <since_tizen> 6 </since_tizen>
169 public Task<AppControlResult> SendLaunchRequestAsync(AppControl control, AppControlReplyCallback replyAfterLaunching)
171 int ret = Interop.AppControl.SetCallerInstanceId(control.SafeAppControlHandle, Id);
173 throw new InvalidOperationException("Failed to set id");
175 return AppControl.SendLaunchRequestAsync(control, replyAfterLaunching);