├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── scopes
│ └── scope_settings.xml
└── vcs.xml
├── CardListGridView.iml
├── README.md
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── hopend
│ │ └── saravana
│ │ └── cardlistgridview
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── hopend
│ │ └── saravana
│ │ └── cardlistgridview
│ │ ├── GridFragment.java
│ │ ├── ListFragment.java
│ │ ├── MainActivity.java
│ │ ├── ObjectGridAdapter.java
│ │ ├── ObjectHolder.java
│ │ ├── ObjectListAdapter.java
│ │ ├── RecyclerViewMaterialAdapter.java
│ │ ├── TaskTypePagerAdapter.java
│ │ ├── TestRecyclerViewAdapter.java
│ │ └── objectbean.java
│ └── res
│ ├── drawable-hdpi
│ ├── ic_launcher.png
│ └── plus.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── layout
│ ├── activity_main.xml
│ ├── fragment_eads.xml
│ ├── fragment_recyclerview.xml
│ ├── grid_item_card_small.xml
│ ├── list_item_card_big.xml
│ └── list_item_card_small.xml
│ ├── menu
│ └── menu_main.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── color.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | CardListGridView
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | Android API 21 Platform
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CardListGridView.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CardListGridView
2 | Material ListView and GridView using recycler view and card view
3 | 
4 |
5 |
6 | 
7 |
8 |
9 | 
10 |
11 |
12 | 
13 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.hopend.saravana.cardlistgridview"
9 | minSdkVersion 15
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies
23 | {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile 'com.android.support:appcompat-v7:22.2.0'
26 | compile 'com.android.support:support-v4:22.2.0'
27 | compile 'com.android.support:cardview-v7:22.2.0'
28 | compile 'com.android.support:support-annotations:22.2.0'
29 | compile 'com.getbase:floatingactionbutton:1.9.0'
30 | compile 'it.neokree:MaterialTabs:0.11'
31 | compile 'com.android.support:recyclerview-v7:22.2.0'
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\android-sdk-windows/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/hopend/saravana/cardlistgridview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hopend/saravana/cardlistgridview/GridFragment.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.net.Uri;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v7.widget.GridLayoutManager;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import java.util.ArrayList;
14 |
15 |
16 | public class GridFragment extends Fragment {
17 |
18 |
19 |
20 | private RecyclerView mRecyclerView;
21 | private RecyclerView.Adapter mAdapter;
22 | ArrayList cards = new ArrayList<>();
23 |
24 | public GridFragment() {
25 | // Required empty public constructor
26 | }
27 |
28 | @Override
29 | public void onCreate(Bundle savedInstanceState)
30 | {
31 | super.onCreate(savedInstanceState);
32 |
33 | }
34 |
35 | @Override
36 | public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
37 | {
38 | View view = inflater.inflate(R.layout.fragment_recyclerview, container, false);
39 |
40 |
41 | mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
42 | RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(), 2);
43 | mRecyclerView.setLayoutManager(layoutManager);
44 | mRecyclerView.setHasFixedSize(true);
45 |
46 |
47 | for(int k=0;k<=10;k++)
48 | {
49 | objectbean obj = new objectbean();
50 | obj.setTitle(String.valueOf(k));
51 | obj.setSinger(String.valueOf(k));
52 | obj.setDuration(String.valueOf(k));
53 | cards.add(obj);
54 | }
55 |
56 |
57 | mAdapter = new RecyclerViewMaterialAdapter(new ObjectGridAdapter(cards,getActivity()));
58 | mRecyclerView.setAdapter(mAdapter);
59 |
60 |
61 |
62 |
63 |
64 | return view;
65 |
66 | }
67 |
68 |
69 | public void onButtonPressed(Uri uri) {
70 |
71 | }
72 |
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hopend/saravana/cardlistgridview/ListFragment.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.net.Uri;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import java.util.ArrayList;
13 |
14 |
15 | public class ListFragment extends Fragment
16 | {
17 |
18 | private RecyclerView mRecyclerView;
19 | private RecyclerView.Adapter mAdapter;
20 | ArrayList cards = new ArrayList<>();
21 |
22 | public ListFragment()
23 | {
24 | // Required empty public constructor
25 | }
26 |
27 | @Override
28 | public void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 |
31 | }
32 |
33 | @Override
34 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
35 | {
36 |
37 | View view = inflater.inflate(R.layout.fragment_recyclerview, container, false);
38 |
39 | mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
40 | RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
41 | mRecyclerView.setLayoutManager(layoutManager);
42 | mRecyclerView.setHasFixedSize(true);
43 |
44 |
45 | for(int k=0;k<=10;k++)
46 | {
47 | objectbean obj = new objectbean();
48 | obj.setTitle(String.valueOf(k));
49 | obj.setSinger(String.valueOf(k));
50 | obj.setDuration(String.valueOf(k));
51 | cards.add(obj);
52 | }
53 |
54 |
55 | mAdapter = new RecyclerViewMaterialAdapter(new ObjectListAdapter(cards,getActivity()));
56 | mRecyclerView.setAdapter(mAdapter);
57 |
58 |
59 |
60 | return view;
61 | }
62 |
63 | // TODO: Rename method, update argument and hook method into UI event
64 | public void onButtonPressed(Uri uri) {
65 |
66 | }
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hopend/saravana/cardlistgridview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.support.v4.view.ViewPager;
4 | import android.support.v7.app.ActionBarActivity;
5 | import android.os.Bundle;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 | import com.getbase.floatingactionbutton.FloatingActionButton;
12 |
13 | import it.neokree.materialtabs.MaterialTab;
14 | import it.neokree.materialtabs.MaterialTabHost;
15 | import it.neokree.materialtabs.MaterialTabListener;
16 |
17 |
18 | public class MainActivity extends ActionBarActivity implements MaterialTabListener {
19 |
20 | FloatingActionButton floatbut;
21 | MaterialTabHost tabHost;
22 | ViewPager pager;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState)
26 | {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 |
30 | tabHost = (MaterialTabHost) findViewById(R.id.materialTabHost);
31 | pager = (ViewPager)findViewById(R.id.viewpager);
32 | floatbut = (FloatingActionButton)findViewById(R.id.addnewtask);
33 |
34 | TaskTypePagerAdapter pagerAdapter = new TaskTypePagerAdapter(getSupportFragmentManager(),MainActivity.this);
35 | pager.setAdapter(pagerAdapter);
36 | pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
37 | @Override
38 | public void onPageSelected(int position) {
39 | // when user do a swipe the selected tab change
40 | tabHost.setSelectedNavigationItem(position);
41 | }
42 | });
43 |
44 | String []tabdata = {"ListView","GridView"};
45 | // insert all tabs from pagerAdapter data
46 | for (int i = 0; i < pagerAdapter.getCount(); i++)
47 | {
48 | tabHost.addTab(
49 | tabHost.newTab()
50 | .setText(tabdata[i])
51 | .setTabListener(MainActivity.this)
52 | );
53 |
54 | }
55 |
56 |
57 | floatbut.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View view) {
60 | Toast.makeText(MainActivity.this,"Floating Action Button",Toast.LENGTH_LONG).show();
61 | }
62 | });
63 |
64 |
65 | }
66 |
67 |
68 | @Override
69 | public boolean onCreateOptionsMenu(Menu menu) {
70 | // Inflate the menu; this adds items to the action bar if it is present.
71 | getMenuInflater().inflate(R.menu.menu_main, menu);
72 | return true;
73 | }
74 |
75 | @Override
76 | public boolean onOptionsItemSelected(MenuItem item) {
77 | // Handle action bar item clicks here. The action bar will
78 | // automatically handle clicks on the Home/Up button, so long
79 | // as you specify a parent activity in AndroidManifest.xml.
80 | int id = item.getItemId();
81 |
82 | //noinspection SimplifiableIfStatement
83 | if (id == R.id.action_settings) {
84 | return true;
85 | }
86 |
87 | return super.onOptionsItemSelected(item);
88 | }
89 |
90 | @Override
91 | public void onTabSelected(MaterialTab materialTab) {
92 | pager.setCurrentItem(materialTab.getPosition());
93 | }
94 |
95 | @Override
96 | public void onTabReselected(MaterialTab materialTab) {
97 |
98 | }
99 |
100 | @Override
101 | public void onTabUnselected(MaterialTab materialTab) {
102 |
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hopend/saravana/cardlistgridview/ObjectGridAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.util.Log;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Toast;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by saravana on 6/14/2015.
15 | */
16 | public class ObjectGridAdapter extends RecyclerView.Adapter
17 | {
18 |
19 | List contents;
20 |
21 | Context ctx;
22 |
23 |
24 | public ObjectGridAdapter(List contents, Context ctx)
25 | {
26 | this.ctx = ctx;
27 | this.contents = contents;
28 | }
29 |
30 | @Override
31 | public ObjectHolder onCreateViewHolder(ViewGroup parent, final int viewType)
32 | {
33 | View view = null;
34 |
35 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item_card_small, parent, false);
36 | return new ObjectHolder(view , new ObjectHolder.IMyViewHolderClicks()
37 | {
38 | @Override
39 | public void onPlay(View caller)
40 | {
41 | Log.e("getting data", "view"+contents.get((int)caller.getTag()).getTitle());
42 |
43 | /* HomePage.songtitle.setText(contents.get((int)caller.getTag()).getFilename());
44 | HomePage.songplaypause.setImageDrawable(null);
45 | HomePage.songplaypause.setImageResource(android.R.drawable.ic_media_pause);
46 | try
47 | {
48 | HomePage.mp.reset();
49 | HomePage.mp.setDataSource(ctx, Uri.parse("file://"+contents.get((int) caller.getTag()).getUri()));
50 | HomePage.mp.prepare();
51 | HomePage.mp.start();
52 | HomePage. mp.setOnPreparedListener((MediaPlayer.OnPreparedListener) ctx);
53 | HomePage.mp.prepareAsync();
54 |
55 | }
56 | catch (Exception e)
57 | {
58 | e.printStackTrace();
59 | }*/
60 |
61 | Toast.makeText(ctx,contents.get((int)caller.getTag()).getTitle(),Toast.LENGTH_LONG).show();
62 |
63 | }
64 | }){};
65 |
66 | }
67 |
68 | @Override
69 | public void onBindViewHolder(ObjectHolder holder, int position)
70 | {
71 | objectbean song = contents.get(position);
72 | holder.bindSong(song,position);
73 | }
74 |
75 |
76 |
77 | @Override
78 | public int getItemCount()
79 | {
80 | return contents.size();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hopend/saravana/cardlistgridview/ObjectHolder.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.TextView;
6 |
7 |
8 |
9 | /**
10 | * Created by saravana on 6/14/2015.
11 | */
12 | public class ObjectHolder extends RecyclerView.ViewHolder implements View.OnClickListener
13 | {
14 | TextView textTitle;
15 | TextView textDuration;
16 |
17 | TextView textSinger;
18 | public IMyViewHolderClicks mListener;
19 |
20 | View vi;
21 |
22 | objectbean msong;
23 |
24 | public ObjectHolder(View itemView, IMyViewHolderClicks listener)
25 | {
26 | super(itemView);
27 | mListener = listener;
28 |
29 | vi = itemView;
30 | textTitle = (TextView) itemView.findViewById( R.id.textTitle);
31 | textDuration = (TextView) itemView.findViewById(R.id.textDuration);
32 | textSinger = (TextView) itemView.findViewById(R.id.textSinger);
33 |
34 | itemView.setOnClickListener(this);
35 |
36 | }
37 |
38 | public void bindSong(objectbean song,int pos)
39 | {
40 | msong = song;
41 | vi.setTag(pos);
42 | textTitle.setText(song.getTitle());
43 | textDuration.setText(song.getSinger());
44 | textSinger.setText(song.getDuration());
45 |
46 | }
47 |
48 | @Override
49 | public void onClick(View view)
50 | {
51 | mListener.onPlay(view);
52 | }
53 |
54 | public static interface IMyViewHolderClicks {
55 | public void onPlay(View caller);
56 |
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hopend/saravana/cardlistgridview/ObjectListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.util.Log;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Toast;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by saravana on 6/14/2015.
15 | */
16 | public class ObjectListAdapter extends RecyclerView.Adapter
17 | {
18 |
19 | List contents;
20 |
21 | Context ctx;
22 |
23 |
24 | public ObjectListAdapter(List contents, Context ctx)
25 | {
26 | this.ctx = ctx;
27 | this.contents = contents;
28 | }
29 |
30 | @Override
31 | public ObjectHolder onCreateViewHolder(ViewGroup parent, final int viewType)
32 | {
33 | View view = null;
34 |
35 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_card_small, parent, false);
36 | return new ObjectHolder(view , new ObjectHolder.IMyViewHolderClicks()
37 | {
38 | @Override
39 | public void onPlay(View caller)
40 | {
41 | Log.e("getting data", "view"+contents.get((int)caller.getTag()).getTitle());
42 |
43 | /* HomePage.songtitle.setText(contents.get((int)caller.getTag()).getFilename());
44 | HomePage.songplaypause.setImageDrawable(null);
45 | HomePage.songplaypause.setImageResource(android.R.drawable.ic_media_pause);
46 | try
47 | {
48 | HomePage.mp.reset();
49 | HomePage.mp.setDataSource(ctx, Uri.parse("file://"+contents.get((int) caller.getTag()).getUri()));
50 | HomePage.mp.prepare();
51 | HomePage.mp.start();
52 | HomePage. mp.setOnPreparedListener((MediaPlayer.OnPreparedListener) ctx);
53 | HomePage.mp.prepareAsync();
54 |
55 | }
56 | catch (Exception e)
57 | {
58 | e.printStackTrace();
59 | }*/
60 |
61 | Toast.makeText(ctx,contents.get((int)caller.getTag()).getTitle(),Toast.LENGTH_LONG).show();
62 |
63 | }
64 | }){};
65 |
66 | }
67 |
68 | @Override
69 | public void onBindViewHolder(ObjectHolder holder, int position)
70 | {
71 | objectbean song = contents.get(position);
72 | holder.bindSong(song,position);
73 | }
74 |
75 |
76 |
77 | @Override
78 | public int getItemCount() {
79 | return contents.size();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hopend/saravana/cardlistgridview/RecyclerViewMaterialAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | public class RecyclerViewMaterialAdapter extends RecyclerView.Adapter {
9 |
10 | //the constants value of the header view
11 | static final int TYPE_PLACEHOLDER = Integer.MIN_VALUE;
12 |
13 | //the size taken by the header
14 | private int mPlaceholderSize = 0;
15 |
16 | //the actual RecyclerView.Adapter
17 | private RecyclerView.Adapter mAdapter;
18 |
19 | /**
20 | * Construct the RecyclerViewMaterialAdapter, which inject a header into an actual RecyclerView.Adapter
21 | *
22 | * @param adapter The real RecyclerView.Adapter which displays content
23 | */
24 | public RecyclerViewMaterialAdapter(RecyclerView.Adapter adapter) {
25 | this.mAdapter = adapter;
26 | }
27 |
28 | /**
29 | * Construct the RecyclerViewMaterialAdapter, which inject a header into an actual RecyclerView.Adapter
30 | *
31 | * @param adapter The real RecyclerView.Adapter which displays content
32 | * @param placeholderSize The number of placeholder items before real items, default is 1
33 | */
34 | public RecyclerViewMaterialAdapter(RecyclerView.Adapter adapter, int placeholderSize) {
35 | this.mAdapter = adapter;
36 | mPlaceholderSize = placeholderSize;
37 | }
38 |
39 | @Override
40 | public int getItemViewType(int position) {
41 | if (position < mPlaceholderSize)
42 | return TYPE_PLACEHOLDER;
43 | else
44 | return mAdapter.getItemViewType(position - mPlaceholderSize); //call getItemViewType on the adapter, less mPlaceholderSize
45 | }
46 |
47 | //dispatch getItemCount to the actual adapter, add mPlaceholderSize
48 | @Override
49 | public int getItemCount() {
50 | return mAdapter.getItemCount() + mPlaceholderSize;
51 | }
52 |
53 | //add the header on first position, else display the true adapter's cells
54 | @Override
55 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
56 | View view = null;
57 |
58 | switch (viewType) {
59 | case TYPE_PLACEHOLDER:
60 | {
61 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_card_big, parent, false);
62 | return new RecyclerView.ViewHolder(view) {
63 | };
64 | }
65 | default:
66 | return mAdapter.onCreateViewHolder(parent, viewType);
67 | }
68 | }
69 |
70 | //dispatch onBindViewHolder on the actual mAdapter
71 | @Override
72 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
73 | switch (getItemViewType(position)) {
74 | case TYPE_PLACEHOLDER:
75 | break;
76 | default:
77 | mAdapter.onBindViewHolder(holder, position - mPlaceholderSize);
78 | break;
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hopend/saravana/cardlistgridview/TaskTypePagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.content.Context;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentManager;
6 | import android.support.v4.app.FragmentPagerAdapter;
7 |
8 |
9 |
10 | import java.util.Random;
11 |
12 | public class TaskTypePagerAdapter extends FragmentPagerAdapter {
13 |
14 | private int pagerCount = 2;
15 |
16 | Context ctx;
17 |
18 |
19 | final Fragment[] fragments =
20 | {
21 |
22 |
23 |
24 | };
25 |
26 | private Random random = new Random();
27 |
28 | public TaskTypePagerAdapter(FragmentManager fm, Context ctx)
29 | {
30 | super(fm);
31 |
32 | this.ctx = ctx;
33 |
34 | }
35 |
36 | @Override public Fragment getItem(int i)
37 | {
38 | //return ColorFragment.newInstance(0xff000000 | random.nextInt(0x00ffffff));
39 |
40 | //return ColorFragment.newInstance(0xffffffff);
41 |
42 | if(i==0)
43 | {
44 | return new ListFragment();
45 | }
46 | else
47 | {
48 | return new GridFragment();
49 | }
50 |
51 |
52 |
53 | }
54 |
55 |
56 |
57 | @Override public int getCount() {
58 | return pagerCount;
59 | }
60 |
61 |
62 |
63 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hopend/saravana/cardlistgridview/TestRecyclerViewAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hopend.saravana.cardlistgridview;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import java.util.List;
9 |
10 |
11 | public class TestRecyclerViewAdapter extends RecyclerView.Adapter {
12 |
13 | List