Search in sources :

Example 6 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project SuperSLiM by TonicArtos.

the class LayoutManager method getFractionOfContentAbove.

private float getFractionOfContentAbove(RecyclerView.State state, boolean ignorePosition) {
    float fractionOffscreen = 0;
    View child = getChildAt(0);
    final int anchorPosition = getPosition(child);
    int numBeforeAnchor = 0;
    float top = getDecoratedTop(child);
    float bottom = getDecoratedBottom(child);
    if (bottom < 0) {
        fractionOffscreen = 1;
    } else if (0 <= top) {
        fractionOffscreen = 0;
    } else {
        float height = getDecoratedMeasuredHeight(child);
        fractionOffscreen = -top / height;
    }
    SectionData sd = new SectionData(this, child);
    if (sd.headerParams.isHeader && sd.headerParams.isHeaderInline()) {
        // Header must not be stickied as it is not attached after section items.
        return fractionOffscreen;
    }
    // Run through all views in the section and add up values offscreen.
    int firstPosition = -1;
    SparseArray<Boolean> positionsOffscreen = new SparseArray<>();
    for (int i = 1; i < getChildCount(); i++) {
        child = getChildAt(i);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (!sd.sameSectionManager(lp)) {
            break;
        }
        final int position = getPosition(child);
        if (!ignorePosition && position < anchorPosition) {
            numBeforeAnchor += 1;
        }
        top = getDecoratedTop(child);
        bottom = getDecoratedBottom(child);
        if (bottom < 0) {
            fractionOffscreen += 1;
        } else if (0 <= top) {
            continue;
        } else {
            float height = getDecoratedMeasuredHeight(child);
            fractionOffscreen += -top / height;
        }
        if (!lp.isHeader) {
            if (firstPosition == -1) {
                firstPosition = position;
            }
            positionsOffscreen.put(position, true);
        }
    }
    return fractionOffscreen - numBeforeAnchor - getSlm(sd).howManyMissingAbove(firstPosition, positionsOffscreen);
}
Also used : SparseArray(android.util.SparseArray) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 7 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP 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 8 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP 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 9 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Synthese_2BIN by TheYoungSensei.

the class ItemDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_detail);
    Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
    setSupportActionBar(toolbar);
    // Show the Up button in the action bar.
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    //
    if (savedInstanceState == null) {
        // Create the detail fragment and add it to the activity
        // using a fragment transaction.
        Bundle arguments = new Bundle();
        arguments.putString(ItemDetailFragment.ARG_ITEM_ID, getIntent().getStringExtra(ItemDetailFragment.ARG_ITEM_ID));
        ItemDetailFragment fragment = new ItemDetailFragment();
        fragment.setArguments(arguments);
        getSupportFragmentManager().beginTransaction().add(R.id.item_detail_container, fragment).commit();
    }
}
Also used : Bundle(android.os.Bundle) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 10 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Synthese_2BIN by TheYoungSensei.

the class BusinessDayDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_businessday_detail);
    Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
    setSupportActionBar(toolbar);
    // Show the Up button in the action bar.
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    //
    if (savedInstanceState == null) {
        // Create the detail fragment and add it to the activity
        // using a fragment transaction.
        Bundle arguments = new Bundle();
        arguments.putString(BusinessDayDetailFragment.ARG_ITEM_ID, getIntent().getStringExtra(BusinessDayDetailFragment.ARG_ITEM_ID));
        BusinessDayDetailFragment fragment = new BusinessDayDetailFragment();
        fragment.setArguments(arguments);
        getSupportFragmentManager().beginTransaction().add(R.id.businessday_detail_container, fragment).commit();
    }
}
Also used : Bundle(android.os.Bundle) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

View (android.view.View)135 RecyclerView (android.support.v7.widget.RecyclerView)97 TextView (android.widget.TextView)69 Toolbar (android.support.v7.widget.Toolbar)50 ActionBar (android.support.v7.app.ActionBar)49 Intent (android.content.Intent)44 ImageView (android.widget.ImageView)41 AdapterView (android.widget.AdapterView)33 ArrayList (java.util.ArrayList)30 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)29 DialogInterface (android.content.DialogInterface)25 AlertDialog (android.support.v7.app.AlertDialog)25 ListView (android.widget.ListView)25 Bundle (android.os.Bundle)22 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)22 SharedPreferences (android.content.SharedPreferences)21 Preference (android.support.v7.preference.Preference)20 GridLayoutManager (android.support.v7.widget.GridLayoutManager)19 SuppressLint (android.annotation.SuppressLint)16 Point (android.graphics.Point)16