Sunday, November 2, 2014

Build a custom Launcher - sourceCode

This tutorial helps you to create your own launcher. note that its a basic launcher, which gives you an idea of launcher. first, create an android project using eclipse or android studio.

1.lets start with AndroidManifest.xml - open this file. we have to do some changes here.



by adding below given categories to intent filter, our activity acts like a launcher
   <category android:name="android.intent.category.HOME" />
    <category android:name="android.intent.category.DEFAULT" />

to allow users to see their wallpaper we use 'android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"'

this is the only changes that we add to our default AndroidManifest.xml file. save it and close. :)


2.activity_main,xml
our main layout contain only one button. when user do click on this button, apps list will be shown.



3.MainActivity.java

we have created a button in above xml file. in our MainActivity we initialize this button and assign a fuction that should be performed on a click event. when we click on button, actvity will create an Intent and start new activity- AppList, which will load all apps in android device.




4.Create new activity AppList. this activity contain only a gridView, which is used to display app icon and app name. we add a listener to grid view, onItemClickListener., on click, the app will open.

Layout of AppList


each grid contain one imageview and a  textview. so we create alayout for grid item as shown below
filename: grid_item.xml



below given AppList.java




i will explain fuction in AppList.

function getApps()- it is used to fetch details of apps intalled on a device. we store these information in an arraylist. we have created a class 'App' to hold properties of Applications.

fuction showApps()-this is used to populate gridview.

finally we add an onItemclickListener to gridview. so whenever we click on an item, the app show in that grid will open.