-/*\r
- * //******************************************************************\r
- * //\r
- * // Copyright 2015 Intel Corporation.\r
- * //\r
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- * //\r
- * // Licensed under the Apache License, Version 2.0 (the "License");\r
- * // you may not use this file except in compliance with the License.\r
- * // You may obtain a copy of the License at\r
- * //\r
- * // http://www.apache.org/licenses/LICENSE-2.0\r
- * //\r
- * // Unless required by applicable law or agreed to in writing, software\r
- * // distributed under the License is distributed on an "AS IS" BASIS,\r
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * // See the License for the specific language governing permissions and\r
- * // limitations under the License.\r
- * //\r
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- */\r
-\r
-package org.iotivity.base.examples.fridgeserver;\r
-\r
-import android.app.Activity;\r
-import android.content.BroadcastReceiver;\r
-import android.content.Context;\r
-import android.content.Intent;\r
-import android.content.IntentFilter;\r
-import android.os.Bundle;\r
-import android.os.Message;\r
-import android.support.v4.content.LocalBroadcastManager;\r
-import android.text.method.ScrollingMovementMethod;\r
-import android.util.Log;\r
-import android.view.Menu;\r
-import android.view.MenuItem;\r
-import android.widget.LinearLayout;\r
-import android.widget.TextView;\r
-\r
-import org.iotivity.base.ModeType;\r
-import org.iotivity.base.OcPlatform;\r
-import org.iotivity.base.PlatformConfig;\r
-import org.iotivity.base.QualityOfService;\r
-import org.iotivity.base.ServiceType;\r
-\r
-import base.iotivity.org.examples.message.IMessageLogger;\r
-\r
-/**\r
- * FridgeServer\r
- * <p/>\r
- * This is the main fridgeServer class. This instantiates Refrigerator object\r
- * which has different resources (DeviceResource, LightResource, DoorResource).\r
- */\r
-public class FridgeServer extends Activity implements IMessageLogger {\r
- private Context mContext;\r
- private static String TAG = "FridgeServer: ";\r
- private TextView mEventsTextView;\r
- private MessageReceiver mMessageReceiver = new MessageReceiver();\r
- private Refrigerator refrigerator;\r
-\r
- /**\r
- * configure OIC platform and call findResource\r
- */\r
- private void initOICStack() {\r
- //create platform config\r
- PlatformConfig cfg = new PlatformConfig(\r
- this,\r
- ServiceType.IN_PROC,\r
- ModeType.SERVER,\r
- "0.0.0.0", // bind to all available interfaces\r
- 0,\r
- QualityOfService.LOW);\r
- OcPlatform.Configure(cfg);\r
- logMessage(TAG + "Creating refrigerator resources");\r
-\r
- refrigerator = new Refrigerator(mContext);\r
- }\r
-\r
- @Override\r
- protected void onCreate(Bundle savedInstanceState) {\r
- super.onCreate(savedInstanceState);\r
- setContentView(R.layout.activity_fridge_server);\r
- registerReceiver(mMessageReceiver, new IntentFilter(StringConstants.INTENT));\r
-\r
- mEventsTextView = new TextView(this);\r
- mEventsTextView.setMovementMethod(new ScrollingMovementMethod());\r
- LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);\r
- layout.addView(mEventsTextView, new LinearLayout.LayoutParams\r
- (LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f));\r
- mContext = this;\r
-\r
- initOICStack();\r
- }\r
-\r
- public class MessageReceiver extends BroadcastReceiver {\r
- @Override\r
- public void onReceive(Context context, Intent intent) {\r
- final String message = intent.getStringExtra(StringConstants.MESSAGE);\r
- logMessage(message);\r
- }\r
- }\r
-\r
- @Override\r
- public void logMessage(final String text) {\r
- if (StringConstants.ENABLE_PRINTING) {\r
- runOnUiThread(new Runnable() {\r
- public void run() {\r
- final Message msg = new Message();\r
- msg.obj = text;\r
- mEventsTextView.append("\n");\r
- mEventsTextView.append(text);\r
- }\r
- });\r
- Log.i(TAG, text);\r
- }\r
- }\r
-\r
- @Override\r
- public boolean onCreateOptionsMenu(Menu menu) {\r
- // Inflate the menu; this adds items to the action bar if it is present.\r
- getMenuInflater().inflate(R.menu.menu_fridge_server, menu);\r
- return true;\r
- }\r
-\r
- @Override\r
- public boolean onOptionsItemSelected(MenuItem item) {\r
- int id = item.getItemId();\r
- if (id == R.id.action_settings) {\r
- return true;\r
- }\r
- return super.onOptionsItemSelected(item);\r
- }\r
-\r
- @Override\r
- public void onDestroy() {\r
- super.onDestroy();\r
- onStop();\r
- }\r
-\r
- @Override\r
- protected void onStop() {\r
- LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);\r
- super.onStop();\r
- }\r
-}\r
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // 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.fridgeserver;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.os.Message;
+import android.support.v4.content.LocalBroadcastManager;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+
+import base.iotivity.org.examples.message.IMessageLogger;
+
+/**
+ * FridgeServer
+ * <p/>
+ * This is the main fridgeServer class. This instantiates Refrigerator object
+ * which has different resources (DeviceResource, LightResource, DoorResource).
+ */
+public class FridgeServer extends Activity implements IMessageLogger {
+ private Context mContext;
+ private static String TAG = "FridgeServer: ";
+ private TextView mEventsTextView;
+ private MessageReceiver mMessageReceiver = new MessageReceiver();
+ private Refrigerator refrigerator;
+
+ /**
+ * configure OIC platform and call findResource
+ */
+ private void initOICStack() {
+ //create platform config
+ PlatformConfig cfg = new PlatformConfig(
+ this,
+ ServiceType.IN_PROC,
+ ModeType.SERVER,
+ "0.0.0.0", // bind to all available interfaces
+ 0,
+ QualityOfService.LOW);
+ OcPlatform.Configure(cfg);
+ logMessage(TAG + "Creating refrigerator resources");
+
+ refrigerator = new Refrigerator(mContext);
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_fridge_server);
+ registerReceiver(mMessageReceiver, new IntentFilter(StringConstants.INTENT));
+
+ mEventsTextView = new TextView(this);
+ mEventsTextView.setMovementMethod(new ScrollingMovementMethod());
+ LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
+ layout.addView(mEventsTextView, new LinearLayout.LayoutParams
+ (LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f));
+ mContext = this;
+
+ initOICStack();
+ }
+
+ public class MessageReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String message = intent.getStringExtra(StringConstants.MESSAGE);
+ logMessage(message);
+ }
+ }
+
+ @Override
+ public void logMessage(final String text) {
+ if (StringConstants.ENABLE_PRINTING) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ final Message msg = new Message();
+ msg.obj = text;
+ mEventsTextView.append("\n");
+ mEventsTextView.append(text);
+ }
+ });
+ Log.i(TAG, text);
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_fridge_server, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == R.id.action_settings) {
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ onStop();
+ }
+
+ @Override
+ protected void onStop() {
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
+ super.onStop();
+ }
+}