X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/50d7b20bf6c495c5b4b666325bda92c85725374d..43da474a54718e5cfcd8be06c0aaa5b81b80699e:/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 932fa513..9bcf9dee 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -21,6 +21,8 @@ import java.util.List; import android.accounts.Account; import android.accounts.AccountManager; +import android.app.ActionBar.LayoutParams; +import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -28,6 +30,8 @@ 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; @@ -35,6 +39,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.webkit.MimeTypeMap; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; @@ -144,8 +149,10 @@ 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()); + v.setEnabled(false); getActivity().startService(i); } @@ -194,27 +201,85 @@ 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.inPurgeable = true; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { + options.inPreferQualityOverSpeed = false; + } + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { + options.inMutable = false; + } + + 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()); + + } catch (NoSuchFieldError e) { + preview.setVisibility(View.INVISIBLE); + Log.e(TAG, "Error from access to unexisting field despite protection " + mFile.getFileLength()); + + } catch (Throwable t) { + preview.setVisibility(View.INVISIBLE); + Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t); } downloadButton.setText(R.string.filedetails_open); downloadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mFile.getMimetype()); - List list = getActivity().getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); - if (list.size() > 0) { + String storagePath = mFile.getStoragePath(); + try { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setDataAndType(Uri.parse("file://"+ storagePath), mFile.getMimetype()); + i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); - } else { - Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show(); + + } catch (Throwable t) { + Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype()); + boolean toastIt = true; + String mimeType = ""; + try { + Intent i = new Intent(Intent.ACTION_VIEW); + mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); + if (mimeType != mFile.getMimetype()) { + i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mimeType); + i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + startActivity(i); + toastIt = false; + } + + } catch (IndexOutOfBoundsException e) { + Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath); + + } catch (ActivityNotFoundException e) { + Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension"); + + } catch (Throwable th) { + Log.e(TAG, "Unexpected problem when opening: " + storagePath, th); + + } finally { + if (toastIt) { + Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show(); + } + } + } } }); @@ -281,24 +346,24 @@ public class FileDetailFragment extends SherlockFragment implements } /** - * In ownCloud 3.0.3 and 4.0.0 there is a bug that SabreDAV does not return + * In ownCloud 3.X.X and 4.X.X there is a bug that SabreDAV does not return * the time that the file was created. There is a chance that this will * be fixed in future versions. Use this method to check if this version of * ownCloud has this fix. - * @return True, if ownCloud the ownCloud version is > 3.0.4 and 4.0.1 + * @return True, if ownCloud the ownCloud version is supporting creationg time */ private boolean ocVersionSupportsTimeCreated(){ - if(mIntent != null){ + /* if(mIntent != null){ Account ocAccount = mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT); if(ocAccount != null){ AccountManager accManager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE); OwnCloudVersion ocVersion = new OwnCloudVersion(accManager .getUserData(ocAccount, AccountAuthenticator.KEY_OC_VERSION)); - if(ocVersion.compareTo(new OwnCloudVersion(0x030004)) >= 0 || ocVersion.compareTo(new OwnCloudVersion(0x040001)) >= 0){ + if(ocVersion.compareTo(new OwnCloudVersion(0x030000)) < 0) { return true; } } - } + }*/ return false; } @@ -309,8 +374,14 @@ public class FileDetailFragment extends SherlockFragment implements private class DownloadFinishReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - ((OCFile)mIntent.getParcelableExtra(EXTRA_FILE)).setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); - updateFileDetails(mIntent); + getView().findViewById(R.id.fdDownloadBtn).setEnabled(true); + if (intent.getAction().equals(FileDownloader.BAD_DOWNLOAD_MESSAGE)) { + Toast.makeText(context, R.string.downloader_download_failed , Toast.LENGTH_SHORT).show(); + + } else if (intent.getAction().equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) { + ((OCFile)mIntent.getParcelableExtra(EXTRA_FILE)).setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); + updateFileDetails(mIntent); + } } }