Advertisement
Guest User

Untitled

a guest
Jul 11th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. package com.zoom.test;
  2.  
  3. import android.app.Activity;
  4. import android.graphics.Bitmap;
  5. import android.graphics.BitmapFactory;
  6. import android.graphics.Matrix;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.MotionEvent;
  10. import android.widget.ImageView;
  11. import android.widget.RelativeLayout;
  12. import android.widget.ZoomButtonsController;
  13.  
  14. public class TestZoomButtonActivity extends Activity {
  15.  
  16.     int cnt = 1;
  17.     ZoomButtonsController mZoomButtonsController;
  18.     ImageView image;
  19.  
  20.     /** Called when the activity is first created. */
  21.     @Override
  22.     public void onCreate(Bundle savedInstanceState) {
  23.         super.onCreate(savedInstanceState);
  24.         setContentView(R.layout.main);
  25.         RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
  26.         image = (ImageView) findViewById(R.id.imageView1);
  27.  
  28.         mZoomButtonsController = new ZoomButtonsController(layout);
  29.         mZoomButtonsController.setFocusable(true);
  30.         mZoomButtonsController.setZoomInEnabled(true);
  31.         mZoomButtonsController.setZoomOutEnabled(true);
  32.         mZoomButtonsController.setAutoDismissed(true);
  33.         mZoomButtonsController.setZoomSpeed(1000);
  34.  
  35.         mZoomButtonsController
  36.                 .setOnZoomListener(new ZoomButtonsController.OnZoomListener() {
  37.                     @Override
  38.                     public void onVisibilityChanged(boolean visible) {
  39.                     }
  40.  
  41.                     @Override
  42.                     public void onZoom(boolean zoomIn) {
  43.                         if (zoomIn) {
  44.                             if (cnt < 10) {
  45.                                 cnt++;
  46.                             }
  47.                         } else {
  48.                             if (cnt > 1) {
  49.                                 cnt--;
  50.                             }
  51.                         }
  52.  
  53.                         Bitmap b = BitmapFactory.decodeResource(getResources(),
  54.                                 R.drawable.ic_launcher);
  55.                         Matrix ma = new Matrix();
  56.  
  57.                         ma.postScale(cnt, cnt);
  58.                         image.setImageBitmap(Bitmap.createBitmap(b, 0, 0,
  59.                                 b.getWidth(), b.getHeight(), ma, true));
  60.                     }
  61.  
  62.                 });
  63.  
  64.     }
  65.  
  66.     @Override
  67.     public boolean onTouchEvent(MotionEvent m) {
  68.  
  69.         // TODO Auto-generated method stub
  70.         mZoomButtonsController.setVisible(true);
  71.         return false;
  72.  
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement