2015 has come almost half a month, always still did not feel a little new year atmosphere, but after all, it is still not the Spring festival for us as if it is indeed normal.
At present, the feeling of self is still immersed in the atmosphere of the end of the year, then the end of the year. At the end of the year because part of the reason again need to contact Launcher code, remember 14 years at the beginning of the first time to see a part of Launcher2 code, now look back to see but found a lot of feelings, unexpectedly forget many, also looked at a long time after a little re-understanding of the feeling.
Return to the point, this time not only to modify the source part of the Launcher2, but also add a bit of their own things, because still rely on the original launcher2 reason, just want to add a bit of their own things in the inherent Launcher2 UI architecture, As for the UI architecture part of Launcher2, I would like to revisit it again, after all, it should not have been recorded before.
The first most intuitive part of the UI interface is the approximate classification. A simple cut is a look at the picture.
The reason why my district is divided into three regions is also because these three parts have occupied most of the UI layout, respectively, from left to right search box/delete box Occupy area, apply icon/widget occupied area, shortcut function key occupies area. If you launcher.xml by layout file, you'll have to be more careful. In this can learn from the user to parse the code snippet
<com.android.launcher2.draglayer xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:launcher= " Http://schemas.android.com/apk/res/com.android.launcher "android:id=" @+id/drag_layer "... > <!--Keep these Behind the workspace so they is not visible when we go to AllApps--<include android:id= "@+id/dock_divider" layout= "@layout/workspace_divider" .../> <!--paging indicator--<include Andro Id:id= "@+id/paged_view_indicator" layout= "@layout/scroll_indicator" .../> <!--the workspace conta INS 5 Screens of cells---<com.android.launcher2.workspace android:id= "@+id/workspace" ... ><!--Five split screen, default display Cell3---<include android:id= "@+id/cell1" layout= "@layout/workspace_screen"/> <include android:id= "@+id/cell2" layout= "@layout/workspace_screen"/> <include android:id= "@+id/cell3" l ayout= "@layout/workspace_screEn "/> <include android:id=" @+id/cell4 "layout=" @layout/workspace_screen "/> <include android:id = "@+id/cell5" layout= "@layout/workspace_screen"/> </com.android.launcher2.Workspace><!--search box/Delete box-- > <include android:id= "@+id/qsb_bar" layout= "@layout/qsb_bar"/><!--Show all the application-specific interfaces, including apps, Wighe The tab tab of TS, and the page that displays all apps and the Real app wighets page--<include layout= "@layout/apps_customize_pane" android:id= "@+i D/apps_customize_pane ". /><!--Workspace The bottom five quick locations--<include layout= "@layout/hotseat" android:id= "@+id/hotseat". /><!--just started when the instruction page--<include layout= "@layout/workspace_cling" android:id= "@+id/workspace_cling" was displayed .../><!--is the Guide page that appears after the first entry to all apps-<include layout= "@layout/folder_cling" android:id= "@+id/fol Der_cling ".../></com.android.launcher2.draglayer>
The above part of the resolution is very clear, no longer explain what.
The changes to the Launcher2 have been made from several places above. It can be seen that the entire launcher layout is contained in the Com.android.launcher2.DragLayer, and then look at this part of the Java code to understand that the best example of framelayout This layout is launcher this is true, because LA Uncher of the source code is the layout of the various features to play the most vividly. Imagine Framelayout made out of launcher in the Android platform as a façade to show everyone will be how comprehensive.
The idea was to add one of your own partitions on top of this intrinsic partition to add a bit of your own functionality, So decisively modified the launcher.xml layout, and the draglayer of the outer layer of the addition of a linearlayout at the same time on the left side of the layout to add a linearlayout to show their own things. But this simple change compiles with errors, log displays
Workspace can only is used in exactly mode.
Follow up to the Pageeview.java code to find this exception hint
if (widthmode! = measurespec.exactly) { throw new IllegalStateException ("Workspace can only is used in exactly mode.") ); }
I don't know what to think about. To set the workspace region to exactly mode, the data for this pattern seems to have to specify the width or height of the details or fill_parent,match_parent to determine the mode, Because the time problem temporarily did not consider the direct comment, the decisive compilation passes, the rest of the work is to calculate the width of their own area to the rest of the workspace and specify a reasonable number of Icon arrangement launcher is basically normal.
Back to their own framelayout, because want to in their own area to display different view according to different circumstances, so first thought of fragment, but then consider repeatedly decided not to use this method, Because the fragment switch requires that the main activity that invokes fragment display be inherited from Fragmentacitivity, Obviously I feel that for a simple modification to change the inheritance of Launcher.java is a bit too complex, so think of the way to use the framelayout is simple. So in your own linearlayout to do a simple test, the first is to add such a test layout in the launcher layout
<linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android : orientation= "Horizontal" > <framelayout android:layout_width= "wrap_content" android:layout_height = "Wrap_content" android:id= "@+id/myframelayout" > <include android:id= "@+id/view1" layout= "@ LAYOUT/MYLAYOUT1 "></include> <include android:id=" @+id/view2 "layout=" @layout/mylayout2 ">< /include> </FrameLayout> </LinearLayout>
To add these, you need to re-do the other two simple layouts, because only the test, so only need to add a textview in each layout, can differentiate is enough.
And then the operation in launcher.
Layoutinflater Minflater; View Myview1; View Myview2; Framelayout myframelayout; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_main); minflater = Getlayoutinflater (); myview1 = (View) Minflater.inflate (R.LAYOUT.MYLAYOUT1, null); myview2 = (View) minflater.inflate (r.layout.mylayout2, NULL); Myframelayout = (framelayout) Findviewbyid (r.id.myframelayout); ...}
Here are some of the final code, I said before the View switch is the nested layout of the switch, I began to call Myview1.setvisibility (View.gone) This way to hide or show it, but I found that is always invalid, Perhaps as a netizen said the Framelayout feature is layered overlay, the layout will be superimposed on the layer, even if the view.gone but still not to show the effect of another. So the last attempt was to use the above code when it was necessary to display one of the view,
Myframelayout.removeallviews ();
Myframelayout.addview (MYVIEW2);
The simple principle of this approach is that every time you need to re-display a view, all of the embedded view in the Framelayout is cleared, and then the view that asks for the display is displayed again.
If you need to listen for keystrokes in the embedded layout layout, you can use a similar Myview2.findviewbyid (r.id.xxx) method to find the corresponding ID key to rewrite the listener.
At least I originally thought is simple realization, the concrete efficiency and the hidden danger because the time relation is not tested temporarily, the follow-up will continue to test and the attention.
Display of multiple layout layouts nested in a framelayout layout