Code example for ZoomControls

Methods: getVisibility, setIsZoomInEnabled, setIsZoomOutEnabled, setVisibility

0
				if (zoomControls.getVisibility() == View.VISIBLE) {
					super.onDown(e);
					return true; 
				} else { 
					onClick(me);
					return false; 
				} 
			} 
 
			@Override 
			public boolean onScroll(MotionEvent e1, MotionEvent e2, float dx, float dy)
			{ 
				if (zoomControls.getVisibility() == View.VISIBLE) {
					changeMatrix.postTranslate(-dx, -dy);
					imageView.setImageMatrix(getViewMatrix());
					requestLayout();
					scheduleControlTimeout(); 
					return true; 
				} else { 
					return false; 
				} 
			} 
 
			@Override 
			public boolean onSingleTapConfirmed(MotionEvent e)
			{ 
				onClick(me);
				return super.onSingleTapConfirmed(e);
			} 
		}); 
		gestureDetector.setIsLongpressEnabled(false);
 
		zoomControls = new ZoomControls(context);
		addView(zoomControls);
		zoomControls.setVisibility(View.GONE);
		zoomControls.setZoomSpeed(75);
		zoomControls.setOnZoomInClickListener(new OnClickListener()
		{ 
			public void onClick(View v)
			{ 
				handleScaleUp(); 
			} 
		}); 
		zoomControls.setOnZoomOutClickListener(new OnClickListener()
		{ 
			public void onClick(View v)
			{ 
				handleScaleDown(); 
			} 
		}); 
 
		super.setOnClickListener(this);
	} 
 
	public void setEnableScale(boolean enableScale)
	{ 
		this.enableScale = enableScale;
		updateScaleType(); 
	} 
 
	public void setEnableZoomControls(boolean enableZoomControls)
	{ 
		this.enableZoomControls = enableZoomControls;
		updateScaleType(); 
	} 
 
	public Drawable getImageDrawable() {
		return imageView.getDrawable();
	} 
 
	/** 
	 * Sets a Bitmap as the content of imageView 
	 * @param bitmap The bitmap to set. If it is null, it will clear the previous image. 
	 */ 
	public void setImageBitmap(Bitmap bitmap) {
		imageView.setImageBitmap(bitmap);
	} 
 
	public void setOnClickListener(OnClickListener clickListener)
	{ 
		this.clickListener = clickListener;
	} 
 
	public boolean handleMessage(Message msg)
	{ 
		switch (msg.what) {
			case MSG_HIDE_CONTROLS: {
				handleHideControls(); 
				return true; 
			} 
		} 
		return false; 
	} 
 
	public void onClick(View view)
	{ 
		boolean sendClick = true;
		if (enableZoomControls) {
			if (zoomControls.getVisibility() != View.VISIBLE) {
				sendClick = false;
				manageControls(); 
				zoomControls.setVisibility(View.VISIBLE);
			} 
			scheduleControlTimeout(); 
		} 
		if (sendClick && clickListener != null) {
			clickListener.onClick(view);
		} 
	} 
 
	private void handleScaleUp() 
	{ 
		if (scaleFactor < scaleMax) {
			onViewChanged(scaleIncrement);
		} 
	} 
 
	private void handleScaleDown() 
	{ 
		if (scaleFactor > scaleMin) {
			onViewChanged(-scaleIncrement);
		} 
	} 
 
	private void handleHideControls() 
	{ 
		zoomControls.setVisibility(View.GONE);
	} 
 
	private void manageControls() 
	{ 
		if (scaleFactor == scaleMax) {
			zoomControls.setIsZoomInEnabled(false);
		} else { 
			zoomControls.setIsZoomInEnabled(true);
		} 
 
		if (scaleFactor == scaleMin) {
			zoomControls.setIsZoomOutEnabled(false);
		} else { 
			zoomControls.setIsZoomOutEnabled(true);
		} 
	} 
 
	private void onViewChanged(float dscale)
	{ 
		updateChangeMatrix(dscale);
		manageControls(); 
		requestLayout();
		scheduleControlTimeout(); 
	} 
 
	private void computeBaseMatrix() 
	{ 
		Drawable d = imageView.getDrawable();
		baseMatrix.reset();
 
		if (d != null) {
			// The base matrix is the matrix that displays the entire image bitmap. 
			// It orients the image when orientation is set and scales in X and Y independently,  
			// so that src matches dst exactly. 
			// This may change the aspect ratio of the src. 
			Rect r = new Rect();
			getDrawingRect(r);
			int intrinsicWidth = d.getIntrinsicWidth();
			int intrinsicHeight = d.getIntrinsicHeight();