Sabtu, 19 April 2014

Detect Battery Info.

In the last exercise "Detect Battery Level", the app simple detect the battery level only. It's modified to have more info to be displayed, include: battery level, voltage, temperature, technology, charging status, and health of the battery.

Detect Battery Info.

main.xml

Get supported picture sizes of Android device's camera: getSupportedPictureSizes()

To read the info of supporte picture size of camera, the method getSupportedPictureSizes() can be used. It return a list of supported picture sizes. This method will always return a list with at least one element. 

List of Supported Picture Sizes

In order to access Camera, we have to modify AndroidManifest.xml to grant permission of Camera.

Detect touch and draw rect on bitmap

In last example "Detect touch and free draw on Bitmap", the points are drawn on the canvas (also the bitmap) directly when user touch.

Detect touch and draw rect on bitmap


In case of drawing square, the user touch on the screen to mark the start position, and move, and release on the end position. We have to keep displaying the updated square. But if we draw the rect on the canvasMaster, it will full of rect when user touch and move.

In this example, we create two overlay ImageViews, have same dimension. Also additional bitmap and canvas for the extra ImagewView. When ACTION_DOWN detected, we mark the starting position. When ACTION_MOVE, we draw rect on the extra canvasDrawingPane, not the canvasMaster. Such that we can clear and re-draw the canvas everytime. And finally when ACTION_UP, simple draw the extra bitmap on canvasMaster.

Display currency symbols

This example TRY to show various available currency symbols on Android. This symbols reference to the file http://www.unicode.org/charts/PDF/U20A0.pdf, it contains an excerpt from the character code tables and list of character names for The Unicode Standard, Version 6.3.

Please note that some symbols cannot be shown, because it have not been installed in Android system.


MainActivity.java

A simple example using Android's SQLite database, exposes data from Cursor to a ListView.

In previous exercise "A simple example using Android's SQLite database", the result of queue was presented as string. It's going to be modified to exposes data from Cursor to a ListView widget.

A simple example using Android's SQLite database, exposes data from Cursor to a ListView.

Modify SQLiteAdapter.java to include a column of "_id" in our database, also include it in the queue. Modify the return of queueAll() to Cursor. Refer to the article "column '_id' does not exist".

Step-by-step to create a simple Android App

The video show the steps to build a simple Android App using Android-ADT (Eclipse), in 7 minutes. In the app, clicking on the button to show a photo, and clicking on the photo to remove itself. In the end of the video show how it in working.

  • The app generated using the Project Wizard of Android SDK Tools 22.6.2, ActionBarActivity created with Fragment. So we have to modify fragment_main.xml for layout, and handle our ui elements in onCreateView() of PlaceholderFragment class.
  • The photo is stored inside the app /res/drawable/spiderman.jpg, its name must be in lowercase letter.

MainActivity.this vs getApplicationContext()

This example examine the behaviour between the contexts retrieved with MainActivity.this vs getApplicationContext(). The getApplicationContext() method return the context of the single, global Application object of the current process. This generally should only be used if you need a Context whose lifecycle is separate from the current context, that is tied to the lifetime of the process rather than the current component.

Shown in the following video, MainActivity.this will change when activity destroyed and re-created, getApplicationContext() will change when the application killed and re-started.