4eef8a1764ee8a5b19104a885dd6939eafd8086c
[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
28 import org.iotivity.base.OcPlatform;
29 import org.iotivity.base.ResourceProperty;
30
31 import java.text.DateFormat;
32 import java.util.Calendar;
33 import java.util.Date;
34 import java.util.EnumSet;
35 import java.util.Locale;
36
37 /**
38  * This class charge of common part.
39  */
40 public class Common {
41
42     public static final int    DATA_SIZE          = 3000;
43     public static String       HOST               = "coap+tcp://192.168.0.1:5683";
44     public static final String COAP_TCP           = "coap+tcp://";
45     public static final String COAPS_TCP          = "coaps+tcp://";
46     public static String       TCP_ADDRESS        = "192.168.0.1";
47     public static String       TCP_PORT           = "5683";
48     public static final String PORT_SEPARATOR     = ":";
49     public static final String IP_ADDRESS         = "0.0.0.0";
50     public static final int    IP_PORT            = 0;
51     public static final String GET_COMMAND        = "get_command";
52     public static final String STATE_KEY          = "state_key";
53     public static final String STATE_GET          = "state_get";
54     public static final String LARGE_KEY          = "large_key";
55     public static final String LARGE_GET          = "large_get";
56     public static final String RESOURCE_URI       = "/a/light";
57     public static final String RESOURCE_TYPE      = "core.light";
58     public static final String RESOURCE_INTERFACE = OcPlatform.DEFAULT_INTERFACE;
59     public static final EnumSet<ResourceProperty> RESOURCE_PROPERTIES =
60             EnumSet.of(ResourceProperty.DISCOVERABLE, ResourceProperty.OBSERVABLE);
61
62     // MQ
63     public final static String MQ_DEFAULT_TOPIC_URI = "/oic/ps/cleanroom";
64     public final static String MQ_BROKER_URI = "/oic/ps";
65
66     public static String getDateCurrentTimeZone() {
67         StringBuilder sb = new StringBuilder();
68         try {
69             Calendar calendar = Calendar.getInstance();
70             calendar.setTimeInMillis(System.currentTimeMillis());
71             DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
72                     DateFormat.DEFAULT,
73                     Locale.getDefault());
74             Date currentTimeZone = calendar.getTime();
75             sb.append(dateFormat.format(currentTimeZone));
76         } catch (Exception e) {
77             e.printStackTrace();
78         }
79         return sb.toString();
80     }
81
82     public static void showToast(Context context, String msg) {
83         Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
84     }
85 }
86