Example usage for android.view View getLayoutParams

List of usage examples for android.view View getLayoutParams

Introduction

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

Prototype

@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() 

Source Link

Document

Get the LayoutParams associated with this view.

Usage

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

/**
 * <p>Builds the popup window's content and returns the height the popup
 * should have. Returns -1 when the content already exists.</p>
 *
 * @return the content's height or -1 if content already exists
 *//*  w ww.j ava 2s .c  o m*/
private int buildDropDown() {
    ViewGroup dropDownView;
    int otherHeights = 0;

    if (mDropDownList == null) {
        Context context = mContext;

        /**
         * This Runnable exists for the sole purpose of checking if the view layout has got
         * completed and if so call showDropDown to display the drop down. This is used to show
         * the drop down as soon as possible after user opens up the search dialog, without
         * waiting for the normal UI pipeline to do it's job which is slower than this method.
         */
        mShowDropDownRunnable = new Runnable() {
            public void run() {
                // View layout should be all done before displaying the drop down.
                View view = getAnchorView();
                if (view != null && view.getWindowToken() != null) {
                    show();
                }
            }
        };

        mDropDownList = createDropDownListView(context, !mModal);
        if (mDropDownListHighlight != null) {
            mDropDownList.setSelector(mDropDownListHighlight);
        }
        mDropDownList.setAdapter(mAdapter);
        mDropDownList.setOnItemClickListener(mItemClickListener);
        mDropDownList.setFocusable(true);
        mDropDownList.setFocusableInTouchMode(true);
        mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                if (position != -1) {
                    XpDropDownListView dropDownList = mDropDownList;

                    if (dropDownList != null) {
                        dropDownList.setListSelectionHidden(false);
                    }
                }
            }

            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        mDropDownList.setOnScrollListener(mScrollListener);

        if (mItemSelectedListener != null) {
            mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
        }

        dropDownView = mDropDownList;

        View hintView = mPromptView;
        if (hintView != null) {
            // if a hint has been specified, we accomodate more space for it and
            // add a text view in the drop down menu, at the bottom of the list
            LinearLayout hintContainer = new LinearLayout(context);
            hintContainer.setOrientation(LinearLayout.VERTICAL);

            LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f);

            switch (mPromptPosition) {
            case POSITION_PROMPT_BELOW:
                hintContainer.addView(dropDownView, hintParams);
                hintContainer.addView(hintView);
                break;

            case POSITION_PROMPT_ABOVE:
                hintContainer.addView(hintView);
                hintContainer.addView(dropDownView, hintParams);
                break;

            default:
                Log.e(TAG, "Invalid hint position " + mPromptPosition);
                break;
            }

            // Measure the hint's height to find how much more vertical
            // space we need to add to the drop down's height.
            final int widthSize;
            final int widthMode;
            if (mDropDownWidth >= 0) {
                widthMode = MeasureSpec.AT_MOST;
                widthSize = mDropDownWidth > mDropDownMaxWidth ? mDropDownMaxWidth : mDropDownWidth;
                //                    widthSize = mDropDownWidth;
            } else {
                if (mDropDownMaxWidth >= 0) {
                    widthMode = MeasureSpec.AT_MOST;
                    widthSize = mDropDownMaxWidth;
                } else {
                    widthMode = MeasureSpec.UNSPECIFIED;
                    widthSize = 0;
                }
            }
            //noinspection Range
            final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
            final int heightSpec = MeasureSpec.UNSPECIFIED;
            hintView.measure(widthSpec, heightSpec);

            hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams();
            otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;

            dropDownView = hintContainer;
        }

        mPopup.setContentView(dropDownView);
    } else {
        dropDownView = (ViewGroup) mPopup.getContentView();
        final View view = mPromptView;
        if (view != null) {
            LinearLayout.LayoutParams hintParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
        }
    }

    // getMaxAvailableHeight() subtracts the padding, so we put it back
    // to get the available height for the whole window
    int padding = 0;
    Drawable background = mPopup.getBackground();
    if (background != null) {
        background.getPadding(mTempRect);
        padding = mTempRect.top + mTempRect.bottom;

        // If we don't have an explicit vertical offset, determine one from the window
        // background so that content will line up.
        //            if (!mDropDownVerticalOffsetSet) {
        //                mDropDownVerticalOffset = -mTempRect.top;
        //            }
    } else {
        mTempRect.setEmpty();
    }

    final int verticalMargin = mMargins.top + mMargins.bottom;

    // Max height available on the screen for a popup.
    final boolean ignoreBottomDecorations = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
    //        final int maxHeight = getMaxAvailableHeight(getAnchorView(), mDropDownVerticalOffset, ignoreBottomDecorations);
    final int maxHeight = getMaxAvailableHeight(getAnchorView(), ignoreBottomDecorations);
    if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
        return maxHeight - verticalMargin + padding;
    }

    final int childWidthSpec;
    switch (mDropDownWidth) {
    case ViewGroup.LayoutParams.WRAP_CONTENT:
        childWidthSpec = MeasureSpec.makeMeasureSpec(getAnchorView().getWidth()
                - (mMargins.left + mMargins.right) - (mTempRect.left + mTempRect.right), MeasureSpec.AT_MOST);
        break;
    case ViewGroup.LayoutParams.MATCH_PARENT:
        childWidthSpec = MeasureSpec.makeMeasureSpec(mContext.getResources().getDisplayMetrics().widthPixels
                - (mMargins.left + mMargins.right) - (mTempRect.left + mTempRect.right), MeasureSpec.EXACTLY);
        break;
    case PREFERRED:
        int widthSize;
        int widthMode;
        if (mDropDownMaxWidth >= 0) {
            widthSize = mDropDownMaxWidth - (mMargins.left + mMargins.right)
                    - (mTempRect.left + mTempRect.right);
            widthMode = MeasureSpec.AT_MOST;
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
        } else {
            widthMode = MeasureSpec.AT_MOST;
            if (mDropDownMaxWidth == WRAP_CONTENT) {
                widthSize = getAnchorView().getWidth() - (mMargins.left + mMargins.right)
                        - (mTempRect.left + mTempRect.right);
            } else { // MATCH_PARENT
                widthSize = mContext.getResources().getDisplayMetrics().widthPixels
                        - (mMargins.left + mMargins.right) - (mTempRect.left + mTempRect.right);
            }
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
        }
        break;
    default:
        //noinspection Range
        childWidthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.EXACTLY);
        break;
    }

    final int listPadding = mDropDownList.getPaddingTop() + mDropDownList.getPaddingBottom();
    final int listContent = mDropDownList.measureHeightOfChildrenCompat(childWidthSpec, 0,
            XpDropDownListView.NO_POSITION, maxHeight - otherHeights - verticalMargin - listPadding + padding,
            -1);
    // add padding only if the list has items in it, that way we don't show
    // the popup if it is not needed
    if (otherHeights > 0 || listContent > 0)
        otherHeights += padding + listPadding;

    return listContent + otherHeights;
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Obtain a populated view from the adapter. If optScrap is non-null and is not
 * reused it will be placed in the recycle bin.
 *
 * @param position position to get view for
 * @param optScrap Optional scrap view; will be reused if possible
 * @return A new view, a recycled view from mRecycler, or optScrap
 */// w ww .j a  va  2  s .  co m
final View obtainView(int position, View optScrap) {
    View view = mRecycler.getTransientStateView(position);
    final Object item = mAdapter.getItem(position);
    final int positionViewType = mAdapter.getItemViewType(item, position);

    if (view == null) {
        // Reuse optScrap if it's of the right type (and not null)
        final int optType = optScrap != null ? ((LayoutParams) optScrap.getLayoutParams()).viewType : -1;

        final View scrap = optType == positionViewType ? optScrap : mRecycler.getScrapView(positionViewType);

        final int itemColumnSpan = mAdapter.getItemColumnSpan(item, position);
        final int itemWidth = getItemWidth(itemColumnSpan);
        view = mAdapter.getView(item, position, scrap, this, itemWidth);

        if (view != scrap && scrap != null) {
            // The adapter didn't use it; put it back.
            mRecycler.addScrap(scrap);
        }

        ViewGroup.LayoutParams lp = view.getLayoutParams();

        if (view.getParent() != this) {
            if (lp == null) {
                lp = generateDefaultLayoutParams();
            } else if (!checkLayoutParams(lp)) {
                lp = generateLayoutParams(lp);
            }

            view.setLayoutParams(lp);
        }
    }

    final LayoutParams sglp = (LayoutParams) view.getLayoutParams();
    sglp.position = position;
    sglp.viewType = positionViewType;
    final long id = mAdapter.getItemIdFromView(view, position);
    sglp.id = id;
    sglp.span = mAdapter.getItemColumnSpan(item, position);

    // When the view at the positions we are tracking update, make sure to
    // update our views as well. That way, we have the correct
    // rectangle for comparing when the drag target enters/ leaves the
    // placeholder view.
    if (isDragReorderingSupported() && mReorderHelper.getDraggedChildId() == id) {
        mReorderHelper.updateDraggedChildView(view);
        mReorderHelper.updateDraggedOverChildView(view);
    }

    return view;
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

/**
 * {@inheritDoc}//from w w  w.jav  a  2  s. com
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (DEBUG)
        Log.v(TAG, "onCreateView");

    resolveTheme();
    inflater = getThemeInflater(inflater);

    GuidedStepRootLayout root = (GuidedStepRootLayout) inflater.inflate(R.layout.lb_guidedstep_fragment,
            container, false);

    root.setFocusOutStart(isFocusOutStartAllowed());
    root.setFocusOutEnd(isFocusOutEndAllowed());

    ViewGroup guidanceContainer = (ViewGroup) root.findViewById(R.id.content_fragment);
    ViewGroup actionContainer = (ViewGroup) root.findViewById(R.id.action_fragment);

    Guidance guidance = onCreateGuidance(savedInstanceState);
    View guidanceView = mGuidanceStylist.onCreateView(inflater, guidanceContainer, guidance);
    guidanceContainer.addView(guidanceView);

    View actionsView = mActionsStylist.onCreateView(inflater, actionContainer);
    actionContainer.addView(actionsView);

    View buttonActionsView = mButtonActionsStylist.onCreateView(inflater, actionContainer);
    actionContainer.addView(buttonActionsView);

    GuidedActionAdapter.EditListener editListener = new GuidedActionAdapter.EditListener() {

        @Override
        public void onImeOpen() {
            runImeAnimations(true);
        }

        @Override
        public void onImeClose() {
            runImeAnimations(false);
        }

        @Override
        public long onGuidedActionEditedAndProceed(GuidedAction action) {
            return GuidedStepFragment.this.onGuidedActionEditedAndProceed(action);
        }

        @Override
        public void onGuidedActionEditCanceled(GuidedAction action) {
            GuidedStepFragment.this.onGuidedActionEditCanceled(action);
        }
    };

    mAdapter = new GuidedActionAdapter(mActions, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            GuidedStepFragment.this.onGuidedActionClicked(action);
            if (isSubActionsExpanded()) {
                collapseSubActions();
            } else if (action.hasSubActions()) {
                expandSubActions(action);
            }
        }
    }, this, mActionsStylist, false);
    mButtonAdapter = new GuidedActionAdapter(mButtonActions, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            GuidedStepFragment.this.onGuidedActionClicked(action);
        }
    }, this, mButtonActionsStylist, false);
    mSubAdapter = new GuidedActionAdapter(null, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            if (mActionsStylist.isInExpandTransition()) {
                return;
            }
            if (GuidedStepFragment.this.onSubGuidedActionClicked(action)) {
                collapseSubActions();
            }
        }
    }, this, mActionsStylist, true);
    mAdapterGroup = new GuidedActionAdapterGroup();
    mAdapterGroup.addAdpter(mAdapter, mButtonAdapter);
    mAdapterGroup.addAdpter(mSubAdapter, null);
    mAdapterGroup.setEditListener(editListener);
    mActionsStylist.setEditListener(editListener);

    mActionsStylist.getActionsGridView().setAdapter(mAdapter);
    if (mActionsStylist.getSubActionsGridView() != null) {
        mActionsStylist.getSubActionsGridView().setAdapter(mSubAdapter);
    }
    mButtonActionsStylist.getActionsGridView().setAdapter(mButtonAdapter);
    if (mButtonActions.size() == 0) {
        // when there is no button actions, we dont need show the second panel, but keep
        // the width zero to run ChangeBounds transition.
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) buttonActionsView.getLayoutParams();
        lp.weight = 0;
        buttonActionsView.setLayoutParams(lp);
    } else {
        // when there are two actions panel, we need adjust the weight of action to
        // guidedActionContentWidthWeightTwoPanels.
        Context ctx = mThemeWrapper != null ? mThemeWrapper : getActivity();
        TypedValue typedValue = new TypedValue();
        if (ctx.getTheme().resolveAttribute(R.attr.guidedActionContentWidthWeightTwoPanels, typedValue, true)) {
            View actionsRoot = root.findViewById(R.id.action_fragment_root);
            float weight = typedValue.getFloat();
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) actionsRoot.getLayoutParams();
            lp.weight = weight;
            actionsRoot.setLayoutParams(lp);
        }
    }

    int pos = (mSelectedIndex >= 0 && mSelectedIndex < mActions.size()) ? mSelectedIndex
            : getFirstCheckedAction();
    setSelectedActionPosition(pos);

    setSelectedButtonActionPosition(0);

    // Add the background view.
    View backgroundView = onCreateBackgroundView(inflater, root, savedInstanceState);
    if (backgroundView != null) {
        FrameLayout backgroundViewRoot = (FrameLayout) root.findViewById(R.id.guidedstep_background_view_root);
        backgroundViewRoot.addView(backgroundView, 0);
    }
    return root;
}

From source file:android.support.v17.leanback.app.GuidedStepSupportFragment.java

/**
 * {@inheritDoc}//w ww. j a  v  a 2  s.co m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (DEBUG)
        Log.v(TAG, "onCreateView");

    resolveTheme();
    inflater = getThemeInflater(inflater);

    GuidedStepRootLayout root = (GuidedStepRootLayout) inflater.inflate(R.layout.lb_guidedstep_fragment,
            container, false);

    root.setFocusOutStart(isFocusOutStartAllowed());
    root.setFocusOutEnd(isFocusOutEndAllowed());

    ViewGroup guidanceContainer = (ViewGroup) root.findViewById(R.id.content_fragment);
    ViewGroup actionContainer = (ViewGroup) root.findViewById(R.id.action_fragment);

    Guidance guidance = onCreateGuidance(savedInstanceState);
    View guidanceView = mGuidanceStylist.onCreateView(inflater, guidanceContainer, guidance);
    guidanceContainer.addView(guidanceView);

    View actionsView = mActionsStylist.onCreateView(inflater, actionContainer);
    actionContainer.addView(actionsView);

    View buttonActionsView = mButtonActionsStylist.onCreateView(inflater, actionContainer);
    actionContainer.addView(buttonActionsView);

    GuidedActionAdapter.EditListener editListener = new GuidedActionAdapter.EditListener() {

        @Override
        public void onImeOpen() {
            runImeAnimations(true);
        }

        @Override
        public void onImeClose() {
            runImeAnimations(false);
        }

        @Override
        public long onGuidedActionEditedAndProceed(GuidedAction action) {
            return GuidedStepSupportFragment.this.onGuidedActionEditedAndProceed(action);
        }

        @Override
        public void onGuidedActionEditCanceled(GuidedAction action) {
            GuidedStepSupportFragment.this.onGuidedActionEditCanceled(action);
        }
    };

    mAdapter = new GuidedActionAdapter(mActions, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            GuidedStepSupportFragment.this.onGuidedActionClicked(action);
            if (isSubActionsExpanded()) {
                collapseSubActions();
            } else if (action.hasSubActions()) {
                expandSubActions(action);
            }
        }
    }, this, mActionsStylist, false);
    mButtonAdapter = new GuidedActionAdapter(mButtonActions, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            GuidedStepSupportFragment.this.onGuidedActionClicked(action);
        }
    }, this, mButtonActionsStylist, false);
    mSubAdapter = new GuidedActionAdapter(null, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            if (mActionsStylist.isInExpandTransition()) {
                return;
            }
            if (GuidedStepSupportFragment.this.onSubGuidedActionClicked(action)) {
                collapseSubActions();
            }
        }
    }, this, mActionsStylist, true);
    mAdapterGroup = new GuidedActionAdapterGroup();
    mAdapterGroup.addAdpter(mAdapter, mButtonAdapter);
    mAdapterGroup.addAdpter(mSubAdapter, null);
    mAdapterGroup.setEditListener(editListener);
    mActionsStylist.setEditListener(editListener);

    mActionsStylist.getActionsGridView().setAdapter(mAdapter);
    if (mActionsStylist.getSubActionsGridView() != null) {
        mActionsStylist.getSubActionsGridView().setAdapter(mSubAdapter);
    }
    mButtonActionsStylist.getActionsGridView().setAdapter(mButtonAdapter);
    if (mButtonActions.size() == 0) {
        // when there is no button actions, we dont need show the second panel, but keep
        // the width zero to run ChangeBounds transition.
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) buttonActionsView.getLayoutParams();
        lp.weight = 0;
        buttonActionsView.setLayoutParams(lp);
    } else {
        // when there are two actions panel, we need adjust the weight of action to
        // guidedActionContentWidthWeightTwoPanels.
        Context ctx = mThemeWrapper != null ? mThemeWrapper : getActivity();
        TypedValue typedValue = new TypedValue();
        if (ctx.getTheme().resolveAttribute(R.attr.guidedActionContentWidthWeightTwoPanels, typedValue, true)) {
            View actionsRoot = root.findViewById(R.id.action_fragment_root);
            float weight = typedValue.getFloat();
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) actionsRoot.getLayoutParams();
            lp.weight = weight;
            actionsRoot.setLayoutParams(lp);
        }
    }

    int pos = (mSelectedIndex >= 0 && mSelectedIndex < mActions.size()) ? mSelectedIndex
            : getFirstCheckedAction();
    setSelectedActionPosition(pos);

    setSelectedButtonActionPosition(0);

    // Add the background view.
    View backgroundView = onCreateBackgroundView(inflater, root, savedInstanceState);
    if (backgroundView != null) {
        FrameLayout backgroundViewRoot = (FrameLayout) root.findViewById(R.id.guidedstep_background_view_root);
        backgroundViewRoot.addView(backgroundView, 0);
    }
    return root;
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Add animators for animating out stale views
 * @param animationOutMode The animation mode to play for stale views
 *//*from w  ww  . j a va  2s  .com*/
private void addOutAnimatorsForStaleViews(List<Animator> animators, AnimationOut animationOutMode) {
    if (animationOutMode == AnimationOut.NONE) {
        return;
    }

    for (final View v : mViewsToAnimateOut) {
        // For each stale view to animate out, retrieve the animators for the view, then attach
        // the StaleViewAnimationEndListener which checks to see if the view should be recycled
        // at the end of the animation.
        final List<Animator> viewAnimators = new ArrayList<Animator>();

        switch (animationOutMode) {
        case SLIDE:
            final LayoutParams lp = (LayoutParams) v.getLayoutParams();
            // Bias towards sliding right, but depending on the column that this view
            // is laid out in, slide towards the nearest side edge.
            int endTranslation = (int) (v.getWidth() * 1.5);
            if (lp.column < (mColCount / 2)) {
                endTranslation = -endTranslation;
            }
            SgvAnimationHelper.addSlideOutAnimators(viewAnimators, v, (int) v.getTranslationX(),
                    endTranslation);
            break;

        case COLLAPSE:
            SgvAnimationHelper.addCollapseOutAnimators(viewAnimators, v);
            break;

        case FLY_DOWN:
            SgvAnimationHelper.addFlyOutAnimators(viewAnimators, v, (int) v.getTranslationY(), getHeight());
            break;

        case FADE:
            SgvAnimationHelper.addFadeAnimators(viewAnimators, v, v.getAlpha(), 0 /* end alpha */);
            break;

        default:
            throw new IllegalStateException("Unknown animationOutMode: " + animationOutMode);
        }

        if (viewAnimators.size() > 0) {
            addStaleViewAnimationEndListener(v, viewAnimators);
            animators.addAll(viewAnimators);
        }
    }
}

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

boolean willAddToExistingUserFolder(Object dragInfo, CellLayout target, int[] targetCell, float distance) {
    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  w  ww  .  j a v a2  s.c o  m*/
    }

    if (dropOverView instanceof FolderIcon) {
        FolderIcon fi = (FolderIcon) dropOverView;
        if (fi.acceptDrop(dragInfo)) {
            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 w w w  .  j  a  v a  2 s  . 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:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

private void addStaleViewAnimationEndListener(final View view, List<Animator> viewAnimators) {
    if (viewAnimators == null) {
        return;//from   www .j  av a 2 s. c om
    }

    for (final Animator animator : viewAnimators) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // In the event that onChanged is called before this animation finishes,
                // we would have mistakenly cached a view that would be recycled.  So
                // check if it's there, and remove it so that obtainView() doesn't
                // accidentally use the cached view later when it's already been
                // moved to the recycler.
                final LayoutParams lp = (LayoutParams) view.getLayoutParams();
                if (mChildRectsForAnimation.containsKey(lp.id)) {
                    mChildRectsForAnimation.remove(lp.id);
                }

                recycleView(view);
            }
        });
    }
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Obtain a populated view from the adapter.  This method checks to see if the view to populate
 * is already laid out on screen somewhere by comparing the item ids.
 *
 * If the view is already laid out, and the view type has not changed, populate the contents
 * and return.//w ww.ja  v  a 2 s  .  co  m
 *
 * If the view is not laid out on screen somewhere, grab a view from the recycler and populate.
 *
 * NOTE: This method should be called during layout.
 *
 * TODO: This can probably be consolidated with the overloaded {@link #obtainView(int, View)}.
 *
 * @param position Position to get the view for.
 */
final View obtainView(int position) {
    // TODO: This method currently does not support transient state views.

    final Object item = mAdapter.getItem(position);

    View scrap = null;
    final int positionViewType = mAdapter.getItemViewType(item, position);

    final long id = mAdapter.getItemId(item, position);
    final ViewRectPair viewRectPair = mChildRectsForAnimation.get(id);
    if (viewRectPair != null) {
        scrap = viewRectPair.view;

        // TODO: Make use of stable ids by retrieving the cached views using stable ids.  In
        // theory, we should maintain a list of active views, and then fetch the views
        // from that list.  If that fails, then we should go to the recycler.
        // For the collection holding stable ids, we must ensure that those views don't get
        // repurposed for other items at different positions.
    }

    final int scrapViewType = scrap != null && (scrap.getLayoutParams() instanceof LayoutParams)
            ? ((LayoutParams) scrap.getLayoutParams()).viewType
            : -1;

    if (scrap == null || scrapViewType != positionViewType) {
        // If there is no cached view or the cached view's type no longer match the type
        // of the item at the specified position, retrieve a new view from the recycler and
        // recycle the cached view.
        if (scrap != null) {
            // The cached view we had is not valid, so add it to the recycler and
            // remove it from the current layout.
            recycleView(scrap);
        }

        scrap = mRecycler.getScrapView(positionViewType);
    }

    final int itemColumnSpan = mAdapter.getItemColumnSpan(item, position);
    final int itemWidth = getItemWidth(itemColumnSpan);
    final View view = mAdapter.getView(item, position, scrap, this, itemWidth);

    ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (view.getParent() != this) {
        if (lp == null) {
            lp = generateDefaultLayoutParams();
        } else if (!checkLayoutParams(lp)) {
            lp = generateLayoutParams(lp);
        }

        view.setLayoutParams(lp);
    }

    final LayoutParams sglp = (LayoutParams) view.getLayoutParams();
    sglp.position = position;
    sglp.viewType = positionViewType;
    sglp.id = id;
    sglp.span = itemColumnSpan;

    // When the view at the positions we are tracking update, make sure to
    // update our views as well. That way, we have the correct
    // rectangle for comparing when the drag target enters/ leaves the
    // placeholder view.
    if (isDragReorderingSupported() && mReorderHelper.getDraggedChildId() == id) {
        mReorderHelper.updateDraggedChildView(view);
        mReorderHelper.updateDraggedOverChildView(view);
    }
    return view;
}

From source file:android.support.v7.widget.RecyclerView.java

static ViewHolder getChildViewHolderInt(View child) {
    if (child == null) {
        return null;
    }//from   w  ww. ja va2 s. co m
    return ((LayoutParams) child.getLayoutParams()).mViewHolder;
}