Search in sources :

Example 51 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method removeAllWorkspaceScreens.

public void removeAllWorkspaceScreens() {
    // Disable all layout transitions before removing all pages to ensure that we don't get the
    // transition animations competing with us changing the scroll when we add pages
    disableLayoutTransitions();
    // Recycle the QSB widget
    View qsb = findViewById(R.id.search_container_workspace);
    if (qsb != null) {
        ((ViewGroup) qsb.getParent()).removeView(qsb);
    }
    // Remove the pages and clear the screen models
    removeFolderListeners();
    removeAllViews();
    mScreenOrder.clear();
    mWorkspaceScreens.clear();
    // Remove any deferred refresh callbacks
    mLauncher.mHandler.removeCallbacksAndMessages(DeferredWidgetRefresh.class);
    // Ensure that the first page is always present
    bindAndInitFirstWorkspaceScreen(qsb);
    // Re-enable the layout transitions
    enableLayoutTransitions();
}
Also used : ViewGroup(android.view.ViewGroup) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView)

Example 52 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project Neo-Launcher by NeoApplications.

the class AddWorkspaceItemsTaskTest method testAddItem_some_items_added.

@Test
public void testAddItem_some_items_added() throws Exception {
    WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.intent = new Intent().setComponent(mComponent1);
    WorkspaceItemInfo info2 = new WorkspaceItemInfo();
    info2.intent = new Intent().setComponent(mComponent2);
    // Setup a screen with a hole
    setupWorkspaceWithHoles(1, 1, new Rect(2, 2, 3, 3));
    executeTaskForTest(newTask(info, info2)).get(0).run();
    ArgumentCaptor<ArrayList> notAnimated = ArgumentCaptor.forClass(ArrayList.class);
    ArgumentCaptor<ArrayList> animated = ArgumentCaptor.forClass(ArrayList.class);
    // only info2 should be added because info was already added to the workspace
    // in setupWorkspaceWithHoles()
    verify(callbacks).bindAppsAdded(any(IntArray.class), notAnimated.capture(), animated.capture());
    assertTrue(notAnimated.getValue().isEmpty());
    assertEquals(1, animated.getValue().size());
    assertTrue(animated.getValue().contains(info2));
}
Also used : Rect(android.graphics.Rect) IntArray(com.android.launcher3.util.IntArray) ArrayList(java.util.ArrayList) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) Test(org.junit.Test)

Example 53 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project Neo-Launcher by NeoApplications.

the class BaseModelUpdateTaskTestCase method setUp.

@Before
public void setUp() throws Exception {
    ShadowLog.stream = System.out;
    mProvider = Robolectric.setupContentProvider(TestLauncherProvider.class);
    ShadowContentResolver.registerProviderInternal(LauncherProvider.AUTHORITY, mProvider);
    callbacks = mock(Callbacks.class);
    appState = mock(LauncherAppState.class);
    model = mock(LauncherModel.class);
    modelWriter = mock(ModelWriter.class);
    when(appState.getModel()).thenReturn(model);
    when(model.getWriter(anyBoolean(), anyBoolean())).thenReturn(modelWriter);
    when(model.getCallback()).thenReturn(callbacks);
    myUser = Process.myUserHandle();
    bgDataModel = new BgDataModel();
    targetContext = RuntimeEnvironment.application;
    idp = new InvariantDeviceProfile();
    iconCache = new MyIconCache(targetContext, idp);
    allAppsList = new AllAppsList(iconCache, new AppFilter());
    when(appState.getIconCache()).thenReturn(iconCache);
    when(appState.getInvariantDeviceProfile()).thenReturn(idp);
    when(appState.getContext()).thenReturn(targetContext);
}
Also used : LauncherModel(com.android.launcher3.LauncherModel) AppFilter(com.android.launcher3.AppFilter) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) LauncherAppState(com.android.launcher3.LauncherAppState) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) TestLauncherProvider(com.android.launcher3.util.TestLauncherProvider) Before(org.junit.Before)

Example 54 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project Neo-Launcher by NeoApplications.

the class LauncherModel method forceReload.

/**
 * Reloads the workspace items from the DB and re-binds the workspace. This should generally
 * not be called as DB updates are automatically followed by UI update
 *
 * @param synchronousBindPage The page to bind first. Can pass -1 to use the current page.
 */
public void forceReload(int synchronousBindPage) {
    synchronized (mLock) {
        // Stop any existing loaders first, so they don't set mModelLoaded to true later
        stopLoader();
        mModelLoaded = false;
    }
    // Start the loader if launcher is already running, otherwise the loader will run,
    // the next time launcher starts
    Callbacks callbacks = getCallback();
    if (callbacks != null) {
        if (synchronousBindPage < 0) {
            synchronousBindPage = callbacks.getCurrentWorkspaceScreen();
        }
        startLoader(synchronousBindPage);
    }
}
Also used : Callbacks(com.android.launcher3.model.BgDataModel.Callbacks)

Example 55 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project android_packages_apps_Trebuchet by LineageOS.

the class AddWorkspaceItemsTaskTest method testAddItem_some_items_added.

@Test
public void testAddItem_some_items_added() throws Exception {
    Callbacks callbacks = mock(Callbacks.class);
    mModelHelper.getModel().addCallbacks(callbacks);
    WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.intent = new Intent().setComponent(mComponent1);
    WorkspaceItemInfo info2 = new WorkspaceItemInfo();
    info2.intent = new Intent().setComponent(mComponent2);
    // Setup a screen with a hole
    setupWorkspaceWithHoles(1, 1, new Rect(2, 2, 3, 3));
    mModelHelper.executeTaskForTest(newTask(info, info2)).get(0).run();
    ArgumentCaptor<ArrayList> notAnimated = ArgumentCaptor.forClass(ArrayList.class);
    ArgumentCaptor<ArrayList> animated = ArgumentCaptor.forClass(ArrayList.class);
    // only info2 should be added because info was already added to the workspace
    // in setupWorkspaceWithHoles()
    verify(callbacks).bindAppsAdded(any(IntArray.class), notAnimated.capture(), animated.capture());
    assertTrue(notAnimated.getValue().isEmpty());
    assertEquals(1, animated.getValue().size());
    assertTrue(animated.getValue().contains(info2));
}
Also used : Rect(android.graphics.Rect) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) IntArray(com.android.launcher3.util.IntArray) ArrayList(java.util.ArrayList) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Test(org.junit.Test)

Aggregations

Callbacks (com.android.launcher3.model.BgDataModel.Callbacks)39 ArrayList (java.util.ArrayList)22 IntArray (com.android.launcher3.util.IntArray)21 ItemInfo (com.android.launcher3.model.data.ItemInfo)18 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)18 Nullable (androidx.annotation.Nullable)16 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)13 AppInfo (com.android.launcher3.model.data.AppInfo)11 CallbackTask (com.android.launcher3.LauncherModel.CallbackTask)9 Animator (android.animation.Animator)8 AnimatorSet (android.animation.AnimatorSet)8 Intent (android.content.Intent)7 ApplicationInfo (android.content.pm.ApplicationInfo)7 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)7 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)7 PackageManager (android.content.pm.PackageManager)7 Rect (android.graphics.Rect)7 LauncherAppState (com.android.launcher3.LauncherAppState)7 LauncherModel (com.android.launcher3.LauncherModel)7 LoaderResults (com.android.launcher3.model.LoaderResults)7