Posts

How to implement pinch and pan zoom on surface view ?

I spent lots of time to find the way, how to  implement zoom functionality on surface view, because in case of  image view you can implement it very easily by using matrix, but its implementation on surface view was not easy. I am going to share that particular code, may be it can helpful for anyone at anytime :). // AndroidSurfaceViewUI Activity  package com.example.zoom; import android.app.Activity; import android.os.Bundle; import android.view.ViewGroup; public class AndroidSurfaceViewUI extends Activity { ZoomView view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); view = new ZoomView(this); view.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); setContentView(view); } } // Surface View package com.example.zoom; import android.content.Context; import android.graphics.Bitmap; imp

Android InApp Billing / Payment

Image
Hi guys, To start with I'd like to say, this isn't the only way to do this. I myself have followed the developer tutorials on developer.android and managed to create this test project which I can now use as a reference when making other projects. Feel free to comment on the style and ask any questions. I would recommend you download the test project I have attached rather than copy and paste, this will stop minor syntax errors. Developer.Android Links: Google Billing Overview Google Billing Integration Going to try and walk you through creating an inapp payment method with the new android market payment system. This isn’t live yet (you can’t publish the app for general use) but you can upload it to the market and do full testing. Ok first the outline. Were going to create and app that has one button, when you click this button it informs the android market you want to make a purchase. On confirmation of this purchase you have bought a pic

Zooming and Dragging images using matrix in android

package com.zoom; import android.app.Activity; import android.graphics.Matrix; import android.graphics.PointF; import android.os.Bundle; import android.util.FloatMath; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; public class Touch extends Activity implements OnTouchListener {    private static final String TAG = "Touch";    // These matrices will be used to move and zoom image    Matrix matrix = new Matrix();    Matrix savedMatrix = new Matrix();    // We can be in one of these 3 states    static final int NONE = 0;    static final int DRAG = 1;    static final int ZOOM = 2;    int mode = NONE;    // Remember some things for zooming    PointF start = new PointF();    PointF mid = new PointF();    float oldDist = 1f;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);      

Android JSON Parsing with Gson Tutorial

Image
Apart from XML,  JSON  is a very common format used in API responses. Its simplicity has helped to gain quite the adoption in favor of the more verbose XML. Additionally, JSON can easily be combined with  REST  producing clear and easy to use APIs. Android includes support for JSON in its SDK as someone can find in the  JSON package summary . However, using those classes, a developer has to deal with low level JSON parsing, which in my opinion is tedious and boring. For this reason, in this tutorial, I am going to show you how to perform automatic JSON parsing. For this purpose we are going to use the  Google Gson  library. From the official site: Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of. There are a few open-source projects that can convert J