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