Search in sources :

Example 46 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project SuperSLiM by TonicArtos.

the class LinearLayoutTests method test_overscrollBeforeStartAfterEnd.

@Test
public void test_overscrollBeforeStartAfterEnd() throws Exception {
    final int numItems = 1;
    final int dy = 100;
    RecyclerView.Adapter adapter;
    int[] layoutPadding;
    adapter = new TestAdapterBuilder().addLinearSection(numItems, Utils.RV_WIDTH, Utils.RV_HEIGHT + dy * 2, null).build(mActivity);
    layoutPadding = new int[] { 0, 0, 0, 0 };
    Utils.doOverscrollTest(new int[] { 0, -dy }, layoutPadding, false, adapter, mLayoutManager, mRecyclerView);
}
Also used : TestAdapterBuilder(com.tonicartos.superslim.util.TestAdapterBuilder) RecyclerView(android.support.v7.widget.RecyclerView) Test(org.junit.Test)

Example 47 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project SuperSLiM by TonicArtos.

the class LinearLayoutTests method test_overscrollAfterStartBeforeEnd.

@Test
public void test_overscrollAfterStartBeforeEnd() throws Exception {
    final int numItems = 1;
    final int dy = 100;
    RecyclerView.Adapter adapter;
    int[] layoutPadding;
    adapter = new TestAdapterBuilder().addLinearSection(numItems, Utils.RV_WIDTH, Utils.RV_HEIGHT - dy * 2, null).build(mActivity);
    layoutPadding = new int[] { 0, 0, 0, 0 };
    Utils.doOverscrollTest(new int[] { 0, dy }, layoutPadding, true, adapter, mLayoutManager, mRecyclerView);
}
Also used : TestAdapterBuilder(com.tonicartos.superslim.util.TestAdapterBuilder) RecyclerView(android.support.v7.widget.RecyclerView) Test(org.junit.Test)

Example 48 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project SuperSLiM by TonicArtos.

the class Utils method doOverscrollTest.

/**
     * Perform an overscroll test.
     *
     * @param offset         Offset to apply to simulate overscroll; dx, dy.
     * @param padding        Padding values; l, t, r, b.
     * @param expected       Expected bounds; l, t, r, b.
     * @param adapter        Adapter to use.
     * @param mLayoutManager Layout manager to use.
     * @param mRecyclerView  RecyclerView to use.
     */
public static void doOverscrollTest(int[] offset, int[] padding, boolean expected, RecyclerView.Adapter adapter, LayoutManagerWrapper mLayoutManager, RecyclerView mRecyclerView) throws Exception {
    setupLayoutTest(padding, adapter, mLayoutManager, mRecyclerView);
    // Shift so that bounds are after start and end.
    adjustPosition(mRecyclerView, offset[0], offset[1]);
    Method isOverscrolled = LayoutManager.class.getDeclaredMethod("isOverscrolled", LayoutState.class);
    isOverscrolled.setAccessible(true);
    LayoutState state = mock(LayoutState.class);
    RecyclerView.State mRecyclerViewState = mock(RecyclerView.State.class);
    when(state.getRecyclerState()).thenReturn(mRecyclerViewState);
    when(mRecyclerViewState.getItemCount()).thenReturn(adapter.getItemCount());
    boolean result = (Boolean) isOverscrolled.invoke(mLayoutManager, state);
    assertEquals(expected, result);
}
Also used : LayoutState(com.tonicartos.superslim.LayoutState) RecyclerView(android.support.v7.widget.RecyclerView) Method(java.lang.reflect.Method)

Example 49 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project CoCoin by Nightonke.

the class HelpActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.activity_help);
    mViewPager = (MaterialViewPager) findViewById(R.id.materialViewPager);
    mViewPager.getPagerTitleStrip().setTypeface(CoCoinUtil.getInstance().typefaceLatoLight, Typeface.NORMAL);
    mViewPager.getPagerTitleStrip().setAllCaps(false);
    mViewPager.getPagerTitleStrip().setUnderlineColor(Color.parseColor("#00000000"));
    mViewPager.getPagerTitleStrip().setIndicatorColor(Color.parseColor("#00000000"));
    mViewPager.getPagerTitleStrip().setUnderlineHeight(0);
    mViewPager.getPagerTitleStrip().setIndicatorHeight(0);
    setTitle("");
    toolbar = mViewPager.getToolbar();
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setDisplayShowTitleEnabled(true);
            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setHomeButtonEnabled(true);
        }
    }
    View logo = findViewById(R.id.logo_white);
    if (logo != null) {
        logo.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mViewPager.notifyHeaderChanged();
            }
        });
    }
    adapter = new HelpFragmentAdapter(getSupportFragmentManager(), 0);
    mViewPager.getViewPager().setAdapter(adapter);
    mViewPager.getPagerTitleStrip().setViewPager(mViewPager.getViewPager());
    mViewPager.getPagerTitleStrip().invalidate();
    mViewPager.getViewPager().setOffscreenPageLimit(2);
    mViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() {

        @Override
        public HeaderDesign getHeaderDesign(int page) {
            return HeaderDesign.fromColorAndDrawable(ContextCompat.getColor(CoCoinApplication.getAppContext(), R.color.my_blue), ContextCompat.getDrawable(CoCoinApplication.getAppContext(), R.drawable.cocoin_blue_bg));
        }
    });
}
Also used : MaterialViewPager(com.github.florent37.materialviewpager.MaterialViewPager) HeaderDesign(com.github.florent37.materialviewpager.header.HeaderDesign) HelpFragmentAdapter(com.nightonke.saver.adapter.HelpFragmentAdapter) View(android.view.View) ActionBar(android.support.v7.app.ActionBar)

Example 50 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project CoCoin by Nightonke.

the class TodayViewFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    layoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setHasFixedSize(true);
    Calendar now = Calendar.getInstance();
    Calendar leftRange;
    Calendar rightRange;
    RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
    int start = -1;
    int end = 0;
    switch(position) {
        case TODAY:
            leftRange = CoCoinUtil.GetTodayLeftRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                }
                if (start == -1) {
                    start = i;
                }
            }
            break;
        case YESTERDAY:
            leftRange = CoCoinUtil.GetYesterdayLeftRange(now);
            rightRange = CoCoinUtil.GetYesterdayRightRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                } else if (!recordManager.RECORDS.get(i).getCalendar().after(rightRange)) {
                    if (start == -1) {
                        start = i;
                    }
                }
            }
            break;
        case THIS_WEEK:
            leftRange = CoCoinUtil.GetThisWeekLeftRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                }
                if (start == -1) {
                    start = i;
                }
            }
            break;
        case LAST_WEEK:
            leftRange = CoCoinUtil.GetLastWeekLeftRange(now);
            rightRange = CoCoinUtil.GetLastWeekRightRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                } else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
                    if (start == -1) {
                        start = i;
                    }
                }
            }
            break;
        case THIS_MONTH:
            leftRange = CoCoinUtil.GetThisMonthLeftRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                }
                if (start == -1) {
                    start = i;
                }
            }
            break;
        case LAST_MONTH:
            leftRange = CoCoinUtil.GetLastMonthLeftRange(now);
            rightRange = CoCoinUtil.GetLastMonthRightRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                } else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
                    if (start == -1) {
                        start = i;
                    }
                }
            }
            break;
        case THIS_YEAR:
            leftRange = CoCoinUtil.GetThisYearLeftRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                }
                if (start == -1) {
                    start = i;
                }
            }
            break;
        case LAST_YEAR:
            leftRange = CoCoinUtil.GetLastYearLeftRange(now);
            rightRange = CoCoinUtil.GetLastYearRightRange(now);
            for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
                if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
                    end = i + 1;
                    break;
                } else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
                    if (start == -1) {
                        start = i;
                    }
                }
            }
            break;
    }
    adapter = new TodayViewRecyclerViewAdapter(start, end, mContext, position);
    mAdapter = new RecyclerViewMaterialAdapter(adapter);
    mRecyclerView.setAdapter(mAdapter);
    MaterialViewPagerHelper.registerRecyclerView(getActivity(), mRecyclerView, null);
}
Also used : RecordManager(com.nightonke.saver.model.RecordManager) Calendar(java.util.Calendar) TodayViewRecyclerViewAdapter(com.nightonke.saver.adapter.TodayViewRecyclerViewAdapter) RecyclerViewMaterialAdapter(com.github.florent37.materialviewpager.adapter.RecyclerViewMaterialAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)688 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)612 View (android.view.View)593 TextView (android.widget.TextView)245 ArrayList (java.util.ArrayList)179 Intent (android.content.Intent)148 ImageView (android.widget.ImageView)132 Toolbar (android.support.v7.widget.Toolbar)118 GridLayoutManager (android.support.v7.widget.GridLayoutManager)111 AdapterView (android.widget.AdapterView)109 ViewGroup (android.view.ViewGroup)97 AlertDialog (android.support.v7.app.AlertDialog)91 Bundle (android.os.Bundle)85 ListView (android.widget.ListView)85 BindView (butterknife.BindView)85 Nullable (android.support.annotation.Nullable)78 DialogInterface (android.content.DialogInterface)71 Context (android.content.Context)65 ArrayAdapter (android.widget.ArrayAdapter)65 LayoutInflater (android.view.LayoutInflater)64