A simple study of launcher
1 What is launcher
The first program that is loaded after the Android system starts. This program is the gateway to other applications.
Launcher Composition:
Homescreen: (Workspace + hotseats), Shortcut,livefolder, appwidget, wallpaper.
Allapplist (with GridView)
2 types of development for launcher
1) Develop your own launcher
2) The fuss in Wordspace
Add shortcut;
Add Livefolder;
Change the background;
Add Appwidget;
3 Analysis of the Launcher.java OnCreate ()
1 @Override2 protected voidonCreate (Bundle savedinstancestate) {3 Super. OnCreate (savedinstancestate);4 //The following paragraph is the interface initialization work5Launcherapplication app =( (Launcherapplication) getapplication ());6Mmodel = App.setlauncher ( This);7Miconcache =App.geticoncache ();8 //get the dragged component instance9Mdragcontroller =NewDragcontroller ( This);Ten //Get Inflater instances OneMinflater =Getlayoutinflater (); A - //Get Appwidget Management Example: Appwidgetmanager, Appwidgethost, Appwidgethostview three-class relationships -Mappwidgetmanager = Appwidgetmanager.getinstance ( This); theMappwidgethost =NewLauncherappwidgethost ( - This, appwidget_host_id); - //host initiates monitoring and listens for data changes in Launcherprovider - mappwidgethost.startlistening (); + - if(profile_startup) { + android.os.Debug.startMethodTracing ( AEnvironment.getexternalstoragedirectory () + "/launcher"); at } - - loadhotseats (); - //Check for localized language changes - Checkforlocalechange (); - //Set Desktop size in setwallpaperdimension (); - to //Loading content Display + Setcontentview (r.layout.launcher); - //set dynamic per-desktop view (the one that slides left and right) the setupviews (); * //Registered Content Observation $ registercontentobservers ();Panax Notoginseng //Lock the application - Lockallapps (); the +Msavedstate =savedinstancestate; A restorestate (msavedstate); the + if(profile_startup) { - android.os.Debug.stopMethodTracing (); $ } $ - if(!mrestoring) { -Mmodel.startloader ( This,true); the } - Wuyi //For handling default keys theMDEFAULTKEYSSB =NewSpannablestringbuilder (); -Selection.setselection (MDEFAULTKEYSSB, 0); Wu -Intentfilter filter =NewIntentfilter ( About intent.action_close_system_dialogs); $ Registerreceiver (mclosesystemdialogsreceiver, filter); -}
4 homescreen can add four pieces of
Shortcut
Livefolder
Appwidget
Wallpaper
5 Analysis Mechanism-sequencediagram
Interface Analysis of 6 launcher
7 Appwidget Monitoring Mechanism
Second, Shortcut&livefolder
1 What is shortcut?
2 Implementing Shortcut steps
1) Build Activity
2) manifest inside register and add intent-filter,name for
Android.intent.action.CREATE_SHORTCUT
3) acitivity, create a intent instance, set the extra_*** property, and then return.
3 adding shortcut to the desktop
4 What is Livefolder
1) Build Activity
2) manifest inside register and add intent-filter,name for
Android.intent.action.CREATE_LIVEFOLDER
3) acitivity, create an intent instance, set the extra_*** property and the Data property,
and then return.
5 Implementing Livefolder Steps
Third, Appwidget
3.1 What is Appwidget
Appwidget If you have a design, what do you think is the difference between him and Shortcut&livefolder?
1) interface display complex, must use the ViewGroup (Layout).
2) events are no longer single.
3) Inter-process communication. Constantly communicate and refresh.
"Design Ideas"
Serivce&appwidgetmanager Binder
Serialization of complex interface transfers
In order to refresh, broadcast, Broadcastreceiver
3.2 Appwidget main frame and class introduction
1> appwidgethost------Interface Related
2> Appwidgethostview------Interface Related
3> Appwidgetmanager
4> Appwidgetprovider
5> Appwidgetproviderinfo
5.1 Meta-data Introduction
5.2 Minwidth,minheight
Widgets are divided by cell, each cell size is 74DP, each widget also needs to subtract both sides of 1DP, that is, your true width and height algorithm is: (Number of cells * 74)-2
In addition, we contract the entire workspace by default:
8 * 7 cells in a tablet
Automatic completion mechanism
"Appwidget Object Anatomy"
5.3 Updateperiodmillis
Update frequency
It is generally not recommended to update the frequency (no meaning) for more than 30 minutes, but it is not recommended to update the frequency less than 5 minutes (power consumption)
5.4 Initiallayout
5.5 Configure
Set the settings to start when adding appwidget activity (over activity)
5.6 Previewimage
Set the preview of Appwidget after adding
6> Remoteviews
The role of Remoteviews
Remoteviews can use the following layout
Framelayout
LinearLayout
Relativelayout
And the following view elements:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
Viewflipper
Listview
Gridview
StackView
Adapterviewflipper
3.3 Appwidget Two processes
"Initialize"
"Update"
1) launcher start host listening
2) Service Send broadcast
3) MyApp received, onUpdate
4,) Remoteviews Service
5) Service Change host, Updateappwidget
6) Launcher hear, present
3.4 Experiment "detailed appwidget creation and interaction mechanism"
1> Appwidgethelloworld
Steps
1) Establish a appwidgetprovider subclass;
2) Register the subclass in manifest, and register the appwidgetproviderinfo configuration file;
3) Complete the Appwidgetproviderinfo configuration file;
4) Complete layout file;
5) Implement Appwidgetprovider onUpdate to refresh the display.
2> adds click event Support to the current appwidget and changes the view status.
3> adds configrationactivity support to the current appwidget.
4> I'm in the widget to trigger events in my app? SendMessage
3.5 In fact, the official provides a good case: Wiktionary & StackView Widget.
3.6 Summarize the key points of the widget to understand.
Widget is actually? Take a look at launcher.
Widget interface size.
Meta-data name must be Android.appwidget.provider.
Iv. How to design our own launcher
1 Understanding the System startup process
2 Understand how the system is going to identify and start launcher
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.action.HOME"/>
<category android:name= "Android.intent.action.DEFAULT"/>
</intent-filter>
3 Design Framework Interface
3.1 homescreen
Workspace
>shortcut
>livefolder
>wallpaper--------Graphic & Animation, OpenGL ES.
>appwidget-------familiar with Appwidget-related framework classes.
3.2 Hotseats
Allapplist--------to load our app via Packagemanager.
4 other
Skin horizontal screen multi-lingual ...
14, Appwidget and launcher