OSLV fixes for RE layer.
authorJay Sharma <jay.sharma@samsung.com>
Fri, 18 Sep 2015 20:02:48 +0000 (01:32 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Sat, 19 Sep 2015 08:37:48 +0000 (08:37 +0000)
- Updated Android sample apps.

Change-Id: I6df99717227d1515e40a08560550b3cb2c82d54c
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2723
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
14 files changed:
service/resource-encapsulation/examples/android/REClient/res/menu/main.xml
service/resource-encapsulation/examples/android/REClient/res/values-w820dp/dimens.xml
service/resource-encapsulation/examples/android/REClient/res/values/dimens.xml
service/resource-encapsulation/examples/android/REClient/res/values/strings.xml
service/resource-encapsulation/examples/android/REServer/AndroidManifest.xml
service/resource-encapsulation/examples/android/REServer/res/layout/group.xml [moved from service/resource-encapsulation/examples/android/REServer/res/layout/list_group.xml with 89% similarity]
service/resource-encapsulation/examples/android/REServer/res/layout/list_item.xml
service/resource-encapsulation/examples/android/REServer/res/menu/main.xml
service/resource-encapsulation/examples/android/REServer/res/values-w820dp/dimens.xml
service/resource-encapsulation/examples/android/REServer/res/values/dimens.xml
service/resource-encapsulation/examples/android/REServer/res/values/strings.xml
service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/MainActivity.java
service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainer.java
service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainerActivity.java

index c002028..21f6445 100644 (file)
@@ -1,9 +1,7 @@
 <menu xmlns:android="http://schemas.android.com/apk/res/android" >
-
     <item
-        android:id="@+id/action_settings"
+        android:id="@+id/re_client"
         android:orderInCategory="100"
         android:showAsAction="never"
-        android:title="@string/action_settings"/>
-
+        android:title="@string/re_client"/>
 </menu>
index f3e7020..146c0e1 100644 (file)
@@ -1,10 +1,3 @@
 <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>
index 55c1e59..fe991af 100644 (file)
@@ -1,7 +1,4 @@
 <resources>
-
-    <!-- Default screen margins, per the Android Design guidelines. -->
     <dimen name="activity_horizontal_margin">16dp</dimen>
     <dimen name="activity_vertical_margin">16dp</dimen>
-
 </resources>
index e584316..b44b03b 100644 (file)
@@ -1,8 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-
     <string name="app_name">REClient</string>
-    <string name="hello_world">Hello world!</string>
-    <string name="action_settings">Settings</string>
-
+    <string name="re_client">RE Client!</string>
 </resources>
index a62acb9..4357edb 100644 (file)
@@ -10,6 +10,7 @@
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 
     <application
         android:allowBackup="true"
@@ -6,7 +6,7 @@
     android:padding="8dp" >
 
     <TextView
-        android:id="@+id/lblListHeader"
+        android:id="@+id/ListHead"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
index 1241652..7e7bf61 100644 (file)
@@ -5,7 +5,7 @@
     android:orientation="vertical" >
 
     <TextView
-        android:id="@+id/lblListItem"
+        android:id="@+id/listItem"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:paddingBottom="5dp"
index d227c49..3925812 100644 (file)
@@ -1,9 +1,7 @@
 <menu xmlns:android="http://schemas.android.com/apk/res/android" >
-
     <item
-        android:id="@+id/action_settings"
+        android:id="@+id/re_server"
         android:orderInCategory="100"
         android:showAsAction="never"
-        android:title="@string/action_settings"/>
-
+        android:title="@string/re_server"/>
 </menu>
\ No newline at end of file
index f3e7020..146c0e1 100644 (file)
@@ -1,10 +1,3 @@
 <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>
index 55c1e59..fe991af 100644 (file)
@@ -1,7 +1,4 @@
 <resources>
-
-    <!-- Default screen margins, per the Android Design guidelines. -->
     <dimen name="activity_horizontal_margin">16dp</dimen>
     <dimen name="activity_vertical_margin">16dp</dimen>
-
 </resources>
index 3f7e62b..8f6be76 100644 (file)
@@ -1,8 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-
     <string name="app_name">REServer</string>
-    <string name="hello_world">Hello world!</string>
-    <string name="action_settings">Settings</string>
-
+    <string name="hello_world">RE Server!</string>
+    <string name="re_server">RE_SERVER</string>
 </resources>
index 0d6eac8..4cd89f6 100644 (file)
@@ -20,7 +20,7 @@
 
 package com.example.sampleserver;
 
-import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -61,6 +61,7 @@ public class MainActivity extends Activity {
     private static MainActivity  activityObj;
     private ArrayAdapter<String> apis;
     private ArrayList<String>    apisList;
+    private Context              context;
     private ListView             list;
     private final String         LOG_TAG = "[ReSampleServer]"
                                                  + this.getClass()
@@ -71,7 +72,7 @@ public class MainActivity extends Activity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         activityObj = this;
-
+        context = this;
         list = (ListView) findViewById(R.id.list);
         apisList = new ArrayList<String>();
 
@@ -109,58 +110,46 @@ public class MainActivity extends Activity {
         // the OcPlatform
         configurePlatform();
 
-        // copy assets folder file to SDcard
-        copyFiles("lib");
+        // copy all the files from assets folder to SDcard
+        CopyAssetsToSDCard();
     }
 
-    private void copyFiles(String path) {
+    private void CopyAssetsToSDCard() {
         AssetManager assetManager = getAssets();
-        String assets[] = null;
-
+        String[] files = null;
         try {
-            assets = assetManager.list(path);
-
-            if (assets.length == 0) {
-                copyFile(path);
-            } else {
-                String fullPath = "/data/data/"
-                        + this.getClass().getPackage().toString() + "/" + path;
-                File dir = new File(fullPath);
-
-                if (!dir.exists())
-                    dir.mkdir();
-                for (int i = 0; i < assets.length; ++i) {
-                    copyFiles(path + "/" + assets[i]);
-                }
+            files = assetManager.list("lib");
+        } catch (IOException e) {
+            Log.e(LOG_TAG, e.getMessage());
+        }
+
+        for (String filename : files) {
+            InputStream in = null;
+            OutputStream out = null;
+            try {
+                in = assetManager.open("lib/" + filename);
+                out = new FileOutputStream(context.getFilesDir().getParent()
+                        + "/files/" + filename);
+                copyIndividualFile(in, out);
+                in.close();
+                in = null;
+                out.flush();
+                out.close();
+                out = null;
+            } catch (Exception e) {
+                Log.e(LOG_TAG, e.getMessage());
             }
-        } catch (IOException ex) {
-            Log.e("tag", "I/O Exception", ex);
         }
     }
 
-    private void copyFile(String filename) {
-        AssetManager assetManager = getAssets();
-        InputStream in = null;
-        OutputStream out = null;
-
-        try {
-            in = assetManager.open(filename);
-            out = openFileOutput(filename.split("/")[1], Context.MODE_PRIVATE);
-
-            byte[] buffer = new byte[1024];
-            int read;
-
-            while ((read = in.read(buffer)) != -1) {
-                out.write(buffer, 0, read);
-            }
+    private void copyIndividualFile(InputStream in, OutputStream out)
+            throws IOException {
 
-            in.close();
-            in = null;
-            out.flush();
-            out.close();
-            out = null;
-        } catch (Exception e) {
-            Log.e("tag", e.getMessage());
+        Log.i(LOG_TAG, "copyIndividualFile");
+        byte[] buffer = new byte[2048];
+        int read;
+        while ((read = in.read(buffer)) != -1) {
+            out.write(buffer, 0, read);
         }
     }
 
index 244d212..5440b71 100644 (file)
@@ -65,6 +65,7 @@ public class ResourceContainer {
             isInitialized = true;
         } else {
             containerInstance.startContainer(configFile);
+            isStarted = true;
         }
 
         logMessage = "Container Started";
index 699f652..b252ded 100644 (file)
@@ -64,7 +64,7 @@ public class ResourceContainerActivity extends Activity {
     public List<String>                      sensors;
     public List<String>                      diApiList;
     public List<String>                      bmiApiList;
-    HashMap<String, List<String>>            listDataChild;
+    HashMap<String, List<String>>            listChild;
 
     private static Handler                   mHandler;
     private Button                           startContainer;
@@ -89,7 +89,7 @@ public class ResourceContainerActivity extends Activity {
         sensors = new ArrayList<String>();
         diApiList = new ArrayList<String>();
         bmiApiList = new ArrayList<String>();
-        listDataChild = new HashMap<String, List<String>>();
+        listChild = new HashMap<String, List<String>>();
 
         // Adding list items (header)
         sensors.add("Discomfort Index Sensor");
@@ -109,9 +109,9 @@ public class ResourceContainerActivity extends Activity {
         bmiApiList.add("6. Stop Bundle");
         bmiApiList.add("7. Remove Bundle");
 
-        listDataChild.put(sensors.get(0), diApiList); // Header, Child data
-        listDataChild.put(sensors.get(1), bmiApiList);
-        listAdapter = new ExpandableList(this, sensors, listDataChild);
+        listChild.put(sensors.get(0), diApiList);
+        listChild.put(sensors.get(1), bmiApiList);
+        listAdapter = new ExpandableList(this, sensors, listChild);
 
         // getting the sd card path
         sdCardPath = this.getFilesDir().getPath();
@@ -149,7 +149,7 @@ public class ResourceContainerActivity extends Activity {
                     resourceContainerInstance.startContainer(sdCardPath);
                     listAdapter = new ExpandableList(ResourceContainerActivity
                             .getResourceContainerActivityObj(), sensors,
-                            listDataChild);
+                            listChild);
                     listBundles.setEnabled(true);
                     startContainer.setText("Stop Container");
                 } else {
@@ -222,96 +222,108 @@ public class ResourceContainerActivity extends Activity {
     // class for handling expandable list items
     public class ExpandableList extends BaseExpandableListAdapter {
 
-        private Context                       _context;
-        private List<String>                  _listDataHeader; // header titles
-        // child data in format of header title, child title
-        private HashMap<String, List<String>> _listDataChild;
+        private Context                       mContext;
+        private HashMap<String, List<String>> mListDataChild;
+        private List<String>                  mListDataHeader;
 
-        public ExpandableList(Context context, List<String> listDataHeader,
-                HashMap<String, List<String>> listChildData) {
-            this._context = context;
-            this._listDataHeader = listDataHeader;
-            this._listDataChild = listChildData;
+        // constructor
+        public ExpandableList(Context context, List<String> dataHeader,
+                HashMap<String, List<String>> childData) {
+            this.mContext = context;
+            this.mListDataHeader = dataHeader;
+            this.mListDataChild = childData;
         }
 
+        // get the child ID
         @Override
-        public Object getChild(int groupPosition, int childPosititon) {
-            return this._listDataChild.get(
-                    this._listDataHeader.get(groupPosition))
-                    .get(childPosititon);
+        public long getChildId(int grpPosition, int childPosition) {
+            return childPosition;
         }
 
+        // get the child
         @Override
-        public long getChildId(int groupPosition, int childPosition) {
-            return childPosition;
+        public Object getChild(int grpPosition, int childPosititon) {
+            return this.mListDataChild.get(
+                    this.mListDataHeader.get(grpPosition)).get(childPosititon);
         }
 
+        // get Group View
         @Override
-        public View getChildView(int groupPosition, final int childPosition,
-                boolean isLastChild, View convertView, ViewGroup parent) {
-
-            final String childText = (String) getChild(groupPosition,
-                    childPosition);
-
-            if (convertView == null) {
-                LayoutInflater infalInflater = (LayoutInflater) this._context
+        public View getGroupView(int grpPosition, boolean isExpandable,
+                View changeView, ViewGroup head) {
+            String mainHeading = (String) getGroup(grpPosition);
+            if (changeView == null) {
+                LayoutInflater flater;
+                flater = (LayoutInflater) this.mContext
                         .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-                convertView = infalInflater.inflate(R.layout.list_item, null);
+                changeView = flater.inflate(R.layout.group, null);
             }
 
-            TextView txtListChild = (TextView) convertView
-                    .findViewById(R.id.lblListItem);
-
-            txtListChild.setText(childText);
-            return convertView;
+            TextView listHeader = (TextView) changeView
+                    .findViewById(R.id.ListHead);
+            listHeader.setTypeface(null, Typeface.BOLD);
+            listHeader.setText(mainHeading);
+            return changeView;
         }
 
+        // get Children count
         @Override
-        public int getChildrenCount(int groupPosition) {
-            return this._listDataChild.get(
-                    this._listDataHeader.get(groupPosition)).size();
+        public int getChildrenCount(int grpPosition) {
+            int count = this.mListDataChild.get(
+                    this.mListDataHeader.get(grpPosition)).size();
+            return count;
         }
 
+        // Get Group
         @Override
-        public Object getGroup(int groupPosition) {
-            return this._listDataHeader.get(groupPosition);
+        public Object getGroup(int grpPosition) {
+            return this.mListDataHeader.get(grpPosition);
         }
 
+        // get Group size
         @Override
         public int getGroupCount() {
-            return this._listDataHeader.size();
+            int size = this.mListDataHeader.size();
+            return size;
         }
 
+        // get Group ID
         @Override
-        public long getGroupId(int groupPosition) {
-            return groupPosition;
+        public long getGroupId(int grpPosition) {
+            return grpPosition;
         }
 
+        // get Group View
         @Override
-        public View getGroupView(int groupPosition, boolean isExpanded,
-                View convertView, ViewGroup parent) {
-            String headerTitle = (String) getGroup(groupPosition);
-            if (convertView == null) {
-                LayoutInflater infalInflater = (LayoutInflater) this._context
+        public View getChildView(int grpPosition, final int childPosition,
+                boolean isLastItem, View changeView, ViewGroup head) {
+
+            final String innerText = (String) getChild(grpPosition,
+                    childPosition);
+
+            if (changeView == null) {
+                LayoutInflater flater = (LayoutInflater) this.mContext
                         .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-                convertView = infalInflater.inflate(R.layout.list_group, null);
+                changeView = flater.inflate(R.layout.list_item, null);
             }
 
-            TextView lblListHeader = (TextView) convertView
-                    .findViewById(R.id.lblListHeader);
-            lblListHeader.setTypeface(null, Typeface.BOLD);
-            lblListHeader.setText(headerTitle);
-            return convertView;
+            TextView textListChild = (TextView) changeView
+                    .findViewById(R.id.listItem);
+
+            textListChild.setText(innerText);
+            return changeView;
         }
 
+        // To check whether child is selectable or not
         @Override
-        public boolean hasStableIds() {
-            return false;
+        public boolean isChildSelectable(int grpPosition, int childPosition) {
+            return true;
         }
 
+        // To check the stable IDs
         @Override
-        public boolean isChildSelectable(int groupPosition, int childPosition) {
-            return true;
+        public boolean hasStableIds() {
+            return false;
         }
     }