Posts Tagged ‘Java’

These posts contain code written in Java or are somehow related to Java.

Android: Bitmap to Integer array

Click here to read Android: Bitmap to Integer array

As stated in the title, this post explains how to generate an Integer pixel array from a Bitmap object, that will hold the color information from each pixel of the image. This post also explains the opposite: creating a Bitmap object from an Integer array. This can be useful when one needs to apply effects to Bitmap instances. As usual, an example Eclipse project is available for download at the end of this post. It works both on the emulator and on physical devices running Android 2.0.

So, let’s get to the code. Putting it in a simplified manner, the below Activity decodes a PNG image into a Bitmap object, then, an array is created with the same number of pixels as the image. After that, a method from the Bitmap instance puts the pixel color information in the array. (more…)

Android: obtaining SD card memory information

Click here to read Android: obtaining SD card memory information

This Android tutorial explains how to obtain the primary external storage (normally, the SD card) information, such as the total available space and how much memory it has left to be consumed by applications and data. Fortunately, this is a short and simple code, that can be used to create file explorer app, or to check if the SD card has enough space to copy data into the external storage. An example Eclipse project with the source code is available for download at the end of the post. It requires Android 2.1 (Eclair) and works both on a real and emulated devices.

In simple terms, the code below checks for a connected SD card, by querying its state. If a external device was found, it then obtains the external memory’s total and available sizes, returning the values in GB, MB, KB and bytes: (more…)

Android: Disabling anti-aliasing for pixel art

Click here to read Android: Disabling anti-aliasing for pixel art

Android is great when it comes to displaying scaled pictures in applications and games since it tries to interpolate the pixels, making the resulting image look as good as possible. That works for almost every case, however, what about pixel art? This behavior isn’t good for that because, after scaling it, the resulting image will be “smoothed out”, invalidating the handcrafted pixel placement.

There are two options in this case: use an image with the correct size and never scale it, or try to disable anything that could be aliasing the image. This post is going to describe how to do the latter. As usual, an example project is available for download at the end of the post. (more…)

Android: Transparent or Translucent View Background

Click here to read Android: Transparent or Translucent View Background

This Android post is going to explain how to change the background color of a View, to make it completely or partially transparent. It may seen a little strange at first, but sometimes it makes sense to create a translucent or transparent background, like when coding an application with multiple viewports, such as a graphic editing tool, for example. Luckily, Android has already some built-in features that aids the programmer in achieving total or partial transparency at any required level.

So, to create a fully transparent background, all that’s needed is to add the following line to the Manifest file: (more…)

Android: Detecting Double Tap Events

Click here to read Android: Detecting Double Tap Events

This Android tutorial explains how to create an Activity that “listens” to double tap events. Doing that isn’t as trivial as getting a single tap from the screen, however writing a code that registers when the screen has been touched twice isn’t complex either. The example featured in this post works on the emulator and on a real Android device.

To implement the double tap, some classes and interfaces are going to be needed, but it’s best to show the example Activity code before explaining each one of them: (more…)