Merge branch '1.1-rel'
[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 final String COAP_TCP           = "coap+tcp://";
44     public static String       TCP_ADDRESS        = "192.168.0.1";
45     public static final String TCP_PORT           = ":8000";
46     public static final String IP_ADDRESS         = "0.0.0.0";
47     public static final int    IP_PORT            = 0;
48     public static final String GET_COMMAND        = "get_command";
49     public static final String STATE_KEY          = "state_key";
50     public static final String STATE_GET          = "state_get";
51     public static final String LARGE_KEY          = "large_key";
52     public static final String LARGE_GET          = "large_get";
53     public static final String RESOURCE_URI       = "/a/light";
54     public static final String RESOURCE_TYPE      = "core.light";
55     public static final String RESOURCE_INTERFACE = OcPlatform.DEFAULT_INTERFACE;
56     public static final EnumSet<ResourceProperty> RESOURCE_PROPERTIES =
57             EnumSet.of(ResourceProperty.DISCOVERABLE, ResourceProperty.OBSERVABLE);
58
59     public static String getDateCurrentTimeZone() {
60         StringBuilder sb = new StringBuilder();
61         try {
62             Calendar calendar = Calendar.getInstance();
63             calendar.setTimeInMillis(System.currentTimeMillis());
64             DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
65                                                                    DateFormat.DEFAULT,
66                                                                    Locale.getDefault());
67             Date currentTimeZone = calendar.getTime();
68             sb.append(dateFormat.format(currentTimeZone));
69         } catch (Exception e) {
70             e.printStackTrace();
71         }
72         return sb.toString();
73     }
74
75     public static void showToast(Context context, String msg) {
76         Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
77     }
78 }