mFragmentsTitles = new ArrayList<>();//每个Fragment对应的title的集合
16 | public MyViewPagerAdapter(FragmentManager fm) {
17 | super(fm);
18 | }
19 | /**
20 | * @param fragment 添加Fragment
21 | * @param fragmentTitle Fragment的标题,即TabLayout中对应Tab的标题
22 | */
23 | public void addFragment(Fragment fragment, String fragmentTitle) {
24 | mFragments.add(fragment);
25 | mFragmentsTitles.add(fragmentTitle);
26 | }
27 |
28 | @Override
29 | public Fragment getItem(int position) {
30 | //得到对应position的Fragment
31 | return mFragments.get(position);
32 | }
33 |
34 | @Override
35 | public int getCount() {
36 | //返回Fragment的数量
37 | return mFragments.size();
38 | }
39 |
40 | @Override
41 | public CharSequence getPageTitle(int position) {
42 | //得到对应position的Fragment的title
43 | return mFragmentsTitles.get(position);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lyx/demo/fragment/FragmentHighPrice.java:
--------------------------------------------------------------------------------
1 | package com.lyx.demo.fragment;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v7.widget.DefaultItemAnimator;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.StaggeredGridLayoutManager;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.lyx.demo.R;
14 | import com.lyx.demo.adapter.MyRecyclerViewAdapter;
15 | import com.lyx.demo.view.LoadMoreRecyclerView;
16 |
17 |
18 | public class FragmentHighPrice extends Fragment {
19 |
20 | private static FragmentHighPrice instance=null;
21 | public static FragmentHighPrice newInstance() {
22 | if(instance==null){
23 | instance= new FragmentHighPrice();
24 | }
25 | return instance;
26 | }
27 | public FragmentHighPrice(){
28 |
29 | }
30 |
31 | @Override
32 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
33 | Bundle savedInstanceState) {
34 | View view = inflater.inflate(R.layout.fragment_layout, container, false);
35 | LoadMoreRecyclerView mRecyclerView = (LoadMoreRecyclerView) view.findViewById(R.id.recycler_view);
36 | mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
37 | mRecyclerView.setItemAnimator(new DefaultItemAnimator());
38 | int[]mImgList = new int[]{R.drawable.g1,R.drawable.g2,R.drawable.g3,R.drawable.g4,R.drawable.g5,R.drawable.g6,R.drawable.g7,R.drawable.g8,R.drawable.g9,R.drawable.g10};
39 | String [] mTag = getActivity().getResources().getStringArray(R.array.test);
40 | mRecyclerView.setAdapter(new MyRecyclerViewAdapter(getActivity(), mImgList,mTag));
41 | return view;
42 | }
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lyx/demo/fragment/FragmentLowPrice.java:
--------------------------------------------------------------------------------
1 | package com.lyx.demo.fragment;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v7.widget.DefaultItemAnimator;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.StaggeredGridLayoutManager;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.lyx.demo.R;
14 | import com.lyx.demo.adapter.MyRecyclerViewAdapter;
15 | import com.lyx.demo.view.LoadMoreRecyclerView;
16 |
17 |
18 | public class FragmentLowPrice extends Fragment {
19 |
20 | private static FragmentLowPrice instance=null;
21 | public static FragmentLowPrice newInstance() {
22 | if(instance==null){
23 | instance= new FragmentLowPrice();
24 | }
25 | return instance;
26 | }
27 | public FragmentLowPrice(){
28 |
29 | }
30 |
31 | @Override
32 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
33 | Bundle savedInstanceState) {
34 | View view = inflater.inflate(R.layout.fragment_layout, container, false);
35 | LoadMoreRecyclerView mRecyclerView = (LoadMoreRecyclerView) view.findViewById(R.id.recycler_view);
36 | mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
37 | mRecyclerView.setItemAnimator(new DefaultItemAnimator());
38 | int[]mImgList = new int[]{R.drawable.g1,R.drawable.g2,R.drawable.g3,R.drawable.g4,R.drawable.g5,R.drawable.g6,R.drawable.g7,R.drawable.g8,R.drawable.g9,R.drawable.g10};
39 | String [] mTag = getActivity().getResources().getStringArray(R.array.test);
40 | mRecyclerView.setAdapter(new MyRecyclerViewAdapter(getActivity(), mImgList,mTag));
41 | return view;
42 | }
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lyx/demo/fragment/FragmentNewProduct.java:
--------------------------------------------------------------------------------
1 | package com.lyx.demo.fragment;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v7.widget.DefaultItemAnimator;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.StaggeredGridLayoutManager;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.lyx.demo.R;
14 | import com.lyx.demo.adapter.MyRecyclerViewAdapter;
15 | import com.lyx.demo.view.LoadMoreRecyclerView;
16 |
17 |
18 | public class FragmentNewProduct extends Fragment {
19 | private static FragmentNewProduct instance=null;
20 | public static FragmentNewProduct newInstance() {
21 | if(instance==null){
22 | instance= new FragmentNewProduct();
23 | }
24 | return instance;
25 | }
26 | public FragmentNewProduct(){}
27 |
28 | @Override
29 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
30 | Bundle savedInstanceState) {
31 | View view = inflater.inflate(R.layout.fragment_layout, container, false);
32 | LoadMoreRecyclerView mRecyclerView = (LoadMoreRecyclerView) view.findViewById(R.id.recycler_view);
33 | mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
34 | mRecyclerView.setItemAnimator(new DefaultItemAnimator());
35 | int[]mImgList = new int[]{R.drawable.g1,R.drawable.g2,R.drawable.g3,R.drawable.g4,R.drawable.g5,R.drawable.g6,R.drawable.g7,R.drawable.g8,R.drawable.g9,R.drawable.g10};
36 | String [] mTag = getActivity().getResources().getStringArray(R.array.test);
37 | mRecyclerView.setAdapter(new MyRecyclerViewAdapter(getActivity(), mImgList,mTag));
38 | return view;
39 | }
40 |
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lyx/demo/fragment/FragmentPopularity.java:
--------------------------------------------------------------------------------
1 | package com.lyx.demo.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.widget.SwipeRefreshLayout;
6 | import android.support.v7.widget.DefaultItemAnimator;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.StaggeredGridLayoutManager;
9 | import android.view.LayoutInflater;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.AdapterView;
14 | import android.widget.Toast;
15 |
16 |
17 | import com.lyx.demo.adapter.MyRecyclerViewAdapter;
18 | import com.lyx.demo.R;
19 | import com.lyx.demo.listener.MyItemClickListener;
20 | import com.lyx.demo.view.LoadMoreRecyclerView;
21 |
22 | public class FragmentPopularity extends Fragment {
23 | private View view;
24 | private SwipeRefreshLayout swipeRefreshLayout;
25 | private static FragmentPopularity instance=null;
26 | public static FragmentPopularity newInstance() {
27 | if(instance==null){
28 | instance= new FragmentPopularity();
29 | }
30 | return instance;
31 | }
32 | public FragmentPopularity(){
33 |
34 | }
35 |
36 | @Override
37 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
38 | Bundle savedInstanceState) {
39 | view = inflater.inflate(R.layout.fragment_layout, container, false);
40 | final LoadMoreRecyclerView mRecyclerView = (LoadMoreRecyclerView) view.findViewById(R.id.recycler_view);
41 | mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
42 | mRecyclerView.setItemAnimator(new DefaultItemAnimator());
43 | int[]mImgList = new int[]{R.drawable.g1,R.drawable.g2,R.drawable.g3,R.drawable.g4,R.drawable.g5,R.drawable.g6,R.drawable.g7,R.drawable.g8,R.drawable.g9,R.drawable.g10};
44 | String [] mTag = getActivity().getResources().getStringArray(R.array.test);
45 | MyRecyclerViewAdapter adapter = new MyRecyclerViewAdapter(getActivity(),mImgList,mTag);
46 | mRecyclerView.setAdapter(adapter);
47 | adapter.setOnItemClickListener(new MyItemClickListener() {
48 | @Override
49 | public void onItemClick(View view, int postion) {
50 | Toast.makeText(getActivity(),"test"+postion,Toast.LENGTH_SHORT).show();
51 | }
52 | });
53 | mRecyclerView.setAutoLoadMoreEnable(true);
54 | mRecyclerView.setLoadMoreListener(new LoadMoreRecyclerView.LoadMoreListener() {
55 | @Override
56 | public void onLoadMore() {
57 | mRecyclerView.postDelayed(new Runnable() {
58 | @Override
59 | public void run() {
60 | swipeRefreshLayout.setRefreshing(false);
61 | Toast.makeText(getActivity(),"加载更多",Toast.LENGTH_SHORT).show();
62 | //TODO 下面注释掉的代码中的false是当数据加载完成以后为false的,然后加载更多的条目就会隐藏。
63 | // mRecyclerView.notifyMoreFinish(false);
64 | }
65 | }, 1000);
66 | }
67 | });
68 | swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
69 | swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
70 | @Override
71 | public void onRefresh() {
72 | swipeRefreshLayout.setRefreshing(false);
73 | Toast.makeText(getActivity(),"刷新",Toast.LENGTH_SHORT).show();
74 | }
75 | });
76 | return view;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lyx/demo/fragment/FragmentSecondsOpen.java:
--------------------------------------------------------------------------------
1 | package com.lyx.demo.fragment;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v7.widget.DefaultItemAnimator;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.StaggeredGridLayoutManager;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.lyx.demo.R;
14 | import com.lyx.demo.adapter.MyRecyclerViewAdapter;
15 | import com.lyx.demo.view.LoadMoreRecyclerView;
16 |
17 |
18 | public class FragmentSecondsOpen extends Fragment {
19 |
20 | private static FragmentSecondsOpen instance=null;
21 | public static FragmentSecondsOpen newInstance() {
22 | if(instance==null){
23 | instance= new FragmentSecondsOpen();
24 | }
25 | return instance;
26 | }
27 | public FragmentSecondsOpen(){
28 |
29 | }
30 |
31 | @Override
32 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
33 | Bundle savedInstanceState) {
34 | View view = inflater.inflate(R.layout.fragment_layout, container, false);
35 | LoadMoreRecyclerView mRecyclerView = (LoadMoreRecyclerView) view.findViewById(R.id.recycler_view);
36 | mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
37 | mRecyclerView.setItemAnimator(new DefaultItemAnimator());
38 | int[]mImgList = new int[]{R.drawable.g1,R.drawable.g2,R.drawable.g3,R.drawable.g4,R.drawable.g5,R.drawable.g6,R.drawable.g7,R.drawable.g8,R.drawable.g9,R.drawable.g10};
39 | String [] mTag = getActivity().getResources().getStringArray(R.array.test);
40 | mRecyclerView.setAdapter(new MyRecyclerViewAdapter(getActivity(), mImgList,mTag));
41 | return view;
42 | }
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lyx/demo/listener/MyItemClickListener.java:
--------------------------------------------------------------------------------
1 | package com.lyx.demo.listener;
2 |
3 | import android.view.View;
4 |
5 | public interface MyItemClickListener {
6 | public void onItemClick(View view, int postion);
7 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/lyx/demo/utils/DensityUtil.java:
--------------------------------------------------------------------------------
1 | package com.lyx.demo.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.util.DisplayMetrics;
6 |
7 | public class DensityUtil {
8 |
9 | // 根据手机的分辨率将dp的单位转成px(像素)
10 | public static int dip2px(Context context, float dpValue) {
11 | final float scale = context.getResources().getDisplayMetrics().density;
12 | return (int) (dpValue * scale + 0.5f);
13 | }
14 |
15 | // 根据手机的分辨率将px(像素)的单位转成dp
16 | public static int px2dip(Context context, float pxValue) {
17 | final float scale = context.getResources().getDisplayMetrics().density;
18 | return (int) (pxValue / scale + 0.5f);
19 | }
20 |
21 | // 将px值转换为sp值
22 | public static int px2sp(Context context, float pxValue) {
23 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
24 | return (int) (pxValue / fontScale + 0.5f);
25 | }
26 |
27 | // 将sp值转换为px值
28 | public static int sp2px(Context context, float spValue) {
29 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
30 | return (int) (spValue * fontScale + 0.5f);
31 | }
32 |
33 | // 屏幕宽度(像素)
34 | public static int getWindowWidth(Activity context){
35 | DisplayMetrics metric = new DisplayMetrics();
36 | context.getWindowManager().getDefaultDisplay().getMetrics(metric);
37 | return metric.widthPixels;
38 | }
39 |
40 | // 屏幕高度(像素)
41 | public static int getWindowHeight(Activity activity){
42 | DisplayMetrics metric = new DisplayMetrics();
43 | activity.getWindowManager().getDefaultDisplay().getMetrics(metric);
44 | return metric.heightPixels;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lyx/demo/utils/ImgUtils.java:
--------------------------------------------------------------------------------
1 | package com.lyx.demo.utils;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.nostra13.universalimageloader.core.DisplayImageOptions;
6 | import com.nostra13.universalimageloader.core.assist.ImageScaleType;
7 | import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
8 | import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
9 |
10 | public class ImgUtils {
11 |
12 | /**
13 | * 使用DisplayImageOptions.Builder()创建DisplayImageOptions,即显示图片的设置
14 | */
15 | public static DisplayImageOptions mDisplayImageOptions() {
16 | DisplayImageOptions options = new DisplayImageOptions.Builder()
17 | .showImageOnLoading(null) // 设置图片下载期间显示的图片
18 | .showImageForEmptyUri(null) // 设置图片Uri为空或是错误的时候显示的图片
19 | .showImageOnFail(null) // 设置图片加载或解码过程中发生错误显示的图片
20 | .cacheInMemory(true) // 设置下载的图片是否缓存在内存中
21 | .cacheOnDisk(true) // 设置下载的图片是否缓存在SD卡中
22 | .considerExifParams(true) // 是否考虑JPEG图像EXIF参数(旋转,翻转)
23 | .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)// 设置图片以如何的编码方式显示(图片会缩放到目标大小完全)
24 | .bitmapConfig(Bitmap.Config.RGB_565) // 设置图片的解码类型
25 | .displayer(new RoundedBitmapDisplayer(30)) // 设置成圆角图片
26 | .build(); // 创建配置过得DisplayImageOption对象
27 | return options;
28 | }
29 |
30 | public static DisplayImageOptions mImageOptions() {
31 | DisplayImageOptions options = new DisplayImageOptions.Builder()
32 | .showImageOnLoading(null) // 设置图片下载期间显示的图片
33 | .showImageForEmptyUri(null) // 设置图片Uri为空或是错误的时候显示的图片
34 | .showImageOnFail(null) // 设置图片加载或解码过程中发生错误显示的图片
35 | .cacheInMemory(true) // 设置下载的图片是否缓存在内存中
36 | .cacheOnDisk(true) // 设置下载的图片是否缓存在SD卡中
37 | .considerExifParams(true) // 是否考虑JPEG图像EXIF参数(旋转,翻转)
38 | .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)// 设置图片以如何的编码方式显示(图片会缩放到目标大小完全)
39 | .bitmapConfig(Bitmap.Config.RGB_565) // 设置图片的解码类型
40 | .displayer(new FadeInBitmapDisplayer(100)) // 是否图片加载好后渐入的动画时间
41 | .build(); // 创建配置过得DisplayImageOption对象
42 | return options;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lyx/demo/view/LoadMoreRecyclerView.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Alipay.com Inc.
3 | * Copyright (c) 2004-2015 All Rights Reserved.
4 | */
5 | package com.lyx.demo.view;
6 |
7 | import android.content.Context;
8 | import android.support.v7.widget.GridLayoutManager;
9 | import android.support.v7.widget.LinearLayoutManager;
10 | import android.support.v7.widget.RecyclerView;
11 | import android.support.v7.widget.StaggeredGridLayoutManager;
12 | import android.util.AttributeSet;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 |
17 | import com.lyx.demo.R;
18 |
19 | /**
20 | * 支持上拉加载更多的
21 | *
22 | */
23 | public class LoadMoreRecyclerView extends RecyclerView {
24 | /**
25 | * item 类型
26 | */
27 | public final static int TYPE_NORMAL = 0;
28 | public final static int TYPE_HEADER = 1;//头部--支持头部增加一个headerView
29 | public final static int TYPE_FOOTER = 2;//底部--往往是loading_more
30 | public final static int TYPE_LIST = 3;//代表item展示的模式是list模式
31 | public final static int TYPE_STAGGER = 4;//代码item展示模式是网格模式
32 |
33 | private boolean mIsFooterEnable = false;//是否允许加载更多
34 |
35 | /**
36 | * 自定义实现了头部和底部加载更多的adapter
37 | */
38 | private AutoLoadAdapter mAutoLoadAdapter;
39 | /**
40 | * 标记是否正在加载更多,防止再次调用加载更多接口
41 | */
42 | private boolean mIsLoadingMore;
43 | /**
44 | * 标记加载更多的position
45 | */
46 | private int mLoadMorePosition;
47 | /**
48 | * 加载更多的监听-业务需要实现加载数据
49 | */
50 | private LoadMoreListener mListener;
51 |
52 | public LoadMoreRecyclerView(Context context) {
53 | super(context);
54 | init();
55 | }
56 |
57 | public LoadMoreRecyclerView(Context context, AttributeSet attrs) {
58 | super(context, attrs);
59 | init();
60 | }
61 |
62 | public LoadMoreRecyclerView(Context context, AttributeSet attrs, int defStyle) {
63 | super(context, attrs, defStyle);
64 | init();
65 | }
66 |
67 | /**
68 | * 初始化-添加滚动监听
69 | *
70 | * 回调加载更多方法,前提是
71 | *
72 | * 1、有监听并且支持加载更多:null != mListener && mIsFooterEnable
73 | * 2、目前没有在加载,正在上拉(dy>0),当前最后一条可见的view是否是当前数据列表的最好一条--及加载更多
74 | *
75 | */
76 | private void init() {
77 | super.addOnScrollListener(new OnScrollListener() {
78 |
79 | @Override
80 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
81 | super.onScrollStateChanged(recyclerView, newState);
82 | }
83 |
84 | @Override
85 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
86 | super.onScrolled(recyclerView, dx, dy);
87 | if (null != mListener && mIsFooterEnable && !mIsLoadingMore && dy > 0) {
88 | int lastVisiblePosition = getLastVisiblePosition();
89 | if (lastVisiblePosition + 1 == mAutoLoadAdapter.getItemCount()) {
90 | setLoadingMore(true);
91 | mLoadMorePosition = lastVisiblePosition;
92 | mListener.onLoadMore();
93 | }
94 | }
95 | }
96 | });
97 | }
98 |
99 | /**
100 | * 设置加载更多的监听
101 | *
102 | * @param listener
103 | */
104 | public void setLoadMoreListener(LoadMoreListener listener) {
105 | mListener = listener;
106 | }
107 |
108 | /**
109 | * 设置正在加载更多
110 | *
111 | * @param loadingMore
112 | */
113 | public void setLoadingMore(boolean loadingMore) {
114 | this.mIsLoadingMore = loadingMore;
115 | }
116 |
117 | /**
118 | * 加载更多监听
119 | */
120 | public interface LoadMoreListener {
121 | /**
122 | * 加载更多
123 | */
124 | void onLoadMore();
125 | }
126 |
127 | /**
128 | *
129 | */
130 | public class AutoLoadAdapter extends Adapter {
131 |
132 | /**
133 | * 数据adapter
134 | */
135 | private Adapter mInternalAdapter;
136 |
137 | private boolean mIsHeaderEnable;
138 | private int mHeaderResId;
139 |
140 | public AutoLoadAdapter(Adapter adapter) {
141 | mInternalAdapter = adapter;
142 | mIsHeaderEnable = false;
143 | }
144 |
145 | @Override
146 | public int getItemViewType(int position) {
147 | int headerPosition = 0;
148 | int footerPosition = getItemCount() - 1;
149 |
150 | if (headerPosition == position && mIsHeaderEnable && mHeaderResId > 0) {
151 | return TYPE_HEADER;
152 | }
153 | if (footerPosition == position && mIsFooterEnable) {
154 | return TYPE_FOOTER;
155 | }
156 | /**
157 | * 这么做保证layoutManager切换之后能及时的刷新上对的布局
158 | */
159 | if (getLayoutManager() instanceof LinearLayoutManager) {
160 | return TYPE_LIST;
161 | } else if (getLayoutManager() instanceof StaggeredGridLayoutManager) {
162 | return TYPE_STAGGER;
163 | } else {
164 | return TYPE_NORMAL;
165 | }
166 | }
167 |
168 | @Override
169 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
170 | if (viewType == TYPE_HEADER) {
171 | return new HeaderViewHolder(LayoutInflater.from(parent.getContext()).inflate(
172 | mHeaderResId, parent, false));
173 | }
174 | if (viewType == TYPE_FOOTER) {
175 | return new FooterViewHolder(
176 | LayoutInflater.from(parent.getContext()).inflate(
177 | R.layout.list_foot_loading, parent, false));
178 | } else { // type normal
179 | return mInternalAdapter.onCreateViewHolder(parent, viewType);
180 | }
181 | }
182 |
183 | public class FooterViewHolder extends ViewHolder {
184 |
185 | public FooterViewHolder(View itemView) {
186 | super(itemView);
187 | }
188 | }
189 |
190 | public class HeaderViewHolder extends ViewHolder {
191 | public HeaderViewHolder(View itemView) {
192 | super(itemView);
193 | }
194 | }
195 |
196 | @Override
197 | public void onBindViewHolder(ViewHolder holder, int position) {
198 | int type = getItemViewType(position);
199 | if (type != TYPE_FOOTER && type != TYPE_HEADER) {
200 | mInternalAdapter.onBindViewHolder(holder, position);
201 | }
202 | }
203 |
204 | /**
205 | * 需要计算上加载更多和添加的头部俩个
206 | *
207 | * @return
208 | */
209 | @Override
210 | public int getItemCount() {
211 | int count = mInternalAdapter.getItemCount();
212 | if (mIsFooterEnable) count++;
213 | if (mIsHeaderEnable) count++;
214 |
215 | return count;
216 | }
217 |
218 | public void setHeaderEnable(boolean enable) {
219 | mIsHeaderEnable = enable;
220 | }
221 |
222 | public void addHeaderView(int resId) {
223 | mHeaderResId = resId;
224 | }
225 | }
226 |
227 | @Override
228 | public void setAdapter(Adapter adapter) {
229 | if (adapter != null) {
230 | mAutoLoadAdapter = new AutoLoadAdapter(adapter);
231 | }
232 | super.swapAdapter(mAutoLoadAdapter, true);
233 | }
234 |
235 | /**
236 | * 切换layoutManager
237 | *
238 | * 为了保证切换之后页面上还是停留在当前展示的位置,记录下切换之前的第一条展示位置,切换完成之后滚动到该位置
239 | * 另外切换之后必须要重新刷新下当前已经缓存的itemView,否则会出现布局错乱(俩种模式下的item布局不同),
240 | * RecyclerView提供了swapAdapter来进行切换adapter并清理老的itemView cache
241 | *
242 | * @param layoutManager
243 | */
244 | public void switchLayoutManager(LayoutManager layoutManager) {
245 | int firstVisiblePosition = getFirstVisiblePosition();
246 | // getLayoutManager().removeAllViews();
247 | setLayoutManager(layoutManager);
248 | // super.swapAdapter(mAutoLoadAdapter, true);
249 | getLayoutManager().scrollToPosition(firstVisiblePosition);
250 | }
251 |
252 | /**
253 | * 获取第一条展示的位置
254 | *
255 | * @return
256 | */
257 | private int getFirstVisiblePosition() {
258 | int position;
259 | if (getLayoutManager() instanceof LinearLayoutManager) {
260 | position = ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();
261 | } else if (getLayoutManager() instanceof GridLayoutManager) {
262 | position = ((GridLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();
263 | } else if (getLayoutManager() instanceof StaggeredGridLayoutManager) {
264 | StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) getLayoutManager();
265 | int[] lastPositions = layoutManager.findFirstVisibleItemPositions(new int[layoutManager.getSpanCount()]);
266 | position = getMinPositions(lastPositions);
267 | } else {
268 | position = 0;
269 | }
270 | return position;
271 | }
272 |
273 | /**
274 | * 获得当前展示最小的position
275 | *
276 | * @param positions
277 | * @return
278 | */
279 | private int getMinPositions(int[] positions) {
280 | int size = positions.length;
281 | int minPosition = Integer.MAX_VALUE;
282 | for (int i = 0; i < size; i++) {
283 | minPosition = Math.min(minPosition, positions[i]);
284 | }
285 | return minPosition;
286 | }
287 |
288 | /**
289 | * 获取最后一条展示的位置
290 | *
291 | * @return
292 | */
293 | private int getLastVisiblePosition() {
294 | int position;
295 | if (getLayoutManager() instanceof LinearLayoutManager) {
296 | position = ((LinearLayoutManager) getLayoutManager()).findLastVisibleItemPosition();
297 | } else if (getLayoutManager() instanceof GridLayoutManager) {
298 | position = ((GridLayoutManager) getLayoutManager()).findLastVisibleItemPosition();
299 | } else if (getLayoutManager() instanceof StaggeredGridLayoutManager) {
300 | StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) getLayoutManager();
301 | int[] lastPositions = layoutManager.findLastVisibleItemPositions(new int[layoutManager.getSpanCount()]);
302 | position = getMaxPosition(lastPositions);
303 | } else {
304 | position = getLayoutManager().getItemCount() - 1;
305 | }
306 | return position;
307 | }
308 |
309 | /**
310 | * 获得最大的位置
311 | *
312 | * @param positions
313 | * @return
314 | */
315 | private int getMaxPosition(int[] positions) {
316 | int size = positions.length;
317 | int maxPosition = Integer.MIN_VALUE;
318 | for (int i = 0; i < size; i++) {
319 | maxPosition = Math.max(maxPosition, positions[i]);
320 | }
321 | return maxPosition;
322 | }
323 |
324 | /**
325 | * 添加头部view
326 | *
327 | * @param resId
328 | */
329 | public void addHeaderView(int resId) {
330 | mAutoLoadAdapter.addHeaderView(resId);
331 | }
332 |
333 | /**
334 | * 设置头部view是否展示
335 | * @param enable
336 | */
337 | public void setHeaderEnable(boolean enable) {
338 | mAutoLoadAdapter.setHeaderEnable(enable);
339 | }
340 |
341 | /**
342 | * 设置是否支持自动加载更多
343 | *
344 | * @param autoLoadMore
345 | */
346 | public void setAutoLoadMoreEnable(boolean autoLoadMore) {
347 | mIsFooterEnable = autoLoadMore;
348 | }
349 |
350 | /**
351 | * 通知更多的数据已经加载
352 | *
353 | * 每次加载完成之后添加了Data数据,用notifyItemRemoved来刷新列表展示,
354 | * 而不是用notifyDataSetChanged来刷新列表
355 | *
356 | * @param hasMore
357 | */
358 | public void notifyMoreFinish(boolean hasMore) {
359 | setAutoLoadMoreEnable(hasMore);
360 | getAdapter().notifyItemRemoved(mLoadMorePosition);
361 | mIsLoadingMore = false;
362 | }
363 | }
364 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g10.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g11.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g11.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g12.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g12.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g13.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g13.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g14.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g14.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g15.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g15.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g16.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g16.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g17.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g17.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g18.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g18.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g19.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g19.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g20.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g20.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g6.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g7.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g8.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/g9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/g9.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/home_banner_index_mask.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xxhdpi/home_banner_index_mask.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/xml_round_grey_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/xml_round_orange_grey_sel.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/xml_round_orange_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
18 |
23 |
24 |
34 |
35 |
44 |
45 |
46 |
52 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_layout.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_gv_active.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_foot_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
15 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LyxDemo
3 |
4 | - 我是测试①
5 | - 我是测试②
6 | - 我是测试③
7 | - 我是测试④
8 | - 我是测试⑤
9 | - 我是测试⑥
10 | - 我是测试⑦
11 | - 我是测试⑧
12 | - 我是测试⑨
13 | - 我是测试10
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/hdc/appbarlayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hdc.appbarlayout;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------