How to add custom view in android's JellyBean Launcher
Asked Answered
H

4

29

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

Hochman answered 17/6, 2013 at 5:51 Comment(5)
I also have a same problem can any one have any hint or idea about this?Islaen
Obviously that app (SOHO) you have mentioned here is a custom home screen launcher app. You can notice that when you press home button it asks for selection whether to go for native home launcher or So.Ho launcher. But in addition to that, app has created its own design to make it feel like native android home screen by linking native android apps in the bottom bar & making 5 screens. But I am not sure how those screens work on drag events. It can be some canvas actions.Snappy
@MPM : Thanks for your reply. but whatever you said I already knew about it. The problem is I want to know how they have integrate this view in native android jellybean launcher.Hochman
android.googlesource.com/platform/packages/apps/Launcher.git android.googlesource.com/platform/packages/apps/Launcher2.git code.google.com/p/android-launcher-plusAoristic
hi can you please explain to me how to add shortcut from all apps to workspace in Launcher3?, here my question :#29411375Becharm
M
2

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);
Mixed answered 3/5, 2014 at 13:23 Comment(5)
Launcher3 - Will this only add a custom view to the left? How would I go about forcing a single desktop page on the launcher and then adding a custom view to the left and right for example?Drinkable
@Mixed I am able to add new page on left but its not showing anything. while scrolling left. its empty. I am using launcher3Bikol
addToCustomContentPage() is basically not getting callBikol
hey, I just want to add a custom page on right side, is it possible with Launcher3 code? If yes then please tell me the way how to do it.I am stuck with it.Cheeseparing
@Anupriya, It's not possible normally. But I think you can make it work in someway. But I don't know how :(Mixed
T
1

If I remember correctly you just need to implement a standard activity which displays a home launcher. In your Manifest.xml you just need to define it like this:

<activity android:name=".YourLauncher" android:label="@string/launcher_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
Tedium answered 17/6, 2013 at 10:43 Comment(2)
Thanks for your reply. but this doesn't help me :(Hochman
hi can you please explain to me how to add shortcut from all apps to workspace in Launcher3?, here my question :#29411375Becharm
D
0

you can simply add view in default lanucher use code

wm = (WindowManager) getSystemService("window");
params = new LayoutParams();
params.type = LayoutParams.TYPE_PHONE;
    params.format = PixelFormat.RGBA_8888;
    params.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL
            | LayoutParams.FLAG_NOT_FOCUSABLE;
    params.x = 100;
    params.y = 100;
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.gravity = Gravity.LEFT | Gravity.TOP;
wm.addView(view, params);

when you want to remove it just

wm.removeView(v);

you also need permission

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Dimarco answered 23/8, 2013 at 8:57 Comment(0)
G
0

Good news, not so good news, bad news.

Good new first.
It is possible to do what you want.

Now the not so good news.
You will have to write the launcher application from scratch(aka Home Screen). Yep, that involves doing all those nice and nifty things that the default launcher does(multiple pages, drag and drop, delete/add app icons, etc). Fortunately, its not as difficult as it sounds. Because the default launcher app itself is opensource. Though this code is complete, its not easy to read. A easier place to start would be the SDK

   Android-SDK/samples/android-x/Home/
   where x is the API level.

They have provided source code for an example home screen and it should give you a good start. With some perseverance and coffee, you should be able to modify the Launcher2 code to add a customized page of your own.

Now the Hard part.
Because a part of your goal is to keep the existing pages same and add a new page, getting this to work for all the flavors of android... HTC sense, Samsung TouchWiz, etc, etc is not a single person workload. They all have different features for the Home screen. Preserving these features and adding a new customized page is a tough task.

Gunfire answered 19/9, 2013 at 21:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.