Change file mode.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / samples / android / casample / sampleService / src / main / java / org / iotivity / ca / service / MainActivity.java
1 package org.iotivity.ca.service;
2
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.content.DialogInterface;
6 import android.content.Intent;
7 import android.nfc.NfcAdapter;
8 import android.os.Bundle;
9 import android.os.Handler;
10 import android.util.Log;
11 import android.view.Menu;
12 import android.view.MenuItem;
13 import android.view.View;
14 import android.view.View.OnClickListener;
15 import android.widget.Button;
16 import android.widget.EditText;
17 import android.widget.RelativeLayout;
18 import android.widget.TextView;
19 import android.widget.Toast;
20 import java.io.File;
21
22 import org.iotivity.ca.sample_service.R;
23 import org.iotivity.ca.service.FileChooser;
24 import org.iotivity.ca.service.FileChooser.FileSelectedListener;
25
26 public class MainActivity extends Activity {
27
28     static RMInterface RM = new RMInterface();
29
30     private final static String TAG = "Sample_Service : MainActivity";
31
32     private final CharSequence[] mNetworkCheckBoxItems = { Network.IP.name(),
33             Network.LE.name(), Network.EDR.name(), Network.TCP.name(), Network.NFC.name()};
34
35     private final CharSequence[] mDTLSCheckBoxItems = { DTLS.UNSECURED.name(),
36             DTLS.SECURED.name() };
37
38     private final CharSequence[] mMsgTyleCheckBoxItems = { MsgType.CON.name(),
39             MsgType.NON.name(), MsgType.ACK.name(), MsgType.RESET.name() };
40
41     private final CharSequence[] mResponseResultCheckBoxItems = {
42             ResponseResult.CA_CREATED.name(), ResponseResult.CA_DELETED.name(),
43             ResponseResult.CA_VALID.name(), ResponseResult.CA_CHANGED.name(),
44             ResponseResult.CA_CONTENT.name(), ResponseResult.CA_EMPTY.name(),
45             ResponseResult.CA_BAD_REQ.name(), ResponseResult.CA_BAD_OPT.name(),
46             ResponseResult.CA_NOT_FOUND.name(), ResponseResult.CA_INTERNAL_SERVER_ERROR.name(),
47             ResponseResult.CA_RETRANSMIT_TIMEOUT.name() };
48
49     private enum Mode {
50         SERVER, CLIENT, BOTH, UNKNOWN
51     };
52
53     private enum Network {
54         IP, LE, EDR, TCP, NFC
55     };
56
57     private enum DTLS {
58         UNSECURED, SECURED
59     };
60
61     private enum MsgType {
62         CON, NON, ACK, RESET
63     };
64
65     private enum ResponseResult {
66         CA_CREATED, CA_DELETED, CA_VALID, CA_CHANGED, CA_CONTENT, CA_EMPTY,
67         CA_BAD_REQ, CA_BAD_OPT, CA_NOT_FOUND, CA_INTERNAL_SERVER_ERROR, CA_RETRANSMIT_TIMEOUT
68     }
69
70     private boolean mCheckedItems[] = {
71             false, false, false, false, false
72     };
73
74     private int mSelectedItems[] = { 0, 0, 0, 0, 0, 0};
75
76     private int mUnSelectedItems[] = { 0, 0, 0, 0, 0, 0};
77
78     private Mode mCurrentMode = Mode.UNKNOWN;
79
80     private RelativeLayout mSendNotificationLayout = null;
81
82     private RelativeLayout mSendRequestLayout = null;
83
84     private RelativeLayout mSendRequestToAllLayout = null;
85
86     private RelativeLayout mSendRequestSettingLayout = null;
87
88     private RelativeLayout mSendRequestToAllSettingLayout = null;
89
90     private RelativeLayout mSendResponseNotiSettingLayout = null;
91
92     private RelativeLayout mReceiveLayout = null;
93
94     private RelativeLayout mRequestTitleLayout = null;
95
96     private RelativeLayout mRequestToAllTitleLayout = null;
97
98     private RelativeLayout mResponseNotificationTitleLayout = null;
99
100     private RelativeLayout mHandleTitleLayout = null;
101
102     private TextView mMode_tv = null;
103
104     private TextView mNetwork_tv = null;
105
106     private EditText mNotification_ed = null;
107
108     private EditText mReqData_ed = null;
109
110     private EditText mReqToAllData_ed = null;
111
112     private Button mNotify_btn = null;
113
114     private Button mReqeust_btn = null;
115
116     private Button mReqeust_setting_btn = null;
117
118     private Button mReqeustToAll_btn = null;
119
120     private Button mReqeustToAll_setting_btn = null;
121
122     private Button mResponse_Notify_setting_btn = null;
123
124     private Button mResponse_btn = null;
125
126     private Button mGetNetworkInfo_btn = null;
127
128     private Button mRecv_btn = null;
129
130     private Button mBig_btn = null;
131
132     private Handler mLogHandler = null;
133
134     /**
135      * Defined ConnectivityType in cacommon.c
136      *
137      * CA_IP = (1 << 0) CA_LE = (1 << 1) CA_EDR = (1 << 2) CA_TCP = (1 << 4) CA_NFC= (1 << 5)
138      */
139     private int CA_IP = (1 << 0);
140     private int CA_LE = (1 << 1);
141     private int CA_EDR = (1 << 2);
142     private int CA_TCP = (1 << 4);
143     private int CA_NFC = (1 << 5);
144     private int isSecured = 0;
145     private int msgType = 1;
146     private int responseValue = 0;
147     private int selectedNetworkType = -1;
148     private int selectedMsgType = 1;
149     private int selectedMsgSecured = 0;
150     private int selectedResponseValue = 0;
151     int selectedNetwork = -1;
152     int interestedNetwork = 0;
153     int uninterestedNetwork = 0;
154     private boolean isSendResponseSetting = false;
155     private boolean isSendRequestToAllSetting = false;
156     private boolean isBigData = false;
157
158     @Override
159     protected void onCreate(Bundle savedInstanceState) {
160         super.onCreate(savedInstanceState);
161         setContentView(R.layout.activity_main);
162
163         RM.setResponseListener(this);
164
165         mLogHandler = new Handler();
166         TextView logView = (TextView) findViewById(R.id.tv_result);
167         DLog.setTextView(mLogHandler, logView);
168
169         // Initialize UI
170         // common
171         mReceiveLayout = (RelativeLayout) findViewById(R.id.layout_receive);
172
173         // client
174         mSendRequestLayout = (RelativeLayout) findViewById(R.id.layout_request);
175         mSendRequestToAllLayout = (RelativeLayout) findViewById(R.id.layout_request_to_all);
176         mSendRequestSettingLayout = (RelativeLayout)
177                 findViewById(R.id.layout_request_setting_for_client);
178         mSendRequestToAllSettingLayout = (RelativeLayout)
179                 findViewById(R.id.layout_request_to_all_setting_for_client);
180         mRequestTitleLayout = (RelativeLayout) findViewById(R.id.layout_request_title);
181         mRequestToAllTitleLayout = (RelativeLayout) findViewById(R.id.layout_request_to_all_title);
182         mHandleTitleLayout = (RelativeLayout) findViewById(R.id.layout_handle_title);
183
184         // server
185         mSendNotificationLayout = (RelativeLayout) findViewById(R.id.layout_notify);
186         mSendResponseNotiSettingLayout = (RelativeLayout)
187                 findViewById(R.id.layout_request_setting_for_server);
188         mResponseNotificationTitleLayout = (RelativeLayout)
189                 findViewById(R.id.layout_Response_Noti_title);
190
191         mMode_tv = (TextView) findViewById(R.id.tv_mode);
192         mNetwork_tv = (TextView) findViewById(R.id.tv_network);
193
194         mNotification_ed = (EditText) findViewById(R.id.et_notification);
195         mReqData_ed = (EditText) findViewById(R.id.et_req_data);
196         mReqToAllData_ed = (EditText) findViewById(R.id.et_req_to_all_data);
197
198         mResponse_btn = (Button) findViewById(R.id.btn_sendresponse);
199         mNotify_btn = (Button) findViewById(R.id.btn_notify);
200         mReqeust_btn = (Button) findViewById(R.id.btn_Request);
201         mReqeust_setting_btn = (Button) findViewById(R.id.btn_Request_setting_for_client);
202         mReqeustToAll_btn = (Button) findViewById(R.id.btn_request_to_all);
203         mReqeustToAll_setting_btn = (Button)
204                 findViewById(R.id.btn_request_to_all_setting_for_client);
205         mResponse_Notify_setting_btn = (Button) findViewById(R.id.btn_Request_setting_for_server);
206         mGetNetworkInfo_btn = (Button) findViewById(R.id.btn_get_network_info);
207         mRecv_btn = (Button) findViewById(R.id.btn_receive);
208         mBig_btn = (Button) findViewById(R.id.btn_big_data);
209         mBig_btn.setOnClickListener(mSelectLargeDataButtonHandler);
210
211         mResponse_btn.setOnClickListener(mSendResponseHandler);
212         mNotify_btn.setOnClickListener(mNotifyHandler);
213         mReqeust_btn.setOnClickListener(mSendRequestHandler);
214         mReqeust_setting_btn.setOnClickListener(mSendRequestSettingHandler);
215         mReqeustToAll_btn.setOnClickListener(mSendRequestToAllHandler);
216         mReqeustToAll_setting_btn.setOnClickListener(mSendRequestToAllSettingHandler);
217         mResponse_Notify_setting_btn
218                 .setOnClickListener(mSendResponseNotiSettingHandler);
219         mRecv_btn.setOnClickListener(mResponseHandler);
220         mGetNetworkInfo_btn.setOnClickListener(mGetNetworkInfoHandler);
221
222         showSelectModeView();
223
224         // Initialize Connectivity Abstraction
225         RM.RMInitialize(getApplicationContext(), this);
226         // set handler
227         RM.RMRegisterHandler();
228     }
229
230     private void showSelectModeView() {
231
232         mSendNotificationLayout.setVisibility(View.INVISIBLE);
233         mSendRequestLayout.setVisibility(View.INVISIBLE);
234         mSendRequestToAllLayout.setVisibility(View.INVISIBLE);
235         mSendRequestSettingLayout.setVisibility(View.INVISIBLE);
236         mSendRequestToAllSettingLayout.setVisibility(View.INVISIBLE);
237         mReceiveLayout.setVisibility(View.INVISIBLE);
238         mRequestTitleLayout.setVisibility(View.INVISIBLE);
239         mRequestToAllTitleLayout.setVisibility(View.INVISIBLE);
240         mHandleTitleLayout.setVisibility(View.INVISIBLE);
241         mResponseNotificationTitleLayout.setVisibility(View.INVISIBLE);
242         mSendResponseNotiSettingLayout.setVisibility(View.INVISIBLE);
243
244         mMode_tv.setText("Select Mode (Server or Client)");
245         Log.i(TAG, "Select Mode (Server or Client)");
246     }
247
248     private void showNetworkView() {
249
250         mNetwork_tv.setText("Select Network Type");
251         Log.i(TAG, "Select Network Type");
252     }
253
254     private void showModeView() {
255
256         mReceiveLayout.setVisibility(View.VISIBLE);
257         mSendRequestToAllLayout.setVisibility(View.VISIBLE);
258         mSendRequestToAllSettingLayout.setVisibility(View.VISIBLE);
259         mRequestToAllTitleLayout.setVisibility(View.VISIBLE);
260         mHandleTitleLayout.setVisibility(View.VISIBLE);
261
262         if (mCurrentMode == Mode.SERVER) {
263
264             mSendNotificationLayout.setVisibility(View.VISIBLE);
265             mSendRequestLayout.setVisibility(View.INVISIBLE);
266             mSendRequestSettingLayout.setVisibility(View.INVISIBLE);
267
268             mRequestTitleLayout.setVisibility(View.INVISIBLE);
269
270             mResponseNotificationTitleLayout.setVisibility(View.VISIBLE);
271             mSendResponseNotiSettingLayout.setVisibility(View.VISIBLE);
272
273         } else if (mCurrentMode == Mode.CLIENT) {
274
275             mSendNotificationLayout.setVisibility(View.INVISIBLE);
276             mSendRequestLayout.setVisibility(View.VISIBLE);
277             mSendRequestSettingLayout.setVisibility(View.VISIBLE);
278
279             mRequestTitleLayout.setVisibility(View.VISIBLE);
280
281             mResponseNotificationTitleLayout.setVisibility(View.INVISIBLE);
282             mSendResponseNotiSettingLayout.setVisibility(View.INVISIBLE);
283         }
284         mNetwork_tv.setText("");
285     }
286
287     @Override
288     public void onNewIntent(Intent intent) {
289         super.onNewIntent(intent);
290         Intent i = new Intent();
291         i.setAction(intent.getAction());
292         i.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES,
293                    intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES));
294         sendBroadcast(i);
295         Log.d(TAG, "Broadcast intent complete");
296     }
297
298     @Override
299     protected void onDestroy() {
300         super.onDestroy();
301
302         // Terminate Connectivity Abstraction
303         RM.RMTerminate();
304         android.os.Process.killProcess(android.os.Process.myPid());
305     }
306
307     @Override
308     public boolean onCreateOptionsMenu(Menu menu) {
309
310         menu.add(0, 1, Menu.NONE, "Start Server");
311         menu.add(0, 2, Menu.NONE, "Start Client");
312         menu.add(0, 3, Menu.NONE, "Select Network");
313
314         return true;
315     }
316
317     @Override
318     public boolean onOptionsItemSelected(MenuItem item) {
319
320         switch (item.getItemId()) {
321
322         case 1:
323
324             RM.RMStartListeningServer();
325
326             if (interestedNetwork == 0) {
327                 mCurrentMode = Mode.SERVER;
328                 mMode_tv.setText("MODE: " + mCurrentMode.toString());
329                 Log.i(TAG, "MODE: " + mCurrentMode.toString());
330                 showNetworkView();
331
332             } else {
333                 mCurrentMode = Mode.SERVER;
334                 mMode_tv.setText("MODE: " + mCurrentMode.toString());
335                 Log.i(TAG, "MODE: " + mCurrentMode.toString());
336                 showModeView();
337             }
338
339             break;
340
341         case 2:
342
343             RM.RMStartDiscoveryServer();
344
345             if (interestedNetwork == 0) {
346                 mCurrentMode = Mode.CLIENT;
347                 mMode_tv.setText("MODE: " + mCurrentMode.toString());
348                 Log.i(TAG, "MODE: " + mCurrentMode.toString());
349                 showNetworkView();
350
351             } else {
352                 mCurrentMode = Mode.CLIENT;
353                 mMode_tv.setText("MODE: " + mCurrentMode.toString());
354                 Log.i(TAG, "MODE: " + mCurrentMode.toString());
355                 showModeView();
356             }
357
358             break;
359
360         case 3:
361
362             checkInterestedNetwork("Select Network");
363
364             break;
365         }
366
367         return super.onOptionsItemSelected(item);
368     }
369
370     private OnClickListener mSendResponseHandler = new OnClickListener() {
371
372         @Override
373         public void onClick(View v) {
374
375             DLog.v(TAG, "SendResponse click");
376             if ( selectedNetwork != -1) {
377                 RM.RMSendResponse(selectedNetwork, isSecured, msgType, responseValue);
378             }
379             else {
380                 DLog.v(TAG, "Please Select Network Type");
381             }
382         }
383     };
384
385     private OnClickListener mNotifyHandler = new OnClickListener() {
386
387         @Override
388         public void onClick(View v) {
389
390             DLog.v(TAG, "SendNotification click");
391             if ( selectedNetwork != -1) {
392                 RM.RMSendNotification(mNotification_ed.getText().toString(),
393                     null, selectedNetwork, isSecured, msgType);
394             }
395             else {
396                 DLog.v(TAG, "Please Select Network Type");
397             }
398         }
399     };
400
401     private OnClickListener mSendRequestHandler = new OnClickListener() {
402
403         @Override
404         public void onClick(View v) {
405
406             DLog.v(TAG, "SendRequest click");
407             if ( selectedNetwork != -1) {
408                 RM.RMSendRequest(mReqData_ed.getText().toString(), null,
409                     selectedNetwork, isSecured, msgType, false);
410             }
411             else {
412                 DLog.v(TAG, "Please Select Network Type");
413             }
414         }
415     };
416
417     private OnClickListener mSendRequestSettingHandler = new OnClickListener() {
418
419         @Override
420         public void onClick(View v) {
421             checkSendNetworkType("Select Send Network Type");
422         }
423     };
424
425     private OnClickListener mSendRequestToAllHandler = new OnClickListener() {
426
427         @Override
428         public void onClick(View v) {
429
430             DLog.v(TAG, "SendRequestToAll click");
431             if ( selectedNetwork != -1) {
432                 RM.RMSendReqestToAll(mReqToAllData_ed.getText().toString(), selectedNetwork);
433             }
434             else {
435                 DLog.v(TAG, "Please Select Network Type");
436             }
437         }
438     };
439
440     private OnClickListener mSendRequestToAllSettingHandler = new OnClickListener() {
441
442         @Override
443         public void onClick(View v) {
444             isSendRequestToAllSetting = true;
445             checkSendNetworkType("Select Send Network Type");
446         }
447     };
448
449     private OnClickListener mSendResponseNotiSettingHandler = new OnClickListener() {
450
451         @Override
452         public void onClick(View v) {
453             isSendResponseSetting = true;
454             checkSendNetworkType("Select Send Network Type");
455         }
456     };
457
458     private OnClickListener mGetNetworkInfoHandler = new OnClickListener() {
459         @Override
460         public void onClick(View v) {
461
462             RM.RMGetNetworkInfomation();
463         }
464     };
465
466     private OnClickListener mResponseHandler = new OnClickListener() {
467
468         @Override
469         public void onClick(View v) {
470
471             RM.RMHandleRequestResponse();
472         }
473     };
474
475     private OnClickListener mSelectLargeDataButtonHandler = new OnClickListener() {
476         @Override
477         public void onClick(View v) {
478
479             isBigData = true;
480             checkSendNetworkType("Select Send Network Type");
481         }
482     };
483
484     private void checkInterestedNetwork(String title) {
485
486         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
487         builder.setTitle(title)
488                 .setMultiChoiceItems(mNetworkCheckBoxItems, mCheckedItems,
489                         new DialogInterface.OnMultiChoiceClickListener() {
490
491                             @Override
492                             public void onClick(DialogInterface dialog,
493                                     int which, boolean isChecked) {
494
495                                 // in case of TCP increase value,
496                                 // because CASample not support RA.
497                                 // which: 0(IP), 1(BT), 2(BLE), 3(TCP)
498                                 if (which == 3) {
499                                     which = 4;
500                                 }
501                                 if (isChecked) {
502                                     mSelectedItems[which] = 1;
503                                     mUnSelectedItems[which] = 0;
504
505                                 } else if (mSelectedItems[which] == 1) {
506
507                                     mSelectedItems[which] = 0;
508                                     mUnSelectedItems[which] = 1;
509                                 }
510                             }
511                         })
512                 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
513
514                     @Override
515                     public void onClick(DialogInterface dialog, int which) {
516
517                         interestedNetwork = 0;
518
519                         for (int i = 0; i < mSelectedItems.length; i++) {
520                             if (mSelectedItems[i] == 1) {
521                                 interestedNetwork |= (1 << i);
522                             }
523                         }
524                         if(0 != interestedNetwork)
525                             RM.RMSelectNetwork(interestedNetwork);
526
527                         uninterestedNetwork = 0;
528
529                         for (int i = 0; i < mUnSelectedItems.length; i++) {
530                             if (mUnSelectedItems[i] == 1) {
531                                 uninterestedNetwork |= (1 << i);
532                             }
533                         }
534                         if(0 != uninterestedNetwork)
535                             RM.RMUnSelectNetwork(uninterestedNetwork);
536
537                     }
538                 }).show();
539     }
540
541     private void checkMsgSecured(String title) {
542
543         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
544
545         builder.setTitle(title)
546                 .setSingleChoiceItems(mDTLSCheckBoxItems, selectedMsgSecured,
547                         new DialogInterface.OnClickListener() {
548
549                             @Override
550                             public void onClick(DialogInterface dialog,
551                                     int which) {
552                                 selectedMsgSecured = which;
553                             }
554                         })
555                 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
556
557                     @Override
558                     public void onClick(DialogInterface dialog, int which) {
559
560                         if (selectedMsgSecured == DTLS.SECURED.ordinal()) {
561                             isSecured = 1;
562                             DLog.v(TAG, "Send secured message");
563
564                         } else if (selectedMsgSecured == DTLS.UNSECURED.ordinal()) {
565                             isSecured = 0;
566                             DLog.v(TAG, "Send unsecured message");
567                         }
568                         checkMsgType("Select Msg Type");
569                     }
570
571                 }).show();
572     }
573
574     private void checkMsgType(String title) {
575
576         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
577         builder.setTitle(title)
578                 .setSingleChoiceItems(mMsgTyleCheckBoxItems, selectedMsgType,
579                         new DialogInterface.OnClickListener() {
580
581                             @Override
582                             public void onClick(DialogInterface dialog,
583                                     int which) {
584                                 selectedMsgType = which;
585                             }
586                         })
587                 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
588
589                     @Override
590                     public void onClick(DialogInterface dialog, int which) {
591
592                         if (selectedMsgType == MsgType.CON.ordinal()) {
593                             msgType = 0;
594                             DLog.v(TAG, "Message Type is CON");
595
596                         } else if (selectedMsgType == MsgType.NON.ordinal()) {
597                             msgType = 1;
598                             DLog.v(TAG, "Message Type is NON");
599                         } else if (selectedMsgType == MsgType.ACK.ordinal()) {
600                             msgType = 2;
601                             DLog.v(TAG, "Message Type is ACK");
602                         } else if (selectedMsgType == MsgType.RESET.ordinal()) {
603                             msgType = 3;
604                             DLog.v(TAG, "Message Type is RESET");
605                             }
606
607                         if (isSendResponseSetting == true && msgType != 3) {
608                             checkResponseResult("Select Value of Response Result");
609                             isSendResponseSetting = false;
610                         }
611                     }
612                 }).show();
613     }
614
615     private void checkResponseResult(String title) {
616
617         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
618         builder.setTitle(title)
619                 .setSingleChoiceItems(mResponseResultCheckBoxItems, selectedResponseValue,
620                         new DialogInterface.OnClickListener() {
621
622                             @Override
623                             public void onClick(DialogInterface dialog,
624                                     int which) {
625                                 selectedResponseValue = which;
626                             }
627                         })
628                 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
629
630                     @Override
631                     public void onClick(DialogInterface dialog, int which) {
632
633                         if (selectedResponseValue == ResponseResult.CA_CREATED.ordinal()) {
634                             responseValue = 201;
635                             DLog.v(TAG, "Response Value is CA_CREATED");
636                         } else if (selectedResponseValue == ResponseResult.CA_DELETED
637                                 .ordinal()) {
638                             responseValue = 202;
639                             DLog.v(TAG, "Response Value is CA_DELETED");
640                         } else if (selectedResponseValue == ResponseResult.CA_VALID
641                                 .ordinal()) {
642                             responseValue = 203;
643                             DLog.v(TAG, "Response Value is CA_VALID");
644                         } else if (selectedResponseValue == ResponseResult.CA_CHANGED
645                                 .ordinal()) {
646                             responseValue = 204;
647                             DLog.v(TAG, "Response Value is CA_CHANGED");
648                         } else if (selectedResponseValue == ResponseResult.CA_CONTENT
649                                 .ordinal()) {
650                             responseValue = 205;
651                             DLog.v(TAG, "Response Value is CA_CONTENT");
652                         } else if (selectedResponseValue == ResponseResult.CA_EMPTY
653                                 .ordinal()) {
654                             responseValue = 0;
655                             DLog.v(TAG, "Response Value is CA_EMPTY");
656                         } else if (selectedResponseValue == ResponseResult.CA_BAD_REQ
657                                 .ordinal()) {
658                             responseValue = 400;
659                             DLog.v(TAG, "Response Value is CA_BAD_REQ");
660                         } else if (selectedResponseValue == ResponseResult.CA_BAD_OPT
661                                 .ordinal()) {
662                             responseValue = 402;
663                             DLog.v(TAG, "Response Value is CA_BAD_OPT");
664                         } else if (selectedResponseValue == ResponseResult.CA_NOT_FOUND
665                                 .ordinal()) {
666                             responseValue = 404;
667                             DLog.v(TAG, "Response Value is CA_NOT_FOUND");
668                         } else if (selectedResponseValue ==
669                                 ResponseResult.CA_INTERNAL_SERVER_ERROR
670                                 .ordinal()) {
671                             responseValue = 500;
672                             DLog.v(TAG, "Response Value is CA_INTERNAL_SERVER_ERROR");
673                         } else if (selectedResponseValue == ResponseResult.CA_RETRANSMIT_TIMEOUT
674                                 .ordinal()) {
675                             responseValue = 504;
676                             DLog.v(TAG, "Response Value is CA_RETRANSMIT_TIMEOUT");
677                         }
678                     }
679                 }).show();
680     }
681
682     private void checkSendNetworkType(String title) {
683         selectedNetworkType = -1;
684         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
685
686         builder.setTitle(title)
687                 .setSingleChoiceItems(mNetworkCheckBoxItems, -1,
688                         new DialogInterface.OnClickListener() {
689
690                             @Override
691                             public void onClick(DialogInterface dialog,
692                                     int which) {
693                                 selectedNetworkType = which;
694                             }
695                         })
696                 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
697
698                     @Override
699                     public void onClick(DialogInterface dialog, int which) {
700
701                         if (selectedNetworkType == Network.IP.ordinal()) {
702                             selectedNetwork = CA_IP;
703                             DLog.v(TAG, "Selected Network is IP");
704                         } else if (selectedNetworkType == Network.LE.ordinal()) {
705                             selectedNetwork = CA_LE;
706                             DLog.v(TAG, "Selected Network is LE");
707                         } else if (selectedNetworkType == Network.EDR.ordinal()) {
708                             selectedNetwork = CA_EDR;
709                             DLog.v(TAG, "Selected Network is EDR");
710                         } else if (selectedNetworkType == Network.TCP.ordinal()) {
711                             selectedNetwork = CA_TCP;
712                             DLog.v(TAG, "Selected Network is TCP");
713                         } else if (selectedNetworkType == Network.NFC.ordinal()) {
714                             selectedNetwork = CA_NFC;
715                             DLog.v(TAG, "Selected Network is NFC");
716                         } else {
717                             DLog.v(TAG, "Selected Network is NULL");
718                             selectedNetwork = -1;
719                         }
720
721                         if (isBigData)
722                         {
723                             new FileChooser(MainActivity.this).setFileListener(
724                                     new FileSelectedListener() {
725                                 public void fileSelected(final File file) {
726                                     if (selectedNetwork != -1) {
727
728                                         String path = file.getAbsolutePath();
729                                         Log.d(TAG, "File Path: " + path);
730
731                                         RM.RMSendRequest(mReqData_ed.getText().toString(), path,
732                                                          selectedNetwork, isSecured, msgType, true);
733                                     } else {
734                                         Toast.makeText(getApplicationContext(),
735                                                        "Request Setting Fisrt!!",
736                                                         Toast.LENGTH_LONG).show();
737                                     }
738                                 }
739                             } ).showDialog();
740                             isBigData = false;
741                         } else {
742                             if (isSendRequestToAllSetting != true) {
743                                 checkMsgSecured("Select DTLS Type");
744                             }
745                         }
746
747                         isSendRequestToAllSetting = false;
748                         isBigData = false;
749                     }
750                 }).show();
751     }
752
753     public void OnResponseReceived(String subject, String receivedData) {
754         String callbackData = subject + receivedData;
755         DLog.v(TAG, callbackData);
756
757         if (subject.equals(getString(R.string.remote_address))) {
758             StringBuilder sb = new StringBuilder();
759             sb.append(getString(R.string.coap_prefix)).append(receivedData);
760             mReqData_ed.setText(sb.toString());
761             mNotification_ed.setText(sb.toString());
762         } else if (subject.equals(getString(R.string.remote_port))) {
763             StringBuilder sb = new StringBuilder();
764             String uri = mReqData_ed.getText().toString();
765             sb.append(uri);
766             if (null != receivedData && uri.contains("."))
767             {
768                 sb.append(":").append(receivedData);
769             }
770             sb.append(getString(R.string.uri));
771             mReqData_ed.setText(sb.toString());
772             mNotification_ed.setText(sb.toString());
773         }
774     }
775 }