From 90df62f3e64b3cca950b3293b3fe9e52a0d30174 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 30 Oct 2015 12:44:11 +0300 Subject: [PATCH] Context menu: added image to Photo menu --- .../builders/AudioVideoNoteMenuBuilder.java | 67 +++++++++++++++++++ .../AudioVideoNoteMenuController.java | 19 +++--- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AudioVideoNoteMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AudioVideoNoteMenuBuilder.java index 7637d59440..5bc775b0f6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AudioVideoNoteMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AudioVideoNoteMenuBuilder.java @@ -1,8 +1,19 @@ package net.osmand.plus.mapcontextmenu.builders; import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; import net.osmand.access.AccessibleAlertBuilder; import net.osmand.plus.OsmandApplication; @@ -38,6 +49,31 @@ public class AudioVideoNoteMenuBuilder extends MenuBuilder { File file = recording.getFile(); if (file != null) { + + if (recording.isPhoto()) { + BitmapFactory.Options opts = new BitmapFactory.Options(); + opts.inSampleSize = 4; + int rot = recording.getBitmapRotation(); + Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath(), opts); + if (rot != 0) { + Matrix matrix = new Matrix(); + matrix.postRotate(rot); + Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); + bmp.recycle(); + bmp = resizedBitmap; + } + + buildImageRow(view, bmp, new OnClickListener() { + @Override + public void onClick(View v) { + Intent vint = new Intent(Intent.ACTION_VIEW); + vint.setDataAndType(Uri.fromFile(recording.getFile()), "image/*"); + vint.setFlags(0x10000000); + v.getContext().startActivity(vint); + } + }); + } + DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(view.getContext()); DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(view.getContext()); Date date = new Date(recording.getFile().lastModified()); @@ -70,4 +106,35 @@ public class AudioVideoNoteMenuBuilder extends MenuBuilder { } }); } + + protected void buildImageRow(final View view, Bitmap bitmap, OnClickListener onClickListener) { + LinearLayout ll = new LinearLayout(view.getContext()); + ll.setOrientation(LinearLayout.HORIZONTAL); + LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ll.setLayoutParams(llParams); + + // Image + LinearLayout llImage = new LinearLayout(view.getContext()); + LinearLayout.LayoutParams llILParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + llImage.setLayoutParams(llILParams); + llImage.setOrientation(LinearLayout.VERTICAL); + llImage.setPadding(dpToPx(10f), dpToPx(10f), dpToPx(10f), dpToPx(4f)); + ll.addView(llImage); + + ImageView imageView = new ImageView(view.getContext()); + //imageView.setBackgroundResource(resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground)); + LinearLayout.LayoutParams llImgParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(194f)); + imageView.setLayoutParams(llImgParams); + imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + //imageView.setAdjustViewBounds(true); + //imageView.setMaxHeight(dpToPx(100f)); + imageView.setImageBitmap(bitmap); + + imageView.setOnClickListener(onClickListener); + llImage.addView(imageView); + + ((LinearLayout) view).addView(ll); + + rowBuilt(); + } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AudioVideoNoteMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AudioVideoNoteMenuController.java index 187845ef56..efed3c10d9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AudioVideoNoteMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AudioVideoNoteMenuController.java @@ -27,22 +27,21 @@ public class AudioVideoNoteMenuController extends MenuController { this.recording = recording; plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class); dateFormat = android.text.format.DateFormat.getMediumDateFormat(mapActivity); - titleButtonController = new TitleButtonController() { - @Override - public void buttonPressed() { - if (plugin != null) { - plugin.playRecording(getMapActivity(), recording); - } - } - }; + if (!recording.isPhoto()) { + titleButtonController = new TitleButtonController() { + @Override + public void buttonPressed() { + if (plugin != null) { + plugin.playRecording(getMapActivity(), recording); + } + } + }; titleButtonController.caption = getMapActivity().getString(R.string.recording_context_menu_play); titleButtonController.leftIconId = R.drawable.ic_play_dark; String durationStr = recording.getPlainDuration(); titleButtonController.needRightText = true; titleButtonController.rightTextCaption = "— " + durationStr; - } else { - titleButtonController.caption = getMapActivity().getString(R.string.recording_context_menu_show); } }