├── .gitignore
├── README.md
├── android_home_page_filter.gif
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── lvfq
│ │ └── homepage_master
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── lvfq
│ │ │ └── homepage_master
│ │ │ ├── BannerViewPagerFragment.java
│ │ │ ├── MainActivity.java
│ │ │ ├── RecyclerViewScrollActivity.java
│ │ │ ├── StartActivity.java
│ │ │ ├── adapter
│ │ │ └── ListViewBaseAdapter.java
│ │ │ ├── impl
│ │ │ ├── IAreaCallBack.java
│ │ │ ├── IFilterCallBack.java
│ │ │ └── OnScrollChangedListener.java
│ │ │ ├── util
│ │ │ ├── DPUtil.java
│ │ │ ├── V.java
│ │ │ └── ViewHolder.java
│ │ │ └── view
│ │ │ ├── CusScrollView.java
│ │ │ ├── FilterView.java
│ │ │ └── MaxListView.java
│ └── res
│ │ ├── color
│ │ └── color_main_text_filter.xml
│ │ ├── drawable-xhdpi
│ │ ├── img_banner_1.jpg
│ │ ├── img_banner_2.jpg
│ │ ├── img_banner_3.jpg
│ │ ├── img_banner_4.jpg
│ │ ├── img_banner_def.jpg
│ │ ├── img_main_tipsel_nor.png
│ │ └── img_main_tipsel_sel.png
│ │ ├── drawable
│ │ ├── dot_focused.xml
│ │ ├── dot_normal.xml
│ │ └── draw_main_text_filter.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_recyclerview_scroll.xml
│ │ ├── activity_start.xml
│ │ ├── fragment_bannervp.xml
│ │ ├── item_filter_list1.xml
│ │ ├── item_filter_list2.xml
│ │ ├── item_filter_single.xml
│ │ ├── item_main_listview.xml
│ │ └── layout_filter.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── lvfq
│ └── homepage_master
│ └── 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 | .externalNativeBuild
10 | /.idea/
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HomePageFilter
2 | Android 常用于首页的条件筛选效果.
3 |
4 | blog: [Android Filter ListView , RecyclerView ](http://blog.csdn.net/lv_fq/article/details/69062592)
5 |
6 | 效果图:
7 |
8 | 
9 |
--------------------------------------------------------------------------------
/android_home_page_filter.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/android_home_page_filter.gif
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.lvfq.homepage_master"
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.0.0'
28 | testCompile 'junit:junit:4.12'
29 | compile 'com.android.support:recyclerview-v7:25.0.0'
30 | }
31 |
--------------------------------------------------------------------------------
/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 /Users/apple/Library/Android/sdk/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/lvfq/homepage_master/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.lvfq.homepage_master", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/BannerViewPagerFragment.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Parcelable;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.view.PagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 | import android.support.v4.view.ViewPager.OnPageChangeListener;
11 | import android.util.DisplayMetrics;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.View.OnClickListener;
15 | import android.view.ViewGroup;
16 | import android.widget.FrameLayout;
17 | import android.widget.ImageView;
18 | import android.widget.ImageView.ScaleType;
19 | import android.widget.LinearLayout;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 | import java.util.concurrent.Executors;
26 | import java.util.concurrent.ScheduledExecutorService;
27 | import java.util.concurrent.TimeUnit;
28 |
29 | public class BannerViewPagerFragment extends Fragment {
30 |
31 | private TextView banner_title_tv;
32 | private int currentItem = 0; // 当前图片的索引号
33 | private ViewPager viewPager;
34 | private BannerPagerAdapter bannerPagerAdapter;
35 | private List imageViews; // 滑动的图片集合
36 | private String[] titles; // 图片标题
37 | private List dots; // 图片标题正文的那些点
38 | private int screenWidth;
39 | private LinearLayout dotsLL; // 小圆点的容器
40 | private Context mContext;
41 | private FrameLayout banner_fl;
42 | private ScheduledExecutorService scheduledExecutorService;
43 | private ImageView imgFault;
44 | private Boolean flag = false;
45 |
46 | private int[] imgs = new int[]{R.drawable.img_banner_4, R.drawable.img_banner_1, R.drawable.img_banner_2, R.drawable.img_banner_3};
47 |
48 | @Override
49 | public void onCreate(Bundle savedInstanceState) {
50 | // TODO Auto-generated method stub
51 | super.onCreate(savedInstanceState);
52 | mContext = getActivity();
53 |
54 | }
55 |
56 | @Override
57 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
58 | Bundle savedInstanceState) {
59 | // TODO Auto-generated method stub
60 | View mView = inflater.inflate(
61 | getResources().getLayout(R.layout.fragment_bannervp),
62 | container, false);
63 | initView(mView);
64 | setTestData();
65 | return mView;
66 | }
67 |
68 |
69 | private void setTestData() {
70 | initFocusView(imgs.length);
71 | bannerPagerAdapter.notifyDataSetChanged();
72 | // for (int i = 0; i < mList.size(); i++) {
73 | // imageViews.get(i).setImageResource(mList.get(i));
74 | // }
75 | banner_fl.setVisibility(View.VISIBLE);
76 | imgFault.setVisibility(View.GONE);
77 |
78 | }
79 |
80 |
81 | @Override
82 | public void onResume() {
83 | // TODO Auto-generated method stub
84 |
85 | viewPager.setCurrentItem(0);// 切换当前显示的图片
86 | scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
87 | // 当Activity显示出来后,每两秒钟切换一次图片显示
88 | scheduledExecutorService.scheduleAtFixedRate(new ScrollTask(), 6, 6,
89 | TimeUnit.SECONDS);
90 | super.onResume();
91 |
92 | }
93 |
94 | public void initView(View mView) {
95 | banner_fl = (FrameLayout) mView
96 | .findViewById(R.id.more_banner_framelayout);
97 | viewPager = (ViewPager) mView.findViewById(R.id.more_banner_vp);
98 | dotsLL = (LinearLayout) mView.findViewById(R.id.more_dots_ll);
99 | banner_title_tv = (TextView) mView
100 | .findViewById(R.id.more_banner_title_tv);
101 |
102 | bannerPagerAdapter = new BannerPagerAdapter();
103 | imageViews = new ArrayList();
104 | dots = new ArrayList();
105 | viewPager.setAdapter(bannerPagerAdapter);
106 |
107 | DisplayMetrics dm = new DisplayMetrics();
108 | getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
109 | screenWidth = dm.widthPixels;
110 | imgFault = (ImageView) mView.findViewById(R.id.imgFault);
111 | }
112 |
113 |
114 | @Override
115 | public void onStart() {
116 |
117 | super.onStart();
118 | }
119 |
120 | @Override
121 | public void onPause() {
122 | scheduledExecutorService.shutdown();
123 | flag = false;
124 | bannerHandler.removeMessages(0);
125 | super.onPause();
126 | }
127 |
128 | @Override
129 | public void onStop() {
130 | // 当Activity不可见的时候停止切换
131 | flag = false;
132 |
133 | bannerHandler.removeMessages(0);
134 | super.onStop();
135 | }
136 |
137 | /**
138 | * 换页切换任务
139 | *
140 | * @author Administrator
141 | */
142 | private class ScrollTask implements Runnable {
143 |
144 | public void run() {
145 | synchronized (viewPager) {
146 | //if(!flag){
147 | currentItem = (currentItem + 1) % imageViews.size();
148 | bannerHandler.obtainMessage().sendToTarget(); // 通过Handler切换图片
149 | // }else{
150 | // flag=false;
151 | // currentItem = 0;
152 | // bannerHandler.obtainMessage().sendToTarget(); // 通过Handler切换图片
153 | // }
154 | }
155 | }
156 |
157 | }
158 |
159 | // 切换当前显示的图片
160 | private Handler bannerHandler = new Handler() {
161 | public void handleMessage(android.os.Message msg) {
162 | if (flag) {
163 | viewPager.setCurrentItem(currentItem);// 切换当前显示的图片
164 | } else {
165 | bannerHandler.removeMessages(0);
166 | viewPager.setCurrentItem(0);
167 | flag = true;
168 | }
169 | }
170 |
171 | ;
172 | };
173 |
174 | /**
175 | * 填充ViewPager页面的适配器
176 | *
177 | * @author Administrator
178 | */
179 | private class BannerPagerAdapter extends PagerAdapter {
180 |
181 | @Override
182 | public int getCount() {
183 | return imageViews.size();
184 | }
185 |
186 | @Override
187 | public Object instantiateItem(View arg0, int arg1) {
188 | ((ViewPager) arg0).addView(imageViews.get(arg1));
189 | return imageViews.get(arg1);
190 | }
191 |
192 | @Override
193 | public void destroyItem(View arg0, int arg1, Object arg2) {
194 | ((ViewPager) arg0).removeView((View) arg2);
195 | }
196 |
197 | @Override
198 | public boolean isViewFromObject(View arg0, Object arg1) {
199 | return arg0 == arg1;
200 | }
201 |
202 | @Override
203 | public void restoreState(Parcelable arg0, ClassLoader arg1) {
204 |
205 | }
206 |
207 | }
208 |
209 | /**
210 | * 当ViewPager中页面的状态发生改变时调用
211 | *
212 | * @author Administrator
213 | */
214 | private class MyPageChangeListener implements OnPageChangeListener {
215 | private int oldPosition = 0;
216 |
217 | /**
218 | * This method will be invoked when a new page becomes selected.
219 | * position: Position index of the new selected page.
220 | */
221 | public void onPageSelected(int position) {
222 |
223 | currentItem = position;
224 | banner_title_tv.setText(titles[position]);
225 |
226 | dots.get(oldPosition).setBackgroundResource(R.drawable.dot_normal);
227 | dots.get(position).setBackgroundResource(R.drawable.dot_focused);
228 | oldPosition = position;
229 | }
230 |
231 | public void onPageScrollStateChanged(int arg0) {
232 |
233 | }
234 |
235 | public void onPageScrolled(int arg0, float arg1, int arg2) {
236 |
237 | }
238 | }
239 |
240 | /**
241 | * 初始化焦点图的控件
242 | */
243 | private void initFocusView(int num) {
244 | titles = new String[num];
245 | if (num > 1) {
246 | // 设置一个监听器,当ViewPager中的页面改变时调用
247 | viewPager.setOnPageChangeListener(new MyPageChangeListener());
248 | }
249 | imageViews.clear();
250 | dots.clear();
251 | dotsLL.removeAllViews();
252 | for (int i = 0; i < num; i++) {
253 | // 初始化小圆点控件
254 | View view = new View(mContext);
255 | dotsLL.addView(view);
256 |
257 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(15, 15);
258 | lp.setMargins(10, 0, 10, 0);
259 | if (i == 0) {
260 | view.setBackgroundResource(R.drawable.dot_focused);
261 | } else {
262 | view.setBackgroundResource(R.drawable.dot_normal);
263 | }
264 | view.setLayoutParams(lp);
265 | dots.add(view);
266 |
267 | // 初始化图片资源
268 | ImageView imageView = new ImageView(mContext);
269 | imageView.setScaleType(ScaleType.CENTER_CROP);
270 | imageView.setImageResource(imgs[i]);
271 | // ImageLoad.loadImg(mContext,mList.get(i).getPath() , R.color.c_eeede9, imageView);
272 | // Glide.with(this).load(mList.get(i).getPath()).placeholder(R.color.c_eeede9).error(R.color.c_eeede9).diskCacheStrategy(DiskCacheStrategy.ALL).crossFade().into(imageView);
273 | imageViews.add(imageView);
274 |
275 | }
276 |
277 | // 设置焦点图点击事件
278 | if (null != imageViews && imageViews.size() > 0) {
279 | for (int i = 0; i < imageViews.size(); i++) {
280 | final int pos = i;
281 | imageViews.get(i).setOnClickListener(
282 | new OnClickListener() {
283 | @Override
284 | public void onClick(View v) {
285 | Toast.makeText(mContext, pos + "", Toast.LENGTH_SHORT).show();
286 | }
287 | });
288 | }
289 | }
290 | }
291 |
292 | /**
293 | * banner图片点击事件
294 | */
295 |
296 | @Override
297 | public void onDestroyView() {
298 | super.onDestroyView();
299 | }
300 |
301 | @Override
302 | public void onDestroy() {
303 | super.onDestroy();
304 | }
305 | }
306 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master;
2 |
3 | import android.app.ProgressDialog;
4 | import android.graphics.Color;
5 | import android.graphics.drawable.GradientDrawable;
6 | import android.os.Build;
7 | import android.os.Bundle;
8 | import android.support.v4.app.FragmentActivity;
9 | import android.view.View;
10 | import android.view.ViewTreeObserver;
11 | import android.widget.LinearLayout;
12 | import android.widget.TextView;
13 |
14 | import com.lvfq.homepage_master.adapter.ListViewBaseAdapter;
15 | import com.lvfq.homepage_master.impl.IAreaCallBack;
16 | import com.lvfq.homepage_master.impl.IFilterCallBack;
17 | import com.lvfq.homepage_master.impl.OnScrollChangedListener;
18 | import com.lvfq.homepage_master.util.DPUtil;
19 | import com.lvfq.homepage_master.util.V;
20 | import com.lvfq.homepage_master.view.CusScrollView;
21 | import com.lvfq.homepage_master.view.FilterView;
22 | import com.lvfq.homepage_master.view.MaxListView;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | import static com.lvfq.homepage_master.util.DPUtil.dip2px;
28 |
29 | public class MainActivity extends FragmentActivity {
30 |
31 |
32 | private FilterView filterView;
33 | private CusScrollView cus_scroll_view;
34 | private MaxListView main_max_listview;
35 | private LinearLayout ll_list_parent;
36 | private LinearLayout ll_toolbar;
37 |
38 | private ListViewBaseAdapter mAdapter;
39 |
40 | private String strArea = "初始值"; // 选择区域
41 | private String strPosition = "初始值"; // 选择职位
42 | private String strExp = "初始值"; // 选择经验
43 | private int initY;
44 |
45 | private int toolBarHeight = 44; // toolbar 高度
46 | private int filterHeight = 40; // 筛选条件布局高度
47 |
48 | private List testList = new ArrayList<>();
49 |
50 | private BannerViewPagerFragment bannerFragment; // 首页轮播图
51 |
52 | private ProgressDialog mProgressDialog;
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(R.layout.activity_main);
58 | mProgressDialog = new ProgressDialog(this);
59 | mProgressDialog.setMessage("加载中...");
60 | mProgressDialog.setCancelable(false);
61 |
62 | initView();
63 | initBanner();
64 | initData();
65 | initAdapter();
66 |
67 | }
68 |
69 | private void initView() {
70 | filterView = V.find(this, R.id.main_filter);
71 | cus_scroll_view = V.find(this, R.id.cus_scroll_view);
72 | main_max_listview = V.find(this, R.id.main_max_listview);
73 | ll_list_parent = V.find(this, R.id.ll_list_parent);
74 | ll_toolbar = V.find(this, R.id.ll_toolbar);
75 |
76 | }
77 |
78 | /**
79 | * 初始化 banner 图
80 | */
81 | private void initBanner() {
82 | bannerFragment = new BannerViewPagerFragment();
83 | android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
84 | ft.replace(R.id.fl_main_container, bannerFragment).commit();
85 | }
86 |
87 | private void initData() {
88 |
89 | addModel(0, 5);
90 |
91 | setToolBarDefBg();
92 |
93 | filterView.setAreaCallBack(new IAreaCallBack() {
94 | @Override
95 | public void callBack(String city, String area) {
96 | strArea = city + " - " + area;
97 | showProgress();
98 | new Thread(new Runnable() {
99 | @Override
100 | public void run() {
101 | try {
102 | Thread.sleep(1000);
103 | runOnUiThread(new Runnable() {
104 | @Override
105 | public void run() {
106 | dismissProgress();
107 | resetRefreshLocal();
108 | mAdapter.notifyDataSetChanged();
109 | }
110 | });
111 | } catch (InterruptedException e) {
112 | e.printStackTrace();
113 | }
114 |
115 | }
116 | }).start();
117 |
118 | }
119 | });
120 |
121 | filterView.setFilterCallBack(new IFilterCallBack() {
122 | @Override
123 | public void callBack(int index, String string) {
124 | switch (index) {
125 | case 1:
126 | strPosition = string;
127 | break;
128 | case 2:
129 | strExp = string;
130 | break;
131 | }
132 | // 模拟数据加载
133 | showProgress();
134 | new Thread(new Runnable() {
135 | @Override
136 | public void run() {
137 | try {
138 | Thread.sleep(1000);
139 | runOnUiThread(new Runnable() {
140 | @Override
141 | public void run() {
142 | // 模拟成功回调
143 | dismissProgress();
144 | resetRefreshLocal();
145 | mAdapter.notifyDataSetChanged();
146 | }
147 | });
148 | } catch (InterruptedException e) {
149 | e.printStackTrace();
150 | }
151 | }
152 | }).start();
153 | }
154 | });
155 |
156 | /**
157 | * 设置ListView 的 父布局的最小高度
158 | */
159 | ll_list_parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
160 | @Override
161 | public void onGlobalLayout() {
162 | int screenHeight = getResources().getDisplayMetrics().heightPixels;
163 |
164 | int statusHeight = DPUtil.getStatusBarHeight(MainActivity.this); // 状态栏高度,像素
165 | initY = (int) ll_list_parent.getY();
166 |
167 | int minHeight = screenHeight - dip2px(MainActivity.this, toolBarHeight + filterHeight) - statusHeight;
168 | ll_list_parent.setMinimumHeight(minHeight);
169 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
170 | ll_list_parent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
171 | } else {
172 | ll_list_parent.getViewTreeObserver().removeGlobalOnLayoutListener(this);
173 | }
174 | }
175 | });
176 |
177 | cus_scroll_view.setOnScrollChangedListener(new OnScrollChangedListener() {
178 | @Override
179 | public void onScrollChanged(CusScrollView scrollView, int x, int y, int oldx, int oldy) {
180 | int bannerHeight = DPUtil.dip2px(MainActivity.this, 180 - toolBarHeight); // 180 是 布局里面写死的 banner 高度。
181 | if (y > bannerHeight) {
182 | ll_toolbar.setBackgroundColor(Color.argb((int) 255, 255, 122, 122)); // 给定的一个颜色值
183 | } else {
184 | if (y <= 0) {
185 | //设置 标题栏默认样式
186 | setToolBarDefBg();
187 | } else {
188 | int alpha = (int) (255 * ((float) y / bannerHeight));
189 | ll_toolbar.setBackgroundColor(Color.argb(alpha, 255, 122, 122));
190 | }
191 | }
192 |
193 | // 控制筛选条件是否显示。
194 | int optionHeight = DPUtil.dip2px(MainActivity.this, 80); // 80 是界面中 模拟占位区域的高度。
195 | if (y >= bannerHeight + optionHeight - filterHeight - toolBarHeight) {
196 | filterView.setVisibility(View.VISIBLE);
197 | } else {
198 | filterView.setVisibility(View.GONE);
199 | }
200 |
201 | }
202 | });
203 |
204 | }
205 |
206 | /**
207 | * 定位列表到第一条
208 | */
209 | private void resetRefreshLocal() {
210 | int offset = dip2px(this, filterHeight + toolBarHeight); // 84 是 toolbar + 筛选条件的布局高度
211 | cus_scroll_view.scrollTo(0, initY - offset);// 设置 scrollView 滚动到某一个点,
212 | }
213 |
214 | /**
215 | * 设置 标题栏默认样式
216 | */
217 | private void setToolBarDefBg() {
218 | int colors[] = {0x88000000, 0x00000000};
219 | GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);
220 | ll_toolbar.setBackgroundDrawable(g);
221 | }
222 |
223 | private void initAdapter() {
224 | mAdapter = new ListViewBaseAdapter(this, R.layout.item_main_listview, testList) {
225 | @Override
226 | public void convert(int position, String item) {
227 | TextView tv_index = f(R.id.tv_item_index);
228 | TextView tv_position = f(R.id.tv_item_position);
229 | TextView tv_area = f(R.id.tv_item_area);
230 | TextView tv_exp = f(R.id.tv_item_exp);
231 |
232 | tv_index.setText((position + 1) + "");
233 | tv_position.setText(strPosition);
234 | tv_exp.setText(strExp);
235 | tv_area.setText(strArea);
236 | if (position == list.size() - 1 && list.size() < 20) {
237 | itemView.setOnClickListener(new View.OnClickListener() {
238 | @Override
239 | public void onClick(View v) {
240 | showProgress();
241 | new Thread(new Runnable() {
242 | @Override
243 | public void run() {
244 | try {
245 | Thread.sleep(1000);
246 | runOnUiThread(new Runnable() {
247 | @Override
248 | public void run() {
249 | dismissProgress();
250 | addModel(testList.size(), 10);
251 | notifyDataSetChanged();
252 | }
253 | });
254 | } catch (InterruptedException e) {
255 | e.printStackTrace();
256 | }
257 |
258 | }
259 | }).start();
260 |
261 | }
262 | });
263 | } else {
264 | itemView.setOnClickListener(null);
265 | }
266 |
267 | }
268 | };
269 | main_max_listview.setAdapter(mAdapter);
270 | }
271 |
272 | /**
273 | * 创建模拟数据
274 | *
275 | * @param startIndex
276 | * @param length
277 | */
278 | private void addModel(int startIndex, int length) {
279 | for (int i = startIndex; i < startIndex + length; i++) {
280 | testList.add("");
281 | }
282 | }
283 |
284 | private void showProgress() {
285 | if (!mProgressDialog.isShowing()) {
286 | mProgressDialog.show();
287 | }
288 | }
289 |
290 | private void dismissProgress() {
291 | if (mProgressDialog.isShowing()) {
292 | mProgressDialog.dismiss();
293 | }
294 | }
295 |
296 |
297 | }
298 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/RecyclerViewScrollActivity.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master;
2 |
3 | import android.app.ProgressDialog;
4 | import android.graphics.Color;
5 | import android.graphics.drawable.GradientDrawable;
6 | import android.os.Build;
7 | import android.os.Bundle;
8 | import android.support.annotation.Nullable;
9 | import android.support.v4.app.FragmentActivity;
10 | import android.support.v7.widget.LinearLayoutManager;
11 | import android.support.v7.widget.RecyclerView;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.view.ViewTreeObserver;
16 | import android.widget.LinearLayout;
17 | import android.widget.TextView;
18 |
19 | import com.lvfq.homepage_master.impl.IAreaCallBack;
20 | import com.lvfq.homepage_master.impl.IFilterCallBack;
21 | import com.lvfq.homepage_master.impl.OnScrollChangedListener;
22 | import com.lvfq.homepage_master.util.DPUtil;
23 | import com.lvfq.homepage_master.util.V;
24 | import com.lvfq.homepage_master.view.CusScrollView;
25 | import com.lvfq.homepage_master.view.FilterView;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | import static com.lvfq.homepage_master.util.DPUtil.dip2px;
31 |
32 | /**
33 | * RecyclerViewScrollActivity
34 | *
35 | * @author lvfq
36 | * @date 2017/4/12 下午1:50
37 | * @mainFunction :
38 | */
39 |
40 | public class RecyclerViewScrollActivity extends FragmentActivity {
41 |
42 | private FilterView filterView;
43 | private CusScrollView cus_scroll_view;
44 | private RecyclerView recyclerView;
45 | private LinearLayout ll_list_parent;
46 | private LinearLayout ll_toolbar;
47 |
48 | private RecyclerViewBaseAdapter mAdapter;
49 |
50 | private String strArea = "初始值"; // 选择区域
51 | private String strPosition = "初始值"; // 选择职位
52 | private String strExp = "初始值"; // 选择经验
53 | private int initY;
54 |
55 | private int toolBarHeight = 44; // toolbar 高度
56 | private int filterHeight = 40; // 筛选条件布局高度
57 |
58 | private List testList = new ArrayList<>();
59 |
60 | private BannerViewPagerFragment bannerFragment; // 首页轮播图
61 |
62 | private ProgressDialog mProgressDialog;
63 |
64 | @Override
65 | protected void onCreate(@Nullable Bundle savedInstanceState) {
66 | super.onCreate(savedInstanceState);
67 | setContentView(R.layout.activity_recyclerview_scroll);
68 |
69 | mProgressDialog = new ProgressDialog(this);
70 | mProgressDialog.setMessage("加载中...");
71 | mProgressDialog.setCancelable(false);
72 |
73 | initView();
74 | initBanner();
75 | initData();
76 | initAdapter();
77 | }
78 |
79 | private void initView() {
80 | filterView = V.find(this, R.id.main_filter);
81 | cus_scroll_view = V.find(this, R.id.cus_scroll_view);
82 | recyclerView = V.find(this, R.id.recyclerview);
83 | ll_list_parent = V.find(this, R.id.ll_list_parent);
84 | ll_toolbar = V.find(this, R.id.ll_toolbar);
85 |
86 | }
87 |
88 | /**
89 | * 初始化 banner 图
90 | */
91 | private void initBanner() {
92 | bannerFragment = new BannerViewPagerFragment();
93 | android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
94 | ft.replace(R.id.fl_main_container, bannerFragment).commit();
95 | }
96 |
97 | private void initData() {
98 |
99 | addModel(0, 5);
100 |
101 | setToolBarDefBg();
102 |
103 | filterView.setAreaCallBack(new IAreaCallBack() {
104 | @Override
105 | public void callBack(String city, String area) {
106 | strArea = city + " - " + area;
107 | showProgress();
108 | new Thread(new Runnable() {
109 | @Override
110 | public void run() {
111 | try {
112 | Thread.sleep(1000);
113 | runOnUiThread(new Runnable() {
114 | @Override
115 | public void run() {
116 | dismissProgress();
117 | resetRefreshLocal();
118 | mAdapter.notifyDataSetChanged();
119 | }
120 | });
121 | } catch (InterruptedException e) {
122 | e.printStackTrace();
123 | }
124 |
125 | }
126 | }).start();
127 |
128 | }
129 | });
130 |
131 | filterView.setFilterCallBack(new IFilterCallBack() {
132 | @Override
133 | public void callBack(int index, String string) {
134 | switch (index) {
135 | case 1:
136 | strPosition = string;
137 | break;
138 | case 2:
139 | strExp = string;
140 | break;
141 | }
142 | // 模拟数据加载
143 | showProgress();
144 | new Thread(new Runnable() {
145 | @Override
146 | public void run() {
147 | try {
148 | Thread.sleep(1000);
149 | runOnUiThread(new Runnable() {
150 | @Override
151 | public void run() {
152 | // 模拟成功回调
153 | dismissProgress();
154 | resetRefreshLocal();
155 | mAdapter.notifyDataSetChanged();
156 | }
157 | });
158 | } catch (InterruptedException e) {
159 | e.printStackTrace();
160 | }
161 | }
162 | }).start();
163 | }
164 | });
165 |
166 | /**
167 | * 设置ListView 的 父布局的最小高度
168 | */
169 | ll_list_parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
170 | @Override
171 | public void onGlobalLayout() {
172 | int screenHeight = getResources().getDisplayMetrics().heightPixels;
173 |
174 | int statusHeight = DPUtil.getStatusBarHeight(RecyclerViewScrollActivity.this); // 状态栏高度,像素
175 | initY = (int) ll_list_parent.getY();
176 |
177 | int minHeight = screenHeight - dip2px(RecyclerViewScrollActivity.this, toolBarHeight + filterHeight) - statusHeight;
178 | ll_list_parent.setMinimumHeight(minHeight);
179 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
180 | ll_list_parent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
181 | } else {
182 | ll_list_parent.getViewTreeObserver().removeGlobalOnLayoutListener(this);
183 | }
184 | }
185 | });
186 |
187 | cus_scroll_view.setOnScrollChangedListener(new OnScrollChangedListener() {
188 | @Override
189 | public void onScrollChanged(CusScrollView scrollView, int x, int y, int oldx, int oldy) {
190 | int bannerHeight = dip2px(RecyclerViewScrollActivity.this, 180 - toolBarHeight); // 180 是 布局里面写死的 banner 高度。
191 | if (y > bannerHeight) {
192 | ll_toolbar.setBackgroundColor(Color.argb((int) 255, 255, 122, 122)); // 给定的一个颜色值
193 | } else {
194 | if (y <= 0) {
195 | //设置 标题栏默认样式
196 | setToolBarDefBg();
197 | } else {
198 | int alpha = (int) (255 * ((float) y / bannerHeight));
199 | ll_toolbar.setBackgroundColor(Color.argb(alpha, 255, 122, 122));
200 | }
201 | }
202 |
203 | // 控制筛选条件是否显示。
204 | int optionHeight = dip2px(RecyclerViewScrollActivity.this, 80); // 80 是界面中 模拟占位区域的高度。
205 | if (y >= bannerHeight + optionHeight - filterHeight - toolBarHeight) {
206 | filterView.setVisibility(View.VISIBLE);
207 | } else {
208 | filterView.setVisibility(View.GONE);
209 | }
210 |
211 | }
212 | });
213 |
214 | }
215 |
216 | /**
217 | * 定位列表到第一条
218 | */
219 | private void resetRefreshLocal() {
220 | int offset = DPUtil.dip2px(this, filterHeight + toolBarHeight); // 84 是 toolbar + 筛选条件的布局高度
221 | cus_scroll_view.scrollTo(0, initY - offset);// 设置 scrollView 滚动到某一个点,
222 | }
223 |
224 | /**
225 | * 设置 标题栏默认样式
226 | */
227 | private void setToolBarDefBg() {
228 | int colors[] = {0x88000000, 0x00000000};
229 | GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);
230 | ll_toolbar.setBackgroundDrawable(g);
231 | }
232 |
233 | private void initAdapter() {
234 |
235 | mAdapter = new RecyclerViewBaseAdapter(testList);
236 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
237 | recyclerView.setAdapter(mAdapter);
238 | }
239 |
240 | /**
241 | * 创建模拟数据
242 | *
243 | * @param startIndex
244 | * @param length
245 | */
246 | private void addModel(int startIndex, int length) {
247 | for (int i = startIndex; i < startIndex + length; i++) {
248 | testList.add("");
249 | }
250 | }
251 |
252 | private void showProgress() {
253 | if (!mProgressDialog.isShowing()) {
254 | mProgressDialog.show();
255 | }
256 | }
257 |
258 | private void dismissProgress() {
259 | if (mProgressDialog.isShowing()) {
260 | mProgressDialog.dismiss();
261 | }
262 | }
263 |
264 | public class RecyclerViewBaseAdapter extends RecyclerView.Adapter {
265 |
266 | private List list;
267 |
268 | public RecyclerViewBaseAdapter(List list) {
269 | this.list = list;
270 | }
271 |
272 | @Override
273 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
274 | return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_listview, parent, false));
275 | }
276 |
277 | @Override
278 | public void onBindViewHolder(ViewHolder holder, int position) {
279 | holder.tv_index.setText((position + 1) + "");
280 | holder.tv_position.setText(strPosition);
281 | holder.tv_exp.setText(strExp);
282 | holder.tv_area.setText(strArea);
283 | if (position == list.size() - 1 && list.size() < 20) {
284 | holder.itemView.setOnClickListener(new View.OnClickListener() {
285 | @Override
286 | public void onClick(View v) {
287 | showProgress();
288 | new Thread(new Runnable() {
289 | @Override
290 | public void run() {
291 | try {
292 | Thread.sleep(1000);
293 | runOnUiThread(new Runnable() {
294 | @Override
295 | public void run() {
296 | dismissProgress();
297 | addModel(testList.size(), 10);
298 | notifyDataSetChanged();
299 | }
300 | });
301 | } catch (InterruptedException e) {
302 | e.printStackTrace();
303 | }
304 |
305 | }
306 | }).start();
307 |
308 | }
309 | });
310 | } else {
311 | holder.itemView.setOnClickListener(null);
312 | }
313 |
314 | }
315 |
316 | @Override
317 | public int getItemCount() {
318 | return list.size();
319 | }
320 |
321 | public class ViewHolder extends RecyclerView.ViewHolder {
322 |
323 | private TextView tv_index;
324 | private TextView tv_position;
325 | private TextView tv_area;
326 | private TextView tv_exp;
327 |
328 | public ViewHolder(View itemView) {
329 | super(itemView);
330 | tv_index = V.find(itemView, R.id.tv_item_index);
331 | tv_position = V.find(itemView, R.id.tv_item_position);
332 | tv_area = V.find(itemView, R.id.tv_item_area);
333 | tv_exp = V.find(itemView, R.id.tv_item_exp);
334 | }
335 | }
336 | }
337 |
338 |
339 | }
340 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/StartActivity.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.view.View;
8 |
9 | /**
10 | * StartActivity
11 | *
12 | * @author lvfq
13 | * @date 2017/4/12 下午2:49
14 | * @mainFunction :
15 | */
16 |
17 | public class StartActivity extends FragmentActivity {
18 |
19 |
20 | @Override
21 | protected void onCreate(@Nullable Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_start);
24 |
25 | }
26 |
27 | public void onClickListView(View view) {
28 | Intent intent = new Intent(this, MainActivity.class);
29 | startActivity(intent);
30 | }
31 |
32 | public void onClickRecyclerView(View view) {
33 | Intent intent = new Intent(this, RecyclerViewScrollActivity.class);
34 | startActivity(intent);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/adapter/ListViewBaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 |
9 | import com.lvfq.homepage_master.util.ViewHolder;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * ListViewBaseAdapter
15 | *
16 | * @author lvfq
17 | * @date 2017/3/20 上午9:46
18 | * @mainFunction :
19 | */
20 |
21 | public abstract class ListViewBaseAdapter extends BaseAdapter {
22 | protected List list;
23 | protected Context context;
24 | private int layoutId;
25 | protected View itemView;
26 |
27 | public ListViewBaseAdapter(Context context, int layoutId, List list) {
28 | this.context = context;
29 | this.layoutId = layoutId;
30 | this.list = list;
31 | }
32 |
33 | @Override
34 | public int getCount() {
35 | return list != null ? list.size() : 0;
36 | }
37 |
38 | @Override
39 | public T getItem(int position) {
40 | return list != null && list.size() > 0 ? list.get(position) : null;
41 | }
42 |
43 | @Override
44 | public long getItemId(int position) {
45 | return position;
46 | }
47 |
48 | @Override
49 | public View getView(int position, View convertView, ViewGroup parent) {
50 | if (convertView == null) {
51 | convertView = LayoutInflater.from(context).inflate(layoutId, parent, false);
52 | }
53 | itemView = convertView;
54 | convert(position, getItem(position));
55 | return convertView;
56 | }
57 |
58 | public abstract void convert(int position, T item);
59 |
60 | protected E f(int id) {
61 | return ViewHolder.get(itemView, id);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/impl/IAreaCallBack.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.impl;
2 |
3 | /**
4 | * IAreaCallBack
5 | *
6 | * @author lvfq
7 | * @date 2017/3/31 下午5:18
8 | * @mainFunction :
9 | */
10 |
11 | public interface IAreaCallBack {
12 | void callBack(String city, String area);
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/impl/IFilterCallBack.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.impl;
2 |
3 | /**
4 | * IFilterCallBack
5 | *
6 | * @author lvfq
7 | * @date 2017/3/31 下午5:29
8 | * @mainFunction : 筛选条件回调
9 | */
10 |
11 | public interface IFilterCallBack {
12 | void callBack(int index, String string);
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/impl/OnScrollChangedListener.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.impl;
2 |
3 | import com.lvfq.homepage_master.view.CusScrollView;
4 |
5 | /**
6 | * Created by lvfq
7 | * Date 2017/3/5 下午1:30.
8 | */
9 |
10 | public interface OnScrollChangedListener {
11 | void onScrollChanged(CusScrollView scrollView, int x, int y, int oldx, int oldy);
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/util/DPUtil.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.util;
2 |
3 | import android.content.Context;
4 |
5 | public class DPUtil {
6 | /**
7 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
8 | */
9 | public static int dip2px(Context context, float dpValue) {
10 | final float scale = context.getResources().getDisplayMetrics().density;
11 | return (int) (dpValue * scale + 0.5f);
12 | }
13 |
14 | /**
15 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
16 | */
17 | public static int px2dip(Context context, float pxValue) {
18 | final float scale = context.getResources().getDisplayMetrics().density;
19 | return (int) (pxValue / scale + 0.5f);
20 | }
21 |
22 | public static int getStatusBarHeight(Context context) {
23 | int result = 0;
24 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
25 | if (resourceId > 0) {
26 | result = context.getResources().getDimensionPixelSize(resourceId);
27 | }
28 | return result;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/util/V.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.util;
2 |
3 | import android.app.Activity;
4 | import android.view.View;
5 |
6 | /**
7 | * V
8 | *
9 | * @author lvfq
10 | * @date 2017/3/31 下午5:41
11 | * @mainFunction :
12 | */
13 |
14 | public class V {
15 | /**
16 | * 简化Activity里面的 findViewById
17 | *
18 | * @param activity
19 | * @param id
20 | * @return
21 | */
22 | public static T find(Activity activity, int id) {
23 | return (T) activity.findViewById(id);
24 | }
25 |
26 | /**
27 | * 简化Fragment中的findViewById
28 | *
29 | * @param view
30 | * @param id
31 | * @return
32 | */
33 | public static T find(View view, int id) {
34 | return (T) view.findViewById(id);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/util/ViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.util;
2 |
3 | import android.util.SparseArray;
4 | import android.view.View;
5 |
6 | /**
7 | * --------------------------------------------
8 | * 作 者 : lfq
9 | * 创建日期 : 2015/10/16 16:42
10 | * 描 述 :
11 | * 简化在主程序中的代码
12 | * 示例:TextView shopName=ViewHolder.get(contentView, R.id.xxx);
13 | * -------------------------------------------
14 | */
15 | public class ViewHolder {
16 | @SuppressWarnings("unchecked")
17 | public static T get(View view, int id) {
18 | SparseArray viewHolder = (SparseArray) view.getTag();
19 | if (viewHolder == null) {
20 | viewHolder = new SparseArray();
21 | view.setTag(viewHolder);
22 | }
23 | View childView = viewHolder.get(id);
24 | if (childView == null) {
25 | childView = view.findViewById(id);
26 | viewHolder.put(id, childView);
27 | }
28 | return (T) childView;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/view/CusScrollView.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.ScrollView;
6 |
7 | import com.lvfq.homepage_master.impl.OnScrollChangedListener;
8 |
9 | /**
10 | * Created by lvfq
11 | * Date 2017/3/5 下午1:28.
12 | */
13 |
14 | public class CusScrollView extends ScrollView {
15 |
16 | private OnScrollChangedListener listener;
17 |
18 | public void setOnScrollChangedListener(OnScrollChangedListener listener){
19 | this.listener = listener;
20 | }
21 |
22 | public CusScrollView(Context context) {
23 | super(context);
24 | }
25 |
26 | public CusScrollView(Context context, AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | public CusScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
31 | super(context, attrs, defStyleAttr);
32 | }
33 |
34 | @Override
35 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
36 | super.onScrollChanged(l, t, oldl, oldt);
37 | if (listener != null) {
38 | listener.onScrollChanged(this ,l , t , oldl , oldt);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/view/FilterView.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.widget.LinearLayout;
8 | import android.widget.ListView;
9 | import android.widget.TextView;
10 |
11 | import com.lvfq.homepage_master.R;
12 | import com.lvfq.homepage_master.adapter.ListViewBaseAdapter;
13 | import com.lvfq.homepage_master.impl.IAreaCallBack;
14 | import com.lvfq.homepage_master.impl.IFilterCallBack;
15 | import com.lvfq.homepage_master.util.V;
16 |
17 | import java.util.ArrayList;
18 | import java.util.Arrays;
19 | import java.util.List;
20 |
21 | import static com.lvfq.homepage_master.R.id.tv_tip1;
22 | import static com.lvfq.homepage_master.R.id.tv_tip2;
23 | import static com.lvfq.homepage_master.R.id.tv_tip3;
24 |
25 | /**
26 | * Created by lvfq
27 | * Date 2017/1/21 上午11:21.
28 | */
29 |
30 | public class FilterView extends LinearLayout implements View.OnClickListener {
31 | private Context context;
32 |
33 | private TextView[] tips = new TextView[3];
34 |
35 | private View fl_content;
36 | private View ll_content;
37 |
38 | private ListView lv_filter_single;
39 | private ListView lv_filter_city;
40 | private ListView lv_filter_area;
41 |
42 | private ListViewBaseAdapter lvSingleAdapter;
43 | private ListViewBaseAdapter lvAdapterCity;
44 | private ListViewBaseAdapter lvAdapterArea;
45 |
46 | private String[] c = new String[]{"北京", "上海", "杭州", "深圳"};
47 |
48 | private String[][] a = new String[][]{
49 | {"东城区", "西城区", "崇文区", "宣武区", "海淀区", "丰台区", "朝阳区"},
50 | {"黄浦区", "徐汇区", "长宁区", "杨浦区", "虹口区", "普陀区", "静安区"},
51 | {"西湖区", "上城区", "下城区", "拱墅区", "江干区", "滨江区", "萧山区", "余杭区", "富阳区"},
52 | {"罗湖区", "福田区", "南山区", "盐田区", "宝安区", "龙岗区", "光明新区"}};
53 |
54 | private List expList = new ArrayList<>(); // 经验列表
55 | private List positionList = new ArrayList<>(); // 岗位列表
56 | private List citys = new ArrayList<>(); // 城市列表
57 | private List> areas = new ArrayList<>(); // 区域列表
58 |
59 | private List singleList = new ArrayList<>(); // 存放当前ListView 所填充数据
60 |
61 | private int curCity = 0;
62 | private int curIndex = -1;
63 |
64 | private IAreaCallBack areaCallBack;
65 | private IFilterCallBack filterCallBack;
66 |
67 |
68 | public FilterView(Context context) {
69 | this(context, null);
70 | }
71 |
72 | public FilterView(Context context, AttributeSet attrs) {
73 | this(context, attrs, 0);
74 | }
75 |
76 | public FilterView(Context context, AttributeSet attrs, int defStyleAttr) {
77 | super(context, attrs, defStyleAttr);
78 | setOrientation(VERTICAL);
79 | this.context = context;
80 | initData();
81 |
82 | init();
83 | }
84 |
85 | private void init() {
86 | View view = LayoutInflater.from(context).inflate(R.layout.layout_filter, null);
87 | addView(view);
88 |
89 | initView(view);
90 |
91 | initAdapter();
92 |
93 | }
94 |
95 | /**
96 | * 实例化组件
97 | *
98 | * @param view
99 | */
100 | private void initView(View view) {
101 | tips[0] = V.find(view, tv_tip1);
102 | tips[1] = V.find(view, tv_tip2);
103 | tips[2] = V.find(view, tv_tip3);
104 |
105 | fl_content = V.find(view, R.id.fl_content);
106 | ll_content = V.find(view, R.id.ll_content);
107 |
108 | lv_filter_single = V.find(view, R.id.lv_filter_single);
109 | lv_filter_city = V.find(view, R.id.lv_filter_city);
110 | lv_filter_area = V.find(view, R.id.lv_filter_area);
111 |
112 | view.findViewById(R.id.fl_tip1).setOnClickListener(this);
113 | view.findViewById(R.id.fl_tip2).setOnClickListener(this);
114 | view.findViewById(R.id.fl_tip3).setOnClickListener(this);
115 | fl_content.setOnClickListener(this);
116 | }
117 |
118 | /**
119 | * 初始化 Adapter
120 | */
121 | private void initAdapter() {
122 | lvSingleAdapter = new ListViewBaseAdapter(context, R.layout.item_filter_single, singleList) {
123 | @Override
124 | public void convert(int position, final String item) {
125 | TextView textView = f(R.id.tv_item_single);
126 | textView.setText(item);
127 | itemView.setOnClickListener(new OnClickListener() {
128 | @Override
129 | public void onClick(View v) {
130 | // TODO: 2017/3/31 列表点击事件
131 | if (filterCallBack != null) {
132 | filterCallBack.callBack(curIndex, item);
133 | }
134 | changeFilterStatus(curIndex);
135 | }
136 | });
137 | }
138 | };
139 |
140 | lvAdapterCity = new ListViewBaseAdapter(context, R.layout.item_filter_list1, citys) {
141 | @Override
142 | public void convert(final int position, String item) {
143 | TextView textView = f(R.id.tv_item_city);
144 | textView.setText(item);
145 | if (curCity == position) {
146 | textView.setBackgroundColor(context.getResources().getColor(android.R.color.darker_gray));
147 | } else {
148 | textView.setBackgroundColor(context.getResources().getColor(android.R.color.white));
149 | }
150 | itemView.setOnClickListener(new OnClickListener() {
151 | @Override
152 | public void onClick(View v) {
153 | singleList.clear();
154 | List list = areas.get(position);
155 | if (list != null && list.size() > 0) {
156 | singleList.addAll(list);
157 | }
158 | curCity = position;
159 | notifyDataSetChanged();
160 | lvAdapterArea.notifyDataSetChanged();
161 | }
162 | });
163 | }
164 | };
165 |
166 | lvAdapterArea = new ListViewBaseAdapter(context, R.layout.item_filter_list2, singleList) {
167 | @Override
168 | public void convert(int position, final String item) {
169 | TextView textView = f(R.id.tv_item_area);
170 | textView.setText(item);
171 | itemView.setOnClickListener(new OnClickListener() {
172 | @Override
173 | public void onClick(View v) {
174 | // 确定回调
175 | if (areaCallBack != null) {
176 | areaCallBack.callBack(citys.get(curCity), item);
177 | }
178 | changeFilterStatus(curIndex);
179 | }
180 | });
181 | }
182 | };
183 |
184 | lv_filter_single.setAdapter(lvSingleAdapter);
185 | lv_filter_city.setAdapter(lvAdapterCity);
186 | lv_filter_area.setAdapter(lvAdapterArea);
187 | }
188 |
189 | @Override
190 | public void onClick(View v) {
191 | switch (v.getId()) {
192 | case R.id.fl_tip1:
193 | singleList.clear();
194 | curCity = 0;
195 | singleList.addAll(areas.get(curCity)); // 这里因为是模拟数据,所以我直接用的是 singleList ,实际项目中可根据数据格式进行调整。
196 | changeFilterStatus(0);
197 | break;
198 | case R.id.fl_tip2:
199 | singleList.clear();
200 | singleList.addAll(positionList);
201 | changeFilterStatus(1);
202 | break;
203 | case R.id.fl_tip3:
204 | singleList.clear();
205 | singleList.addAll(expList);
206 | changeFilterStatus(2);
207 | break;
208 | case R.id.fl_content:
209 | changeFilterStatus(curIndex);
210 | break;
211 | }
212 | }
213 |
214 | /**
215 | * 改变筛选条件状态
216 | *
217 | * @param index
218 | */
219 | private void changeFilterStatus(int index) {
220 | if (curIndex == index) {
221 | fl_content.setVisibility(GONE);
222 | tips[index].setSelected(false);
223 | curIndex = -1;
224 | } else {
225 | if (fl_content.getVisibility() != VISIBLE) {
226 | fl_content.setVisibility(VISIBLE);
227 | }
228 | if (index == 0) {
229 | ll_content.setVisibility(VISIBLE);
230 | lv_filter_single.setVisibility(GONE);
231 |
232 | if (lvAdapterCity != null) {
233 | lvAdapterCity.notifyDataSetChanged();
234 | }
235 | if (lvAdapterArea != null) {
236 | lvAdapterArea.notifyDataSetChanged();
237 | }
238 | } else {
239 | ll_content.setVisibility(GONE);
240 | lv_filter_single.setVisibility(VISIBLE);
241 |
242 | if (lvSingleAdapter != null) {
243 | lvSingleAdapter.notifyDataSetChanged();
244 | }
245 | }
246 | tips[index].setSelected(true);
247 | if (curIndex != -1) {
248 | tips[curIndex].setSelected(false);
249 | }
250 | curIndex = index;
251 | }
252 | }
253 |
254 |
255 | /**
256 | * 初始化模拟数据
257 | */
258 | private void initData() {
259 | initArea();
260 | initPosition();
261 | initExpList();
262 | }
263 |
264 | /**
265 | * 模拟经验要求列表
266 | */
267 | private void initExpList() {
268 | for (int i = 0; i < 5; i++) {
269 | expList.add((i + 1) + "年以上经验");
270 | }
271 | }
272 |
273 | /**
274 | * 模拟区域数据
275 | */
276 | private void initArea() {
277 | citys = Arrays.asList(c);
278 | for (int i = 0; i < a.length; i++) {
279 | areas.add(Arrays.asList(a[i]));
280 | }
281 | }
282 |
283 | /**
284 | * 模拟岗位数据
285 | */
286 | private void initPosition() {
287 | positionList.add("运营总监");
288 | positionList.add("产品经理");
289 | positionList.add("技术主管");
290 | positionList.add("财务助理");
291 | }
292 |
293 | /**
294 | * 设置区域点击回调
295 | *
296 | * @param areaCallBack
297 | */
298 | public void setAreaCallBack(IAreaCallBack areaCallBack) {
299 | this.areaCallBack = areaCallBack;
300 | }
301 |
302 | /**
303 | * 单选项点击回调
304 | *
305 | * @param filterCallBack
306 | */
307 | public void setFilterCallBack(IFilterCallBack filterCallBack) {
308 | this.filterCallBack = filterCallBack;
309 | }
310 |
311 | }
312 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lvfq/homepage_master/view/MaxListView.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.ListView;
6 |
7 | public class MaxListView extends ListView {
8 |
9 | public MaxListView(Context context) {
10 | super(context);
11 | }
12 |
13 | public MaxListView(Context context, AttributeSet attrs) {
14 | super(context, attrs);
15 | }
16 |
17 | public MaxListView(Context context, AttributeSet attrs, int defStyle) {
18 | super(context, attrs, defStyle);
19 | }
20 |
21 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
22 |
23 | int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
24 |
25 | MeasureSpec.AT_MOST);
26 |
27 | super.onMeasure(widthMeasureSpec, expandSpec);
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/color/color_main_text_filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/img_banner_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/drawable-xhdpi/img_banner_1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/img_banner_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/drawable-xhdpi/img_banner_2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/img_banner_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/drawable-xhdpi/img_banner_3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/img_banner_4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/drawable-xhdpi/img_banner_4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/img_banner_def.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/drawable-xhdpi/img_banner_def.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/img_main_tipsel_nor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/drawable-xhdpi/img_main_tipsel_nor.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/img_main_tipsel_sel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/drawable-xhdpi/img_main_tipsel_sel.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dot_focused.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dot_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/draw_main_text_filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
18 |
19 |
23 |
24 |
30 |
31 |
39 |
40 |
49 |
50 |
59 |
60 |
61 |
66 |
67 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
83 |
84 |
90 |
91 |
97 |
98 |
99 |
100 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recyclerview_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
18 |
19 |
23 |
24 |
30 |
31 |
39 |
40 |
49 |
50 |
59 |
60 |
61 |
66 |
67 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
81 |
82 |
88 |
89 |
95 |
96 |
97 |
98 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_bannervp.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
27 |
28 |
34 |
35 |
42 |
43 |
44 |
45 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_filter_list1.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_filter_list2.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_filter_single.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_main_listview.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
19 |
20 |
24 |
25 |
28 |
29 |
37 |
38 |
47 |
48 |
49 |
50 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
34 |
35 |
36 |
37 |
44 |
45 |
58 |
59 |
60 |
61 |
68 |
69 |
82 |
83 |
84 |
85 |
93 |
94 |
107 |
108 |
109 |
110 |
114 |
115 |
120 |
121 |
125 |
126 |
131 |
132 |
138 |
139 |
144 |
145 |
149 |
150 |
154 |
155 |
156 |
157 |
158 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/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 | #fe838e
8 | #666666
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HomePage-Master
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/lvfq/homepage_master/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lvfq.homepage_master;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/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.3.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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvfaqiang/HomePageFilter/f55398202a00f64379bccef86d57b6cb2d193526/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-3.3-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 |
--------------------------------------------------------------------------------