30

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

Aleksey Potapov
  • 3,363
  • 4
  • 38
  • 61
Bhavesh Patadiya
  • 25,555
  • 14
  • 76
  • 105
  • 1
    I also have a same problem can any one have any hint or idea about this? – Yog Guru Jun 17 '13 at 06:02
  • 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. – M P Mathugama Jun 20 '13 at 12:45
  • @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. – Bhavesh Patadiya Jun 20 '13 at 12:48
  • https://android.googlesource.com/platform/packages/apps/Launcher.git https://android.googlesource.com/platform/packages/apps/Launcher2.git https://code.google.com/p/android-launcher-plus/ – Alexander.Iljushkin Jun 25 '13 at 05:42
  • hi can you please explain to me how to add shortcut from all apps to workspace in Launcher3?, here my question :http://stackoverflow.com/questions/29410875/drag-and-drop-icons-to-home-screen – Mounir Elfassi Apr 27 '15 at 14:26

4 Answers4

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);
sha256
  • 2,739
  • 1
  • 23
  • 32
  • 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? –  Apr 30 '16 at 13:19
  • @sha256 I am able to add new page on left but its not showing anything. while scrolling left. its empty. I am using launcher3 – rupesh Jan 17 '17 at 13:03
  • addToCustomContentPage() is basically not getting call – rupesh Jan 17 '17 at 13:21
  • 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. – Anupriya Jan 27 '17 at 06:04
  • @Anupriya, It's not possible normally. But I think you can make it work in someway. But I don't know how :( – sha256 Jan 29 '17 at 05:01
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>
rekire
  • 45,039
  • 29
  • 149
  • 249
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" />
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.

pellucide
  • 2,868
  • 2
  • 18
  • 23