blob: 0cab8fc496ea9d70b9b5d87abfec1c437e695ecb [file] [log] [blame]
Chih-Chung Chang063f09d2009-04-01 04:02:00 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080017package com.android.camera;
18
19import android.content.Context;
20import android.graphics.Bitmap;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080021import android.graphics.Matrix;
Ray Chen012d0f32009-07-20 16:33:41 +080022import android.graphics.RectF;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080023import android.graphics.drawable.Drawable;
24import android.os.Handler;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080025import android.util.AttributeSet;
Chih-Chung Chang063f09d2009-04-01 04:02:00 -070026import android.view.KeyEvent;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080027import android.widget.ImageView;
28
Ray Chen23c51b72009-04-10 03:41:00 -070029abstract class ImageViewTouchBase extends ImageView {
Owen Lin937fc482009-04-14 02:02:51 -070030
31 @SuppressWarnings("unused")
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080032 private static final String TAG = "ImageViewTouchBase";
Owen Lin937fc482009-04-14 02:02:51 -070033
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080034 // This is the base transformation which is used to show the image
35 // initially. The current computation for this shows the image in
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -070036 // it's entirety, letterboxing as needed. One could choose to
Owen Lin937fc482009-04-14 02:02:51 -070037 // show the image as cropped instead.
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080038 //
39 // This matrix is recomputed when we go from the thumbnail image to
40 // the full size image.
41 protected Matrix mBaseMatrix = new Matrix();
42
Owen Lin937fc482009-04-14 02:02:51 -070043 // This is the supplementary transformation which reflects what
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080044 // the user has done in terms of zooming and panning.
45 //
46 // This matrix remains the same when we go from the thumbnail image
47 // to the full size image.
48 protected Matrix mSuppMatrix = new Matrix();
49
50 // This is the final matrix which is computed as the concatentation
51 // of the base matrix and the supplementary matrix.
Owen Linbbc560b2009-04-17 11:31:27 +080052 private final Matrix mDisplayMatrix = new Matrix();
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080053
54 // Temporary buffer used for getting the values out of a matrix.
Owen Linbbc560b2009-04-17 11:31:27 +080055 private final float[] mMatrixValues = new float[9];
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080056
57 // The current bitmap being displayed.
Chih-Chung Chang522e8362009-08-26 16:12:34 +080058 protected final RotateBitmap mBitmapDisplayed = new RotateBitmap(null);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080059
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080060 int mThisWidth = -1, mThisHeight = -1;
Owen Lin937fc482009-04-14 02:02:51 -070061
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080062 float mMaxZoom;
Owen Lin937fc482009-04-14 02:02:51 -070063
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -070064 // ImageViewTouchBase will pass a Bitmap to the Recycler if it has finished
65 // its use of that Bitmap.
66 public interface Recycler {
67 public void recycle(Bitmap b);
68 }
69
70 public void setRecycler(Recycler r) {
71 mRecycler = r;
72 }
73
74 private Recycler mRecycler;
75
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080076 @Override
Chih-Chung Chang063f09d2009-04-01 04:02:00 -070077 protected void onLayout(boolean changed, int left, int top,
78 int right, int bottom) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080079 super.onLayout(changed, left, top, right, bottom);
80 mThisWidth = right - left;
81 mThisHeight = bottom - top;
82 Runnable r = mOnLayoutRunnable;
83 if (r != null) {
84 mOnLayoutRunnable = null;
85 r.run();
86 }
Ray Chen012d0f32009-07-20 16:33:41 +080087 if (mBitmapDisplayed.getBitmap() != null) {
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -070088 getProperBaseMatrix(mBitmapDisplayed, mBaseMatrix);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080089 setImageMatrix(getImageViewMatrix());
90 }
91 }
92
93 @Override
94 public boolean onKeyDown(int keyCode, KeyEvent event) {
Chih-Chung Chang0b8028e2009-09-25 15:12:14 -070095 if (keyCode == KeyEvent.KEYCODE_BACK
96 && event.getRepeatCount() == 0) {
97 event.startTracking();
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080098 return true;
99 }
100 return super.onKeyDown(keyCode, event);
101 }
102
Chih-Chung Chang0b8028e2009-09-25 15:12:14 -0700103 @Override
104 public boolean onKeyUp(int keyCode, KeyEvent event) {
105 if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking()
106 && !event.isCanceled()) {
107 if (getScale() > 1.0f) {
108 // If we're zoomed in, pressing Back jumps out to show the
109 // entire image, otherwise Back returns the user to the gallery.
110 zoomTo(1.0f);
111 return true;
112 }
113 }
114 return super.onKeyUp(keyCode, event);
115 }
116
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800117 protected Handler mHandler = new Handler();
Owen Lin937fc482009-04-14 02:02:51 -0700118
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800119 protected int mLastXTouchPos;
120 protected int mLastYTouchPos;
Owen Lin937fc482009-04-14 02:02:51 -0700121
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800122 @Override
123 public void setImageBitmap(Bitmap bitmap) {
Ray Chen012d0f32009-07-20 16:33:41 +0800124 setImageBitmap(bitmap, 0);
125 }
126
127 private void setImageBitmap(Bitmap bitmap, int rotation) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800128 super.setImageBitmap(bitmap);
129 Drawable d = getDrawable();
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700130 if (d != null) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800131 d.setDither(true);
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700132 }
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700133
Ray Chen012d0f32009-07-20 16:33:41 +0800134 Bitmap old = mBitmapDisplayed.getBitmap();
135 mBitmapDisplayed.setBitmap(bitmap);
136 mBitmapDisplayed.setRotation(rotation);
137
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700138 if (old != null && old != bitmap && mRecycler != null) {
139 mRecycler.recycle(old);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800140 }
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700141 }
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800142
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800143 public void clear() {
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700144 setImageBitmapResetBase(null, true);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800145 }
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800146
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700147 private Runnable mOnLayoutRunnable = null;
148
149 // This function changes bitmap, reset base matrix according to the size
150 // of the bitmap, and optionally reset the supplementary matrix.
151 public void setImageBitmapResetBase(final Bitmap bitmap,
152 final boolean resetSupp) {
Ray Chen012d0f32009-07-20 16:33:41 +0800153 setImageRotateBitmapResetBase(new RotateBitmap(bitmap), resetSupp);
154 }
155
156 public void setImageRotateBitmapResetBase(final RotateBitmap bitmap,
157 final boolean resetSupp) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800158 final int viewWidth = getWidth();
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800159
160 if (viewWidth <= 0) {
161 mOnLayoutRunnable = new Runnable() {
162 public void run() {
Ray Chen012d0f32009-07-20 16:33:41 +0800163 setImageRotateBitmapResetBase(bitmap, resetSupp);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800164 }
165 };
166 return;
167 }
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700168
Ray Chen012d0f32009-07-20 16:33:41 +0800169 if (bitmap.getBitmap() != null) {
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700170 getProperBaseMatrix(bitmap, mBaseMatrix);
Ray Chen012d0f32009-07-20 16:33:41 +0800171 setImageBitmap(bitmap.getBitmap(), bitmap.getRotation());
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800172 } else {
173 mBaseMatrix.reset();
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700174 setImageBitmap(null);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800175 }
176
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700177 if (resetSupp) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800178 mSuppMatrix.reset();
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700179 }
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800180 setImageMatrix(getImageViewMatrix());
181 mMaxZoom = maxZoom();
182 }
183
184 // Center as much as possible in one or both axis. Centering is
Owen Lin937fc482009-04-14 02:02:51 -0700185 // defined as follows: if the image is scaled down below the
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800186 // view's dimensions then center it (literally). If the image
187 // is scaled larger than the view and is translated out of view
188 // then translate it back into view (i.e. eliminate black bars).
Chih-Chung Chang97fc2012009-06-25 11:31:11 +0800189 protected void center(boolean horizontal, boolean vertical) {
Ray Chen012d0f32009-07-20 16:33:41 +0800190 if (mBitmapDisplayed.getBitmap() == null) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800191 return;
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700192 }
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800193
194 Matrix m = getImageViewMatrix();
195
Ray Chen012d0f32009-07-20 16:33:41 +0800196 RectF rect = new RectF(0, 0,
197 mBitmapDisplayed.getBitmap().getWidth(),
198 mBitmapDisplayed.getBitmap().getHeight());
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800199
Ray Chen012d0f32009-07-20 16:33:41 +0800200 m.mapRect(rect);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800201
Ray Chen012d0f32009-07-20 16:33:41 +0800202 float height = rect.height();
203 float width = rect.width();
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800204
205 float deltaX = 0, deltaY = 0;
206
207 if (vertical) {
208 int viewHeight = getHeight();
209 if (height < viewHeight) {
Ray Chen012d0f32009-07-20 16:33:41 +0800210 deltaY = (viewHeight - height) / 2 - rect.top;
211 } else if (rect.top > 0) {
212 deltaY = -rect.top;
213 } else if (rect.bottom < viewHeight) {
214 deltaY = getHeight() - rect.bottom;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800215 }
216 }
217
218 if (horizontal) {
219 int viewWidth = getWidth();
220 if (width < viewWidth) {
Ray Chen012d0f32009-07-20 16:33:41 +0800221 deltaX = (viewWidth - width) / 2 - rect.left;
222 } else if (rect.left > 0) {
223 deltaX = -rect.left;
224 } else if (rect.right < viewWidth) {
225 deltaX = viewWidth - rect.right;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800226 }
227 }
228
229 postTranslate(deltaX, deltaY);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800230 setImageMatrix(getImageViewMatrix());
231 }
Owen Lin937fc482009-04-14 02:02:51 -0700232
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800233 public ImageViewTouchBase(Context context) {
234 super(context);
235 init();
236 }
237
238 public ImageViewTouchBase(Context context, AttributeSet attrs) {
239 super(context, attrs);
240 init();
241 }
242
243 private void init() {
244 setScaleType(ImageView.ScaleType.MATRIX);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800245 }
246
247 protected float getValue(Matrix matrix, int whichValue) {
248 matrix.getValues(mMatrixValues);
249 return mMatrixValues[whichValue];
250 }
Owen Lin937fc482009-04-14 02:02:51 -0700251
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800252 // Get the scale factor out of the matrix.
253 protected float getScale(Matrix matrix) {
254 return getValue(matrix, Matrix.MSCALE_X);
255 }
256
257 protected float getScale() {
258 return getScale(mSuppMatrix);
259 }
Owen Lin937fc482009-04-14 02:02:51 -0700260
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800261 // Setup the base matrix so that the image is centered and scaled properly.
Ray Chen012d0f32009-07-20 16:33:41 +0800262 private void getProperBaseMatrix(RotateBitmap bitmap, Matrix matrix) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800263 float viewWidth = getWidth();
264 float viewHeight = getHeight();
265
Ray Chen012d0f32009-07-20 16:33:41 +0800266 float w = bitmap.getWidth();
267 float h = bitmap.getHeight();
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800268 matrix.reset();
Ray Chen012d0f32009-07-20 16:33:41 +0800269
Chih-Chung Chang1f463a62009-07-30 17:59:09 +0800270 // We limit up-scaling to 2x otherwise the result may look bad if it's
271 // a small icon.
272 float widthScale = Math.min(viewWidth / w, 2.0f);
273 float heightScale = Math.min(viewHeight / h, 2.0f);
Ray Chen012d0f32009-07-20 16:33:41 +0800274 float scale = Math.min(widthScale, heightScale);
275
276 matrix.postConcat(bitmap.getRotateMatrix());
277 matrix.postScale(scale, scale);
278
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800279 matrix.postTranslate(
Ray Chen012d0f32009-07-20 16:33:41 +0800280 (viewWidth - w * scale) / 2F,
281 (viewHeight - h * scale) / 2F);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800282 }
Owen Lin937fc482009-04-14 02:02:51 -0700283
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800284 // Combine the base matrix and the supp matrix to make the final matrix.
285 protected Matrix getImageViewMatrix() {
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700286 // The final matrix is computed as the concatentation of the base matrix
287 // and the supplementary matrix.
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800288 mDisplayMatrix.set(mBaseMatrix);
289 mDisplayMatrix.postConcat(mSuppMatrix);
290 return mDisplayMatrix;
291 }
292
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700293 static final float SCALE_RATE = 1.25F;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800294
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700295 // Sets the maximum zoom, which is a scale relative to the base matrix. It
296 // is calculated to show the image at 400% zoom regardless of screen or
297 // image orientation. If in the future we decode the full 3 megapixel image,
298 // rather than the current 1024x768, this should be changed down to 200%.
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800299 protected float maxZoom() {
Ray Chen012d0f32009-07-20 16:33:41 +0800300 if (mBitmapDisplayed.getBitmap() == null) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800301 return 1F;
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700302 }
Owen Lin937fc482009-04-14 02:02:51 -0700303
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700304 float fw = (float) mBitmapDisplayed.getWidth() / (float) mThisWidth;
305 float fh = (float) mBitmapDisplayed.getHeight() / (float) mThisHeight;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800306 float max = Math.max(fw, fh) * 4;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800307 return max;
308 }
309
310 protected void zoomTo(float scale, float centerX, float centerY) {
311 if (scale > mMaxZoom) {
312 scale = mMaxZoom;
313 }
Owen Lin937fc482009-04-14 02:02:51 -0700314
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800315 float oldScale = getScale();
316 float deltaScale = scale / oldScale;
317
318 mSuppMatrix.postScale(deltaScale, deltaScale, centerX, centerY);
319 setImageMatrix(getImageViewMatrix());
Chih-Chung Chang0a475e12009-04-16 11:42:12 +0800320 center(true, true);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800321 }
Owen Lin937fc482009-04-14 02:02:51 -0700322
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700323 protected void zoomTo(final float scale, final float centerX,
324 final float centerY, final float durationMs) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800325 final float incrementPerMs = (scale - getScale()) / durationMs;
326 final float oldScale = getScale();
327 final long startTime = System.currentTimeMillis();
Owen Lin937fc482009-04-14 02:02:51 -0700328
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800329 mHandler.post(new Runnable() {
330 public void run() {
331 long now = System.currentTimeMillis();
Owen Lin937fc482009-04-14 02:02:51 -0700332 float currentMs = Math.min(durationMs, now - startTime);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800333 float target = oldScale + (incrementPerMs * currentMs);
334 zoomTo(target, centerX, centerY);
Owen Lin937fc482009-04-14 02:02:51 -0700335
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800336 if (currentMs < durationMs) {
337 mHandler.post(this);
338 }
339 }
Owen Lin937fc482009-04-14 02:02:51 -0700340 });
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800341 }
342
343 protected void zoomTo(float scale) {
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700344 float cx = getWidth() / 2F;
345 float cy = getHeight() / 2F;
Owen Lin937fc482009-04-14 02:02:51 -0700346
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700347 zoomTo(scale, cx, cy);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800348 }
Owen Lin937fc482009-04-14 02:02:51 -0700349
Chih-Chung Changeb9b5372009-09-10 12:36:52 +0800350 protected void zoomToPoint(float scale, float pointX, float pointY) {
351 float cx = getWidth() / 2F;
352 float cy = getHeight() / 2F;
353
354 panBy(cx - pointX, cy - pointY);
355 zoomTo(scale, cx, cy);
356 }
357
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800358 protected void zoomIn() {
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700359 zoomIn(SCALE_RATE);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800360 }
Owen Lin937fc482009-04-14 02:02:51 -0700361
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800362 protected void zoomOut() {
Chih-Chung Chang063f09d2009-04-01 04:02:00 -0700363 zoomOut(SCALE_RATE);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800364 }
365
366 protected void zoomIn(float rate) {
367 if (getScale() >= mMaxZoom) {
368 return; // Don't let the user zoom into the molecular level.
369 }
Ray Chen012d0f32009-07-20 16:33:41 +0800370 if (mBitmapDisplayed.getBitmap() == null) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800371 return;
372 }
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800373
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700374 float cx = getWidth() / 2F;
375 float cy = getHeight() / 2F;
376
377 mSuppMatrix.postScale(rate, rate, cx, cy);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800378 setImageMatrix(getImageViewMatrix());
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800379 }
380
381 protected void zoomOut(float rate) {
Ray Chen012d0f32009-07-20 16:33:41 +0800382 if (mBitmapDisplayed.getBitmap() == null) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800383 return;
384 }
Owen Lin937fc482009-04-14 02:02:51 -0700385
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700386 float cx = getWidth() / 2F;
387 float cy = getHeight() / 2F;
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800388
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700389 // Zoom out to at most 1x.
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800390 Matrix tmp = new Matrix(mSuppMatrix);
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700391 tmp.postScale(1F / rate, 1F / rate, cx, cy);
392
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800393 if (getScale(tmp) < 1F) {
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700394 mSuppMatrix.setScale(1F, 1F, cx, cy);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800395 } else {
Chih-Chung Chang7db87ab2009-04-12 21:42:43 -0700396 mSuppMatrix.postScale(1F / rate, 1F / rate, cx, cy);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800397 }
398 setImageMatrix(getImageViewMatrix());
Chih-Chung Chang0a475e12009-04-16 11:42:12 +0800399 center(true, true);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800400 }
Owen Lin937fc482009-04-14 02:02:51 -0700401
The Android Open Source Projectb64d3452009-03-03 19:32:20 -0800402 protected void postTranslate(float dx, float dy) {
403 mSuppMatrix.postTranslate(dx, dy);
404 }
405
406 protected void panBy(float dx, float dy) {
407 postTranslate(dx, dy);
408 setImageMatrix(getImageViewMatrix());
409 }
410}