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);
774 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.CENTERLEFT);
775 if ((message != null)&&(message.length() > 0))
777 Paint paint = new Paint();
778 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.CENTERLEFT));
779 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.CENTERLEFT));
780 paint.setAntiAlias(true);
781 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
782 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
783 float cy = (canvas.getHeight() / 2.0f) - ((fontMetrics.ascent + fontMetrics.descent) / 2.0f);
784 canvas.drawText(message, viewRect.left + 3.0f, cy, paint);
788 message = messageHolder.getMessage(ShowMessageHolder.MessageArea.CENTERRIGHT);
789 if ((message != null)&&(message.length() > 0))
791 Paint paint = new Paint();
792 paint.setColor(messageHolder.getColor(ShowMessageHolder.MessageArea.CENTERRIGHT));
793 paint.setTextSize(messageHolder.getSize(ShowMessageHolder.MessageArea.CENTERRIGHT));
794 paint.setAntiAlias(true);
795 paint.setShadowLayer(5.0f, 3.0f, 3.0f, Color.BLACK); // これで文字に影をつけたい
796 float width = paint.measureText(message);
797 Paint.FontMetrics fontMetrics = paint.getFontMetrics();
798 float cy = (canvas.getHeight() / 2.0f) - ((fontMetrics.ascent + fontMetrics.descent) / 2.0f);
799 canvas.drawText(message, (viewRect.right - 3.0f) - width, cy, paint);
805 * Converts a point on image area to a point on view area.
807 * @param point A point on image area. (e.g. a live preview image)
808 * @return A point on view area. (e.g. a touch panel view)
810 private PointF convertPointFromImageArea(PointF point) {
811 if (imageBitmap == null) {
815 float viewPointX = point.x;
816 float viewPointY = point.y;
817 float imageSizeWidth;
818 float imageSizeHeight;
819 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
820 imageSizeWidth = imageBitmap.getWidth();
821 imageSizeHeight = imageBitmap.getHeight();
823 imageSizeWidth = imageBitmap.getHeight();
824 imageSizeHeight = imageBitmap.getWidth();
826 float viewSizeWidth = this.getWidth();
827 float viewSizeHeight = this.getHeight();
828 float ratioX = viewSizeWidth / imageSizeWidth;
829 float ratioY = viewSizeHeight / imageSizeHeight;
832 switch (imageScaleType) {
834 viewPointX *= ratioX;
835 viewPointY *= ratioY;
837 case FIT_CENTER: // go to next label.
839 scale = Math.min(ratioX, ratioY);
842 viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
843 viewPointY += (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
846 scale = Math.max(ratioX, ratioY);
849 viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
850 viewPointY += (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
853 viewPointX += viewSizeWidth / 2.0 - imageSizeWidth / 2.0f;
854 viewPointY += viewSizeHeight / 2.0 - imageSizeHeight / 2.0f;
859 return new PointF(viewPointX, viewPointY);
863 * Converts a point on view area to a point on image area.
865 * @param point A point on view area. (e.g. a touch panel view)
866 * @return A point on image area. (e.g. a live preview image)
868 private PointF convertPointFromViewArea(PointF point) {
869 if (imageBitmap == null) {
873 float imagePointX = point.x;
874 float imagePointY = point.y;
875 float imageSizeWidth;
876 float imageSizeHeight;
877 if (imageRotationDegrees == 0 || imageRotationDegrees == 180) {
878 imageSizeWidth = imageBitmap.getWidth();
879 imageSizeHeight = imageBitmap.getHeight();
881 imageSizeWidth = imageBitmap.getHeight();
882 imageSizeHeight = imageBitmap.getWidth();
884 float viewSizeWidth = this.getWidth();
885 float viewSizeHeight = this.getHeight();
886 float ratioX = viewSizeWidth / imageSizeWidth;
887 float ratioY = viewSizeHeight / imageSizeHeight;
890 switch (imageScaleType) {
892 imagePointX /= ratioX;
893 imagePointY /= ratioY;
895 case FIT_CENTER: // go to next label.
897 scale = Math.min(ratioX, ratioY);
898 imagePointX -= (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
899 imagePointY -= (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
900 imagePointX /= scale;
901 imagePointY /= scale;
904 scale = Math.max(ratioX, ratioY);
905 imagePointX -= (viewSizeWidth - imageSizeWidth * scale) / 2.0f;
906 imagePointY -= (viewSizeHeight - imageSizeHeight * scale) / 2.0f;
907 imagePointX /= scale;
908 imagePointY /= scale;
911 imagePointX -= (viewSizeWidth - imageSizeWidth) / 2.0f;
912 imagePointY -= (viewSizeHeight - imageSizeHeight) / 2.0f;
917 return new PointF(imagePointX, imagePointY);
921 * Converts a rectangle on image area to a rectangle on view area.
923 * @param rect A rectangle on image area. (e.g. a live preview image)
924 * @return A rectangle on view area. (e.g. a touch panel view)
926 private RectF convertRectFromImageArea(RectF rect)
928 if (imageBitmap == null)
933 PointF imageTopLeft = new PointF(rect.left, rect.top);
934 PointF imageBottomRight = new PointF(rect.right, rect.bottom);
936 PointF viewTopLeft = convertPointFromImageArea(imageTopLeft);
937 PointF viewBottomRight = convertPointFromImageArea(imageBottomRight);
939 return (new RectF(viewTopLeft.x, viewTopLeft.y, viewBottomRight.x, viewBottomRight.y));
946 public void setShowGridFrame(boolean isShowGridFeature)
948 showGridFeature = isShowGridFeature;
949 SharedPreferences preferences = android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(getContext());
950 SharedPreferences.Editor editor = preferences.edit();
951 editor.putBoolean(IPreferenceCameraPropertyAccessor.SHOW_GRID_STATUS, showGridFeature);
960 public void toggleShowGridFrame()
962 setShowGridFrame(!showGridFeature);
969 public void setShowLevelGauge(boolean isShowLevelGaugeFeature)
971 Log.v(TAG, "setShowLevelGauge : " + isShowLevelGaugeFeature);
972 showLevelGaugeFeature = isShowLevelGaugeFeature;
973 SharedPreferences preferences = android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(getContext());
974 SharedPreferences.Editor editor = preferences.edit();
975 editor.putBoolean(IPreferenceCameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, showLevelGaugeFeature);
977 ILevelGauge levelGauge = messageHolder.getLevelGauge();
978 if (levelGauge == null)
980 // デジタル水準器がとれない場合は、何もしない
981 Log.v(TAG, "setShowLevelGauge : levelGauge is null.");
984 levelGauge.updateLevelGaugeChecking(isShowLevelGaugeFeature);
992 public void toggleShowLevelGauge()
994 setShowLevelGauge(!showLevelGaugeFeature);
1002 public boolean isShowLevelGauge()
1004 return (showLevelGaugeFeature);
1012 public boolean isShowGrid()
1014 return (showGridFeature);
1022 public IMessageDrawer getMessageDrawer()
1024 return (messageHolder);
1032 public void showDialog(IDialogDrawer dialogDrawer)
1034 this.dialogDrawer = dialogDrawer;
1042 public void hideDialog()
1044 this.dialogDrawer = null;
1053 public boolean touchedPosition(float posX, float posY)
1055 return ((dialogDrawer != null)&&(dialogDrawer.touchedPosition(posX, posY)));