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