replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / android / examples / simplebase / src / main / java / org / iotivity / base / examples / SimpleBase.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.app.Activity;
26 import android.app.Fragment;
27 import android.content.Intent;
28 import android.nfc.NfcAdapter;
29 import android.os.Bundle;
30 import android.support.v4.widget.DrawerLayout;
31 import android.util.Log;
32
33 /**
34  * SimpleBase is a sample OCF Base layer application.
35  * It can handle message and bluetooth manually.
36  */
37 public class SimpleBase extends Activity implements DrawerFragment.DrawerCallbacks {
38
39     private static final String TAG = "OIC_SIMPLE_BASE";
40     private DrawerFragment      mDrawerFragment;
41
42     private CharSequence        mTitle;
43
44     @Override
45     protected void onCreate(Bundle savedInstanceState) {
46         super.onCreate(savedInstanceState);
47         setContentView(R.layout.activity_simplebase);
48
49         mDrawerFragment = (DrawerFragment) getFragmentManager()
50                 .findFragmentById(R.id.navigation_drawer);
51         mTitle = getTitle();
52
53         mDrawerFragment.setUp(R.id.navigation_drawer,
54                 (DrawerLayout) findViewById(R.id.drawer_layout));
55     }
56
57     @Override
58     public void onDrawerItemSelected(int position) {
59         Fragment fragment;
60         switch (position) {
61             case 0:
62                 mTitle = getString(R.string.title_message);
63                 fragment = new MessageFragment();
64                 break;
65             case 1:
66                 mTitle = getString(R.string.title_bluetooth);
67                 fragment = new BluetoothFragment();
68                 break;
69             case 2:
70                 mTitle = getString(R.string.title_cloud);
71                 fragment = new CloudFragment();
72                 break;
73             case 3:
74                 mTitle = getString(R.string.title_keepalive);
75                 fragment = new KeepAliveFragment();
76                 break;
77             case 4:
78                 mTitle = getString(R.string.title_template);
79                 fragment = new TemplateFragment();
80                 break;
81             default:
82                 mTitle = getString(R.string.title_message);
83                 fragment = new MessageFragment();
84                 break;
85         }
86         getFragmentManager().beginTransaction()
87                             .replace(R.id.container, fragment)
88                             .commit();
89
90         getActionBar().setTitle(mTitle);
91     }
92
93     @Override
94     public void onNewIntent(Intent intent) {
95         super.onNewIntent(intent);
96         Log.d(TAG, "onNewIntent with changes sending broadcast IN ");
97
98         Intent i = new Intent();
99         i.setAction(intent.getAction());
100         i.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES,
101                 intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES));
102         sendBroadcast(i);
103         Log.d(TAG, "Initialize Context again resetting");
104     }
105 }