Search in sources :

Example 1 with StackAdapter

use of com.fima.cardsui.StackAdapter in project Rashr by DsLNeXuS.

the class CardUI method refresh.

//suppress this error message to be able to use spaces in higher api levels
@SuppressLint("NewApi")
public void refresh() {
    if (mAdapter == null) {
        mAdapter = new StackAdapter(mContext, mStacks, mSwipeable);
        if (mListView != null) {
            mListView.setAdapter(mAdapter);
        } else if (mTableLayout != null) {
            TableRow tr = null;
            for (int i = 0; i < mAdapter.getCount(); i += mColumnNumber) {
                //add a new table row with the current context
                tr = new TableRow(mTableLayout.getContext());
                tr.setOrientation(TableRow.HORIZONTAL);
                tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
                //add as many cards as the number of columns indicates per row
                for (int j = 0; j < mColumnNumber; j++) {
                    if (i + j < mAdapter.getCount()) {
                        View card = mAdapter.getView(i + j, null, tr);
                        if (card.getLayoutParams() != null) {
                            card.setLayoutParams(new TableRow.LayoutParams(card.getLayoutParams().width, card.getLayoutParams().height, 1f));
                        } else {
                            card.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
                        }
                        tr.addView(card);
                    }
                }
                mTableLayout.addView(tr);
            }
            if (tr != null) {
                //fill the empty space with spacers
                for (int j = mAdapter.getCount() % mColumnNumber; j > 0; j--) {
                    View space = null;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        space = new Space(tr.getContext());
                    } else {
                        space = new View(tr.getContext());
                    }
                    space.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
                    tr.addView(space);
                }
            }
        }
    } else {
        // in case swipeable changed;
        mAdapter.setSwipeable(mSwipeable);
        mAdapter.setItems(mStacks);
    }
}
Also used : StackAdapter(com.fima.cardsui.StackAdapter) Space(android.widget.Space) TableRow(android.widget.TableRow) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 ListView (android.widget.ListView)1 Space (android.widget.Space)1 TableRow (android.widget.TableRow)1 TextView (android.widget.TextView)1 StackAdapter (com.fima.cardsui.StackAdapter)1