Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom view in android's JellyBean Launcher

I am working on making custom launcher in android. I have referred the code of android's Jellybean launcher. now I want to make some modification in this launcher.

What I want : As we know there are default five work-space screens and I want to add custom view in any one of the workspace screen. My xml file should be inflated in any one of the screen.

I have tried many ways to do it but as the default launcher code is very complex still having no luck to finding out way for it.

There is already app named SOHO in Playstore doing exactly what I want. I have add the screenshot for referencing what i want.

Please help me if anyone of you having any idea to do it.

enter image description here

like image 559
Bhavesh Patadiya Avatar asked Jun 17 '13 05:06

Bhavesh Patadiya


1 Answers

I've the answer for you. You can do it both in Launcher2 and Launcher3 package from (AOSP). Jellybean is using Launcher2 may be. I personally suggest you to go with Launcher3, it has buit-in way to do so.

Launcher3:

create a class that extends the com.android.launcher3.Launcher class and override the necessary methods like so:

public class MyLauncher extends Launcher {       @Override     protected boolean hasCustomContentToLeft() {         return true;     }       @Override     protected void addCustomContentToLeft() {         View customView = getLayoutInflater().inflate(R.layout.custom, null);          CustomContentCallbacks callbacks = new CustomContentCallbacks() {              @Override             public void onShow() {}              @Override             public void onScrollProgressChanged(float progress) {}              @Override             public void onHide() {}         };           addToCustomContentPage(customView, callbacks, "custom view");     }  } 

Here R.layout.custom is the custom view that you wanted. Then in the manifest file change the launcher activity class from Launcher to MyLauncher. And that's it.

Launcher2:

in Workspace.java create the following method:

public void addCustomView(View child){    CellLayout layout = (CellLayout) getChildAt(0);    layout.addView(child); } 

then in Launcher.java, find the following line:

mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); 

then paste the following code somewhere after that line:

View child = LayoutInflater.from(this).inflate(R.layout.custom, null); mWorkspace.addCustomView(child); 
like image 65
sha256 Avatar answered Sep 24 '22 07:09

sha256