Code example for ZoomButtonsController

Methods: getContainer, setAutoDismissed, setOnZoomListener, setZoomInEnabled, setZoomOutEnabled, setZoomSpeed

1
	{ 
		if (mZoomButtons == null) 
		{ 
			ViewGroup parent = (ViewGroup)this.getParent(); 
			 
	    	mZoomButtons = new ZoomButtonsController(parent); 
	    	mZoomButtons.setAutoDismissed(false); 
	    	mZoomButtons.setZoomSpeed(30); 
	    	mZoomButtons.setOnZoomListener(new ZoomButtonsController.OnZoomListener() 
			{ 
				public void onZoom(boolean zoomIn) 
				{ 
					float scale; 
					 
//					Log.d("ZoomableImageView", "onZoom" + (zoomIn ? "In" : "Out")); 
					 
					if (zoomIn) 
						scale = 1.1f; 
					else 
						scale = 0.9f; 
					 
					resetZoomButtonsHideTimeout(); 
					 
					zoom(scale); 
				} 
				 
				public void onVisibilityChanged(boolean visible) 
				{ 
					if (visible) 
						updateZoomButtonsEnabled(); 
				} 
			}); 
	    	 
	    	// Make sure zoom in/out are disabled if the current scale is outside zoom bounds  
	    	updateZoomButtonsEnabled(); 
	    	 
	    	ViewGroup zoomContainer = mZoomButtons.getContainer(); 
 
//			Log.d("ZoomableImageView", "parent class is " + parent.getClass().toString()); 
 
			// Move zoom controls to bottom right, if possible 
	    	if (parent instanceof LinearLayout) 
	    	{ 
	    		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
	    				LayoutParams.WRAP_CONTENT); 
	    		params.gravity = Gravity.BOTTOM | Gravity.RIGHT; 
	    		 
	    		zoomContainer.setLayoutParams(params); 
	    	} 
	    	else if (parent instanceof RelativeLayout) 
	    	{ 
	    		RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
	    				LayoutParams.WRAP_CONTENT); 
 
	    		params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
	    		params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
	    		 
	    		zoomContainer.setLayoutParams(params); 
	    	} 
	    	 
	    	// Don't add zoom buttons directly; use their container instead, otherwise they won't be visible 
	    	parent.addView(zoomContainer); 
		} 
		 
		if (mHideZoomButtonsRunnable == null) 
		{ 
	        mHideZoomButtonsRunnable = new Runnable() 
	    	{ 
	    		public void run() 
	    		{ 
	                mZoomButtons.getZoomControls().startAnimation(mFadeOut);
	                mZoomButtons.getZoomControls().setVisibility(View.GONE);
	                mZoomButtonsAnimationHandler.removeCallbacks(this);
	    		} 
	    	}; 
		} 
   	} 
	 
	protected void initialize(Context context)
	{ 
        super.setClickable(true); 
        this.mContext = context;
        mScaleDetector = VersionedGestureDetector.newInstance(context, new ScaleListener());
        matrix.setTranslate(1f, 1f);
        m = new float[9];
        setImageMatrix(matrix);
        setScaleType(ScaleType.MATRIX);
         
        // initialize animations 
        if (mFadeIn == null)
        { 
        	mFadeIn = new AlphaAnimation(0, 1);
        	mFadeIn.setDuration(ZOOM_BUTTONS_ANIMATION_TIME);
        } 
         
        if (mFadeOut == null)
        { 
        	mFadeOut = new AlphaAnimation(1, 0);
        	mFadeOut.setDuration(ZOOM_BUTTONS_ANIMATION_TIME);
        } 
	} 
	 
    @Override 
    public void setImageBitmap(Bitmap bm) { 
        super.setImageBitmap(bm);
        bmWidth = bm.getWidth();
        bmHeight = bm.getHeight();
    } 
     
    protected void updateZoomButtonsEnabled() 
    { 
    	initializeZoomButtonsIfNecessary(); 
    	 
        if (currScale >= maxScale)
        	mZoomButtons.setZoomInEnabled(false);
        else if (currScale <= minScale)
        	mZoomButtons.setZoomOutEnabled(false);
        else 
        { 
        	mZoomButtons.setZoomInEnabled(true);
        	mZoomButtons.setZoomOutEnabled(true);
        } 
    } 
     
    protected void doTranslation(float deltaX, float deltaY)
    {