From 4190af891d00bab65e7629258a5fd14b397bfebe Mon Sep 17 00:00:00 2001 From: drizea Date: Tue, 31 Jul 2012 13:11:43 +0300 Subject: [PATCH] image download fixed --- .../res/layout/record_details_basic_fragment.xml | 7 +++- .../src/Android/res/layout/search_result_item.xml | 8 ++-- .../android/searchCatalog/ImageDownloader.java | 28 +++++++++++++- .../searchCatalog/SearchCatalogListView.java | 44 +++++++++++----------- .../android/utils/ui/BasicDetailsFragment.java | 14 +++++++ 5 files changed, 72 insertions(+), 29 deletions(-) diff --git a/Open-ILS/src/Android/res/layout/record_details_basic_fragment.xml b/Open-ILS/src/Android/res/layout/record_details_basic_fragment.xml index b994b54034..5b001cfe3c 100644 --- a/Open-ILS/src/Android/res/layout/record_details_basic_fragment.xml +++ b/Open-ILS/src/Android/res/layout/record_details_basic_fragment.xml @@ -66,11 +66,14 @@ diff --git a/Open-ILS/src/Android/res/layout/search_result_item.xml b/Open-ILS/src/Android/res/layout/search_result_item.xml index 045d5402e6..2b3270d941 100644 --- a/Open-ILS/src/Android/res/layout/search_result_item.xml +++ b/Open-ILS/src/Android/res/layout/search_result_item.xml @@ -10,10 +10,12 @@ + android:src="@drawable/address_book" + android:padding="4dip" + /> diff --git a/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/ImageDownloader.java b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/ImageDownloader.java index 5451405de6..b8711ca4d6 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/ImageDownloader.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/ImageDownloader.java @@ -44,6 +44,24 @@ public class ImageDownloader { private int MIN_IMG_HEIGHT = 75; + private int bitmap_width; + private int bitmap_height; + private boolean scale; + + public ImageDownloader(int min_img_height){ + + MIN_IMG_HEIGHT = min_img_height; + } + + public ImageDownloader(){ + + } + + public ImageDownloader(int w, int h, boolean scale){ + this.bitmap_height = h; + this.bitmap_width = w; + this.scale = scale; + } /** * Download the specified image from the Internet and binds it to the provided ImageView. The * binding is immediate if the image is found in the cache and will be done asynchronously @@ -269,12 +287,18 @@ public class ImageDownloader { // Change bitmap only if this process is still associated with it // Or if we don't use any bitmap to task association (NO_DOWNLOADED_DRAWABLE mode) if ((this == bitmapDownloaderTask) || (mode != Mode.CORRECT)) { - imageView.setImageBitmap(bitmap); + Bitmap newScaledBitmap = null; + if(bitmap != null && scale == true){ + newScaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap_width, bitmap_height, true); + imageView.setImageBitmap(newScaledBitmap); + }else{ + imageView.setImageBitmap(bitmap); + } } if(bitmap == null){ if(imageView != null) - imageView.setImageResource(R.drawable.address_book); + imageView.setImageResource(R.drawable.no_image); } } diff --git a/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java index f2cb753269..a60c581ef9 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java @@ -650,28 +650,28 @@ public class SearchCatalogListView extends Activity{ Log.d(tag, "Successfully completed XML Row Inflation!"); } - - Log.d(TAG, "reord image value " + recordImage); - // Get reference to ImageView - recordImage = (ImageView) row.findViewById(R.id.search_record_img); - //TODO fix bugs + features - String imageHref = GlobalConfigs.httpAddress + "/opac/extras/ac/jacket/small/"+record.isbn; - //start async download of image - imageDownloader.download(imageHref, recordImage); - // Get reference to TextView - title - recordTitle = (TextView) row.findViewById(R.id.search_record_title); - - // Get reference to TextView - author - recordAuthor = (TextView) row.findViewById(R.id.search_record_author); - - //Get referance to TextView - record Publisher date+publisher - recordPublisher = (TextView) row.findViewById(R.id.search_record_publishing); - - //set text - - recordTitle.setText(record.title); - recordAuthor.setText(record.author); - recordPublisher.setText(record.pubdate + " " + record.publisher); + + Log.d(TAG, "reord image value " + recordImage); + // Get reference to ImageView + recordImage = (ImageView) row.findViewById(R.id.search_record_img); + //TODO fix bugs + features + String imageHref = GlobalConfigs.httpAddress + "/opac/extras/ac/jacket/small/"+record.isbn; + //start async download of image + imageDownloader.download(imageHref, recordImage); + // Get reference to TextView - title + recordTitle = (TextView) row.findViewById(R.id.search_record_title); + + // Get reference to TextView - author + recordAuthor = (TextView) row.findViewById(R.id.search_record_author); + + //Get referance to TextView - record Publisher date+publisher + recordPublisher = (TextView) row.findViewById(R.id.search_record_publishing); + + //set text + + recordTitle.setText(record.title); + recordAuthor.setText(record.author); + recordPublisher.setText(record.pubdate + " " + record.publisher); } return row; } diff --git a/Open-ILS/src/Android/src/org/evergreen/android/utils/ui/BasicDetailsFragment.java b/Open-ILS/src/Android/src/org/evergreen/android/utils/ui/BasicDetailsFragment.java index 2a10eea6d5..515e9a3571 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/utils/ui/BasicDetailsFragment.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/utils/ui/BasicDetailsFragment.java @@ -14,12 +14,14 @@ import org.evergreen.android.globals.GlobalConfigs; import org.evergreen.android.globals.NoAccessToServer; import org.evergreen.android.globals.NoNetworkAccessException; import org.evergreen.android.searchCatalog.CopyInformation; +import org.evergreen.android.searchCatalog.ImageDownloader; import org.evergreen.android.searchCatalog.RecordInfo; import org.evergreen.android.searchCatalog.SearchCatalog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.Intent; +import android.graphics.Bitmap; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; @@ -31,6 +33,7 @@ import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; @@ -73,7 +76,10 @@ public class BasicDetailsFragment extends Fragment{ private Dialog dialog; private ArrayList bookBags; + + private final ImageDownloader imageDownloader = new ImageDownloader(); + private ImageView recordImage; //max display info private int list_size = 3; @@ -129,6 +135,8 @@ public class BasicDetailsFragment extends Fragment{ synopsisTextView = (TextView) layout.findViewById(R.id.record_details_simple_synopsis); isbnTextView = (TextView) layout.findViewById(R.id.record_details_simple_isbn); + recordImage = (ImageView) layout.findViewById(R.id.record_details_simple_image); + placeHoldButton = (Button) layout.findViewById(R.id.simple_place_hold_button); addToBookbagButton = (Button) layout.findViewById(R.id.simple_add_to_bookbag_button); @@ -142,6 +150,12 @@ public class BasicDetailsFragment extends Fragment{ } }); + String imageHref = GlobalConfigs.httpAddress + "/opac/extras/ac/jacket/large/"+record.isbn; + + //start async download of image + imageDownloader.download(imageHref, recordImage); + + AccountAccess ac = AccountAccess.getAccountAccess(); bookBags = ac.bookBags; -- 2.11.0