Skip to content

Commit

Permalink
Merge branch '1239'
Browse files Browse the repository at this point in the history
  • Loading branch information
kishoreyekkanti committed Feb 11, 2013
2 parents e6c50d2 + 84e8d29 commit 2ca1d76
Show file tree
Hide file tree
Showing 20 changed files with 235 additions and 128 deletions.
15 changes: 0 additions & 15 deletions RapidFTR-Android/res/layout/form_photo_thumbnail.xml

This file was deleted.

17 changes: 13 additions & 4 deletions RapidFTR-Android/res/layout/form_photo_upload_box.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
android:layout_height="fill_parent"
android:scrollbars="vertical">

<include layout="@layout/form_label" />
<include layout="@layout/form_help_text" />

<include layout="@layout/form_photo_thumbnail" android:id="@+id/capture" />
<Button android:id="@+id/thumbnail"
android:background="@drawable/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/photo_capture">
</Button>

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/photo_grid_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:stretchMode="none"
android:horizontalSpacing="2dp"
android:verticalSpacing="2dp"
android:gravity="center"
android:scrollbars="vertical"
android:padding="0dp"
/>
</com.rapidftr.view.fields.PhotoUploadBox>
6 changes: 4 additions & 2 deletions RapidFTR-Android/res/layout/form_section.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:scrollbars="vertical">

<include layout="@layout/form_label" />
<include layout="@layout/form_help_text" />

<LinearLayout android:id="@+id/container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
android:layout_height="fill_parent"
android:scrollbars="vertical"/>

</LinearLayout>

Expand Down
6 changes: 6 additions & 0 deletions RapidFTR-Android/res/menu/image_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/set_as_primary"
android:title="@string/set_as_primary"/>
</menu>
1 change: 1 addition & 0 deletions RapidFTR-Android/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<string name="photo_view_error">حدث خطأ عند تحميل الصورة</string>
<string name="photo_not_captured">لم يتم إلتقاط صورة للسجل</string>
<string name="photo_gallery_delete_error">غير قادر على مسح الصورة. الرجاء الذهاب إلى الأستوديو و مسحها يدويا</string>
<string name="set_as_primary">Set as primary photo</string>

<string name="synchronize_all">تزامن الكل</string>
<string name="cancel_synchronize_all">إلغاء تزامن الكل</string>
Expand Down
1 change: 1 addition & 0 deletions RapidFTR-Android/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<string name="photo_view_error">An error occurred while loading the photo</string>
<string name="photo_not_captured">No photo captured for the record</string>
<string name="photo_gallery_delete_error">Unable to delete photo from Gallery. Please go to Gallery and delete it manually</string>
<string name="set_as_primary">Set as primary photo</string>

<string name="synchronize_all">Synchronize All</string>
<string name="cancel_synchronize_all">Cancel Synchronize All</string>
Expand Down
1 change: 1 addition & 0 deletions RapidFTR-Android/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<string name="photo_view_error">An error occurred while loading the photo</string>
<string name="photo_not_captured">No photo captured for the record</string>
<string name="photo_gallery_delete_error">Unable to delete photo from Gallery. Please go to Gallery and delete it manually</string>
<string name="set_as_primary">Set as primary photo</string>

<string name="synchronize_all">Synchronize All</string>
<string name="cancel_synchronize_all">Cancel Synchronize All</string>
Expand Down
1 change: 1 addition & 0 deletions RapidFTR-Android/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<string name="photo_view_error">An error occurred while loading the photo</string>
<string name="photo_not_captured">No photo captured for the record</string>
<string name="photo_gallery_delete_error">Unable to delete photo from Gallery. Please go to Gallery and delete it manually</string>
<string name="set_as_primary">Set as primary photo</string>

<string name="synchronize_all">Synchronize All</string>
<string name="cancel_synchronize_all">Cancel Synchronize All</string>
Expand Down
1 change: 1 addition & 0 deletions RapidFTR-Android/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<string name="photo_view_error">An error occurred while loading the photo</string>
<string name="photo_not_captured">No photo captured for the record</string>
<string name="photo_gallery_delete_error">Unable to delete photo from Gallery. Please go to Gallery and delete it manually</string>
<string name="set_as_primary">Set as primary photo</string>

<string name="synchronize_all">Synchronize All</string>
<string name="cancel_synchronize_all">Cancel Synchronize All</string>
Expand Down
2 changes: 2 additions & 0 deletions RapidFTR-Android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<string name="photo_view_error">An error occurred while loading the photo</string>
<string name="photo_not_captured">No photo captured for the record</string>
<string name="photo_gallery_delete_error">Unable to delete photo from Gallery. Please go to Gallery and delete it manually</string>
<string name="set_as_primary">Set as primary photo</string>


<string name="synchronize_all">Synchronize All</string>
<string name="cancel_synchronize_all">Cancel Synchronize All</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.rapidftr.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import com.rapidftr.R;
import com.rapidftr.utils.PhotoCaptureHelper;
Expand All @@ -19,9 +21,24 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
if (getIntent().getBooleanExtra("enabled", false)) {
getMenuInflater().inflate(R.menu.image_menu, menu);
return true;
}
return false;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.set_as_primary:
Intent intent = new Intent();
intent.putExtra("file_name", getIntent().getStringExtra("file_name"));
setResult(RESULT_OK, intent);
finish();
}
return true;
}

protected ImageView getImageView() {
return (ImageView) findViewById(R.id.photo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
if (child != null) {
TextView uniqueIdView = (TextView) view.findViewById(R.id.row_child_unique_id);
TextView nameView = (TextView) view.findViewById(R.id.row_child_name);
// ImageView imageView = (ImageView) view.findViewById(R.id.thumbnail);
ImageView imageView = (ImageView) view.findViewById(R.id.thumbnail);
try {
setFields(String.valueOf(child.getShortId()), uniqueIdView);
setFields(String.valueOf(child.optString("name")), nameView);
// assignThumbnail(child, imageView);
assignThumbnail(child, imageView);

view.setOnClickListener(clickListener(child));
} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
try {
bitmap = photoCaptureHelper.getThumbnailOrDefault(photoKeys.get(position).toString());
imageView = new ImageView(context);
imageView.setPadding(0,0,0,0);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(bitmap);
} catch (JSONException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.rapidftr.database.Database.ChildTableColumn.internal_id;
import static com.rapidftr.view.fields.PhotoUploadBox.PHOTO_KEYS;
import static java.util.Arrays.asList;

public class ChildService {
Expand Down Expand Up @@ -96,11 +97,15 @@ private void setChildAttributes(Child child) throws JSONException {
}

private void addMultiMediaFilesToTheRequest(Child child) throws JSONException {
if (child.opt("current_photo_key") != null && !child.optString("current_photo_key").equals("")) {
List<Object> photoKeys = getPhotoKeys(child);
if (!photoKeys.contains(child.optString("current_photo_key"))) {
fluentRequest.param("current_photo_key", child.optString("current_photo_key"));
JSONArray photoKeys = child.optJSONArray(PHOTO_KEYS);
JSONArray photoKeysToAdd = new JSONArray();
if(photoKeys != null){
for(int i = 0; i< photoKeys.length(); i++){
if(!photoKeys.optString(i).startsWith("photo-")){
photoKeysToAdd.put(photoKeys.optString(i));
}
}
fluentRequest.param("photo_keys", photoKeysToAdd.toString());
}
if (child.opt("recorded_audio") != null && !child.optString("recorded_audio").equals("")) {
if (!getAudioKey(child).equals(child.optString("recorded_audio"))) {
Expand Down Expand Up @@ -174,20 +179,32 @@ public Child apply(Map content) {

public void setPhoto(Child child) throws IOException, JSONException {
PhotoCaptureHelper photoCaptureHelper = new PhotoCaptureHelper(context);
String currentPhotoKey = child.optString("current_photo_key");
try {
if (!currentPhotoKey.equals("")) {
photoCaptureHelper.getFile(currentPhotoKey, ".jpg");

JSONArray photoKeys = child.optJSONArray("photo_keys");
if(photoKeys != null){
getPhotoFromServerIfNeeded(child, photoCaptureHelper, photoKeys);
}

}

private void getPhotoFromServerIfNeeded(Child child, PhotoCaptureHelper photoCaptureHelper, JSONArray photoKeys) throws JSONException, IOException {
for(int i = 0; i < photoKeys.length(); i++){
String photoKey = photoKeys.get(i).toString();
try {
if (!photoKey.equals("")) {
photoCaptureHelper.getFile(photoKey, ".jpg");
}
}
catch (FileNotFoundException e) {
getPhotoFromServer(child, photoCaptureHelper, photoKey);
}
} catch (FileNotFoundException e) {
getPhotoFromServer(child, photoCaptureHelper, currentPhotoKey);
}
}

public void getPhotoFromServer(Child child, PhotoCaptureHelper photoCaptureHelper, String currentPhotoKey) throws IOException {
HttpResponse httpResponse = getPhoto(child);
public void getPhotoFromServer(Child child, PhotoCaptureHelper photoCaptureHelper, String fileName) throws IOException {
HttpResponse httpResponse = getPhoto(child, fileName);
Bitmap bitmap = BitmapFactory.decodeStream(httpResponse.getEntity().getContent());
savePhoto(bitmap, photoCaptureHelper, currentPhotoKey);
savePhoto(bitmap, photoCaptureHelper, fileName);
}


Expand All @@ -208,7 +225,7 @@ private void getAudioFromServer(Child child, AudioCaptureHelper audioCaptureHelp
audioCaptureHelper.saveAudio(child, response.getEntity().getContent());
}

private void savePhoto(Bitmap bitmap, PhotoCaptureHelper photoCaptureHelper, String current_photo_key) throws IOException {
public void savePhoto(Bitmap bitmap, PhotoCaptureHelper photoCaptureHelper, String current_photo_key) throws IOException {
if (bitmap != null && !current_photo_key.equals("")) {
try {
photoCaptureHelper.saveThumbnail(bitmap, 0, current_photo_key);
Expand All @@ -219,9 +236,9 @@ private void savePhoto(Bitmap bitmap, PhotoCaptureHelper photoCaptureHelper, Str
}
}

public HttpResponse getPhoto(Child child) throws IOException {
public HttpResponse getPhoto(Child child, String fileName) throws IOException {
return fluentRequest
.path(String.format("/children/%s/photo/%s", child.optString("_id"), child.optString("current_photo_key")))
.path(String.format("/children/%s/photo/%s", child.optString("_id"), fileName))
.context(context)
.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.json.JSONException;

import java.io.*;
import java.net.URI;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.util.*;

Expand Down Expand Up @@ -126,11 +127,9 @@ protected FluentResponse executeMultiPart(HttpEntityEnclosingRequestBase request
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
if (params.size() > 0) {
for (Map.Entry<String, String> param : params.entrySet()){
if(param.getKey().equals("current_photo_key")){
if(param.getKey().equals("photo_keys")){
try {
multipartEntity.addPart("child[photo]",
new ByteArrayBody(IOUtils.toByteArray(new PhotoCaptureHelper((RapidFtrApplication) context).getDecodedImageStream(param.getValue())),
"image/jpg", param.getValue()+".jpg"));
addPhotoToMultipart(multipartEntity, param.getValue());
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -156,13 +155,23 @@ protected FluentResponse executeMultiPart(HttpEntityEnclosingRequestBase request
}
}
}


}
request.setEntity(multipartEntity);
return execute(request);
}

public void addPhotoToMultipart(MultipartEntity multipartEntity, String param) throws IOException, GeneralSecurityException, JSONException {
JSONArray photoKeys = new JSONArray(param);
for(int i = 0; i < photoKeys.length(); i++){
multipartEntity.addPart("child[photo]["+i+"]", attachPhoto(photoKeys.get(i).toString()));
}
}

protected ByteArrayBody attachPhoto(String fileName) throws IOException, GeneralSecurityException {
return new ByteArrayBody(IOUtils.toByteArray(new PhotoCaptureHelper((RapidFtrApplication) context).getDecodedImageStream(fileName)),
"image/jpg", fileName+".jpg");
}

protected FluentResponse executeUnenclosed(HttpRequestBase request) throws IOException {
if (params.size() > 0) {
for (Map.Entry<String, String> param : params.entrySet())
Expand Down
Loading

0 comments on commit 2ca1d76

Please sign in to comment.