Blog Feed: Android Coding

Blog Feed:

Already a Member? Log In to Your Account


Reduce bitmap by setting inSampleSize of BitmapFactory.Options

Published on 2012-05-25 04:51:00

if inSampleSize of BitmapFactory.Options set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory. The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels. Any value > read more

Unsharp Mask (USM) on Android Image Processing

Published on 2012-05-22 07:15:00

Read it first: Image processing on Android, the basic logic of Convolution Matrix. The Unsharp Mask filter sharpens edges of the elements without increasing noise or blemish. Refer to GIMP doc to know How does an unsharp mask work. As my understanding, for each pixel = original + (original - blur) In this code, I use the blured image from "Apply Blur effect on Android, using Convolution Matrix" to obtain the USM image. In order to make it obviously, I apply the effect three times. packag [..] > read more

Display image in full size

Published on 2012-05-22 06:26:00

In the former articles in Image processing on Android series, the image is displayed in shrinked version to suit the device's screen. It's modified display in scrollable true size. Modify the layout, main.xml, to embed the ImageViews inside nested HorizontalScrollView and ScrollView. Such that the ImageViews will be displayed in full-size and scrollable. > read more

Switch Activity once a marker on a MapView tapped

Published on 2012-05-21 02:52:00

This example continuously work on the article "Handle both onTap(GeoPoint p, MapView mapView) and onTap(int index) implemented in MapView": When a marker on the MapView tapped, it will switch to another Activity with some data passes; Title, Latitude and Longitude. Create a new Android project target with Google APIs. In order to use MapView on your app, you have to obtain your Map API Key, refer http://android-coding.blogspot.com/2011/06/mapview-and-maps-api-key.html The main layout, mai [..] > read more

Android image processing - Gaussian Blur

Published on 2012-05-19 00:49:00

Read it first: Image processing on Android, the basic logic of Convolution Matrix. In this example, the Sample Gaussian matrix from the article of Wikipedia - Gaussian blur is used as the 7 x 7 kernal to convolve image to apply Gaussian blur. package com.AndroidImageProcessing; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.view.View; impor [..] > read more

Android image processing - Edge Detect

Published on 2012-05-18 10:05:00

Read it first: Image processing on Android, the basic logic of Convolution Matrix. > read more

Android image processing - Edge Enhance

Published on 2012-05-17 22:22:00

Read it first: Image processing on Android, the basic logic of Convolution Matrix. It's example to perform edge enhance on Android. package com.AndroidImageProcessing; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.widget.ImageView; import android.widget.ProgressBar; public class AndroidImageProcessingActivity ext [..] > read more

Process image in background thread

Published on 2012-05-17 08:43:00

Last article "Sharpen image, using Convolution Matrix" perform image processing in main thread (or called UI Thread), system will not respond any other user action before the task finished - It not a good practice! If your activity take long time not responding, it will be killed by the system. It will be modified to be performed in background Runnable. Before the image process finished, a ProgressBar will be shown to indicate that it's running. AndroidImageProcessingActivity.java pack [..] > read more

Sharpen image, using Convolution Matrix

Published on 2012-05-16 13:33:00

Example to sharpen image, on Android using Convolution Matrix. Copy text picture in /res/drawable/ folder, name it testpicture.jpg. package com.AndroidImageProcessing; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle; import android.widget.ImageView; public class AndroidImageProcessingActivity extends Activity { final static int KERNAL_WIDTH = 3; final static int KERNAL_HEIGHT = [..] > read more

Apply Blur effect on Android, using Convolution Matrix

Published on 2012-05-15 02:56:00

Last article describe the basic logic of Convolution Matrix, it's used to apply Blur effect on Bitmap. - The Kernal used for blur is: {1, 1, 1 > read more

Image processing on Android, step-by-step

Published on 2012-05-13 03:48:00

At the beginning when I prepare the post "Create blur edge on bitmap, using BlurMaskFilter", I want to apply blur effect on bitmap actually. But I can't find any build-in API do so it! In the coming posts, I try to do it myself. I found a page in http://docs.gimp.org/en/plug-in-convmatrix.html, it explain Convolution Matrix very clear and easy understand. So my first step is to implement the Convolution Matrix according to the example. package com.AndroidImageProcessing; import android.ap [..] > read more

Example of EmbossMaskFilter

Published on 2012-05-11 14:44:00

EmbossMaskFilter(float[] direction, float ambient, float specular, float blurRadius) create an emboss maskfilter. direction: array of 3 scalars [x, y, z] specifying the direction of the light source ambient: 0...1 amount of ambient light specular: coefficient for specular highlights blurRadius: amount to blur before applying lighting package com.AndroidBitmapProcessing; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.gra [..] > read more

Create blur edge on bitmap, using BlurMaskFilter.

Published on 2012-05-10 13:25:00

The android.graphics.BlurMaskFilter class takes a mask, and blurs its edge by the specified radius. This example show how to make blur bitmap inner, and blur white outer edge. package com.AndroidBitmapProcessing; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BlurMaskFilter; import android.graphics.Canvas; import android.graphics.Paint; import android.os.Bundle; import android.view.View; import android.view.View.O [..] > read more

Adjust brightness of a bitmap

Published on 2012-05-09 20:06:00

To adjust brightness of a bitmap, simple change value of individual color components. Example: package com.AndroidBitmapProcessing; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; import android.os.Bundle; import android.view.View; import android.view.View.OnClick [..] > read more

Convert bitmap from color to GrayScale using ColorMatrixColorFilter

Published on 2012-05-07 11:12:00

Last article "Convert bitmap from color to GrayScale" by calculation. It's another approach using ColorMatrixColorFilter. ColorMatrix is a 5x4 matrix for transforming the color+alpha components of a Bitmap. The method setSaturation() set the matrix to affect the saturation of colors. A value of 0 maps the color to gray-scale. ColorMatrixColorFilter create a colorfilter that transforms colors through a 4x5 color matrix. In the sample code below, getGrayscale_ColorMatrixColorFilter() method [..] > read more

Convert bitmap from color to GrayScale

Published on 2012-05-06 10:02:00

Last article described how to Convert bitmap from color to black and white using the simple formula BW = (R + G +)/3. Some experts suggested that it should be 0.3R + 0.59G + 0.11B ~ refer http://en.wikipedia.org/wiki/Grayscale. Copy your test picture to /res/drawable folder, name it testpicture.jpg. package com.AndroidBitmapProcessing; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle [..] > read more

Convert bitmap from color to black and white

Published on 2012-05-06 08:43:00

In this example, the bitmap is converted from color to black and white by adding all three color of red, green and blue and dividing by 3. (The next article demonstrate how to Convert bitmap from color to GrayScale using 0.3R + 0.59G + 0.11B.) package com.AndroidBitmapProcessing; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle; import android.widget.ImageView; public class AndroidBi [..] > read more

Bitmap image processing, pixel by pixel.

Published on 2012-05-05 13:35:00

This example create a new bitmap from a existing bitmap with rotated color channel, Green->Blue, Red->Green, Blue->Red). package com.AndroidBitmapProcessing; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle; import android.widget.ImageView; public class AndroidBitmapProcessingActivity extends Activity { ImageView imageView_Source, imageView_Dest; Bitmap bitmap_Source, bitmap_Dest; [..] > read more

Save the captured canvas bitmap from custom View

Published on 2012-05-02 14:07:00

Last article demonstrated how to get the canvas bitmap of custom view. In this article, I will show how to save in file. Modify the openCaptureDialog() method in main activity(AndroidMyCanvasActivity.java) of last article to save the bitmap in jpg. It will be saved in root of sdcard, named test.jpg. package com.AndroidMyCanvas; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import androi [..] > read more

Get the canvas bitmap of custom View

Published on 2012-05-01 18:39:00

I have a series of previous articles to draw something on custom view's canvas. All these code lose everythng after the app exit. Now I want to save the drawing in a file. In this article, I will demonstrate how to get the canvas bitmap of custom view. In next article, I will show how to save in file. When user want to capture the canvas bitmap, touch MENU -> Capture Canvas. I don't know why I can't get the bitmap of the custom view by getDrawingCache() as shown in the article "Capture Scr [..] > read more

Detect TouchEvent on custom View to free draw path dynamically

Published on 2012-04-30 08:32:00

Override onTouchEvent() method of custom View, to create path dynamically. Create a new class MyView extends View, MyView.java. package com.AndroidMyCanvas; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; public class MyView extends View { boolean freeTouched = false; Path freePath; publ [..] > read more

Draw text along path

Published on 2012-04-29 13:09:00

To draw text along path, we can call Canvas.drawTextOnPath(text, path, hOffset, vOffset, paint). Example: Create a new class MyView extends View. Override the onDraw(Canvas canvas) method calling Canvas.drawTextOnPath() to draw text along path. package com.AndroidMyCanvas; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.util.AttributeSet; import android.view.View; pub [..] > read more

Draw rotated oval, canvas.drawOval + canvas.rotate

Published on 2012-04-16 16:05:00

Refer to last article Draw oval on canvas, canvas.drawOval(), we can draw oval vertically or horizontally. So, how can we draw a rotated oval? We can rotate the canvas before canvas.drawOval(), and rotate reversely after draw.Example:Create a new class MyView extends View. Override the onDraw(Canvas canvas) method to draw oval on Canvas.package com.AndroidMyCanvas;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import andr [..] > read more

Draw oval on canvas, canvas.drawOval()

Published on 2012-04-13 14:58:00

Create a new class MyView extends View. Override the onDraw(Canvas canvas) method to draw oval on Canvas.package com.AndroidMyCanvas;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.util.AttributeSet;import android.view.View;public class MyView extends View { public MyView(Context context) { super(context); } public MyView(Context context, AttributeSet attrs) { super(context, a [..] > read more

Detect Touch Event part IV - get touch area

Published on 2012-04-13 01:54:00

Previous article: Detect Touch Event part III - get touch pressure and sizeThe method getTouchMajor() and getTouchMinor() (getTouchMajor(int pointerIndex) and getTouchMinor(int pointerIndex) for multi-touch) of MotionEvent returns the length of the major and minor axis of an ellipse that describes the touch area.Example:package com.TestSingleTouch;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint; [..] > read more

Draw cubic bezier on path - cubicTo()

Published on 2012-04-12 14:31:00

cubicTo (float x1, float y1, float x2, float y2, float x3, float y3)Add a cubic bezier from the last point, approaching control points (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).Create a new class MyView extends View. Override the onDraw(Canvas canvas) method to draw a path with cubicTo().package com.AndroidMyCanvas;import android.content.Context;import android.graphics.Canvas;import android.graphi [..] > read more

Draw round-rect on canvas, drawRoundRect()

Published on 2012-04-11 08:40:00

drawRoundRect (RectF rect, float rx, float ry, Paint paint)Draw the specified round-rect using the specified paint. The roundrect will be filled or framed based on the Style in the paint.rect - The rectangular bounds of the roundRect to be drawnrx - The x-radius of the oval used to round the cornersry - The y-radius of the oval used to round the cornerspaint - The paint used to draw the roundRectCreate a new class MyView extends View. Override the onDraw(Canvas canvas) method to draw round-rect [..] > read more

Draw arc on canvas, canvas.drawArc()

Published on 2012-04-10 03:16:00

To drawa arc on canvas, call canvas.drawArc(): drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)where:oval - The bounds of oval used to define the shape and size of the arcstartAngle - Starting angle (in degrees) where the arc beginssweepAngle - Sweep angle (in degrees) measured clockwiseuseCenter - If true, include the center of the oval in the arc, and close it if it is being stroked. This will draw a wedgepaint - The paint used to draw the arcCreate a new [..] > read more

Draw circle on canvas, canvas.drawCirclet()

Published on 2012-04-08 04:13:00

Create a new class MyView extends View. Override the onDraw(Canvas canvas) method to draw circle on Canvas.package com.AndroidMyCanvas;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.util.AttributeSet;import android.view.View;public class MyView extends View { Paint paint; Path path; public MyView(Context context) { super(context); init(); } public MyView(Context context, Attr [..] > read more

Draw rectangle on canvas, canvas.drawRect()

Published on 2012-04-06 04:39:00

Create a new class MyView extends View. Override the onDraw(Canvas canvas) method to draw rectangle on Canvas.package com.AndroidMyCanvas;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.util.AttributeSet;import android.view.View;public class MyView extends View { Paint paint; Path path; public MyView(Context context) { super(context); init(); } public MyView(Context context, A [..] > read more

Draw on Canvas directly, in custom View.

Published on 2012-04-05 05:09:00

Create a new class MyView extends View, it's our custom View. Override the onDraw(Canvas canvas) method to draw on Canvas directly.package com.AndroidMyCanvas;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.util.AttributeSet;import android.view.View;public class MyView extends View { Paint paint; Path path; public MyView(Context context) { super(context); init(); } public MyVi [..] > read more

CountDownTimer

Published on 2012-03-28 11:58:00

The android.os.CountDownTimer class schedule a countdown until a time in the future, with regular notifications on intervals along the way.The Constructor CountDownTimer(long millisInFuture, long countDownInterval) call with the number of millis in the future from the call to start() until the countdown is done and onFinish() is called(millisInFuture) and The interval along the way to receive onTick(long) callbacks(countDownInterval).package com.CountDownTimer;import android.app.Activity;import [..] > read more

Unzip zip file using java.util.zip

Published on 2012-03-26 09:45:00

Example to unzip /mnt/sdcard/test/test.zip file to /mnt/sdcard/test/unzip/ folder.package com.AndroidUnZip;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.zip.ZipEntry;import java.util.zip.ZipInputStream;import android.app.Activity;import android.os.Bundle;import android.os.Environment;import android.widget.Toas [..] > read more

Gestures detection and canvas scale, translate and rotate.

Published on 2012-03-23 13:31:00

Further works on previous SurfaceView Game step-by-step: react device movement/orientation using accelerometer; in this article we are going to implement GestureOverlayView to detect gestures input, and apply scale, translate and rotate on canvas accordingly.- In order to make it simple, disable Sensor function, comment the myAccelerometer related code in MyGameActivity.java.- Create gestures of up/down/left/right, clockwise/anti-clockwise, enlarge/reduce, refer to the article Gestures Builder: [..] > read more

Touch to move Bitmap inside a custom View

Published on 2012-03-19 16:57:00

Refer to the article Detect Touch Event, test on Custom View. Modify to add a Bitmap in the custom view, if user touch the View over the bitmap, it will be moved accordingly.package com.TestSingleTouch;import android.app.Activity;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.os.Bundle;import android.view.MotionEvent;import android.view.Vi [..] > read more

Implement Horizontal ListView using android.widget.Gallery, with custom BaseAdapter.

Published on 2012-03-15 23:13:00

Refer to the article Implement a photo bar using android.widget.Gallery, with custom BaseAdapter, and custom object. It can be modify to implement a Horizontal ListView, like this:Modify the main java code to implement our custom BaseAdapter for Gallery.package com.AnHorizontalListView;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;impor [..] > read more

Dual VideoView to play 3gp from YouTube

Published on 2012-03-15 08:36:00

It's a simple example to include two VideoView in layout to play differnece 3gp from YouTube at the same time.Reference: A simple example using VideoView to play 3gp from YouTube.Main Layout: Main Code:package com.AnVideoView;import android.app.Activity;import android.net.Uri;import android.os.Bundle;import android.widget.MediaController;import android.widget.VideoView;public class AnVideoView extends Activity { String SrcPath = "rtsp://v5.cache1.c.youtube.com/CjYLENy [..] > read more

Create our Android Compass

Published on 2012-03-12 17:01:00

Base on last post "Detect Orientation using Accelerometer and Magnetic Field sensors", a Android compass is implemented here. In the implementation, the final result (base on Accelerometer and Magnetic Field sensors) is show in RED, point to the north.Create a custom View, Compass, extends View. The method update() is called from onSensorChanged() of main activity, with the updated direction.package com.AndroidDetOrientation;import android.content.Context;import android.graphics.Canvas;import an [..] > read more

Detect Orientation using Accelerometer and Magnetic Field sensors

Published on 2012-03-11 18:44:00

The post Detect Android device rotation, using Accelerometer sensor base on accelerometer only. It is another method to obtain it using both Accelerometer and Magnetic Field sensors together.Example:package com.AndroidDetOrientation;import android.app.Activity;import android.hardware.Sensor;import android.hardware.SensorEvent;import android.hardware.SensorEventListener;import android.hardware.SensorManager;import android.os.Bundle;import android.widget.TextView;public class AndroidDetOrientation [..] > read more

SurfaceView Game step-by-step: react device movement/orientation using accelerometer

Published on 2012-03-07 07:52:00

With the help of accelerometer on Android device(Get detail info of Accelerometer), we can react device movement/orientation for our SurfaceView Game(Implement onTouchEvent() to handle user touch on SurfaceView). After finished, the the Sprite will move once user move the device.Implement new class - MyAccelerometer.java.package com.MyGame;import android.content.Context;import android.hardware.Sensor;import android.hardware.SensorEvent;import android.hardware.SensorEventListener;import android.h [..] > read more

Get detail info of Accelerometer

Published on 2012-03-05 11:55:00

package com.exercise.AndroidAccelerometer;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;import android.hardware.Sensor;import android.hardware.SensorEvent;import android.hardware.SensorEventListener;import android.hardware.SensorManager;public class AndroidAccelerometerActivity extends Activity implements SensorEventListener{ private SensorManager sensorManager; private Sensor sensorAccelerometer; TextView readingAzimuth, readingPitch, readingRoll; /* [..] > read more

Detect Android device rotation, using Accelerometer sensor

Published on 2012-02-27 11:24:00

package com.AndroidRotation;import android.app.Activity;import android.hardware.Sensor;import android.hardware.SensorEvent;import android.hardware.SensorEventListener;import android.hardware.SensorManager;import android.os.Bundle;import android.widget.TextView;public class AndroidRotationActivity extends Activity implements SensorEventListener{ private SensorManager manager; private Sensor sensor; TextView azimuth, pitch, roll; /** Called when the activity is first created. */ @Override pu [..] > read more

Implement onTouchEvent() to handle user touch on SurfaceView

Published on 2012-02-15 17:14:00

Modify from last article Sprite auto-run, implement onTouchEvent() to handle user touch on SurfaceView. When user touch on the screen(SurfaceView), it will call setX(x) and setY(y) of mySprite object to update its position.package com.MyGame;import android.content.Context;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.PorterDuff.Mode;import android.util.AttributeSet;import android.view.MotionEvent;public class MyForegrou [..] > read more

Sprite auto-run

Published on 2012-02-12 10:33:00

In last article Introduce Sprite without movement. In this article, we are going to make it self move.Modify Sprite.java to make it self random move inside the canvas.package com.MyGame;import java.util.Random;import android.graphics.Bitmap;import android.graphics.Canvas;public class Sprite { private Bitmap bitmap; private int x; private int y; float bitmap_halfWidth, bitmap_halfHeight; Random random = new Random(); private int dirX; private int dirY; private int moveX; private int moveY; fina [..] > read more

Introduce Sprite

Published on 2012-02-09 15:02:00

Base on last post Create transparent foreground SurfaceView, the object on foreground was draw as a bitmap. We are going to implement a Sprite class here. Sprite object keep it's own status such as location(x, y) and bitmap, and also draw itself on canvas.Add class Sprite.javapackage com.MyGame;import android.graphics.Bitmap;import android.graphics.Canvas;public class Sprite {private Bitmap bitmap;private int x;private int y;float bitmap_halfWidth, bitmap_halfHeight;public Sprite(Bitmap bm, int [..] > read more

Create transparent foreground SurfaceView

Published on 2012-01-28 13:08:00

Start reading here: Create a SurfaceView Game step-by-stepIn previoud posts, we have created a custom SurfaceView(MyGameSurfaceView.java) with background thread. Now we are going to create another MyForeground class by extending our MyGameSurfaceView, with overriding code. Base on the existing MyGameSurfaceView class, it's easy to implement the new MyForeground class.- Create a new class: Right click to select our package (com.MyGame) in Package Explorer, select File -> New -> Class in Eclipse M [..] > read more

Flickering problems due to double buffer of SurfaceView

Published on 2012-01-25 15:21:00

If you try the code in last post Link SurfaceView and Background Thread work together, you can note that the screen seem to flicker between two bitmap! It's due to double buffer of Android's SurfaceView: When you draw on Buffer A, Buffer B is being displayed; then you draw on Buffer B, Buffer A is being displayed. Such that you draw random points on Buffer A and B alternatively, not a single bitmap. This feature can solve some problem of display performance - but not in our case.In order to solv [..] > read more

Link SurfaceView and Background Thread work together

Published on 2012-01-24 15:28:00

In previous posts "Create SurfaceView for our game" and "Implement background thread for our game", we have created DUMMY MyGameSurfaceView and MyGameThread classes, without any function, and without any interaction. In this step, we are going to modify the Java code to make them work together.Modify main.xml to include MyGameSurfaceView in the layout. Modify the main activity (MyGameActivity), call myGameSurfaceView1.MyGameSurfaceView_OnResume() in onResume() and call myGameSurfaceView1.MyGame [..] > read more

Implement background thread for our game

Published on 2012-01-21 14:59:00

Start reading here: Create a SurfaceView Game step-by-step- Click to select our package (com.MyGame) in Package Explorer. Then click File of Eclipse, -> New -> Class- Enter "MyGameThread" in the Name field, then click Browse... to select Superclass.- Enter Thread in the search box to choice Thread - java.lang, then click OK.- Then click Finish in the New Java Class dialog.- In the Edit Windows (with MyGameThread.java), right click on any blank space, select Source -> Override/Implement Methods.. [..] > read more

Create SurfaceView for our game

Published on 2012-01-15 09:57:00

Start reading here: Create a SurfaceView Game step-by-stepIn this step, we are going to create our dummy SurfaceView:- Click to select our package (com.MyGame) in Package Explorer. Then click File of Eclipse, -> New -> Class- Enter "MyGameSurfaceView" in the Name field, then click Browse... to select Superclass.- Enter SurfaceView in the search box to choice SurfaceView - android.view, then click OK.- Then click Finish in the New Java Class dialog.- A new class of MyGameSurfaceView.java extends [..] > read more

Create a SurfaceView Game step-by-step

Published on 2012-01-12 01:52:00

In the coming posts, I will TRY to create a basic game, a VERY BASIC GAME: base on SurfaceView implements SurfaceHolder, display something as Sprites, running in backgroud Thread.New a project MyGame of package com.MyGame, target Android 2.2, API Level 8.Prepare my characterCreating graph is my weakest. As a example, I decide to copy my character from Android build-in icon.- Create a /res/drawable folder.- Open a file explorer and browse to any Android build-in platform drawable folder (ex. /and [..] > read more

Create custom Theme inheriting properties from build-in Theme

Published on 2012-01-03 12:25:00

Refer from the previous posts:- Create style using Android Resources Tools- Create style inheriting properties from another style- Apply style on whole application/activity as theme- Using Android build-in themeWe can create our custom Theme, by inheriting properties from build-in Theme.Create(or modify from previous post) /res/values/mystyle.xml, create our custom style (MyStyle) from build-in "@android:style/Theme.Dialog". wrap_content wrap_content #AAA 18dip # [..] > read more

HttpClient and HttpGet

Published on 2011-07-04 11:43:00

org.apache.http.client.HttpClient is a Interface class for an HTTP client. HTTP clients encapsulate a smorgasbord of objects required to execute HTTP requests.org.apache.http.client.methods.HttpGet provide HTTP GET method.A simple example:package com > read more

Set RelativeLayout.ALIGN_PARENT_TOP/RelativeLayout.ALIGN_PARENT_BOTTOM using Java code

Published on 2011-06-23 11:04:00

Example to set RelativeLayout.ALIGN_PARENT_TOP/RelativeLayout.ALIGN_PARENT_BOTTOM, using Java code, by calling addRule() of RelativeLayout.LayoutParams. To re-locate views in run-time.Example:package com.AndroidAlignParent;import android.app.Activity > read more

Detect Touch Event part III - get touch pressure and size

Published on 2011-06-21 09:47:00

The MotionEvent object retured with pressure and size of touching. It can be get using getPressure() and getSize() method. The code in last post "Detect Touch Event, test on Custom View; part II" is further modified to show touching pressure and size > read more

Detect Touch Event, test on Custom View; part II.

Published on 2011-06-21 08:56:00

Following the former post "Detect Touch Event, test on Custom View". In order to trace the trigged MotionEvent in onTouchEvent(), it's modified to have a TextView to display the event.package com.TestSingleTouch;import android.app.Activity;import and > read more

Easy drawing current location and compass on the MapView, using MyLocationOverlay.

Published on 2011-06-19 03:23:00

com.google.android.maps provide a usefull class MyLocationOverlay to draw current location (and also compass) on the Map.To use MyLocationOverlay is simply:add a object of MyLocationOverlay in your mapView Overlayscall enableMyLocation() and/or enabl > read more

Using ItemizedOverlay to add marker on MapView

Published on 2011-06-17 12:39:00

Reference last exercise MapView and MapActivity, we are going to add overlay of ItemizedOverlay, to add marker on our MapView.The main.xml and AndroidManifest.xml are kept as in last post MapView and MapActivity.Add a new class MyItemizedOverlay.java > read more

MapView and MapActivity

Published on 2011-06-17 06:03:00

Using the Google Maps library, you can create your own map-viewing Activity.By default the Android SDK includes the Google APIs add-on, which in turn includes the Maps external library. The Google APIs add-on requires Android 1.5 SDK or later release > read more

MapView and Maps API Key

Published on 2011-06-16 14:45:00

The MapView class in the Maps external library is a very useful class that lets you easily integrate Google Maps into your application. It provides built-in map downloading, rendering, and caching of Maps tiles, as well as a variety of display option > read more

Display a icon/image on button using Java code

Published on 2011-06-16 04:52:00

The method setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' b > read more

Ready image file using build-in Gallery, with Intent.ACTION_PICK

Published on 2011-06-15 11:53:00

We can start a activity with Intent.ACTION_PICK, to start Android build-in Gallery app to select image. Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);startActivityForResult(intent, RQS_G > read more

Reduce Bitmap size using BitmapFactory.Options.inSampleSize

Published on 2011-06-14 06:01:00

In the post "Load ImageView with JPG file in SD Card", the ImageView is loaded with bitmap in full-size. It cost too much resources for a mobile device, and easy to make the app closed unexpectly.We can generate a shrinked bitmap using BitmapFactory. > read more

Load ImageView with JPG file in SD Card

Published on 2011-06-13 08:09:00

android.graphics.BitmapFactory class provide a method decodeFile(String pathName) to decode a file path into a bitmap. The decoded bitmap can be loaded to ImageView using setImageBitmap() method of the ImageView.package com.AndroidLoadImageView;impor > read more

Pick contact using intent of Intent.ACTION_PICK, with People.CONTENT_URI

Published on 2011-06-09 11:28:00

It's a example to pick from system contact, using intent of Intent.ACTION_PICK, with People.CONTENT_URI. And show how to retrieve the contact in onActivityResult(), using Cursor.package com.AndroidPickContact;import android.app.Activity;import androi > read more

Android Coding@mobile

Published on 2011-06-08 04:09:00

Blogger introduce mobile version recently. Please check my mobile version: http://android-coding.blogspot.com/?m=1 > read more

Settings.ACTION_LOCATION_SOURCE_SETTINGS vs. Settings.ACTION_SECURITY_SETTINGS

Published on 2011-06-08 03:05:00

As described in my old post, we can "Start Location setting if GPS disabled" by start activity with intent of "Settings.ACTION_SECURITY_SETTINGS".Thanks for Brian comments:It is better to use Settings.ACTION_LOCATION_SOURCE_SETTINGS instead of Settin > read more

Get neighboring cell information, getNeighboringCellInfo().

Published on 2011-06-07 15:15:00

TelephonyManager.getNeighboringCellInfo() return a List of neighboring cell information(NeighboringCellInfo), including Received Signal Strength and Cell ID location.package com.AndroidTelephonyManager;import java.util.List;import org.apache.http.Htt > read more

Start Google Maps using intent of ACTION_VIEW, with zoom level.

Published on 2011-06-07 02:44:00

To start Google Maps using intent of ACTION_VIEW with zoom level, you can use with the Uri:geo:Latitude,Longitude?z=Modify the main.xml in last post "Start Google Maps using intent of ACTION_VIEW", include a SeekBar for user to set > read more

Start Google Maps using intent of ACTION_VIEW

Published on 2011-06-06 15:15:00

To start Android geo viewer, Google Maps, we can start activity with intent "android.content.Intent.ACTION_VIEW", with Uri of "geo:latitude,longitude".Modify last post "Get location of Cell ID, from opencellid.org using HttpGet()", start Google Maps > read more

Get location of Cell ID, from opencellid.org using HttpGet().

Published on 2011-06-06 04:25:00

A class OpenCellID was created to handle the http communication with opencellid.org. To simplify the job, request with "fmt=txt" is sent, such that we can simply splite the result to retrieve our latitude, longitude.To know more about the project Ope > read more

OpenCellID

Published on 2011-06-05 10:49:00

We can get our approximate location using TelephonyManager to get our phone connected Network Operator (MCC+MNC), cell id and location area code.Refer to:- Get Network info using TelephonyManager- Get cell location on a GSM phone, getCellLocation()La > read more

Convert cellLocation to real location (Latitude and Longitude)

Published on 2011-06-04 13:54:00

The post "Get cell location on a GSM phone, getCellLocation()" get cell id and location area code. It's not a useful info with converted to real location."http://www.google.com/glm/mmap" is a non-public API to convert cellLocation to latitude and lon > read more

Get cell location on a GSM phone, getCellLocation()

Published on 2011-06-04 08:59:00

TelephonyManager.getCellLocation() return the current location of the device.We need the following permission in this example:android.permission.ACCESS_COARSE_LOCATIONandroid.permission.ACCESS_FINE_LOCATIONandroid.permission.READ_PHONE_STATEpackage c > read more

Get Network info using TelephonyManager

Published on 2011-06-03 04:29:00

Using TelephonyManager, we can get cell phone network info; such as Network Operator (MCC+MNC), Network Operator Name, Network Type, Network Country Iso.Permission READ_PHONE_STATE is required.package com.AndroidTelephonyManager;import android.app.Ac > read more

Get unique device ID (IMEI, MEID or ESN) of Android phones.

Published on 2011-06-02 14:32:00

The method getDeviceId() of TelephonyManager returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones. Return null if device ID is not available. Permission READ_PHONE_STATE is required.package com.AndroidTeleph > read more

Get phone type using android.telephony.TelephonyManager

Published on 2011-06-02 04:04:00

android.telephony.TelephonyManager is a class providing access to information about the telephony services on the device. Applications can use the methods in this class to determine telephony services and states, as well as to access some types of su > read more

Create custom dialog using AlertDialog.Builder, with dynamic content

Published on 2011-05-29 06:13:00

This example have the almost same output in the previous post "Create custom dialog with dynamic content, updated in onPrepareDialog()". The difference is it create dialog using AlertDialog.Builder, instead of in onCreateDialog() and onPrepareDialog( > read more

Create custom dialog with dynamic content, updated in onPrepareDialog()

Published on 2011-05-27 03:23:00

In the post "Create custom dialog with EditText", the dialog is created in onCreateDialog(). Please notice that the call-back function onCreateDialog() will be called when a dialog is requested for the first time, such that the content defined in onC > read more

Capture Screen, using View.getDrawingCache()

Published on 2011-05-26 08:38:00

To capture screen, such as in a view, we can use the following code: View screen = (View)findViewById(R.id.screen); screen.setDrawingCacheEnabled(true); Bitmap bmScreen = screen.getDrawingCache();where screen is the view, to be captured. > read more

Create Options Menu with SurfaceView

Published on 2011-05-25 11:27:00

To create Options Menu on SurfaceView, simple override onCreateOptionsMenu() to add menu options, and override onOptionsItemSelected() to handle the event.package com.TestSurefaceView;import android.app.Activity;import android.content.Context;import > read more

Detect multi-touch, on SurfaceView

Published on 2011-05-24 09:36:00

Override onTouchEvent() in SurfaceView to handle mlti-touch.package com.TestSurefaceView;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import andr > read more

Change background color using Java code, setBackgroundColor()

Published on 2011-05-22 06:44:00

package com.AndroidBackgroundColor;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.SeekBar;public class AndroidBackgroundColor extends Activity { SeekBar seekRed, seekGreen, seekBlue, seekAlpha; Vi > read more

Change Text color using setTextColor()

Published on 2011-05-21 13:12:00

package com.exercise.AndroidTextColor;import android.app.Activity;import android.os.Bundle;import android.widget.SeekBar;import android.widget.TextView;public class AndroidTextColor extends Activity { SeekBar seekRed, seekGreen, seekBlue, seekAlpha; > read more

Hide and unhide a view

Published on 2011-05-20 12:53:00

package com.AndroidHideView;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Spinner;import android.widget.TextView;public class A > read more

Change TextSize in run-time

Published on 2011-05-20 01:24:00

package com.AndroidTextSize;import android.app.Activity;import android.os.Bundle;import android.util.TypedValue;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Spinner;import android > read more

Change typeface and style programmatically using Java Code

Published on 2011-05-19 12:07:00

To change typeface and style of TextView, use the code:textview.setTypeface(typeface, style);where typeface can be:Typeface.DEFAULTTypeface.DEFAULT_BOLDTypeface.MONOSPACETypeface.SANS_SERIFTypeface.SERIFstyle can be:Typeface.BOLDTypeface.BOLD_ITALICT > read more

Resize Button programmatically using Java Code

Published on 2011-05-18 14:46:00

Buttons can be resized by changing and update LayoutParams.width and LayoutParams.height. Notice that the width and height return from Button.getWidth() and Button.getHeight() will not reflect the updated size at once. You can click the "Check my siz > read more

Get size (width, height) of a View

Published on 2011-05-18 04:43:00

This example show how to read size of a view (Button in this example), using getWidth(), getHeight().Be aware not to call getWidth() or getHeight() too early before the view have been laid out on the screen, otherwise "0" will be returned.package com > read more

Detect "natural" orientation of screen, using Display.getRotation()

Published on 2011-05-16 04:16:00

package com.AndroidOrientation;import android.app.Activity;import android.content.Context;import android.hardware.SensorManager;import android.os.Bundle;import android.view.Display;import android.view.OrientationEventListener;import android.view.Surf > read more

Voice recognizer + Text to speech

Published on 2011-05-12 02:42:00

Merge last two post; Start Android system's voice recognizer using Intent & Implement Android's Text to speech function.Onec the recognized result selected, it will be speeched using TTS.package com.AndroidRecognizer;import java.util.ArrayList;im > read more

Start Android system's voice recognizer using Intent

Published on 2011-05-11 05:00:00

package com.AndroidRecognizer;import java.util.ArrayList;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.speech.RecognizerIntent;import android.view.View;import android.widget.ArrayAdapter;import andr > read more

Implement Android's Text to speech function

Published on 2011-05-10 11:54:00

package com.AndroidTTS;import android.app.Activity;import android.os.Bundle;import android.speech.tts.TextToSpeech;import android.speech.tts.TextToSpeech.OnInitListener;import android.view.View;import android.widget.Button;import android.widget.EditT > read more

Make you App looked like a Dialog

Published on 2011-05-09 04:47:00

To make your app looked like a dialog, you can use the Android pre-defined Theme.Dialog.Modify AndroidManifest.xml, to add the code inside android:theme="@android:style/Theme.Dialog"example: > read more

Set background of your app to be transparent

Published on 2011-05-08 06:12:00

To set background of your app to be transparent, you can use Android pre-defined Theme.Translucent.Modify AndroidManifest.xml, to add the code inside android:theme="@android:style/Theme.Translucent"example: > read more

Handle onTouchEvent in SurfaceView

Published on 2011-05-06 03:08:00

Here Override onTouchEvent() in SurfaceView to handle user touch event.package com.TestSurefaceView;import java.util.Random;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import > read more

Drawing on SurfaceView

Published on 2011-05-05 10:58:00

Last post introduce "A basic implementation of SurfaceView". To draw something on the SurfaceView, place the codes in-between surfaceHolder.lockCanvas() and surfaceHolder.unlockCanvasAndPost(canvas).package com.TestSurefaceView;import java.util.Rando > read more

A basic implementation of SurfaceView

Published on 2011-05-04 10:38:00

SurfaceView provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen.Acces > read more

Detect Multi-Touch Event, test on Custom View

Published on 2011-05-01 09:00:00

package com.TestMultiTouch;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.os.Bundle;import android.view.MotionEvent;import android.v > read more

Detect Multi-Touch Event

Published on 2011-04-30 08:21:00

It's a testing app for multi-touch event, target API level 8, Android 2.2. In my test on Nexus One running 2.2.1, only two points can be recognized.package com.TestMultiTouch;import android.app.Activity;import android.os.Bundle;import android.view.Mo > read more

Detect Touch Event, test on Custom View

Published on 2011-04-29 11:02:00

package com.TestSingleTouch;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.os.Bundle;import android.view.MotionEvent;import android. > read more

Detect Touch Event

Published on 2011-04-28 13:11:00

package com.TestSingleTouch;import android.app.Activity;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.widget.LinearLayout;import android.widget.TextView;public class TestSingleTouch extends Activity > read more

Set EditText horizontally scrollable

Published on 2011-04-27 12:55:00

It can be define in XML using the statement: android:scrollHorizontally="true"or using Java code: setHorizontallyScrolling(true); > read more

Create custom dialog with EditText

Published on 2011-04-25 15:03:00

Create a XML in /res/layout/ folder to define the layout of the custom dialog.eg. customlayout.xml > read more

Create Dialog with options, using AlertDialog.Builder

Published on 2011-04-25 06:48:00

package com.AndroidAlertDialog;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.Toast;public class A > read more

TimePickerDialog - how to set 24 hour view, or AM/PM.

Published on 2011-04-25 03:38:00

TimePickerDialog is a dialog that prompts the user for the time of day using a TimePicker. Refer the post "TimePickerDialog" for working example.TimePickerDialog provide two Constructors:TimePickerDialog(Context context, TimePickerDialog.OnTimeSetLis > read more

AutoCompleteTextView

Published on 2011-04-23 11:42:00

AutoCompleteTextView is an editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit > read more

Load Array from XML Resources

Published on 2011-04-22 12:02:00

To load array contents from XML resources: String[] month = getResources().getStringArray(R.array.xxx);where xxx is the name of the array.Here is a example of ListActivity, using ArrayAdapter with array contents loaded from XML resource > read more

ViewFlipper with Animation

Published on 2011-04-15 15:52:00

ViewFlipper is a simple ViewAnimator that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval.create four XML file for the > read more

Example to implement SlidingDrawer in XML

Published on 2011-04-14 13:42:00

SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen. > read more

getExternalStoragePublicDirectory(String type): Get a top-level public external storage directory for particular type

Published on 2011-04-13 13:33:00

Start from API Level 8 (Android 2.2), android.os.Environment class provide getExternalStoragePublicDirectory(String type) method, to get a top-level public external storage directory for placing files of a particular type. This is where the user will > read more

Detect GPS ON/OFF status using android.provider.Settings.Secure

Published on 2011-04-12 15:41:00

android.provider.Settings.Secure is secure system settings, containing system preferences that applications can read but are not allowed to write. These are for preferences that the user must explicitly modify through the system UI or specialized API > read more

How to set orientation of activity/application in AndroidManifest.xml

Published on 2011-04-08 03:47:00

To set orientation in AndroidManifest.xml, add the following code under or . android:screenOrientation="landscape"Related: Change the desired orientation of activity: setRequestedOrientation() > read more

How to send SMS using android.telephony.SmsManager

Published on 2011-04-05 14:05:00

android.telephony.SmsManager manages SMS operations such as sending data, text, and pdu SMS messages. Get this object by calling the static method SmsManager.getDefault(). It supports both GSM and CDMA; please don't mix up with deprecated android.tel > read more

Get ANDROID_ID

Published on 2011-04-04 12:15:00

ANDROID_ID is 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain constant for the lifetime of the device. (The value may change if a factory reset is performed on the device.) String Id = Settings. > read more

Check and Gets the Android external storage directory

Published on 2011-04-03 12:28:00

The class android.os.Environment provides access to environment variables.The method getExternalStorageDirectory() can be used to get the Android external storage directory. This directory may not currently be accessible if it has been mounted by the > read more

How to get application context

Published on 2011-04-01 09:16:00

To get the context, the method Context.getApplicationContext() or Activity.getApplication() can be used. textContext1.setText("using getApplicationContext():n" + getApplicationContext()); textContext2.setText("using getApplicat > read more

Detect Key action

Published on 2011-03-30 15:49:00

To detect key action of Android device from user, you can override the methods onKeyDown() and onKeyUp().Example:package com.AndroidKey;import android.app.Activity;import android.os.Bundle;import android.view.KeyEvent;import android.widget.Toast;publ > read more

Pass data from activity to service

Published on 2011-03-29 15:22:00

In activity: Intent myIntent = new Intent(MainActivity.this, MyService.class); Bundle bundle = new Bundle(); bundle.putCharSequence("extraData", data); myIntent.putExtras(bundle); pendingIntent = PendingIntent.getService(MainActivity.this, 0, > read more

Pass data between activity

Published on 2011-03-27 06:45:00

When start a new activity in our main activity using startActivity(), data can be passed using Bundle.Inside the main activity, MainActivity.java Intent intent = new Intent(); intent.setClass(MainActivity.this, NewActivity.class) > read more

Send email by startActivity with Intent.ACTION_SEND

Published on 2011-03-23 14:17:00

Here is a example by calling startActivity() with Intent.ACTION_SEND. Android OS will start a app Chooser suitable for "plain/text" email sending. String emailList[] = {emailAddress1, emailAddress2, ...}; Intent intent = new Intent(Intent.A > read more

Send SMS by startActivity with Intent.ACTION_SENDTO

Published on 2011-03-22 08:31:00

Here is a example by calling startActivity() with Intent.ACTION_SENDTO. Android default SMS app will be started to send SMS with pre-defined text and number. remark: change "xxxxxxxx" to the number of the phone to receive SMS. Uri uri = Uri.pa > read more

Using VideoView to play mp4 from sdcard

Published on 2011-03-18 07:38:00

First of all, download/save a mp4 file in SD Card of the Android device, eg: "/sdcard/Video/Android in Spaaaaaace!_low.mp4". > read more

A simple example using VideoView to play 3gp from YouTube

Published on 2011-03-17 07:38:00

main.xml > read more

An example of RelativeLayout

Published on 2011-03-12 07:31:00

An example of XML using RelativeLayout, two buttons are placed on both left and right, and the last button is placed on the center position. > read more

Start Location setting if GPS disabled

Published on 2011-03-04 12:27:00

The following code can be used to start Location setting: Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);startActivity(intent);This example will start Location setting if GPS is curently disabled: String GpsProvider = Settings.S > read more

How to check if GPS is currently enabled or disabled

Published on 2011-03-03 16:00:00

Using the method Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED), we can get the allowed location provider, GPS. To check if GPS is currently enabled or disabled, using the code: String GpsProvider = > read more

Final Android 3.0 Platform and Updated SDK Tools

Published on 2011-02-26 15:22:00

We are pleased to announce that the full SDK for Android 3.0 is now available to developers. The APIs are final, and you can now develop apps targeting this new platform and publish them to Android Market. The new API level is 11.For an overview o > read more

Detect Android Wifi State

Published on 2011-02-25 11:15:00

int WifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE , WifiManager.WIFI_STATE_UNKNOWN);The returned value can be:WIFI_STATE_DISABLEDWIFI_STATE_DISABLINGWIFI_STATE_ENABLEDWIFI_STATE_ENABLINGWIFI_STATE_UNKNOWN > read more

Turn Android Wifi On/Off

Published on 2011-02-24 11:56:00

To turn Wifi ON: WifiManager wifiManager = (WifiManager)getBaseContext().getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true);To turn Wifi OFF: WifiManager wifiManager = (WifiManager)getBaseContext().getSystemService(Cont > read more

SimpleDateFormat

Published on 2011-02-22 13:03:00

Usage of SimpleDateFormat: SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy hh:mm:ss a"); String now = formatter.format(new Date()); > read more

Change Screen Brightness

Published on 2011-02-21 14:15:00

To change screen brightness:WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.buttonBrightness = value; getWindow().setAttributes(layoutParams);where value is float between 0 to 1, value of less than 0 to use t > read more

Change the desired orientation of activity: setRequestedOrientation()

Published on 2011-02-20 13:21:00

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);public void setRequestedOrientation(int requestedOrientation) is used to change the desired orientation of this activity. If the activity is currently in the foreground or otherwise im > read more

InputFilter

Published on 2011-02-19 13:47:00

InputFilters can be attached to Editables to constrain the changes that can be made to them. ex. EditText edit = (EditText)findViewById(R.id.edit); InputFilter[] FilterArray = new InputFilter[2]; FilterArray[0] = new InputFilter. > read more

Toast with image

Published on 2011-02-18 12:05:00

It's a sample code to display Toast with image.package com.AndroidImageToast;import android.app.Activity;import android.os.Bundle;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TextView;import android.widget. > read more

Using inputType="textPassword" to format EditText as password

Published on 2011-02-17 14:39:00

> read more

ImageButton

Published on 2011-02-16 07:22:00

ImageButton displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button, with the standard button background that changes color during different button states. T > read more



© 2006-2012 OnToplist.com, All Rights Reserved