Search in sources :

Example 96 with RecyclerView

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

the class Utils method checkSimpleGridLayout.

public static void checkSimpleGridLayout(RecyclerView recyclerView, int itemHeight, int numColumns) {
    final int width = recyclerView.getWidth();
    final int gridWidth = width - recyclerView.getPaddingLeft() - recyclerView.getPaddingRight();
    final int columnWidth = gridWidth / numColumns;
    for (int i = 0; i < 20; i += numColumns) {
        final int top = i / numColumns * itemHeight;
        for (int j = 0; j < numColumns && i + j < 20; j++) {
            View child = recyclerView.getChildAt(i + j);
            assertThat(child).hasHeight(itemHeight);
            assertThat(child).hasLeft(j * columnWidth + recyclerView.getPaddingLeft());
            if (j == numColumns - 1) {
                assertThat(child).hasRight(width - recyclerView.getPaddingRight());
            } else {
                assertThat(child).hasRight(j * columnWidth + columnWidth + recyclerView.getPaddingLeft());
            }
            assertThat(child).hasTop(top + recyclerView.getPaddingTop());
            assertThat(child).hasBottom(top + itemHeight + recyclerView.getPaddingTop());
        }
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 97 with RecyclerView

use of android.support.v7.widget.RecyclerView 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 98 with RecyclerView

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

the class RecyclerViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    assert recyclerView != null;
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(new RecyclerViewAdapter());
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 99 with RecyclerView

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

the class AccountBookMonthViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.activity_account_book_month_view);
    userName = (TextView) findViewById(R.id.user_name);
    userEmail = (TextView) findViewById(R.id.user_email);
    userName.setTypeface(CoCoinUtil.typefaceLatoRegular);
    userEmail.setTypeface(CoCoinUtil.typefaceLatoLight);
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        userName.setText(user.getUsername());
        userEmail.setText(user.getEmail());
    }
    mViewPager = (MaterialViewPager) findViewById(R.id.materialViewPager);
    View view = mViewPager.getRootView();
    TextView title = (TextView) view.findViewById(R.id.logo_white);
    title.setTypeface(CoCoinUtil.typefaceLatoLight);
    title.setText(SettingManager.getInstance().getAccountBookName());
    mViewPager.getPagerTitleStrip().setTypeface(CoCoinUtil.GetTypeface(), Typeface.NORMAL);
    setTitle("");
    toolbar = mViewPager.getToolbar();
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    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);
        }
    }
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0);
    mDrawer.setDrawerListener(mDrawerToggle);
    View logo = findViewById(R.id.logo_white);
    if (logo != null) {
        logo.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mViewPager.notifyHeaderChanged();
            }
        });
    }
    monthModeAdapter = new MonthViewFragmentAdapter(getSupportFragmentManager());
    mViewPager.getViewPager().setOffscreenPageLimit(monthModeAdapter.getCount());
    mViewPager.getViewPager().setAdapter(monthModeAdapter);
    mViewPager.getPagerTitleStrip().setViewPager(mViewPager.getViewPager());
    if (monthModeAdapter.getCount() == 1) {
        mViewPager.getPagerTitleStrip().setVisibility(View.INVISIBLE);
    }
    mViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() {

        @Override
        public HeaderDesign getHeaderDesign(int page) {
            return HeaderDesign.fromColorAndDrawable(CoCoinUtil.GetTagColor(RecordManager.TAGS.get(page).getId()), CoCoinUtil.GetTagDrawable(-3));
        }
    });
    recyclerView = (RecyclerView) mDrawer.findViewById(R.id.recycler_view);
    drawerMonthViewRecyclerViewAdapter = new DrawerMonthViewRecyclerViewAdapter(mContext);
    recyclerView.setAdapter(drawerMonthViewRecyclerViewAdapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    drawerMonthViewRecyclerViewAdapter.SetOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            mViewPager.getViewPager().setCurrentItem(position);
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mDrawer.closeDrawers();
                }
            }, 700);
        }
    });
    profileImage = (CircleImageView) mDrawer.findViewById(R.id.profile_image);
    profileImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SettingManager.getInstance().getLoggenOn()) {
                CoCoinUtil.showToast(mContext, R.string.change_logo_tip);
            } else {
                CoCoinUtil.showToast(mContext, R.string.login_tip);
            }
        }
    });
    mDemoSlider = (SliderLayout) findViewById(R.id.slider);
    HashMap<String, Integer> urls = CoCoinUtil.GetDrawerTopUrl();
    for (String name : urls.keySet()) {
        CustomSliderView customSliderView = new CustomSliderView(this);
        // initialize a SliderLayout
        customSliderView.image(urls.get(name)).setScaleType(BaseSliderView.ScaleType.Fit);
        mDemoSlider.addSlider(customSliderView);
    }
    mDemoSlider.setPresetTransformer(SliderLayout.Transformer.ZoomOut);
    mDemoSlider.setCustomAnimation(new DescriptionAnimation());
    mDemoSlider.setDuration(4000);
    mDemoSlider.setCustomIndicator((PagerIndicator) findViewById(R.id.custom_indicator));
    loadLogo();
}
Also used : MaterialViewPager(com.github.florent37.materialviewpager.MaterialViewPager) DrawerMonthViewRecyclerViewAdapter(com.nightonke.saver.adapter.DrawerMonthViewRecyclerViewAdapter) User(com.nightonke.saver.model.User) BmobUser(cn.bmob.v3.BmobUser) OnItemClickListener(com.nightonke.saver.adapter.DrawerMonthViewRecyclerViewAdapter.OnItemClickListener) HeaderDesign(com.github.florent37.materialviewpager.header.HeaderDesign) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Handler(android.os.Handler) CustomSliderView(com.nightonke.saver.ui.CustomSliderView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) CustomSliderView(com.nightonke.saver.ui.CustomSliderView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) BaseSliderView(com.daimajia.slider.library.SliderTypes.BaseSliderView) MonthViewFragmentAdapter(com.nightonke.saver.adapter.MonthViewFragmentAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) DescriptionAnimation(com.daimajia.slider.library.Animations.DescriptionAnimation) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar)

Example 100 with RecyclerView

use of android.support.v7.widget.RecyclerView 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)1778 View (android.view.View)1237 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1106 TextView (android.widget.TextView)384 GridLayoutManager (android.support.v7.widget.GridLayoutManager)234 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)225 ImageView (android.widget.ImageView)210 ArrayList (java.util.ArrayList)190 Toolbar (android.support.v7.widget.Toolbar)137 Intent (android.content.Intent)117 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)102 ViewGroup (android.view.ViewGroup)101 Nullable (android.support.annotation.Nullable)99 Context (android.content.Context)96 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)96 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)93 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)93 Bundle (android.os.Bundle)92 Test (org.junit.Test)90 Paint (android.graphics.Paint)80