1 package jp.sfjp.gokigen.a01c.liveview;
3 import android.content.Context;
4 import android.content.SharedPreferences;
5 import android.graphics.Bitmap;
6 import android.graphics.BitmapFactory;
7 import android.graphics.Canvas;
8 import android.graphics.Color;
9 import android.graphics.Paint;
10 import android.graphics.PointF;
11 import android.graphics.Rect;
12 import android.graphics.RectF;
13 import android.media.ExifInterface;
14 import android.os.Looper;
15 import android.preference.PreferenceManager;
16 import android.util.AttributeSet;
17 import android.util.DisplayMetrics;
18 import android.util.Log;
19 import android.util.TypedValue;
20 import android.view.MotionEvent;
21 import android.view.View;
22 import android.widget.ImageView;
25 import java.util.Timer;
26 import java.util.TimerTask;
28 import jp.co.olympus.camerakit.OLYCamera;
30 import jp.sfjp.gokigen.a01c.R;
31 import jp.sfjp.gokigen.a01c.liveview.dialog.IDialogController;
32 import jp.sfjp.gokigen.a01c.liveview.dialog.IDialogDrawer;
33 import jp.sfjp.gokigen.a01c.liveview.gridframe.GridFrameFactory;
34 import jp.sfjp.gokigen.a01c.liveview.gridframe.IGridFrameDrawer;
35 import jp.sfjp.gokigen.a01c.olycamerawrapper.ILevelGauge;
36 import jp.sfjp.gokigen.a01c.preference.IPreferenceCameraPropertyAccessor;
39 * CameraLiveImageView :
40 * (OLYMPUS の ImageCaptureSample をカスタマイズ)
43 public class CameraLiveImageView extends View implements CameraLiveViewListenerImpl.IImageDataReceiver, IAutoFocusFrameDisplay, ILiveImageStatusNotify, IDialogController
45 private final String TAG = toString();
47 private static final String EXIF_ORIENTATION = "Orientation";
49 private boolean showGridFeature = false;
50 private boolean showLevelGaugeFeature = false;
51 private ImageView.ScaleType imageScaleType;
52 private Bitmap imageBitmap;
53 private int imageRotationDegrees;
54 private boolean showingFocusFrame = false;
55 private IAutoFocusFrameDisplay.FocusFrameStatus focusFrameStatus;
56 private RectF focusFrameRect;
57 private Timer focusFrameHideTimer;
59 private IGridFrameDrawer gridFrameDrawer = null;
60 private ShowMessageHolder messageHolder;
62 private IDialogDrawer dialogDrawer = null;
68 public CameraLiveImageView(Context context)
71 initComponent(context);
78 public CameraLiveImageView(Context context, AttributeSet attrs)
80 super(context, attrs);
81 initComponent(context);
88 public CameraLiveImageView(Context context, AttributeSet attrs, int defStyleAttr)
90 super(context, attrs, defStyleAttr);
91 initComponent(context);
95 * 初期化ロジック (preferenceからデータを読み出す)
97 private void initComponent(Context context)
99 messageHolder = new ShowMessageHolder();
101 imageScaleType = ImageView.ScaleType.FIT_CENTER;
102 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
104 showGridFeature = preferences.getBoolean(IPreferenceCameraPropertyAccessor.SHOW_GRID_STATUS, true);
105 showLevelGaugeFeature = preferences.getBoolean(IPreferenceCameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, false);
107 int framingGridStatus = Integer.parseInt(preferences.getString(IPreferenceCameraPropertyAccessor.FRAME_GRID, IPreferenceCameraPropertyAccessor.FRAME_GRID_DEFAULT_VALUE));
108 gridFrameDrawer = GridFrameFactory.getGridFrameDrawer(framingGridStatus);
110 // ダミーのビットマップデータ読み込み...画面表示のテスト用ロジック
113 imageBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.momonga);
127 protected void onAttachedToWindow()
129 super.onAttachedToWindow();
137 protected void onDetachedFromWindow()
139 super.onDetachedFromWindow();
142 if (focusFrameHideTimer != null)
144 focusFrameHideTimer.cancel();
145 focusFrameHideTimer = null;
154 protected void onDraw(Canvas canvas)
156 super.onDraw(canvas);
162 if (dialogDrawer != null)
164 dialogDrawer.drawDialog(canvas);
168 // メッセージの表示 (Overwrite)
169 drawInformationMessages(canvas);
177 public float getContentSizeWidth() {
178 return getIntrinsicContentSizeWidth();
186 public float getContentSizeHeight() {
187 return getIntrinsicContentSizeHeight();
194 private float getIntrinsicContentSizeWidth()
196 if (imageBitmap == null)
200 return (imageBitmap.getWidth());
207 private float getIntrinsicContentSizeHeight()
209 if (imageBitmap == null)
213 return (imageBitmap.getHeight());
217 * Sets a image to view.
218 * (CameraLiveViewListenerImpl.IImageDataReceiver の実装)
220 * @param data A image of live-view.
221 * @param metadata A metadata of the image.
223 public void setImageData(byte[] data, Map<String, Object> metadata)
228 if (data != null && metadata != null)
233 bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
235 catch (OutOfMemoryError e)
241 // Acquire a rotation degree of image.
242 int orientation = ExifInterface.ORIENTATION_UNDEFINED;
243 if (metadata.containsKey(EXIF_ORIENTATION))
245 orientation = Integer.parseInt((String) metadata.get(EXIF_ORIENTATION));
249 case ExifInterface.ORIENTATION_NORMAL:
252 case ExifInterface.ORIENTATION_ROTATE_90:
253 rotationDegrees = 90;
255 case ExifInterface.ORIENTATION_ROTATE_180:
256 rotationDegrees = 180;
258 case ExifInterface.ORIENTATION_ROTATE_270:
259 rotationDegrees = 270;
265 imageBitmap = bitmap;
266 imageRotationDegrees = rotationDegrees;
272 * Returns a point which is detected by a motion event.
274 * @param event A motion event.
275 * @return A point in the view finder. if a point is equal to null, the point is out of the view finder.
277 public PointF getPointWithEvent(MotionEvent event)
279 if (event == null || imageBitmap == null)
284 PointF pointOnView = new PointF(event.getX(), event.getY());
285 PointF pointOnImage = convertPointFromViewArea(pointOnView);
288 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
289 imageWidth = imageBitmap.getWidth();
290 imageHeight = imageBitmap.getHeight();
292 imageWidth = imageBitmap.getHeight();
293 imageHeight = imageBitmap.getWidth();
295 return (OLYCamera.convertPointOnLiveImageIntoViewfinder(pointOnImage, imageWidth, imageHeight, imageRotationDegrees));
299 * Returns whether a image area contains a specified point.
301 * @param point The point to examine.
302 * @return true if the image is not null or empty and the point is located within the rectangle; otherwise, false.
304 public boolean isContainsPoint(PointF point)
306 return ((point != null) && (new RectF(0, 0, 1, 1)).contains(point.x, point.y));
310 * Hides the forcus frame.
312 public void hideFocusFrame()
314 if (focusFrameHideTimer != null)
316 focusFrameHideTimer.cancel();
317 focusFrameHideTimer = null;
319 showingFocusFrame = false;
324 * Shows the focus frame.
326 * @param rect A rectangle of the focus frame on view area.
327 * @param status A status of the focus frame.
328 * @param duration A duration of the focus frame showing.
331 public void showFocusFrame(RectF rect, FocusFrameStatus status, double duration)
333 if (focusFrameHideTimer != null) {
334 focusFrameHideTimer.cancel();
335 focusFrameHideTimer = null;
338 showingFocusFrame = true;
339 focusFrameStatus = status;
340 focusFrameRect = rect;
345 focusFrameHideTimer = new Timer();
346 focusFrameHideTimer.schedule(new TimerTask() {
351 }, (long) (duration * 1000));
359 private void refreshCanvas()
361 if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
371 * @param canvas キャンバス
373 private void drawCanvas(Canvas canvas)
375 // Clears the canvas.
376 canvas.drawARGB(255, 0, 0, 0);
379 Bitmap bitmapToShow = imageBitmap;
380 if (bitmapToShow == null)
386 // Rotates the image.
387 int centerX = canvas.getWidth() / 2;
388 int centerY = canvas.getHeight() / 2;
389 canvas.rotate(imageRotationDegrees, centerX, centerY);
391 RectF viewRect = null;
393 // Calculate the viewport of bitmap.
394 if (imageScaleType == ImageView.ScaleType.FIT_CENTER)
396 viewRect = decideViewRect(canvas, bitmapToShow, imageRotationDegrees);
399 Rect imageRect = new Rect(0, 0, bitmapToShow.getWidth(), bitmapToShow.getHeight());
400 canvas.drawBitmap(bitmapToShow, imageRect, viewRect, null);
404 // Sorry, other scale types are not supported.
405 Log.v(TAG, "Sorry, other scale types are not supported. " + imageScaleType);
408 // Cancels rotation of the canvas.
409 canvas.rotate(-imageRotationDegrees, centerX, centerY);
413 if ((focusFrameRect != null) && (showingFocusFrame)) {
414 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
415 drawFocusFrame(canvas, bitmapToShow.getWidth(), bitmapToShow.getHeight());
417 drawFocusFrame(canvas, bitmapToShow.getHeight(), bitmapToShow.getWidth());
421 if (viewRect != null)
424 if ((showGridFeature) && (gridFrameDrawer != null))
426 drawGridFrame(canvas, viewRect);
429 // レベルゲージ(デジタル水準器)の表示
430 if (showLevelGaugeFeature)
432 drawLevelGauge(canvas, viewRect);
441 private RectF decideViewRect(Canvas canvas, Bitmap bitmapToShow, int degree)
445 if ((degree == 0) || (degree == 180))
447 srcWidth = bitmapToShow.getWidth();
448 srcHeight = bitmapToShow.getHeight();
452 // Replaces width and height.
453 srcWidth = bitmapToShow.getHeight();
454 srcHeight = bitmapToShow.getWidth();
457 int maxWidth = canvas.getWidth();
458 int maxHeight = canvas.getHeight();
460 int centerX = canvas.getWidth() / 2;
461 int centerY = canvas.getHeight() / 2;
463 float widthRatio = maxWidth / (float) srcWidth;
464 float heightRatio = maxHeight / (float) srcHeight;
465 float smallRatio = Math.min(widthRatio, heightRatio);
469 if (widthRatio < heightRatio)
471 // Fits to maxWidth with keeping aspect ratio.
473 dstHeight = (int) (smallRatio * srcHeight);
477 // Fits to maxHeight with keeping aspect ratio.
478 dstHeight = maxHeight;
479 dstWidth = (int) (smallRatio * srcWidth);
482 final float halfWidth = dstWidth * 0.5f;
483 final float halfHeight = dstHeight * 0.5f;
484 if ((degree == 0) || (degree == 180))
488 centerY - halfHeight,
489 centerX - halfWidth + dstWidth,
490 centerY - halfHeight + dstHeight));
493 // Replaces the width and height.
495 centerX - halfHeight,
497 centerX - halfHeight + dstHeight,
498 centerY - halfWidth + dstWidth));
504 * @param canvas キャンバス
505 * @param imageWidth 幅
506 * @param imageHeight 高さ
508 private void drawFocusFrame(Canvas canvas, float imageWidth, float imageHeight)
510 //Log.v(TAG, "drawFocusFrame() :" + focusFrameStatus);
512 // Calculate the rectangle of focus.
513 RectF focusRectOnImage = OLYCamera.convertRectOnViewfinderIntoLiveImage(focusFrameRect, imageWidth, imageHeight, imageRotationDegrees);
514 RectF focusRectOnView = convertRectFromImageArea(focusRectOnImage);
516 // Draw a rectangle to the canvas.
517 Paint focusFramePaint = new Paint();
518 focusFramePaint.setStyle(Paint.Style.STROKE);
519 switch (focusFrameStatus) {
521 focusFramePaint.setColor(Color.WHITE);
525 focusFramePaint.setColor(Color.GREEN);
529 focusFramePaint.setColor(Color.RED);
533 focusFramePaint.setColor(Color.YELLOW);
536 float focusFrameStrokeWidth = 2.0f;
537 DisplayMetrics dm = getResources().getDisplayMetrics();
538 float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, focusFrameStrokeWidth, dm);
539 focusFramePaint.setStrokeWidth(strokeWidth);
540 canvas.drawRect(focusRectOnView, focusFramePaint);
546 * @param canvas キャンバスエリア
547 * @param viewRect 表示領域
549 private void drawGridFrame(Canvas canvas, RectF viewRect)
552 if ((imageRotationDegrees == 0) || (imageRotationDegrees == 180)) {
553 gridRect = new RectF(viewRect);
555 float height = viewRect.right - viewRect.left;
556 float width = viewRect.bottom - viewRect.top;
557 float left = (canvas.getWidth() / 2.0f) - (width / 2.0f);
558 float top = (canvas.getHeight() / 2.0f) - (height / 2.0f);
559 gridRect = new RectF(left, top, left + width, top + height);
562 Paint framePaint = new Paint();
563 framePaint.setStyle(Paint.Style.STROKE);
564 framePaint.setAntiAlias(true);
566 //DisplayMetrics dm = getResources().getDisplayMetrics();
567 //float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1.0f, dm);
568 //framePaint.setStrokeWidth(strokeWidth);
569 framePaint.setStrokeWidth(0.0f);
570 framePaint.setColor(gridFrameDrawer.getDrawColor());
571 gridFrameDrawer.drawFramingGrid(canvas, gridRect, framePaint);
578 private void drawLevelGauge(Canvas canvas, RectF viewRect)
580 ILevelGauge levelGauge = messageHolder.getLevelGauge();
581 if (levelGauge == null)
583 // デジタル水準器がとれない場合は、何もしない
588 int height = (int) viewRect.bottom; // canvas.getHeight();
589 int width = (int) viewRect.right; // canvas.getWidth();
590 int centerX = width / 2;
591 int centerY = height / 2;
593 //float maxBandWidth = width / 3.0f; // ゲージの最大長 (画面の 1/3 ぐらい)
594 float maxBandHeight = height / 3.0f; // ゲージの最大長 (画面の 1/3 ぐらい)
595 int barWidthInitial = 4; // 表示するゲージの幅(の初期値)
596 int barWidth; // 実際に表示するゲージの幅
598 Paint paint = new Paint();
601 float verticalValue = levelGauge.getLevel(ILevelGauge.LevelArea.LEVEL_VERTICAL);
602 float verticalSize = verticalValue / 60.0f * maxBandHeight; // 45度で切り替わるはずだが、一応...
603 if (Math.abs(verticalSize) < 1.0f)
605 // 線引き限界以下、水平検出とする (この時の線は倍の長さにする)
607 barWidth = barWidthInitial * 2;
611 barWidth = barWidthInitial;
613 paint.setStrokeWidth(barWidth);
614 paint.setColor(levelGauge.getLevelColor(verticalValue));
615 canvas.drawLine((width - barWidth), centerY, (width - barWidth), (centerY + verticalSize), paint);
618 float horizontalValue = levelGauge.getLevel(ILevelGauge.LevelArea.LEVEL_HORIZONTAL);
619 paint.setStrokeWidth(2.0f);
620 paint.setAntiAlias(true);
621 paint.setColor(levelGauge.getLevelColor(horizontalValue));
622 if ((imageRotationDegrees == 0) || (imageRotationDegrees == 180))
625 float YY = canvas.getHeight() / 2.0f; // centerY
626 float diffY = (float) Math.sin(Math.toRadians(horizontalValue)) * (float) centerX;
627 canvas.drawLine(0, (YY + diffY), width, (YY - diffY), paint);
632 float XX = canvas.getWidth() / 2.0f; // centerX
633 float diffX = (float) Math.sin(Math.toRadians(horizontalValue)) * (float) centerY;
634 canvas.drawLine((XX + diffX), 0, (XX - diffX), canvas.getHeight(), paint);
639 float horizontalValue = levelGauge.getLevel(ILevelGauge.LevelArea.LEVEL_HORIZONTAL);
640 float horizontalSize = horizontalValue / 60.0f * maxBandWidth; // 45度ぐらいで切り替わるはずだが、一応...
641 if (Math.abs(horizontalSize) < 1.0f)
643 // 線引き限界以下、水平検出とする (この時の線は倍の長さにする)
644 horizontalSize = 1.0f;
645 barWidth = barWidthInitial * 2;
649 barWidth = barWidthInitial;
651 paint.setStrokeWidth(barWidth);
652 paint.setColor(levelGauge.getLevelColor(horizontalValue));
653 canvas.drawLine(centerX, (height - barWidth), (centerX + horizontalSize), (height - barWidth), paint);
660 private void drawInformationMessages(Canvas canvas)
664 if (imageBitmap != null)
666 // ビットマップの表示エリアに合わせて位置をチューニングする
667 viewRect = decideViewRect(canvas, imageBitmap, 0);
672 viewRect = new RectF(5.0f, 0.0f, canvas.getWidth() - 5.0f, canvas.getHeight() - 55.0f);
676 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.CENTER);
677 if ((message != null)&&(message.length() > 0))
679 Paint paint = new Paint();
680 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.CENTER));
681 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.CENTER));
682 paint.setAntiAlias(true);
683 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
684 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
685 float cx = (canvas.getWidth() / 2.0f) - (paint.measureText(message) / 2.0f);
686 float cy = (canvas.getHeight() / 2.0f) - ((fontMetrics.ascent + fontMetrics.descent) / 2.0f);
687 canvas.drawText(message, cx, cy, paint);
691 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.UPLEFT);
692 if ((message != null)&&(message.length() > 0))
694 Paint paintUp = new Paint();
695 paintUp.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.UPLEFT));
696 paintUp.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.UPLEFT));
697 paintUp.setAntiAlias(true);
698 paintUp.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
699 Paint.FontMetrics fontMetrics = paintUp.getFontMetrics();
700 canvas.drawText(message, viewRect.left + 3.0f, viewRect.top + (fontMetrics.descent - fontMetrics.ascent), paintUp);
704 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.UPRIGHT);
705 if ((message != null)&&(message.length() > 0))
707 Paint paintUp = new Paint();
708 paintUp.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.UPRIGHT));
709 paintUp.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.UPRIGHT));
710 paintUp.setAntiAlias(true);
711 paintUp.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
712 float width = paintUp.measureText(message);
713 Paint.FontMetrics fontMetrics = paintUp.getFontMetrics();
714 canvas.drawText(message, (viewRect.right - 3.0f) - width, viewRect.top + (fontMetrics.descent - fontMetrics.ascent), paintUp);
718 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.LOWLEFT);
719 if ((message != null)&&(message.length() > 0))
721 Paint paint = new Paint();
722 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.LOWLEFT));
723 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.LOWLEFT));
724 paint.setAntiAlias(true);
725 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
726 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
727 canvas.drawText(message, viewRect.left + 3.0f, viewRect.bottom - fontMetrics.bottom, paint);
731 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.LOWRIGHT);
732 if ((message != null)&&(message.length() > 0))
734 Paint paint = new Paint();
735 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.LOWRIGHT));
736 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.LOWRIGHT));
737 paint.setAntiAlias(true);
738 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
739 float width = paint.measureText(message);
740 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
741 canvas.drawText(message, (viewRect.right - 3.0f) - width, viewRect.bottom - fontMetrics.bottom, paint);
746 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.UPCENTER);
747 if ((message != null)&&(message.length() > 0))
749 Paint paintUp = new Paint();
750 paintUp.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.UPCENTER));
751 paintUp.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.UPCENTER));
752 paintUp.setAntiAlias(true);
753 paintUp.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
754 float width = paintUp.measureText(message) / 2.0f;
755 Paint.FontMetrics fontMetrics = paintUp.getFontMetrics();
756 canvas.drawText(message, (viewRect.centerX()) - width, viewRect.top + (fontMetrics.descent - fontMetrics.ascent), paintUp);
760 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.LOWCENTER);
761 if ((message != null)&&(message.length() > 0))
763 Paint paint = new Paint();
764 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.LOWCENTER));
765 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.LOWCENTER));
766 paint.setAntiAlias(true);
767 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
768 float width = paint.measureText(message) / 2.0f;
769 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
770 canvas.drawText(message, (viewRect.centerX()) - width, viewRect.bottom - fontMetrics.bottom, paint);
776 * Converts a point on image area to a point on view area.
778 * @param point A point on image area. (e.g. a live preview image)
779 * @return A point on view area. (e.g. a touch panel view)
781 private PointF convertPointFromImageArea(PointF point) {
782 if (imageBitmap == null) {
786 float viewPointX = point.x;
787 float viewPointY = point.y;
788 float imageSizeWidth;
789 float imageSizeHeight;
790 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
791 imageSizeWidth = imageBitmap.getWidth();
792 imageSizeHeight = imageBitmap.getHeight();
794 imageSizeWidth = imageBitmap.getHeight();
795 imageSizeHeight = imageBitmap.getWidth();
797 float viewSizeWidth = this.getWidth();
798 float viewSizeHeight = this.getHeight();
799 float ratioX = viewSizeWidth / imageSizeWidth;
800 float ratioY = viewSizeHeight / imageSizeHeight;
803 switch (imageScaleType) {
805 viewPointX *= ratioX;
806 viewPointY *= ratioY;
808 case FIT_CENTER: // go to next label.
810 scale = Math.min(ratioX, ratioY);
813 viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
814 viewPointY += (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
817 scale = Math.max(ratioX, ratioY);
820 viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
821 viewPointY += (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
824 viewPointX += viewSizeWidth / 2.0 - imageSizeWidth / 2.0f;
825 viewPointY += viewSizeHeight / 2.0 - imageSizeHeight / 2.0f;
830 return new PointF(viewPointX, viewPointY);
834 * Converts a point on view area to a point on image area.
836 * @param point A point on view area. (e.g. a touch panel view)
837 * @return A point on image area. (e.g. a live preview image)
839 private PointF convertPointFromViewArea(PointF point) {
840 if (imageBitmap == null) {
844 float imagePointX = point.x;
845 float imagePointY = point.y;
846 float imageSizeWidth;
847 float imageSizeHeight;
848 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
849 imageSizeWidth = imageBitmap.getWidth();
850 imageSizeHeight = imageBitmap.getHeight();
852 imageSizeWidth = imageBitmap.getHeight();
853 imageSizeHeight = imageBitmap.getWidth();
855 float viewSizeWidth = this.getWidth();
856 float viewSizeHeight = this.getHeight();
857 float ratioX = viewSizeWidth / imageSizeWidth;
858 float ratioY = viewSizeHeight / imageSizeHeight;
861 switch (imageScaleType) {
863 imagePointX /= ratioX;
864 imagePointY /= ratioY;
866 case FIT_CENTER: // go to next label.
868 scale = Math.min(ratioX, ratioY);
869 imagePointX -= (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
870 imagePointY -= (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
871 imagePointX /= scale;
872 imagePointY /= scale;
875 scale = Math.max(ratioX, ratioY);
876 imagePointX -= (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
877 imagePointY -= (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
878 imagePointX /= scale;
879 imagePointY /= scale;
882 imagePointX -= (viewSizeWidth - imageSizeWidth) / 2.0f;
883 imagePointY -= (viewSizeHeight - imageSizeHeight) / 2.0f;
888 return new PointF(imagePointX, imagePointY);
892 * Converts a rectangle on image area to a rectangle on view area.
894 * @param rect A rectangle on image area. (e.g. a live preview image)
895 * @return A rectangle on view area. (e.g. a touch panel view)
897 private RectF convertRectFromImageArea(RectF rect)
899 if (imageBitmap == null)
904 PointF imageTopLeft = new PointF(rect.left, rect.top);
905 PointF imageBottomRight = new PointF(rect.right, rect.bottom);
907 PointF viewTopLeft = convertPointFromImageArea(imageTopLeft);
908 PointF viewBottomRight = convertPointFromImageArea(imageBottomRight);
910 return (new RectF(viewTopLeft.x, viewTopLeft.y, viewBottomRight.x, viewBottomRight.y));
917 public void setShowGridFrame(boolean isShowGridFeature)
919 showGridFeature = isShowGridFeature;
920 SharedPreferences preferences = android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(getContext());
921 SharedPreferences.Editor editor = preferences.edit();
922 editor.putBoolean(IPreferenceCameraPropertyAccessor.SHOW_GRID_STATUS, showGridFeature);
931 public void toggleShowGridFrame()
933 setShowGridFrame(!showGridFeature);
940 public void setShowLevelGauge(boolean isShowLevelGaugeFeature)
942 Log.v(TAG, "setShowLevelGauge : " + isShowLevelGaugeFeature);
943 showLevelGaugeFeature = isShowLevelGaugeFeature;
944 SharedPreferences preferences = android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(getContext());
945 SharedPreferences.Editor editor = preferences.edit();
946 editor.putBoolean(IPreferenceCameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, showLevelGaugeFeature);
948 ILevelGauge levelGauge = messageHolder.getLevelGauge();
949 if (levelGauge == null)
951 // デジタル水準器がとれない場合は、何もしない
952 Log.v(TAG, "setShowLevelGauge : levelGauge is null.");
955 levelGauge.updateLevelGaugeChecking(isShowLevelGaugeFeature);
963 public void toggleShowLevelGauge()
965 setShowLevelGauge(!showLevelGaugeFeature);
973 public boolean isShowLevelGauge()
975 return (showLevelGaugeFeature);
983 public boolean isShowGrid()
985 return (showGridFeature);
993 public IMessageDrawer getMessageDrawer()
995 return (messageHolder);
1003 public void showDialog(IDialogDrawer dialogDrawer)
1005 this.dialogDrawer = dialogDrawer;
1013 public void hideDialog()
1015 this.dialogDrawer = null;
1024 public boolean touchedPosition(float posX, float posY)
1026 return ((dialogDrawer != null)&&(dialogDrawer.touchedPosition(posX, posY)));