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.fridgeserver;
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 fridgeServer class. This instantiates Refrigerator object
49 * which has different resources (DeviceResource, LightResource, DoorResources).
51 public class FridgeServer extends Activity {
52 private Refrigerator refrigerator;
55 * configure OIC platform and call findResource
57 private void startFridgeServer() {
58 //create platform config
59 PlatformConfig cfg = new PlatformConfig(
63 "0.0.0.0", // bind to all available interfaces
65 QualityOfService.LOW);
66 logMessage("Configuring platform");
67 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 public static final String MESSAGE = "message";
78 public static final String INTENT = "org.iotivity.base.examples.fridgeserver";
79 private TextView mConsoleTextView;
80 private ScrollView mScrollView;
81 private MessageReceiver mMessageReceiver = new MessageReceiver();
84 protected void onCreate(Bundle savedInstanceState) {
85 super.onCreate(savedInstanceState);
86 setContentView(R.layout.activity_fridge_server);
87 registerReceiver(mMessageReceiver, new IntentFilter(INTENT));
89 mConsoleTextView = (TextView) findViewById(R.id.consoleTextView);
90 mConsoleTextView.setMovementMethod(new ScrollingMovementMethod());
91 mScrollView = (ScrollView) findViewById(R.id.scrollView);
92 mScrollView.fullScroll(View.FOCUS_DOWN);
93 final Button button = (Button) findViewById(R.id.button);
95 if (null == savedInstanceState) {
96 button.setOnClickListener(new View.OnClickListener() {
98 public void onClick(View v) {
99 button.setEnabled(false);
100 new Thread(new Runnable() {
108 String consoleOutput = savedInstanceState.getString("consoleOutputString");
109 mConsoleTextView.setText(consoleOutput);
113 public class MessageReceiver extends BroadcastReceiver {
115 public void onReceive(Context context, Intent intent) {
116 final String message = intent.getStringExtra(MESSAGE);
121 public void logMessage(final String text) {
122 runOnUiThread(new Runnable() {
124 final Message msg = new Message();
126 mConsoleTextView.append("\n");
127 mConsoleTextView.append(text);