Android Open Source - TouchImageView Single Touch Image View Activity






From Project

Back to project page TouchImageView.

License

The source code is released under:

opyright (c) 2012 Michael Ortiz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softw...

If you think the Android project TouchImageView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ortiz.touch;
import java.text.DecimalFormat;
//ww w  . ja  v a 2  s .  co  m
import android.app.Activity;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Bundle;
import android.widget.TextView;

import com.example.touch.R;
import com.ortiz.touch.TouchImageView.OnTouchImageViewListener;


public class SingleTouchImageViewActivity extends Activity {
  
  private TouchImageView image;
  private TextView scrollPositionTextView;
  private TextView zoomedRectTextView;
  private TextView currentZoomTextView;
  private DecimalFormat df;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_touchimageview);
    //
    // DecimalFormat rounds to 2 decimal places.
    //
    df = new DecimalFormat("#.##");
    scrollPositionTextView = (TextView) findViewById(R.id.scroll_position);
    zoomedRectTextView = (TextView) findViewById(R.id.zoomed_rect);
    currentZoomTextView = (TextView) findViewById(R.id.current_zoom);
    image = (TouchImageView) findViewById(R.id.img);
    
    //
    // Set the OnTouchImageViewListener which updates edit texts
    // with zoom and scroll diagnostics.
    //
    image.setOnTouchImageViewListener(new OnTouchImageViewListener() {
      
      @Override
      public void onMove() {
        PointF point = image.getScrollPosition();
        RectF rect = image.getZoomedRect();
        float currentZoom = image.getCurrentZoom();
        boolean isZoomed = image.isZoomed();
        scrollPositionTextView.setText("x: " + df.format(point.x) + " y: " + df.format(point.y));
        zoomedRectTextView.setText("left: " + df.format(rect.left) + " top: " + df.format(rect.top)
            + "\nright: " + df.format(rect.right) + " bottom: " + df.format(rect.bottom));
        currentZoomTextView.setText("getCurrentZoom(): " + currentZoom + " isZoomed(): " + isZoomed);
      }
    });
  }
}




Java Source Code List

com.ortiz.touch.ExtendedViewPager.java
com.ortiz.touch.MainActivity.java
com.ortiz.touch.MirroringExampleActivity.java
com.ortiz.touch.SingleTouchImageViewActivity.java
com.ortiz.touch.SwitchImageExampleActivity.java
com.ortiz.touch.SwitchScaleTypeExampleActivity.java
com.ortiz.touch.TouchImageView.java
com.ortiz.touch.ViewPagerExampleActivity.java