Updated Android Sample App for Notification provider.
authornikhil.a <nikhil.a7@samsung.com>
Mon, 19 Sep 2016 06:59:09 +0000 (12:29 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 20 Sep 2016 10:49:37 +0000 (10:49 +0000)
1) Added option to start provider service with different acceptors.
2) Added registerTopic and setTopic option.
3) Updated UI.

Change-Id: I8373173a9d9274b458e3c15680831ada91b30fee
Signed-off-by: nikhil.a <nikhil.a7@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11907
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/notification/examples/android/NotiProviderExample/app/build.gradle
service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java
service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/NotiListener.java
service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderSample.java [moved from service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java with 81% similarity, mode: 0644]
service/notification/examples/android/NotiProviderExample/app/src/main/res/layout/activity_main.xml
service/notification/examples/android/NotiProviderExample/app/src/main/res/values/strings.xml
service/notification/examples/android/NotiProviderExample/app/src/test/java/com/sec/notiproviderexample/ExampleUnitTest.java [deleted file]
service/notification/examples/android/NotiProviderExample/iotivity-armeabi-notification-service-debug/build.gradle [deleted file]
service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-debug/build.gradle [deleted file]
service/notification/examples/android/NotiProviderExample/settings.gradle

index c20792d..38ea4c4 100644 (file)
@@ -16,6 +16,4 @@ android {
 dependencies {\r
     compile fileTree(include: ['*.jar'], dir: 'libs')\r
     compile 'com.android.support:appcompat-v7:23.0.1'\r
-    compile project(':iotivity-armeabi-notification-service-debug')\r
-    compile project(':iotivity-base-armeabi-debug')\r
 }\r
index a5072f6..c9d821c 100755 (executable)
@@ -25,7 +25,6 @@ package com.sec.notiproviderexample;
 import android.app.Notification;\r
 import android.app.NotificationManager;\r
 import android.content.Intent;\r
-import android.content.SyncInfo;\r
 import android.os.Bundle;\r
 import android.os.Handler;\r
 import android.os.Message;\r
@@ -34,10 +33,15 @@ import android.util.Log;
 import android.view.View;\r
 import android.widget.Button;\r
 import android.widget.EditText;\r
+import android.widget.RadioButton;\r
 import android.widget.TextView;\r
 import android.widget.Toast;\r
 \r
 import org.iotivity.service.ns.common.MediaContents;\r
+\r
+import java.text.DateFormat;\r
+import java.util.Date;\r
+\r
 public class MainActivity extends AppCompatActivity {\r
 \r
     private final String TAG = "NS_MAIN_ACTIVITY";\r
@@ -47,22 +51,28 @@ public class MainActivity extends AppCompatActivity {
 \r
     private Button btnTitle;\r
     private Button btnBody;\r
+    private Button btnTopic;\r
     private Button btnSend;\r
     private Button btnStart;\r
+    private Button btnRegister;\r
+    private Button btnSet;\r
     private Button btnStop;\r
-    private Button btnAccept;\r
-    private Button btnSync;\r
+    private Button btnLog;\r
     private EditText editTextTitle;\r
     private EditText editTextBody;\r
+    private EditText editTextTopic;\r
+    private RadioButton radioProvider;\r
+    private RadioButton radioConsumer;\r
     private static TextView TvLog;\r
 \r
     private static int notiId = 100;\r
     private static int subCnt = 0;\r
     private boolean isStarted = false;\r
     private String consumerId;\r
+    private boolean gAcceptor = true;\r
 \r
     private NotiListener mNotiListener = null;\r
-    private ProviderProxy mProviderProxy = null;\r
+    private ProviderSample mProviderSample = null;\r
 \r
     public static Handler mHandler = new Handler() {\r
         @Override\r
@@ -103,35 +113,39 @@ public class MainActivity extends AppCompatActivity {
 \r
         btnTitle = (Button) findViewById(R.id.BtnTitle);\r
         btnBody = (Button) findViewById(R.id.BtnBody);\r
+        btnTopic = (Button) findViewById(R.id.BtnTopic);\r
         btnSend = (Button) findViewById(R.id.BtnCreateNoti);\r
 \r
         btnStart = (Button) findViewById(R.id.BtnStart);\r
-        btnAccept = (Button) findViewById(R.id.BtnAccept);\r
-        btnSync = (Button) findViewById(R.id.BtnSync);\r
+        btnRegister = (Button) findViewById(R.id.BtnRegister);\r
+        btnSet = (Button) findViewById(R.id.BtnSet);\r
+        btnLog = (Button) findViewById(R.id.BtnLog);\r
         btnStop = (Button) findViewById(R.id.BtnStop);\r
 \r
         editTextTitle = (EditText) findViewById(R.id.EditTextTitle);\r
         editTextBody = (EditText) findViewById(R.id.EditTextBody);\r
+        editTextTopic = (EditText) findViewById(R.id.EditTextTopic);\r
+\r
+        radioProvider = (RadioButton) findViewById(R.id.RadioProvider);\r
+        radioConsumer = (RadioButton) findViewById(R.id.RadioConsumer);\r
 \r
         TvLog = (TextView) findViewById(R.id.TvLog);\r
 \r
         btnTitle.setEnabled(false);\r
         btnBody.setEnabled(false);\r
+        btnTopic.setEnabled(false);\r
 \r
         btnSend.setOnClickListener(mClickListener);\r
-\r
         btnStart.setOnClickListener(mClickListener);\r
-\r
-        btnAccept.setOnClickListener(mClickListener);\r
-        btnAccept.setVisibility(View.INVISIBLE);\r
-\r
-        btnSync.setOnClickListener(mClickListener);\r
-        btnSync.setVisibility(View.INVISIBLE);\r
-\r
+        btnRegister.setOnClickListener(mClickListener);\r
+        btnSet.setOnClickListener(mClickListener);\r
+        btnLog.setOnClickListener(mClickListener);\r
         btnStop.setOnClickListener(mClickListener);\r
+        radioProvider.setOnClickListener(mClickListener);\r
+        radioConsumer.setOnClickListener(mClickListener);\r
 \r
-        mProviderProxy = new ProviderProxy(getApplicationContext());\r
-        mProviderProxy.setHandler(mHandler);\r
+        mProviderSample = new ProviderSample(getApplicationContext());\r
+        mProviderSample.setHandler(mHandler);\r
 \r
         mNotiListener = new NotiListener(this);\r
 \r
@@ -144,36 +158,80 @@ public class MainActivity extends AppCompatActivity {
         super.onDestroy();\r
     }\r
 \r
-    public ProviderProxy getProviderProxy()\r
+    public ProviderSample getProviderSample()\r
     {\r
-        return mProviderProxy;\r
+        return mProviderSample;\r
     }\r
 \r
     Button.OnClickListener mClickListener = new View.OnClickListener() {\r
         public void onClick(View v) {\r
             switch (v.getId()) {\r
-\r
-                case R.id.BtnStart: {\r
+                case R.id.RadioProvider: {\r
                     if (isStarted == false) {\r
-                        Log.i(TAG, "Start NS Provider Service");\r
+                        gAcceptor = true;\r
+                        showToast("Provider as acceptor is " + gAcceptor);\r
+                    }\r
+                    else\r
+                        showToast("Start ProviderService again to change acceptor as provider");\r
+                }\r
+                break;\r
 \r
-                        TvLog.setText("Start NS-Provider\n");\r
+                case R.id.RadioConsumer: {\r
+                    if (isStarted == false) {\r
+                        gAcceptor = false;\r
+                        showToast("Provider as acceptor is "+ gAcceptor);\r
+                    }\r
+                    else\r
+                        showToast("Start ProviderService again to change acceptor as consumer");\r
+                }\r
+                break;\r
 \r
-                        boolean policy = true; // provider controls the acceptance of consumers\r
-                        mProviderProxy.Start(policy);\r
+                case R.id.BtnStart: {\r
+                    if (isStarted == false) {\r
+                        Log.i(TAG, "Start  Provider Service");\r
+                        TvLog.setText("Start Provider Service\n");\r
+                        mProviderSample.Start(gAcceptor);\r
                         isStarted = true;\r
+                        radioProvider.setEnabled(false);\r
+                        radioConsumer.setEnabled(false);\r
                     } else {\r
-                        Log.e(TAG, "NS Provider Service had already started");\r
+                        Log.e(TAG, " Provider Service had already started");\r
+                        showToast(" Provider Service had already started");\r
                     }\r
                 }\r
                 break;\r
 \r
-                case R.id.BtnAccept: {\r
-                    if(isStarted == false)\r
-                    {\r
-                        Log.e(TAG, "Fail to request Accept");\r
+                case R.id.BtnRegister: {\r
+                    if (isStarted == false) {\r
+                        Log.i(TAG, "Start  Provider Service");\r
+                        TvLog.append("Register Topic : OCF_TOPIC1\n");\r
+                        TvLog.append("Register Topic : OCF_TOPIC2\n");\r
+                        TvLog.append("Register Topic : OCF_TOPIC3\n");\r
+                        TvLog.append("Register Topic : OCF_TOPIC4\n");\r
+                        showToast("Start Provider Service First");\r
                         break;\r
                     }\r
+                    mProviderSample.RegisterTopic();\r
+\r
+                }\r
+                break;\r
+\r
+                case R.id.BtnSet: {\r
+                    if (isStarted == false) {\r
+                        Log.i(TAG, "Start Provider Service");\r
+                        TvLog.append("Set Topic : OCF_TOPIC1\n");\r
+                        TvLog.append("Set Topic : OCF_TOPIC2\n");\r
+                        TvLog.append("Set Topic : OCF_TOPIC3\n");\r
+                        TvLog.append("Set Topic : OCF_TOPIC4\n");\r
+                        showToast("Start Provider Service First");\r
+                        break;\r
+                    }\r
+                    if(gAcceptor == false){\r
+                        showToast("Operation Not Permitted: \nStart Provider Service with provider as acceptor");\r
+                        break;\r
+                    }\r
+                    mProviderSample.SetTopic();\r
+\r
                 }\r
                 break;\r
 \r
@@ -182,10 +240,12 @@ public class MainActivity extends AppCompatActivity {
                     String id = Integer.toString(notiId); // generate notificaion ID\r
                     String title = editTextTitle.getText().toString();\r
                     String body = editTextBody.getText().toString();\r
+                    String topic  = editTextTopic.getText().toString();\r
 \r
                     if(isStarted == false)\r
                     {\r
                         Log.e(TAG, "Fail to send NSMessage");\r
+                        showToast("Start ProviderService First");\r
                         break;\r
                     }\r
 \r
@@ -202,41 +262,38 @@ public class MainActivity extends AppCompatActivity {
                     Log.i(TAG, "#" + notiId + " notified ..");\r
                     TvLog.append("Send Notitication(Msg ID: " + notiId + ")\n");\r
                     notiId++;\r
-                    org.iotivity.service.ns.common.Message notiMessage = new org.iotivity.service.ns.common.Message(title,body,"dss");\r
+                    org.iotivity.service.ns.common.Message notiMessage = new org.iotivity.service.ns.common.Message(title,body,"provider");\r
                     notiMessage.setTTL(10);\r
-                    notiMessage.setTime("12:10");\r
-                    MediaContents media = new MediaContents("daasd");\r
+                    notiMessage.setTime(DateFormat.getDateTimeInstance().format(new Date()));\r
+                    notiMessage.setTopic(topic);\r
+                    MediaContents media = new MediaContents("Video");\r
                     notiMessage.setMediaContents(media);\r
-                    mProviderProxy.SendMessage(notiMessage);\r
-                }\r
-                break;\r
-\r
-                case R.id.BtnSync: {\r
-                    if(isStarted == false)\r
-                    {\r
-                        Log.e(TAG, "Fail to send sync");\r
-                        break;\r
-                    }\r
-                    org.iotivity.service.ns.common.SyncInfo.SyncType syncType =  org.iotivity.service.ns.common.SyncInfo.SyncType.READ;\r
-                    mProviderProxy.SendSyncInfo(1,syncType);\r
+                    mProviderSample.SendMessage(notiMessage);\r
                 }\r
                 break;\r
 \r
                 case R.id.BtnStop: {\r
-                    if(isStarted == false)\r
-                    {\r
+                    if(isStarted == false) {\r
                         Log.e(TAG, "Fail to stop service");\r
+                        showToast("Already Stopped");\r
                         break;\r
                     }\r
 \r
-                    mProviderProxy.Stop();\r
+                    mProviderSample.Stop();\r
                     isStarted = false;\r
-\r
-                    TvLog.append("Stop NS-Provider\n");\r
+                    radioProvider.setEnabled(true);\r
+                    radioConsumer.setEnabled(true);\r
+                    showToast("Stopped ProviderService"+ isStarted);\r
+                    TvLog.append("Stop Provider Service\n");\r
                 }\r
                 break;\r
+\r
+                case R.id.BtnLog: {\r
+\r
+                    TvLog.setText("");\r
+                }\r
+                break;  }\r
             }\r
-        }\r
     };\r
 }\r
 \r
index d68560b..27c7c7c 100755 (executable)
@@ -23,7 +23,6 @@
 package com.sec.notiproviderexample;\r
 \r
 import android.app.Notification;\r
-import android.content.SyncInfo;\r
 import android.os.Bundle;\r
 import android.service.notification.NotificationListenerService;\r
 import android.service.notification.StatusBarNotification;\r
@@ -35,7 +34,7 @@ import java.util.ArrayList;
 public class NotiListener extends NotificationListenerService {\r
 \r
     private final String TAG = "NS_JNI_NOTI_LISTENER";\r
-    private static ProviderProxy mProviderProxy = null;\r
+    private static ProviderSample mProviderSample = null;\r
     private MainActivity mActivity = null;\r
     ArrayList mBlackSourceList = new ArrayList<String>();\r
 \r
@@ -49,11 +48,11 @@ public class NotiListener extends NotificationListenerService {
         Log.i(TAG, "Create NotiListener with MainActivity");\r
 \r
         this.mActivity = activity;\r
-        this.mProviderProxy = mActivity.getProviderProxy();\r
+        this.mProviderSample = mActivity.getProviderSample();\r
 \r
         setBlackSourceList();\r
 \r
-        if(mProviderProxy == null) {\r
+        if(mProviderSample == null) {\r
             Log.i(TAG, "Fail to get providerProxy instance");\r
         }\r
     }\r
@@ -111,8 +110,8 @@ public class NotiListener extends NotificationListenerService {
         notiMessage.setTime("12:10");\r
         MediaContents media = new MediaContents("daasd");\r
         notiMessage.setMediaContents(media);\r
-        if (mProviderProxy != null) {\r
-            mProviderProxy.SendMessage(notiMessage);\r
+        if (mProviderSample != null) {\r
+            mProviderSample.SendMessage(notiMessage);\r
         } else {\r
             Log.i(TAG, "providerExample is NULL");\r
         }\r
@@ -130,12 +129,12 @@ public class NotiListener extends NotificationListenerService {
         Log.i(TAG, "Noti. Package Name : " + sbn.getPackageName());\r
         Log.i(TAG, "Noti. ID : " + sbn.getId());\r
 \r
-        if(mProviderProxy.getMsgMap().containsKey(sbn.getId()))\r
+        if(mProviderSample.getMsgMap().containsKey(sbn.getId()))\r
         {\r
-            if(mProviderProxy.getMsgMap().get(sbn.getId()) == 2)\r
+            if(mProviderSample.getMsgMap().get(sbn.getId()) == 2)\r
             {\r
                 org.iotivity.service.ns.common.SyncInfo.SyncType type = org.iotivity.service.ns.common.SyncInfo.SyncType.READ;\r
-                mProviderProxy.SendSyncInfo(1,type);\r
+                mProviderSample.SendSyncInfo(1,type);\r
             }\r
         }\r
     }\r
-/*\r
-//******************************************************************\r
-//\r
-// Copyright 2016 Samsung Electronics All Rights Reserved.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the "License");\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-//      http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- */\r
-\r
-package com.sec.notiproviderexample;\r
-\r
-import android.content.Context;\r
-import android.os.*;\r
-import android.util.Log;\r
-import android.widget.Toast;\r
-\r
-import org.iotivity.base.ModeType;\r
-import org.iotivity.base.OcPlatform;\r
-import org.iotivity.base.OcResourceHandle;\r
-import org.iotivity.base.PlatformConfig;\r
-import org.iotivity.base.QualityOfService;\r
-import org.iotivity.base.ServiceType;\r
-import org.iotivity.service.ns.common.Message;\r
-import org.iotivity.service.ns.provider.*;\r
-import org.iotivity.service.ns.common.*;\r
-\r
-\r
-import java.util.HashMap;\r
-\r
-public class ProviderProxy\r
-        implements ProviderService.OnConsumerSubscribedListener, ProviderService.OnMessageSynchronizedListener{\r
-\r
-    private static final String TAG = "NS_PROVIDER_PROXY";\r
-\r
-    private Context mContext = null;\r
-    private OcResourceHandle mResourceHandle;   //resource handle\r
-    private ProviderService ioTNotification = null;\r
-    private HashMap<String, Integer> msgMap;\r
-\r
-    private Handler mHandler = null;\r
-\r
-    private static final int CONSUMER_SUBSCRIBED = 1;\r
-    private static final int MESSAGE_SYNC = 2;\r
-\r
-    private static final int SYNC_READ = 0;\r
-    private static final int SYNC_DISMISS = 1;\r
-    private static final int SYNC_UNREAD = 2;\r
-\r
-    public ProviderProxy(Context context) {\r
-        Log.i(TAG, "Create providerProxy Instance");\r
-\r
-        this.msgMap = new HashMap<>();\r
-        this.mContext = context;\r
-        ioTNotification =  ProviderService.getInstance();\r
-    }\r
-\r
-    public void setHandler(Handler handler)\r
-    {\r
-        this.mHandler = handler;\r
-    }\r
-\r
-    private void configurePlatform() {\r
-\r
-        PlatformConfig platformConfig = new PlatformConfig(\r
-                mContext,\r
-                ServiceType.IN_PROC,\r
-                ModeType.CLIENT_SERVER,\r
-                "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces\r
-                0,         // Uses randomly available port\r
-                QualityOfService.LOW\r
-        );\r
-\r
-        Log.i(TAG, "Configuring platform.");\r
-        OcPlatform.Configure(platformConfig);\r
-        try {\r
-            OcPlatform.stopPresence(); // Initialize OcPlatform\r
-        } catch(Exception e) {\r
-            Log.e(TAG, "Exception: stopping presence when configuration step: " + e);\r
-        }\r
-        Log.i(TAG, "Configuration done Successfully");\r
-    }\r
-\r
-    public void Start(boolean policy)\r
-    {\r
-        Log.i(TAG, "Start ProviderService -IN");\r
-        configurePlatform();\r
-        try{\r
-            int result =  ioTNotification.start(this, this, policy, "Info");\r
-            Log.i(TAG, "Notification Start: " + result);\r
-        }\r
-        catch(Exception e){\r
-\r
-        }\r
-\r
-        Log.i(TAG, "Start ProviderService - OUT");\r
-    }\r
-\r
-    public void Stop() {\r
-        Log.i(TAG, "Stop ProviderService - IN");\r
-        try {\r
-            OcPlatform.stopPresence();\r
-        } catch (Exception e) {\r
-            Log.e(TAG, "Exception: stopping presence when terminating NS server: " + e);\r
-        }\r
-        try{\r
-            int result =  ioTNotification.stop();\r
-            Log.i(TAG, "Notification Stop: " + result);\r
-        }\r
-        catch(Exception e){\r
-\r
-        }\r
-\r
-        Log.i(TAG, "Stop ProviderService - OUT");\r
-    }\r
-\r
-    public void SendMessage(Message notiMessage) {\r
-        Log.i(TAG, "SendMessage ProviderService - IN");\r
-\r
-        try{\r
-            int result =  ioTNotification.sendMessage(notiMessage);\r
-            Log.i(TAG, "Notification Send Message: " + result);\r
-        }\r
-        catch(Exception e){\r
-\r
-        }\r
-\r
-        Log.i(TAG, "SendMessage ProviderService - OUT");\r
-        mHandler.post(new Runnable() {\r
-            @Override\r
-            public void run() {\r
-                Toast.makeText(mContext, "Notification sent", Toast.LENGTH_SHORT).show();\r
-            }\r
-        });\r
-    }\r
-\r
-    public void SendSyncInfo(long messageId, SyncInfo.SyncType syncType) {\r
-        Log.i(TAG, "SendSyncInfo ProviderService - IN");\r
-        if(msgMap.containsKey(messageId)) {\r
-            if(msgMap.get(messageId) == SYNC_UNREAD)\r
-            {\r
-                try{\r
-                    ioTNotification.sendSyncInfo(messageId, syncType);\r
-                    Log.i(TAG, "Notification Sync " );\r
-                }\r
-                catch(Exception e) {\r
-\r
-                }\r
-                Log.i(TAG, "SendSyncInfo ProviderService - OUT");\r
-                msgMap.put("ID: "+messageId, SYNC_READ);\r
-            }\r
-        }\r
-    }\r
-\r
-    public void EnableRemoteService(String servAdd) {\r
-        Log.i(TAG, "EnableRemoteService ProviderService - IN");\r
-        try{\r
-            int result = ioTNotification.enableRemoteService(servAdd);\r
-            Log.i(TAG, "Notification EnableRemoteService: "+ result );\r
-        }\r
-        catch(Exception e) {\r
-\r
-        }\r
-        Log.i(TAG, "EnableRemoteService ProviderService - OUT");\r
-    }\r
-\r
-    public void DisableRemoteService(String servAdd) {\r
-        Log.i(TAG, "DisableRemoteService ProviderService - IN");\r
-        try{\r
-            int result = ioTNotification.disableRemoteService(servAdd);\r
-            Log.i(TAG, "Notification DisableRemoteService: "+ result );\r
-        }\r
-        catch(Exception e) {\r
-\r
-        }\r
-        Log.i(TAG, "DisableRemoteService ProviderService - OUT");\r
-    }\r
-\r
-    public void AcceptSubscription(Consumer consumer, boolean accepted)\r
-    {\r
-        Log.i(TAG,"AcceptSubscription ProviderService - IN");\r
-        try{\r
-            int result = consumer.acceptSubscription(accepted);\r
-            Log.i(TAG, "Notification AcceptSubscription: "+result );\r
-        }\r
-        catch(Exception e) {\r
-\r
-        }\r
-        Log.i(TAG, "AcceptSubscription ProviderService - OUT");\r
-    }\r
-\r
-    @Override\r
-    public void onConsumerSubscribed(Consumer consumer) {\r
-        Log.i(TAG, "onConsumerSubscribed - IN");\r
-        AcceptSubscription(consumer, true);\r
-        android.os.Message msg = mHandler.obtainMessage(CONSUMER_SUBSCRIBED,\r
-                "Consumer Id: " + consumer.getConsumerId()  );\r
-        mHandler.sendMessage(msg);\r
-        Log.i(TAG, "onConsumerSubscribed - OUT");\r
-    }\r
-\r
-    @Override\r
-    public void onMessageSynchronized(SyncInfo syncInfo) {\r
-        Log.i(TAG, "Received SyncInfo with messageID: "+syncInfo.getMessageId());\r
-        android.os.Message msg = mHandler.obtainMessage(MESSAGE_SYNC,\r
-                "Message Id: " + syncInfo.getMessageId()  );\r
-        mHandler.sendMessage(msg);\r
-    }\r
-\r
-    public HashMap<String, Integer> getMsgMap() {\r
-        return msgMap;\r
-    }\r
-}\r
+/*
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package com.sec.notiproviderexample;
+
+import android.content.Context;
+import android.os.*;
+import android.util.Log;
+import android.widget.Toast;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcResourceHandle;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+import org.iotivity.service.ns.common.Message;
+import org.iotivity.service.ns.provider.*;
+import org.iotivity.service.ns.common.*;
+
+
+import java.util.HashMap;
+
+public class ProviderSample
+        implements ProviderService.OnConsumerSubscribedListener, ProviderService.OnMessageSynchronizedListener{
+
+    private static final String TAG = "NS_PROVIDER_PROXY";
+
+    private Context mContext = null;
+    private OcResourceHandle mResourceHandle;   //resource handle
+    private ProviderService ioTNotification = null;
+    private HashMap<String, Integer> msgMap;
+
+    private Handler mHandler = null;
+
+    private static final int CONSUMER_SUBSCRIBED = 1;
+    private static final int MESSAGE_SYNC = 2;
+
+    private static final int SYNC_READ = 0;
+    private static final int SYNC_DISMISS = 1;
+    private static final int SYNC_UNREAD = 2;
+    private boolean gAcceptor;
+    private Consumer gConsumer;
+
+    public ProviderSample(Context context) {
+        Log.i(TAG, "Create providerSample Instance");
+
+        this.msgMap = new HashMap<>();
+        this.mContext = context;
+        ioTNotification =  ProviderService.getInstance();
+    }
+
+    public void setHandler(Handler handler)
+    {
+        this.mHandler = handler;
+    }
+
+    private void configurePlatform() {
+
+        PlatformConfig platformConfig = new PlatformConfig(
+                mContext,
+                ServiceType.IN_PROC,
+                ModeType.CLIENT_SERVER,
+                "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+                0,         // Uses randomly available port
+                QualityOfService.LOW
+        );
+
+        Log.i(TAG, "Configuring platform.");
+        OcPlatform.Configure(platformConfig);
+        try {
+            OcPlatform.stopPresence(); // Initialize OcPlatform
+        } catch(Exception e) {
+            Log.e(TAG, "Exception: stopping presence when configuration step: " + e);
+        }
+        Log.i(TAG, "Configuration done Successfully");
+    }
+
+    public void Start(boolean policy)
+    {
+        Log.i(TAG, "Start ProviderService -IN");
+        configurePlatform();
+        gAcceptor = policy;
+        try{
+            int result =  ioTNotification.start(this, this, policy, "Info");
+            Log.i(TAG, "Notification Start: " + result);
+        }
+        catch(Exception e){
+
+        }
+
+        Log.i(TAG, "Start ProviderService - OUT");
+    }
+
+    public void RegisterTopic()
+    {
+        Log.i(TAG, "Register Topics -IN");
+        try{
+            int result =  ioTNotification.registerTopic("OCF_TOPIC1");
+            Log.i(TAG, " RegisterTopic: " + result);
+            result =  ioTNotification.registerTopic("OCF_TOPIC2");
+            Log.i(TAG, " RegisterTopic: " + result);
+            result =  ioTNotification.registerTopic("OCF_TOPIC3");
+            Log.i(TAG, " RegisterTopic: " + result);
+            result =  ioTNotification.registerTopic("OCF_TOPIC4");
+            Log.i(TAG, " RegisterTopic: " + result);
+        }
+        catch(Exception e){
+
+        }
+
+        Log.i(TAG, "Start ProviderService - OUT");
+    }
+
+    public int SetTopic()
+    {
+        Log.i(TAG, "Set Topic -IN");
+        if(gConsumer == null){
+            return 0;
+        }
+        try{
+            int result =  gConsumer.setTopic("OCF_TOPIC1");
+            Log.i(TAG, " Set Topic : " + result);
+            result =  gConsumer.setTopic("OCF_TOPIC2");
+            Log.i(TAG, " Set Topic : " + result);
+            result =  gConsumer.setTopic("OCF_TOPIC3");
+            Log.i(TAG, " Set Topic : " + result);
+            result =  gConsumer.setTopic("OCF_TOPIC4");
+            Log.i(TAG, " Set Topic : " + result);
+        }
+        catch(Exception e){
+
+        }
+
+        Log.i(TAG, "Start ProviderService - OUT");
+        return 1;
+    }
+
+    public void Stop() {
+        Log.i(TAG, "Stop ProviderService - IN");
+        try {
+            OcPlatform.stopPresence();
+        } catch (Exception e) {
+            Log.e(TAG, "Exception: stopping presence when terminating NS server: " + e);
+        }
+        try{
+            int result =  ioTNotification.stop();
+            Log.i(TAG, "Notification Stop: " + result);
+        }
+        catch(Exception e){
+
+        }
+
+        Log.i(TAG, "Stop ProviderService - OUT");
+    }
+
+
+    public void SendMessage(Message notiMessage) {
+        Log.i(TAG, "SendMessage ProviderService - IN");
+
+        try{
+            int result =  ioTNotification.sendMessage(notiMessage);
+            Log.i(TAG, "Notification Send Message: " + result);
+        }
+        catch(Exception e){
+
+        }
+
+        Log.i(TAG, "SendMessage ProviderService - OUT");
+        mHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                Toast.makeText(mContext, "Notification sent", Toast.LENGTH_SHORT).show();
+            }
+        });
+    }
+
+    public void SendSyncInfo(long messageId, SyncInfo.SyncType syncType) {
+        Log.i(TAG, "SendSyncInfo ProviderService - IN");
+        if(msgMap.containsKey(messageId)) {
+            if(msgMap.get(messageId) == SYNC_UNREAD)
+            {
+                try{
+                    ioTNotification.sendSyncInfo(messageId, syncType);
+                    Log.i(TAG, "Notification Sync " );
+                }
+                catch(Exception e) {
+
+                }
+                Log.i(TAG, "SendSyncInfo ProviderService - OUT");
+                msgMap.put("ID: "+messageId, SYNC_READ);
+            }
+        }
+    }
+
+    public void EnableRemoteService(String servAdd) {
+        Log.i(TAG, "EnableRemoteService ProviderService - IN");
+        try{
+            int result = ioTNotification.enableRemoteService(servAdd);
+            Log.i(TAG, "Notification EnableRemoteService: "+ result );
+        }
+        catch(Exception e) {
+
+        }
+        Log.i(TAG, "EnableRemoteService ProviderService - OUT");
+    }
+
+    public void DisableRemoteService(String servAdd) {
+        Log.i(TAG, "DisableRemoteService ProviderService - IN");
+        try{
+            int result = ioTNotification.disableRemoteService(servAdd);
+            Log.i(TAG, "Notification DisableRemoteService: "+ result );
+        }
+        catch(Exception e) {
+
+        }
+        Log.i(TAG, "DisableRemoteService ProviderService - OUT");
+    }
+
+    public void AcceptSubscription(Consumer consumer, boolean accepted)
+    {
+        Log.i(TAG,"AcceptSubscription ProviderService - IN");
+        try{
+            int result = consumer.acceptSubscription(accepted);
+            Log.i(TAG, "Notification AcceptSubscription: "+result );
+        }
+        catch(Exception e) {
+
+        }
+        Log.i(TAG, "AcceptSubscription ProviderService - OUT");
+    }
+
+    @Override
+    public void onConsumerSubscribed(Consumer consumer) {
+        Log.i(TAG, "onConsumerSubscribed - IN");
+        gConsumer = consumer;
+        AcceptSubscription(consumer, true);
+        android.os.Message msg = mHandler.obtainMessage(CONSUMER_SUBSCRIBED,
+                "Consumer Id: " + consumer.getConsumerId()  );
+        mHandler.sendMessage(msg);
+        Log.i(TAG, "onConsumerSubscribed - OUT");
+    }
+
+    @Override
+    public void onMessageSynchronized(SyncInfo syncInfo) {
+        Log.i(TAG, "Received SyncInfo with messageID: "+syncInfo.getMessageId());
+        android.os.Message msg = mHandler.obtainMessage(MESSAGE_SYNC,
+                "Message Id: " + syncInfo.getMessageId()  );
+        mHandler.sendMessage(msg);
+    }
+
+    public HashMap<String, Integer> getMsgMap() {
+        return msgMap;
+    }
+}
index 2365c5c..d109ae4 100644 (file)
     <LinearLayout\r
         android:layout_width="match_parent"\r
         android:layout_height="wrap_content"\r
-        android:paddingLeft="16dp"\r
-        android:paddingRight="16dp"\r
+        android:paddingLeft="1dp"\r
+        android:paddingRight="1dp"\r
         android:orientation="vertical" >\r
 \r
-        <View\r
-            android:layout_width="match_parent"\r
-            android:layout_height="1dp"\r
-            android:layout_alignParentBottom="true"\r
-            android:background="@android:color/darker_gray"/>\r
 \r
         <LinearLayout\r
             android:layout_width="match_parent"\r
-            android:layout_height="10dp">\r
+            android:layout_height="wrap_content"\r
+            android:paddingLeft="5dp"\r
+            android:paddingRight="5dp"\r
+            android:orientation="horizontal"\r
+            android:weightSum="1">\r
+\r
+            <Button\r
+                android:layout_height="wrap_content"\r
+                android:layout_width="150dp"\r
+                android:id="@+id/BtnStart"\r
+                android:text="START"/>\r
+\r
+            <Button\r
+                android:layout_height="wrap_content"\r
+                android:layout_width="150dp"\r
+                android:id="@+id/BtnStop"\r
+                android:text="STOP" />\r
         </LinearLayout>\r
 \r
         <LinearLayout\r
             android:layout_height="wrap_content"\r
             android:paddingLeft="5dp"\r
             android:paddingRight="5dp"\r
-            android:orientation="horizontal" >\r
+            android:orientation="horizontal"\r
+            android:weightSum="1">\r
 \r
-            <Button\r
-                android:layout_gravity="center_vertical|center_horizontal"\r
-                android:layout_height="60dp"\r
+            <RadioGroup\r
+                android:id="@+id/RadioGroup"\r
                 android:layout_width="match_parent"\r
-                android:id="@+id/BtnStart"\r
-                android:text="START"/>\r
+                android:layout_height="wrap_content"\r
+                android:layout_alignParentLeft="true"\r
+                android:orientation='horizontal'>\r
+                    <TextView\r
+                    android:layout_width="wrap_content"\r
+                    android:layout_height="wrap_content"\r
+                    android:text="ACCEPTOR: "\r
+                    android:id="@+id/textview"\r
+                    android:checked="false" />\r
+                    <RadioButton\r
+                        android:layout_width="wrap_content"\r
+                        android:layout_height="wrap_content"\r
+                        android:text="Provider"\r
+                        android:id="@+id/RadioProvider"\r
+                        android:checked="true" />\r
+\r
+                    <RadioButton\r
+                        android:layout_width="wrap_content"\r
+                        android:layout_height="wrap_content"\r
+                        android:text="Consumer"\r
+                        android:id="@+id/RadioConsumer"\r
+                        android:checked="false" />\r
+\r
+            </RadioGroup>\r
         </LinearLayout>\r
 \r
         <LinearLayout\r
             android:layout_height="wrap_content"\r
             android:paddingLeft="5dp"\r
             android:paddingRight="5dp"\r
-            android:orientation="horizontal" >\r
+            android:orientation="horizontal"\r
+            android:weightSum="1">\r
 \r
             <Button\r
-\r
                 android:layout_height="wrap_content"\r
                 android:layout_width="150dp"\r
-                android:id="@+id/BtnAccept"\r
-                android:text="ACCEPT"/>\r
+                android:id="@+id/BtnRegister"\r
+                android:text="@string/btn_reg"/>\r
 \r
             <Button\r
-\r
                 android:layout_height="wrap_content"\r
                 android:layout_width="150dp"\r
-                android:id="@+id/BtnSync"\r
-                android:text="SYNC"/>\r
+                android:id="@+id/BtnSet"\r
+                android:text="@string/btn_set" />\r
         </LinearLayout>\r
 \r
         <LinearLayout\r
                 android:layout_width="match_parent"\r
                 android:layout_height="wrap_content"\r
                 android:windowSoftInputMode="stateHidden"\r
-                android:hint="글자를 입력하세요" />\r
+                android:hint="Add Message Title" />\r
         </LinearLayout>\r
 \r
         <LinearLayout\r
                 android:layout_width="match_parent"\r
                 android:layout_height="wrap_content"\r
                 android:windowSoftInputMode="stateHidden"\r
-                android:hint="글자를 입력하세요" />\r
+                android:hint="Add Message Body" />\r
+        </LinearLayout>\r
+\r
+        <LinearLayout\r
+            android:id="@+id/Topic"\r
+            android:layout_width="match_parent"\r
+            android:layout_height="wrap_content"\r
+            android:paddingLeft="5dp"\r
+            android:paddingRight="5dp"\r
+            android:orientation="horizontal" >\r
+\r
+            <Button\r
+                android:layout_height="wrap_content"\r
+                android:layout_width="wrap_content"\r
+                android:id="@+id/BtnTopic"\r
+                android:text="@string/btn_topic"\r
+                android:onClick="selfDestruct" />\r
+\r
+            <EditText\r
+                android:id="@+id/EditTextTopic"\r
+                android:layout_width="match_parent"\r
+                android:layout_height="wrap_content"\r
+                android:windowSoftInputMode="stateHidden"\r
+                android:hint="OCF_TOPIC1 (1-4)" />\r
         </LinearLayout>\r
 \r
         <Button\r
             android:layout_gravity="center_vertical|center_horizontal"\r
-            android:layout_height="60dp"\r
+            android:layout_height="wrap_content"\r
             android:layout_width="match_parent"\r
             android:id="@+id/BtnCreateNoti"\r
             android:text="@string/btn_create_noti"\r
             />\r
-\r
+        <Button\r
+            android:layout_gravity="center_vertical|center_horizontal"\r
+            android:layout_height="wrap_content"\r
+            android:layout_width="match_parent"\r
+            android:id="@+id/BtnLog"\r
+            android:text="@string/btn_log"\r
+            android:layout_alignParentBottom="true"\r
+            android:layout_centerHorizontal="true" />\r
         <LinearLayout\r
             android:layout_width="match_parent"\r
             android:layout_height="10dp">\r
 \r
             <LinearLayout\r
                 android:layout_width="match_parent"\r
-                android:layout_height="150dp"\r
+                android:layout_height="250dp"\r
                 android:paddingLeft="5dp"\r
                 android:paddingRight="5dp"\r
                 android:orientation="horizontal" >\r
 \r
                 <TextView\r
                     android:layout_gravity="center_vertical|center_horizontal"\r
-                    android:layout_height="150dp"\r
+                    android:layout_height="1000dp"\r
                     android:layout_width="match_parent"\r
                     android:scrollbars="vertical"\r
                     android:id="@+id/TvLog"\r
 \r
         </ScrollView>\r
 \r
-        <LinearLayout\r
-            android:layout_width="match_parent"\r
-            android:layout_height="wrap_content"\r
-            android:paddingLeft="5dp"\r
-            android:paddingRight="5dp"\r
-            android:orientation="horizontal" >\r
-\r
-            <Button\r
-                android:layout_gravity="center_vertical|center_horizontal"\r
-                android:layout_height="60dp"\r
-                android:layout_width="match_parent"\r
-                android:id="@+id/BtnStop"\r
-                android:text="STOP"/>\r
-        </LinearLayout>\r
-\r
-        <View\r
-            android:layout_width="match_parent"\r
-            android:layout_height="1dp"\r
-            android:layout_alignParentBottom="true"\r
-            android:background="@android:color/darker_gray"/>\r
-\r
-        <LinearLayout\r
-            android:layout_width="match_parent"\r
-            android:layout_height="20dp">\r
-        </LinearLayout>\r
-\r
     </LinearLayout>\r
 \r
-\r
 </RelativeLayout>\r
index b762eec..80b63f8 100644 (file)
@@ -2,6 +2,10 @@
     <string name="app_name">NotificationProviderExample</string>\r
     <string name="btn_title">Title</string>\r
     <string name="btn_body">Body</string>\r
+    <string name="btn_topic">Topic</string>\r
+    <string name="btn_reg">Register Topic</string>\r
+    <string name="btn_set">Set Topic</string>\r
     <string name="btn_send">Send Notification</string>\r
-    <string name="btn_create_noti">Create Notification</string>\r
+    <string name="btn_create_noti">Send Notification</string>\r
+    <string name="btn_log">Clear Logs</string>\r
 </resources>\r
diff --git a/service/notification/examples/android/NotiProviderExample/app/src/test/java/com/sec/notiproviderexample/ExampleUnitTest.java b/service/notification/examples/android/NotiProviderExample/app/src/test/java/com/sec/notiproviderexample/ExampleUnitTest.java
deleted file mode 100644 (file)
index f69c509..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.sec.notiproviderexample;\r
-\r
-import org.junit.Test;\r
-\r
-import static org.junit.Assert.*;\r
-\r
-/**\r
- * To work on unit tests, switch the Test Artifact in the Build Variants view.\r
- */\r
-public class ExampleUnitTest {\r
-    @Test\r
-    public void addition_isCorrect() throws Exception {\r
-        assertEquals(4, 2 + 2);\r
-    }\r
-}
\ No newline at end of file
diff --git a/service/notification/examples/android/NotiProviderExample/iotivity-armeabi-notification-service-debug/build.gradle b/service/notification/examples/android/NotiProviderExample/iotivity-armeabi-notification-service-debug/build.gradle
deleted file mode 100644 (file)
index 3fbdd9f..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-configurations.create("default")
-artifacts.add("default", file('iotivity-armeabi-notification-service-debug.aar'))
\ No newline at end of file
diff --git a/service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-debug/build.gradle b/service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-debug/build.gradle
deleted file mode 100644 (file)
index 305a7ec..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-configurations.create("default")
-artifacts.add("default", file('iotivity-base-armeabi-debug.aar'))
\ No newline at end of file