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.graphics.Typeface;
14 import android.media.ExifInterface;
15 import android.os.Looper;
16 import android.preference.PreferenceManager;
17 import android.util.AttributeSet;
18 import android.util.DisplayMetrics;
19 import android.util.Log;
20 import android.util.TypedValue;
21 import android.view.MotionEvent;
22 import android.view.View;
23 import android.widget.ImageView;
26 import java.util.Timer;
27 import java.util.TimerTask;
29 import jp.co.olympus.camerakit.OLYCamera;
31 import jp.sfjp.gokigen.a01c.R;
32 import jp.sfjp.gokigen.a01c.liveview.gridframe.GridFrameFactory;
33 import jp.sfjp.gokigen.a01c.liveview.gridframe.IGridFrameDrawer;
34 import jp.sfjp.gokigen.a01c.olycamerawrapper.ILevelGauge;
35 import jp.sfjp.gokigen.a01c.preference.ICameraPropertyAccessor;
38 * CameraLiveImageView :
39 * (OLYMPUS の ImageCaptureSample をカスタマイズ)
42 public class CameraLiveImageView extends View implements CameraLiveViewListenerImpl.IImageDataReceiver, IAutoFocusFrameDisplay, ILiveImageStatusNotify
44 private final String TAG = toString();
46 private static final String EXIF_ORIENTATION = "Orientation";
48 private boolean showGridFeature = false;
49 private boolean showLevelGaugeFeature = false;
50 private ImageView.ScaleType imageScaleType;
51 private Bitmap imageBitmap;
52 private int imageRotationDegrees;
53 private boolean showingFocusFrame = false;
54 private IAutoFocusFrameDisplay.FocusFrameStatus focusFrameStatus;
55 private RectF focusFrameRect;
56 private Timer focusFrameHideTimer;
58 private IGridFrameDrawer gridFrameDrawer = null;
59 private ShowMessageHolder messageHolder;
65 public CameraLiveImageView(Context context)
68 initComponent(context);
75 public CameraLiveImageView(Context context, AttributeSet attrs)
77 super(context, attrs);
78 initComponent(context);
85 public CameraLiveImageView(Context context, AttributeSet attrs, int defStyleAttr)
87 super(context, attrs, defStyleAttr);
88 initComponent(context);
92 * 初期化ロジック (preferenceからデータを読み出す)
94 private void initComponent(Context context)
96 messageHolder = new ShowMessageHolder();
98 imageScaleType = ImageView.ScaleType.FIT_CENTER;
99 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
101 showGridFeature = preferences.getBoolean(ICameraPropertyAccessor.SHOW_GRID_STATUS, true);
102 showLevelGaugeFeature = preferences.getBoolean(ICameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, false);
104 int framingGridStatus = Integer.parseInt(preferences.getString(ICameraPropertyAccessor.FRAME_GRID, ICameraPropertyAccessor.FRAME_GRID_DEFAULT_VALUE));
105 gridFrameDrawer = GridFrameFactory.getGridFrameDrawer(framingGridStatus);
107 // ダミーのビットマップデータ読み込み...画面表示のテスト用ロジック
110 imageBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.momonga);
124 protected void onAttachedToWindow()
126 super.onAttachedToWindow();
134 protected void onDetachedFromWindow()
136 super.onDetachedFromWindow();
139 if (focusFrameHideTimer != null)
141 focusFrameHideTimer.cancel();
142 focusFrameHideTimer = null;
151 protected void onDraw(Canvas canvas)
153 super.onDraw(canvas);
158 // メッセージの表示 (Overwrite)
159 drawInformationMessages(canvas);
167 public float getContentSizeWidth() {
168 return getIntrinsicContentSizeWidth();
176 public float getContentSizeHeight() {
177 return getIntrinsicContentSizeHeight();
184 private float getIntrinsicContentSizeWidth()
186 if (imageBitmap == null)
190 return (imageBitmap.getWidth());
197 private float getIntrinsicContentSizeHeight()
199 if (imageBitmap == null)
203 return (imageBitmap.getHeight());
207 * Sets a image to view.
208 * (CameraLiveViewListenerImpl.IImageDataReceiver の実装)
210 * @param data A image of live-view.
211 * @param metadata A metadata of the image.
213 public void setImageData(byte[] data, Map<String, Object> metadata)
218 if (data != null && metadata != null)
223 bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
225 catch (OutOfMemoryError e)
231 // Acquire a rotation degree of image.
232 int orientation = ExifInterface.ORIENTATION_UNDEFINED;
233 if (metadata.containsKey(EXIF_ORIENTATION))
235 orientation = Integer.parseInt((String) metadata.get(EXIF_ORIENTATION));
239 case ExifInterface.ORIENTATION_NORMAL:
242 case ExifInterface.ORIENTATION_ROTATE_90:
243 rotationDegrees = 90;
245 case ExifInterface.ORIENTATION_ROTATE_180:
246 rotationDegrees = 180;
248 case ExifInterface.ORIENTATION_ROTATE_270:
249 rotationDegrees = 270;
255 imageBitmap = bitmap;
256 imageRotationDegrees = rotationDegrees;
262 * Returns a point which is detected by a motion event.
264 * @param event A motion event.
265 * @return A point in the view finder. if a point is equal to null, the point is out of the view finder.
267 public PointF getPointWithEvent(MotionEvent event)
269 if (event == null || imageBitmap == null)
274 PointF pointOnView = new PointF(event.getX(), event.getY());
275 PointF pointOnImage = convertPointFromViewArea(pointOnView);
278 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
279 imageWidth = imageBitmap.getWidth();
280 imageHeight = imageBitmap.getHeight();
282 imageWidth = imageBitmap.getHeight();
283 imageHeight = imageBitmap.getWidth();
285 return (OLYCamera.convertPointOnLiveImageIntoViewfinder(pointOnImage, imageWidth, imageHeight, imageRotationDegrees));
289 * Returns whether a image area contains a specified point.
291 * @param point The point to examine.
292 * @return true if the image is not null or empty and the point is located within the rectangle; otherwise, false.
294 public boolean isContainsPoint(PointF point)
296 return ((point != null) && (new RectF(0, 0, 1, 1)).contains(point.x, point.y));
300 * Hides the forcus frame.
302 public void hideFocusFrame()
304 if (focusFrameHideTimer != null)
306 focusFrameHideTimer.cancel();
307 focusFrameHideTimer = null;
309 showingFocusFrame = false;
314 * Shows the focus frame.
316 * @param rect A rectangle of the focus frame on view area.
317 * @param status A status of the focus frame.
318 * @param duration A duration of the focus frame showing.
321 public void showFocusFrame(RectF rect, FocusFrameStatus status, double duration)
323 if (focusFrameHideTimer != null) {
324 focusFrameHideTimer.cancel();
325 focusFrameHideTimer = null;
328 showingFocusFrame = true;
329 focusFrameStatus = status;
330 focusFrameRect = rect;
335 focusFrameHideTimer = new Timer();
336 focusFrameHideTimer.schedule(new TimerTask() {
341 }, (long) (duration * 1000));
349 private void refreshCanvas()
351 if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
361 * @param canvas キャンバス
363 private void drawCanvas(Canvas canvas)
365 // Clears the canvas.
366 canvas.drawARGB(255, 0, 0, 0);
369 Bitmap bitmapToShow = imageBitmap;
370 if (bitmapToShow == null)
376 // Rotates the image.
377 int centerX = canvas.getWidth() / 2;
378 int centerY = canvas.getHeight() / 2;
379 canvas.rotate(imageRotationDegrees, centerX, centerY);
381 RectF viewRect = null;
383 // Calculate the viewport of bitmap.
384 if (imageScaleType == ImageView.ScaleType.FIT_CENTER)
386 viewRect = decideViewRect(canvas, bitmapToShow, imageRotationDegrees);
389 Rect imageRect = new Rect(0, 0, bitmapToShow.getWidth(), bitmapToShow.getHeight());
390 canvas.drawBitmap(bitmapToShow, imageRect, viewRect, null);
394 // Sorry, other scale types are not supported.
395 Log.v(TAG, "Sorry, other scale types are not supported. " + imageScaleType);
398 // Cancels rotation of the canvas.
399 canvas.rotate(-imageRotationDegrees, centerX, centerY);
403 if ((focusFrameRect != null) && (showingFocusFrame)) {
404 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
405 drawFocusFrame(canvas, bitmapToShow.getWidth(), bitmapToShow.getHeight());
407 drawFocusFrame(canvas, bitmapToShow.getHeight(), bitmapToShow.getWidth());
411 if (viewRect != null)
414 if ((showGridFeature) && (gridFrameDrawer != null))
416 drawGridFrame(canvas, viewRect);
419 // レベルゲージ(デジタル水準器)の表示
420 if (showLevelGaugeFeature)
422 drawLevelGauge(canvas, viewRect);
431 private RectF decideViewRect(Canvas canvas, Bitmap bitmapToShow, int degree)
435 if ((degree == 0) || (degree == 180))
437 srcWidth = bitmapToShow.getWidth();
438 srcHeight = bitmapToShow.getHeight();
442 // Replaces width and height.
443 srcWidth = bitmapToShow.getHeight();
444 srcHeight = bitmapToShow.getWidth();
447 int maxWidth = canvas.getWidth();
448 int maxHeight = canvas.getHeight();
450 int centerX = canvas.getWidth() / 2;
451 int centerY = canvas.getHeight() / 2;
453 float widthRatio = maxWidth / (float) srcWidth;
454 float heightRatio = maxHeight / (float) srcHeight;
455 float smallRatio = Math.min(widthRatio, heightRatio);
459 if (widthRatio < heightRatio)
461 // Fits to maxWidth with keeping aspect ratio.
463 dstHeight = (int) (smallRatio * srcHeight);
467 // Fits to maxHeight with keeping aspect ratio.
468 dstHeight = maxHeight;
469 dstWidth = (int) (smallRatio * srcWidth);
472 final float halfWidth = dstWidth * 0.5f;
473 final float halfHeight = dstHeight * 0.5f;
474 if ((degree == 0) || (degree == 180))
478 centerY - halfHeight,
479 centerX - halfWidth + dstWidth,
480 centerY - halfHeight + dstHeight));
483 // Replaces the width and height.
485 centerX - halfHeight,
487 centerX - halfHeight + dstHeight,
488 centerY - halfWidth + dstWidth));
494 * @param canvas キャンバス
495 * @param imageWidth 幅
496 * @param imageHeight 高さ
498 private void drawFocusFrame(Canvas canvas, float imageWidth, float imageHeight)
500 //Log.v(TAG, "drawFocusFrame() :" + focusFrameStatus);
502 // Calculate the rectangle of focus.
503 RectF focusRectOnImage = OLYCamera.convertRectOnViewfinderIntoLiveImage(focusFrameRect, imageWidth, imageHeight, imageRotationDegrees);
504 RectF focusRectOnView = convertRectFromImageArea(focusRectOnImage);
506 // Draw a rectangle to the canvas.
507 Paint focusFramePaint = new Paint();
508 focusFramePaint.setStyle(Paint.Style.STROKE);
509 switch (focusFrameStatus) {
511 focusFramePaint.setColor(Color.WHITE);
515 focusFramePaint.setColor(Color.GREEN);
519 focusFramePaint.setColor(Color.RED);
523 focusFramePaint.setColor(Color.YELLOW);
526 float focusFrameStrokeWidth = 2.0f;
527 DisplayMetrics dm = getResources().getDisplayMetrics();
528 float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, focusFrameStrokeWidth, dm);
529 focusFramePaint.setStrokeWidth(strokeWidth);
530 canvas.drawRect(focusRectOnView, focusFramePaint);
536 * @param canvas キャンバスエリア
537 * @param viewRect 表示領域
539 private void drawGridFrame(Canvas canvas, RectF viewRect)
542 if ((imageRotationDegrees == 0) || (imageRotationDegrees == 180)) {
543 gridRect = new RectF(viewRect);
545 float height = viewRect.right - viewRect.left;
546 float width = viewRect.bottom - viewRect.top;
547 float left = (canvas.getWidth() / 2.0f) - (width / 2.0f);
548 float top = (canvas.getHeight() / 2.0f) - (height / 2.0f);
549 gridRect = new RectF(left, top, left + width, top + height);
552 Paint framePaint = new Paint();
553 framePaint.setStyle(Paint.Style.STROKE);
554 framePaint.setAntiAlias(true);
556 //DisplayMetrics dm = getResources().getDisplayMetrics();
557 //float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1.0f, dm);
558 //framePaint.setStrokeWidth(strokeWidth);
559 framePaint.setStrokeWidth(0.0f);
560 framePaint.setColor(gridFrameDrawer.getDrawColor());
561 gridFrameDrawer.drawFramingGrid(canvas, gridRect, framePaint);
568 private void drawLevelGauge(Canvas canvas, RectF viewRect)
570 ILevelGauge levelGauge = messageHolder.getLevelGauge();
571 if (levelGauge == null)
573 // デジタル水準器がとれない場合は、何もしない
578 int height = (int) viewRect.bottom; // canvas.getHeight();
579 int width = (int) viewRect.right; // canvas.getWidth();
580 int centerX = width / 2;
581 int centerY = height / 2;
583 //float maxBandWidth = width / 3.0f; // ゲージの最大長 (画面の 1/3 ぐらい)
584 float maxBandHeight = height / 3.0f; // ゲージの最大長 (画面の 1/3 ぐらい)
585 int barWidthInitial = 4; // 表示するゲージの幅(の初期値)
586 int barWidth; // 実際に表示するゲージの幅
588 Paint paint = new Paint();
591 float verticalValue = levelGauge.getLevel(ILevelGauge.LevelArea.LEVEL_VERTICAL);
592 float verticalSize = verticalValue / 60.0f * maxBandHeight; // 45度で切り替わるはずだが、一応...
593 if (Math.abs(verticalSize) < 1.0f)
595 // 線引き限界以下、水平検出とする (この時の線は倍の長さにする)
597 barWidth = barWidthInitial * 2;
601 barWidth = barWidthInitial;
603 paint.setStrokeWidth(barWidth);
604 paint.setColor(levelGauge.getLevelColor(verticalValue));
605 canvas.drawLine((width - barWidth), centerY, (width - barWidth), (centerY + verticalSize), paint);
608 float horizontalValue = levelGauge.getLevel(ILevelGauge.LevelArea.LEVEL_HORIZONTAL);
609 paint.setStrokeWidth(2.0f);
610 paint.setAntiAlias(true);
611 paint.setColor(levelGauge.getLevelColor(horizontalValue));
612 if ((imageRotationDegrees == 0) || (imageRotationDegrees == 180))
615 float YY = canvas.getHeight() / 2.0f; // centerY
616 float diffY = (float) Math.sin(Math.toRadians(horizontalValue)) * (float) centerX;
617 canvas.drawLine(0, (YY + diffY), width, (YY - diffY), paint);
622 float XX = canvas.getWidth() / 2.0f; // centerX
623 float diffX = (float) Math.sin(Math.toRadians(horizontalValue)) * (float) centerY;
624 canvas.drawLine((XX + diffX), 0, (XX - diffX), canvas.getHeight(), paint);
629 float horizontalValue = levelGauge.getLevel(ILevelGauge.LevelArea.LEVEL_HORIZONTAL);
630 float horizontalSize = horizontalValue / 60.0f * maxBandWidth; // 45度ぐらいで切り替わるはずだが、一応...
631 if (Math.abs(horizontalSize) < 1.0f)
633 // 線引き限界以下、水平検出とする (この時の線は倍の長さにする)
634 horizontalSize = 1.0f;
635 barWidth = barWidthInitial * 2;
639 barWidth = barWidthInitial;
641 paint.setStrokeWidth(barWidth);
642 paint.setColor(levelGauge.getLevelColor(horizontalValue));
643 canvas.drawLine(centerX, (height - barWidth), (centerX + horizontalSize), (height - barWidth), paint);
650 private void drawInformationMessages(Canvas canvas)
654 if (imageBitmap != null)
656 // ビットマップの表示エリアに合わせて位置をチューニングする
657 viewRect = decideViewRect(canvas, imageBitmap, 0);
662 viewRect = new RectF(5.0f, 0.0f, canvas.getWidth() - 5.0f, canvas.getHeight() - 55.0f);
666 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.CENTER);
667 if ((message != null)&&(message.length() > 0))
669 Paint paint = new Paint();
670 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.CENTER));
671 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.CENTER));
672 paint.setAntiAlias(true);
673 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
674 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
675 float cx = (canvas.getWidth() / 2.0f) - (paint.measureText(message) / 2.0f);
676 float cy = (canvas.getHeight() / 2.0f) - ((fontMetrics.ascent + fontMetrics.descent) / 2.0f);
677 canvas.drawText(message, cx, cy, paint);
681 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.UPLEFT);
682 if ((message != null)&&(message.length() > 0))
684 Paint paintUp = new Paint();
685 paintUp.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.UPLEFT));
686 paintUp.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.UPLEFT));
687 paintUp.setAntiAlias(true);
688 paintUp.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
689 Paint.FontMetrics fontMetrics = paintUp.getFontMetrics();
690 canvas.drawText(message, viewRect.left + 3.0f, viewRect.top + (fontMetrics.descent - fontMetrics.ascent), paintUp);
694 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.UPRIGHT);
695 if ((message != null)&&(message.length() > 0))
697 Paint paintUp = new Paint();
698 paintUp.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.UPRIGHT));
699 paintUp.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.UPRIGHT));
700 paintUp.setAntiAlias(true);
701 paintUp.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
702 float width = paintUp.measureText(message);
703 Paint.FontMetrics fontMetrics = paintUp.getFontMetrics();
704 canvas.drawText(message, (viewRect.right - 3.0f) - width, viewRect.top + (fontMetrics.descent - fontMetrics.ascent), paintUp);
708 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.LOWLEFT);
709 if ((message != null)&&(message.length() > 0))
711 Paint paint = new Paint();
712 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.LOWLEFT));
713 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.LOWLEFT));
714 paint.setAntiAlias(true);
715 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
716 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
717 canvas.drawText(message, viewRect.left + 3.0f, viewRect.bottom - fontMetrics.bottom, paint);
721 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.LOWRIGHT);
722 if ((message != null)&&(message.length() > 0))
724 Paint paint = new Paint();
725 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.LOWRIGHT));
726 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.LOWRIGHT));
727 paint.setAntiAlias(true);
728 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
729 float width = paint.measureText(message);
730 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
731 canvas.drawText(message, (viewRect.right - 3.0f) - width, viewRect.bottom - fontMetrics.bottom, paint);
736 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.UPCENTER);
737 if ((message != null)&&(message.length() > 0))
739 Paint paintUp = new Paint();
740 paintUp.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.UPCENTER));
741 paintUp.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.UPCENTER));
742 paintUp.setAntiAlias(true);
743 paintUp.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
744 float width = paintUp.measureText(message) / 2.0f;
745 Paint.FontMetrics fontMetrics = paintUp.getFontMetrics();
746 canvas.drawText(message, (viewRect.centerX()) - width, viewRect.top + (fontMetrics.descent - fontMetrics.ascent), paintUp);
750 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.LOWCENTER);
751 if ((message != null)&&(message.length() > 0))
753 Paint paint = new Paint();
754 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.LOWCENTER));
755 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.LOWCENTER));
756 paint.setAntiAlias(true);
757 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
758 float width = paint.measureText(message) / 2.0f;
759 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
760 canvas.drawText(message, (viewRect.centerX()) - width, viewRect.bottom - fontMetrics.bottom, paint);
766 * Converts a point on image area to a point on view area.
768 * @param point A point on image area. (e.g. a live preview image)
769 * @return A point on view area. (e.g. a touch panel view)
771 private PointF convertPointFromImageArea(PointF point) {
772 if (imageBitmap == null) {
776 float viewPointX = point.x;
777 float viewPointY = point.y;
778 float imageSizeWidth;
779 float imageSizeHeight;
780 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
781 imageSizeWidth = imageBitmap.getWidth();
782 imageSizeHeight = imageBitmap.getHeight();
784 imageSizeWidth = imageBitmap.getHeight();
785 imageSizeHeight = imageBitmap.getWidth();
787 float viewSizeWidth = this.getWidth();
788 float viewSizeHeight = this.getHeight();
789 float ratioX = viewSizeWidth / imageSizeWidth;
790 float ratioY = viewSizeHeight / imageSizeHeight;
793 switch (imageScaleType) {
795 viewPointX *= ratioX;
796 viewPointY *= ratioY;
798 case FIT_CENTER: // go to next label.
800 scale = Math.min(ratioX, ratioY);
803 viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
804 viewPointY += (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
807 scale = Math.max(ratioX, ratioY);
810 viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
811 viewPointY += (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
814 viewPointX += viewSizeWidth / 2.0 - imageSizeWidth / 2.0f;
815 viewPointY += viewSizeHeight / 2.0 - imageSizeHeight / 2.0f;
820 return new PointF(viewPointX, viewPointY);
824 * Converts a point on view area to a point on image area.
826 * @param point A point on view area. (e.g. a touch panel view)
827 * @return A point on image area. (e.g. a live preview image)
829 private PointF convertPointFromViewArea(PointF point) {
830 if (imageBitmap == null) {
834 float imagePointX = point.x;
835 float imagePointY = point.y;
836 float imageSizeWidth;
837 float imageSizeHeight;
838 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
839 imageSizeWidth = imageBitmap.getWidth();
840 imageSizeHeight = imageBitmap.getHeight();
842 imageSizeWidth = imageBitmap.getHeight();
843 imageSizeHeight = imageBitmap.getWidth();
845 float viewSizeWidth = this.getWidth();
846 float viewSizeHeight = this.getHeight();
847 float ratioX = viewSizeWidth / imageSizeWidth;
848 float ratioY = viewSizeHeight / imageSizeHeight;
851 switch (imageScaleType) {
853 imagePointX /= ratioX;
854 imagePointY /= ratioY;
856 case FIT_CENTER: // go to next label.
858 scale = Math.min(ratioX, ratioY);
859 imagePointX -= (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
860 imagePointY -= (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
861 imagePointX /= scale;
862 imagePointY /= scale;
865 scale = Math.max(ratioX, ratioY);
866 imagePointX -= (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
867 imagePointY -= (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
868 imagePointX /= scale;
869 imagePointY /= scale;
872 imagePointX -= (viewSizeWidth - imageSizeWidth) / 2.0f;
873 imagePointY -= (viewSizeHeight - imageSizeHeight) / 2.0f;
878 return new PointF(imagePointX, imagePointY);
882 * Converts a rectangle on image area to a rectangle on view area.
884 * @param rect A rectangle on image area. (e.g. a live preview image)
885 * @return A rectangle on view area. (e.g. a touch panel view)
887 private RectF convertRectFromImageArea(RectF rect)
889 if (imageBitmap == null)
894 PointF imageTopLeft = new PointF(rect.left, rect.top);
895 PointF imageBottomRight = new PointF(rect.right, rect.bottom);
897 PointF viewTopLeft = convertPointFromImageArea(imageTopLeft);
898 PointF viewBottomRight = convertPointFromImageArea(imageBottomRight);
900 return (new RectF(viewTopLeft.x, viewTopLeft.y, viewBottomRight.x, viewBottomRight.y));
907 public void setShowGridFrame(boolean isShowGridFeature)
909 showGridFeature = isShowGridFeature;
910 SharedPreferences preferences = android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(getContext());
911 SharedPreferences.Editor editor = preferences.edit();
912 editor.putBoolean(ICameraPropertyAccessor.SHOW_GRID_STATUS, showGridFeature);
921 public void toggleShowGridFrame()
923 setShowGridFrame(!showGridFeature);
930 public void setShowLevelGauge(boolean isShowLevelGaugeFeature)
932 Log.v(TAG, "setShowLevelGauge : " + isShowLevelGaugeFeature);
933 showLevelGaugeFeature = isShowLevelGaugeFeature;
934 SharedPreferences preferences = android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(getContext());
935 SharedPreferences.Editor editor = preferences.edit();
936 editor.putBoolean(ICameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, showLevelGaugeFeature);
938 ILevelGauge levelGauge = messageHolder.getLevelGauge();
939 if (levelGauge == null)
941 // デジタル水準器がとれない場合は、何もしない
942 Log.v(TAG, "setShowLevelGauge : levelGauge is null.");
945 levelGauge.updateLevelGaugeChecking(isShowLevelGaugeFeature);
953 public void toggleShowLevelGauge()
955 setShowLevelGauge(!showLevelGaugeFeature);
963 public boolean isShowLevelGauge()
965 return (showLevelGaugeFeature);
973 public boolean isShowGrid()
975 return (showGridFeature);
983 public IMessageDrawer getMessageDrawer()
985 return (messageHolder);