質問

I downloaded Launcher3 (Google's Kitkat Launcher) from 4.4 Sources.

I imported it into eclipse . I got rid of errors.And my launcher works pretty good.

But something missing. "GOOGLE NOW" page when you scroll to left.

I can't activate google now.Anyway i don't need that. I want to put my own fragment or layout into first page and other pages will work same like normal launcher. Like a Google's experience Launcher(Kitkat Launcher of google)'s Google Now page ..

Like this : enter image description here

I added my layout like this :

here is original codes from workspace.java

  public long insertNewWorkspaceScreen(long screenId, int insertIndex) {
    if (mWorkspaceScreens.containsKey(screenId)) {
        throw new RuntimeException("Screen id " + screenId + " already exists!");
    }

    CellLayout newScreen = (CellLayout)
            mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null);

    newScreen.setOnLongClickListener(mLongClickListener);
    newScreen.setOnClickListener(mLauncher);
    newScreen.setSoundEffectsEnabled(false);
    mWorkspaceScreens.put(screenId, newScreen);
    mScreenOrder.add(insertIndex, screenId);
    addView(newScreen, insertIndex);
    return screenId;
}

here is edited codes by me on workspace.java

      public long insertNewWorkspaceScreen(long screenId, int insertIndex) {
        if (mWorkspaceScreens.containsKey(screenId)) {
            throw new RuntimeException("Screen id " + screenId + " already exists!");
        }
if (screenId == 2) //Firstscreen/page
{

 RelativeLayout newScreen = (RelativeLayout)
                mLauncher.getLayoutInflater().inflate(R.layout.blinkfeed, null);

        newScreen.setOnClickListener(mLongClickListener);
        newScreen.setOnClickListener(mLauncher);
        newScreen.setSoundEffectsEnabled(false);
     //   mWorkspaceScreens.put(screenId, newScreen);
        mScreenOrder.add(insertIndex, screenId);
        addView(newScreen, insertIndex);
        return screenId;

}
else
{
        CellLayout newScreen = (CellLayout)
                mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null);

        newScreen.setOnLongClickListener(mLongClickListener);
        newScreen.setOnClickListener(mLauncher);
        newScreen.setSoundEffectsEnabled(false);
        mWorkspaceScreens.put(screenId, newScreen);
        mScreenOrder.add(insertIndex, screenId);
        addView(newScreen, insertIndex);
        return screenId;
}
    }

as you can see when its first page i changed layout but i'm getting problems on childviews, animations etc, anyway i cant even access other pages after that. i putted everywhere try catch when i get errors because of "celllayout cannot bind to relative bla bla .."

my try catch like this

try
{
cell layout stuff its trying to make animations etc.
}
catch (Exception e)
{
//empty
}

i couldn't make it work at the moment like a google now pages :) does anybody know about adding a fragment/layout into first page ?

Thanks.

役に立ちましたか?

解決

If you want to add some fragment or view in the same manner as Google Now, the Launcher3 code supports that. You basically have 2 ways of getting the desired behavior:

  • Subclass the Launcher class and overwrite hasCustomContentToLeft() to return true and addCustomContentToLeft() where you can create/inflate your view to be added. Make sure you call addToCustomContentPage and implement the CustomContentCallbacks if you want to be notified when the screen is open.

  • Implement the same methods as described above in the Launcher class directly.

Hope this helps, Mihai

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top