├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── libs │ └── imageloader_library.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hdc │ │ └── appbarlayout │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── lyx │ │ │ └── demo │ │ │ ├── activities │ │ │ └── MainActivity.java │ │ │ ├── adapter │ │ │ ├── BannerAdapter.java │ │ │ ├── MyRecyclerViewAdapter.java │ │ │ ├── MyViewHolder.java │ │ │ └── MyViewPagerAdapter.java │ │ │ ├── fragment │ │ │ ├── FragmentHighPrice.java │ │ │ ├── FragmentLowPrice.java │ │ │ ├── FragmentNewProduct.java │ │ │ ├── FragmentPopularity.java │ │ │ └── FragmentSecondsOpen.java │ │ │ ├── listener │ │ │ └── MyItemClickListener.java │ │ │ ├── utils │ │ │ ├── DensityUtil.java │ │ │ └── ImgUtils.java │ │ │ └── view │ │ │ └── LoadMoreRecyclerView.java │ └── res │ │ ├── drawable-hdpi │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ ├── g1.jpg │ │ ├── g10.jpg │ │ ├── g11.jpg │ │ ├── g12.jpg │ │ ├── g13.jpg │ │ ├── g14.jpg │ │ ├── g15.jpg │ │ ├── g16.jpg │ │ ├── g17.jpg │ │ ├── g18.jpg │ │ ├── g19.jpg │ │ ├── g2.jpg │ │ ├── g20.jpg │ │ ├── g3.jpg │ │ ├── g4.jpg │ │ ├── g5.jpg │ │ ├── g6.jpg │ │ ├── g7.jpg │ │ ├── g8.jpg │ │ ├── g9.jpg │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ ├── home_banner_index_mask.png │ │ └── ic_launcher.png │ │ ├── drawable-xxxhdpi │ │ └── ic_launcher.png │ │ ├── drawable │ │ ├── xml_round_grey_icon.xml │ │ ├── xml_round_orange_grey_sel.xml │ │ └── xml_round_orange_icon.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_layout.xml │ │ ├── item_gv_active.xml │ │ ├── layout_item.xml │ │ └── list_foot_loading.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── hdc │ └── appbarlayout │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | LyxDemo -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | C:\Users\ytx\AppData\Roaming\Subversion 48 | 49 | 50 | 51 | 52 | 53 | 1.8 54 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment 2 | 标题栏本来是在banner的下方,当滑动下面的RecyclerView的时候标题栏会随着向上移动,但是当标题栏移动到顶部时是要悬浮在顶部, 3 | 下面无论如何上滑标题拦都不再移动,当向下滑动时知直到出现RecyclerView的第一条时标题栏才会随着向下移动 4 | ![](http://img.blog.csdn.net/20161008172637173) 5 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.hdc.appbarlayout" 9 | minSdkVersion 15 10 | targetSdkVersion 23 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 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | compile 'com.android.support:recyclerview-v7:23.4.0' 27 | compile 'com.android.support:design:23.4.0' 28 | compile files('libs/imageloader_library.jar') 29 | } 30 | -------------------------------------------------------------------------------- /app/libs/imageloader_library.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyxRobert/Android-AppBarLayout-TabLayout-RecyclerView-ViewPager-Fragment/09a39e6701aa379c5f6c48b0b65ac6cea8ce99d7/app/libs/imageloader_library.jar -------------------------------------------------------------------------------- /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 D:\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/hdc/appbarlayout/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.hdc.appbarlayout; 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 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/lyx/demo/activities/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.lyx.demo.activities; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | import android.support.design.widget.TabLayout; 7 | import android.support.v4.view.ViewPager; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.widget.ImageView; 10 | import android.widget.LinearLayout; 11 | 12 | import com.lyx.demo.R; 13 | import com.lyx.demo.adapter.BannerAdapter; 14 | import com.lyx.demo.adapter.MyViewPagerAdapter; 15 | import com.lyx.demo.fragment.FragmentLowPrice; 16 | import com.lyx.demo.fragment.FragmentHighPrice; 17 | import com.lyx.demo.fragment.FragmentPopularity; 18 | import com.lyx.demo.fragment.FragmentSecondsOpen; 19 | import com.lyx.demo.fragment.FragmentNewProduct; 20 | import com.lyx.demo.utils.DensityUtil; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | 26 | public class MainActivity extends AppCompatActivity { 27 | LinearLayout llIndexContainer; 28 | private List mADParseArray; 29 | private final int HOME_AD_RESULT = 1; 30 | private ViewPager vp_shuffling; 31 | private Handler mHandler = new Handler() { 32 | public void handleMessage(Message msg) { 33 | switch (msg.what) { 34 | // 广告 35 | case HOME_AD_RESULT: 36 | vp_shuffling.setCurrentItem(vp_shuffling.getCurrentItem() + 1, 37 | true); 38 | break; 39 | } 40 | }; 41 | }; 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setContentView(R.layout.activity_main); 46 | initView(); 47 | ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager); 48 | MyViewPagerAdapter viewPagerAdapter = new MyViewPagerAdapter(getSupportFragmentManager()); 49 | viewPagerAdapter.addFragment(FragmentPopularity.newInstance(), "人气");//添加Fragment 50 | viewPagerAdapter.addFragment(FragmentNewProduct.newInstance(), "新品"); 51 | viewPagerAdapter.addFragment(FragmentSecondsOpen.newInstance(), "秒开"); 52 | viewPagerAdapter.addFragment(FragmentHighPrice.newInstance(), "高价"); 53 | viewPagerAdapter.addFragment(FragmentLowPrice.newInstance(), "低价"); 54 | mViewPager.setAdapter(viewPagerAdapter);//设置适配器 55 | 56 | TabLayout mTabLayout = (TabLayout) findViewById(R.id.tabLayout); 57 | mTabLayout.addTab(mTabLayout.newTab().setText("人气"));//给TabLayout添加Tab 58 | mTabLayout.addTab(mTabLayout.newTab().setText("新品")); 59 | mTabLayout.addTab(mTabLayout.newTab().setText("秒开")); 60 | mTabLayout.addTab(mTabLayout.newTab().setText("高价")); 61 | mTabLayout.addTab(mTabLayout.newTab().setText("低价")); 62 | mTabLayout.setupWithViewPager(mViewPager);//给TabLayout设置关联ViewPager,如果设置了ViewPager,那么ViewPagerAdapter中的getPageTitle()方法返回的就是Tab上的标题 63 | } 64 | 65 | private void initView() { 66 | vp_shuffling = (ViewPager) findViewById(R.id.vp_shuffling); 67 | // 广告数据 68 | llIndexContainer = (LinearLayout)findViewById(R.id.ll_index_container); 69 | mADParseArray = new ArrayList(); 70 | mADParseArray 71 | .add("http://m.easyto.com/m/zhulifuwu_banner.jpg"); 72 | mADParseArray 73 | .add("http://m.easyto.com/m/japan/images/banner_3y_new.jpg"); 74 | mADParseArray 75 | .add("http://m.easyto.com/m/japan/images/banner_5y_new.jpg"); 76 | vp_shuffling.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 77 | 78 | @Override 79 | public void onPageSelected(int position) { 80 | refreshPoint(position % mADParseArray.size()); 81 | if (mHandler.hasMessages(HOME_AD_RESULT)) { 82 | mHandler.removeMessages(HOME_AD_RESULT); 83 | } 84 | mHandler.sendEmptyMessageDelayed(HOME_AD_RESULT, 3000); 85 | } 86 | 87 | @Override 88 | public void onPageScrolled(int arg0, float arg1, int arg2) { 89 | } 90 | 91 | @Override 92 | public void onPageScrollStateChanged(int arg0) { 93 | if (ViewPager.SCROLL_STATE_DRAGGING == arg0 94 | && mHandler.hasMessages(HOME_AD_RESULT)) { 95 | mHandler.removeMessages(HOME_AD_RESULT); 96 | } 97 | } 98 | }); 99 | BannerAdapter adapter = new BannerAdapter(MainActivity.this, mADParseArray); 100 | vp_shuffling.setAdapter(adapter); 101 | addIndicatorImageViews(mADParseArray.size()); 102 | vp_shuffling.setCurrentItem(mADParseArray.size() * 1000, false); 103 | // 自动轮播线程 104 | mHandler.sendEmptyMessageDelayed(HOME_AD_RESULT, 3000); 105 | } 106 | // 添加指示图标 107 | private void addIndicatorImageViews(int size) { 108 | llIndexContainer.removeAllViews(); 109 | for (int i = 0; i < size; i++) { 110 | ImageView iv = new ImageView(MainActivity.this); 111 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(DensityUtil.dip2px(MainActivity.this, 5), DensityUtil.dip2px(MainActivity.this, 5)); 112 | if (i != 0) { 113 | lp.leftMargin = DensityUtil.dip2px(MainActivity.this, 7); 114 | } 115 | iv.setLayoutParams(lp); 116 | iv.setBackgroundResource(R.drawable.xml_round_orange_grey_sel); 117 | iv.setEnabled(false); 118 | if (i == 0) { 119 | iv.setEnabled(true); 120 | } 121 | llIndexContainer.addView(iv); 122 | } 123 | } 124 | // 为ViewPager设置监听器 125 | private void refreshPoint(int position) { 126 | if (llIndexContainer != null) { 127 | for (int i = 0; i < llIndexContainer.getChildCount(); i++) { 128 | llIndexContainer.getChildAt(i).setEnabled(false); 129 | if (i == position) { 130 | llIndexContainer.getChildAt(i).setEnabled(true); 131 | } 132 | } 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /app/src/main/java/com/lyx/demo/adapter/BannerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lyx.demo.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ImageView; 8 | 9 | import com.lyx.demo.utils.ImgUtils; 10 | import com.nostra13.universalimageloader.core.DisplayImageOptions; 11 | import com.nostra13.universalimageloader.core.ImageLoader; 12 | import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; 13 | 14 | import java.util.List; 15 | 16 | 17 | 18 | public class BannerAdapter extends PagerAdapter { 19 | private List adList; 20 | private Context context; 21 | private DisplayImageOptions options; 22 | private ImageLoader imageLoader; 23 | public BannerAdapter(Context mContext, List adList) { 24 | this.adList = adList; 25 | context = mContext; 26 | options = ImgUtils.mImageOptions(); 27 | imageLoader = ImageLoader.getInstance(); 28 | imageLoader.init(ImageLoaderConfiguration.createDefault(mContext)); 29 | } 30 | 31 | @Override 32 | public int getCount() { 33 | return Integer.MAX_VALUE; 34 | } 35 | 36 | @Override 37 | public Object instantiateItem(ViewGroup container, int arg2) { 38 | final int position = arg2 % adList.size(); 39 | ImageView imageView = new ImageView(context); 40 | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 41 | ViewGroup.LayoutParams.MATCH_PARENT); 42 | imageView.setLayoutParams(params); 43 | imageView.setScaleType(ImageView.ScaleType.FIT_XY); 44 | // imageView.setOnClickListener(new OnClickListener() { 45 | // 46 | // @Override 47 | // public void onClick(View v) { 48 | // if (adList != null) { 49 | // Intent mIntent = new Intent(); 50 | // if (adList.get(position).getTYPE().equals("1")) { 51 | // Intent intent= new Intent(); 52 | // intent.setAction("android.intent.action.VIEW"); 53 | // Uri content_url = Uri.parse(adList.get(position).getBOOKID().trim()); 54 | // intent.setData(content_url); 55 | // mContext.startActivity(intent); 56 | // } else if (adList.get(position).getTYPE().equals("2")){ 57 | // Bundle bundle = new Bundle(); 58 | // bundle.putString("bookId", adList.get(position).getBOOKID().trim()); 59 | // mActivity.index(Constants.Code.DETAIL_CONTENT, bundle); 60 | // }else if (adList.get(position).getTYPE().equals("3")){ 61 | // 62 | // } 63 | // try { 64 | // mContext.startActivity(mIntent); 65 | // } catch (Exception e) { 66 | // e.printStackTrace(); 67 | // } 68 | // } 69 | // } 70 | // }); 71 | imageLoader.displayImage(adList.get(position), imageView, options); 72 | container.addView(imageView, ViewGroup.LayoutParams.MATCH_PARENT, 73 | ViewGroup.LayoutParams.MATCH_PARENT); 74 | return imageView; 75 | } 76 | 77 | @Override 78 | public boolean isViewFromObject(View view, Object object) { 79 | return view == object; 80 | } 81 | @Override 82 | public void destroyItem(ViewGroup container, int position, Object object) { 83 | container.removeView((View) object); 84 | } 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/com/lyx/demo/adapter/MyRecyclerViewAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lyx.demo.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.lyx.demo.R; 10 | import com.lyx.demo.listener.MyItemClickListener; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by ytx on 2016/10/8. 16 | */ 17 | public class MyRecyclerViewAdapter extends RecyclerView.Adapter implements View.OnClickListener{ 18 | private int [] mImgList; 19 | private String[]mTag; 20 | private Context context; 21 | private List lists; 22 | private MyItemClickListener mOnItemClickListener = null; 23 | public MyRecyclerViewAdapter(Context context,int [] mImgList, String[]mTag) { 24 | this.mImgList = mImgList; 25 | this.mTag = mTag; 26 | this.context = context; 27 | } 28 | 29 | 30 | @Override 31 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 32 | View view = LayoutInflater.from(context).inflate(R.layout.item_gv_active, parent, false); 33 | MyViewHolder viewHolder = new MyViewHolder(view); 34 | view.setOnClickListener(this); 35 | return viewHolder; 36 | } 37 | 38 | @Override 39 | public void onBindViewHolder(MyViewHolder holder, int position) { 40 | holder.mImg.setBackgroundResource(mImgList[position]); 41 | holder.mTextView.setText(mTag[position]); 42 | holder.itemView.setTag(position); 43 | } 44 | 45 | @Override 46 | public int getItemCount() { 47 | return mImgList.length; 48 | } 49 | 50 | @Override 51 | public void onClick(View v) { 52 | if(mOnItemClickListener != null){ 53 | mOnItemClickListener.onItemClick(v,(int)v.getTag()); 54 | } 55 | } 56 | public void setOnItemClickListener(MyItemClickListener listener) { 57 | this.mOnItemClickListener = listener; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/lyx/demo/adapter/MyViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.lyx.demo.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.View; 5 | import android.widget.ImageView; 6 | import android.widget.TextView; 7 | 8 | import com.lyx.demo.R; 9 | import com.lyx.demo.listener.MyItemClickListener; 10 | 11 | class MyViewHolder extends RecyclerView.ViewHolder implements MyItemClickListener { 12 | TextView mTextView; 13 | ImageView mImg; 14 | public MyViewHolder(View itemView) { 15 | super(itemView); 16 | mTextView = (TextView) itemView.findViewById(R.id.tv_active); 17 | mImg = (ImageView)itemView.findViewById(R.id.img_active); 18 | } 19 | 20 | @Override 21 | public void onItemClick(View view, int postion) { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/lyx/demo/adapter/MyViewPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lyx.demo.adapter; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by 晓勇 on 2015/7/12 0012. 12 | */ 13 | public class MyViewPagerAdapter extends FragmentPagerAdapter { 14 | private final List mFragments = new ArrayList<>();//添加的Fragment的集合 15 | private final List 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 | --------------------------------------------------------------------------------