From: David A. Velasco Date: Thu, 11 Dec 2014 09:21:41 +0000 (+0100) Subject: Merge pull request #781 from owncloud/fix_logs_change_orientation X-Git-Tag: oc-android-1.7.0_signed~80 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/1f796350b0a3fac88222265ebdd1e84e14ebbac6?hp=c34646aed37a51fc9499b9bef8e5b30c7e8e10a6 Merge pull request #781 from owncloud/fix_logs_change_orientation User chooser for sending mail in LogHistory (with crash fixed if device is rotated in the e-mail app) --- diff --git a/res/layout/preference_widget_radiobutton.xml b/res/layout/preference_widget_radiobutton.xml new file mode 100644 index 00000000..85f8f600 --- /dev/null +++ b/res/layout/preference_widget_radiobutton.xml @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/res/values-de-rDE/strings.xml b/res/values-de-rDE/strings.xml index dca43024..00fdce2e 100644 --- a/res/values-de-rDE/strings.xml +++ b/res/values-de-rDE/strings.xml @@ -296,5 +296,5 @@ um diese Datei zu verschieben Sofortiges Hochladen Sicherheit - Upload-Verzeichnis für Videos + Verzeichnis zum Hochladen der Videos diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index bfc86cee..2d7ccd4d 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -296,4 +296,5 @@ um diese Datei zu verschieben Sofortiges Hochladen Sicherheit + Verzeichnis zum Hochladen der Videos diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml index ea3aa0a8..4efe1ef9 100644 --- a/res/values-it/strings.xml +++ b/res/values-it/strings.xml @@ -35,7 +35,7 @@ Mostra i log registrati Elimina la cronologia Aiuto - Consiglia ad un amico + Consiglia a un amico Segnalazioni Imprint Ricorda la posizione della condivisione @@ -296,4 +296,5 @@ per spostare questo file Caricamenti istantanei Protezione + Percorso di caricamento video diff --git a/res/values-ja-rJP/strings.xml b/res/values-ja-rJP/strings.xml index a3c0452e..7c0d99c0 100644 --- a/res/values-ja-rJP/strings.xml +++ b/res/values-ja-rJP/strings.xml @@ -297,4 +297,5 @@ このファイルを移動 自動アップロード セキュリティ + 動画のアップロードパス diff --git a/res/values-nl/strings.xml b/res/values-nl/strings.xml index 600e182d..84a0e0dd 100644 --- a/res/values-nl/strings.xml +++ b/res/values-nl/strings.xml @@ -299,4 +299,5 @@ Hieronder staan de lokale bestanden en de externe bestanden in %5$s waar ze naar om dit bestand te verplaatsen Directe uploads Beveiliging + Upload Video Pad diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml index 8a628018..3f58746b 100644 --- a/res/values-ru/strings.xml +++ b/res/values-ru/strings.xml @@ -38,6 +38,8 @@ Рекомендовать другу Обратная связь Штамп + Запомнить расположение публикации + Запомнить расположение загрузки последней публикации Попробуйте %1$s на вашем смартфоне! Хочу предложить вам использовать %1$s на смартфоне!\nЗагрузить можно здесь: %2$s @@ -294,4 +296,5 @@ переместить этот файл Мгновенные загрузки Безопасность + Путь для загрузки Видео diff --git a/res/values-sl/strings.xml b/res/values-sl/strings.xml index b283b274..86be0f34 100644 --- a/res/values-sl/strings.xml +++ b/res/values-sl/strings.xml @@ -296,4 +296,5 @@ med premikanjem datoteke Takojšnje pošiljanje v oblak Varnost + Pot videa za pošiljanje diff --git a/res/values-tr/strings.xml b/res/values-tr/strings.xml index ec1c6a70..a35922f7 100644 --- a/res/values-tr/strings.xml +++ b/res/values-tr/strings.xml @@ -296,4 +296,5 @@ bu dosyayı taşımak için Anında Yüklemeler Güvenlik + Video Yükleme Yolu diff --git a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 1d2cda8c..ce53c444 100644 --- a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -29,8 +29,10 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; +import android.graphics.Matrix; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import android.media.ExifInterface; import android.media.ThumbnailUtils; import android.net.Uri; import android.os.AsyncTask; @@ -216,6 +218,9 @@ public class ThumbnailsCacheManager { if (bitmap != null) { thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px); + + // Rotate image, obeying exif tag + thumbnail = BitmapUtils.rotateImage(thumbnail, mFile.getStoragePath()); // Add thumbnail to cache addBitmapToCache(imageKey, thumbnail); @@ -317,5 +322,5 @@ public class ThumbnailsCacheManager { mThumbnailsDiskCacheLock.notifyAll(); // Wake any waiting threads } } - + } diff --git a/src/com/owncloud/android/ui/LongClickableCheckBoxPreference.java b/src/com/owncloud/android/ui/LongClickableCheckBoxPreference.java deleted file mode 100644 index 5befe64a..00000000 --- a/src/com/owncloud/android/ui/LongClickableCheckBoxPreference.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.owncloud.android.ui; - -import android.content.Context; -import android.preference.CheckBoxPreference; -import android.view.View; - -public class LongClickableCheckBoxPreference extends CheckBoxPreference implements View.OnLongClickListener { - - public LongClickableCheckBoxPreference(Context context) { - super(context); - } - - @Override - public boolean onLongClick(View v) { - return true; - } -} diff --git a/src/com/owncloud/android/ui/RadioButtonPreference.java b/src/com/owncloud/android/ui/RadioButtonPreference.java new file mode 100644 index 00000000..8f562b36 --- /dev/null +++ b/src/com/owncloud/android/ui/RadioButtonPreference.java @@ -0,0 +1,20 @@ +package com.owncloud.android.ui; + +import android.content.Context; +import android.preference.CheckBoxPreference; +import android.view.View; + +import com.owncloud.android.R; + +public class RadioButtonPreference extends CheckBoxPreference implements View.OnLongClickListener { + + public RadioButtonPreference(Context context) { + super(context, null, android.R.attr.checkBoxPreferenceStyle); + setWidgetLayoutResource(R.layout.preference_widget_radiobutton); + } + + @Override + public boolean onLongClick(View v) { + return true; + } +} diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index f794cf15..04a4c7af 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -53,7 +53,7 @@ import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.db.DbHandler; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.ui.LongClickableCheckBoxPreference; +import com.owncloud.android.ui.RadioButtonPreference; import com.owncloud.android.utils.DisplayUtils; @@ -107,9 +107,9 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa ListAdapter listAdapter = listView.getAdapter(); Object obj = listAdapter.getItem(position); - if (obj != null && obj instanceof LongClickableCheckBoxPreference) { + if (obj != null && obj instanceof RadioButtonPreference) { mShowContextMenu = true; - mAccountName = ((LongClickableCheckBoxPreference) obj).getKey(); + mAccountName = ((RadioButtonPreference) obj).getKey(); Preferences.this.openContextMenu(listView); @@ -463,7 +463,7 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa else { for (Account a : accounts) { - LongClickableCheckBoxPreference accountPreference = new LongClickableCheckBoxPreference(this); + RadioButtonPreference accountPreference = new RadioButtonPreference(this); accountPreference.setKey(a.name); // Handle internationalized domain names accountPreference.setTitle(DisplayUtils.convertIdn(a.name, false)); @@ -483,7 +483,7 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE); Account accounts[] = am.getAccountsByType(MainApp.getAccountType()); for (Account a : accounts) { - CheckBoxPreference p = (CheckBoxPreference) findPreference(a.name); + RadioButtonPreference p = (RadioButtonPreference) findPreference(a.name); if (key.equals(a.name)) { boolean accountChanged = !p.isChecked(); p.setChecked(true); diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java index a3814c77..0995793d 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -53,6 +53,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.fragment.FileFragment; +import com.owncloud.android.utils.BitmapUtils; import com.owncloud.android.utils.TouchImageViewCustom; @@ -82,6 +83,8 @@ public class PreviewImageFragment extends FileFragment { private static final String TAG = PreviewImageFragment.class.getSimpleName(); private boolean mIgnoreFirstSavedState; + + private LoadBitmapTask mLoadBitmapTask = null; /** @@ -190,12 +193,22 @@ public class PreviewImageFragment extends FileFragment { public void onStart() { super.onStart(); if (getFile() != null) { - BitmapLoader bl = new BitmapLoader(mImageView, mMessageView, mProgressWheel); - bl.execute(new String[]{getFile().getStoragePath()}); + mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel); + mLoadBitmapTask.execute(new String[]{getFile().getStoragePath()}); } } + @Override + public void onStop() { + super.onStop(); + if (mLoadBitmapTask != null) { + mLoadBitmapTask.cancel(true); + mLoadBitmapTask = null; + } + + } + /** * {@inheritDoc} */ @@ -328,8 +341,8 @@ public class PreviewImageFragment extends FileFragment { finish(); } - - private class BitmapLoader extends AsyncTask { + + private class LoadBitmapTask extends AsyncTask { /** * Weak reference to the target {@link ImageView} where the bitmap will be loaded into. @@ -365,7 +378,7 @@ public class PreviewImageFragment extends FileFragment { * * @param imageView Target {@link ImageView} where the bitmap will be loaded into. */ - public BitmapLoader(ImageViewCustom imageView, TextView messageView, ProgressBar progressWheel) { + public LoadBitmapTask(ImageViewCustom imageView, TextView messageView, ProgressBar progressWheel) { mImageViewRef = new WeakReference(imageView); mMessageViewRef = new WeakReference(messageView); mProgressWheelRef = new WeakReference(progressWheel); @@ -379,43 +392,65 @@ public class PreviewImageFragment extends FileFragment { String storagePath = params[0]; try { + if (isCancelled()) return result; + File picture = new File(storagePath); if (picture != null) { - //Decode file into a bitmap in real size for being able to make zoom on the image + // Decode file into a bitmap in real size for being able to make zoom on + // the image result = BitmapFactory.decodeStream(new FlushedInputStream (new BufferedInputStream(new FileInputStream(picture)))); } + if (isCancelled()) return result; + if (result == null) { mErrorMessageId = R.string.preview_image_error_unknown_format; Log_OC.e(TAG, "File could not be loaded as a bitmap: " + storagePath); + } else { + // Rotate image, obeying exif tag. + result = BitmapUtils.rotateImage(result, storagePath); } } catch (OutOfMemoryError e) { Log_OC.e(TAG, "Out of memory occured for file " + storagePath, e); - // If out of memory error when loading image, try to load it scaled + if (isCancelled()) return result; + + // If out of memory error when loading or rotating image, try to load it scaled result = loadScaledImage(storagePath); if (result == null) { mErrorMessageId = R.string.preview_image_error_unknown_format; Log_OC.e(TAG, "File could not be loaded as a bitmap: " + storagePath); + } else { + // Rotate scaled image, obeying exif tag + result = BitmapUtils.rotateImage(result, storagePath); } } catch (NoSuchFieldError e) { mErrorMessageId = R.string.common_error_unknown; - Log_OC.e(TAG, "Error from access to unexisting field despite protection; file " + storagePath, e); + Log_OC.e(TAG, "Error from access to unexisting field despite protection; file " + + storagePath, e); } catch (Throwable t) { mErrorMessageId = R.string.common_error_unknown; Log_OC.e(TAG, "Unexpected error loading " + getFile().getStoragePath(), t); } + return result; } @Override + protected void onCancelled(Bitmap result) { + if (result != null) { + result.recycle(); + } + } + + @Override protected void onPostExecute(Bitmap result) { hideProgressWheel(); if (result != null) { @@ -424,7 +459,7 @@ public class PreviewImageFragment extends FileFragment { showErrorMessage(); } } - + @SuppressLint("InlinedApi") private void showLoadedImage(Bitmap result) { if (mImageViewRef != null) { diff --git a/src/com/owncloud/android/utils/BitmapUtils.java b/src/com/owncloud/android/utils/BitmapUtils.java index 687b5a4f..70367278 100644 --- a/src/com/owncloud/android/utils/BitmapUtils.java +++ b/src/com/owncloud/android/utils/BitmapUtils.java @@ -16,9 +16,13 @@ */ package com.owncloud.android.utils; +import com.owncloud.android.lib.common.utils.Log_OC; + import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Matrix; import android.graphics.BitmapFactory.Options; +import android.media.ExifInterface; /** * Utility class with methods for decoding Bitmaps. @@ -96,4 +100,75 @@ public class BitmapUtils { return inSampleSize; } + /** + * Rotate bitmap according to EXIF orientation. + * Cf. http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ + * @param bitmap Bitmap to be rotated + * @param storagePath Path to source file of bitmap. Needed for EXIF information. + * @return correctly EXIF-rotated bitmap + */ + public static Bitmap rotateImage(Bitmap bitmap, String storagePath){ + Bitmap resultBitmap = bitmap; + + try + { + ExifInterface exifInterface = new ExifInterface(storagePath); + int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); + + Matrix matrix = new Matrix(); + + // 1: nothing to do + + // 2 + if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) + { + matrix.postScale(-1.0f, 1.0f); + } + // 3 + else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) + { + matrix.postRotate(180); + } + // 4 + else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) + { + matrix.postScale(1.0f, -1.0f); + } + // 5 + else if (orientation == ExifInterface.ORIENTATION_TRANSPOSE) + { + matrix.postRotate(-90); + matrix.postScale(1.0f, -1.0f); + } + // 6 + else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) + { + matrix.postRotate(90); + } + // 7 + else if (orientation == ExifInterface.ORIENTATION_TRANSVERSE) + { + matrix.postRotate(90); + matrix.postScale(1.0f, -1.0f); + } + // 8 + else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) + { + matrix.postRotate(270); + } + + // Rotate the bitmap + resultBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); + if (resultBitmap != bitmap) { + bitmap.recycle(); + } + } + catch (Exception exception) + { + Log_OC.e("BitmapUtil", "Could not rotate the image: " + storagePath); + } + return resultBitmap; + } + + }