From 26cc9dcbea89b5767c4c4c7dd3cfeb11a7ab168d Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Wed, 3 Oct 2018 22:31:55 +0200 Subject: rework MediaViewerActivity --- .../pixart/messenger/persistance/FileBackend.java | 12 +- .../pixart/messenger/ui/ConversationFragment.java | 2 +- .../pixart/messenger/ui/MediaViewerActivity.java | 378 +++++++++++++++++++++ .../ui/ShowFullscreenMessageActivity.java | 305 ----------------- .../java/de/pixart/messenger/ui/util/ViewUtil.java | 6 +- 5 files changed, 390 insertions(+), 313 deletions(-) create mode 100644 src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java delete mode 100644 src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java (limited to 'src/main/java/de') diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 8397a7bb8..0333d24fd 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -111,8 +111,7 @@ public class FileBackend { } } - public boolean deleteFile(Message message) { - File file = getFile(message); + public boolean deleteFile(File file) { if (file.delete()) { updateMediaScanner(file); return true; @@ -121,6 +120,11 @@ public class FileBackend { } } + public boolean deleteFile(Message message) { + File file = getFile(message); + return deleteFile(file); + } + public DownloadableFile getFile(Message message) { return getFile(message, true); } @@ -219,8 +223,8 @@ public class FileBackend { } public static String getConversationsDirectory(final String type) { - if (type.equalsIgnoreCase("null") || type == null) { - return getAppMediaDirectory() + "Pix-Art Messenger" + "/"; + if (type.equalsIgnoreCase("null")) { + return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Pix-Art Messenger" + "/"; } else { return getAppMediaDirectory() + "Pix-Art Messenger" + " " + type + "/"; } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index e7c7ae1a8..2655837fa 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -625,7 +625,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke final boolean hideVoice = p.getBoolean("show_record_voice_btn", activity.getResources().getBoolean(R.bool.show_record_voice_btn)); PopupMenu popup = new PopupMenu(activity, v); popup.inflate(R.menu.choose_attachment); - Menu menu = popup.getMenu(); + final Menu menu = popup.getMenu(); ConversationMenuConfigurator.configureQuickShareAttachmentMenu(conversation, menu, hideVoice); popup.setOnMenuItemClickListener(attachmentItem -> { switch (attachmentItem.getItemId()) { diff --git a/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java b/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java new file mode 100644 index 000000000..a8285d594 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java @@ -0,0 +1,378 @@ +package de.pixart.messenger.ui; + +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.content.res.Configuration; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.media.MediaMetadataRetriever; +import android.net.Uri; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.ActionBar; +import android.support.v7.view.menu.MenuBuilder; +import android.support.v7.view.menu.MenuPopupHelper; +import android.support.v7.widget.PopupMenu; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.WindowManager; +import android.webkit.MimeTypeMap; +import android.widget.ImageView; +import android.widget.Toast; + +import com.davemorrissey.labs.subscaleview.ImageSource; +import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; +import com.github.rtoshiro.view.video.FullscreenVideoLayout; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import de.pixart.messenger.Config; +import de.pixart.messenger.R; +import de.pixart.messenger.persistance.FileBackend; +import de.pixart.messenger.utils.ExifHelper; +import de.pixart.messenger.utils.MimeUtils; + +import static de.pixart.messenger.persistance.FileBackend.close; + +public class MediaViewerActivity extends XmppActivity { + + Integer oldOrientation; + SubsamplingScaleImageView mImage; + FullscreenVideoLayout mVideo; + ImageView mFullscreenbutton; + Uri mFileUri; + File mFile; + FloatingActionButton fab; + int height = 0; + int width = 0; + int rotation = 0; + boolean isImage = false; + boolean isVideo = false; + + public static String getMimeType(String path) { + try { + String type = null; + String extension = path.substring(path.lastIndexOf(".") + 1, path.length()); + if (extension != null) { + type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + } + return type; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + this.mTheme = findTheme(); + setTheme(this.mTheme); + + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null && actionBar.isShowing()) { + actionBar.hide(); + } + + oldOrientation = getRequestedOrientation(); + + WindowManager.LayoutParams layout = getWindow().getAttributes(); + if (useMaxBrightness()) { + layout.screenBrightness = 1; + } + getWindow().setAttributes(layout); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + setContentView(R.layout.activity_media_viewer); + mImage = findViewById(R.id.message_image_view); + mVideo = findViewById(R.id.message_video_view); + mFullscreenbutton = findViewById(R.id.vcv_img_fullscreen); + fab = findViewById(R.id.fab); + fab.setOnClickListener(v -> { + PopupMenu popup = new PopupMenu(MediaViewerActivity.this, v); + popup.inflate(R.menu.media_viewer); + final Menu menu = popup.getMenu(); + MenuItem delete = menu.findItem(R.id.action_delete); + MenuItem open = menu.findItem(R.id.action_open); + Log.d(Config.LOGTAG, "Path = " + mFile.toString()); + if (mFile == null || !mFile.toString().startsWith("/") || mFile.toString().contains(FileBackend.getConversationsDirectory("null"))) { + delete.setVisible(true); + } else { + delete.setVisible(false); + } + if (isVideo) { + if (isDarkTheme()) { + open.setIcon(R.drawable.ic_video_white_24dp); + } else { + open.setIcon(R.drawable.ic_video_black_24dp); + } + } else if (isImage) { + if (isDarkTheme()) { + open.setIcon(R.drawable.ic_image_white_24dp); + } else { + open.setIcon(R.drawable.ic_image_black_24dp); + } + } + popup.setOnMenuItemClickListener(item -> { + switch (item.getItemId()) { + case R.id.action_share: + share(); + break; + case R.id.action_open: + open(); + break; + case R.id.action_delete: + deleteFile(); + break; + default: + return false; + } + return true; + }); + MenuPopupHelper menuHelper = new MenuPopupHelper(MediaViewerActivity.this, (MenuBuilder) menu, v); + menuHelper.setForceShowIcon(true); + menuHelper.show(); + }); + } + + private void share() { + Intent share = new Intent(Intent.ACTION_SEND); + share.setType(getMimeType(mFile.toString())); + share.putExtra(Intent.EXTRA_STREAM, FileBackend.getUriForFile(this, mFile)); + try { + startActivity(Intent.createChooser(share, getText(R.string.share_with))); + } catch (ActivityNotFoundException e) { + //This should happen only on faulty androids because normally chooser is always available + Toast.makeText(this, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); + } + } + + private void deleteFile() { + this.xmppConnectionService.getFileBackend().deleteFile(mFile); + finish(); + } + + private void open() { + Uri uri; + try { + uri = FileBackend.getUriForFile(this, mFile); + } catch (SecurityException e) { + Log.d(Config.LOGTAG, "No permission to access " + mFile.getAbsolutePath(), e); + Toast.makeText(this, this.getString(R.string.no_permission_to_access_x, mFile.getAbsolutePath()), Toast.LENGTH_SHORT).show(); + return; + } + String mime = MimeUtils.guessMimeTypeFromUri(this, uri); + Intent openIntent = new Intent(Intent.ACTION_VIEW); + openIntent.setDataAndType(uri, mime); + openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + PackageManager manager = this.getPackageManager(); + List info = manager.queryIntentActivities(openIntent, 0); + if (info.size() == 0) { + openIntent.setDataAndType(uri, "*/*"); + } + try { + this.startActivity(openIntent); + finish(); + } catch (ActivityNotFoundException e) { + Toast.makeText(this, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); + } + } + + @Override + protected void refreshUiReal() { + + } + + @Override + protected void onStart() { + super.onStart(); + Intent intent = getIntent(); + if (intent != null) { + if (intent.hasExtra("image")) { + mFileUri = intent.getParcelableExtra("image"); + mFile = new File(mFileUri.getPath()); + if (mFileUri != null && mFile.exists() && mFile.length() > 0) { + try { + isImage = true; + DisplayImage(mFile, mFileUri); + } catch (Exception e) { + isImage = false; + Log.d(Config.LOGTAG, "Illegal exeption :" + e); + Toast.makeText(MediaViewerActivity.this, getString(R.string.error_file_corrupt), Toast.LENGTH_SHORT).show(); + finish(); + } + } else { + Toast.makeText(MediaViewerActivity.this, getString(R.string.file_deleted), Toast.LENGTH_SHORT).show(); + } + } else if (intent.hasExtra("video")) { + mFileUri = intent.getParcelableExtra("video"); + mFile = new File(mFileUri.getPath()); + if (mFileUri != null && mFile.exists() && mFile.length() > 0) { + try { + isVideo = true; + DisplayVideo(mFileUri); + } catch (Exception e) { + isVideo = false; + Log.d(Config.LOGTAG, "Illegal exeption :" + e); + Toast.makeText(MediaViewerActivity.this, getString(R.string.error_file_corrupt), Toast.LENGTH_SHORT).show(); + finish(); + } + } else { + Toast.makeText(MediaViewerActivity.this, getString(R.string.file_deleted), Toast.LENGTH_SHORT).show(); + } + } + } + } + + private void DisplayImage(final File file, final Uri FileUri) { + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeFile(new File(file.getPath()).getAbsolutePath(), options); + height = options.outHeight; + width = options.outWidth; + rotation = getRotation(Uri.parse("file://" + file.getAbsolutePath())); + Log.d(Config.LOGTAG, "Image height: " + height + ", width: " + width + ", rotation: " + rotation); + if (useAutoRotateScreen()) { + rotateScreen(width, height, rotation); + } + mImage.setVisibility(View.VISIBLE); + try { + mImage.setImage(ImageSource.uri(FileUri)); + } catch (Exception e) { + Toast.makeText(this, getString(R.string.error_file_corrupt), Toast.LENGTH_LONG).show(); + e.printStackTrace(); + } + } + + private void DisplayVideo(final Uri uri) { + MediaMetadataRetriever retriever = new MediaMetadataRetriever(); + retriever.setDataSource(uri.getPath()); + Bitmap bitmap = null; + try { + bitmap = retriever.getFrameAtTime(); + height = bitmap.getHeight(); + width = bitmap.getWidth(); + } catch (Exception e) { + height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)); + width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); + } finally { + if (bitmap != null) { + bitmap.recycle(); + } + } + rotation = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)); + Log.d(Config.LOGTAG, "Video height: " + height + ", width: " + width + ", rotation: " + rotation); + if (useAutoRotateScreen()) { + rotateScreen(width, height, rotation); + } + try { + mVideo.setVisibility(View.VISIBLE); + mVideo.setVideoURI(uri); + mFullscreenbutton.setVisibility(View.INVISIBLE); + mVideo.setShouldAutoplay(true); + + } catch (IOException e) { + Toast.makeText(this, getString(R.string.error_file_corrupt), Toast.LENGTH_LONG).show(); + e.printStackTrace(); + } + } + + private int getRotation(Uri image) { + InputStream is = null; + try { + is = this.getContentResolver().openInputStream(image); + return ExifHelper.getOrientation(is); + } catch (FileNotFoundException e) { + return 0; + } finally { + close(is); + } + } + + private void rotateScreen(final int width, final int height, final int rotation) { + if (width > height) { + if (rotation == 0 || rotation == 180) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); + } else { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); + } + } else if (width <= height) { + if (rotation == 90 || rotation == 270) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); + } else { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); + } + } + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + } + + @Override + public void onResume() { + WindowManager.LayoutParams layout = getWindow().getAttributes(); + if (useMaxBrightness()) { + layout.screenBrightness = 1; + } + getWindow().setAttributes(layout); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + mVideo.setShouldAutoplay(true); + super.onResume(); + } + + @Override + public void onPause() { + mVideo.reset(); + WindowManager.LayoutParams layout = getWindow().getAttributes(); + if (useMaxBrightness()) { + layout.screenBrightness = -1; + } + getWindow().setAttributes(layout); + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setRequestedOrientation(oldOrientation); + super.onPause(); + } + + @Override + public void onStop() { + mVideo.reset(); + WindowManager.LayoutParams layout = getWindow().getAttributes(); + if (useMaxBrightness()) { + layout.screenBrightness = -1; + } + getWindow().setAttributes(layout); + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setRequestedOrientation(oldOrientation); + super.onStop(); + } + + @Override + void onBackendConnected() { + + } + + public boolean useMaxBrightness() { + return getPreferences().getBoolean("use_max_brightness", getResources().getBoolean(R.bool.use_max_brightness)); + } + + public boolean useAutoRotateScreen() { + return getPreferences().getBoolean("use_auto_rotate", getResources().getBoolean(R.bool.auto_rotate)); + } + + protected SharedPreferences getPreferences() { + return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + } +} \ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java b/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java deleted file mode 100644 index b34e49653..000000000 --- a/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java +++ /dev/null @@ -1,305 +0,0 @@ -package de.pixart.messenger.ui; - -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.ActivityInfo; -import android.content.res.Configuration; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.media.MediaMetadataRetriever; -import android.net.Uri; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.design.widget.FloatingActionButton; -import android.support.v7.app.ActionBar; -import android.util.Log; -import android.view.View; -import android.view.WindowManager; -import android.webkit.MimeTypeMap; -import android.widget.ImageView; -import android.widget.Toast; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.resource.drawable.GlideDrawable; -import com.bumptech.glide.request.animation.GlideAnimation; -import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; -import com.github.chrisbanes.photoview.PhotoView; -import com.github.chrisbanes.photoview.PhotoViewAttacher; -import com.github.rtoshiro.view.video.FullscreenVideoLayout; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; - -import de.pixart.messenger.Config; -import de.pixart.messenger.R; -import de.pixart.messenger.persistance.FileBackend; -import de.pixart.messenger.utils.ExifHelper; - -import static de.pixart.messenger.persistance.FileBackend.close; - -public class ShowFullscreenMessageActivity extends XmppActivity { - - Integer oldOrientation; - PhotoView mImage; - FullscreenVideoLayout mVideo; - ImageView mFullscreenbutton; - Uri mFileUri; - File mFile; - FloatingActionButton fab; - int height = 0; - int width = 0; - int rotation = 0; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - this.mTheme = findTheme(); - setTheme(this.mTheme); - - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null && actionBar.isShowing()) { - actionBar.hide(); - } - - oldOrientation = getRequestedOrientation(); - - WindowManager.LayoutParams layout = getWindow().getAttributes(); - if (useMaxBrightness()) { - layout.screenBrightness = 1; - } - getWindow().setAttributes(layout); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - setContentView(R.layout.activity_fullscreen_message); - mImage = findViewById(R.id.message_image_view); - mVideo = findViewById(R.id.message_video_view); - mFullscreenbutton = findViewById(R.id.vcv_img_fullscreen); - fab = findViewById(R.id.fab); - fab.setOnClickListener(v -> { - mVideo.reset(); - shareWith(mFile); - }); - } - - private void shareWith(File mFile) { - Intent share = new Intent(Intent.ACTION_SEND); - share.setType(getMimeType(mFile.toString())); - share.putExtra(Intent.EXTRA_STREAM, FileBackend.getUriForFile(this, mFile)); - try { - startActivity(Intent.createChooser(share, getText(R.string.share_with))); - } catch (ActivityNotFoundException e) { - //This should happen only on faulty androids because normally chooser is always available - Toast.makeText(this, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); - } - } - - public static String getMimeType(String path) { - try { - String type = null; - String extension = path.substring(path.lastIndexOf(".") + 1, path.length()); - if (extension != null) { - type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); - } - return type; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - @Override - protected void refreshUiReal() { - - } - - @Override - protected void onStart() { - super.onStart(); - Intent intent = getIntent(); - if (intent != null) { - if (intent.hasExtra("image")) { - mFileUri = intent.getParcelableExtra("image"); - mFile = new File(mFileUri.getPath()); - if (mFileUri != null && mFile.exists() && mFile.length() > 0) { - try { - DisplayImage(mFile); - } catch (Exception e) { - Log.d(Config.LOGTAG, "Illegal exeption :" + e); - Toast.makeText(ShowFullscreenMessageActivity.this, getString(R.string.error_file_corrupt), Toast.LENGTH_SHORT).show(); - finish(); - } - } else { - Toast.makeText(ShowFullscreenMessageActivity.this, getString(R.string.file_deleted), Toast.LENGTH_SHORT).show(); - } - } else if (intent.hasExtra("video")) { - mFileUri = intent.getParcelableExtra("video"); - mFile = new File(mFileUri.getPath()); - if (mFileUri != null && mFile.exists() && mFile.length() > 0) { - try { - DisplayVideo(mFileUri); - } catch (Exception e) { - Log.d(Config.LOGTAG, "Illegal exeption :" + e); - Toast.makeText(ShowFullscreenMessageActivity.this, getString(R.string.error_file_corrupt), Toast.LENGTH_SHORT).show(); - finish(); - } - } else { - Toast.makeText(ShowFullscreenMessageActivity.this, getString(R.string.file_deleted), Toast.LENGTH_SHORT).show(); - } - } - } - } - - private void DisplayImage(final File file) { - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - BitmapFactory.decodeFile(new File(file.getPath()).getAbsolutePath(), options); - height = options.outHeight; - width = options.outWidth; - rotation = getRotation(Uri.parse("file://" + file.getAbsolutePath())); - Log.d(Config.LOGTAG, "Image height: " + height + ", width: " + width + ", rotation: " + rotation); - if (useAutoRotateScreen()) { - rotateScreen(width, height, rotation); - } - final PhotoViewAttacher mAttacher = new PhotoViewAttacher(mImage); - mImage.setVisibility(View.VISIBLE); - try { - Glide.with(this) - .load(file) - .dontAnimate() - .into(new GlideDrawableImageViewTarget(mImage) { - @Override - public void onResourceReady(GlideDrawable resource, GlideAnimation animation) { - super.onResourceReady(resource, animation); - mAttacher.update(); - } - }); - } catch (Exception e) { - Toast.makeText(this, getString(R.string.error_file_corrupt), Toast.LENGTH_LONG).show(); - e.printStackTrace(); - } - } - - private void DisplayVideo(final Uri uri) { - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - retriever.setDataSource(uri.getPath()); - Bitmap bitmap = null; - try { - bitmap = retriever.getFrameAtTime(); - height = bitmap.getHeight(); - width = bitmap.getWidth(); - } catch (Exception e) { - height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)); - width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); - } finally { - if (bitmap != null) { - bitmap.recycle(); - } - } - rotation = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)); - Log.d(Config.LOGTAG, "Video height: " + height + ", width: " + width + ", rotation: " + rotation); - if (useAutoRotateScreen()) { - rotateScreen(width, height, rotation); - } - try { - mVideo.setVisibility(View.VISIBLE); - mVideo.setVideoURI(uri); - mFullscreenbutton.setVisibility(View.INVISIBLE); - mVideo.setShouldAutoplay(true); - - } catch (IOException e) { - Toast.makeText(this, getString(R.string.error_file_corrupt), Toast.LENGTH_LONG).show(); - e.printStackTrace(); - } - } - - private int getRotation(Uri image) { - InputStream is = null; - try { - is = this.getContentResolver().openInputStream(image); - return ExifHelper.getOrientation(is); - } catch (FileNotFoundException e) { - return 0; - } finally { - close(is); - } - } - - private void rotateScreen(final int width, final int height, final int rotation) { - if (width > height) { - if (rotation == 0 || rotation == 180) { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); - } else { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); - } - } else if (width <= height) { - if (rotation == 90 || rotation == 270) { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); - } else { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); - } - } - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - } - - @Override - public void onResume() { - WindowManager.LayoutParams layout = getWindow().getAttributes(); - if (useMaxBrightness()) { - layout.screenBrightness = 1; - } - getWindow().setAttributes(layout); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - mVideo.setShouldAutoplay(true); - super.onResume(); - } - - @Override - public void onPause() { - mVideo.reset(); - WindowManager.LayoutParams layout = getWindow().getAttributes(); - if (useMaxBrightness()) { - layout.screenBrightness = -1; - } - getWindow().setAttributes(layout); - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - setRequestedOrientation(oldOrientation); - super.onPause(); - } - - @Override - public void onStop() { - mVideo.reset(); - WindowManager.LayoutParams layout = getWindow().getAttributes(); - if (useMaxBrightness()) { - layout.screenBrightness = -1; - } - getWindow().setAttributes(layout); - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - setRequestedOrientation(oldOrientation); - super.onStop(); - } - - @Override - void onBackendConnected() { - - } - - public boolean useMaxBrightness() { - return getPreferences().getBoolean("use_max_brightness", getResources().getBoolean(R.bool.use_max_brightness)); - } - - public boolean useAutoRotateScreen() { - return getPreferences().getBoolean("use_auto_rotate", getResources().getBoolean(R.bool.auto_rotate)); - } - - protected SharedPreferences getPreferences() { - return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - } -} \ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/util/ViewUtil.java b/src/main/java/de/pixart/messenger/ui/util/ViewUtil.java index b1905479b..07e25e31d 100644 --- a/src/main/java/de/pixart/messenger/ui/util/ViewUtil.java +++ b/src/main/java/de/pixart/messenger/ui/util/ViewUtil.java @@ -15,7 +15,7 @@ import java.util.List; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.persistance.FileBackend; -import de.pixart.messenger.ui.ShowFullscreenMessageActivity; +import de.pixart.messenger.ui.MediaViewerActivity; public class ViewUtil { @@ -36,7 +36,7 @@ public class ViewUtil { } // use internal viewer for images and videos if (mime.startsWith("image/")) { - Intent intent = new Intent(context, ShowFullscreenMessageActivity.class); + Intent intent = new Intent(context, MediaViewerActivity.class); intent.putExtra("image", Uri.fromFile(file)); try { context.startActivity(intent); @@ -45,7 +45,7 @@ public class ViewUtil { //ignored } } else if (mime.startsWith("video/")) { - Intent intent = new Intent(context, ShowFullscreenMessageActivity.class); + Intent intent = new Intent(context, MediaViewerActivity.class); intent.putExtra("video", Uri.fromFile(file)); try { context.startActivity(intent); -- cgit v1.2.3