1 / 13

Agenda

Cincinnati Android Developers Meetup Android Touch Event & Singleton vs. Android's Application Class 12/21/2011. Agenda. 6:15 to 6:30 - Food and Mingling 6:30 to 6:45 - FailBlog Viewer Updates / Touch Events Auto Sizing Images on Load Moving the Image and Pinch Zooming

nicole
Download Presentation

Agenda

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cincinnati Android Developers MeetupAndroid Touch Event &Singleton vs. Android's Application Class12/21/2011

  2. Agenda 6:15 to 6:30 - Food and Mingling 6:30 to 6:45 - FailBlog Viewer Updates / Touch Events Auto Sizing Images on Load Moving the Image and Pinch Zooming 6:45 to 7:15 - Singleton vs. Android's Application Class 7:15 to 7:30 - Publishing to the Market 7:30 to 8:00 - Q&A / Next Meetings 8:00 and Beyond - BEER

  3. Failblog Viewer Updates Enhancements Auto Sizing Images on Load Moving the Image and Pinch Zooming Code Hosted on Google Code http://fail-blog-rss-viewer.googlecode.com/svn/trunk/ If you want to be a committer get in touch with Matt or Bill This was based on the article: How to use Multi-touch in Android 2 by Ed Burnette http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2/1747?tag=content;siu-container Future Enhancements?

  4. Failblog Viewer Updates - Touch Overview The image is transformed with either a scale or translate based on the user interaction. The onTouch event actions: MotionEvent.ACTION_DOWN MotionEvent.ACTION_MOVE MotionEvent.ACTION_POINTER_DOWN Not Shown MotionEvent.ACTION_UP MotionEvent.ACTION_POINTER_UP

  5. Failblog Viewer Updates – Touch Code 1 The following variables are needed to move and resize the image: public class ViewerActivity extends BaseActivity implements OnTouchListener { Matrix matrix = new Matrix(); Matrix savedMatrix = new Matrix(); static final int NONE = 0; static final int DRAG = 1; static final int ZOOM = 2; private PointFstartingPoint = new PointF(); private PointFimageCenterPoint = new PointF(); private float pinchDistanceStart = 0; private int displayWidth = 0; private int displayHeight = 0; int mode = NONE;

  6. Failblog Viewer Updates – Touch Code 2 These helper methods are private float getTouchDistance(MotionEvent event) { float x = event.getX(0) - event.getX(1); float y = event.getY(0) - event.getY(1); return FloatMath.sqrt(x * x + y * y); } private void midPoint(PointF point, MotionEvent event) { float x = event.getX(0) + event.getX(1); float y = event.getY(0) + event.getY(1); point.set(x / 2, y / 2); }

  7. Failblog Viewer Updates – Touch Code 3 public booleanonTouch(View v, MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: // Second finger down pinchDistanceStart= getTouchDistance(event); if(pinchDistanceStart> 10f) { savedMatrix.set(matrix); midPoint(imageCenterPoint, event); mode = ZOOM; } break;

  8. Failblog Viewer Updates – Touch Code 4 case MotionEvent.ACTION_DOWN: // First finger touch savedMatrix.set(matrix); startingPoint.x= event.getX(); startingPoint.y= event.getY(); mode = DRAG; imageOverlay.clearAnimation(); imageOverlay.startAnimation(fadeOut); break; case MotionEvent.ACTION_UP: // All fingers up imageOverlay.clearAnimation(); imageOverlay.startAnimation(fadeOut); break; case MotionEvent.ACTION_POINTER_UP: mode = NONE; break;

  9. Failblog Viewer Updates – Touch Code 5 case MotionEvent.ACTION_MOVE: if (mode == DRAG) { matrix.set(savedMatrix); matrix.postTranslate(event.getX() - startingPoint.x, event.getY() - startingPoint.y); } else if (mode == ZOOM) { float pinchDistanceEnd = getTouchDistance(event); if (pinchDistanceStart > 10f) { matrix.set(savedMatrix); float scale = pinchDistanceEnd / pinchDistanceStart; matrix.postScale(scale, scale, imageCenterPoint.x, imageCenterPoint.y); } } break; } mainImage.setImageMatrix(matrix); return true; }

  10. Singleton vs. Android's Application Class Presentation by Bill Mote

  11. Publishing to the Market Register for a publisher account Create a certificate and private key Export using the Eclipse Export Android Application wizard Publish to the market Help http://developer.android.com/guide/publishing/publishing.html

  12. Publishing to the Market Register for a publisher account https://market.android.com/publish/ Create a certificate and private key keytool -genkey-alias cincyandroiduserstestkey -keyalg RSA -validity 20000 -keystorecerts/cincyandroiduserstest.keystore Export using the Eclipse Export Android Application wizard Right Click on the project -> Android Tools -> Export Signed Application Package Follow the wizard (select the project, enter the keystore, password and select the cert) Publish to the market Help http://developer.android.com/guide/publishing/publishing.html

  13. Q&A / Next Meetings Monthly Android Developers Presentation & Discussion Wednesday January 18, 2012 Social Coders Wednesday December 28, 2011 @ 6:15PM Buffalo Wild Wings Grill & Bar 11363 Montgomery Road, Cincinnati, OH

More Related