In the last post, we completed the application at desktop, by which you can switch to each saved viewpoint, export to an image and upload it to the cloud. In this post, we will introduce the application at mobile end. The source code is available with Download Nw-C&M - Android
Firstly, this application needs to have the access to the cloud. Several necessary steps:
- Add Amazon cloud library.
- Permit the application to use Internet in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
- Same to desktop application, create the client with confidential keys. Remember to remove access key or any confidential information of your cloud account if you want to share the code in public
// create client of S3 to connect to the cloud
private AmazonS3Client s3Client =
new AmazonS3Client(
new BasicAWSCredentials
( Constants.ACCESS_KEY_ID,
Constants.SECRET_KEY ) );
The Amazon SDK for Eclipse provides the libraries of the abilities of Amazon cloud such as S3, SimpleDB, EC2 etc, and also provides some samples. For experiment, you could use the SDK sample as the skeleton to save time to configure the application for cloud. I used S3_UploaderActivity. You just need to change the application name in the manifest file.
As we know, at cloud end, each model has one folder withn which there are saved viewpoints images. So we need to have a list view that to display the folder as group and each group has child items. The will need to use ExpandableListView. I have to say this is the most tricky in this demo :S The Item View is totally different to the ComBox, List View or Tree View of the languages of desktop. Fortunately, there are amount of posts in internet which have discussed a lot on this topic. I accommodated one of them.
http://www.dreamincode.net/forums/topic/270612-how-to-get-started-with-expandablelistview/
After connecting the cloud, we could check the bucket and dump the items information. Following are some pieces of the main code. For details, please check the source project Download Nw-C&M - Android..
1. dump folder
// name list of folders
// each folder represents the name of model.
ListObjectsRequest request =
new ListObjectsRequest();
request.setBucketName(Constants.PICTURE_BUCKET);
// object listing
ObjectListing current =
s3Client.listObjects( request);
//enumerate the list
for(S3ObjectSummary objectSummary : current.getObjectSummaries())
{
// store the folder names to the list of expandable list view as group item.
String eachkey = objectSummary.getKey();
if(eachkey.endsWith("/"))
folderdata.add(eachkey);
// folderdata is used to build the structure of expandable list view
}
for(String eachFolder : folderdata)
{
String groupName = eachFolder;
// connect to cloud to
// get the items within the folder
ListObjectsRequest request = new ListObjectsRequest();
request.setBucketName(Constants.PICTURE_BUCKET);
request.withPrefix(eachFolder);
ObjectListing current = s3Client.listObjects( request);
// iterate each item to get its name
for(S3ObjectSummary objectSummary : current.getObjectSummaries())
{
String childName = objectSummary.getKey();
// exclude the folder name
if(childName.equals(eachFolder))
continue;
// for build child item of expandable list view
ExpandListChild child = new ExpandListChild();
child.setName(childName.substring(childName.indexOf("/") + 1,childName.length() ));
child.setTag(objectSummary.getKey());
list2.add(child);
}
gru.setItems(list2);
list.add(gru);
}
Finally, in the event of clicking child item of expandable list view, we chose the simplest way to view the image, by using Image View.
// get the value (image name) of the selected item
String selectedValue = ((ExpandListChild)childItem).getTag();
// find download the image in the cloud bucket
GetObjectRequest s3Request =
new GetObjectRequest(
Constants.PICTURE_BUCKET,
selectedValue);
S3Object s3Response = s3Client.getObject(s3Request);
if (s3Response != null)
{
//display it in the image view
InputStream reader = new BufferedInputStream(s3Response.getObjectContent());
ImageView imgView = (ImageView)findViewById(R.id.imageView1);
imgView.setImageBitmap(BitmapFactory.decodeStream(reader));
}
Run the application, click [Receive Data]. The items in the cloud bucket will be listed.
Expand any of them and click the child item, the corresponding image of saved viewpoint will be displayed.
This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...
ios App Development Company
Posted by: Hellan Adam | 06/29/2017 at 11:49 PM