Home is the first application to interact with users after the Android device is enabled. Home will always run on the background when other applications are running on the foreground.
On an Android device with a screen resolution of 320*480 pixels, the desktop consists of 3 Fast 320 * PX areas when the screen is portrait, each area is divided into 16 80*100 pixel cells. The horizontal screen consists of three 424 * 296px cells, each screen is divided into 16 cells, but each cell is 106 * 74px. (The android2.2 system has now reached five screens ).
See the figure for specific dimensions:
Three types of components can be added to the launcher desktop: shortcuts, real-time folders, and desktop components. The Desktop shortcuts and real-time folders occupy the size of one cell in the desktop area, the desktop widget occupies one or more cells according to the functional requirements.
There are two ways to create shortcuts: 1. Build an intent in the application, and then notify launcher to create a shortcut in the form of broadcast; 2. register an intentfilter that meets specific conditions for the application's components, and then add a shortcut to start the component on the launcher's desktop.
Let's look at the code for adding shortcuts (first ):
Mainactivity Code: (layout Code omitted)
Code:
- Package com. myshortcut;
- Import Android. App. activity;
- Import Android. content. intent;
- Import android.net. Uri;
- Import Android. OS. Bundle;
- Import Android. OS. parcelable;
- Import Android. View. view;
- Import Android. View. View. onclicklistener;
- Import Android. widget. Button;
- /*
- * Desktop components-> shortcuts-> Add shortcuts to applications
- */
- Public class hellosponcut extends activity implements onclicklistener
- {
- Private button bt_fire = NULL;
- Private button bt_police = NULL;
- Private intent directCall = NULL;
- Private final string action_add_shortcut = "com. Android. launcher. Action. install_shortcut ";
- /** Called when the activity is first created .*/
- @ Override
- Public void oncreate (bundle savedinstancestate)
- {
- Super. oncreate (savedinstancestate );
- Setcontentview (R. layout. Main );
- Bt_fire = (button) findviewbyid (R. Id. bt_fire );
- Bt_police = (button) findviewbyid (R. Id. bt_police );
- Bt_fire.setonclicklistener (this );
- Bt_effece.setonclicklistener (this );
- DirectCall = new intent (intent. action_call );
- }
- @ Override
- Public void onclick (view V)
- {
- // Todo auto-generated method stub
- Intent addshortcut = new intent (action_add_shortcut );
- String nametodial = NULL;
- Parcelable icon = NULL;
- Switch (V. GETID ())
- {
- Case R. Id. bt_fire:
- Nametodial = "119 ";
- Icon = intent. Reset cuticonresource. fromcontext (this,
- R. drawable. Fire );
- Break;
- Case R. Id. bt_police:
- Nametodial = "110 ";
- /*
- * When cuticonresource is intent
- * An internal class is used to construct shortcuts, while intent implements the parcelable interface, so intent objects and
- * All cuticonresource objects can use putextra (string, parcelable) to input information
- * Add intent information to broadcast.
- */
- Icon = intent. Reset cuticonresource. fromcontext (this,
- R. drawable. Police );
- Break;
- Default:
- Break;
- }
- Addshortcut. putextra (intent. extra_shortcut_name, nametodial );
- Addshortcut. putextra (intent. extra_shortcut_icon_resource, icon );
- DirectCall. setdata (URI. parse ("Tel:" + nametodial ));
- Addshortcut. putextra (intent. extra_shortcut_intent, directCall );
- This. sendbroadcast (addshortcut );
- }
- }
Running result:
1,
2. (toast is provided by the system)
3. (After successful addition)
4. (To delete the shortcut icon, please press the icon long and drag it to the "drawer" area below to change the "drawer" to the "bin" icon)
Reference books: go deep into googleandroid