Archive

Archive for the ‘Home’ Category

AndroidKickstartR – A pretty fun project

December 1, 2012 Leave a comment

Well, this site gives a quite fun simple idea for quick Android project configuration.

AndroidKickstartR 

However, I’m not sure it’s gonna be a long-term useful tool.

Advertisements
Categories: Home

Decompress file using Zip utility

October 12, 2012 Leave a comment

As I mentioned in previous post about compressing file using Zip utility, so there should be a way to de-compress zip files, too.

Here is the sample usage:

1. Utils.java

	/**
	 * to decompress file zip
	 *
	 * @param	zipFile		the target ZIP file to unzip
	 * @param	pathToUnzip	where unzipped file to be stored
	 *
	 */
	public static void decompress(String zipFile, String pathToUnzip) {

		try {
			ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFile));
			ZipEntry entry = null;
			while((entry = zipIn.getNextEntry()) != null) {
				if(!entry.isDirectory()) {
					FileOutputStream fout = new FileOutputStream(pathToUnzip + "/" + entry.getName());
					for(int c = zipIn.read(); c != -1; c = zipIn.read()) {
						fout.write(c);
					}
					zipIn.closeEntry();
					fout.close();
				}
			}

			zipIn.close();
		} catch (Exception ex) {
			Log.d("Error", ex.getMessage());
		}
	}

2. MainScreen.java

package pete.apps.samples.compressionzip;

import android.app.Activity;
import android.os.Bundle;
import pete.apps.samples.compressionzip.Utils;

public class MainScreen extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        doDecompress();
    }

    public void doDecompress() {
    	final String DIR_TARGET = "/sdcard/Download/Unzip";
    	final String FILE_ZIP = "/sdcard/Download/target.zip";

    	Utils.decompress(FILE_ZIP, DIR_TARGET);
    }
}

– Note  that if inside the Zip file containing also directories, then you need to check whether the __ZipEntry__ queried from ZIP file is a directory or not to create an equivalent directory while unzipping files; then just output files from zip package as normal.

 

Cheers,

Pete Houston

Categories: Home Tags: , ,

Create application with multiple entry-point activities

June 4, 2012 2 comments

A great stuff I’ve got today is that “An application can have many different entry-point activities.”

Here the sample, I create a project with four Activities: First Act, Second Act, Third Act, Four Act

Multiple entry-point Activites for one application

Multiple entry-point Activites for one application

The trick behind this stuff is to register your desired activities on AndroidManifest.xml w/ <intent-filter> is MAIN.

The sample for my sample case it should be like this:

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="First Act"
            android:name=".FirstAct"
            android:icon="@drawable/ic_first_act"
            android:taskAffinity=".FirstAct"
            >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:label="Second Act"
            android:name=".SecondAct"
            android:icon="@drawable/ic_second_act"
            android:taskAffinity=".SecondAct"
            >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:label="Third Act"
            android:name=".ThirdAct"
            android:icon="@drawable/ic_third_act"
            android:taskAffinity=".ThirdAct"
            >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

       <activity
            android:label="Four Act"
            android:name=".FourAct"
            android:icon="@drawable/ic_four_act"
            android:taskAffinity=".FourAct"
            >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

There are some applications done this before. As I remember the app: “Facebook for Android” in version 1.9.0 (release on 19/Apr/2012) containing three activites registering to MAIN/LAUNCHER.

Cheers,

Pete Houston

Categories: Home Tags: , ,

It’s time to try WordPress


Quite a long time that I’ve not been working on my blog. Today, I’m going to open it again and try a new domain, Android.

Let see how it works 🙂

Categories: Home Tags: , ,