It can be tested Message and Bluetooth APIs.
Change-Id: I6315c0eba8d22d5c152fbe3de74ad8a1abda387f
Signed-off-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/6137
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
-include ':simpleserver', ':simpleclient', ':fridgeserver', ':fridgeclient', ':guiclient', ':provisioningclient', ':presenceserver', ':presenceclient', ':devicediscoveryclient', ':devicediscoveryserver', ':groupclient', ':groupserver', ':fridgegroupclient', ':fridgegroupserver'
+include ':simpleserver', ':simpleclient', ':fridgeserver', ':fridgeclient', ':guiclient', ':provisioningclient', ':presenceserver', ':presenceclient', ':devicediscoveryclient', ':devicediscoveryserver', ':groupclient', ':groupserver', ':fridgegroupclient', ':fridgegroupserver', ':simplebase'
--- /dev/null
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 21
+ buildToolsVersion "20.0.0"
+
+ defaultConfig {
+ applicationId "org.iotivity.base.examples.simplebase"
+ minSdkVersion 21
+ targetSdkVersion 21
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+ lintOptions {
+ abortOnError false
+ }
+}
+repositories {
+ flatDir {
+ dirs "../../android_api/base/build/outputs/aar/"
+ }
+}
+
+try {
+ dependencies {
+ compile files('libs/android-support-v4.jar')
+ compile ":iotivity-base-${TARGET_ARCH}-${RELEASE}@aar"
+ }
+} catch (all) {
+ print "${ERROR_MSG}"
+ assert all
+}
--- /dev/null
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/iotivity/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":simplebase" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="examples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="android-gradle" name="Android-Gradle">
+ <configuration>
+ <option name="GRADLE_PROJECT_PATH" value=":simplebase" />
+ </configuration>
+ </facet>
+ <facet type="android" name="Android">
+ <configuration>
+ <option name="SELECTED_BUILD_VARIANT" value="debug" />
+ <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+ <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+ <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+ <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
+ <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
+ <afterSyncTasks>
+ <task>generateDebugAndroidTestSources</task>
+ <task>generateDebugSources</task>
+ </afterSyncTasks>
+ <option name="ALLOW_USER_CONFIGURATION" value="false" />
+ <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+ <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+ <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+ <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+ </configuration>
+ </facet>
+ </component>
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+ <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+ <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/reports" />
+ <excludeFolder url="file://$MODULE_DIR$/build/test-results" />
+ <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+ </content>
+ <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" exported="" name="iotivity-base-armeabi-release-" level="project" />
+ <orderEntry type="library" exported="" name="android-android-21" level="project" />
+ </component>
+</module>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.iotivity.base.examples" >
+ <uses-feature android:name="android.hardware.nfc" />
+ <uses-feature
+ android:name="android.hardware.bluetooth_le"
+ android:required="true" />
+
+ <uses-permission android:name="android.permission.BLUETOOTH" />
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+ <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+ <uses-permission android:name="android.permission.NFC" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/iotivityicon"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <activity
+ android:screenOrientation="portrait"
+ android:name=".SimpleBase"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
--- /dev/null
+/*
+ * ******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothGatt;
+import android.bluetooth.BluetoothManager;
+import android.bluetooth.le.BluetoothLeScanner;
+import android.bluetooth.le.ScanCallback;
+import android.bluetooth.le.ScanFilter;
+import android.bluetooth.le.ScanResult;
+import android.bluetooth.le.ScanSettings;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.ParcelUuid;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+import org.iotivity.ca.CaBtPairingInterface;
+import org.iotivity.ca.CaInterface;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
+
+/**
+ * This class is for testing of Bluetooth util.
+ */
+public class BluetoothFragment extends Fragment implements
+ CaInterface.OnBtDeviceFoundListener,
+ CaInterface.OnConnectionManagerStateListener {
+
+ private static final String TAG = "OCF_SIMPLE_BLUETOOTH";
+ private static final String CA_GATT_SERVICE_UUID = "ADE3D529-C784-4F63-A987-EB69F70EE816";
+
+ private Activity mActivity;
+ private Context mContext;
+ private BluetoothAdapter mBluetoothAdapter;
+ private static final int REQUEST_ENABLE_BT = 1;
+ private static final long SCAN_PERIOD = 10000;
+ private BluetoothLeScanner mLEScanner;
+ private ScanSettings mScanSettings;
+ private List<ScanFilter> mScanFilters;
+ private BluetoothGatt mGatt;
+ private ArrayList<String> mItems;
+ private ArrayList<BluetoothDevice> mBluetoothDevices;
+ private ArrayAdapter<String> mAdapters;
+
+ private boolean mIsScanning;
+ private boolean mIsBTSelected;
+
+ private Button mBtButton;
+ private Button mLeButton;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_bluetooth, container, false);
+ mBtButton = (Button) rootView.findViewById(R.id.btn_bt);
+ mBtButton.setOnClickListener(scanButtonListener(true));
+
+ mLeButton = (Button) rootView.findViewById(R.id.btn_le);
+ mLeButton.setOnClickListener(scanButtonListener(false));
+
+ ListView listView = (ListView) rootView.findViewById(R.id.list_view);
+ mItems = new ArrayList<String>();
+ mAdapters = new ArrayAdapter<String>(mActivity, android.R.layout.simple_list_item_1, mItems);
+ listView.setAdapter(mAdapters);
+ listView.setOnItemClickListener(itemClickListener);
+ listView.setOnItemLongClickListener(itemLongClickListener);
+
+ return rootView;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mActivity = getActivity();
+ mContext = mActivity.getBaseContext();
+
+ mBluetoothDevices = new ArrayList<BluetoothDevice>();
+
+ if (!mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
+ Common.showToast(mContext, "BLE Not Supported");
+ }
+ final BluetoothManager bluetoothManager = (BluetoothManager) mActivity
+ .getSystemService(Context.BLUETOOTH_SERVICE);
+ mBluetoothAdapter = bluetoothManager.getAdapter();
+
+ PlatformConfig cfg = new PlatformConfig(mActivity, mContext,
+ ServiceType.IN_PROC,
+ ModeType.CLIENT,
+ Common.IP_ADDRESS,
+ Common.IP_PORT,
+ QualityOfService.LOW);
+
+ OcPlatform.Configure(cfg);
+ CaInterface.startBtPairingService(mContext, this);
+ CaInterface.startManagerService(mContext, this);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
+ Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+ startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
+ } else {
+ if (Build.VERSION.SDK_INT >= 21) {
+ mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
+ if (mScanSettings == null) {
+ mScanSettings = new ScanSettings.Builder()
+ .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
+ .build();
+ }
+
+ if (mScanFilters == null) {
+ mScanFilters = new ArrayList<ScanFilter>();
+ ScanFilter scanFilter = new ScanFilter.Builder()
+ .setServiceUuid(ParcelUuid.fromString(CA_GATT_SERVICE_UUID)).build();
+ mScanFilters.add(scanFilter);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
+ scanLeDevice(false);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ CaInterface.stopBtPairingService();
+ CaInterface.stopManagerService();
+ CaBtPairingInterface.destroyEdrInterface();
+ if (mGatt != null) {
+ mGatt.close();
+ mGatt = null;
+ }
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_ENABLE_BT) {
+ if (resultCode == Activity.RESULT_CANCELED) {
+ mActivity.finish();
+ return;
+ }
+ }
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ View.OnClickListener scanButtonListener(final boolean isBT) {
+ return new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (!mIsScanning) {
+ mItems.clear();
+ mBluetoothDevices.clear();
+ mAdapters.notifyDataSetChanged();
+ mIsBTSelected = isBT;
+ }
+
+ if (isBT) {
+ if (mIsScanning) {
+ // BT Stop
+ try {
+ CaInterface.stopScan();
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ mBtButton.setText(R.string.bt_scan);
+ mLeButton.setVisibility(View.VISIBLE);
+ } else {
+ // BT Scan
+ try {
+ CaInterface.startScan();
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ mBtButton.setText(R.string.stop_scan);
+ mLeButton.setVisibility(View.GONE);
+ }
+ } else {
+ if (mIsScanning) {
+ // LE Stop
+ mLeButton.setText(R.string.le_scan);
+ mBtButton.setVisibility(View.VISIBLE);
+ } else {
+ // LE Scan
+ mLeButton.setText(R.string.stop_scan);
+ mBtButton.setVisibility(View.GONE);
+ }
+ scanLeDevice(!mIsScanning);
+ }
+ mIsScanning = !mIsScanning;
+ }
+ };
+ }
+
+ @Override
+ public synchronized void onBtDeviceFound(BluetoothDevice device) throws OcException {
+ Log.i(TAG, "onBtDeviceFound address : " + device.getAddress());
+
+ addItemToList(device);
+ }
+
+ private AdapterView.OnItemClickListener itemClickListener = new AdapterView
+ .OnItemClickListener() {
+ public void onItemClick(AdapterView<?> adapterView, View clickedView, int pos, long id) {
+ StringBuilder sb = new StringBuilder();
+
+ if (mIsBTSelected) {
+ sb.append("Pairing with : ");
+ try {
+ CaInterface.createBond(mBluetoothDevices.get(pos));
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ } else {
+ sb.append("Set Connect with : ");
+ try {
+ final String address = mBluetoothDevices.get(pos).getAddress();
+ CaInterface.setAutoConnectionDevice(address);
+ OcPlatform.OnResourceFoundListener resourceFoundListener =
+ new OcPlatform.OnResourceFoundListener() {
+ @Override
+ public void onResourceFound(OcResource ocResource) {
+ Log.i(TAG, "onResourceFound : " + ocResource.getUri());
+ }
+ };
+ OcPlatform.findResource("", address + OcPlatform.WELL_KNOWN_QUERY,
+ EnumSet.of(OcConnectivityType.CT_ADAPTER_GATT_BTLE),
+ resourceFoundListener, QualityOfService.LOW);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+ Common.showToast(mContext, sb.append(mItems.get(pos)).toString());
+ }
+ };
+
+ private AdapterView.OnItemLongClickListener itemLongClickListener = new AdapterView
+ .OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView<?> adapterView, View view, int pos, long id) {
+ StringBuilder sb = new StringBuilder();
+
+ if (!mIsBTSelected) {
+ sb.append("Unset Connect with : ");
+ try {
+ CaInterface.unsetAutoConnectionDevice(mBluetoothDevices.get(pos).getAddress());
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+ Common.showToast(mContext, sb.append(mItems.get(pos)).toString());
+
+ return true;
+ }
+ };
+
+ private void scanLeDevice(final boolean enable) {
+ if (enable) {
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mLEScanner.stopScan(mScanCallback);
+ }
+ }, SCAN_PERIOD);
+
+ mLEScanner.startScan(mScanFilters, mScanSettings, mScanCallback);
+ } else {
+ mLEScanner.stopScan(mScanCallback);
+ }
+ }
+
+ private ScanCallback mScanCallback = new ScanCallback() {
+ @Override
+ public void onScanResult(int callbackType, ScanResult result) {
+ Log.i(TAG, "onScanResult : " + result.toString());
+
+ addItemToList(result.getDevice());
+ }
+
+ @Override
+ public void onScanFailed(int errorCode) {
+ Log.e(TAG, "Scan Failed, Error Code : " + errorCode);
+ }
+ };
+
+ private void addItemToList(BluetoothDevice btDevice) {
+ StringBuilder sb = new StringBuilder(btDevice.toString());
+ sb.append(" (");
+ if (btDevice.getName() != null) {
+ sb.append(btDevice.getName().toString());
+ } else {
+ sb.append("NULL");
+ }
+ sb.append(")");
+
+ if (mItems.contains(sb.toString())) {
+ // Duplicate
+ } else {
+ // add item
+ mItems.add(sb.toString());
+ mBluetoothDevices.add(btDevice);
+ mAdapters.notifyDataSetChanged();
+ }
+ }
+
+ @Override
+ public void onAdapterStateChanged(OcConnectivityType type, boolean enabled) {
+ final String msg = getString(R.string.action_onadapterstatechanged) + enabled;
+ Log.i(TAG, msg);
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Common.showToast(mContext, msg);
+ }
+ });
+ }
+
+ @Override
+ public void onConnectionStateChanged(OcConnectivityType type,
+ String address, boolean connected) {
+ Log.i(TAG, "onConnectionStateChanged address: " + address);
+ final String msg = getString(R.string.action_onconnectionstatechanged) + connected;
+ Log.i(TAG, msg);
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Common.showToast(mContext, msg);
+ }
+ });
+ }
+}
--- /dev/null
+/*
+ * ******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base.examples;
+
+import android.content.Context;
+import android.widget.Toast;
+
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.ResourceProperty;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.EnumSet;
+import java.util.Locale;
+
+/**
+ * This class charge of common part.
+ */
+public class Common {
+
+ public static final int DATA_SIZE = 3000;
+ public static final String COAP_TCP = "coap+tcp://";
+ public static String TCP_ADDRESS = "192.168.0.1";
+ public static final String TCP_PORT = ":8000";
+ public static final String IP_ADDRESS = "0.0.0.0";
+ public static final int IP_PORT = 0;
+ public static final String GET_COMMAND = "get_command";
+ public static final String STATE_KEY = "state_key";
+ public static final String STATE_GET = "state_get";
+ public static final String LARGE_KEY = "large_key";
+ public static final String LARGE_GET = "large_get";
+ public static final String RESOURCE_URI = "/a/light";
+ public static final String RESOURCE_TYPE = "core.light";
+ public static final String RESOURCE_INTERFACE = OcPlatform.DEFAULT_INTERFACE;
+ public static final EnumSet<ResourceProperty> RESOURCE_PROPERTIES =
+ EnumSet.of(ResourceProperty.DISCOVERABLE, ResourceProperty.OBSERVABLE);
+
+ public static String getDateCurrentTimeZone() {
+ StringBuilder sb = new StringBuilder();
+ try {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
+ DateFormat.DEFAULT,
+ Locale.getDefault());
+ Date currentTimeZone = calendar.getTime();
+ sb.append(dateFormat.format(currentTimeZone));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return sb.toString();
+ }
+
+ public static void showToast(Context context, String msg) {
+ Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
+ }
+}
--- /dev/null
+/*
+ * ******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base.examples;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.app.Fragment;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.support.v4.app.ActionBarDrawerToggle;
+import android.support.v4.view.GravityCompat;
+import android.support.v4.widget.DrawerLayout;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+/**
+ * Through a drawer able to move to another menu.
+ */
+public class DrawerFragment extends Fragment {
+
+ private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
+ private DrawerCallbacks mCallbacks;
+
+ private ActionBarDrawerToggle mDrawerToggle;
+
+ private DrawerLayout mDrawerLayout;
+ private ListView mDrawerListView;
+ private View mFragmentContainerView;
+
+ private int mCurrentSelectedPosition = 0;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (savedInstanceState != null) {
+ mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
+ }
+
+ selectItem(mCurrentSelectedPosition);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ mDrawerListView = (ListView) inflater.inflate(R.layout.fragment_drawer,
+ container, false);
+ mDrawerListView
+ .setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view,
+ int position, long id) {
+ selectItem(position);
+ }
+ });
+ mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar()
+ .getThemedContext(),
+ android.R.layout.simple_list_item_activated_1,
+ android.R.id.text1, new String[] {
+ getString(R.string.title_message),
+ getString(R.string.title_bluetooth),
+ getString(R.string.title_template), }));
+ mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
+
+ return mDrawerListView;
+ }
+
+ public void setUp(int fragmentId, DrawerLayout drawerLayout) {
+ mFragmentContainerView = getActivity().findViewById(fragmentId);
+ mDrawerLayout = drawerLayout;
+
+ mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
+ GravityCompat.START);
+
+ ActionBar actionBar = getActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setHomeButtonEnabled(true);
+ mDrawerToggle = new ActionBarDrawerToggle(getActivity(),
+ mDrawerLayout,
+ R.drawable.ic_drawer,
+ R.string.navigation_drawer_open,
+ R.string.navigation_drawer_close) {
+ @Override
+ public void onDrawerClosed(View drawerView) {
+ super.onDrawerClosed(drawerView);
+ if (!isAdded()) {
+ return;
+ }
+
+ getActivity().invalidateOptionsMenu();
+ }
+
+ @Override
+ public void onDrawerOpened(View drawerView) {
+ super.onDrawerOpened(drawerView);
+ if (!isAdded()) {
+ return;
+ }
+
+ getActivity().invalidateOptionsMenu();
+ }
+ };
+
+ mDrawerLayout.post(new Runnable() {
+ @Override
+ public void run() {
+ mDrawerToggle.syncState();
+ }
+ });
+
+ mDrawerLayout.setDrawerListener(mDrawerToggle);
+ }
+
+ private void selectItem(int position) {
+ mCurrentSelectedPosition = position;
+ if (mDrawerListView != null) {
+ mDrawerListView.setItemChecked(position, true);
+ }
+ if (mDrawerLayout != null) {
+ mDrawerLayout.closeDrawer(mFragmentContainerView);
+ }
+ if (mCallbacks != null) {
+ mCallbacks.onDrawerItemSelected(position);
+ }
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ mCallbacks = (DrawerCallbacks) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException("Activity must implement DrawerCallbacks.");
+ }
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mCallbacks = null;
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ mDrawerToggle.onConfigurationChanged(newConfig);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (mDrawerToggle.onOptionsItemSelected(item)) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ private ActionBar getActionBar() {
+ return getActivity().getActionBar();
+ }
+
+ public static interface DrawerCallbacks {
+ void onDrawerItemSelected(int position);
+ }
+}
--- /dev/null
+/*
+ * ******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Fragment;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.nfc.NfcAdapter;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.ToggleButton;
+
+import org.iotivity.base.EntityHandlerResult;
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.OcResourceHandle;
+import org.iotivity.base.OcResourceRequest;
+import org.iotivity.base.OcResourceResponse;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+import org.iotivity.ca.CaEdrInterface;
+import org.iotivity.ca.CaIpInterface;
+import org.iotivity.ca.CaLeClientInterface;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class is for messaging between the server and the client.
+ * It can handle message manually.
+ */
+public class MessageFragment extends Fragment implements OcResource.OnGetListener,
+ OcResource.OnPutListener {
+
+ private static final String TAG = "OIC_SIMPLE_MESSAGE";
+ private final String EOL = System.getProperties().getProperty("line.separator");
+ private final double MILLI_PER_SEC = 1000.0;
+
+ private Activity mActivity;
+ private Context mContext;
+
+ OcPlatform.EntityHandler mEntityHandler;
+ private OcResourceHandle mResourceHandle;
+ private OcResource mFoundResource;
+
+ private QualityOfService mQos = QualityOfService.LOW;
+
+ private LinearLayout mServerLayout;
+ private LinearLayout mClientLayout;
+ private TextView mResourceText;
+ private TextView mActionLog;
+ private TextView mResultLog;
+ private ToggleButton mQosToggle;
+ private Button mRegisterButton;
+ private Button mGetButton;
+ private Button mPutButton;
+ private Button mLargeButton;
+ private Button mDiscoverIPButton;
+ private Button mDiscoverBTButton;
+ private Button mDiscoverLEButton;
+ private Button mDiscoverTCPButton;
+ private Button mDiscoverNFCButton;
+
+ private String mLargeData;
+ private boolean mState;
+ private long mStartTime;
+ private long mEndTime;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mActivity = getActivity();
+ mContext = mActivity.getBaseContext();
+ }
+
+ View.OnClickListener getButtonListener() {
+ return new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (mFoundResource != null) {
+ mStartTime = System.currentTimeMillis();
+ sendGetToFoundResource(Common.STATE_GET);
+ } else {
+ Common.showToast(mContext, "Please discovery first");
+ Log.e(TAG, "get() : resource is null");
+ }
+ }
+ };
+ }
+
+ View.OnClickListener putButtonListener() {
+ return new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (mFoundResource != null) {
+ mStartTime = System.currentTimeMillis();
+ sendPutToFoundResource();
+ } else {
+ Common.showToast(mContext, "Please discovery first");
+ Log.e(TAG, "put() : resource is null");
+ }
+ }
+ };
+ }
+
+ View.OnClickListener getLargeListener() {
+ return new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (mFoundResource != null) {
+ mStartTime = System.currentTimeMillis();
+ sendGetToFoundResource(Common.LARGE_GET);
+ } else {
+ Common.showToast(mContext, "Please discovery first");
+ Log.e(TAG, "large() : resource is null");
+ }
+ }
+ };
+ }
+
+ View.OnClickListener discoverButtonListener(
+ final OcConnectivityType connectivityType) {
+ return new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ initOcPlatform(ModeType.CLIENT);
+ mFoundResource = null;
+
+ if (OcConnectivityType.CT_ADAPTER_TCP == connectivityType) {
+ showTCPInput();
+ } else {
+ try {
+ Log.i(TAG, "discoverButtonListener");
+ OcPlatform.findResource("",
+ OcPlatform.WELL_KNOWN_QUERY,
+ EnumSet.of(connectivityType),
+ resourceFoundListener, mQos);
+
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mActionLog.setText("[Action Log]" + EOL);
+ mActionLog.append("Find resource()" + EOL);
+ mActionLog.append("Connectivity : " + connectivityType + EOL);
+
+ mResultLog.setText("[Result Log]" + EOL);
+ mResultLog.append("Start Time : ");
+ mResultLog.append(Common.getDateCurrentTimeZone() + EOL);
+ mStartTime = System.currentTimeMillis();
+ }
+ });
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+ mServerLayout.setVisibility(View.GONE);
+ }
+ };
+ }
+
+ void makeTCPResource(String address) {
+
+ List<String> resourceTypeList = new ArrayList<String>();
+ List<String> resourceInterfaceList = new ArrayList<String>();
+ resourceInterfaceList.add(Common.RESOURCE_INTERFACE);
+ resourceTypeList.add(Common.RESOURCE_TYPE);
+ try {
+ mFoundResource = OcPlatform.constructResourceObject(address,
+ Common.RESOURCE_URI,
+ EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP), false,
+ resourceTypeList, resourceInterfaceList);
+
+ mActionLog.setText("[Action Log]" + EOL);
+ mActionLog.append("Found resource()" + EOL);
+ mActionLog.append("Connectivity : " + OcConnectivityType.CT_ADAPTER_TCP + EOL);
+ mActionLog.append(mFoundResource.getHost() + Common.RESOURCE_URI);
+
+ mResultLog.setText("[Result Log]" + EOL);
+
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ void sendGetToFoundResource(String command) {
+ try {
+ Log.i(TAG, "sendGetToFoundResource");
+
+ Map<String, String> queryParameters = new HashMap<String, String>();
+ queryParameters.put(Common.GET_COMMAND, command);
+
+ mFoundResource.get(queryParameters, this, mQos);
+
+ mActionLog.setText("[Action Log]" + EOL + "Send get()"+ EOL + "To : ");
+ mActionLog.append(mFoundResource.getHost() + mFoundResource.getUri() + EOL);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ void sendPutToFoundResource() {
+ try {
+ Log.i(TAG, "sendPutToFoundResource");
+
+ OcRepresentation rep = new OcRepresentation();
+ rep.setValue(Common.STATE_KEY, !mState);
+
+ Map<String, String> queryParams = new HashMap<>();
+
+ mFoundResource.put(rep, queryParams, this);
+ mActionLog.setText("[Action Log]" + EOL);
+ mActionLog.append("Send put()" + EOL + "To : ");
+ mActionLog.append(mFoundResource.getHost() + mFoundResource.getUri() + EOL);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ OcPlatform.OnResourceFoundListener resourceFoundListener =
+ new OcPlatform.OnResourceFoundListener() {
+ @Override
+ public void onResourceFound(OcResource ocResource) {
+ synchronized (mActivity) {
+ final String resourceUri = ocResource.getUri();
+ Log.i(TAG, "onResourceFound : " + ocResource.getUri());
+
+ if (resourceUri.contains(Common.RESOURCE_URI)) {
+ mFoundResource = ocResource;
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mEndTime = System.currentTimeMillis();
+ double flightTime = (double) (mEndTime - mStartTime) / MILLI_PER_SEC;
+ mResultLog.append("Discovery Time : ");
+ mResultLog.append(String.format("%.3f", flightTime) + "sec" + EOL);
+ mActionLog.append(mFoundResource.getHost() + resourceUri + EOL);
+ }
+ });
+ }
+ }
+ }
+ };
+
+ @Override
+ public void onGetCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {
+ String repUri = ocRepresentation.getUri();
+ Log.i(TAG, "onGetCompleted : " + repUri);
+
+ try {
+ final String command = ocRepresentation.getValue(Common.GET_COMMAND);
+
+ if (command == null || command.isEmpty()) {
+ Log.e(TAG, "Get command is null");
+ return;
+ } else if (command.equals(Common.STATE_GET)) {
+ mState = ocRepresentation.getValue(Common.STATE_KEY);
+ mLargeData = "";
+ } else if (command.equals(Common.LARGE_GET)) {
+ mLargeData = ocRepresentation.getValue(Common.LARGE_KEY);
+ }
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mEndTime = System.currentTimeMillis();
+ double flightTime = (double) (mEndTime - mStartTime) / MILLI_PER_SEC;
+
+ if (mLargeData == null || mLargeData.isEmpty()) {
+ mResultLog.append(EOL + "Get Light State : " + mState + EOL);
+ } else {
+ mResultLog.append(EOL + "Payload Size : " + mLargeData.length() + EOL);
+ }
+
+ mResultLog.append("Get Time : " + String.format("%.3f", flightTime) + "sec" + EOL);
+ }
+ });
+ }
+
+ @Override
+ public void onGetFailed(Throwable throwable) {
+ Log.e(TAG, "Get failed");
+ }
+
+ @Override
+ public void onPutCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {
+ String repUri = ocRepresentation.getUri();
+ Log.i(TAG, "onPutCompleted : " + repUri);
+
+ try {
+ mState = ocRepresentation.getValue(Common.STATE_KEY);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mEndTime = System.currentTimeMillis();
+ double flightTime = (double) (mEndTime - mStartTime) / MILLI_PER_SEC;
+ mResultLog.append(EOL + "Set Light State : " + !mState + EOL + "Put Time : ");
+ mResultLog.append(String.format("%.3f", flightTime) + "sec" + EOL);
+ }
+ });
+ }
+
+ @Override
+ public void onPutFailed(Throwable throwable) {
+ Log.e(TAG, "Put failed");
+ }
+
+ // ******************************************************************************
+ // End of the OCF Client specific code
+ // ******************************************************************************
+
+ private void createResource() {
+ mEntityHandler = new OcPlatform.EntityHandler() {
+ @Override
+ public EntityHandlerResult handleEntity(
+ OcResourceRequest ocResourceRequest) {
+ return mEntityHandler(ocResourceRequest);
+ }
+ };
+
+ try {
+ mResourceHandle = OcPlatform.registerResource(Common.RESOURCE_URI,
+ Common.RESOURCE_TYPE, Common.RESOURCE_INTERFACE,
+ mEntityHandler, Common.RESOURCE_PROPERTIES);
+
+ } catch (OcException e) {
+ String errString = "Error : " + e.getErrorCode().toString();
+ Log.e(TAG, errString);
+ StringWriter sw = new StringWriter();
+ e.printStackTrace(new PrintWriter(sw));
+ String exceptionAsString = sw.toString();
+ Log.e(TAG, exceptionAsString);
+ mResourceText.setText(errString);
+ }
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < Common.DATA_SIZE; i++) {
+ sb.append('j');
+ }
+ mLargeData = sb.toString();
+
+ sb.setLength(0);
+ sb.append("URI : " + Common.RESOURCE_URI + EOL);
+ sb.append("Type : " + Common.RESOURCE_TYPE + EOL);
+ sb.append("Interface : " + Common.RESOURCE_INTERFACE + EOL);
+ sb.append("Properties : " + Common.RESOURCE_PROPERTIES.toString() + EOL);
+ mResourceText.setText(sb.toString());
+ mActionLog.setText("");
+ mResultLog.setText("Created resource" + EOL);
+ }
+
+ protected EntityHandlerResult mEntityHandler(OcResourceRequest ocResourceRequest) {
+ EntityHandlerResult result = EntityHandlerResult.ERROR;
+ final StringBuilder sb = new StringBuilder();
+ switch (ocResourceRequest.getRequestType()) {
+ case GET:
+ sb.append("Type : GET");
+ if (sendGetResponse(ocResourceRequest)) {
+ result = EntityHandlerResult.OK;
+ }
+ break;
+ case PUT:
+ sb.append("Type : PUT");
+ if (sendPutResponse(ocResourceRequest)) {
+ result = EntityHandlerResult.OK;
+ }
+ break;
+ case DELETE:
+ sb.append("Type : DELETE");
+ break;
+ case POST:
+ sb.append("Type : POST");
+ break;
+ default:
+ break;
+ }
+ sb.append(EOL + "Light State : " + mState);
+ sb.append(EOL + "Time : " + Common.getDateCurrentTimeZone());
+ if (result == EntityHandlerResult.ERROR) {
+ sb.append(EOL + "!! Error occurred during sending the response !!");
+ }
+
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mResultLog.setText(sb.toString());
+ }
+ });
+
+ return result;
+ }
+
+ private boolean sendGetResponse(OcResourceRequest ocResourceRequest) {
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Common.showToast(mContext, "received get command, send response");
+ }
+ });
+
+ Map<String, String> queryParameters = ocResourceRequest.getQueryParameters();
+ final String command = queryParameters.get(Common.GET_COMMAND);
+
+ if (command == null
+ || (!command.equals(Common.STATE_GET) && !command.equals(Common.LARGE_GET))) {
+ return false;
+ }
+
+ OcRepresentation rep = new OcRepresentation();
+ try {
+ rep.setValue(Common.GET_COMMAND, command);
+ if (command.equals(Common.STATE_GET)) {
+ rep.setValue(Common.STATE_KEY, mState);
+ } else if (command.equals(Common.LARGE_GET)) {
+ rep.setValue(Common.LARGE_KEY, mLargeData);
+ }
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+
+ OcResourceResponse response = new OcResourceResponse();
+
+ response.setRequestHandle(ocResourceRequest.getRequestHandle());
+ response.setResourceHandle(ocResourceRequest.getResourceHandle());
+ response.setResourceRepresentation(rep);
+ try {
+ OcPlatform.sendResponse(response);
+ return true;
+ } catch (OcException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ private boolean sendPutResponse(OcResourceRequest ocResourceRequest) {
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Common.showToast(mContext, "received put command, send response");
+ }
+ });
+
+ try {
+ OcRepresentation rep = ocResourceRequest.getResourceRepresentation();
+ if (rep.hasAttribute(Common.STATE_KEY)) {
+ mState = rep.getValue(Common.STATE_KEY);
+ }
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+
+ OcResourceResponse response = new OcResourceResponse();
+ OcRepresentation rep = new OcRepresentation();
+
+ response.setRequestHandle(ocResourceRequest.getRequestHandle());
+ response.setResourceHandle(ocResourceRequest.getResourceHandle());
+ response.setResourceRepresentation(rep);
+ try {
+ OcPlatform.sendResponse(response);
+ return true;
+ } catch (OcException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ // ******************************************************************************
+ // End of the OCF Server specific code
+ // ******************************************************************************
+
+ private void initOcPlatform(ModeType type) {
+ PlatformConfig cfg = new PlatformConfig(mActivity, mContext,
+ ServiceType.IN_PROC,
+ type,
+ Common.IP_ADDRESS,
+ Common.IP_PORT,
+ mQos);
+ OcPlatform.Configure(cfg);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_message, container, false);
+
+ mServerLayout = (LinearLayout) rootView.findViewById(R.id.server_layout);
+ mClientLayout = (LinearLayout) rootView.findViewById(R.id.client_layout);
+
+ mResourceText = (TextView) rootView.findViewById(R.id.resource_view);
+ mActionLog = (TextView) rootView.findViewById(R.id.action_log_view);
+ mResultLog = (TextView) rootView.findViewById(R.id.result_log_view);
+
+ mDiscoverIPButton = (Button) rootView.findViewById(R.id.ip_button);
+ mDiscoverBTButton = (Button) rootView.findViewById(R.id.bt_button);
+ mDiscoverLEButton = (Button) rootView.findViewById(R.id.le_button);
+ mDiscoverTCPButton = (Button) rootView.findViewById(R.id.tcp_button);
+ mDiscoverNFCButton = (Button) rootView.findViewById(R.id.nfc_button);
+
+ mRegisterButton = (Button) rootView.findViewById(R.id.register_button);
+ mGetButton = (Button) rootView.findViewById(R.id.get_button);
+ mPutButton = (Button) rootView.findViewById(R.id.put_button);
+ mLargeButton = (Button) rootView.findViewById(R.id.large_button);
+
+ mQosToggle = (ToggleButton) rootView.findViewById(R.id.qos_toggle_button);
+
+ mDiscoverIPButton.setOnClickListener(
+ discoverButtonListener(OcConnectivityType.CT_ADAPTER_IP));
+ mDiscoverBTButton.setOnClickListener(
+ discoverButtonListener(OcConnectivityType.CT_ADAPTER_RFCOMM_BTEDR));
+ mDiscoverLEButton.setOnClickListener(
+ discoverButtonListener(OcConnectivityType.CT_ADAPTER_GATT_BTLE));
+ mDiscoverTCPButton.setOnClickListener(
+ discoverButtonListener(OcConnectivityType.CT_ADAPTER_TCP));
+ mDiscoverNFCButton.setOnClickListener(
+ discoverButtonListener(OcConnectivityType.CT_ADAPTER_NFC));
+
+ mRegisterButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (mResourceHandle == null) {
+ initOcPlatform(ModeType.SERVER);
+ createResource();
+ mClientLayout.setVisibility(View.GONE);
+ } else {
+ Common.showToast(mContext, "Already created resource");
+ }
+ }
+ });
+ mGetButton.setOnClickListener(getButtonListener());
+ mPutButton.setOnClickListener(putButtonListener());
+ mLargeButton.setOnClickListener(getLargeListener());
+
+ mQosToggle
+ .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+ if (b) {
+ mQos = QualityOfService.HIGH;
+ } else {
+ mQos = QualityOfService.LOW;
+ }
+ }
+ });
+
+ return rootView;
+ }
+
+ private void showTCPInput() {
+
+ LayoutInflater layoutInflater = LayoutInflater.from(mContext);
+ View inputView = layoutInflater.inflate(R.layout.tcp_input, null);
+ AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mActivity);
+ alertDialogBuilder.setView(inputView);
+
+ final EditText editText = (EditText) inputView.getRootView().findViewById(R.id.ipText);
+ editText.setText(Common.TCP_ADDRESS);
+ alertDialogBuilder
+ .setCancelable(false)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ if (editText.getText().length() != 0) {
+ Common.TCP_ADDRESS = editText.getText().toString();
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(Common.COAP_TCP);
+ sb.append(Common.TCP_ADDRESS);
+ sb.append(Common.TCP_PORT);
+ makeTCPResource(sb.toString());
+ }
+ }
+ })
+ .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+
+ AlertDialog alert = alertDialogBuilder.create();
+ alert.show();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+}
--- /dev/null
+/*
+ * ******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.content.Intent;
+import android.nfc.NfcAdapter;
+import android.os.Bundle;
+import android.support.v4.widget.DrawerLayout;
+import android.util.Log;
+
+/**
+ * SimpleBase is a sample OCF Base layer application.
+ * It can handle message and bluetooth manually.
+ */
+public class SimpleBase extends Activity implements DrawerFragment.DrawerCallbacks {
+
+ private static final String TAG = "OIC_SIMPLE_BASE";
+ private DrawerFragment mDrawerFragment;
+
+ private CharSequence mTitle;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_simplebase);
+
+ mDrawerFragment = (DrawerFragment) getFragmentManager()
+ .findFragmentById(R.id.navigation_drawer);
+ mTitle = getTitle();
+
+ mDrawerFragment.setUp(R.id.navigation_drawer,
+ (DrawerLayout) findViewById(R.id.drawer_layout));
+ }
+
+ @Override
+ public void onDrawerItemSelected(int position) {
+ Fragment fragment;
+ switch (position) {
+ case 0:
+ mTitle = getString(R.string.title_message);
+ fragment = new MessageFragment();
+ break;
+ case 1:
+ mTitle = getString(R.string.title_bluetooth);
+ fragment = new BluetoothFragment();
+ break;
+ case 2:
+ mTitle = getString(R.string.title_template);
+ fragment = new TemplateFragment();
+ break;
+ default:
+ mTitle = getString(R.string.title_message);
+ fragment = new MessageFragment();
+ break;
+ }
+ getFragmentManager().beginTransaction()
+ .replace(R.id.container, fragment)
+ .commit();
+
+ getActionBar().setTitle(mTitle);
+ }
+
+ @Override
+ public void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ Log.d(TAG, "onNewIntent with changes sending broadcast IN ");
+
+ Intent i = new Intent();
+ i.setAction(intent.getAction());
+ i.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES,
+ intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES));
+ sendBroadcast(i);
+ Log.d(TAG, "Initialize Context again resetting");
+ }
+}
--- /dev/null
+/*
+ * ******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+/**
+ * This class the template for the test.
+ */
+public class TemplateFragment extends Fragment implements View.OnClickListener {
+
+ private Activity mActivity;
+ private Context mContext;
+
+ Button buttonA;
+ Button buttonB;
+ Button buttonC;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_template, container, false);
+
+ buttonA = (Button) rootView.findViewById(R.id.btn_A);
+ buttonB = (Button) rootView.findViewById(R.id.btn_B);
+ buttonC = (Button) rootView.findViewById(R.id.btn_C);
+
+ buttonA.setOnClickListener(this);
+ buttonB.setOnClickListener(this);
+ buttonC.setOnClickListener(this);
+
+ return rootView;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mActivity = getActivity();
+ mContext = mActivity.getBaseContext();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public void onClick(View view) {
+ StringBuilder sb = new StringBuilder(getString(R.string.action_onclick));
+ switch (view.getId()) {
+ case R.id.btn_A:
+ sb.append(getString(R.string.button_A));
+ break;
+ case R.id.btn_B:
+ sb.append(getString(R.string.button_B));
+ break;
+ case R.id.btn_C:
+ sb.append(getString(R.string.button_C));
+ break;
+ }
+ Common.showToast(mContext, sb.toString());
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:id="@+id/drawer_layout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".SimpleBase" >
+
+ <FrameLayout
+ android:id="@+id/container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+ <fragment
+ android:id="@+id/navigation_drawer"
+ android:name="org.iotivity.base.examples.DrawerFragment"
+ android:layout_width="@dimen/navigation_drawer_width"
+ android:layout_height="match_parent"
+ android:layout_gravity="start"
+ tools:layout="@layout/fragment_drawer" />
+
+</android.support.v4.widget.DrawerLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context=".BluetoothFragment" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:gravity="center_horizontal"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/btn_bt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="10dp"
+ android:layout_weight="1"
+ android:text="@string/bt_scan" />
+
+ <Button
+ android:id="@+id/btn_le"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="10dp"
+ android:layout_weight="1"
+ android:text="@string/le_scan" />
+ </LinearLayout>
+
+ <ListView
+ android:id="@+id/list_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:choiceMode="singleChoice"
+ android:divider="#cfcfcf"
+ android:dividerHeight="1.5dp" />
+ </LinearLayout>
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<ListView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#cccc"
+ android:choiceMode="singleChoice"
+ android:divider="@android:color/transparent"
+ android:dividerHeight="0dp"
+ tools:context=".DrawerFragment" />
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="0dp"
+ android:paddingRight="0dp"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context=".MessageFragment" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:id="@+id/server_layout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:focusable="true"
+ android:focusableInTouchMode="true"
+ android:gravity="center_horizontal"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="#AAAAAA"
+ android:gravity="center_vertical"
+ android:paddingLeft="10dp"
+ android:text="Resource Server Information"
+ android:textColor="#FFFFFF"
+ android:textSize="14sp" />
+
+ <TextView
+ android:id="@+id/resource_view"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingBottom="20dp"
+ android:paddingLeft="20dp"
+ android:paddingTop="5dp"
+ android:text="@string/resource_view" />
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="#AAAAAA"
+ android:gravity="center_vertical"
+ android:paddingLeft="10dp"
+ android:text="Server Buttons"
+ android:textColor="#FFFFFF"
+ android:textSize="14sp" />
+
+ <Button
+ android:id="@+id/register_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginLeft="6dp"
+ android:layout_marginTop="10dp"
+ android:text="Register Resource" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/client_layout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:focusable="true"
+ android:focusableInTouchMode="true"
+ android:gravity="center_horizontal"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="#AAAAAA"
+ android:gravity="center_vertical"
+ android:paddingLeft="10dp"
+ android:text="Client Buttons"
+ android:textColor="#FFFFFF"
+ android:textSize="14sp" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="10dp"
+ android:gravity="center_horizontal"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/ip_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_weight="1"
+ android:text="IP" />
+
+ <Button
+ android:id="@+id/bt_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_weight="1"
+ android:text="BT" />
+
+ <Button
+ android:id="@+id/le_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_weight="1"
+ android:text="LE" />
+
+ <Button
+ android:id="@+id/tcp_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_weight="1"
+ android:text="TCP/IP" />
+
+ <Button
+ android:id="@+id/nfc_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_weight="1"
+ android:text="NFC" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginBottom="10dp"
+ android:gravity="center_horizontal"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/get_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="Get()" />
+
+ <Button
+ android:id="@+id/put_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="Put()" />
+
+ <Button
+ android:id="@+id/large_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="Large()" />
+
+ <TextView
+ android:id="@+id/textView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_marginLeft="10dp"
+ android:text="QoS:"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ <ToggleButton
+ android:id="@+id/qos_toggle_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:checked="false"
+ android:text="QoS Toggle Button"
+ android:textOff="NON"
+ android:textOn="CON"
+ android:textSize="12sp" />
+ </LinearLayout>
+ </LinearLayout>
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="#AAAAAA"
+ android:gravity="center_vertical"
+ android:paddingLeft="10dp"
+ android:text="Log"
+ android:textColor="#FFFFFF"
+ android:textSize="14sp" />
+
+ <TextView
+ android:id="@+id/action_log_view"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingBottom="5dp"
+ android:paddingLeft="20dp"
+ android:paddingTop="5dp"
+ android:text="@string/action_log_view" />
+
+ <ScrollView
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <TextView
+ android:id="@+id/result_log_view"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingLeft="20dp"
+ android:paddingTop="5dp"
+ android:text="@string/result_log_view" />
+ </ScrollView>
+ </LinearLayout>
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context=".TemplateFragment" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <Button
+ android:id="@+id/btn_A"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="10dp"
+ android:text="@string/button_A" />
+
+ <Button
+ android:id="@+id/btn_B"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="10dp"
+ android:text="@string/button_B" />
+
+ <Button
+ android:id="@+id/btn_C"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="10dp"
+ android:text="@string/button_C" />
+ </LinearLayout>
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:padding="@dimen/activity_vertical_margin" >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Input Server IP"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <EditText
+ android:id="@+id/ipText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="@dimen/activity_vertical_margin" />
+
+</LinearLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="AppTheme" parent="android:Theme.Material.Light">
+ </style>
+</resources>
--- /dev/null
+<resources>
+ <!-- Example customization of dimensions originally defined in res/values/dimens.xml
+ (such as screen margins) for screens with more than 820dp of available width. This
+ would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
+ <dimen name="activity_horizontal_margin">64dp</dimen>
+</resources>
--- /dev/null
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+
+ <dimen name="navigation_drawer_width">240dp</dimen>
+</resources>
--- /dev/null
+<resources>
+ <string name="app_name">Simple Base</string>
+
+ <string name="title_message">Message</string>
+ <string name="title_bluetooth">Bluetooth</string>
+ <string name="title_template">Template</string>
+
+ <string name="resource_view">[Resource View]</string>
+ <string name="action_log_view">[Action Log View]</string>
+ <string name="result_log_view">[Result Log View]</string>
+
+ <string name="bt_scan">BT SCAN</string>
+ <string name="le_scan">LE SCAN</string>
+ <string name="stop_scan">STOP SCAN</string>
+
+ <string name="action_onadapterstatechanged">onAdapterStateChanged : </string>
+ <string name="action_onconnectionstatechanged">onConnectionStateChanged : </string>
+ <string name="action_onclick">onClick : </string>
+
+ <string name="button_A">Button A</string>
+ <string name="button_B">Button B</string>
+ <string name="button_C">Button C</string>
+
+ <string name="navigation_drawer_open">Open navigation drawer</string>
+ <string name="navigation_drawer_close">Close navigation drawer</string>
+</resources>
--- /dev/null
+<resources>
+
+ <!-- Base application theme. -->
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+ <!-- Customize your theme here. -->
+ </style>
+
+</resources>