replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / android / examples / simplebase / src / main / java / org / iotivity / base / examples / Common.java
1 /*
2  * ******************************************************************
3  *
4  * Copyright 2016 Samsung Electronics All Rights Reserved.
5  *
6  * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.base.examples;
24
25 import android.content.Context;
26 import android.widget.Toast;
27 import android.util.Log;
28
29 import org.iotivity.base.OcPlatform;
30 import org.iotivity.base.ResourceProperty;
31
32 import java.text.DateFormat;
33 import java.util.Calendar;
34 import java.util.Date;
35 import java.util.EnumSet;
36 import java.util.Locale;
37
38 /**
39  * This class charge of common part.
40  */
41 public class Common {
42
43     private static final String TAG               = "OIC_SIMPLE_COMMON";
44     public static final int    DATA_SIZE          = 3000;
45     public static String       HOST               = "coap+tcp://192.168.0.1:5683";
46     public static final String COAP_TCP           = "coap+tcp://";
47     public static final String COAPS_TCP          = "coaps+tcp://";
48     public static String       TCP_ADDRESS        = "192.168.0.1";
49     public static String       TCP_PORT           = "5683";
50     public static final String PORT_SEPARATOR     = ":";
51     public static final String IP_ADDRESS         = "0.0.0.0";
52     public static final int    IP_PORT            = 0;
53     public static final String GET_COMMAND        = "get_command";
54     public static final String STATE_KEY          = "state_key";
55     public static final String STATE_GET          = "state_get";
56     public static final String LARGE_KEY          = "large_key";
57     public static final String LARGE_GET          = "large_get";
58     public static final String RESOURCE_URI       = "/a/light";
59     public static final String RESOURCE_TYPE      = "core.light";
60     public static final String RESOURCE_INTERFACE = OcPlatform.DEFAULT_INTERFACE;
61     public static final EnumSet<ResourceProperty> RESOURCE_PROPERTIES =
62             EnumSet.of(ResourceProperty.DISCOVERABLE, ResourceProperty.OBSERVABLE);
63
64     // MQ
65     public final static String MQ_DEFAULT_TOPIC_URI = "/oic/ps/cleanroom";
66     public final static String MQ_BROKER_URI = "/oic/ps";
67
68     private static String mLeAddress = null;
69
70     public static String getDateCurrentTimeZone() {
71         StringBuilder sb = new StringBuilder();
72         try {
73             Calendar calendar = Calendar.getInstance();
74             calendar.setTimeInMillis(System.currentTimeMillis());
75             DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
76                     DateFormat.DEFAULT,
77                     Locale.getDefault());
78             Date currentTimeZone = calendar.getTime();
79             sb.append(dateFormat.format(currentTimeZone));
80         } catch (Exception e) {
81             e.printStackTrace();
82         }
83         return sb.toString();
84     }
85
86     public static void showToast(Context context, String msg) {
87         Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
88     }
89
90     public static void setLeAddress(String address)
91     {
92         Log.i(TAG, "setLeAddress : " + address.toString());
93         mLeAddress = address;
94     }
95
96     public static String getLeAddress()
97     {
98         Log.i(TAG, "getLeAddress : " + mLeAddress);
99         return mLeAddress;
100     }
101 }
102