OSDN Git Service

Added dashed diagonal for crop.
authorRuben Brunk <rubenbrunk@google.com>
Thu, 29 Nov 2012 05:52:46 +0000 (21:52 -0800)
committerRuben Brunk <rubenbrunk@google.com>
Thu, 29 Nov 2012 07:27:18 +0000 (23:27 -0800)
Bug: 7634466
Change-Id: I14c778766d4b00495b2f5f6fa5f87f4877f76381

src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/PanelController.java
src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java

index ad26bfe..c1e4f6a 100644 (file)
@@ -203,6 +203,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         mImageFlip = (ImageFlip) findViewById(R.id.imageFlip);
         mImageTinyPlanet = (ImageTinyPlanet) findViewById(R.id.imageTinyPlanet);
 
+        mImageCrop.setAspectTextSize((int) getPixelsFromDip(18));
         ImageCrop.setTouchTolerance((int) getPixelsFromDip(25));
         mImageViews.add(mImageShow);
         mImageViews.add(mImageCurves);
index 00af7e5..52bf98a 100644 (file)
@@ -157,38 +157,52 @@ public class PanelController implements OnClickListener {
             ImageCrop imageCrop = (ImageCrop) mCurrentImage;
             switch (itemId) {
                 case R.id.crop_menu_1to1: {
-                    button.setText(mContext.getString(R.string.aspect1to1_effect));
+                    String t = mContext.getString(R.string.aspect1to1_effect);
+                    button.setText(t);
                     imageCrop.apply(1, 1);
+                    imageCrop.setAspectString(t);
                     break;
                 }
                 case R.id.crop_menu_4to3: {
-                    button.setText(mContext.getString(R.string.aspect4to3_effect));
+                    String t = mContext.getString(R.string.aspect4to3_effect);
+                    button.setText(t);
                     imageCrop.apply(4, 3);
+                    imageCrop.setAspectString(t);
                     break;
                 }
                 case R.id.crop_menu_3to4: {
-                    button.setText(mContext.getString(R.string.aspect3to4_effect));
+                    String t = mContext.getString(R.string.aspect3to4_effect);
+                    button.setText(t);
                     imageCrop.apply(3, 4);
+                    imageCrop.setAspectString(t);
                     break;
                 }
                 case R.id.crop_menu_5to7: {
-                    button.setText(mContext.getString(R.string.aspect5to7_effect));
+                    String t = mContext.getString(R.string.aspect5to7_effect);
+                    button.setText(t);
                     imageCrop.apply(5, 7);
+                    imageCrop.setAspectString(t);
                     break;
                 }
                 case R.id.crop_menu_7to5: {
-                    button.setText(mContext.getString(R.string.aspect7to5_effect));
+                    String t = mContext.getString(R.string.aspect7to5_effect);
+                    button.setText(t);
                     imageCrop.apply(7, 5);
+                    imageCrop.setAspectString(t);
                     break;
                 }
                 case R.id.crop_menu_none: {
-                    button.setText(mContext.getString(R.string.aspectNone_effect));
+                    String t = mContext.getString(R.string.aspectNone_effect);
+                    button.setText(t);
                     imageCrop.applyClear();
+                    imageCrop.setAspectString(t);
                     break;
                 }
                 case R.id.crop_menu_original: {
-                    button.setText(mContext.getString(R.string.aspectOriginal_effect));
+                    String t = mContext.getString(R.string.aspectOriginal_effect);
+                    button.setText(t);
                     imageCrop.applyOriginal();
+                    imageCrop.setAspectString(t);
                     break;
                 }
             }
index a031fa5..a352a16 100644 (file)
@@ -62,6 +62,17 @@ public class ImageCrop extends ImageGeometry {
 
     private static final String LOGTAG = "ImageCrop";
 
+    private String mAspect = "";
+    private int mAspectTextSize = 24;
+
+    public void setAspectTextSize(int textSize){
+        mAspectTextSize = textSize;
+    }
+
+    public void setAspectString(String a){
+        mAspect = a;
+    }
+
     private static final Paint gPaint = new Paint();
 
     public ImageCrop(Context context) {
@@ -642,6 +653,35 @@ public class ImageCrop extends ImageGeometry {
         gPaint.setStyle(Paint.Style.STROKE);
         drawRuleOfThird(canvas, crop, gPaint);
 
+        if (mFixAspectRatio){
+            float w = crop.width();
+            float h = crop.height();
+            float diag = (float) Math.sqrt(w*w + h*h);
+
+            float dash_len = 20;
+            int num_intervals = (int) (diag / dash_len);
+            float [] tl = { crop.left, crop.top };
+            float centX = tl[0] + w/2;
+            float centY = tl[1] + h/2 + 5;
+            float [] br = { crop.right, crop.bottom };
+            float [] vec = GeometryMath.getUnitVectorFromPoints(tl, br);
+
+            float [] counter = tl;
+            for (int x = 0; x < num_intervals; x++ ){
+                float tempX = counter[0] + vec[0] * dash_len;
+                float tempY = counter[1] + vec[1] * dash_len;
+                if ((x % 2) == 0 && Math.abs(x - num_intervals / 2) > 2){
+                    canvas.drawLine(counter[0], counter[1], tempX, tempY, gPaint);
+                }
+                counter[0] = tempX;
+                counter[1] = tempY;
+            }
+
+            gPaint.setTextAlign(Paint.Align.CENTER);
+            gPaint.setTextSize(mAspectTextSize);
+            canvas.drawText(mAspect, centX, centY, gPaint);
+        }
+
         gPaint.setColor(mBorderColor);
         gPaint.setStrokeWidth(3);
         gPaint.setStyle(Paint.Style.STROKE);