Search in sources :

Example 16 with LayoutParams

use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project SuperSLiM by TonicArtos.

the class LayoutManager method fillToStart.

/**
     * Fill towards the start edge.
     *
     * @param leadingEdge Line to fill up to. Content will not be wholly beyond this line.
     * @param state       Layout state.
     * @return Line content was filled up to.
     */
private int fillToStart(int leadingEdge, LayoutState state) {
    View anchor = getAnchorAtStart();
    LayoutParams anchorParams = (LayoutParams) anchor.getLayoutParams();
    final int sfp = anchorParams.getTestedFirstPosition();
    final View first = getHeaderOrFirstViewForSection(sfp, Direction.START, state);
    final SectionData sd = new SectionData(this, first);
    final SectionLayoutManager slm = getSlm(sd);
    int markerLine;
    int anchorPosition = getPosition(anchor);
    if (anchorPosition == sd.firstPosition) {
        markerLine = getDecoratedTop(anchor);
    } else {
        if (anchorPosition - 1 == sd.firstPosition && sd.hasHeader) {
            // Already at first content position, so no more to do.
            markerLine = getDecoratedTop(anchor);
        } else {
            markerLine = slm.finishFillToStart(leadingEdge, anchor, sd, state);
        }
    }
    markerLine = updateHeaderForStart(first, leadingEdge, markerLine, sd, state);
    if (markerLine > leadingEdge) {
        markerLine = fillNextSectionToStart(leadingEdge, markerLine, state);
    }
    return markerLine;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 17 with LayoutParams

use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project SuperSLiM by TonicArtos.

the class LayoutManager method scrollVerticallyBy.

@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
    int numChildren = getChildCount();
    if (numChildren == 0) {
        return 0;
    }
    LayoutState layoutState = new LayoutState(this, recycler, state);
    final Direction direction = dy > 0 ? Direction.END : Direction.START;
    final boolean isDirectionEnd = direction == Direction.END;
    final int height = getHeight();
    final int leadingEdge = isDirectionEnd ? height + dy : dy;
    // from the bottom up.
    if (isDirectionEnd) {
        final View end = getAnchorAtEnd();
        LayoutParams params = (LayoutParams) end.getLayoutParams();
        SectionLayoutManager slm = getSlm(params);
        final int endEdge = slm.getLowestEdge(params.getTestedFirstPosition(), getChildCount() - 1, getDecoratedBottom(end));
        if (endEdge < height - getPaddingBottom() && getPosition(end) == (state.getItemCount() - 1)) {
            return 0;
        }
    }
    final int fillEdge = fillUntil(leadingEdge, direction, layoutState);
    final int delta;
    if (isDirectionEnd) {
        // Add padding so we scroll to inset area at scroll end.
        int fillDelta = fillEdge - height + getPaddingBottom();
        delta = fillDelta < dy ? fillDelta : dy;
    } else {
        int fillDelta = fillEdge - getPaddingTop();
        delta = fillDelta > dy ? fillDelta : dy;
    }
    if (delta != 0) {
        offsetChildrenVertical(-delta);
        trimTail(isDirectionEnd ? Direction.START : Direction.END, layoutState);
    }
    layoutState.recycleCache();
    return delta;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 18 with LayoutParams

use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project HoloEverywhere by Prototik.

the class ActionBarView method setMenu.

public void setMenu(SupportMenu menu, MenuPresenter.Callback cb) {
    if (menu == mOptionsMenu) {
        return;
    }
    if (mOptionsMenu != null) {
        mOptionsMenu.removeMenuPresenter(mActionMenuPresenter);
        mOptionsMenu.removeMenuPresenter(mExpandedMenuPresenter);
    }
    MenuBuilder builder = (MenuBuilder) menu;
    mOptionsMenu = builder;
    if (mMenuView != null) {
        final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
        if (oldParent != null) {
            oldParent.removeView(mMenuView);
        }
    }
    if (mActionMenuPresenter == null) {
        mActionMenuPresenter = new ActionMenuPresenter(mContext);
        mActionMenuPresenter.setCallback(cb);
        mActionMenuPresenter.setId(R.id.action_menu_presenter);
        mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
    }
    ActionMenuView menuView;
    final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
    if (!mSplitActionBar) {
        mActionMenuPresenter.setExpandedActionViewsExclusive(getResources().getBoolean(R.bool.abc_action_bar_expanded_action_views_exclusive));
        configPresenters(builder);
        menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        final ViewGroup oldParent = (ViewGroup) menuView.getParent();
        if (oldParent != null && oldParent != this) {
            oldParent.removeView(menuView);
        }
        addView(menuView, layoutParams);
    } else {
        mActionMenuPresenter.setExpandedActionViewsExclusive(false);
        // Allow full screen width in split mode.
        mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);
        // No limit to the item count; use whatever will fit.
        mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
        // Span the whole width
        layoutParams.width = LayoutParams.FILL_PARENT;
        configPresenters(builder);
        menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        if (mSplitView != null) {
            final ViewGroup oldParent = (ViewGroup) menuView.getParent();
            if (oldParent != null && oldParent != mSplitView) {
                oldParent.removeView(menuView);
            }
            menuView.setVisibility(getAnimatedVisibility());
            mSplitView.addView(menuView, layoutParams);
        } else {
            // We'll add this later if we missed it this time.
            menuView.setLayoutParams(layoutParams);
        }
    }
    mMenuView = menuView;
}
Also used : ViewGroup(android.view.ViewGroup) ActionMenuView(android.support.v7.internal.view.menu.ActionMenuView) MenuBuilder(android.support.v7.internal.view.menu.MenuBuilder) SubMenuBuilder(android.support.v7.internal.view.menu.SubMenuBuilder) ActionMenuPresenter(android.support.v7.internal.view.menu.ActionMenuPresenter)

Example 19 with LayoutParams

use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project UltimateRecyclerView by cymcsg.

the class HeaderPositionCalculator method itemIsObscuredByHeader.

/**
     * Determines if an item is obscured by a header
     *
     * @param parent
     * @param item        to determine if obscured by header
     * @param header      that might be obscuring the item
     * @param orientation of the {@link RecyclerView}
     * @return true if the item view is obscured by the header view
     */
private boolean itemIsObscuredByHeader(RecyclerView parent, View item, View header, int orientation) {
    RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) item.getLayoutParams();
    Rect headerMargins = mDimensionCalculator.getMargins(header);
    int adapterPosition = parent.getChildAdapterPosition(item);
    if (adapterPosition == RecyclerView.NO_POSITION || mHeaderProvider.getHeader(parent, adapterPosition) != header) {
        // Handles an edge case where a trailing header is smaller than the current sticky header.
        return false;
    }
    if (orientation == LinearLayoutManager.VERTICAL) {
        int itemTop = item.getTop() - layoutParams.topMargin;
        int headerBottom = header.getBottom() + headerMargins.bottom + headerMargins.top;
        if (itemTop > headerBottom) {
            return false;
        }
    } else {
        int itemLeft = item.getLeft() - layoutParams.leftMargin;
        int headerRight = header.getRight() + headerMargins.right + headerMargins.left;
        if (itemLeft > headerRight) {
            return false;
        }
    }
    return true;
}
Also used : Rect(android.graphics.Rect) RecyclerView(android.support.v7.widget.RecyclerView)

Example 20 with LayoutParams

use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project Tusky by Vavassor.

the class ComposeActivity method addMediaToQueue.

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
             * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
             * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(), textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaButtons();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaButtons();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}
Also used : ImageView(android.widget.ImageView) AppCompatResources(android.support.v7.content.res.AppCompatResources) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

View (android.view.View)138 RecyclerView (android.support.v7.widget.RecyclerView)128 TextView (android.widget.TextView)52 ImageView (android.widget.ImageView)36 LinearLayout (android.widget.LinearLayout)32 ViewGroup (android.view.ViewGroup)31 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)16 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)15 FrameLayout (android.widget.FrameLayout)15 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)13 Paint (android.graphics.Paint)12 RelativeLayout (android.widget.RelativeLayout)12 BindView (butterknife.BindView)12 Rect (android.graphics.Rect)11 Toolbar (android.support.v7.widget.Toolbar)11 EditText (android.widget.EditText)10 DialogInterface (android.content.DialogInterface)9 Handler (android.os.Handler)9 AdapterView (android.widget.AdapterView)9 Intent (android.content.Intent)8