Search in sources :

Example 21 with View

use of android.view.View in project Launcher3 by chislon.

the class Workspace method updateShortcuts.

void updateShortcuts(ArrayList<AppInfo> apps) {
    ArrayList<ShortcutAndWidgetContainer> childrenLayouts = getAllShortcutAndWidgetContainers();
    for (ShortcutAndWidgetContainer layout : childrenLayouts) {
        int childCount = layout.getChildCount();
        for (int j = 0; j < childCount; j++) {
            final View view = layout.getChildAt(j);
            Object tag = view.getTag();
            if (LauncherModel.isShortcutInfoUpdateable((ItemInfo) tag)) {
                ShortcutInfo info = (ShortcutInfo) tag;
                final Intent intent = info.intent;
                final ComponentName name = intent.getComponent();
                final int appCount = apps.size();
                for (int k = 0; k < appCount; k++) {
                    AppInfo app = apps.get(k);
                    if (app.componentName.equals(name)) {
                        BubbleTextView shortcut = (BubbleTextView) view;
                        info.updateIcon(mIconCache);
                        info.title = app.title.toString();
                        shortcut.applyFromShortcutInfo(info, mIconCache);
                    }
                }
            }
        }
    }
}
Also used : Intent(android.content.Intent) ComponentName(android.content.ComponentName) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) Point(android.graphics.Point)

Example 22 with View

use of android.view.View in project Launcher3 by chislon.

the class Workspace method onDrop.

public void onDrop(final DragObject d) {
    mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, mDragViewVisualCenter);
    CellLayout dropTargetLayout = mDropToLayout;
    // We want the point to be mapped to the dragTarget.
    if (dropTargetLayout != null) {
        if (mLauncher.isHotseatLayout(dropTargetLayout)) {
            mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
        } else {
            mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null);
        }
    }
    int snapScreen = -1;
    boolean resizeOnDrop = false;
    if (d.dragSource != this) {
        final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1] };
        onDropExternal(touchXY, d.dragInfo, dropTargetLayout, false, d);
    } else if (mDragInfo != null) {
        final View cell = mDragInfo.cell;
        Runnable resizeRunnable = null;
        if (dropTargetLayout != null && !d.cancelled) {
            // Move internally
            boolean hasMovedLayouts = (getParentCellLayoutForView(cell) != dropTargetLayout);
            boolean hasMovedIntoHotseat = mLauncher.isHotseatLayout(dropTargetLayout);
            long container = hasMovedIntoHotseat ? LauncherSettings.Favorites.CONTAINER_HOTSEAT : LauncherSettings.Favorites.CONTAINER_DESKTOP;
            long screenId = (mTargetCell[0] < 0) ? mDragInfo.screenId : getIdForScreen(dropTargetLayout);
            int spanX = mDragInfo != null ? mDragInfo.spanX : 1;
            int spanY = mDragInfo != null ? mDragInfo.spanY : 1;
            // First we find the cell nearest to point at which the item is
            // dropped, without any consideration to whether there is an item there.
            mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], spanX, spanY, dropTargetLayout, mTargetCell);
            float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
            // cell also contains a shortcut, then create a folder with the two shortcuts.
            if (!mInScrollArea && createUserFolderIfNecessary(cell, container, dropTargetLayout, mTargetCell, distance, false, d.dragView, null)) {
                stripEmptyScreens();
                return;
            }
            if (addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell, distance, d, false)) {
                stripEmptyScreens();
                return;
            }
            // Aside from the special case where we're dropping a shortcut onto a shortcut,
            // we need to find the nearest cell location that is vacant
            ItemInfo item = (ItemInfo) d.dragInfo;
            int minSpanX = item.spanX;
            int minSpanY = item.spanY;
            if (item.minSpanX > 0 && item.minSpanY > 0) {
                minSpanX = item.minSpanX;
                minSpanY = item.minSpanY;
            }
            int[] resultSpan = new int[2];
            mTargetCell = dropTargetLayout.createArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP);
            boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0;
            // if the widget resizes on drop
            if (foundCell && (cell instanceof AppWidgetHostView) && (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY)) {
                resizeOnDrop = true;
                item.spanX = resultSpan[0];
                item.spanY = resultSpan[1];
                AppWidgetHostView awhv = (AppWidgetHostView) cell;
                AppWidgetResizeFrame.updateWidgetSizeRanges(awhv, mLauncher, resultSpan[0], resultSpan[1]);
            }
            if (getScreenIdForPageIndex(mCurrentPage) != screenId && !hasMovedIntoHotseat) {
                snapScreen = getPageIndexForScreenId(screenId);
                snapToPage(snapScreen);
            }
            if (foundCell) {
                final ItemInfo info = (ItemInfo) cell.getTag();
                if (hasMovedLayouts) {
                    // Reparent the view
                    getParentCellLayoutForView(cell).removeView(cell);
                    addInScreen(cell, container, screenId, mTargetCell[0], mTargetCell[1], info.spanX, info.spanY);
                }
                // update the item's position after drop
                CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
                lp.cellX = lp.tmpCellX = mTargetCell[0];
                lp.cellY = lp.tmpCellY = mTargetCell[1];
                lp.cellHSpan = item.spanX;
                lp.cellVSpan = item.spanY;
                lp.isLockedToGrid = true;
                cell.setId(LauncherModel.getCellLayoutChildId(container, mDragInfo.screenId, mTargetCell[0], mTargetCell[1], mDragInfo.spanX, mDragInfo.spanY));
                if (container != LauncherSettings.Favorites.CONTAINER_HOTSEAT && cell instanceof LauncherAppWidgetHostView) {
                    final CellLayout cellLayout = dropTargetLayout;
                    // We post this call so that the widget has a chance to be placed
                    // in its final location
                    final LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) cell;
                    AppWidgetProviderInfo pinfo = hostView.getAppWidgetInfo();
                    if (pinfo != null && pinfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE) {
                        final Runnable addResizeFrame = new Runnable() {

                            public void run() {
                                DragLayer dragLayer = mLauncher.getDragLayer();
                                dragLayer.addResizeFrame(info, hostView, cellLayout);
                            }
                        };
                        resizeRunnable = (new Runnable() {

                            public void run() {
                                if (!isPageMoving()) {
                                    addResizeFrame.run();
                                } else {
                                    mDelayedResizeRunnable = addResizeFrame;
                                }
                            }
                        });
                    }
                }
                LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, lp.cellX, lp.cellY, item.spanX, item.spanY);
            } else {
                // If we can't find a drop location, we return the item to its original position
                CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
                mTargetCell[0] = lp.cellX;
                mTargetCell[1] = lp.cellY;
                CellLayout layout = (CellLayout) cell.getParent().getParent();
                layout.markCellsAsOccupiedForView(cell);
            }
        }
        final CellLayout parent = (CellLayout) cell.getParent().getParent();
        final Runnable finalResizeRunnable = resizeRunnable;
        // Prepare it to be animated into its new position
        // This must be called after the view has been re-parented
        final Runnable onCompleteRunnable = new Runnable() {

            @Override
            public void run() {
                mAnimatingViewIntoPlace = false;
                updateChildrenLayersEnabled(false);
                if (finalResizeRunnable != null) {
                    finalResizeRunnable.run();
                }
                stripEmptyScreens();
            }
        };
        mAnimatingViewIntoPlace = true;
        if (d.dragView.hasDrawn()) {
            final ItemInfo info = (ItemInfo) cell.getTag();
            if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) {
                int animationType = resizeOnDrop ? ANIMATE_INTO_POSITION_AND_RESIZE : ANIMATE_INTO_POSITION_AND_DISAPPEAR;
                animateWidgetDrop(info, parent, d.dragView, onCompleteRunnable, animationType, cell, false);
            } else {
                int duration = snapScreen < 0 ? -1 : ADJACENT_SCREEN_DROP_DURATION;
                mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, onCompleteRunnable, this);
            }
        } else {
            d.deferDragViewCleanupPostAnimation = false;
            cell.setVisibility(VISIBLE);
        }
        parent.onDropChild(cell);
    }
}
Also used : View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) Point(android.graphics.Point) AppWidgetHostView(android.appwidget.AppWidgetHostView) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 23 with View

use of android.view.View in project Launcher3 by chislon.

the class Workspace method getPageIndicatorClickListener.

@Override
protected OnClickListener getPageIndicatorClickListener() {
    AccessibilityManager am = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (!am.isTouchExplorationEnabled()) {
        return null;
    }
    OnClickListener listener = new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            enterOverviewMode();
        }
    };
    return listener;
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) OnClickListener(android.view.View.OnClickListener) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView)

Example 24 with View

use of android.view.View in project Launcher3 by chislon.

the class PagedViewWithDraggableItems method determineDraggingStart.

/*
     * Determines if we should change the touch state to start dragging after the
     * user moves their touch point far enough.
     */
protected void determineDraggingStart(MotionEvent ev) {
    /*
         * Locally do absolute value. mLastMotionX is set to the y value
         * of the down event.
         */
    final int pointerIndex = ev.findPointerIndex(mActivePointerId);
    final float x = ev.getX(pointerIndex);
    final float y = ev.getY(pointerIndex);
    final int xDiff = (int) Math.abs(x - mLastMotionX);
    final int yDiff = (int) Math.abs(y - mLastMotionY);
    final int touchSlop = mTouchSlop;
    boolean yMoved = yDiff > touchSlop;
    boolean isUpwardMotion = (yDiff / (float) xDiff) > mDragSlopeThreshold;
    if (isUpwardMotion && yMoved && mLastTouchedItem != null) {
        // Drag if the user moved far enough along the Y axis
        beginDragging(mLastTouchedItem);
        // Cancel any pending long press
        if (mAllowLongPress) {
            mAllowLongPress = false;
            // Try canceling the long press. It could also have been scheduled
            // by a distant descendant, so use the mAllowLongPress flag to block
            // everything
            final View currentPage = getPageAt(mCurrentPage);
            if (currentPage != null) {
                currentPage.cancelLongPress();
            }
        }
    }
}
Also used : View(android.view.View)

Example 25 with View

use of android.view.View in project Launcher3 by chislon.

the class ShortcutAndWidgetContainer method setChildrenDrawingCacheEnabled.

@Override
protected void setChildrenDrawingCacheEnabled(boolean enabled) {
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View view = getChildAt(i);
        view.setDrawingCacheEnabled(enabled);
        // Update the drawing caches
        if (!view.isHardwareAccelerated() && enabled) {
            view.buildDrawingCache(true);
        }
    }
}
Also used : View(android.view.View) Paint(android.graphics.Paint)

Aggregations

View (android.view.View)17009 TextView (android.widget.TextView)5834 ImageView (android.widget.ImageView)3323 ListView (android.widget.ListView)2098 RecyclerView (android.support.v7.widget.RecyclerView)1838 AdapterView (android.widget.AdapterView)1715 ViewGroup (android.view.ViewGroup)1568 Intent (android.content.Intent)1026 Paint (android.graphics.Paint)951 Button (android.widget.Button)876 OnClickListener (android.view.View.OnClickListener)808 AbsListView (android.widget.AbsListView)795 LayoutInflater (android.view.LayoutInflater)771 LinearLayout (android.widget.LinearLayout)656 ArrayList (java.util.ArrayList)638 RemoteView (android.widget.RemoteViews.RemoteView)600 ScrollView (android.widget.ScrollView)566 Rect (android.graphics.Rect)534 SuppressLint (android.annotation.SuppressLint)433 Context (android.content.Context)405