Android Development Tools 0.9.6 is out

Android Development Tools (ADT) is a plugin for the Eclipse IDE that is designed to give you a powerful, integrated environment in which to build Android applications.
New version 0.9.6 is available for download/update.

What’s new:

Dependencies

  • ADT 0.9.6 is designed for use with SDK Tools r5 and later. Before updating to ADT 0.9.6, we highly recommend that you use the Android SDK and AVD Manager to install SDK Tools r5 into your SDK

General Notes

  • Editing default.properties outside of Eclipse will now automatically update the project
  • Loads the SDK content only when a project requires it. This will make Eclipse use less resources when the SDK contains many versions of Android
  • Resolves potential deadlock between modal dialogs, when launching ADT the first time with the SDK Usage panel
  • Fixes issues with the New Project Wizard when selecting samples

AVD/SDK Manager

  • Adds support for platform samples components
  • Improves support for dependency between components
  • AVDs now sorted by API level
  • The AVD creation dialog now enforces a minimum SD card size of 9MB
  • Prevents deletion of running AVDs

DDMS

  • DDMS plug-in now contains the Allocation Tracker view
  • New action in the Logcat view: “Go to problem” lets you go directly from an exception trace output to the code

Editors

  • Explode mode in the Visual Layout Editor adds a margin to all layout objects so that it’s easier to see embedded or empty layouts
  • Outline mode in the Visual Layout Editor draws layout outline to make it easier to see layout objects
  • Several fixes in the configuration selector of the Visual Layout Editor

Application launching

  • Applications launched from ADT now behave as if they were clicked from the Home screen.
  • Fixes issue where add-on with no optional library would not show up as valid targets for application launches.
  • Resolves possible crash when launching applications.
Dependencies:
ADT 0.9.6 is designed for use with SDK Tools r5 and later. Before updating to ADT 0.9.6, we highly recommend that you use the Android SDK and AVD Manager to install SDK Tools r5 into your SDK.

General Notes:
  • Editing default.properties outside of Eclipse will now automatically update the project.
  • Loads the SDK content only when a project requires it. This will make Eclipse use less resources when the SDK contains many versions of Android.
  • Resolves potential deadlock between modal dialogs, when launching ADT the first time with the SDK Usage panel.
  • Fixes issues with the New Project Wizard when selecting samples.
AVD/SDK Manager:
  • Adds support for platform samples components.
  • Improves support for dependency between components.
  • AVDs now sorted by API level.
  • The AVD creation dialog now enforces a minimum SD card size of 9MB.
  • Prevents deletion of running AVDs.
DDMS:
  • DDMS plug-in now contains the Allocation Tracker view.
  • New action in the Logcat view: “Go to problem” lets you go directly from an exception trace output to the code.
Editors:
  • Explode mode in the Visual Layout Editor adds a margin to all layout objects so that it’s easier to see embedded or empty layouts.
  • Outline mode in the Visual Layout Editor draws layout outline to make it easier to see layout objects.
  • Several fixes in the configuration selector of the Visual Layout Editor.
Application launching:
  • Applications launched from ADT now behave as if they were clicked from the Home screen.
  • Fixes issue where add-on with no optional library would not show up as valid targets for application launches.
  • Resolves possible crash when launching applications.
  • Share/Bookmark

Android NDK r3 is out

The third release of the Android Native Development Kit (NDK) is now available.
It can be used to target devices running Android 1.5 and higher.
New features:

  • Toolchain improvement
  • OpenGL ES 2.0 support

Details are here.

  • Share/Bookmark

Using URLConnection in Java

URLConnections are closely related to URLs. Indeed, you get a reference to a URLConnection by using the openConnection() method of an URL object. In many ways, the URL class is only a wrapper around the URLConnection class. URLConnections provide more control over the communication between the client and the server. In particular, URLConnections provide not just input streams by which the client can read data from the server, but also output streams to send data from the client to the server. Read the rest of this entry »

  • Share/Bookmark

Using URL in Java

Here I am going to show example which works with URL.
Each URL(Uniform Resource Locator) unambiguously identifies the location of a resource on the Internet.
Example shows how to connect to an URL, download its data and show it in console via System.out

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * This class shows how to work properly with URL
 * @author The Developer's Info
 */
public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = null;
        try {
            URL u = new URL("http://thedevelopersinfo.com");
            inputStream = u.openStream();
            for (int c = inputStream.read(); c != -1; c = inputStream.read()) {
                System.out.write(c);
            }
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }
}

Download code from this post.

  • Share/Bookmark

Eclipse Galileo SR2 is available

There is a great news for developers who use Eclipse – version Galileo SR2 is available for download from eclipse.org.

If you don’t want to download the full packages, you can start an upgrade – that’s what I did just a few minutes ago (Help -> Check for Update).

  • Share/Bookmark

Getting separator symbol in Java

This snippet of code allows to get symbol which represents separator in your file-system:

System.getProperty("file.separator");
  • Share/Bookmark

Writing files in Java

I am going to show example which shows how to write a file in Java.
If you want to write some file you should start with FileOutputStream. This class is a concrete subclass of OutputStream.
Example:

package tutorial;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * This class shows how to write a file
 * @author The Developer's Info
 */
public class Main {

    public static void main(String[] args) {
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            String workingDirectory = System.getProperty("user.dir");
            File fileDir = new File(workingDirectory, "src/tutorial");
            File readFile = new File(fileDir, "Main.java");

            File writeFile = new File(fileDir, "CopyFile");

            fileInputStream = new FileInputStream(readFile);

//            fileOutputStream = new FileOutputStream(writeFile, true);
            fileOutputStream = new FileOutputStream(writeFile);

            show(fileInputStream, fileOutputStream);
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
            } catch (IOException ex) {}
            try {
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
            } catch (IOException ex) {}
        }
    }

    /**
     * This method read and write a file
     * @param fileInputStream input stream
     * @param fileOutputStream output stream
     * @throws IOException
     */
    private static void show(FileInputStream fileInputStream, FileOutputStream fileOutputStream) throws IOException {
        byte[] buffer = new byte[1024];
        while (true) {
            int bytesRead = fileInputStream.read(buffer);
            if (bytesRead == -1) {
                break;
            }
            fileOutputStream.write(buffer, 0, bytesRead);
        }
    }
}

I had commented code in line number 26.
This constructor lets you specify whether the file’s contents should be erased before data is written into it (append == false) or whether data is to be tacked onto the end of the file (append == true). You can uncomment this line and comment next line of code and you will see how content is added in the end of the file.

  • Share/Bookmark

Reading files in Java

I am going to show example which shows how to read a file in Java.
If you want to read some file you should start with FileInputStream. This class is a concrete subclass of InputStream. It provides an input stream connected to a particular file.
Example:

package tutorial;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;

/**
 * This class shows how to read a file and show it in system console
 * @author The Developer's Info
 */
public class Main {

    public static void main(String[] args) {
        FileInputStream fileInputStream = null;
        try {
            String workingDirectory = System.getProperty("user.dir");
            File fileDir = new File(workingDirectory, "src/tutorial");
            File file = new File(fileDir, "Main.java");

            fileInputStream = new FileInputStream(file);

            show(fileInputStream, System.out);
        } catch (IOException ex) {
        } finally {
            try {
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
            } catch (IOException ex) {}
        }
        System.out.println();
    }

    /**
     * This method shows Main.java content in console
     * @param fin input stream
     * @param out output stream
     * @throws IOException
     */
    private static void show(FileInputStream fin, PrintStream out) throws IOException {
        byte[] buffer = new byte[1024];
        while (true) {
            int bytesRead = fin.read(buffer);
            if (bytesRead == -1) {
                break;
            }
            out.write(buffer, 0, bytesRead);
        }
    }
}

Main method here is show(). It is very simple method. In general Java allows to work with all things very easy.

  • Share/Bookmark

Getting system root directory in Java

If you are working with file-system in Java, you should understand that your program can run in other types of OS:(Windows, Unix, Linux).
These OS has own file-system structure. For example you need to read or write file in Windows, which located at disk C:\, you should write:

File root = new File("C:\\");
File dir = new File(root, "someDir");
File child = new File(dir, "someFile");

It’s normal, because you know that your file located at disk C:\. Remember – avoid this practice. What if your program will run in Linux? You should modify your code:

File root = new File("/");
File dir = new File(root, "someDir");
File child = new File(dir, "someFile");

It’s not good. Java has great way for getting root directory:

File[] roots = File.listRoots();
File dir = new File(roots[0], "someDir");
File child = new File(dir, "someFile");

I ran this snippet of code in my Windows machine and I got all my local disks. roots[0] is my local disk C:\.

  • Share/Bookmark

Getting path to user’s home directory in Java

There is a way to find out path to user’s home folder. Need to get system property:

System.getProperty("user.home");

That’s all.

  • Share/Bookmark

"If people do not believe that architecture is simple, it is only because they do not realize how complicated life is." - J.H. von Neumann