Search in sources :

Example 26 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class UserLockStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    Context context = app.getContext();
    HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
    if (mIsUserUnlocked) {
        QueryResult shortcuts = new ShortcutRequest(context, mUser).query(ShortcutRequest.PINNED);
        if (shortcuts.wasSuccess()) {
            for (ShortcutInfo shortcut : shortcuts) {
                pinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut);
            }
        } else {
            // Shortcut manager can fail due to some race condition when the lock state
            // changes too frequently. For the purpose of the update,
            // consider it as still locked.
            mIsUserUnlocked = false;
        }
    }
    // Update the workspace to reflect the changes to updated shortcuts residing on it.
    ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
    HashSet<ShortcutKey> removedKeys = new HashSet<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                if (mIsUserUnlocked) {
                    ShortcutKey key = ShortcutKey.fromItemInfo(si);
                    ShortcutInfo shortcut = pinnedShortcuts.get(key);
                    // (probably due to clear data), delete the workspace item as well
                    if (shortcut == null) {
                        removedKeys.add(key);
                        return;
                    }
                    si.runtimeStatusFlags &= ~FLAG_DISABLED_LOCKED_USER;
                    si.updateFromDeepShortcutInfo(shortcut, context);
                    app.getIconCache().getShortcutIcon(si, shortcut);
                } else {
                    si.runtimeStatusFlags |= FLAG_DISABLED_LOCKED_USER;
                }
                updatedWorkspaceItemInfos.add(si);
            }
        });
    }
    bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
    if (!removedKeys.isEmpty()) {
        deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
    }
    // Remove shortcut id map for that user
    Iterator<ComponentKey> keysIter = dataModel.deepShortcutMap.keySet().iterator();
    while (keysIter.hasNext()) {
        if (keysIter.next().user.equals(mUser)) {
            keysIter.remove();
        }
    }
    if (mIsUserUnlocked) {
        dataModel.updateDeepShortcutCounts(null, mUser, new ShortcutRequest(context, mUser).query(ShortcutRequest.ALL));
    }
    bindDeepShortcuts(dataModel);
}
Also used : Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComponentKey(com.android.launcher3.util.ComponentKey) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) QueryResult(com.android.launcher3.shortcuts.ShortcutRequest.QueryResult) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 27 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class BaseDraggingActivity method startActivitySafely.

public boolean startActivitySafely(View v, Intent intent, @Nullable ItemInfo item) {
    if (mIsSafeModeEnabled && !PackageManagerHelper.isSystemApp(this, intent)) {
        Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
        return false;
    }
    Bundle optsBundle = (v != null) ? getActivityLaunchOptions(v, item).toBundle() : null;
    UserHandle user = item == null ? null : item.user;
    // Prepare intent
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (v != null) {
        intent.setSourceBounds(getViewBounds(v));
    }
    try {
        boolean isShortcut = (item instanceof WorkspaceItemInfo) && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) && !((WorkspaceItemInfo) item).isPromise();
        if (isShortcut) {
            // Shortcuts need some special checks due to legacy reasons.
            startShortcutIntentSafely(intent, optsBundle, item);
        } else if (user == null || user.equals(Process.myUserHandle())) {
            // Could be launching some bookkeeping activity
            startActivity(intent, optsBundle);
        } else {
            getSystemService(LauncherApps.class).startMainActivity(intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
        }
        if (item != null) {
            InstanceId instanceId = new InstanceIdSequence().newInstanceId();
            logAppLaunch(item, instanceId);
        }
        return true;
    } catch (NullPointerException | ActivityNotFoundException | SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e);
    }
    return false;
}
Also used : InstanceId(com.android.launcher3.logging.InstanceId) InstanceIdSequence(com.android.launcher3.logging.InstanceIdSequence) ActivityNotFoundException(android.content.ActivityNotFoundException) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 28 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class FolderNameProviderTest method setUp.

@Before
public void setUp() {
    mContext = RuntimeEnvironment.application;
    mItem1 = new WorkspaceItemInfo(new AppInfo(new ComponentName("a.b.c", "a.b.c/a.b.c.d"), "title1", UserHandle.of(10), new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))));
    mItem2 = new WorkspaceItemInfo(new AppInfo(new ComponentName("a.b.c", "a.b.c/a.b.c.d"), "title2", UserHandle.of(10), new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))));
}
Also used : ComponentName(android.content.ComponentName) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AppInfo(com.android.launcher3.model.data.AppInfo) Before(org.junit.Before)

Example 29 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

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)

Example 30 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class AddWorkspaceItemsTaskTest method testAddItem_existing_item_ignored.

@Test
public void testAddItem_existing_item_ignored() throws Exception {
    WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.intent = new Intent().setComponent(mComponent1);
    // Setup a screen with a hole
    setupWorkspaceWithHoles(1, 1, new Rect(2, 2, 3, 3));
    // Nothing was added
    assertTrue(mModelHelper.executeTaskForTest(newTask(info)).isEmpty());
}
Also used : Rect(android.graphics.Rect) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Test(org.junit.Test)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)418 View (android.view.View)168 ArrayList (java.util.ArrayList)145 ItemInfo (com.android.launcher3.model.data.ItemInfo)125 Intent (android.content.Intent)119 FolderInfo (com.android.launcher3.model.data.FolderInfo)100 AppInfo (com.android.launcher3.model.data.AppInfo)94 BubbleTextView (com.android.launcher3.BubbleTextView)87 AppWidgetHostView (android.appwidget.AppWidgetHostView)84 SuppressLint (android.annotation.SuppressLint)78 DragView (com.android.launcher3.dragndrop.DragView)78 ComponentName (android.content.ComponentName)76 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)73 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)72 Rect (android.graphics.Rect)68 FolderIcon (com.android.launcher3.folder.FolderIcon)68 Context (android.content.Context)62 HashSet (java.util.HashSet)62 Point (android.graphics.Point)59 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)57