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.gridframe.GridFrameFactory;
32 import jp.sfjp.gokigen.a01c.liveview.gridframe.IGridFrameDrawer;
33 import jp.sfjp.gokigen.a01c.olycamerawrapper.ILevelGauge;
34 import jp.sfjp.gokigen.a01c.preference.ICameraPropertyAccessor;
37 * CameraLiveImageView :
38 * (OLYMPUS の ImageCaptureSample をカスタマイズ)
41 public class CameraLiveImageView extends View implements CameraLiveViewListenerImpl.IImageDataReceiver, IAutoFocusFrameDisplay, ILiveImageStatusNotify
43 private final String TAG = toString();
45 private static final String EXIF_ORIENTATION = "Orientation";
47 private boolean showGridFeature = false;
48 private boolean showLevelGaugeFeature = false;
49 private ImageView.ScaleType imageScaleType;
50 private Bitmap imageBitmap;
51 private int imageRotationDegrees;
52 private boolean showingFocusFrame = false;
53 private IAutoFocusFrameDisplay.FocusFrameStatus focusFrameStatus;
54 private RectF focusFrameRect;
55 private Timer focusFrameHideTimer;
57 private IGridFrameDrawer gridFrameDrawer = null;
58 private ShowMessageHolder messageHolder;
64 public CameraLiveImageView(Context context)
67 initComponent(context);
74 public CameraLiveImageView(Context context, AttributeSet attrs)
76 super(context, attrs);
77 initComponent(context);
84 public CameraLiveImageView(Context context, AttributeSet attrs, int defStyleAttr)
86 super(context, attrs, defStyleAttr);
87 initComponent(context);
91 * 初期化ロジック (preferenceからデータを読み出す)
93 private void initComponent(Context context)
95 messageHolder = new ShowMessageHolder();
97 imageScaleType = ImageView.ScaleType.FIT_CENTER;
98 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
100 showGridFeature = preferences.getBoolean(ICameraPropertyAccessor.SHOW_GRID_STATUS, true);
101 showLevelGaugeFeature = preferences.getBoolean(ICameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, false);
103 int framingGridStatus = Integer.parseInt(preferences.getString(ICameraPropertyAccessor.FRAME_GRID, ICameraPropertyAccessor.FRAME_GRID_DEFAULT_VALUE));
104 gridFrameDrawer = GridFrameFactory.getGridFrameDrawer(framingGridStatus);
106 // ダミーのビットマップデータ読み込み...画面表示のテスト用ロジック
109 imageBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.momonga);
123 protected void onAttachedToWindow()
125 super.onAttachedToWindow();
133 protected void onDetachedFromWindow()
135 super.onDetachedFromWindow();
138 if (focusFrameHideTimer != null)
140 focusFrameHideTimer.cancel();
141 focusFrameHideTimer = null;
150 protected void onDraw(Canvas canvas)
152 super.onDraw(canvas);
157 // メッセージの表示 (Overwrite)
158 drawInformationMessages(canvas);
166 public float getContentSizeWidth() {
167 return getIntrinsicContentSizeWidth();
175 public float getContentSizeHeight() {
176 return getIntrinsicContentSizeHeight();
183 private float getIntrinsicContentSizeWidth()
185 if (imageBitmap == null)
189 return (imageBitmap.getWidth());
196 private float getIntrinsicContentSizeHeight()
198 if (imageBitmap == null)
202 return (imageBitmap.getHeight());
206 * Sets a image to view.
207 * (CameraLiveViewListenerImpl.IImageDataReceiver の実装)
209 * @param data A image of live-view.
210 * @param metadata A metadata of the image.
212 public void setImageData(byte[] data, Map<String, Object> metadata)
217 if (data != null && metadata != null)
222 bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
224 catch (OutOfMemoryError e)
230 // Acquire a rotation degree of image.
231 int orientation = ExifInterface.ORIENTATION_UNDEFINED;
232 if (metadata.containsKey(EXIF_ORIENTATION))
234 orientation = Integer.parseInt((String) metadata.get(EXIF_ORIENTATION));
238 case ExifInterface.ORIENTATION_NORMAL:
241 case ExifInterface.ORIENTATION_ROTATE_90:
242 rotationDegrees = 90;
244 case ExifInterface.ORIENTATION_ROTATE_180:
245 rotationDegrees = 180;
247 case ExifInterface.ORIENTATION_ROTATE_270:
248 rotationDegrees = 270;
254 imageBitmap = bitmap;
255 imageRotationDegrees = rotationDegrees;
261 * Returns a point which is detected by a motion event.
263 * @param event A motion event.
264 * @return A point in the view finder. if a point is equal to null, the point is out of the view finder.
266 public PointF getPointWithEvent(MotionEvent event)
268 if (event == null || imageBitmap == null)
273 PointF pointOnView = new PointF(event.getX(), event.getY());
274 PointF pointOnImage = convertPointFromViewArea(pointOnView);
277 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
278 imageWidth = imageBitmap.getWidth();
279 imageHeight = imageBitmap.getHeight();
281 imageWidth = imageBitmap.getHeight();
282 imageHeight = imageBitmap.getWidth();
284 return (OLYCamera.convertPointOnLiveImageIntoViewfinder(pointOnImage, imageWidth, imageHeight, imageRotationDegrees));
288 * Returns whether a image area contains a specified point.
290 * @param point The point to examine.
291 * @return true if the image is not null or empty and the point is located within the rectangle; otherwise, false.
293 public boolean isContainsPoint(PointF point)
295 return ((point != null) && (new RectF(0, 0, 1, 1)).contains(point.x, point.y));
299 * Hides the forcus frame.
301 public void hideFocusFrame()
303 if (focusFrameHideTimer != null)
305 focusFrameHideTimer.cancel();
306 focusFrameHideTimer = null;
308 showingFocusFrame = false;
313 * Shows the focus frame.
315 * @param rect A rectangle of the focus frame on view area.
316 * @param status A status of the focus frame.
317 * @param duration A duration of the focus frame showing.
320 public void showFocusFrame(RectF rect, FocusFrameStatus status, double duration)
322 if (focusFrameHideTimer != null) {
323 focusFrameHideTimer.cancel();
324 focusFrameHideTimer = null;
327 showingFocusFrame = true;
328 focusFrameStatus = status;
329 focusFrameRect = rect;
334 focusFrameHideTimer = new Timer();
335 focusFrameHideTimer.schedule(new TimerTask() {
340 }, (long) (duration * 1000));
348 private void refreshCanvas()
350 if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
360 * @param canvas キャンバス
362 private void drawCanvas(Canvas canvas)
364 // Clears the canvas.
365 canvas.drawARGB(255, 0, 0, 0);
368 Bitmap bitmapToShow = imageBitmap;
369 if (bitmapToShow == null)
375 // Rotates the image.
376 int centerX = canvas.getWidth() / 2;
377 int centerY = canvas.getHeight() / 2;
378 canvas.rotate(imageRotationDegrees, centerX, centerY);
380 RectF viewRect = null;
382 // Calculate the viewport of bitmap.
383 if (imageScaleType == ImageView.ScaleType.FIT_CENTER)
385 viewRect = decideViewRect(canvas, bitmapToShow, imageRotationDegrees);
388 Rect imageRect = new Rect(0, 0, bitmapToShow.getWidth(), bitmapToShow.getHeight());
389 canvas.drawBitmap(bitmapToShow, imageRect, viewRect, null);
393 // Sorry, other scale types are not supported.
394 Log.v(TAG, "Sorry, other scale types are not supported. " + imageScaleType);
397 // Cancels rotation of the canvas.
398 canvas.rotate(-imageRotationDegrees, centerX, centerY);
402 if ((focusFrameRect != null) && (showingFocusFrame)) {
403 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
404 drawFocusFrame(canvas, bitmapToShow.getWidth(), bitmapToShow.getHeight());
406 drawFocusFrame(canvas, bitmapToShow.getHeight(), bitmapToShow.getWidth());
410 if (viewRect != null)
413 if ((showGridFeature) && (gridFrameDrawer != null))
415 drawGridFrame(canvas, viewRect);
418 // レベルゲージ(デジタル水準器)の表示
419 if (showLevelGaugeFeature)
421 drawLevelGauge(canvas, viewRect);
430 private RectF decideViewRect(Canvas canvas, Bitmap bitmapToShow, int degree)
434 if ((degree == 0) || (degree == 180))
436 srcWidth = bitmapToShow.getWidth();
437 srcHeight = bitmapToShow.getHeight();
441 // Replaces width and height.
442 srcWidth = bitmapToShow.getHeight();
443 srcHeight = bitmapToShow.getWidth();
446 int maxWidth = canvas.getWidth();
447 int maxHeight = canvas.getHeight();
449 int centerX = canvas.getWidth() / 2;
450 int centerY = canvas.getHeight() / 2;
452 float widthRatio = maxWidth / (float) srcWidth;
453 float heightRatio = maxHeight / (float) srcHeight;
454 float smallRatio = Math.min(widthRatio, heightRatio);
458 if (widthRatio < heightRatio)
460 // Fits to maxWidth with keeping aspect ratio.
462 dstHeight = (int) (smallRatio * srcHeight);
466 // Fits to maxHeight with keeping aspect ratio.
467 dstHeight = maxHeight;
468 dstWidth = (int) (smallRatio * srcWidth);
471 final float halfWidth = dstWidth * 0.5f;
472 final float halfHeight = dstHeight * 0.5f;
473 if ((degree == 0) || (degree == 180))
477 centerY - halfHeight,
478 centerX - halfWidth + dstWidth,
479 centerY - halfHeight + dstHeight));
482 // Replaces the width and height.
484 centerX - halfHeight,
486 centerX - halfHeight + dstHeight,
487 centerY - halfWidth + dstWidth));
493 * @param canvas キャンバス
494 * @param imageWidth 幅
495 * @param imageHeight 高さ
497 private void drawFocusFrame(Canvas canvas, float imageWidth, float imageHeight)
499 //Log.v(TAG, "drawFocusFrame() :" + focusFrameStatus);
501 // Calculate the rectangle of focus.
502 RectF focusRectOnImage = OLYCamera.convertRectOnViewfinderIntoLiveImage(focusFrameRect, imageWidth, imageHeight, imageRotationDegrees);
503 RectF focusRectOnView = convertRectFromImageArea(focusRectOnImage);
505 // Draw a rectangle to the canvas.
506 Paint focusFramePaint = new Paint();
507 focusFramePaint.setStyle(Paint.Style.STROKE);
508 switch (focusFrameStatus) {
510 focusFramePaint.setColor(Color.WHITE);
514 focusFramePaint.setColor(Color.GREEN);
518 focusFramePaint.setColor(Color.RED);
522 focusFramePaint.setColor(Color.YELLOW);
525 float focusFrameStrokeWidth = 2.0f;
526 DisplayMetrics dm = getResources().getDisplayMetrics();
527 float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, focusFrameStrokeWidth, dm);
528 focusFramePaint.setStrokeWidth(strokeWidth);
529 canvas.drawRect(focusRectOnView, focusFramePaint);
535 * @param canvas キャンバスエリア
536 * @param viewRect 表示領域
538 private void drawGridFrame(Canvas canvas, RectF viewRect)
541 if ((imageRotationDegrees == 0) || (imageRotationDegrees == 180)) {
542 gridRect = new RectF(viewRect);
544 float height = viewRect.right - viewRect.left;
545 float width = viewRect.bottom - viewRect.top;
546 float left = (canvas.getWidth() / 2.0f) - (width / 2.0f);
547 float top = (canvas.getHeight() / 2.0f) - (height / 2.0f);
548 gridRect = new RectF(left, top, left + width, top + height);
551 Paint framePaint = new Paint();
552 framePaint.setStyle(Paint.Style.STROKE);
554 //DisplayMetrics dm = getResources().getDisplayMetrics();
555 //float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1.0f, dm);
556 //framePaint.setStrokeWidth(strokeWidth);
557 framePaint.setStrokeWidth(0.0f);
558 framePaint.setColor(gridFrameDrawer.getDrawColor());
559 gridFrameDrawer.drawFramingGrid(canvas, gridRect, framePaint);
566 private void drawLevelGauge(Canvas canvas, RectF viewRect)
568 ILevelGauge levelGauge = messageHolder.getLevelGauge();
569 if (levelGauge == null)
571 // デジタル水準器がとれない場合は、何もしない
576 int height = (int) viewRect.bottom; // canvas.getHeight();
577 int width = (int) viewRect.right; // canvas.getWidth();
578 int centerX = width / 2;
579 int centerY = height / 2;
581 //float maxBandWidth = width / 3.0f; // ゲージの最大長 (画面の 1/3 ぐらい)
582 float maxBandHeight = height / 3.0f; // ゲージの最大長 (画面の 1/3 ぐらい)
583 int barWidthInitial = 4; // 表示するゲージの幅(の初期値)
584 int barWidth; // 実際に表示するゲージの幅
586 Paint paint = new Paint();
589 float verticalValue = levelGauge.getLevel(ILevelGauge.LevelArea.LEVEL_VERTICAL);
590 float verticalSize = verticalValue / 60.0f * maxBandHeight; // 45度で切り替わるはずだが、一応...
591 if (Math.abs(verticalSize) < 1.0f)
593 // 線引き限界以下、水平検出とする (この時の線は倍の長さにする)
595 barWidth = barWidthInitial * 2;
599 barWidth = barWidthInitial;
601 paint.setStrokeWidth(barWidth);
602 paint.setColor(levelGauge.getLevelColor(verticalValue));
603 canvas.drawLine((width - barWidth), centerY, (width - barWidth), (centerY + verticalSize), paint);
606 float horizontalValue = levelGauge.getLevel(ILevelGauge.LevelArea.LEVEL_HORIZONTAL);
607 paint.setStrokeWidth(2.0f);
608 paint.setAntiAlias(true);
609 paint.setColor(levelGauge.getLevelColor(horizontalValue));
610 if ((imageRotationDegrees == 0) || (imageRotationDegrees == 180))
613 float YY = canvas.getHeight() / 2.0f; // centerY
614 float diffY = (float) Math.sin(Math.toRadians(horizontalValue)) * (float) centerX;
615 canvas.drawLine(0, (YY + diffY), width, (YY - diffY), paint);
620 float XX = canvas.getWidth() / 2.0f; // centerX
621 float diffX = (float) Math.sin(Math.toRadians(horizontalValue)) * (float) centerY;
622 canvas.drawLine((XX + diffX), 0, (XX - diffX), canvas.getHeight(), paint);
627 float horizontalValue = levelGauge.getLevel(ILevelGauge.LevelArea.LEVEL_HORIZONTAL);
628 float horizontalSize = horizontalValue / 60.0f * maxBandWidth; // 45度ぐらいで切り替わるはずだが、一応...
629 if (Math.abs(horizontalSize) < 1.0f)
631 // 線引き限界以下、水平検出とする (この時の線は倍の長さにする)
632 horizontalSize = 1.0f;
633 barWidth = barWidthInitial * 2;
637 barWidth = barWidthInitial;
639 paint.setStrokeWidth(barWidth);
640 paint.setColor(levelGauge.getLevelColor(horizontalValue));
641 canvas.drawLine(centerX, (height - barWidth), (centerX + horizontalSize), (height - barWidth), paint);
648 private void drawInformationMessages(Canvas canvas)
652 if (imageBitmap != null)
654 // ビットマップの表示エリアに合わせて位置をチューニングする
655 viewRect = decideViewRect(canvas, imageBitmap, 0);
660 viewRect = new RectF(5.0f, 0.0f, canvas.getWidth() - 5.0f, canvas.getHeight() - 55.0f);
664 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.CENTER);
665 if ((message != null)&&(message.length() > 0))
667 Paint paint = new Paint();
668 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.CENTER));
669 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.CENTER));
670 paint.setAntiAlias(true);
671 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
672 float cx = (canvas.getWidth() / 2.0f) - (paint.measureText(message) / 2.0f);
673 float cy = (canvas.getHeight() / 2.0f) - ((fontMetrics.ascent + fontMetrics.descent) / 2.0f);
674 canvas.drawText(message, cx, cy, paint);
678 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.UPLEFT);
679 if ((message != null)&&(message.length() > 0))
681 Paint paintUp = new Paint();
682 paintUp.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.UPLEFT));
683 paintUp.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.UPLEFT));
684 paintUp.setAntiAlias(true);
685 Paint.FontMetrics fontMetrics = paintUp.getFontMetrics();
686 canvas.drawText(message, viewRect.left + 3.0f, viewRect.top + (fontMetrics.descent - fontMetrics.ascent), paintUp);
690 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.UPRIGHT);
691 if ((message != null)&&(message.length() > 0))
693 Paint paintUp = new Paint();
694 paintUp.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.UPRIGHT));
695 paintUp.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.UPRIGHT));
696 paintUp.setAntiAlias(true);
697 float width = paintUp.measureText(message);
698 Paint.FontMetrics fontMetrics = paintUp.getFontMetrics();
699 canvas.drawText(message, (viewRect.right - 3.0f) - width, viewRect.top + (fontMetrics.descent - fontMetrics.ascent), paintUp);
703 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.LOWLEFT);
704 if ((message != null)&&(message.length() > 0))
706 Paint paint = new Paint();
707 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.LOWLEFT));
708 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.LOWLEFT));
709 paint.setAntiAlias(true);
710 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
711 canvas.drawText(message, viewRect.left + 3.0f, viewRect.bottom - fontMetrics.bottom, paint);
715 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.LOWRIGHT);
716 if ((message != null)&&(message.length() > 0))
718 Paint paint = new Paint();
719 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.LOWRIGHT));
720 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.LOWRIGHT));
721 paint.setAntiAlias(true);
722 float width = paint.measureText(message);
723 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
724 canvas.drawText(message, (viewRect.right - 3.0f) - width, viewRect.bottom - fontMetrics.bottom, paint);
729 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.UPCENTER);
730 if ((message != null)&&(message.length() > 0))
732 Paint paintUp = new Paint();
733 paintUp.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.UPCENTER));
734 paintUp.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.UPCENTER));
735 paintUp.setAntiAlias(true);
736 float width = paintUp.measureText(message) / 2.0f;
737 Paint.FontMetrics fontMetrics = paintUp.getFontMetrics();
738 canvas.drawText(message, (viewRect.centerX()) - width, viewRect.top + (fontMetrics.descent - fontMetrics.ascent), paintUp);
742 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.LOWCENTER);
743 if ((message != null)&&(message.length() > 0))
745 Paint paint = new Paint();
746 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.LOWCENTER));
747 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.LOWCENTER));
748 paint.setAntiAlias(true);
749 float width = paint.measureText(message) / 2.0f;
750 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
751 canvas.drawText(message, (viewRect.centerX()) - width, viewRect.bottom - fontMetrics.bottom, paint);
757 * Converts a point on image area to a point on view area.
759 * @param point A point on image area. (e.g. a live preview image)
760 * @return A point on view area. (e.g. a touch panel view)
762 private PointF convertPointFromImageArea(PointF point) {
763 if (imageBitmap == null) {
767 float viewPointX = point.x;
768 float viewPointY = point.y;
769 float imageSizeWidth;
770 float imageSizeHeight;
771 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
772 imageSizeWidth = imageBitmap.getWidth();
773 imageSizeHeight = imageBitmap.getHeight();
775 imageSizeWidth = imageBitmap.getHeight();
776 imageSizeHeight = imageBitmap.getWidth();
778 float viewSizeWidth = this.getWidth();
779 float viewSizeHeight = this.getHeight();
780 float ratioX = viewSizeWidth / imageSizeWidth;
781 float ratioY = viewSizeHeight / imageSizeHeight;
784 switch (imageScaleType) {
786 viewPointX *= ratioX;
787 viewPointY *= ratioY;
789 case FIT_CENTER: // go to next label.
791 scale = Math.min(ratioX, ratioY);
794 viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
795 viewPointY += (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
798 scale = Math.max(ratioX, ratioY);
801 viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
802 viewPointY += (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
805 viewPointX += viewSizeWidth / 2.0 - imageSizeWidth / 2.0f;
806 viewPointY += viewSizeHeight / 2.0 - imageSizeHeight / 2.0f;
811 return new PointF(viewPointX, viewPointY);
815 * Converts a point on view area to a point on image area.
817 * @param point A point on view area. (e.g. a touch panel view)
818 * @return A point on image area. (e.g. a live preview image)
820 private PointF convertPointFromViewArea(PointF point) {
821 if (imageBitmap == null) {
825 float imagePointX = point.x;
826 float imagePointY = point.y;
827 float imageSizeWidth;
828 float imageSizeHeight;
829 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
830 imageSizeWidth = imageBitmap.getWidth();
831 imageSizeHeight = imageBitmap.getHeight();
833 imageSizeWidth = imageBitmap.getHeight();
834 imageSizeHeight = imageBitmap.getWidth();
836 float viewSizeWidth = this.getWidth();
837 float viewSizeHeight = this.getHeight();
838 float ratioX = viewSizeWidth / imageSizeWidth;
839 float ratioY = viewSizeHeight / imageSizeHeight;
842 switch (imageScaleType) {
844 imagePointX /= ratioX;
845 imagePointY /= ratioY;
847 case FIT_CENTER: // go to next label.
849 scale = Math.min(ratioX, ratioY);
850 imagePointX -= (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
851 imagePointY -= (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
852 imagePointX /= scale;
853 imagePointY /= scale;
856 scale = Math.max(ratioX, ratioY);
857 imagePointX -= (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
858 imagePointY -= (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
859 imagePointX /= scale;
860 imagePointY /= scale;
863 imagePointX -= (viewSizeWidth - imageSizeWidth) / 2.0f;
864 imagePointY -= (viewSizeHeight - imageSizeHeight) / 2.0f;
869 return new PointF(imagePointX, imagePointY);
873 * Converts a rectangle on image area to a rectangle on view area.
875 * @param rect A rectangle on image area. (e.g. a live preview image)
876 * @return A rectangle on view area. (e.g. a touch panel view)
878 private RectF convertRectFromImageArea(RectF rect)
880 if (imageBitmap == null)
885 PointF imageTopLeft = new PointF(rect.left, rect.top);
886 PointF imageBottomRight = new PointF(rect.right, rect.bottom);
888 PointF viewTopLeft = convertPointFromImageArea(imageTopLeft);
889 PointF viewBottomRight = convertPointFromImageArea(imageBottomRight);
891 return (new RectF(viewTopLeft.x, viewTopLeft.y, viewBottomRight.x, viewBottomRight.y));
898 public void setShowGridFrame(boolean isShowGridFeature)
900 showGridFeature = isShowGridFeature;
901 SharedPreferences preferences = android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(getContext());
902 SharedPreferences.Editor editor = preferences.edit();
903 editor.putBoolean(ICameraPropertyAccessor.SHOW_GRID_STATUS, showGridFeature);
912 public void toggleShowGridFrame()
914 setShowGridFrame(!showGridFeature);
921 public void setShowLevelGauge(boolean isShowLevelGaugeFeature)
923 Log.v(TAG, "setShowLevelGauge : " + isShowLevelGaugeFeature);
924 showLevelGaugeFeature = isShowLevelGaugeFeature;
925 SharedPreferences preferences = android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(getContext());
926 SharedPreferences.Editor editor = preferences.edit();
927 editor.putBoolean(ICameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, showLevelGaugeFeature);
929 ILevelGauge levelGauge = messageHolder.getLevelGauge();
930 if (levelGauge == null)
932 // デジタル水準器がとれない場合は、何もしない
933 Log.v(TAG, "setShowLevelGauge : levelGauge is null.");
936 levelGauge.updateLevelGaugeChecking(isShowLevelGaugeFeature);
944 public void toggleShowLevelGauge()
946 setShowLevelGauge(!showLevelGaugeFeature);
954 public boolean isShowLevelGauge()
956 return (showLevelGaugeFeature);
964 public boolean isShowGrid()
966 return (showGridFeature);
974 public IMessageDrawer getMessageDrawer()
976 return (messageHolder);