Posts

Showing posts from July, 2011

Android - Matrix Pre, Post and Set methods

Matrix provide pre, post and set method for matrix transformation.
Pre and post are generally used to concatenate the existing Matrix value.
Set is used to overwrite the current matrix value with the existing ones.
But, please use Set method with care. It seems that Set methods will overwrite all the value in the 3x3 matrix. So, if you perform a postScale, then a setTranslate, the value set by postScale will be gone.
So, if you really want to set a translate with respect to x=0 and y=0, you can try the following
The following is trying to concat a scale, then perform a translation with respect to (0,0)
Matrix m = new Matrix(); //do a scale and post concat m.postScale(2.0f, 2.0f); //get the existing 3x3 matrix values float mVal[] new float[9]; m.getValues(mVal); // erase the current value before concat new value m.postTranslate(-mVal[Matrix.MTRANS_X], 0); m.postTranslate(100.0f, 0);

Android - Matrix

Android provides a very neat and nice way to perform image transformation. The class is Matrix.
http://developer.android.com/reference/android/graphics/Matrix.html#setTranslate(float, float)
For example, if you are at a ImageView, you could scale the underlying bitmap image by the following codes
public void scale(){ //define a new matrix Matrix m = new Matrix(); //double the scale m.postScale(2.0f, 2.0f); //set matrix to image setImageMatrix(m); }
By doing the above, the bitmap image will be scaled on next draw

Android - ImageButton transparent background

To create a transparent background for an ImageButton, you can put the following into the XML tag for the ImageButton
android:background="#00000000"

Android - SimpleOnGestureListener not receiving event

If you are creating SimpleOnGestureListener to capture double tab, single tab, etc... event and your extended class is not responding or capturing any event, the below information may help
Overriding onDown method
Make sure you override onDown(MotionEvent e) and return true
@Override public boolean onDown(MotionEvent e) { return true; }
By default, SimpleOnGestureListener onDown method return false. However, every touch event start at onDown. If this onDown method return false, the event will not propagate to other event method such as onDoubleTab and onSingleTabConfirmed. Therefore, those event method will not be trigger.

Android - Emulator DNS issue

Somehow, the Android emulator may use any network interface DNS server for resolving the address. It could be an issue if emulator use the wrong DNS server and cause address unresolved issue.
A few way could solve it
1. Controlling your emulator DNS
Use -dns-server X.X.X.X when you start up your emulator regardless from Eclipse or SDK Manager http://developer.android.com/guide/developing/tools/emulator.html

2. Disable interfaces
Disable any network interface that are not using and restart your PC.
3. Disable and reenable your network interface
This may help your emulator to update the DNS server list it is using.
4. Flush your system DNS cache
At cmd, type ipconfig /flushdns
5. Check your DNS setting at your network adaptor
By using Windows Resource Monitor, you can see what DNS server is your emulator using. Check the DNS server validity. If necessary, change the DNS server setting at your network adaptor. Make sure the valid DNS server is at the top of the DNS server list as the Emulator may …