Example usage for android.view View getTag

List of usage examples for android.view View getTag

Introduction

In this page you can find the example usage for android.view View getTag.

Prototype

@ViewDebug.ExportedProperty
public Object getTag() 

Source Link

Document

Returns this view's tag.

Usage

From source file:com.android.launcher3.Launcher.java

private void startAppShortcutOrInfoActivity(View v) {
    ItemInfo item = (ItemInfo) v.getTag();
    Intent intent = item.getIntent();/*from   w w w. j  a  v a 2 s  .c o m*/
    if (intent == null) {
        throw new IllegalArgumentException("Input must have a valid intent");
    }
    boolean success = startActivitySafely(v, intent, item);
    getUserEventDispatcher().logAppLaunch(v, intent);

    if (success && v instanceof BubbleTextView) {
        mWaitingForResume = (BubbleTextView) v;
        mWaitingForResume.setStayPressed(true);
    }
}

From source file:com.android.launcher3.Launcher.java

/**
 * Event handler for an app shortcut click.
 *
 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
 *//*ww w  .  j  a va 2  s  . c  o  m*/
protected void onClickAppShortcut(final View v) {
    if (LOGD)
        Log.d(TAG, "onClickAppShortcut");
    Object tag = v.getTag();
    if (!(tag instanceof ShortcutInfo)) {
        throw new IllegalArgumentException("Input must be a Shortcut");
    }

    // Open shortcut
    final ShortcutInfo shortcut = (ShortcutInfo) tag;

    if (shortcut.isDisabled != 0) {
        if ((shortcut.isDisabled & ~ShortcutInfo.FLAG_DISABLED_SUSPENDED
                & ~ShortcutInfo.FLAG_DISABLED_QUIET_USER) == 0) {
            // If the app is only disabled because of the above flags, launch activity anyway.
            // Framework will tell the user why the app is suspended.
        } else {
            if (!TextUtils.isEmpty(shortcut.disabledMessage)) {
                // Use a message specific to this shortcut, if it has one.
                Toast.makeText(this, shortcut.disabledMessage, Toast.LENGTH_SHORT).show();
                return;
            }
            // Otherwise just use a generic error message.
            int error = R.string.activity_not_available;
            if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
                error = R.string.safemode_shortcut_error;
            } else if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_BY_PUBLISHER) != 0
                    || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_LOCKED_USER) != 0) {
                error = R.string.shortcut_not_available;
            }
            Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
            return;
        }
    }

    // Check for abandoned promise
    if ((v instanceof BubbleTextView) && shortcut.isPromise()
            && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
        showBrokenAppInstallDialog(shortcut.getTargetComponent().getPackageName(),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        startAppShortcutOrInfoActivity(v);
                    }
                });
        return;
    }

    // Start activities
    startAppShortcutOrInfoActivity(v);
}

From source file:com.android.launcher3.Launcher.java

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *//*from w  w  w  .  ja v a2  s  .co m*/
@Override
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        final View view;
        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
        case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            view = createShortcut(info);
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            view = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }

        /*
        * Remove colliding items.
        */
        if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
            CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
            if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                View v = cl.getChildAt(item.cellX, item.cellY);
                Object tag = v.getTag();
                String desc = "Collision while binding workspace item: " + item + ". Collides with " + tag;
                if (ProviderConfig.IS_DOGFOOD_BUILD) {
                    throw (new RuntimeException(desc));
                } else {
                    Log.d(TAG, desc);
                    LauncherModel.deleteItemFromDatabase(this, item);
                    continue;
                }
            }
        }
        workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX, item.cellY, 1, 1);
        if (animateIcons) {
            // Animate all the applications up now
            view.setAlpha(0f);
            view.setScaleX(0f);
            view.setScaleY(0f);
            bounceAnims.add(createNewAppBounceAnimation(view, i));
            newShortcutsScreenId = item.screenId;
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.snapToPage(newScreenIndex);
                            mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                        }
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}

From source file:com.android.launcher3.Launcher.java

/**
 * Unbinds the view for the specified item, and removes the item and all its children.
 *
 * @param v the view being removed.//from w  w w.j  a  v  a  2s  .c o  m
 * @param itemInfo the {@link ItemInfo} for this view.
 * @param deleteFromDb whether or not to delete this item from the db.
 */
public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
    if (itemInfo instanceof ShortcutInfo) {
        // Remove the shortcut from the folder before removing it from launcher
        View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
        if (folderIcon instanceof FolderIcon) {
            ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true);
        } else {
            mWorkspace.removeWorkspaceItem(v);
        }
        if (deleteFromDb) {
            LauncherModel.deleteItemFromDatabase(this, itemInfo);
        }
    } else if (itemInfo instanceof FolderInfo) {
        final FolderInfo folderInfo = (FolderInfo) itemInfo;
        if (v instanceof FolderIcon) {
            ((FolderIcon) v).removeListeners();
        }
        mWorkspace.removeWorkspaceItem(v);
        if (deleteFromDb) {
            LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
        }
    } else if (itemInfo instanceof LauncherAppWidgetInfo) {
        final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
        mWorkspace.removeWorkspaceItem(v);
        removeWidgetToAutoAdvance(v);
        if (deleteFromDb) {
            deleteWidgetInfo(widgetInfo);
        }
    } else {
        return false;
    }
    return true;
}

From source file:cc.flydev.launcher.Workspace.java

boolean createUserFolderIfNecessary(View newView, long container, CellLayout target, int[] targetCell,
        float distance, boolean external, DragView dragView, Runnable postAnimationRunnable) {
    if (distance > mMaxDistanceForFolderCreation)
        return false;
    View v = target.getChildAt(targetCell[0], targetCell[1]);

    boolean hasntMoved = false;
    if (mDragInfo != null) {
        CellLayout cellParent = getParentCellLayoutForView(mDragInfo.cell);
        hasntMoved = (mDragInfo.cellX == targetCell[0] && mDragInfo.cellY == targetCell[1])
                && (cellParent == target);
    }/*www .j  a  v  a  2s.c  o m*/

    if (v == null || hasntMoved || !mCreateUserFolderOnDrop)
        return false;
    mCreateUserFolderOnDrop = false;
    final long screenId = (targetCell == null) ? mDragInfo.screenId : getIdForScreen(target);

    boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo);
    boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo);

    if (aboveShortcut && willBecomeShortcut) {
        ShortcutInfo sourceInfo = (ShortcutInfo) newView.getTag();
        ShortcutInfo destInfo = (ShortcutInfo) v.getTag();
        // if the drag started here, we need to remove it from the workspace
        if (!external) {
            getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell);
        }

        Rect folderLocation = new Rect();
        float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation);
        target.removeView(v);

        FolderIcon fi = mLauncher.addFolder(target, container, screenId, targetCell[0], targetCell[1]);
        destInfo.cellX = -1;
        destInfo.cellY = -1;
        sourceInfo.cellX = -1;
        sourceInfo.cellY = -1;

        // If the dragView is null, we can't animate
        boolean animate = dragView != null;
        if (animate) {
            fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale,
                    postAnimationRunnable);
        } else {
            fi.addItem(destInfo);
            fi.addItem(sourceInfo);
        }
        return true;
    }
    return false;
}

From source file:cc.flydev.launcher.Workspace.java

boolean willCreateUserFolder(ItemInfo info, CellLayout target, int[] targetCell, float distance,
        boolean considerTimeout) {
    if (distance > mMaxDistanceForFolderCreation)
        return false;
    View dropOverView = target.getChildAt(targetCell[0], targetCell[1]);

    if (dropOverView != null) {
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams();
        if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.tmpCellY)) {
            return false;
        }/*from   ww  w  .  j a  va  2s .c  o  m*/
    }

    boolean hasntMoved = false;
    if (mDragInfo != null) {
        hasntMoved = dropOverView == mDragInfo.cell;
    }

    if (dropOverView == null || hasntMoved || (considerTimeout && !mCreateUserFolderOnDrop)) {
        return false;
    }

    boolean aboveShortcut = (dropOverView.getTag() instanceof ShortcutInfo);
    boolean willBecomeShortcut = (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
            || info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT);

    return (aboveShortcut && willBecomeShortcut);
}

From source file:com.android.launcher4.Workspace.java

/**
 * Removes items that match the item info specified. When applications are removed
 * as a part of an update, this is called to ensure that other widgets and application
 * shortcuts are not removed.// w  w  w  . j av a2  s  .c  o  m
 */
void removeItemsByComponentName(final HashSet<ComponentName> componentNames, final UserHandleCompat user) {
    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (final CellLayout layoutParent : cellLayouts) {
        final ViewGroup layout = layoutParent.getShortcutsAndWidgets();

        final HashMap<ItemInfo, View> children = new HashMap<ItemInfo, View>();
        for (int j = 0; j < layout.getChildCount(); j++) {
            final View view = layout.getChildAt(j);
            children.put((ItemInfo) view.getTag(), view);
        }

        final ArrayList<View> childrenToRemove = new ArrayList<View>();
        final HashMap<FolderInfo, ArrayList<ShortcutInfo>> folderAppsToRemove = new HashMap<FolderInfo, ArrayList<ShortcutInfo>>();
        LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() {
            @Override
            public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
                if (parent instanceof FolderInfo) {
                    if (componentNames.contains(cn) && info.user.equals(user)) {
                        FolderInfo folder = (FolderInfo) parent;
                        ArrayList<ShortcutInfo> appsToRemove;
                        if (folderAppsToRemove.containsKey(folder)) {
                            appsToRemove = folderAppsToRemove.get(folder);
                        } else {
                            appsToRemove = new ArrayList<ShortcutInfo>();
                            folderAppsToRemove.put(folder, appsToRemove);
                        }
                        appsToRemove.add((ShortcutInfo) info);
                        return true;
                    }
                } else {
                    if (componentNames.contains(cn) && info.user.equals(user)) {
                        childrenToRemove.add(children.get(info));
                        return true;
                    }
                }
                return false;
            }
        };
        LauncherModel.filterItemInfos(children.keySet(), filter);

        // Remove all the apps from their folders
        for (FolderInfo folder : folderAppsToRemove.keySet()) {
            ArrayList<ShortcutInfo> appsToRemove = folderAppsToRemove.get(folder);
            for (ShortcutInfo info : appsToRemove) {
                folder.remove(info);
            }
        }

        // Remove all the other children
        for (View child : childrenToRemove) {
            // Note: We can not remove the view directly from CellLayoutChildren as this
            // does not re-mark the spaces as unoccupied.
            layoutParent.removeViewInLayout(child);
            if (child instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) child);
            }
        }

        if (childrenToRemove.size() > 0) {
            layout.requestLayout();
            layout.invalidate();
        }
    }

    // Strip all the empty screens
    stripEmptyScreens();
}

From source file:com.android.launcher3.Workspace.java

protected void reinflateWidgetsIfNecessary() {
    final int clCount = getChildCount();
    for (int i = 0; i < clCount; i++) {
        CellLayout cl = (CellLayout) getChildAt(i);
        ShortcutAndWidgetContainer swc = cl.getShortcutsAndWidgets();
        final int itemCount = swc.getChildCount();
        for (int j = 0; j < itemCount; j++) {
            View v = swc.getChildAt(j);

            if (v != null && v.getTag() instanceof LauncherAppWidgetInfo) {
                LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
                LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) info.hostView;
                if (lahv != null && lahv.isReinflateRequired()) {
                    mLauncher.removeAppWidget(info);
                    // Remove the current widget which is inflated with the wrong orientation
                    cl.removeView(lahv);
                    mLauncher.bindAppWidget(info);
                }/*from  w  w  w.  ja va  2  s  .  c  om*/
            }
        }
    }
}

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

public boolean createUserFolderIfNecessary(View newView, long container, CellLayout target, int[] targetCell,
        float distance, boolean external, DragView dragView, Runnable postAnimationRunnable) {
    if (distance > mMaxDistanceForFolderCreation)
        return false;
    View v = target.getChildAt(targetCell[0], targetCell[1]);

    boolean hasntMoved = false;
    if (mDragInfo != null) {
        CellLayout cellParent = getParentCellLayoutForView(mDragInfo.cell);
        hasntMoved = (mDragInfo.cellX == targetCell[0] && mDragInfo.cellY == targetCell[1])
                && (cellParent == target);
    }//from  www  .java 2 s . c o  m

    if (v == null || hasntMoved || !mCreateUserFolderOnDrop)
        return false;
    mCreateUserFolderOnDrop = false;
    final long screenId = (targetCell == null) ? mDragInfo.screenId : getIdForScreen(target);

    boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo);
    boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo);

    if (aboveShortcut && willBecomeShortcut) {
        ShortcutInfo sourceInfo = (ShortcutInfo) newView.getTag();
        ShortcutInfo destInfo = (ShortcutInfo) v.getTag();
        // if the drag started here, we need to remove it from the workspace
        if (!external) {
            getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell);
        }

        Rect folderLocation = new Rect();
        float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation);
        target.removeView(v);

        FolderIcon fi = mLauncher.addFolder(target, container, screenId, targetCell[0], targetCell[1]);
        destInfo.cellX = -1;
        destInfo.cellY = -1;
        sourceInfo.cellX = -1;
        sourceInfo.cellY = -1;

        // If the dragView is null, we can't animate
        boolean animate = dragView != null;
        if (animate) {
            fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale,
                    postAnimationRunnable);
        } else {
            fi.addItem(destInfo);
            fi.addItem(sourceInfo);
        }
        return true;
    }
    return false;
}

From source file:com.android.launcher3.Workspace.java

void removeItemsByPackageName(final ArrayList<String> packages, final UserHandleCompat user) {
    final HashSet<String> packageNames = new HashSet<String>();
    packageNames.addAll(packages);//from w  ww . j  a  v a 2  s .c o m

    // Filter out all the ItemInfos that this is going to affect
    final HashSet<ItemInfo> infos = new HashSet<ItemInfo>();
    final HashSet<ComponentName> cns = new HashSet<ComponentName>();
    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (CellLayout layoutParent : cellLayouts) {
        ViewGroup layout = layoutParent.getShortcutsAndWidgets();
        int childCount = layout.getChildCount();
        for (int i = 0; i < childCount; ++i) {
            View view = layout.getChildAt(i);
            infos.add((ItemInfo) view.getTag());
        }
    }
    LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() {
        @Override
        public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
            if (packageNames.contains(cn.getPackageName()) && info.user.equals(user)) {
                cns.add(cn);
                return true;
            }
            return false;
        }
    };
    LauncherModel.filterItemInfos(infos, filter);

    // Remove the affected components
    removeItemsByComponentName(cns, user);
}