Thursday, February 3, 2011

Basics of Andriod super simplyfied

1. From previous blog set up andriod.
2. Create an andriod project in eclipse.
3. When you are creating the project you will see Built target andriod 2.2 and 2.3 .
4. Give some name of the application and some package name java style.
5. Give some activity name- this is the first place where your application will begin.
6. Click on Finish.
7. Now open the project you will see the first file as AndroidManifest.xml this is the file where you specify the first activity or first place of the application.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.org"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".FirstGame"
                  android:label="@string/hello">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="8" />

</manifest> 

Now in this file you will see @drawable which actually specifies the drawable folder under res folder above..The drawable folder under res which has icon and other images.

Now you will see @string which specifies string.xml under values.We will go into details later.


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, FirstGame!</string>
    </resources>


Basically what you do is specify the images and activity in xml which has refrence to drawable folder and string which are used in the application,

.Now you need to create a class file in the package in the folder you specified during the creation of the folder.


package com.org;





import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class FirstGame extends Activity {
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        mSnakeView.setView((TextView) findViewById(R.id.hello));
       
    }
}
Below is the code of first activity/class as you ca see there is a function onCreate.

There are some other function onPause,onDestroy these are exposed services.

When the application is first hit onCreate is called.

public class FirstGame extends Activity {
      private FirstGameView mSnakeView;
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
       mSnakeView.setView((TextView) findViewById(R.id.startgame));
       
    }
}


As you can see there is findViewById() uses the startgame variable to display first text on the screen "Start"


These are some of the basic basic concepts i will update as i move along

R.id here R is the resource file which is created automatically depending upon the xml by andriod


Delete all files in a folder using PHP

<?php
$dir= "/home/localadmin/test2";
   
class Deletefile{
function deleteDirectory($dir) {
    if (!file_exists($dir)) return true;
    if (!is_dir($dir) || is_link($dir)) {
    @chmod($dir, 0777);
    return unlink($dir);}
        foreach (scandir($dir) as $item) {
            if ($item == '.' || $item == '..') continue;
            if (!self::deleteDirectory($dir . "/" . $item)) {
                @chmod($dir . "/" . $item, 0777);
                if (!self::deleteDirectory($dir . "/" . $item)) return false;
            };
        }
        return @rmdir($dir);
    }

}

$df = new Deletefile();
$df->deleteDirectory($dir);
echo "Reached here";