1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 /// @file Activator.java
23 package oic.plugin.gear.noti;
25 import java.util.EnumSet;
26 import java.util.UUID;
28 import org.iotivity.base.ModeType;
29 import org.iotivity.base.ObserveType;
30 import org.iotivity.base.OcPlatform;
31 import org.iotivity.base.OcResource;
32 import org.iotivity.base.OcResourceHandle;
33 import org.iotivity.base.PlatformConfig;
34 import org.iotivity.base.QualityOfService;
35 import org.iotivity.base.ResourceProperty;
36 import org.iotivity.base.ServiceType;
37 import org.osgi.framework.BundleActivator;
38 import org.osgi.framework.BundleContext;
39 import org.osgi.framework.ServiceReference;
41 import android.app.Activity;
42 import android.content.Context;
43 import android.util.Log;
45 import com.samsung.android.sdk.SsdkUnsupportedException;
46 import com.samsung.android.sdk.richnotification.Srn;
47 import com.samsung.android.sdk.richnotification.SrnRichNotification;
48 import com.samsung.android.sdk.richnotification.SrnRichNotificationManager;
49 import com.samsung.android.sdk.richnotification.SrnRichNotificationManager.ErrorType;
50 import com.samsung.android.sdk.richnotification.SrnRichNotificationManager.EventListener;
52 public class Activator extends Activity implements BundleActivator,
55 final private static String TAG = "GearNoti";
57 public enum TemplateTypes {
61 private static BundleContext context;
62 public static Context AppContext;
63 public static SrnRichNotificationManager mRichNotificationManager;
66 public String m_power;
71 m_name = "device.notify";
75 static int OBSERVE_TYPE_TO_USE = ObserveType.OBSERVE
78 public static Notify myNotify;
79 public static OcResource curResource;
80 public static OcResourceHandle resourceHandle;
82 static Activity mActivity;
84 static BundleContext getContext() {
88 public void start(BundleContext bundleContext) throws Exception {
89 Activator.context = bundleContext;
91 ServiceReference<Context> ref = Activator.context
92 .getServiceReference(Context.class);
93 AppContext = Activator.context.getService(ref);
95 myNotify = new Notify();
99 // Initializes an instance of Srn.
100 srn.initialize(AppContext);
101 Log.w(TAG, "SRN initialized");
102 } catch (SsdkUnsupportedException e) {
103 Log.w(TAG, "SsdkUnsupportedException");
106 mRichNotificationManager = new SrnRichNotificationManager(AppContext);
108 if (mRichNotificationManager.isConnected()) {
109 // Starts the manager.
110 mRichNotificationManager.start();
111 Log.w(TAG, "RichNoti Manager Started");
113 SrnRichNotification myRichNotification = new SrnRichNotification(
115 Log.w(TAG, "RichNoti instance created");
117 PlatformConfig cfg = new PlatformConfig(this, ServiceType.IN_PROC,
118 ModeType.CLIENT_SERVER, "0.0.0.0", 0, QualityOfService.LOW);
120 OcPlatform.Configure(cfg);
122 EntityHandlerNoti entitycb = new EntityHandlerNoti();
124 resourceHandle = OcPlatform.registerResource("/a/galaxy/gear",
125 "device.notify", OcPlatform.DEFAULT_INTERFACE, entitycb,
126 EnumSet.of(ResourceProperty.DISCOVERABLE));
129 Log.w(TAG, "Something Happened");
134 protected void onResume() {
136 mRichNotificationManager.registerRichNotificationListener(this);
140 protected void onPause() {
142 mRichNotificationManager.unregisterRichNotificationListener(this);
146 public void onError(UUID arg0, ErrorType arg1) {
147 // TODO Auto-generated method stub
152 public void onRead(UUID arg0) {
153 // TODO Auto-generated method stub
158 public void onRemoved(UUID arg0) {
159 // TODO Auto-generated method stub
164 public void stop(BundleContext arg0) throws Exception {
165 // TODO Auto-generated method stub
166 OcPlatform.unregisterResource(resourceHandle);
168 mRichNotificationManager = null;