130 likes | 273 Views
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
E N D
Cincinnati Android Developers MeetupAndroid Touch Event &Singleton vs. Android's Application Class12/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 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
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?
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
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;
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); }
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;
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;
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; }
Singleton vs. Android's Application Class Presentation by Bill Mote
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
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
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