From d60fdb8a9ae84c62320cc686220249489cb4f39a Mon Sep 17 00:00:00 2001 From: Jay Sharma Date: Sat, 19 Sep 2015 01:32:48 +0530 Subject: [PATCH] OSLV fixes for RE layer. - Updated Android sample apps. Change-Id: I6df99717227d1515e40a08560550b3cb2c82d54c Signed-off-by: Jay Sharma Reviewed-on: https://gerrit.iotivity.org/gerrit/2723 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- .../examples/android/REClient/res/menu/main.xml | 6 +- .../android/REClient/res/values-w820dp/dimens.xml | 7 -- .../android/REClient/res/values/dimens.xml | 3 - .../android/REClient/res/values/strings.xml | 5 +- .../examples/android/REServer/AndroidManifest.xml | 1 + .../res/layout/{list_group.xml => group.xml} | 2 +- .../android/REServer/res/layout/list_item.xml | 2 +- .../examples/android/REServer/res/menu/main.xml | 6 +- .../android/REServer/res/values-w820dp/dimens.xml | 7 -- .../android/REServer/res/values/dimens.xml | 3 - .../android/REServer/res/values/strings.xml | 6 +- .../src/com/example/sampleserver/MainActivity.java | 79 ++++++------- .../example/sampleserver/ResourceContainer.java | 1 + .../sampleserver/ResourceContainerActivity.java | 128 +++++++++++---------- 14 files changed, 115 insertions(+), 141 deletions(-) rename service/resource-encapsulation/examples/android/REServer/res/layout/{list_group.xml => group.xml} (89%) diff --git a/service/resource-encapsulation/examples/android/REClient/res/menu/main.xml b/service/resource-encapsulation/examples/android/REClient/res/menu/main.xml index c002028..21f6445 100644 --- a/service/resource-encapsulation/examples/android/REClient/res/menu/main.xml +++ b/service/resource-encapsulation/examples/android/REClient/res/menu/main.xml @@ -1,9 +1,7 @@ - - + android:title="@string/re_client"/> diff --git a/service/resource-encapsulation/examples/android/REClient/res/values-w820dp/dimens.xml b/service/resource-encapsulation/examples/android/REClient/res/values-w820dp/dimens.xml index f3e7020..146c0e1 100644 --- a/service/resource-encapsulation/examples/android/REClient/res/values-w820dp/dimens.xml +++ b/service/resource-encapsulation/examples/android/REClient/res/values-w820dp/dimens.xml @@ -1,10 +1,3 @@ - - 64dp - diff --git a/service/resource-encapsulation/examples/android/REClient/res/values/dimens.xml b/service/resource-encapsulation/examples/android/REClient/res/values/dimens.xml index 55c1e59..fe991af 100644 --- a/service/resource-encapsulation/examples/android/REClient/res/values/dimens.xml +++ b/service/resource-encapsulation/examples/android/REClient/res/values/dimens.xml @@ -1,7 +1,4 @@ - - 16dp 16dp - diff --git a/service/resource-encapsulation/examples/android/REClient/res/values/strings.xml b/service/resource-encapsulation/examples/android/REClient/res/values/strings.xml index e584316..b44b03b 100644 --- a/service/resource-encapsulation/examples/android/REClient/res/values/strings.xml +++ b/service/resource-encapsulation/examples/android/REClient/res/values/strings.xml @@ -1,8 +1,5 @@ - REClient - Hello world! - Settings - + RE Client! diff --git a/service/resource-encapsulation/examples/android/REServer/AndroidManifest.xml b/service/resource-encapsulation/examples/android/REServer/AndroidManifest.xml index a62acb9..4357edb 100644 --- a/service/resource-encapsulation/examples/android/REServer/AndroidManifest.xml +++ b/service/resource-encapsulation/examples/android/REServer/AndroidManifest.xml @@ -10,6 +10,7 @@ + - - + android:title="@string/re_server"/> \ No newline at end of file diff --git a/service/resource-encapsulation/examples/android/REServer/res/values-w820dp/dimens.xml b/service/resource-encapsulation/examples/android/REServer/res/values-w820dp/dimens.xml index f3e7020..146c0e1 100644 --- a/service/resource-encapsulation/examples/android/REServer/res/values-w820dp/dimens.xml +++ b/service/resource-encapsulation/examples/android/REServer/res/values-w820dp/dimens.xml @@ -1,10 +1,3 @@ - - 64dp - diff --git a/service/resource-encapsulation/examples/android/REServer/res/values/dimens.xml b/service/resource-encapsulation/examples/android/REServer/res/values/dimens.xml index 55c1e59..fe991af 100644 --- a/service/resource-encapsulation/examples/android/REServer/res/values/dimens.xml +++ b/service/resource-encapsulation/examples/android/REServer/res/values/dimens.xml @@ -1,7 +1,4 @@ - - 16dp 16dp - diff --git a/service/resource-encapsulation/examples/android/REServer/res/values/strings.xml b/service/resource-encapsulation/examples/android/REServer/res/values/strings.xml index 3f7e62b..8f6be76 100644 --- a/service/resource-encapsulation/examples/android/REServer/res/values/strings.xml +++ b/service/resource-encapsulation/examples/android/REServer/res/values/strings.xml @@ -1,8 +1,6 @@ - REServer - Hello world! - Settings - + RE Server! + RE_SERVER diff --git a/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/MainActivity.java b/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/MainActivity.java index 0d6eac8..4cd89f6 100644 --- a/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/MainActivity.java +++ b/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/MainActivity.java @@ -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 apis; private ArrayList 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(); @@ -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); } } diff --git a/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainer.java b/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainer.java index 244d212..5440b71 100644 --- a/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainer.java +++ b/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainer.java @@ -65,6 +65,7 @@ public class ResourceContainer { isInitialized = true; } else { containerInstance.startContainer(configFile); + isStarted = true; } logMessage = "Container Started"; diff --git a/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainerActivity.java b/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainerActivity.java index 699f652..b252ded 100644 --- a/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainerActivity.java +++ b/service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainerActivity.java @@ -64,7 +64,7 @@ public class ResourceContainerActivity extends Activity { public List sensors; public List diApiList; public List bmiApiList; - HashMap> listDataChild; + HashMap> listChild; private static Handler mHandler; private Button startContainer; @@ -89,7 +89,7 @@ public class ResourceContainerActivity extends Activity { sensors = new ArrayList(); diApiList = new ArrayList(); bmiApiList = new ArrayList(); - listDataChild = new HashMap>(); + listChild = new HashMap>(); // 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 _listDataHeader; // header titles - // child data in format of header title, child title - private HashMap> _listDataChild; + private Context mContext; + private HashMap> mListDataChild; + private List mListDataHeader; - public ExpandableList(Context context, List listDataHeader, - HashMap> listChildData) { - this._context = context; - this._listDataHeader = listDataHeader; - this._listDataChild = listChildData; + // constructor + public ExpandableList(Context context, List dataHeader, + HashMap> 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; } } -- 2.7.4