2 *******************************************************************
4 * Copyright 2015 Intel Corporation.
6 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 package org.iotivity.base.examples;
25 import android.app.Activity;
26 import android.content.BroadcastReceiver;
27 import android.content.Context;
28 import android.content.Intent;
29 import android.content.IntentFilter;
30 import android.os.Bundle;
31 import android.os.Message;
32 import android.text.method.ScrollingMovementMethod;
33 import android.util.Log;
34 import android.view.View;
35 import android.widget.Button;
36 import android.widget.ScrollView;
37 import android.widget.TextView;
39 import org.iotivity.base.ModeType;
40 import org.iotivity.base.OcPlatform;
41 import org.iotivity.base.PlatformConfig;
42 import org.iotivity.base.QualityOfService;
43 import org.iotivity.base.ServiceType;
48 * This is the main fridgeGroupServer class. This instantiates Refrigerator object
49 * which has different resources such as LightResource, DoorResource, etc.
51 public class FridgeGroupServer extends Activity {
52 private Refrigerator refrigerator;
55 * configure OIC platform and call findResource
57 private void startFridgeServer() {
58 logMessage("Configuring platform config");
59 PlatformConfig cfg = new PlatformConfig(
63 "0.0.0.0", // bind to all available interfaces
65 QualityOfService.LOW);
66 OcPlatform.Configure(cfg);
68 logMessage("Creating refrigerator resources");
69 refrigerator = new Refrigerator(this);
70 logMessage("-----------------------------------------------------");
73 //******************************************************************************
74 // End of the OIC specific code
75 //******************************************************************************
76 private static String TAG = "FridgeServer: ";
77 private TextView mConsoleTextView;
78 private ScrollView mScrollView;
79 private BroadcastReceiver mMessageReceiver = new MessageReceiver();
82 protected void onCreate(Bundle savedInstanceState) {
83 super.onCreate(savedInstanceState);
84 setContentView(R.layout.activity_fridge_server);
85 registerReceiver(mMessageReceiver, new IntentFilter(Resource.INTENT));
87 mConsoleTextView = (TextView) findViewById(R.id.consoleTextView);
88 mConsoleTextView.setMovementMethod(new ScrollingMovementMethod());
89 mScrollView = (ScrollView) findViewById(R.id.scrollView);
90 mScrollView.fullScroll(View.FOCUS_DOWN);
91 final Button button = (Button) findViewById(R.id.button);
93 if (null == savedInstanceState) {
94 button.setOnClickListener(new View.OnClickListener() {
96 public void onClick(View v) {
97 button.setEnabled(false);
98 new Thread(new Runnable() {
106 String consoleOutput = savedInstanceState.getString("consoleOutputString");
107 mConsoleTextView.setText(consoleOutput);
112 protected void onSaveInstanceState(Bundle outState) {
113 super.onSaveInstanceState(outState);
114 outState.putString("consoleOutputString", mConsoleTextView.getText().toString());
118 protected void onRestoreInstanceState(Bundle savedInstanceState) {
119 super.onRestoreInstanceState(savedInstanceState);
120 String consoleOutput = savedInstanceState.getString("consoleOutputString");
121 mConsoleTextView.setText(consoleOutput);
124 public class MessageReceiver extends BroadcastReceiver {
126 public void onReceive(Context context, Intent intent) {
127 final String message = intent.getStringExtra(Resource.MESSAGE);
132 private void logMessage(final String text) {
133 runOnUiThread(new Runnable() {
135 final Message msg = new Message();
137 mConsoleTextView.append("\n");
138 mConsoleTextView.append(text);