Android launcher trampled on the pit

Source: Internet
Author: User

Demand:
1, using the Android system Launcher hide the main menu all the applications displayed on the desktop is workspace;
2, hide launcher above the default Google search;
3, switch A set of launcher theme.

Implementation results:

Analysis:
1, hide the main menu, Google Default in the Android L version has a hidden main menu switch--launcherappstate.isdisableallapps ()
Returns true to hide, which returns false for display.
2, hide Google search, there are many ways. Relatively simple, this article will be a pen
3, switch the theme of the last time the implementation of ideas, specifically to see the installation package performance optimization, dynamic loading resources

Here's the road to pits.
1. Hide Main Menu
First set Launcherappstate.isdisableallapps () to hide the main menu
The exact principle.

This will be in the Hotseat.java according to the above conditions to determine whether to show or hide, Allapp is actually a textview of course, just this is not enough of the more detailed things have time in-depth analysis

Pit one, through the above steps, we are the default is to display all the applications on the workspace, but the system launcher people know that the workspace on the default only the following removal action

Only in the main menu to drag and drop the application information and uninstall operation, this problem will directly lead to, if you want to uninstall the app can only go to the settings to uninstall, remove on the desktop just remove and it still exists restart launcher will find this application is back, this is a comparison of the pit dad,

Workaround:
First find the top show uninstall and AppInfo place
By analyzing the last discovery is shown in the Buttondroptarget two sub-class
Deletedroptarget and infodroptarget see names and know what they do, and Buttondroptarget realizes the two interfaces defined by launcher.

publicclass ButtonDropTarget extends TextView implements DropTarget, DragController.DragListener

Discover that Google engineers are just as good as their names.
DropTarget the placement of the listener target
Dragcontroller drag-and-drop event control class

And we'll find a isvisible in all two of these classes. This is the switch that controls whether the two tabs on the top of the launcher are displayed by analysis.
Inside the infodroptarget we find

if (!source.supportsAppInfoDropTarget()) {            false;        }

And Supportsappinfodroptarget is a method of interface, it has three implementation classes

Returns true only if it is Appscustomizepagedview
The other two are false so we know why the app information can be displayed in the main menu and the desktop can't display the app information.

So this method of workspace is also changed to True

@Override     Public void ondragstart(DragSource source, Object info,intDragaction) {if(launcherlog.debug) {LAUNCHERLOG.D (TAG,"Ondratstart:source ="+ Source +", info ="+ info +", dragaction ="+ dragaction); }BooleanIsVisible =true;//Hide This button unless we is dragging something from AllApps        //by lly for Disableallapp 20161112 start         if(InfoinstanceofFolderInfo) {isVisible =false; }if(InfoinstanceofLauncherappwidgetinfo) {isVisible =false; }if(InfoinstanceofPendingaddwidgetinfo) {isVisible =false; }//by lly for Disableallapp 20161112 end        if(!source.supportsappinfodroptarget ()) {isVisible =false; }        ....        }

Then, in each case, let it not show up when it is a file or desktop widget or dragged from the Widgets view AppInfo
At this point, infodroptarget processing is complete.

Let's take a look at Deletedroptarget's treatment.
In fact, it's similar to dealing with infodroptarget, but it's a bit more cumbersome here, and directly on the code.

 @Override     Public void ondragstart(DragSource source, Object info,intDragaction) {BooleanIsVisible =true;//by lly for Disableallapp        BooleanUseuninstalllabel = Isshortcut (Source,info);//isallappsapplication (source, info);        BooleanUsedeletelabel =!useuninstalllabel && source.supportsdeletedroptarget ();//If we are dragging a application from appscustomize, only show the control If we can        //Delete the app (it is downloaded), and rename the string to "uninstall" in such a case.        //Hide The delete target if it is a widget from appscustomize.        //by lly for Disableallapp start         if(InfoinstanceofShortcutinfo) {Try{Shortcutinfo AppInfo = (shortcutinfo) info;                Packagemanager Packagemanager = GetContext (). Getpackagemanager (); ApplicationInfo ai = Packagemanager.getapplicationinfo (AppInfo.intent.getComponent (). Getpackagename (),0); Missysapp = (ai.flags & Applicationinfo.flag_system) >0; }Catch(Namenotfoundexception e)            {E.printstacktrace (); }            }//by lly for Disableallapp end        if(!willacceptdrop (info) | | | isallappswidget (source, info)) {isVisible =false; }//by lly for Disallapp 20161112 start    Private Boolean Isshortcut(DragSource source, Object info) {returnSource.supportsappinfodroptarget () && (infoinstanceofShortcutinfo); }//by lly for Disallapp 20161112 startPrivate Boolean isallappsapplication(DragSource source, Object info) {returnSource.supportsappinfodroptarget () && (infoinstanceofAppInfo); }
public static Boolean Willacceptdrop (Object info) {if(Info instanceof ItemInfo) {ItemInfo item = (iteminfo) info;...            if(Item.itemtype = = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && item instanceof shortcutinfo) {if(Launcherappstate.isdisableallapps ())                    {Shortcutinfo Shortcutinfo = (shortcutinfo) info; by lly forDisableallapp startif(!missysapp) {shortcutinfo.flags =1; }//by lly forDisableallapp Endreturn(Shortcutinfo.flags & appinfo.downloaded_flag)! =0; }Else{returnTrue }            }        }returnFalse }

Look at the notes above the place almost know how I did it, first I was to let the above show uninstall
The main thing is that Useuninstalllabel is true.

And then we'll see if it's a system application, because system applications can't be uninstalled.

if (info instanceof shortcutinfo) {try{Shortcutinfo appInfo = (shortcutinfo) info;Packagemanager Packagemanager = GetContext (). Getpackagemanager();ApplicationInfo ai = Packagemanager. Getapplicationinfo(AppInfo. Intent. Getcomponent(). Getpackagename(),0); Missysapp = (ai. Flags& ApplicationInfo. FLAG_system) >0;} catch (Namenotfoundexception e) {E. Printstacktrace();}            }

Determine flags based on whether it is a system application

Thus controlling the value of the IsVisible
This shows that uninstall has been completed.
Next look at the function is dragged to the uninstall tag how to delete

private void Completedrop (Dragobject d) {...        if(launcherlog.debug) {LAUNCHERLOG.D (TAG,"Completedrop:item ="+ Item +", d ="+ D); }if(Isallappsapplication (D.dragsource, item)) {...}Else if(Isuninstallfromdisableallapp (d)) {//by lly for             ...Mwaitingforuninstall = Mlauncher.startapplicationuninstallactivity (ComponentName, Shortcut.flags,        user); }} Private Boolean isuninstallfromworkspace (Dragobject d) {if(Launcherappstate.isdisableallapps () && isworkspaceorfolderapplication (d))            {Shortcutinfo shortcut = (shortcutinfo) d.draginfo; Manifest shortcuts to initiate an un-install.return!        Installshortcutreceiver.isvalidshortcutlaunchintent (shortcut.intent); }returnFalse }//by lly forDisableallapp Start Private Boolean Isuninstallfromdisableallapp (Dragobject d) {if(D.draginfo instanceof Launcherappwidgetinfo) {returnFalse }returnTrue }//by lly forDisableallapp End

It's still rewriting the interpretation criteria.
To this step the basic function has been implemented but the operation of the words found dragged to the label drop icon disappears whether it is a appinfo label or a uninstall tag
Here's a straight answer. He was hidden when he disappeared. You dragged the individual icon, and he showed up again, but it's a bug.

/** Indicates that the drag operation was cancelled */    publicbooleanfalse;
ifnull) {            mLauncher.startApplicationDetailsActivity(componentName, user);        }        true;//by lly

When the app information is displayed, just let cancelled be true to cancel the drag event.

Animatetotrashandcompletedrop (d) referred to Acceptdrop in Deletedroptarget

@Override    publicbooleanacceptDrop(DragObject d) {        //by lly for disableAllapp start            animateToTrashAndCompleteDrop(d);            if(isUninstallFromDisableAllApp(d)){                true;            }        returnfalse;//willAcceptDrop(d.dragInfo);      //by lly for disableAllapp end    }

Here the pit is filled up, tested for a while no such modifications have been found in new pits.

Pit II
Through the method provided by Google to hide the main menu after 1, press the menu key Desktop widget interface does not appear, 2, when long press the blank space to enter the widget interface and then return to the interface display exception, 3, drag the widget to the desktop after releasing the hand display exception.

This will not buy Xiaoguanzi directly explain why, as to why I know you did not see this is a few weeks, I still solve the bug?
Because you can see it by setting it up like Google

void resetLayout() {        mContent.removeAllViewsInLayout();        if (!LauncherAppState.isDisableAllApps()) {            ...            if (mLauncher != null) {                allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());                mLauncher.setAllAppsButton(allAppsButton);                allAppsButton.setOnClickListener(mLauncher);                allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);            }           ...        }    }

This place is mostly the place where the Allapp menu is added, but that's not going to work for our analysis. Mainly to see

 mLauncher.setAllAppsButton(allAppsButton);

This menu is set to Launcher.

    /**     * Sets the all apps button. This method is called from {@link Hotseat}.     */    publicvoidsetAllAppsButton(View allAppsButton) {        mAllAppsButton = allAppsButton;    }    publicgetAllAppsButton() {        return mAllAppsButton;    }

And then through Getallappsbutton get this Mallappsbutton finally in Showappscustomizehelper and hideappscustomizehelper inside use this Mallappsbutton actually is a TextView However, we set the hidden main menu after this mallappsbutton is empty so that caused the problem, then know that the cause of the resolution is very good.

for some reason our views aren‘t initialized, don‘t animate       // boolean initialized = getAllAppsButton() != null;        if (animated /*&& initialized*/) {        ...        }

Just don't let him go. Of course, the next few places will be removed.

At this point the pit two also filled

2, hide launcher above the default Google search;
3, switch A set of launcher theme.

These two requirements are relatively simple to no longer analyze if necessary, please send me a private messages.

Android launcher trampled on the pit

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.