X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/24a1111aa117f9d825646c23909e39a0d12f43b8..12c00057e7a4b279ad245d54d906e74a899aec4b:/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 2241f6f6..ee695553 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -17,14 +17,20 @@ */ package eu.alefzero.owncloud.ui.fragment; +import java.util.List; + import android.accounts.Account; import android.accounts.AccountManager; +import android.app.ActionBar.LayoutParams; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.BitmapFactory.Options; +import android.graphics.Path.FillType; import android.net.Uri; import android.os.Bundle; import android.util.Log; @@ -141,7 +147,8 @@ public class FileDetailFragment extends SherlockFragment implements Intent i = new Intent(getActivity(), FileDownloader.class); i.putExtra(FileDownloader.EXTRA_ACCOUNT, mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT)); - i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath()); + i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath()); + i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getURLDecodedRemotePath()); i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength()); getActivity().startService(i); } @@ -191,14 +198,31 @@ public class FileDetailFragment extends SherlockFragment implements // Update preview if (mFile.getStoragePath() != null) { + ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview); try { if (mFile.getMimetype().startsWith("image/")) { - ImageView preview = (ImageView) getView().findViewById( - R.id.fdPreview); - Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath()); + BitmapFactory.Options options = new Options(); + options.inScaled = true; + options.inMutable = false; + options.inPreferQualityOverSpeed = false; + options.inPurgeable = true; + + Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options); + + int width = options.outWidth; + int height = options.outHeight; + int scale = 1; + if (width >= 2048 || height >= 2048) { + scale = (int) (Math.ceil(Math.max(height, width)/2048.)); + options.inSampleSize = scale; + bmp.recycle(); + + bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options); + } preview.setImageBitmap(bmp); } } catch (OutOfMemoryError e) { + preview.setVisibility(View.INVISIBLE); Log.e(TAG, "Out of memory occured for file with size " + mFile.getFileLength()); } downloadButton.setText(R.string.filedetails_open); @@ -207,7 +231,12 @@ public class FileDetailFragment extends SherlockFragment implements public void onClick(View v) { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mFile.getMimetype()); - startActivity(i); + List list = getActivity().getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); + if (list.size() > 0) { + startActivity(i); + } else { + Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show(); + } } }); } else { @@ -301,9 +330,10 @@ public class FileDetailFragment extends SherlockFragment implements private class DownloadFinishReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - updateFileDetails(); + ((OCFile)mIntent.getParcelableExtra(EXTRA_FILE)).setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); + updateFileDetails(mIntent); } - + } }