├── .gitignore ├── .idea ├── dictionaries │ └── admin.xml ├── gradle.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ └── app-release.apk └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zkteam │ │ └── discover │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── discover.json │ ├── java │ │ └── com │ │ │ └── zkteam │ │ │ └── discover │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ ├── DiscoverLeve1Adapter.java │ │ │ └── DiscoverLevel2Adapter.java │ │ │ ├── app │ │ │ └── BaseApp.java │ │ │ ├── base │ │ │ ├── ExRvAdapterBase.java │ │ │ ├── ExRvItemViewHolderBase.java │ │ │ └── OnExRvItemViewClickListener.java │ │ │ ├── bean │ │ │ ├── ChildrenOpers.java │ │ │ ├── DiscoverIndexResult.java │ │ │ ├── DiscoverOper.java │ │ │ └── Oper.java │ │ │ ├── decoration │ │ │ ├── DiscoverIndexLevel2Decoration.java │ │ │ └── ExRvDecoration.java │ │ │ ├── fresco │ │ │ ├── FrescoHelper.java │ │ │ ├── FrescoImageView.java │ │ │ ├── FrescoInitUtil.java │ │ │ └── FrescoIniter.java │ │ │ ├── manager │ │ │ ├── LinearSmoothScroller.java │ │ │ └── TopSnappedLayoutManager.java │ │ │ ├── util │ │ │ ├── CollectionUtil.java │ │ │ ├── DensityUtil.java │ │ │ ├── DeviceUtil.java │ │ │ ├── DimenConstant.java │ │ │ ├── DiscoverIndexUtil.java │ │ │ ├── FileUtil.java │ │ │ ├── IOUtil.java │ │ │ ├── StorageUtil.java │ │ │ ├── TextUtil.java │ │ │ └── ViewUtil.java │ │ │ └── vh │ │ │ ├── DiscoverIndexLevel1ViewHolder.java │ │ │ ├── DiscoverIndexLevel2BannerViewHolder.java │ │ │ ├── DiscoverIndexLevel2MiniViewHolder.java │ │ │ ├── DiscoverIndexLevel2TitleViewHolder.java │ │ │ └── ExRvItemViewHolderEmpty.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── page_discover_index_level1_vh.xml │ │ ├── page_discover_index_level2_vh_banner.xml │ │ ├── page_discover_index_level2_vh_mini.xml │ │ └── page_discover_index_level2_vh_title.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── ic_page_main_search_left_selected_status.png │ │ └── ic_shop_detail_right_arrow.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── zkteam │ └── discover │ └── ExampleUnitTest.java ├── build.gradle ├── discover.keystore ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pic ├── AD24390AAB4429800079CBBE5D04AE5D.png ├── BCDA22936B6632ED876589BE749F016D.png └── FCEDFD139973E5AD8BE18BE0314E814E.png └── 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/dictionaries/admin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![省钱快报](https://pp.myapp.com/ma_icon/0/icon_52402621_1548143849/96) 2 | # 省钱快报分类列表 3 | 4 | ### 项目只适合分享,学习,交流 5 | 6 | ## 目录结构 7 | - [开发环境](#1.0.0) 8 | - [更新日志](#2.0.0) 9 | - [应用截图](#3.0.0) 10 | - [下载地址](#4.0.0) 11 | - [项目中使用到的三方库说明](#5.0.0) 12 | - [项目反馈](#6.0.0) 13 | - [Issuse Me](#7.0.0) 14 | 15 |

一.开发环境

16 | 17 | | 开发工具 | 开发语言 |SDK版本 |JDK版本| 18 | |:------ |:---------:| :-----: | :-----: | 19 | | AndroidStudio3.0 | JAVA | 26 | 1.8 | 20 | 21 | 22 | 23 |

二.更新日志

24 | 25 | ### 2018-5-02 26 | 27 | --- 28 | 29 | - 1.添加Fresco图片加载库 30 | 31 | - 2.封装RecyclerView基类 32 | 33 | - 3.添加本地Json数据 34 | 35 | - 4.添加Butterknife,Fastjson 等Jar包 36 | 37 | - 5.完成1.0版本Demo 38 | 39 | --- 40 | 41 |

三.应用截图

42 |
43 | 44 |

45 |

3.1.1图
46 |

47 |
48 |
49 |
50 | 51 |

52 |

3.1.2图
53 |

54 |
55 |
56 | 57 |
58 | 59 |

60 |

3.1.3图
61 |

62 |
63 | 64 |

四.下载地址

65 | 66 | 67 | * 下载地址:[点击这里](https://www.pgyer.com/discover) 68 | 69 | --- 70 | 71 | 72 |

五.三方库说明

73 | 74 | 75 | ``` 76 | 77 | // log 78 | compile 'com.orhanobut:logger:1.15' 79 | // RecyclerView 80 | compile 'com.android.support:recyclerview-v7:26.1.0' 81 | //黄油刀 82 | compile 'com.jakewharton:butterknife:8.5.1' 83 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' 84 | 85 | compile 'com.alibaba:fastjson:1.2.9'//fastjson 86 | compile 'com.facebook.fresco:fresco:1.7.1' 87 | compile 'com.facebook.fresco:animated-gif:1.7.1' 88 | compile 'com.facebook.fresco:webpsupport:1.7.1' 89 | 90 | ``` 91 | --- 92 | 93 |

六.项目反馈

94 | 95 | | 联系人 | QQ | 96 | |:------ |:---------:| 97 | | 大印 | 377413612 | 98 | 99 |

七.Issuse Me

100 | 101 | 102 |  
     喜欢的小伙伴可以在右上角Star一下,在这过程中遇到什么问题与BUG ,欢迎大家[Issuse Me](https://github.com/GaoYin2016/Discover/issues) 103 | 104 |  

Copyright 2018 DaYin

105 | 106 | --- 107 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.jakewharton.butterknife' 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.zkteam.discover" 7 | minSdkVersion 14 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.0' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 28 | 29 | // log 30 | compile 'com.orhanobut:logger:1.15' 31 | // RecyclerView 32 | compile 'com.android.support:recyclerview-v7:26.1.0' 33 | //黄油刀 34 | compile 'com.jakewharton:butterknife:8.5.1' 35 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' 36 | 37 | compile 'com.alibaba:fastjson:1.2.9'//fastjson 38 | compile 'com.facebook.fresco:fresco:1.7.1' 39 | compile 'com.facebook.fresco:animated-gif:1.7.1' 40 | compile 'com.facebook.fresco:webpsupport:1.7.1' 41 | } 42 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/release/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/release/app-release.apk -------------------------------------------------------------------------------- /app/src/androidTest/java/com/zkteam/discover/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover; 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 | * Instrumented 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.zkteam.discover", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.GridLayoutManager; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Toast; 11 | 12 | import com.alibaba.fastjson.JSON; 13 | import com.alibaba.fastjson.JSONException; 14 | import com.zkteam.discover.adapter.DiscoverLeve1Adapter; 15 | import com.zkteam.discover.adapter.DiscoverLevel2Adapter; 16 | import com.zkteam.discover.base.OnExRvItemViewClickListener; 17 | import com.zkteam.discover.bean.DiscoverIndexResult; 18 | import com.zkteam.discover.bean.DiscoverOper; 19 | import com.zkteam.discover.decoration.DiscoverIndexLevel2Decoration; 20 | import com.zkteam.discover.manager.TopSnappedLayoutManager; 21 | import com.zkteam.discover.util.CollectionUtil; 22 | import com.zkteam.discover.util.DimenConstant; 23 | import com.zkteam.discover.util.DiscoverIndexUtil; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.util.List; 28 | 29 | import butterknife.BindView; 30 | import butterknife.ButterKnife; 31 | import butterknife.Unbinder; 32 | 33 | public class MainActivity extends AppCompatActivity { 34 | 35 | @BindView(R.id.ervLevel1) 36 | RecyclerView mErvLevel1; 37 | public DiscoverLeve1Adapter mLevel1Adapter; 38 | public LinearLayoutManager mLevel1LayoutMgr; 39 | 40 | @BindView(R.id.ervLevel2) 41 | RecyclerView mErvLevel2; 42 | public DiscoverLevel2Adapter mLevel2Adapter; 43 | public TopSnappedLayoutManager mLevel2LayoutMgr; 44 | private Unbinder unbinder; 45 | 46 | private float halfHeight = -1.0f; // 屏幕一半高度 47 | private final int DEFAULT_INT = -1024; // 默认位置 48 | private int targetPosition = -1024; // 右侧默认位置 49 | private int mCurrentLeftPos; // 当前左侧位置 50 | 51 | @Override 52 | protected void onCreate(Bundle savedInstanceState) { 53 | super.onCreate(savedInstanceState); 54 | setContentView(R.layout.activity_main); 55 | unbinder = ButterKnife.bind(this); 56 | initData(); 57 | initContentView(); 58 | } 59 | 60 | @Override 61 | protected void onDestroy() { 62 | 63 | super.onDestroy(); 64 | if (unbinder != null) 65 | unbinder.unbind(); 66 | } 67 | 68 | private void initData() { 69 | 70 | } 71 | 72 | private void initContentView() { 73 | 74 | initLevel1Views(); 75 | initLevel2Views(); 76 | initlidateContent(); 77 | } 78 | 79 | /** 80 | * 一级类目 81 | */ 82 | private void initLevel1Views() { 83 | 84 | mLevel1Adapter = new DiscoverLeve1Adapter(); 85 | mLevel1Adapter.setOnExRvItemViewClickListener(new OnExRvItemViewClickListener() { 86 | @Override 87 | public void onExRvItemViewClick(View view, int dataPos) { 88 | 89 | onListItemLeve1ViewClick(dataPos); 90 | } 91 | }); 92 | 93 | mLevel1LayoutMgr = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); 94 | 95 | mErvLevel1.setLayoutManager(mLevel1LayoutMgr); 96 | mErvLevel1.setAdapter(mLevel1Adapter); 97 | ViewGroup.LayoutParams vglp = mErvLevel1.getLayoutParams(); 98 | vglp.width = (int) (DimenConstant.SCREEN_WIDTH * (0.25)); 99 | } 100 | 101 | /** 102 | * 二级类目 103 | */ 104 | private void initLevel2Views() { 105 | 106 | mLevel2Adapter = new DiscoverLevel2Adapter(); 107 | mLevel2Adapter.setOnExRvItemViewClickListener(new OnExRvItemViewClickListener() { 108 | @Override 109 | public void onExRvItemViewClick(View view, int dataPos) { 110 | 111 | onRvItemLevel2ViewClick(dataPos); 112 | } 113 | }); 114 | 115 | mLevel2LayoutMgr = new TopSnappedLayoutManager(this, 3, GridLayoutManager.VERTICAL, false); 116 | 117 | mLevel2LayoutMgr.setRecycleChildrenOnDetach(true); 118 | mLevel2LayoutMgr.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 119 | @Override 120 | public int getSpanSize(int dataPos) { 121 | 122 | int type = mLevel2Adapter.getDataItemViewType(dataPos); 123 | switch (type) { 124 | case DiscoverLevel2Adapter.TYPE_ITEM_BANNER: 125 | case DiscoverLevel2Adapter.TYPE_ITEM_TITLE: 126 | return 3; 127 | default: 128 | case DiscoverLevel2Adapter.TYPE_ITEM_WEBVIEW: 129 | return 1; 130 | } 131 | } 132 | }); 133 | mErvLevel2.setLayoutManager(mLevel2LayoutMgr); 134 | mErvLevel2.setItemViewCacheSize(10); 135 | mErvLevel2.addItemDecoration(new DiscoverIndexLevel2Decoration()); 136 | mErvLevel2.setAdapter(mLevel2Adapter); 137 | mErvLevel2.addOnScrollListener(new RecyclerView.OnScrollListener() { 138 | @Override 139 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 140 | 141 | super.onScrollStateChanged(recyclerView, newState); 142 | if (newState == RecyclerView.SCROLL_STATE_IDLE || newState == RecyclerView.SCROLL_STATE_DRAGGING) 143 | targetPosition = DEFAULT_INT; 144 | } 145 | 146 | @Override 147 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 148 | super.onScrolled(recyclerView, dx, dy); 149 | if (targetPosition == DEFAULT_INT) 150 | setLeftSelection(); 151 | } 152 | }); 153 | 154 | RecyclerView.RecycledViewPool recycledViewPool = mErvLevel2.getRecycledViewPool(); 155 | recycledViewPool.setMaxRecycledViews(mLevel2Adapter.TYPE_ITEM_WEBVIEW, 20); 156 | ViewGroup.LayoutParams vglp = mErvLevel2.getLayoutParams(); 157 | vglp.width = (int) (DimenConstant.SCREEN_WIDTH * (0.75)); 158 | } 159 | 160 | private void initlidateContent() { 161 | 162 | try { 163 | 164 | String jsonData = getAssetsData("discover.json"); 165 | DiscoverIndexResult discoverIndexResult = JSON.parseObject(jsonData, DiscoverIndexResult.class); 166 | 167 | final List opers = discoverIndexResult.getDiscoverList(); 168 | DiscoverIndexUtil.filterNullOperList(opers); 169 | discoverIndexResult.setLocalLevel2List(DiscoverIndexUtil.merageOperLevel2List(opers)); 170 | 171 | if (CollectionUtil.isEmpty(discoverIndexResult.getDiscoverList()) && CollectionUtil.isEmpty(discoverIndexResult.getLocalLevel2List())) 172 | return; 173 | 174 | invalidateLevel1View(discoverIndexResult.getDiscoverList()); 175 | invalidateLevel2View(discoverIndexResult.getLocalLevel2List()); 176 | } catch (JSONException ex) { 177 | ex.printStackTrace(); 178 | } 179 | } 180 | 181 | private void invalidateLevel1View(List discoverList) { 182 | 183 | mLevel1Adapter.setData(discoverList); 184 | mLevel1Adapter.notifyDataSetChanged(); 185 | } 186 | 187 | private void invalidateLevel2View(List localLevel2List) { 188 | 189 | mLevel2Adapter.setData(localLevel2List); 190 | mLevel2Adapter.notifyDataSetChanged(); 191 | } 192 | 193 | private void setLeftSelection() { 194 | 195 | try { 196 | 197 | int leftPos = setLeftPosition(); 198 | if (leftPos == -1) 199 | return; 200 | 201 | if (!mErvLevel2.canScrollVertically(1)) 202 | leftPos = mLevel1Adapter.getDataLastItemPosition(); 203 | 204 | if (mLevel1LayoutMgr.findFirstVisibleItemPosition() > leftPos) 205 | mErvLevel1.smoothScrollToPosition(leftPos); 206 | else if (mLevel1LayoutMgr.findLastVisibleItemPosition() < leftPos) 207 | mErvLevel1.smoothScrollToPosition(leftPos); 208 | 209 | if (mCurrentLeftPos != leftPos) { 210 | 211 | // 居中滚动 212 | scrollListItemLevel1ViewToCenter(leftPos); 213 | mCurrentLeftPos = leftPos; 214 | } 215 | } catch (Throwable e) { 216 | e.printStackTrace(); 217 | } 218 | } 219 | 220 | private int setLeftPosition() { 221 | 222 | int fristPosition = mLevel2LayoutMgr.findFirstVisibleItemPosition(); 223 | int lastPosition = mLevel2LayoutMgr.findLastVisibleItemPosition(); 224 | 225 | if (halfHeight == -1.0f) 226 | halfHeight = ((float) (mErvLevel2.getHeight()) * 0.5f); 227 | 228 | for (int i = fristPosition; i <= lastPosition; i++) { 229 | 230 | Object obj = mLevel2Adapter.getDataItem(i); 231 | if (obj instanceof DiscoverOper) { 232 | 233 | DiscoverOper discoverOper = (DiscoverOper) obj; 234 | if (discoverOper.isTypeTitle()) { 235 | 236 | float currentTop = mErvLevel2.getChildAt(i - fristPosition).getTop(); 237 | 238 | if (currentTop > halfHeight) //小于屏幕一半 切换 Select 239 | return discoverOper.getParentPosition() - 1; 240 | else 241 | return discoverOper.getParentPosition(); 242 | } 243 | } 244 | } 245 | return -1; 246 | } 247 | 248 | private void onListItemLeve1ViewClick(int dataPos) { 249 | 250 | // 选中列表Postition位置元素 并居中 251 | scrollListItemLevel1ViewToCenter(dataPos); 252 | // 根据Position查找列表对应Item锚点定位到顶部 253 | level2ListScrollToPosition(dataPos); 254 | } 255 | 256 | private void onRvItemLevel2ViewClick(int dataPos) { 257 | 258 | Object object = mLevel2Adapter.getDataItem(dataPos); 259 | if (object instanceof DiscoverOper) 260 | Toast.makeText(this, String.format("点击%s", ((DiscoverOper) object).getTitle()), Toast.LENGTH_LONG).show(); 261 | } 262 | 263 | private void scrollListItemLevel1ViewToCenter(int position) { 264 | 265 | try { 266 | 267 | View childAt = mErvLevel1.getChildAt(position - mLevel1LayoutMgr.findFirstVisibleItemPosition()); 268 | if (childAt != null) { 269 | 270 | int y = (childAt.getTop() - mErvLevel1.getHeight() / 2); 271 | mErvLevel1.smoothScrollBy(0, y); 272 | } 273 | } catch (Throwable e) { 274 | e.printStackTrace(); 275 | } finally { 276 | 277 | mLevel1Adapter.setSelectPos(position); 278 | } 279 | } 280 | 281 | private void level2ListScrollToPosition(int dataPos) { 282 | 283 | Object obj = mLevel1Adapter.getDataItem(dataPos); 284 | if (obj instanceof DiscoverOper) { 285 | 286 | DiscoverOper oper = (DiscoverOper) obj; 287 | targetPosition = mLevel2Adapter.getSelectPosition(oper.getElement_id()); 288 | if (targetPosition > -1) 289 | mErvLevel2.smoothScrollToPosition(targetPosition); 290 | } 291 | } 292 | 293 | /** 294 | * 加载资源文件 295 | * 296 | * @param path 297 | * @return 298 | */ 299 | private String getAssetsData(String path) { 300 | String result = ""; 301 | try { 302 | //获取输入流 303 | InputStream mAssets = getAssets().open(path); 304 | //获取文件的字节数 305 | int lenght = mAssets.available(); 306 | //创建byte数组 307 | byte[] buffer = new byte[lenght]; 308 | //将文件中的数据写入到字节数组中 309 | mAssets.read(buffer); 310 | mAssets.close(); 311 | result = new String(buffer); 312 | return result; 313 | } catch (IOException e) { 314 | e.printStackTrace(); 315 | return result; 316 | } 317 | } 318 | } 319 | 320 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/adapter/DiscoverLeve1Adapter.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.adapter; 2 | 3 | import android.view.ViewGroup; 4 | 5 | import com.zkteam.discover.base.ExRvAdapterBase; 6 | import com.zkteam.discover.bean.DiscoverOper; 7 | import com.zkteam.discover.util.CollectionUtil; 8 | import com.zkteam.discover.vh.DiscoverIndexLevel1ViewHolder; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * =========================================================== 14 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 15 | * 邮 箱:18810474975@163.com 16 | * 版 本: 17 | * 创建日期:2018/4/24 上午10:57 18 | * 描 述: 19 | * 修订历史: 20 | * =========================================================== 21 | */ 22 | public class DiscoverLeve1Adapter extends ExRvAdapterBase { 23 | 24 | // 选中 25 | public static final String STATUS_SELECT = "SELECT"; 26 | // 默认 27 | public static final String STATUS_NOMAL = "NOMAL"; 28 | // 当前索引 29 | private int mSelectPosition; 30 | 31 | public void setSelectPos(int position) { 32 | 33 | if (position >= 0 && position < getDataItemCount() && mSelectPosition != position) { 34 | 35 | notifyItemRangeChanged(mSelectPosition, 1, STATUS_NOMAL); 36 | notifyItemRangeChanged(position, 1, STATUS_SELECT); 37 | mSelectPosition = position; 38 | } 39 | } 40 | 41 | @Override 42 | public DiscoverIndexLevel1ViewHolder onCreateDataViewHolder(ViewGroup parent, int viewType) { 43 | 44 | return new DiscoverIndexLevel1ViewHolder(parent); 45 | } 46 | 47 | @Override 48 | public void onBindDataViewHolder(DiscoverIndexLevel1ViewHolder holder, int dataPos) { 49 | 50 | holder.invalidateView(getDataItem(dataPos), dataPos == mSelectPosition); 51 | } 52 | 53 | @Override 54 | public void onBindDataViewHolder(DiscoverIndexLevel1ViewHolder holder, int dataPos, List payLoads) { 55 | 56 | if (CollectionUtil.isEmpty(payLoads)) 57 | return; 58 | 59 | String payload = (String) payLoads.get(0); 60 | if (STATUS_SELECT.equalsIgnoreCase(payload)) 61 | holder.setSelectedStyle(); //选中状态 62 | else if (STATUS_NOMAL.equalsIgnoreCase(payload)) 63 | holder.setNormalStyle(); // 默认状态 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/adapter/DiscoverLevel2Adapter.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.adapter; 2 | 3 | import android.view.ViewGroup; 4 | 5 | import com.zkteam.discover.base.ExRvAdapterBase; 6 | import com.zkteam.discover.base.ExRvItemViewHolderBase; 7 | import com.zkteam.discover.bean.DiscoverOper; 8 | import com.zkteam.discover.bean.Oper; 9 | import com.zkteam.discover.util.CollectionUtil; 10 | import com.zkteam.discover.util.DensityUtil; 11 | import com.zkteam.discover.util.DimenConstant; 12 | import com.zkteam.discover.vh.DiscoverIndexLevel2BannerViewHolder; 13 | import com.zkteam.discover.vh.DiscoverIndexLevel2MiniViewHolder; 14 | import com.zkteam.discover.vh.DiscoverIndexLevel2TitleViewHolder; 15 | import com.zkteam.discover.vh.ExRvItemViewHolderEmpty; 16 | 17 | /** 18 | * =========================================================== 19 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 20 | * 邮 箱:18810474975@163.com 21 | * 版 本: 22 | * 创建日期:2018/4/24 上午10:58 23 | * 描 述: 24 | * 修订历史: 25 | * =========================================================== 26 | */ 27 | public class DiscoverLevel2Adapter extends ExRvAdapterBase { 28 | 29 | 30 | public static final int TYPE_ITEM_TITLE = 0; // Title 运营位 31 | public static final int TYPE_ITEM_WEBVIEW = 1; // webView 运营位 32 | public static final int TYPE_ITEM_BANNER = 2; // Banner 运营位 33 | private static final int TYPE_ITEM_NONE = 3; // NONE 34 | 35 | /** 36 | * 查询指定elementId的运营位元素pos 37 | * 38 | * @param elementId 39 | * @return 未找到返回-1 40 | */ 41 | public int getSelectPosition(int elementId) { 42 | 43 | for (int i = 0; i < CollectionUtil.size(getData()); i++) { 44 | 45 | DiscoverOper discoverOper = (DiscoverOper) CollectionUtil.getItem(getData(), i); 46 | if (discoverOper.getElement_id() == elementId) 47 | return i; 48 | } 49 | return -1; 50 | } 51 | 52 | @Override 53 | public int getDataItemViewType(int dataPos) { 54 | 55 | Object obj = getDataItem(dataPos); 56 | if (obj instanceof DiscoverOper) { 57 | 58 | DiscoverOper oper = (DiscoverOper) obj; 59 | 60 | if (oper.isTypeWebView()) 61 | return TYPE_ITEM_WEBVIEW; 62 | else if (oper.isTypeBanner()) 63 | return TYPE_ITEM_BANNER; 64 | else if (oper.isTypeTitle()) 65 | return TYPE_ITEM_TITLE; 66 | } 67 | 68 | return TYPE_ITEM_NONE; 69 | } 70 | 71 | @Override 72 | public ExRvItemViewHolderBase onCreateDataViewHolder(ViewGroup parent, int viewType) { 73 | 74 | switch (viewType) { 75 | case TYPE_ITEM_TITLE: 76 | return new DiscoverIndexLevel2TitleViewHolder(parent); 77 | case TYPE_ITEM_WEBVIEW: 78 | return new DiscoverIndexLevel2MiniViewHolder(parent); 79 | case TYPE_ITEM_BANNER: 80 | int bannerWidth = (int) (DimenConstant.SCREEN_WIDTH * (0.75f)) - DensityUtil.dip2px(20f); 81 | return new DiscoverIndexLevel2BannerViewHolder(parent, bannerWidth); 82 | default: 83 | case TYPE_ITEM_NONE: 84 | return ExRvItemViewHolderEmpty.newVertInstance(parent); 85 | } 86 | } 87 | 88 | @Override 89 | public void onBindDataViewHolder(ExRvItemViewHolderBase holder, int dataPos) { 90 | 91 | if (holder instanceof DiscoverIndexLevel2TitleViewHolder) 92 | ((DiscoverIndexLevel2TitleViewHolder) holder).invalidateView((DiscoverOper) getDataItem(dataPos)); 93 | else if (holder instanceof DiscoverIndexLevel2MiniViewHolder) 94 | ((DiscoverIndexLevel2MiniViewHolder) holder).invalidateView((Oper) getDataItem(dataPos)); 95 | else if (holder instanceof DiscoverIndexLevel2BannerViewHolder) 96 | ((DiscoverIndexLevel2BannerViewHolder) holder).invalidateView((Oper) getDataItem(dataPos)); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/app/BaseApp.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.app; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.zkteam.discover.fresco.FrescoInitUtil; 7 | 8 | /** 9 | * =========================================================== 10 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 11 | * 邮 箱:18810474975@163.com 12 | * 版 本: 13 | * 创建日期:2018/4/24 上午11:49 14 | * 描 述: 15 | * 修订历史: 16 | * =========================================================== 17 | */ 18 | public class BaseApp extends Application { 19 | 20 | private static Context mContext; 21 | 22 | @Override 23 | public void onCreate() { 24 | 25 | super.onCreate(); 26 | mContext = getApplicationContext(); 27 | initFrescoConfig(); 28 | } 29 | 30 | private void initFrescoConfig() { 31 | 32 | FrescoInitUtil.initFrescoConfig(); 33 | } 34 | 35 | public static Context getContext() { 36 | 37 | return mContext; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/base/ExRvAdapterBase.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.base; 2 | 3 | import android.support.v7.widget.OrientationHelper; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.ViewGroup; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public abstract class ExRvAdapterBase extends RecyclerView.Adapter { 11 | 12 | private List mData; 13 | private int mOrientation = OrientationHelper.VERTICAL; 14 | 15 | private OnExRvItemViewClickListener mClickLisn; 16 | 17 | protected ExRvAdapterBase() { 18 | } 19 | 20 | protected ExRvAdapterBase(List data) { 21 | 22 | setData(data); 23 | } 24 | 25 | 26 | //************************ 覆写的父类函数 ************************** 27 | 28 | 29 | /** 30 | * 返回所有item个数 31 | * 包含 header,footer,data 32 | * 如果没有 header,footer 就只是data的size 33 | * 34 | * @return 35 | */ 36 | @Override 37 | public final int getItemCount() { 38 | 39 | return getDataItemCount(); 40 | } 41 | 42 | /** 43 | * 返回 item 的id 44 | * 默认实现返回 position 45 | * 46 | * @param position 47 | * @return 48 | */ 49 | @Override 50 | public long getItemId(int position) { 51 | 52 | return position; 53 | } 54 | 55 | /** 56 | * 如果是header 返回 ITEM_VIEW_TYPE_HEADER 57 | * 如果是footer 返回 ITEM_VIEW_TYPE_FOOTER 58 | * 如果是data item 返回 0 59 | * 60 | * @param position 61 | * @return 62 | */ 63 | @Override 64 | public final int getItemViewType(int position) { 65 | 66 | return getDataItemViewType(getDataPosByAdapterPos(position)); 67 | } 68 | 69 | @Override 70 | public final ExRvItemViewHolderBase onCreateViewHolder(ViewGroup parent, int viewType) { 71 | 72 | switch (viewType) { 73 | default: 74 | K vh = onCreateDataViewHolder(parent, viewType); 75 | vh.onAdapterSetEventListener(mClickLisn); 76 | vh.onAdapterInitConvertView(); 77 | return vh; 78 | } 79 | } 80 | 81 | /** 82 | * 如果有header position 偏移量要减 1, 才是实际data的position 83 | * 84 | * @param holder 85 | * @param position 86 | */ 87 | @Override 88 | public final void onBindViewHolder(ExRvItemViewHolderBase holder, int position) { 89 | 90 | switch (holder.getItemViewType()) { 91 | default: 92 | int dataPos = getDataPosByAdapterPos(position); 93 | holder.onAdapterSetDataPosition(dataPos); 94 | onBindDataViewHolder((K) holder, dataPos); 95 | break; 96 | } 97 | } 98 | 99 | @Override 100 | public void onBindViewHolder(ExRvItemViewHolderBase holder, int position, List payloads) { 101 | 102 | super.onBindViewHolder(holder, position, payloads); 103 | onBindDataViewHolder((K) holder, getDataPosByAdapterPos(position), payloads); 104 | } 105 | 106 | @Override 107 | public void onViewAttachedToWindow(ExRvItemViewHolderBase holder) { 108 | 109 | if (holder != null) 110 | holder.onAdapterViewAttachedToWindow(); 111 | } 112 | 113 | @Override 114 | public void onViewDetachedFromWindow(ExRvItemViewHolderBase holder) { 115 | 116 | if (holder != null) 117 | holder.onAdapterViewDetachedFromWindow(); 118 | } 119 | 120 | @Override 121 | public void onViewRecycled(ExRvItemViewHolderBase holder) { 122 | 123 | if (holder != null) 124 | holder.onAdapterViewRecycled(); 125 | } 126 | 127 | //***************************** 供子类覆写的函数 **************************** 128 | 129 | 130 | /** 131 | * 获取data item view type 132 | * 133 | * @param dataPos 134 | * @return 135 | */ 136 | public int getDataItemViewType(int dataPos) { 137 | 138 | return 0; 139 | } 140 | 141 | public abstract K onCreateDataViewHolder(ViewGroup parent, int viewType); 142 | 143 | public abstract void onBindDataViewHolder(K holder, int dataPos); 144 | 145 | public void onBindDataViewHolder(K holder, int dataPos, List payLoads) { 146 | //nothing 147 | } 148 | 149 | //*************************** 与data集合操作相关的函数 ************************** 150 | 151 | 152 | public List getData() { 153 | 154 | return mData; 155 | } 156 | 157 | /** 158 | * 返回data的个数 159 | * 160 | * @return 161 | */ 162 | public int getDataItemCount() { 163 | 164 | return mData == null ? 0 : mData.size(); 165 | } 166 | 167 | public T getDataItem(int dataPos) { 168 | 169 | return checkDataPosition(dataPos) ? mData.get(dataPos) : null; 170 | } 171 | 172 | public void setData(List data) { 173 | 174 | clearData(); 175 | addDataAll(data); 176 | } 177 | 178 | public void addData(T item) { 179 | 180 | if (item != null) { 181 | 182 | initDataIfNull(); 183 | mData.add(item); 184 | } 185 | } 186 | 187 | public void addData(int dataPos, T item) { 188 | 189 | if (item != null) { 190 | 191 | initDataIfNull(); 192 | if (checkDataInsertPosition(dataPos)) 193 | mData.add(dataPos, item); 194 | } 195 | } 196 | 197 | public void addDataAll(List data) { 198 | 199 | if (data != null && data.size() > 0) { 200 | 201 | initDataIfNull(); 202 | mData.addAll(data); 203 | } 204 | } 205 | 206 | public void addDataAll(int dataPos, List data) { 207 | 208 | if (data != null && data.size() > 0 && 209 | checkDataInsertPosition(dataPos)) { 210 | 211 | initDataIfNull(); 212 | mData.addAll(dataPos, data); 213 | } 214 | } 215 | 216 | public boolean removeData(T item) { 217 | 218 | if (hasData() && item != null) 219 | return mData.remove(item); 220 | else 221 | return false; 222 | } 223 | 224 | public T removeData(int dataPos) { 225 | 226 | if (hasData() && checkDataPosition(dataPos)) 227 | return mData.remove(dataPos); 228 | else 229 | return null; 230 | } 231 | 232 | /** 233 | * 清空数据 234 | */ 235 | public void clearData() { 236 | 237 | if (mData != null) 238 | mData.clear(); 239 | } 240 | 241 | /** 242 | * 获取最后一item的position 243 | * 244 | * @return 如果集合为空返回-1 245 | */ 246 | public int getDataLastItemPosition() { 247 | 248 | return getDataItemCount() - 1; 249 | } 250 | 251 | /** 252 | * 获取集合中指定type的第一个position 253 | * 254 | * @param type 255 | * @return 256 | */ 257 | public int findDataPosByDataItemViewType(int type) { 258 | 259 | if (isDataEmpty()) 260 | return -1; 261 | 262 | for (int i = 0; i < mData.size(); i++) { 263 | 264 | if (getDataItemViewType(i) == type) 265 | return i; 266 | } 267 | 268 | return -1; 269 | } 270 | 271 | /** 272 | * 获取最后一种itemType的数据对象 273 | * 274 | * @param type 275 | * @return 276 | */ 277 | public T findDataByLastDataItemViewType(int type) { 278 | 279 | if (isDataEmpty()) 280 | return null; 281 | 282 | int size = getDataItemCount(); 283 | for (int i = size - 1; i >= 0; i--) { 284 | 285 | if (getDataItemViewType(i) == type) 286 | return getDataItem(i); 287 | } 288 | 289 | return null; 290 | } 291 | 292 | /** 293 | * 获取最后一个元素的类型 294 | * 295 | * @return 296 | */ 297 | public int findDataLastItemViewType() { 298 | 299 | if (isDataEmpty()) 300 | return -1; 301 | else 302 | return getDataItemViewType(getDataItemCount() - 1); 303 | } 304 | 305 | /** 306 | * 检查pos是否越界 307 | * 308 | * @param position 309 | * @return 310 | */ 311 | public boolean checkDataPosition(int position) { 312 | 313 | return position >= 0 && position < getDataItemCount(); 314 | } 315 | 316 | /** 317 | * 检查插入操作pos是否越界 318 | * 319 | * @param position 320 | * @return 321 | */ 322 | public boolean checkDataInsertPosition(int position) { 323 | 324 | return position >= 0 && position <= getDataItemCount(); 325 | } 326 | 327 | /** 328 | * 判断是否有数据 329 | * 330 | * @return 331 | */ 332 | public boolean hasData() { 333 | 334 | return getDataItemCount() > 0; 335 | } 336 | 337 | /** 338 | * 判断数据是否为空 339 | * 340 | * @return 341 | */ 342 | public boolean isDataEmpty() { 343 | 344 | return getDataItemCount() <= 0; 345 | } 346 | 347 | /** 348 | * 将adapterPosition 转换为 data对应的position 349 | * 因为在有header的情况下,将adapterPosition将不再是data对应的position 350 | * 351 | * @param adapterPosition adapter的position 352 | * @return 353 | */ 354 | public int getDataPosByAdapterPos(int adapterPosition) { 355 | 356 | return adapterPosition; 357 | } 358 | 359 | private void initDataIfNull() { 360 | 361 | if (mData == null) 362 | mData = new ArrayList(); 363 | } 364 | 365 | //***************************** 监听器相关函数 **************************** 366 | 367 | 368 | /** 369 | * 设置点击监听器 370 | * 371 | * @param lisn 372 | */ 373 | public void setOnExRvItemViewClickListener(OnExRvItemViewClickListener lisn) { 374 | 375 | mClickLisn = lisn; 376 | } 377 | 378 | //************************** 其他 **************************** 379 | 380 | 381 | public void setOrientation(int orientation) { 382 | 383 | mOrientation = orientation; 384 | } 385 | 386 | private String simpleTag() { 387 | 388 | return getClass().getSimpleName(); 389 | } 390 | } 391 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/base/ExRvItemViewHolderBase.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.base; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | public abstract class ExRvItemViewHolderBase extends RecyclerView.ViewHolder implements View.OnClickListener { 9 | 10 | private View mConvertView; 11 | private int mDataPosition = -1, mDataOldPosition = -2; 12 | private OnExRvItemViewClickListener mClickLisn; 13 | 14 | 15 | public ExRvItemViewHolderBase(View itemView) { 16 | 17 | super(itemView); 18 | mConvertView = itemView; 19 | } 20 | 21 | protected ExRvItemViewHolderBase(ViewGroup parent, int itemViewResId) { 22 | 23 | this(LayoutInflater.from(parent.getContext()).inflate(itemViewResId, parent, false)); 24 | } 25 | 26 | 27 | /**************************** 供适配器回调函数 ******************************/ 28 | 29 | public final void onAdapterSetEventListener(OnExRvItemViewClickListener clickLisn) { 30 | 31 | mClickLisn = clickLisn; 32 | } 33 | 34 | public final void onAdapterInitConvertView() { 35 | 36 | initConvertView(mConvertView); 37 | } 38 | 39 | public final void onAdapterSetDataPosition(int position) { 40 | 41 | mDataOldPosition = mDataPosition; 42 | mDataPosition = position; 43 | } 44 | 45 | public void onAdapterViewRecycled() { 46 | 47 | //nothing 48 | } 49 | 50 | public void onAdapterViewDetachedFromWindow() { 51 | 52 | //nothing 53 | } 54 | 55 | public void onAdapterViewAttachedToWindow() { 56 | 57 | //nothing 58 | } 59 | 60 | 61 | /**************************** 供子类覆写函数 ******************************/ 62 | 63 | 64 | protected abstract void initConvertView(View convertView); 65 | 66 | 67 | /**************************** 供子类调用函数 ******************************/ 68 | 69 | 70 | public View getConvertView() { 71 | 72 | return mConvertView; 73 | } 74 | 75 | /** 76 | * 返回校正过的pos值,保证了有header时返回的pos是data的pos 77 | * 尽量使用该函数, adapterPosition()尽量弃用 78 | * 79 | * @return 80 | */ 81 | public final int getDataPosition() { 82 | 83 | return mDataPosition; 84 | } 85 | 86 | /** 87 | * 返回校正过的pos值,保证了有header时返回的pos是data的pos 88 | * 尽量使用该函数, adapterPosition()尽量弃用 89 | * 90 | * @return 91 | */ 92 | public final int getOldDataPosition() { 93 | 94 | return mDataOldPosition; 95 | } 96 | 97 | /** 98 | * 默认onclick实现 99 | * 100 | * @param v 101 | */ 102 | @Override 103 | public void onClick(View v) { 104 | 105 | callbackClickListener(v, getDataPosition()); 106 | } 107 | 108 | protected void callbackClickListener(View view, int dataPos) { 109 | 110 | if (mClickLisn != null) 111 | mClickLisn.onExRvItemViewClick(view, dataPos); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/base/OnExRvItemViewClickListener.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.base; 2 | 3 | import android.view.View; 4 | 5 | public interface OnExRvItemViewClickListener { 6 | 7 | void onExRvItemViewClick(View view, int dataPos); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/bean/ChildrenOpers.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.bean; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * =========================================================== 8 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 9 | * 邮 箱:18810474975@163.com 10 | * 版 本: 11 | * 创建日期:2018/3/1 上午10:00 12 | * 描 述: 13 | * 修订历史: 14 | * =========================================================== 15 | */ 16 | public class ChildrenOpers implements Serializable { 17 | 18 | private List banner; //Banner 19 | 20 | private List webview; // WebView 21 | 22 | public List getBanner() { 23 | 24 | return banner; 25 | } 26 | 27 | public void setBanner(List banner) { 28 | 29 | this.banner = banner; 30 | } 31 | 32 | public List getWebview() { 33 | 34 | return webview; 35 | } 36 | 37 | public void setWebview(List webview) { 38 | 39 | this.webview = webview; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "ChildrenOpers{" + 45 | "banner=" + banner + 46 | ", webview=" + webview + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/bean/DiscoverIndexResult.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.bean; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * =========================================================== 9 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 10 | * 邮 箱:18810474975@163.com 11 | * 版 本: 12 | * 创建日期:2018/2/28 下午5:40 13 | * 描 述:找券 实体类 14 | * 修订历史: 15 | * =========================================================== 16 | */ 17 | public class DiscoverIndexResult { 18 | 19 | private List discoverList; 20 | private List localLevel2List; 21 | 22 | public List getLocalLevel2List() { 23 | 24 | return localLevel2List; 25 | } 26 | 27 | public void setLocalLevel2List(List localLevel2List) { 28 | 29 | this.localLevel2List = localLevel2List; 30 | } 31 | 32 | public List getDiscoverList() { 33 | 34 | return discoverList; 35 | } 36 | 37 | @JSONField(name = "zhekou_discover_left_nav") 38 | public void setDiscoverList(List discoverList) { 39 | 40 | this.discoverList = discoverList; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "DiscoverIndexResult{" + 46 | "discoverList=" + discoverList + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/bean/DiscoverOper.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.bean; 2 | 3 | import com.zkteam.discover.util.IOUtil; 4 | 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.ObjectInputStream; 8 | import java.io.ObjectOutputStream; 9 | import java.io.Serializable; 10 | 11 | /** 12 | * =========================================================== 13 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 14 | * 邮 箱:18810474975@163.com 15 | * 版 本: 16 | * 创建日期:2018/3/6 下午8:16 17 | * 描 述: 18 | * 修订历史: 19 | * =========================================================== 20 | */ 21 | public class DiscoverOper extends Oper implements Serializable { 22 | 23 | public static final String TYPE_TITLE = "title"; //本地标记 24 | 25 | private int parentId; 26 | private int parentChannelId; 27 | private String parentTitle; 28 | private int childPosition; 29 | private int parentPosition; 30 | 31 | public int getChildPosition() { 32 | 33 | return childPosition; 34 | } 35 | 36 | public void setChildPosition(int childPosition) { 37 | 38 | this.childPosition = childPosition; 39 | } 40 | 41 | public int getParentPosition() { 42 | 43 | return parentPosition; 44 | } 45 | 46 | public void setParentPosition(int parentPosition) { 47 | 48 | this.parentPosition = parentPosition; 49 | } 50 | 51 | public int getParentId() { 52 | 53 | return parentId; 54 | } 55 | 56 | public void setParentId(int parentId) { 57 | 58 | this.parentId = parentId; 59 | } 60 | 61 | public int getParentChannelId() { 62 | 63 | return parentChannelId; 64 | } 65 | 66 | public void setParentChannelId(int channelId) { 67 | 68 | this.parentChannelId = channelId; 69 | } 70 | 71 | public String getParentTitle() { 72 | 73 | return parentTitle; 74 | } 75 | 76 | public void setParentTitle(String parentTitle) { 77 | 78 | this.parentTitle = parentTitle; 79 | } 80 | 81 | public boolean isTypeTitle() { 82 | 83 | return TYPE_TITLE.equals(getElement_type()); 84 | } 85 | 86 | 87 | public DiscoverOper clone() { 88 | 89 | DiscoverOper outer = null; 90 | ByteArrayOutputStream baos = null; 91 | ObjectOutputStream oos = null; 92 | ObjectInputStream ois = null; 93 | ByteArrayInputStream bais = null; 94 | try { 95 | // 将该对象序列化成流,因为写在流里的是对象的一个拷贝,而原对象仍然存在于JVM里面。所以利用这个特性可以实现对象的深拷贝 96 | baos = new ByteArrayOutputStream(); 97 | oos = new ObjectOutputStream(baos); 98 | oos.writeObject(this); 99 | bais = new ByteArrayInputStream(baos.toByteArray()); 100 | ois = new ObjectInputStream(bais); 101 | outer = (DiscoverOper) ois.readObject(); 102 | } catch (Exception e) { 103 | 104 | return this; 105 | } finally { 106 | 107 | IOUtil.closeOutStream(baos); 108 | IOUtil.closeOutStream(oos); 109 | IOUtil.closeInStream(ois); 110 | IOUtil.closeInStream(bais); 111 | } 112 | return outer; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/bean/Oper.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.bean; 2 | 3 | import com.zkteam.discover.util.TextUtil; 4 | 5 | /** 6 | * =========================================================== 7 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 8 | * 邮 箱:18810474975@163.com 9 | * 版 本: 10 | * 创建日期:2018/4/24 上午11:16 11 | * 描 述: 12 | * 修订历史: 13 | * =========================================================== 14 | */ 15 | public class Oper { 16 | 17 | public static final String TYPE_WEBVIEW = "webview"; 18 | 19 | public static final String TYPE_COUPON_IDS = "coupon_ids"; 20 | public static final String TYPE_COUPON_SINGLE = "single_coupon";//2.5.6新增 21 | 22 | public static final String TYPE_TOPIC_IDS = "topic_ids"; 23 | public static final String TYPE_TOPIC_SINGLE = "single_topic";//2.5.6新增 24 | public static final String TYPE_TOPIC_3PIC = "single_topic_3";//2.5.8新增 新用户专场 25 | public static final String TYPE_BANNER = "banner"; // 2.6.2 新增 Banner类型 26 | 27 | private int element_id; 28 | private String element_type = TextUtil.TEXT_EMPTY; 29 | private String title = TextUtil.TEXT_EMPTY; 30 | private String subtitle = TextUtil.TEXT_EMPTY; 31 | private String extend = TextUtil.TEXT_EMPTY; 32 | private String pic = TextUtil.TEXT_EMPTY; 33 | private int pic_width; 34 | private int pic_height; 35 | private ChildrenOpers children; 36 | 37 | public int getElement_id() { 38 | return element_id; 39 | } 40 | 41 | public void setElement_id(int element_id) { 42 | this.element_id = element_id; 43 | } 44 | 45 | public ChildrenOpers getChildren() { 46 | return children; 47 | } 48 | 49 | public void setChildren(ChildrenOpers children) { 50 | this.children = children; 51 | } 52 | 53 | public String getElement_type() { 54 | return element_type; 55 | } 56 | 57 | public void setElement_type(String element_type) { 58 | this.element_type = element_type; 59 | } 60 | 61 | public String getTitle() { 62 | return title; 63 | } 64 | 65 | public void setTitle(String title) { 66 | this.title = title; 67 | } 68 | 69 | public String getSubtitle() { 70 | return subtitle; 71 | } 72 | 73 | public void setSubtitle(String subtitle) { 74 | this.subtitle = subtitle; 75 | } 76 | 77 | public String getExtend() { 78 | return extend; 79 | } 80 | 81 | public void setExtend(String extend) { 82 | this.extend = extend; 83 | } 84 | 85 | public String getPic() { 86 | return pic; 87 | } 88 | 89 | public void setPic(String pic) { 90 | this.pic = pic; 91 | } 92 | 93 | public int getPic_width() { 94 | return pic_width; 95 | } 96 | 97 | public void setPic_width(int pic_width) { 98 | this.pic_width = pic_width; 99 | } 100 | 101 | public int getPic_height() { 102 | return pic_height; 103 | } 104 | 105 | public void setPic_height(int pic_height) { 106 | this.pic_height = pic_height; 107 | } 108 | 109 | 110 | public boolean isTypeWebView() { 111 | 112 | return TYPE_WEBVIEW.equalsIgnoreCase(element_type); 113 | } 114 | 115 | public boolean isTypeBanner() { 116 | 117 | return TYPE_BANNER.equals(element_type); 118 | } 119 | 120 | @Override 121 | public String toString() { 122 | 123 | return "Oper{" + 124 | "element_type='" + element_type + '\'' + 125 | ", title='" + title + '\'' + 126 | ", subtitle='" + subtitle + '\'' + 127 | ", extend='" + extend + '\'' + 128 | ", pic='" + pic + '\'' + 129 | ", pic_width=" + pic_width + 130 | ", pic_height=" + pic_height + 131 | '}'; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/decoration/DiscoverIndexLevel2Decoration.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.decoration; 2 | 3 | import android.graphics.Rect; 4 | import android.support.v7.widget.GridLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | 8 | import com.zkteam.discover.base.ExRvItemViewHolderBase; 9 | import com.zkteam.discover.util.DensityUtil; 10 | import com.zkteam.discover.vh.DiscoverIndexLevel2BannerViewHolder; 11 | import com.zkteam.discover.vh.DiscoverIndexLevel2MiniViewHolder; 12 | import com.zkteam.discover.vh.DiscoverIndexLevel2TitleViewHolder; 13 | 14 | /** 15 | * =========================================================== 16 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 17 | * 邮 箱:18810474975@163.com 18 | * 版 本: 19 | * 创建日期:2018/2/28 下午11:32 20 | * 描 述: 21 | * 修订历史: 22 | * =========================================================== 23 | */ 24 | public class DiscoverIndexLevel2Decoration extends ExRvDecoration { 25 | 26 | @Override 27 | protected void getExRvItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 28 | 29 | ExRvItemViewHolderBase viewHolder = (ExRvItemViewHolderBase) parent.getChildViewHolder(view); 30 | if (viewHolder instanceof DiscoverIndexLevel2TitleViewHolder) { 31 | 32 | outRect.top = DensityUtil.dip2px(20f); 33 | outRect.left = DensityUtil.dip2px(14f); 34 | outRect.right = outRect.left; 35 | 36 | } else if (viewHolder instanceof DiscoverIndexLevel2MiniViewHolder) { 37 | 38 | GridLayoutManager.LayoutParams sglm = (GridLayoutManager.LayoutParams) viewHolder.getConvertView().getLayoutParams(); 39 | int spanIndex = sglm.getSpanIndex(); 40 | 41 | if (spanIndex == 0) { 42 | 43 | outRect.left = DensityUtil.dip2px(25); 44 | } else if (spanIndex == 2) { 45 | 46 | outRect.right = DensityUtil.dip2px(25); 47 | } 48 | 49 | outRect.top = DensityUtil.dip2px(15f); 50 | 51 | } else if (viewHolder instanceof DiscoverIndexLevel2BannerViewHolder) { 52 | 53 | outRect.top = DensityUtil.dip2px(19f); 54 | outRect.left = DensityUtil.dip2px(10f); 55 | outRect.right = outRect.left; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/decoration/ExRvDecoration.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.decoration; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Rect; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | 8 | import com.zkteam.discover.base.ExRvItemViewHolderBase; 9 | 10 | public class ExRvDecoration extends RecyclerView.ItemDecoration { 11 | 12 | @Override 13 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 14 | 15 | onExRvDraw(c, parent, state); 16 | } 17 | 18 | @Override 19 | public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { 20 | 21 | onExRvDrawOver(c, parent, state); 22 | } 23 | 24 | protected void onExRvDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 25 | 26 | //nothing 27 | } 28 | 29 | protected void onExRvDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { 30 | 31 | //nothing 32 | } 33 | 34 | @Override 35 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 36 | 37 | getExRvItemOffsets(outRect, view, parent, state); 38 | } 39 | 40 | protected void getExRvItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 41 | 42 | ExRvItemViewHolderBase viewHolder = (ExRvItemViewHolderBase) parent.getChildViewHolder(view); 43 | getExRvDataItemOffsets(outRect, viewHolder, parent, state); 44 | } 45 | protected void getExRvDataItemOffsets(Rect outRect, ExRvItemViewHolderBase viewHolder, RecyclerView parent, RecyclerView.State state) { 46 | 47 | //nothing 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/fresco/FrescoHelper.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.fresco; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.net.Uri; 6 | 7 | import com.facebook.cache.common.SimpleCacheKey; 8 | import com.facebook.common.executors.CallerThreadExecutor; 9 | import com.facebook.common.executors.UiThreadImmediateExecutorService; 10 | import com.facebook.common.memory.PooledByteBuffer; 11 | import com.facebook.common.references.CloseableReference; 12 | import com.facebook.datasource.BaseDataSubscriber; 13 | import com.facebook.datasource.DataSource; 14 | import com.facebook.datasource.DataSubscriber; 15 | import com.facebook.drawee.backends.pipeline.Fresco; 16 | import com.facebook.imagepipeline.core.ImagePipeline; 17 | import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber; 18 | import com.facebook.imagepipeline.image.CloseableImage; 19 | import com.facebook.imagepipeline.request.BasePostprocessor; 20 | import com.facebook.imagepipeline.request.ImageRequest; 21 | import com.facebook.imagepipeline.request.ImageRequestBuilder; 22 | import com.facebook.imagepipeline.request.Postprocessor; 23 | 24 | import java.io.InputStream; 25 | import java.util.concurrent.ArrayBlockingQueue; 26 | import java.util.concurrent.ThreadPoolExecutor; 27 | import java.util.concurrent.TimeUnit; 28 | 29 | public class FrescoHelper { 30 | 31 | /** 32 | * 下载图片 33 | * 34 | * @param context 35 | * @param baseBitmapDataSubscriber onNewResultImpl进行对加载完成bitmap操作,下载失败回调onFailureImpl 36 | */ 37 | public void downloadRequest(Context context, String url, BaseBitmapDataSubscriber baseBitmapDataSubscriber) { 38 | 39 | // 获取网络图片 40 | ImageRequest imageRequest = ImageRequestBuilder 41 | .newBuilderWithSource(Uri.parse(url)) 42 | .setProgressiveRenderingEnabled(true) 43 | .build(); 44 | 45 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 46 | DataSource> dataSource = 47 | imagePipeline.fetchDecodedImage(imageRequest, context); 48 | 49 | dataSource.subscribe(baseBitmapDataSubscriber, CallerThreadExecutor.getInstance()); 50 | } 51 | 52 | /** 53 | * 下载图片监听未解码的原始数据的回调 54 | * 55 | * @param context 56 | * @param url 57 | * @param baseDataSubscriber 58 | * @return DataSource 被订阅对象 调用close可消息订阅释放资源 59 | */ 60 | public DataSource downloadRequest(Context context, String url, BaseDataSubscriber baseDataSubscriber) { 61 | 62 | // 获取网络图片 63 | ImageRequest imageRequest = ImageRequestBuilder 64 | .newBuilderWithSource(Uri.parse(url)) 65 | .setProgressiveRenderingEnabled(true) 66 | .build(); 67 | 68 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 69 | DataSource> dataSource = 70 | imagePipeline.fetchEncodedImage(imageRequest, context); 71 | 72 | dataSource.subscribe(baseDataSubscriber, UiThreadImmediateExecutorService.getInstance()); 73 | return dataSource; 74 | } 75 | 76 | /** 77 | * 高斯模糊处理器 78 | * 79 | * @return 80 | */ 81 | public Postprocessor newBlurPostProcessor(final Context context, final int blurRadius) { 82 | 83 | return new BasePostprocessor() { 84 | 85 | @Override 86 | public void process(Bitmap destBitmap, Bitmap sourceBitmap) { 87 | 88 | // BitmapUtil.blurThisImage(context, sourceBitmap, destBitmap, blurRadius); 89 | } 90 | }; 91 | } 92 | 93 | public void clearMemoryCache(Uri uri) { 94 | 95 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 96 | if (isInMemoryCache(uri)) 97 | imagePipeline.evictFromMemoryCache(uri); 98 | } 99 | 100 | public void clearDiskCache(Uri uri) { 101 | 102 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 103 | if (isInDiskCache(uri.toString())) 104 | imagePipeline.evictFromDiskCache(uri); 105 | } 106 | 107 | public static void clearCache(Uri uri) { 108 | 109 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 110 | imagePipeline.evictFromCache(uri); 111 | } 112 | 113 | public static boolean isInMemoryCache(Uri uri) { 114 | 115 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 116 | return imagePipeline.isInBitmapMemoryCache(uri); 117 | } 118 | 119 | public static boolean isInDiskCache(String uri) { 120 | 121 | return Fresco.getImagePipelineFactory().getMainFileCache().hasKey(new SimpleCacheKey(uri)); 122 | } 123 | 124 | public static InputStream getDiskCacheFile(String uri) throws Exception { 125 | 126 | return Fresco.getImagePipelineFactory().getMainFileCache().getResource(new SimpleCacheKey(uri)).openStream(); 127 | } 128 | 129 | public static boolean isInCache(Uri uri) { 130 | 131 | return isInMemoryCache(uri) || isInDiskCache(uri.toString()); 132 | } 133 | 134 | public void asyncCheckInDiskCache(Uri uri, BaseDataSubscriber baseDataSubscriber) { 135 | 136 | //异步判断是否在磁盘中 137 | DataSource inDiskCacheSource = Fresco.getImagePipeline().isInDiskCache(uri); 138 | DataSubscriber subscriber = baseDataSubscriber; 139 | // DataSubscriber subscriber = new BaseDataSubscriber() { 140 | // 141 | // @Override 142 | // protected void onNewResultImpl(DataSource dataSource) { 143 | // if (!dataSource.isFinished()) { 144 | // return; 145 | // } 146 | // boolean isInCache = dataSource.getResult(); 147 | // } 148 | // 149 | // @Override 150 | // protected void onFailureImpl(DataSource dataSource) { 151 | // 152 | // } 153 | // }; 154 | inDiskCacheSource.subscribe(subscriber, new ThreadPoolExecutor(3, 127, 3, 155 | TimeUnit.SECONDS, new ArrayBlockingQueue(3), 156 | new ThreadPoolExecutor.DiscardOldestPolicy())); 157 | } 158 | 159 | /** 160 | * 清除内存缓存数据 161 | */ 162 | public static void clearMemoryCache() { 163 | 164 | try { 165 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 166 | imagePipeline.clearMemoryCaches(); 167 | } catch (Throwable t) { 168 | } 169 | } 170 | 171 | /** 172 | * 清除磁盘缓存 173 | */ 174 | public static void clearDiskCache() { 175 | 176 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 177 | imagePipeline.clearDiskCaches(); 178 | } 179 | 180 | /** 181 | * 清除内存及磁盘缓存 182 | */ 183 | public static void clearMemoryAndDiskCache() { 184 | 185 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 186 | imagePipeline.clearCaches(); 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/fresco/FrescoImageView.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.fresco; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.net.Uri; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | 9 | import com.facebook.common.internal.Supplier; 10 | import com.facebook.drawee.backends.pipeline.PipelineDraweeController; 11 | import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder; 12 | import com.facebook.drawee.controller.BaseControllerListener; 13 | import com.facebook.drawee.drawable.ProgressBarDrawable; 14 | import com.facebook.drawee.drawable.ScalingUtils; 15 | import com.facebook.drawee.generic.RoundingParams; 16 | import com.facebook.drawee.view.GenericDraweeView; 17 | import com.facebook.imagepipeline.common.ResizeOptions; 18 | import com.facebook.imagepipeline.request.ImageRequest; 19 | import com.facebook.imagepipeline.request.ImageRequestBuilder; 20 | import com.facebook.imagepipeline.request.Postprocessor; 21 | import com.zkteam.discover.util.TextUtil; 22 | 23 | 24 | /** 25 | * 自定义fresco图片加载框架视图 26 | *

27 | * Scaling 是一种画布操作,通常是由硬件加速的。图片实际大小保持不变,它只不过在绘制时被放大或缩小。 28 | * Resizing 是一种软件执行的管道操作。它返回一张新的,尺寸不同的图片。 29 | * Downsampling 同样是软件实现的管道操作。它不是创建一张新的图片,而是在解码时改变图片的大小。 30 | */ 31 | public class FrescoImageView extends GenericDraweeView { 32 | 33 | private static Supplier sDraweeControllerBuilderSupplier; 34 | private PipelineDraweeControllerBuilder mDraweeControllerBuilder; 35 | 36 | private BaseControllerListener mBaseControllerListener;//临听下载 37 | private Postprocessor mPostprocessor;//后置处理图片 38 | private boolean mSmallCache;//是否为小图,缓存至小图目录 39 | private static boolean mGlobalWindowVisibilityChangedAutoDetachEnable; 40 | private boolean mWindowVisibilityChangedAutoDetachEnable; 41 | private boolean mAutoDetached; 42 | 43 | public FrescoImageView(Context context) { 44 | 45 | super(context); 46 | init(); 47 | } 48 | 49 | public FrescoImageView(Context context, AttributeSet attrs) { 50 | 51 | super(context, attrs); 52 | init(); 53 | } 54 | 55 | public FrescoImageView(Context context, AttributeSet attrs, int defStyle) { 56 | 57 | super(context, attrs, defStyle); 58 | init(); 59 | } 60 | 61 | private void init() { 62 | 63 | mDraweeControllerBuilder = sDraweeControllerBuilderSupplier.get(); 64 | } 65 | 66 | public static void initialize(Supplier draweeControllerBuilderSupplier) { 67 | 68 | sDraweeControllerBuilderSupplier = draweeControllerBuilderSupplier; 69 | } 70 | 71 | public static void shutDown() { 72 | 73 | sDraweeControllerBuilderSupplier = null; 74 | } 75 | 76 | public static void setGlobalOnWindowVisibilityChangedAutoDetachEnable(boolean enable){ 77 | 78 | mGlobalWindowVisibilityChangedAutoDetachEnable = enable; 79 | } 80 | 81 | //###################### 初始化配置项 ######################### 82 | 83 | 84 | /** 85 | * 默认占位图 86 | * 87 | * @param resourceId 88 | */ 89 | public void setDefPlaceholderImage(int resourceId) { 90 | 91 | getHierarchy().setPlaceholderImage(resourceId); 92 | } 93 | 94 | /** 95 | * 失败默认占位图 96 | * 97 | * @param resourceId 98 | */ 99 | public void setDefFailureImage(int resourceId) { 100 | 101 | getHierarchy().setFailureImage(resourceId); 102 | } 103 | 104 | /** 105 | * 设置圆角 106 | * 107 | * @param roundingParams 108 | */ 109 | public void setRoundingParams(RoundingParams roundingParams) { 110 | 111 | getHierarchy().setRoundingParams(roundingParams); 112 | } 113 | 114 | /** 115 | * 设置fadeIn 效果 116 | * 117 | * @param fadeIn 118 | */ 119 | public void setFadeIn(boolean fadeIn) { 120 | 121 | if (!fadeIn) 122 | getHierarchy().setFadeDuration(0); 123 | } 124 | 125 | /** 126 | * fresco 支持的缩放模式不支持ImageView ScaleType。 127 | * 128 | * @param scaleType 129 | */ 130 | public void setFrescoScaleType(ScalingUtils.ScaleType scaleType) { 131 | 132 | getHierarchy().setActualImageScaleType(scaleType); 133 | } 134 | 135 | public ScalingUtils.ScaleType getFrescoScaleType() { 136 | 137 | return getHierarchy().getActualImageScaleType(); 138 | } 139 | 140 | /** 141 | * 监听下载 142 | * 143 | * @param baseControllerListener 下载成功回调 onIntermediateImageSet,失败回调 onFailure 144 | */ 145 | public void setBaseControllerListener(BaseControllerListener baseControllerListener) { 146 | 147 | mBaseControllerListener = baseControllerListener; 148 | } 149 | 150 | /** 151 | * 图片下载完成后图片处理 152 | * 153 | * @param postprocessor 下载加载完成后图片处理:process方法处理bitmap 154 | */ 155 | public void setPostprocessor(Postprocessor postprocessor) { 156 | 157 | mPostprocessor = postprocessor; 158 | } 159 | 160 | /** 161 | * 设置加载图片进度显示效果 162 | * 163 | * @param progressBarDrawable 164 | */ 165 | public void setProgressBarDrawable(ProgressBarDrawable progressBarDrawable) { 166 | 167 | getHierarchy().setProgressBarImage(progressBarDrawable); 168 | } 169 | 170 | public void setSmallCache() { 171 | 172 | mSmallCache = true; 173 | } 174 | 175 | public void setWindowVisibilityChangedAutoDetach(boolean autoDetach){ 176 | 177 | mWindowVisibilityChangedAutoDetachEnable = autoDetach; 178 | } 179 | 180 | //###################### 图片加载项 ######################### 181 | 182 | /* 加载res本地图片 */ 183 | public void setImageResId(int resourceId) { 184 | 185 | setImageResIdResize(resourceId, null); 186 | } 187 | 188 | public void setImageResIdByLp(int resourceId) { 189 | 190 | if (getLayoutParams().width > 0 && getLayoutParams().height > 0) 191 | setImageResIdResize(resourceId, new ResizeOptions(getLayoutParams().width, getLayoutParams().height)); 192 | else 193 | setImageResIdResize(resourceId, null); 194 | } 195 | 196 | public void setImageResIdResize(int resourceId, ResizeOptions resizeOptions) { 197 | 198 | setImageUriResize(Uri.parse("res:///" + resourceId), resizeOptions); 199 | } 200 | 201 | /* 加载图片url or sdcard图片路径 */ 202 | public void setImageUri(String imageUri) { 203 | 204 | setImageUriResize(imageUri, null); 205 | } 206 | 207 | public void setImageUriByLp(String imageUri) { 208 | 209 | if (getLayoutParams().width > 0 && getLayoutParams().height > 0) 210 | setImageUriResize(imageUri, new ResizeOptions(getLayoutParams().width, getLayoutParams().height)); 211 | else 212 | setImageUriResize(imageUri, null); 213 | } 214 | 215 | public void setImageUriResize(String imageUri, ResizeOptions resizeOptions) { 216 | 217 | imageUri = TextUtil.filterNull(imageUri); 218 | 219 | if (imageUri.startsWith("/")) 220 | imageUri = "file://" + imageUri; 221 | 222 | setImageUriResize(Uri.parse(imageUri), resizeOptions); 223 | } 224 | 225 | /* 加载uri图片 */ 226 | public void setImageUri(Uri uri) { 227 | 228 | if (uri == null) 229 | uri = Uri.parse(TextUtil.TEXT_EMPTY); 230 | 231 | setImageUriResize(uri, null); 232 | } 233 | 234 | public void setImageUriByLp(Uri uri) { 235 | 236 | if (uri == null) 237 | uri = Uri.parse(TextUtil.TEXT_EMPTY); 238 | 239 | setImageUriResize(uri, new ResizeOptions(getLayoutParams().width, getLayoutParams().height)); 240 | } 241 | 242 | public void setImageUriResize(Uri uri, ResizeOptions resizeOptions) { 243 | 244 | if (uri == null) 245 | uri = Uri.parse(TextUtil.TEXT_EMPTY); 246 | 247 | loadImageUri(uri, resizeOptions); 248 | } 249 | 250 | /** 251 | * 通过uri加载图片 252 | * 253 | * @param uri 254 | * @param resizeOptions 255 | */ 256 | private void loadImageUri(final Uri uri, ResizeOptions resizeOptions) { 257 | 258 | ImageRequest request; 259 | if (mSmallCache) { 260 | 261 | request = ImageRequestBuilder.newBuilderWithSource(uri) 262 | .setResizeOptions(resizeOptions)//Resize 并不改变原始图片,它只在解码前修改内存中的图片大小 263 | .setPostprocessor(mPostprocessor) 264 | .setCacheChoice(ImageRequest.CacheChoice.SMALL) 265 | .build(); 266 | } else { 267 | 268 | request = ImageRequestBuilder.newBuilderWithSource(uri) 269 | .setResizeOptions(resizeOptions) 270 | .setPostprocessor(mPostprocessor) 271 | .build(); 272 | } 273 | 274 | PipelineDraweeController controller = (PipelineDraweeController) mDraweeControllerBuilder.setControllerListener(mBaseControllerListener) 275 | .setUri(uri) 276 | .setImageRequest(request) 277 | .setTapToRetryEnabled(false) 278 | .setOldController(getController()) // 列表滚动 优化 279 | .setAutoPlayAnimations(true) //自动播放gif动画 280 | .build(); 281 | 282 | setController(controller); 283 | } 284 | 285 | @Override 286 | protected void onWindowVisibilityChanged(int visibility) { 287 | 288 | super.onWindowVisibilityChanged(visibility); 289 | 290 | if (View.VISIBLE == visibility) { 291 | 292 | if(mAutoDetached){ 293 | 294 | doAttach(); 295 | mAutoDetached = false; 296 | } 297 | 298 | } else { 299 | 300 | if (mWindowVisibilityChangedAutoDetachEnable || 301 | mGlobalWindowVisibilityChangedAutoDetachEnable) { 302 | 303 | doDetach(); 304 | mAutoDetached = true; 305 | } 306 | } 307 | } 308 | 309 | public void attachImage(){ 310 | 311 | doAttach(); 312 | } 313 | 314 | public void detachImage(){ 315 | 316 | doDetach(); 317 | } 318 | 319 | @Override 320 | protected void onDraw(Canvas canvas) { 321 | 322 | try { 323 | super.onDraw(canvas); 324 | } catch (Exception e) { 325 | } 326 | } 327 | } 328 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/fresco/FrescoInitUtil.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.fresco; 2 | 3 | import android.app.ActivityManager; 4 | import android.content.Context; 5 | import android.os.Build; 6 | 7 | import com.facebook.cache.disk.DiskCacheConfig; 8 | import com.facebook.common.disk.NoOpDiskTrimmableRegistry; 9 | import com.facebook.common.internal.Supplier; 10 | import com.facebook.common.memory.NoOpMemoryTrimmableRegistry; 11 | import com.facebook.common.util.ByteConstants; 12 | import com.facebook.imagepipeline.cache.DefaultCacheKeyFactory; 13 | import com.facebook.imagepipeline.cache.MemoryCacheParams; 14 | import com.facebook.imagepipeline.core.ImagePipelineConfig; 15 | import com.zkteam.discover.app.BaseApp; 16 | import com.zkteam.discover.util.StorageUtil; 17 | 18 | public class FrescoInitUtil { 19 | 20 | //分配的可用内存 21 | private static final int MAX_HEAP_SIZE = (int) Runtime.getRuntime().maxMemory(); 22 | 23 | //使用的缓存数量 24 | private static final int MAX_MEMORY_CACHE_SIZE = MAX_HEAP_SIZE / 4; 25 | 26 | //默认图所放路径的文件夹名 27 | private static final String IMAGE_CACHE_DEFAULT_DIR = "frescoCacheDefault"; 28 | 29 | //默认图磁盘缓存的最大值 30 | private static final int MAX_DISK_CACHE_SIZE = 80 * ByteConstants.MB; 31 | 32 | //默认图低磁盘空间缓存的最大值 33 | private static final int MAX_DISK_CACHE_LOW_SIZE = 50 * ByteConstants.MB; 34 | 35 | //默认图极低磁盘空间缓存的最大值 36 | private static final int MAX_DISK_CACHE_VERYLOW_SIZE = 30 * ByteConstants.MB; 37 | 38 | //小图所放路径的文件夹名 39 | private static final String IMAGE_CACHE_SMALL_DIR = "frescoCacheSmall"; 40 | 41 | //小图低磁盘空间缓存的最大值 42 | //如何区分小图片需要在ImageRequestBuilder手动调用setCacheChoice(ImageRequest.CacheChoice.SMALL)指定 43 | private static final int MAX_SMALL_DISK_LOW_CACHE_SIZE = 20 * ByteConstants.MB; 44 | 45 | //小图极低磁盘空间缓存的最大值(特性:可将大量的小图放到额外放在另一个磁盘空间防止大图占用磁盘空间而删除了大量的小图) 46 | private static final int MAX_SMALL_DISK_VERYLOW_CACHE_SIZE = 10 * ByteConstants.MB; 47 | 48 | private static final int MAX_CACHE_ENTRIES = Integer.MAX_VALUE; 49 | // private static final int MAX_EVICTION_QUEUE_SIZE = 6*ByteConstants.MB;//Integer.MAX_VALUE; 50 | private static final int MAX_EVICTION_QUEUE_ENTRIES = 128;//Integer.MAX_VALUE; 51 | private static final int MAX_CACHE_ENTRY_SIZE = Integer.MAX_VALUE; 52 | 53 | private static ActivityManager mActivityManager; 54 | 55 | public static void initFrescoConfig() { 56 | 57 | ImagePipelineConfig pipeConfig = ImagePipelineConfig.newBuilder(BaseApp.getContext()) 58 | .setBitmapMemoryCacheParamsSupplier(new BitmapCacheParamsSupplier())//bitmap内存缓存数据的策略 59 | .setCacheKeyFactory(DefaultCacheKeyFactory.getInstance())//缓存键值对的获取 参考DefaultCacheKeyFactory进行修改缓存key 60 | .setDownsampleEnabled(true)//缩放图片 同样是软件实现的管道操作。它不是创建一张新的图片,而是在解码时改变图片的大小。 61 | .setEncodedMemoryCacheParamsSupplier(new EncodedMemoryCacheParamsSupplier())//未解码(原始压缩格式的图片)内存设置 62 | //设置本地读写线程池,网络数据线程池 解码线程池,以及后台线程池. DefaultExecutorSupplier默认设置 63 | //.setExecutorSupplier(executorSupplier) 64 | //NoOpImageCacheStatsTracker 追踪图片缓存相关状态 65 | //.setImageCacheStatsTracker(imageCacheStatsTracker) 66 | //设置磁盘缓存项配置 67 | .setMainDiskCacheConfig(getDisCacheConfigDefault(BaseApp.getContext())) 68 | .setSmallImageDiskCacheConfig(getDisCacheConfigSmall(BaseApp.getContext())) 69 | //设置管理池,默认为PoolFactory 存放了相应的bitmap,nativememory,shareByte数据池管理 70 | //.setPoolFactory(poolFactory) 71 | //渐进式JPEG配置 SimpleProgressiveJpegConfig 72 | //.setProgressiveJpegConfig(progressiveJpegConfig) 73 | //设置请求监听集合 74 | //.setRequestListeners(requestListeners) 75 | .setMemoryTrimmableRegistry(NoOpMemoryTrimmableRegistry.getInstance()) 76 | .build(); 77 | 78 | FrescoIniter.initialize(BaseApp.getContext(), pipeConfig); 79 | 80 | } 81 | 82 | public static DiskCacheConfig getDisCacheConfigDefault(final Context context) { 83 | 84 | return DiskCacheConfig.newBuilder(context).setBaseDirectoryPath(StorageUtil.getAppPicDir()) 85 | .setBaseDirectoryName(IMAGE_CACHE_DEFAULT_DIR)//文件夹名 86 | .setMaxCacheSize(MAX_DISK_CACHE_SIZE)//默认缓存的最大大小。 87 | .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)//缓存的最大大小,使用设备时低磁盘空间。 88 | .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)//缓存的最大大小,当设备极低磁盘空间 89 | .setDiskTrimmableRegistry(NoOpDiskTrimmableRegistry.getInstance()) 90 | .build(); 91 | } 92 | 93 | public static DiskCacheConfig getDisCacheConfigSmall(final Context context) { 94 | 95 | return DiskCacheConfig.newBuilder(context).setBaseDirectoryPath(StorageUtil.getAppPicDir()) 96 | .setBaseDirectoryName(IMAGE_CACHE_SMALL_DIR)//文件夹名 97 | .setMaxCacheSize(MAX_DISK_CACHE_SIZE)//默认缓存的最大大小。 98 | .setMaxCacheSizeOnLowDiskSpace(MAX_SMALL_DISK_LOW_CACHE_SIZE)//缓存的最大大小,使用设备时低磁盘空间。 99 | .setMaxCacheSizeOnVeryLowDiskSpace(MAX_SMALL_DISK_VERYLOW_CACHE_SIZE)//缓存的最大大小,当设备极低磁盘空间 100 | .setDiskTrimmableRegistry(NoOpDiskTrimmableRegistry.getInstance()) 101 | .build(); 102 | } 103 | 104 | public static class BitmapCacheParamsSupplier implements Supplier { 105 | 106 | @Override 107 | public MemoryCacheParams get() { 108 | 109 | mActivityManager = (ActivityManager) BaseApp.getContext().getSystemService(Context.ACTIVITY_SERVICE); 110 | 111 | final int maxCacheSize = getMaxCacheSize(); 112 | final int maxCacheEntrySize = maxCacheSize / 2; 113 | 114 | return new MemoryCacheParams( 115 | maxCacheSize, // 内存缓存中总图片的最大大小,以字节为单位。 116 | MAX_CACHE_ENTRIES, // 内存缓存中图片的最大数量 117 | maxCacheSize / 2, // 内存缓存待回收 但尚未被回收的最大大小,以字节为单位。 118 | MAX_EVICTION_QUEUE_ENTRIES,//// 内存缓存待回收图片的最大数量 119 | maxCacheEntrySize);// 内存缓存中单个图片的最大大小 120 | } 121 | 122 | private int getMaxCacheSize() { 123 | 124 | try { 125 | 126 | final int maxMemory = 127 | Math.min(mActivityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE); 128 | if (maxMemory < 32 * ByteConstants.MB) { 129 | return 4 * ByteConstants.MB; 130 | } else if (maxMemory < 64 * ByteConstants.MB) { 131 | return 6 * ByteConstants.MB; 132 | } else { 133 | // We don't want to use more ashmem on Gingerbread for now, since it doesn't respond well to 134 | // native memory pressure (doesn't throw exceptions, crashes app, crashes phone) 135 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { 136 | return 8 * ByteConstants.MB; 137 | } else { 138 | return maxMemory / 2; 139 | } 140 | } 141 | } catch (Exception e) { 142 | 143 | e.printStackTrace(); 144 | } 145 | return 8 * ByteConstants.MB; 146 | } 147 | } 148 | 149 | public static class EncodedMemoryCacheParamsSupplier implements Supplier { 150 | 151 | private static final int MAX_CACHE_ENTRIES = Integer.MAX_VALUE; 152 | private static final int MAX_EVICTION_QUEUE_ENTRIES = MAX_CACHE_ENTRIES; 153 | 154 | @Override 155 | public MemoryCacheParams get() { 156 | 157 | final int maxCacheSize = getMaxCacheSize(); 158 | final int maxCacheEntrySize = maxCacheSize / 4; 159 | 160 | return new MemoryCacheParams( 161 | maxCacheSize, 162 | MAX_CACHE_ENTRIES, 163 | maxCacheSize, 164 | MAX_EVICTION_QUEUE_ENTRIES, 165 | maxCacheEntrySize); 166 | } 167 | 168 | private int getMaxCacheSize() { 169 | 170 | final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE); 171 | 172 | if (maxMemory < 16 * ByteConstants.MB) { 173 | return 1 * ByteConstants.MB; 174 | } else if (maxMemory < 32 * ByteConstants.MB) { 175 | return 2 * ByteConstants.MB; 176 | } else { 177 | return 4 * ByteConstants.MB; 178 | } 179 | } 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/fresco/FrescoIniter.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.fresco; 2 | 3 | import android.content.Context; 4 | 5 | import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder; 6 | import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier; 7 | import com.facebook.imagepipeline.core.ImagePipeline; 8 | import com.facebook.imagepipeline.core.ImagePipelineConfig; 9 | import com.facebook.imagepipeline.core.ImagePipelineFactory; 10 | 11 | /** 12 | * Fresco 初始化类 13 | */ 14 | public class FrescoIniter { 15 | 16 | private static PipelineDraweeControllerBuilderSupplier sDraweeControllerBuilderSupplier; 17 | 18 | public static void initialize(Context context) { 19 | 20 | ImagePipelineFactory.initialize(context); 21 | initializeDrawee(context); 22 | } 23 | 24 | public static void initialize(Context context, ImagePipelineConfig imagePipelineConfig) { 25 | 26 | ImagePipelineFactory.initialize(imagePipelineConfig); 27 | initializeDrawee(context); 28 | } 29 | 30 | private static void initializeDrawee(Context context) { 31 | 32 | sDraweeControllerBuilderSupplier = new PipelineDraweeControllerBuilderSupplier(context); 33 | FrescoImageView.initialize(sDraweeControllerBuilderSupplier); 34 | } 35 | 36 | public static PipelineDraweeControllerBuilderSupplier getDraweeControllerBuilderSupplier() { 37 | 38 | return sDraweeControllerBuilderSupplier; 39 | } 40 | 41 | public static PipelineDraweeControllerBuilder newDraweeControllerBuilder() { 42 | 43 | return sDraweeControllerBuilderSupplier.get(); 44 | } 45 | 46 | public static ImagePipelineFactory getImagePipelineFactory() { 47 | 48 | return ImagePipelineFactory.getInstance(); 49 | } 50 | 51 | public static ImagePipeline getImagePipeline() { 52 | 53 | return getImagePipelineFactory().getImagePipeline(); 54 | } 55 | 56 | /** 57 | * 此方法不需要调用,因在应用当中只初始化一次,如调用之后必须得重调用initialize 进行初始化 58 | */ 59 | public static void shutDown() { 60 | 61 | sDraweeControllerBuilderSupplier = null; 62 | FrescoImageView.shutDown(); 63 | ImagePipelineFactory.shutDown(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/manager/LinearSmoothScroller.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.manager; 2 | 3 | import android.content.Context; 4 | import android.graphics.PointF; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.widget.RecyclerView.LayoutManager; 7 | import android.support.v7.widget.RecyclerView.LayoutParams; 8 | import android.support.v7.widget.RecyclerView.SmoothScroller; 9 | import android.support.v7.widget.RecyclerView.State; 10 | import android.util.DisplayMetrics; 11 | import android.view.View; 12 | import android.view.animation.DecelerateInterpolator; 13 | import android.view.animation.LinearInterpolator; 14 | 15 | /** 16 | * =========================================================== 17 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 18 | * 邮 箱:18810474975@163.com 19 | * 版 本: 20 | * 创建日期:2018/3/12 下午8:36 21 | * 描 述: 自定义SmoothScroller 控制RecyclerView 滚动速度,滚动时间 22 | * 修订历史: 23 | * =========================================================== 24 | */ 25 | public class LinearSmoothScroller extends SmoothScroller { 26 | 27 | private static final float MILLISECONDS_PER_INCH = 25.0f; 28 | public static final int SNAP_TO_ANY = 0; 29 | public static final int SNAP_TO_END = 1; 30 | public static final int SNAP_TO_START = -1; 31 | private static final float TARGET_SEEK_EXTRA_SCROLL_RATIO = 1.2f; 32 | private static final int TARGET_SEEK_SCROLL_DISTANCE_PX = 10000; 33 | private final float MILLISECONDS_PER_PX; 34 | protected final DecelerateInterpolator mDecelerateInterpolator = new DecelerateInterpolator(); 35 | protected int mInterimTargetDx = SNAP_TO_ANY; 36 | protected int mInterimTargetDy = SNAP_TO_ANY; 37 | protected final LinearInterpolator mLinearInterpolator = new LinearInterpolator(); 38 | protected PointF mTargetVector; 39 | 40 | public LinearSmoothScroller(Context context) { 41 | this.MILLISECONDS_PER_PX = calculateSpeedPerPixel(context.getResources().getDisplayMetrics()); 42 | } 43 | 44 | protected void onStart() { 45 | } 46 | 47 | protected void onTargetFound(View targetView, State state, Action action) { 48 | int dx = calculateDxToMakeVisible(targetView, getHorizontalSnapPreference()); 49 | int dy = calculateDyToMakeVisible(targetView, getVerticalSnapPreference()); 50 | int time = calculateTimeForDeceleration((int) Math.sqrt((double) ((dx * dx) + (dy * dy)))); 51 | if (time > 0) { 52 | action.update(-dx, -dy, time, this.mDecelerateInterpolator); 53 | } 54 | } 55 | 56 | protected void onSeekTargetStep(int dx, int dy, State state, Action action) { 57 | if (getChildCount() == 0) { 58 | stop(); 59 | return; 60 | } 61 | this.mInterimTargetDx = clampApplyScroll(this.mInterimTargetDx, dx); 62 | this.mInterimTargetDy = clampApplyScroll(this.mInterimTargetDy, dy); 63 | if (this.mInterimTargetDx == 0 && this.mInterimTargetDy == 0) { 64 | updateActionForInterimTarget(action); 65 | } 66 | } 67 | 68 | protected void onStop() { 69 | this.mInterimTargetDy = SNAP_TO_ANY; 70 | this.mInterimTargetDx = SNAP_TO_ANY; 71 | this.mTargetVector = null; 72 | } 73 | 74 | /** 75 | * 计算滚动时长 76 | * 77 | * @param displayMetrics 78 | * @return 79 | */ 80 | protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) { 81 | return MILLISECONDS_PER_INCH / ((float) displayMetrics.densityDpi); 82 | } 83 | 84 | protected int calculateTimeForDeceleration(int dx) { 85 | return (int) Math.ceil(((double) calculateTimeForScrolling(dx)) / 0.3356d); 86 | } 87 | 88 | protected int calculateTimeForScrolling(int dx) { 89 | return (int) Math.ceil((double) (((float) Math.abs(dx)) * this.MILLISECONDS_PER_PX)); 90 | } 91 | 92 | protected int getHorizontalSnapPreference() { 93 | if (this.mTargetVector == null || this.mTargetVector.x == 0.0f) { 94 | return SNAP_TO_ANY; 95 | } 96 | return this.mTargetVector.x > 0.0f ? SNAP_TO_END : SNAP_TO_START; 97 | } 98 | 99 | protected int getVerticalSnapPreference() { 100 | if (this.mTargetVector == null || this.mTargetVector.y == 0.0f) { 101 | return SNAP_TO_ANY; 102 | } 103 | return this.mTargetVector.y > 0.0f ? SNAP_TO_END : SNAP_TO_START; 104 | } 105 | 106 | protected void updateActionForInterimTarget(Action action) { 107 | PointF scrollVector = computeScrollVectorForPosition(getTargetPosition()); 108 | if (scrollVector == null || (scrollVector.x == 0.0f && scrollVector.y == 0.0f)) { 109 | action.jumpTo(getTargetPosition()); 110 | stop(); 111 | return; 112 | } 113 | normalize(scrollVector); 114 | this.mTargetVector = scrollVector; 115 | this.mInterimTargetDx = (int) (scrollVector.x * 10000.0f); 116 | this.mInterimTargetDy = (int) (scrollVector.y * 10000.0f); 117 | action.update((int) (((float) this.mInterimTargetDx) * TARGET_SEEK_EXTRA_SCROLL_RATIO), (int) (((float) this.mInterimTargetDy) * TARGET_SEEK_EXTRA_SCROLL_RATIO), (int) (((float) calculateTimeForScrolling(TARGET_SEEK_SCROLL_DISTANCE_PX)) * TARGET_SEEK_EXTRA_SCROLL_RATIO), this.mLinearInterpolator); 118 | } 119 | 120 | private int clampApplyScroll(int tmpDt, int dt) { 121 | int before = tmpDt; 122 | tmpDt -= dt; 123 | if (before * tmpDt <= 0) { 124 | return SNAP_TO_ANY; 125 | } 126 | return tmpDt; 127 | } 128 | 129 | public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) { 130 | switch (snapPreference) { 131 | case SNAP_TO_START /*-1*/: 132 | return boxStart - viewStart; 133 | case SNAP_TO_ANY /*0*/: 134 | int dtStart = boxStart - viewStart; 135 | if (dtStart > 0) { 136 | return dtStart; 137 | } 138 | int dtEnd = boxEnd - viewEnd; 139 | if (dtEnd < 0) { 140 | return dtEnd; 141 | } 142 | return SNAP_TO_ANY; 143 | case SNAP_TO_END /*1*/: 144 | return boxEnd - viewEnd; 145 | default: 146 | throw new IllegalArgumentException("snap preference should be one of the constants defined in SmoothScroller, starting with SNAP_"); 147 | } 148 | } 149 | 150 | public int calculateDyToMakeVisible(View view, int snapPreference) { 151 | LayoutManager layoutManager = getLayoutManager(); 152 | if (layoutManager == null || !layoutManager.canScrollVertically()) { 153 | return SNAP_TO_ANY; 154 | } 155 | LayoutParams params = (LayoutParams) view.getLayoutParams(); 156 | return calculateDtToFit(layoutManager.getDecoratedTop(view) - params.topMargin, layoutManager.getDecoratedBottom(view) + params.bottomMargin, layoutManager.getPaddingTop(), layoutManager.getHeight() - layoutManager.getPaddingBottom(), snapPreference); 157 | } 158 | 159 | public int calculateDxToMakeVisible(View view, int snapPreference) { 160 | LayoutManager layoutManager = getLayoutManager(); 161 | if (layoutManager == null || !layoutManager.canScrollHorizontally()) { 162 | return SNAP_TO_ANY; 163 | } 164 | LayoutParams params = (LayoutParams) view.getLayoutParams(); 165 | return calculateDtToFit(layoutManager.getDecoratedLeft(view) - params.leftMargin, layoutManager.getDecoratedRight(view) + params.rightMargin, layoutManager.getPaddingLeft(), layoutManager.getWidth() - layoutManager.getPaddingRight(), snapPreference); 166 | } 167 | 168 | @Nullable 169 | public PointF computeScrollVectorForPosition(int targetPosition) { 170 | LayoutManager layoutManager = getLayoutManager(); 171 | if (layoutManager instanceof ScrollVectorProvider) { 172 | return ((ScrollVectorProvider) layoutManager).computeScrollVectorForPosition(targetPosition); 173 | } 174 | return null; 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/manager/TopSnappedLayoutManager.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.manager; 2 | 3 | import android.content.Context; 4 | import android.graphics.PointF; 5 | import android.support.v7.widget.GridLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.support.v7.widget.RecyclerView.SmoothScroller; 8 | import android.support.v7.widget.RecyclerView.State; 9 | import android.util.AttributeSet; 10 | 11 | /** 12 | * =========================================================== 13 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 14 | * 邮 箱:18810474975@163.com 15 | * 版 本: 16 | * 创建日期:2018/3/12 下午12:37 17 | * 描 述: 重写 smoothScrollToPosition 滚动置顶 18 | * 修订历史: 19 | * =========================================================== 20 | */ 21 | public class TopSnappedLayoutManager extends GridLayoutManager { 22 | 23 | private class TopSnappedSmoothScroller extends LinearSmoothScroller { 24 | public TopSnappedSmoothScroller(Context context) { 25 | super(context); 26 | } 27 | 28 | public PointF computeScrollVectorForPosition(int targetPosition) { 29 | 30 | return TopSnappedLayoutManager.this.computeScrollVectorForPosition(targetPosition); 31 | } 32 | 33 | protected int getVerticalSnapPreference() { 34 | 35 | return -1; 36 | } 37 | } 38 | 39 | public TopSnappedLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 40 | super(context, attrs, defStyleAttr, defStyleRes); 41 | } 42 | 43 | public TopSnappedLayoutManager(Context context, int spanCount) { 44 | super(context, spanCount); 45 | } 46 | 47 | public TopSnappedLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) { 48 | super(context, spanCount, orientation, reverseLayout); 49 | } 50 | 51 | public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) { 52 | SmoothScroller smoothScroller = new TopSnappedSmoothScroller(recyclerView.getContext()); 53 | smoothScroller.setTargetPosition(position); 54 | startSmoothScroll(smoothScroller); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/util/CollectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** 9 | * 集合工具类 10 | */ 11 | public class CollectionUtil { 12 | 13 | /** 14 | * 判断集合是否为空 15 | * 16 | * @param collection 17 | * @return 18 | */ 19 | public static boolean isEmpty(Collection collection) { 20 | 21 | return collection == null || collection.isEmpty(); 22 | } 23 | 24 | /** 25 | * 返回集合的大小,null集合返回0 26 | * 27 | * @param collection 28 | * @return 29 | */ 30 | public static int size(Collection collection) { 31 | 32 | return collection == null ? 0 : collection.size(); 33 | } 34 | 35 | /** 36 | * 返回map大小 37 | * @param map 38 | * @return 39 | */ 40 | public static int size(Map map){ 41 | 42 | return map == null ? 0 : map.size(); 43 | } 44 | 45 | /** 46 | * 判断map是否为空 47 | * @param map 48 | * @return 49 | */ 50 | public static boolean isEmpty(Map map){ 51 | 52 | return map == null ? true : map.isEmpty(); 53 | } 54 | 55 | /** 56 | * 判断position是否在集合长度范围内 57 | * 58 | * @param collection 59 | * @param position 60 | * @return 61 | */ 62 | public static boolean checkPosition(Collection collection, int position) { 63 | 64 | return position >= 0 && position < size(collection); 65 | } 66 | 67 | /** 68 | * 获取过滤后的position 69 | * 70 | * @param collection 71 | * @param position 72 | * @return 73 | */ 74 | public static int filterPosition(Collection collection, int position) { 75 | 76 | if (isEmpty(collection)) 77 | return 0; 78 | 79 | if (position < 0) { 80 | position = 0; 81 | } else if (position >= collection.size()) { 82 | position = collection.size() - 1; 83 | } 84 | 85 | return position; 86 | } 87 | 88 | /** 89 | * 做下标越界判断,如果越界返回null 90 | * 91 | * @param list 92 | * @param position 93 | * @param 94 | * @return 95 | */ 96 | public static T getItem(List list, int position) { 97 | 98 | return checkPosition(list, position) ? list.get(position) : null; 99 | } 100 | 101 | /** 102 | * 获取集合最后一个元素 103 | * 104 | * @param list 105 | * @param 106 | * @return 107 | */ 108 | public static T getLastItem(List list) { 109 | 110 | return getItem(list, size(list) - 1); 111 | } 112 | 113 | /** 114 | * 清空集合 115 | * 116 | * @param list 117 | * @param 118 | */ 119 | public static void clear(List list) { 120 | 121 | if (!isEmpty(list)) 122 | list.clear(); 123 | } 124 | 125 | /** 126 | * 移除item 127 | * 128 | * @param list 129 | * @param item 130 | * @param 131 | * @return 132 | */ 133 | public static boolean remove(List list, T item) { 134 | 135 | if (!isEmpty(list) && item != null) 136 | return list.remove(item); 137 | else 138 | return false; 139 | } 140 | 141 | /** 142 | * 移除item 143 | * 144 | * @param list 145 | * @param position 146 | * @param 147 | */ 148 | public static boolean remove(List list, int position) { 149 | 150 | if (list != null && checkPosition(list, position)) { 151 | 152 | list.remove(position); 153 | return true; 154 | } else { 155 | 156 | return false; 157 | } 158 | } 159 | 160 | /** 161 | * 移除指定子集 162 | * 163 | * @param srcList 164 | * @param removeList 165 | * @param 166 | */ 167 | public static void removeAll(List srcList, List removeList) { 168 | 169 | if (CollectionUtil.isEmpty(srcList) || CollectionUtil.isEmpty(removeList)) 170 | return; 171 | 172 | srcList.removeAll(removeList); 173 | } 174 | 175 | /** 176 | * 将文本根据指定的字符串分割成字符串集合 177 | * 178 | * @param text 179 | * @param split 180 | * @return 181 | */ 182 | public static ArrayList splitText(String text, String split) { 183 | 184 | return splitText(text, split, false); 185 | } 186 | 187 | /** 188 | * 将文本根据指定的字符串分割成字符串集合 189 | * 190 | * @param text 191 | * @param split 192 | * @return 193 | */ 194 | public static ArrayList splitText(String text, String split, boolean filterEmpty) { 195 | 196 | ArrayList list = new ArrayList(); 197 | 198 | if (TextUtil.isEmpty(text)) 199 | return list; 200 | 201 | String[] array = text.split(TextUtil.filterNull(split)); 202 | if (array == null || array.length == 0) 203 | return list; 204 | 205 | for (int i = 0; i < array.length; i++) { 206 | 207 | if (filterEmpty) { 208 | 209 | if (!TextUtil.isEmptyTrim(array[i])) 210 | list.add(array[i]); 211 | } else { 212 | 213 | list.add(array[i]); 214 | } 215 | } 216 | 217 | return list; 218 | } 219 | 220 | /** 221 | * 根据集合拼成指定分隔符分隔的字符串 222 | * 223 | * @param texts 224 | * @param split 225 | * @return 226 | */ 227 | public static String getText(List texts, String split) { 228 | 229 | if (isEmpty(texts)) 230 | return TextUtil.TEXT_EMPTY; 231 | 232 | StringBuilder sb = new StringBuilder(); 233 | 234 | for (int i = 0; i < texts.size(); i++) { 235 | 236 | if (i > 0) 237 | sb.append(split); 238 | 239 | sb.append(texts.get(i)); 240 | } 241 | 242 | return sb.toString(); 243 | } 244 | 245 | /** 246 | * 判断数组是否为空 247 | * 248 | * @param array 249 | * @return 250 | */ 251 | public static boolean isEmpty(T[] array) { 252 | 253 | return array == null || array.length == 0; 254 | } 255 | 256 | /** 257 | * 返回数组的大小,null数组返回0 258 | * 259 | * @param array 260 | * @return 261 | */ 262 | public static int size(T[] array) { 263 | 264 | return array == null ? 0 : array.length; 265 | } 266 | 267 | /** 268 | * 判断position是否在数组长度范围内 269 | * 270 | * @param array 271 | * @param position 272 | * @return 273 | */ 274 | public static boolean checkPosition(T[] array, int position) { 275 | 276 | return position >= 0 && position < size(array); 277 | } 278 | 279 | /** 280 | * 做下标越界判断,如果越界返回null 281 | * 282 | * @param array 283 | * @param position 284 | * @param 285 | * @return 286 | */ 287 | public static T getItem(T[] array, int position) { 288 | 289 | return checkPosition(array, position) ? array[position] : null; 290 | } 291 | 292 | /** 293 | * 截取子集,该函数会对集合和索引做边界判断 294 | * 如果endIndex超出长度,则会截取到末尾 295 | * 296 | * @param list 297 | * @param startIndex 298 | * @param endIndex 299 | * @param 300 | * @return 301 | */ 302 | public static List subList(List list, int startIndex, int endIndex) { 303 | 304 | if (CollectionUtil.isEmpty(list)) 305 | return list; 306 | 307 | if (startIndex < 0) 308 | startIndex = 0; 309 | 310 | if (startIndex > list.size()) 311 | startIndex = list.size(); 312 | 313 | if (endIndex < 0) 314 | endIndex = 0; 315 | 316 | if (endIndex > list.size()) 317 | endIndex = list.size(); 318 | 319 | if (startIndex > endIndex) 320 | startIndex = endIndex; 321 | 322 | return list.subList(startIndex, endIndex); 323 | } 324 | 325 | /** 326 | * 比较两个集合是否相同 327 | * 328 | * @param c1 329 | * @param c2 330 | * @return 331 | */ 332 | public static boolean equals(Collection c1, Collection c2) { 333 | 334 | if (c1 == null || c2 == null) 335 | return false; 336 | 337 | return c1.equals(c2); 338 | } 339 | 340 | /** 341 | * 循环 342 | * 343 | * @param data 344 | * @param target 345 | * @param handleAbort 346 | * @param lisn 347 | * @param 348 | * @param 349 | * @return 350 | */ 351 | public static boolean forLoop(List data, K target, boolean handleAbort, ForLoopListener lisn) { 352 | 353 | if (isEmpty(data) || lisn == null) 354 | return false; 355 | 356 | boolean result = false; 357 | for (int i = 0; i < data.size(); i++) { 358 | 359 | if (lisn.onItem(i, data.get(i), target)) { 360 | 361 | result = true; 362 | if (handleAbort) 363 | break; 364 | } 365 | } 366 | 367 | return result; 368 | } 369 | 370 | public static void addAll(List sources, List addList) { 371 | 372 | if(CollectionUtil.isEmpty(addList)) 373 | return; 374 | 375 | sources.addAll(addList); 376 | } 377 | 378 | public static interface ForLoopListener { 379 | 380 | boolean onItem(int index, T item, K target); 381 | } 382 | } 383 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/util/DensityUtil.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.util; 2 | 3 | import com.zkteam.discover.app.BaseApp; 4 | 5 | /** 6 | * dp px 转换工具类 7 | */ 8 | public class DensityUtil { 9 | 10 | private static float scale = BaseApp.getContext().getResources().getDisplayMetrics().density; 11 | 12 | /** 13 | * dp 转 px 14 | * @param dpValue 15 | * @return 16 | */ 17 | public static int dip2px(float dpValue) { 18 | 19 | return (int) (dpValue * scale + 0.5f); 20 | } 21 | 22 | /** 23 | * px 转 dp 24 | * @param pxValue 25 | * @return 26 | */ 27 | public static int px2dip(float pxValue) { 28 | 29 | return (int) (pxValue / scale + 0.5f); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/util/DeviceUtil.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.util; 2 | 3 | import android.app.Activity; 4 | import android.app.ActivityManager; 5 | import android.app.ActivityManager.RunningAppProcessInfo; 6 | import android.app.KeyguardManager; 7 | import android.content.Context; 8 | import android.graphics.Rect; 9 | import android.os.Build; 10 | import android.text.TextUtils; 11 | import android.view.WindowManager; 12 | 13 | import com.zkteam.discover.app.BaseApp; 14 | 15 | import java.net.InetAddress; 16 | import java.net.NetworkInterface; 17 | import java.util.Enumeration; 18 | import java.util.List; 19 | 20 | import static android.content.Context.KEYGUARD_SERVICE; 21 | 22 | /** 23 | * 设备信息获取工具类 24 | */ 25 | public class DeviceUtil { 26 | 27 | private static int mScreenWidth; 28 | private static int mScreenHeight; 29 | 30 | /** 31 | * 获取设备屏幕宽度 32 | * 33 | * @return 34 | */ 35 | public static int getScreenWidth() { 36 | 37 | if (mScreenWidth == 0) 38 | mScreenWidth = BaseApp.getContext().getResources().getDisplayMetrics().widthPixels; 39 | 40 | return mScreenWidth; 41 | } 42 | 43 | /** 44 | * 获取设备屏幕高度 45 | * 46 | * @return 47 | */ 48 | public static int getScreenHeight() { 49 | 50 | if (mScreenHeight == 0) 51 | mScreenHeight = BaseApp.getContext().getResources().getDisplayMetrics().heightPixels; 52 | 53 | return mScreenHeight; 54 | } 55 | 56 | /** 57 | * 获取当前activity 状态栏高度 58 | * 59 | * @param activity 60 | * @return 61 | */ 62 | public static int getStatusBarHeightByFrame(Activity activity) { 63 | 64 | Rect frame = new Rect(); 65 | activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); 66 | return frame.top; 67 | } 68 | 69 | /** 70 | * 设置状态栏颜色 71 | * 72 | * @param activity 73 | * @param color 74 | */ 75 | public static void setStatusBarColor(Activity activity, int color) { 76 | 77 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 78 | activity.getWindow().setStatusBarColor(color); 79 | } 80 | 81 | /** 82 | * 设置状态栏颜色资源 83 | * 84 | * @param activity 85 | * @param colorResId 86 | */ 87 | public static void setStatusBarColorResource(Activity activity, int colorResId) { 88 | 89 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 90 | activity.getWindow().setStatusBarColor(activity.getResources().getColor(colorResId)); 91 | } 92 | 93 | /** 94 | * 设置状态栏透明 95 | * 96 | * @param activity 97 | * @param translucent 98 | * @return 99 | */ 100 | public static boolean setStatusBarTranslucent(Activity activity, boolean translucent, boolean kitkatEnable) { 101 | 102 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) 103 | return false; 104 | 105 | try { 106 | 107 | //umeng日志中,在某些机型上,addFlags函数会报 108 | // java.lang.SecurityException: No permission to prevent power key: 109 | // Neither user 10069 nor current process has android.permission.PREVENT_POWER_KEY 110 | //所以这里做了简单的try catch 处理 111 | if (kitkatEnable || Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 112 | 113 | if (translucent) { 114 | 115 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 116 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 117 | } else { 118 | 119 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 120 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 121 | } 122 | 123 | return true; 124 | } 125 | 126 | } catch (Exception e) { 127 | 128 | e.printStackTrace(); 129 | } 130 | 131 | return false; 132 | } 133 | 134 | /** 135 | * 获取设备型号 136 | * 137 | * @return 138 | */ 139 | public static String getDeviceType() { 140 | 141 | return TextUtil.filterNull(Build.MODEL); 142 | } 143 | 144 | /** 145 | * 获取系统版本信息 146 | * 147 | * @return 148 | */ 149 | public static String getOsVersion() { 150 | 151 | return TextUtil.filterNull(Build.VERSION.RELEASE); 152 | } 153 | 154 | /** 155 | * 获取系统能给当前能给app分配的最大内存 156 | * 157 | * @return 158 | */ 159 | public static long getRuntimeMaxMemory() { 160 | 161 | return Runtime.getRuntime().maxMemory(); 162 | } 163 | 164 | /** 165 | * 获取本机ip地址 166 | * 167 | * @return 168 | */ 169 | public static String getLocalIpAddress() { 170 | 171 | try { 172 | 173 | for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { 174 | 175 | NetworkInterface intf = en.nextElement(); 176 | for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { 177 | 178 | InetAddress inetAddress = enumIpAddr.nextElement(); 179 | if (!inetAddress.isLoopbackAddress()) { 180 | return inetAddress.getHostAddress().toString(); 181 | } 182 | } 183 | } 184 | } catch (Throwable t) { 185 | 186 | } 187 | 188 | return TextUtil.TEXT_EMPTY; 189 | } 190 | 191 | /** 192 | * 获取设备品牌 193 | * 194 | * @return 195 | */ 196 | public static String getBrand() { 197 | 198 | return TextUtil.filterNull(Build.BRAND); 199 | } 200 | 201 | public static String getBrandAndModel() { 202 | 203 | return Build.BRAND + "_" + Build.MODEL; 204 | } 205 | 206 | public static boolean isOppoBrand() { 207 | 208 | return isBrand("oppo"); 209 | } 210 | 211 | public static boolean isVivoBrand() { 212 | 213 | return isBrand("vivo"); 214 | } 215 | 216 | public static boolean isXiaoMiBrand() { 217 | 218 | return isBrand("xiaomi"); 219 | } 220 | 221 | public static boolean isHuaWei() { 222 | 223 | return isBrand("huawei"); 224 | } 225 | 226 | public static boolean isMeizu() { 227 | 228 | return isBrand("meizu"); 229 | } 230 | 231 | private static boolean isBrand(String brand) { 232 | 233 | return TextUtil.filterNull(Build.BRAND).toLowerCase().contains(brand); 234 | } 235 | 236 | 237 | /** 238 | * @param context 239 | * @return false:表示未锁屏 240 | */ 241 | public static boolean isLockScreen(Context context) { 242 | 243 | try { 244 | 245 | KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); 246 | return keyguardManager.inKeyguardRestrictedInputMode(); 247 | 248 | } catch (Throwable t) { 249 | 250 | return false; 251 | } 252 | } 253 | 254 | 255 | /** 256 | * 判断应用是否是在后台 257 | */ 258 | public static boolean isAppInBackground(Context context) { 259 | ActivityManager activityManager = (ActivityManager) context 260 | .getSystemService(Context.ACTIVITY_SERVICE); 261 | KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(KEYGUARD_SERVICE); 262 | 263 | List appProcesses = activityManager 264 | .getRunningAppProcesses(); 265 | for (RunningAppProcessInfo appProcess : appProcesses) { 266 | if (TextUtils.equals(appProcess.processName, context.getPackageName())) { 267 | boolean isBackground = (appProcess.importance != RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.importance != RunningAppProcessInfo.IMPORTANCE_VISIBLE); 268 | boolean isLockedState = keyguardManager.inKeyguardRestrictedInputMode(); 269 | return isBackground || isLockedState; 270 | } 271 | } 272 | return false; 273 | } 274 | 275 | } 276 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/util/DimenConstant.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.util; 2 | 3 | public interface DimenConstant { 4 | 5 | int SCREEN_WIDTH = DeviceUtil.getScreenWidth(); 6 | int SCREEN_HEIGHT = DeviceUtil.getScreenHeight(); 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/util/DiscoverIndexUtil.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.util; 2 | 3 | 4 | import com.zkteam.discover.bean.ChildrenOpers; 5 | import com.zkteam.discover.bean.DiscoverOper; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | 11 | /** 12 | * =========================================================== 13 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 14 | * 邮 箱:18810474975@163.com 15 | * 版 本: 16 | * 创建日期:2018/3/1 下午2:53 17 | * 描 述: 18 | * 修订历史: 19 | * =========================================================== 20 | */ 21 | public class DiscoverIndexUtil { 22 | 23 | /** 24 | * 过滤 WebView列表和Banner列表为null 情况 25 | * 26 | * @param opers 27 | */ 28 | public static void filterNullOperList(List opers) { 29 | 30 | if (CollectionUtil.isEmpty(opers)) 31 | return; 32 | 33 | Iterator iter = opers.iterator(); 34 | while (iter.hasNext()) { 35 | 36 | if (isFilterNullOper(iter.next())) 37 | iter.remove(); 38 | } 39 | } 40 | 41 | /** 42 | * 过滤为NULL 运营位 43 | * 44 | * @param discoverOper 45 | * @return 46 | */ 47 | private static boolean isFilterNullOper(DiscoverOper discoverOper) { 48 | 49 | if (discoverOper == null) 50 | return true; 51 | 52 | ChildrenOpers childrenOpers = discoverOper.getChildren(); 53 | if (childrenOpers == null) 54 | return true; 55 | 56 | return CollectionUtil.isEmpty(childrenOpers.getWebview()) && (CollectionUtil.isEmpty(childrenOpers.getBanner())); 57 | } 58 | 59 | /** 60 | * 处理 右侧运营位 合并数据 61 | * 62 | * @param opers 63 | */ 64 | public static List merageOperLevel2List(List opers) { 65 | 66 | if (opers == null) 67 | return null; 68 | 69 | List merageOpers = new ArrayList(); 70 | for (int i = 0; i < CollectionUtil.size(opers); i++) { 71 | 72 | DiscoverOper oper = CollectionUtil.getItem(opers, i); 73 | if (oper == null) 74 | continue; 75 | 76 | ChildrenOpers childrenOpers = oper.getChildren(); 77 | if (childrenOpers == null) 78 | continue; 79 | 80 | oper.setElement_type(DiscoverOper.TYPE_TITLE); 81 | oper.setParentTitle(oper.getTitle()); 82 | oper.setParentPosition(i); 83 | oper.setChildPosition(i); 84 | oper.setParentId(oper.getElement_id()); 85 | merageOpers.add(oper); 86 | 87 | List operWebViews = childrenOpers.getWebview(); // WebView 88 | // 模拟数据 89 | operWebViews.addAll(childrenOpers.getWebview()); 90 | operWebViews.addAll(childrenOpers.getWebview()); 91 | for (int j = 0; j < CollectionUtil.size(operWebViews); j++) { 92 | 93 | DiscoverOper webViewOper = operWebViews.get(j); 94 | webViewOper.setParentTitle(oper.getTitle()); 95 | webViewOper.setParentPosition(i); 96 | webViewOper.setChildPosition(j); 97 | webViewOper.setParentId(oper.getElement_id()); 98 | merageOpers.add(webViewOper); 99 | } 100 | 101 | List operBanners = childrenOpers.getBanner(); // Banner 102 | // 模拟数据 103 | operBanners.addAll(childrenOpers.getBanner()); 104 | operBanners.addAll(childrenOpers.getBanner()); 105 | for (int k = 0; k < CollectionUtil.size(operBanners); k++) { 106 | 107 | DiscoverOper bannerOper = operBanners.get(k); 108 | bannerOper.setParentTitle(oper.getTitle()); 109 | bannerOper.setParentPosition(i); 110 | bannerOper.setChildPosition(k); 111 | bannerOper.setParentId(oper.getElement_id()); 112 | merageOpers.add(bannerOper); 113 | } 114 | } 115 | return merageOpers; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/util/FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.util; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileOutputStream; 7 | import java.io.ObjectInputStream; 8 | import java.io.ObjectOutputStream; 9 | import java.io.RandomAccessFile; 10 | import java.nio.channels.FileChannel; 11 | 12 | /** 13 | * 文件操作工具类 14 | */ 15 | public class FileUtil { 16 | 17 | /** 18 | * 判断文件或目录是否存在 19 | * @param f 20 | * @return 21 | */ 22 | public static boolean checkExists(File f){ 23 | 24 | return f == null ? false : f.exists(); 25 | } 26 | 27 | /** 28 | * 检查指定目录是否存在,如果不存在则创建 29 | * @param dir 30 | */ 31 | public static boolean ensureDirExists(String dir) { 32 | 33 | if(TextUtil.isEmpty(dir)) 34 | return false; 35 | 36 | return ensureDirExists(new File(dir)); 37 | } 38 | 39 | /** 40 | * 检查指定目录是否存在,如果不存在则创建 41 | * @param dir 42 | * @return 43 | */ 44 | public static boolean ensureDirExists(File dir){ 45 | 46 | if(dir != null && dir.isDirectory()){ 47 | 48 | return dir.exists() ? true : dir.mkdirs(); 49 | }else{ 50 | 51 | return false; 52 | } 53 | } 54 | 55 | /** 56 | * 删除指定File,支持目录和文件 57 | * @param file 58 | */ 59 | public static void deleteFile(File file) { 60 | 61 | if(file == null || !file.exists()) 62 | return; 63 | 64 | if (file.isFile()) { 65 | 66 | file.delete(); 67 | } else { 68 | 69 | File[] files = file.listFiles(); 70 | 71 | if(files != null && files.length > 0){ 72 | 73 | for (File f : files) { 74 | 75 | deleteFile(f);// 递归删除每一个文件 76 | } 77 | } 78 | 79 | file.delete();// 删除该文件夹 80 | } 81 | } 82 | 83 | /** 84 | * 获取指定文件大小,支持文件和目录 85 | * @param file 86 | * @return 87 | */ 88 | public static long getSize(File file){ 89 | 90 | if(file == null || !file.exists()) 91 | return 0; 92 | 93 | if(file.isFile()){ 94 | 95 | return file.length(); 96 | }else{ 97 | 98 | long total = 0; 99 | 100 | File[] files = file.listFiles(); 101 | if(files != null){ 102 | 103 | for(int i=0; i() { 337 | 338 | @Override 339 | protected Void doInBackground(Void... params) { 340 | 341 | try { 342 | 343 | if(dir.exists()) 344 | FileUtil.deleteFile(dir); 345 | 346 | } catch (Throwable e) { 347 | 348 | } 349 | 350 | return null; 351 | } 352 | 353 | }.execute(); 354 | } 355 | 356 | public static void asyncCreateNomediaFileInHomeDir() { 357 | 358 | 359 | new AsyncTask() { 360 | 361 | @Override 362 | protected Void doInBackground(Void... params) { 363 | 364 | try { 365 | 366 | File noMediaFile = new File(getAppHomeDir(), ".nomedia"); 367 | if (!noMediaFile.exists()) 368 | noMediaFile.createNewFile(); 369 | 370 | } catch (IOException e) { 371 | 372 | } 373 | 374 | return null; 375 | } 376 | 377 | }.execute(); 378 | 379 | } 380 | } -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/util/TextUtil.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.util; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * 文本工具类 8 | */ 9 | public class TextUtil { 10 | 11 | public static final String TEXT_EMPTY = ""; 12 | public static final String TEXT_NULL = "null"; 13 | public static final String TEXT_ZERO = "0"; 14 | 15 | /** 16 | * 将字符序列转成字符串对象 17 | * @param charSequence 18 | * @return 19 | */ 20 | public static String toString(CharSequence charSequence){ 21 | 22 | return charSequence == null ? TextUtil.TEXT_EMPTY : charSequence.toString(); 23 | } 24 | 25 | /** 26 | * 过滤空串 27 | * @param str 28 | * @return 29 | */ 30 | public static String filterNull(String str){ 31 | 32 | return str == null ? TEXT_EMPTY : str; 33 | } 34 | 35 | /** 36 | * 将空串过滤为0 37 | * @param str 38 | * @return 39 | */ 40 | public static String filterEmptyZero(String str){ 41 | 42 | return filterEmpty(str, TEXT_ZERO); 43 | } 44 | 45 | /** 46 | * 如果str为空或空串,则返回默认值 47 | * @param str 48 | * @param defStr 49 | * @return 50 | */ 51 | public static String filterEmpty(String str, String defStr){ 52 | 53 | return isEmpty(str) ? defStr : str; 54 | } 55 | 56 | /** 57 | * 过滤trim后的字符串 58 | * @param str 59 | * @return 60 | */ 61 | public static String filterTrim(String str){ 62 | 63 | return str == null ? TEXT_EMPTY : str.trim(); 64 | } 65 | 66 | /** 67 | * 过滤trim后的字符串,如果串为空,则返回默认值 68 | * @param str 69 | * @param defStr 70 | * @return 71 | */ 72 | public static String filterTrim(String str, String defStr){ 73 | 74 | return isEmptyTrim(str) ? defStr : str; 75 | } 76 | 77 | /** 78 | * 比较两个字符串 79 | * @param str1 80 | * @param str2 81 | * @return 82 | */ 83 | public static boolean equalsText(String str1, String str2){ 84 | 85 | if(str1 == null && str2 == null){ 86 | 87 | return true; 88 | }else if(str1 != null && str2 != null){ 89 | 90 | return str1.equals(str2); 91 | }else{ 92 | 93 | return false; 94 | } 95 | } 96 | 97 | /** 98 | * 判断文本是否为空 99 | * @param str 100 | * @return 101 | */ 102 | public static boolean isEmpty(CharSequence str) { 103 | 104 | if (str == null || str.length() == 0) 105 | return true; 106 | else 107 | return false; 108 | } 109 | 110 | /** 111 | * 返回字符序列长度 112 | * @param chars 113 | * @return 114 | */ 115 | public static int size(CharSequence chars){ 116 | 117 | return chars == null ? 0 : chars.length(); 118 | } 119 | 120 | /** 121 | * 返回字符串trim后的size 122 | * @param str 123 | * @return 124 | */ 125 | public static int trimSize(String str){ 126 | 127 | return str == null ? 0 : str.trim().length(); 128 | } 129 | 130 | /** 131 | * 判断是否为0 132 | * @param str 133 | * @return 134 | */ 135 | public static boolean isZero(String str){ 136 | 137 | return TEXT_ZERO.equals(str); 138 | } 139 | 140 | /** 141 | * 判断trim后的文本是否为空 142 | * @param str 143 | * @return 144 | */ 145 | public static boolean isEmptyTrim(String str) { 146 | 147 | if (str == null || str.trim().length() == 0) 148 | return true; 149 | else 150 | return false; 151 | } 152 | 153 | /** 154 | * 判断str是否是数字组成的 155 | * @param str 156 | * @return 157 | */ 158 | public static boolean isNumeric(String str) { 159 | 160 | if(TextUtil.isEmpty(str)) 161 | return false; 162 | 163 | Pattern pattern = Pattern.compile("[0-9]+"); 164 | return pattern.matcher(str).matches(); 165 | } 166 | 167 | /** 168 | * 判断text是否是小数 169 | * @param text 170 | * @return 171 | */ 172 | public static boolean isDecimal(String text){ 173 | 174 | if(TextUtil.isEmpty(text)) 175 | return false; 176 | 177 | Pattern pattern = Pattern.compile("^[0-9]+(\\.[0-9]+)?$"); 178 | return pattern.matcher(text).matches(); 179 | } 180 | 181 | /** 182 | * 从文本中截取小数,如果有多个匹配,则取第一个,无匹配返回空串 183 | * @param text 184 | * @return 185 | */ 186 | public static String parseDecimalText(String text){ 187 | 188 | if(TextUtil.isEmpty(text)) 189 | return TextUtil.TEXT_EMPTY; 190 | 191 | Pattern pattern = Pattern.compile("[0-9]+(\\.[0-9]+)?"); 192 | Matcher matcher = pattern.matcher(text); 193 | while(matcher.find()){ 194 | 195 | return matcher.group(); 196 | } 197 | 198 | return TextUtil.TEXT_EMPTY; 199 | } 200 | 201 | /** 202 | * 验证手机号 203 | * 判断规则有过时的危险 204 | * @param str 205 | * @return 206 | */ 207 | public static boolean isMobile(CharSequence str) { 208 | 209 | if(isEmpty(str)) 210 | return false; 211 | 212 | Pattern p = Pattern.compile("^[1][3-9][0-9]{9}$"); 213 | Matcher m = p.matcher(str); 214 | return m.matches(); 215 | } 216 | 217 | public static String filterTklTitle(String searchKey) { 218 | 219 | String word = searchKey; 220 | if (TextUtil.isTaobaoTkl(searchKey)) 221 | word = getTaobaoTklTitle(searchKey); 222 | 223 | return word; 224 | } 225 | 226 | public static String getTaobaoTklTitle(String searchKey) { 227 | 228 | Pattern pattern = Pattern.compile("(?<=【).*?(?=】)"); 229 | Matcher matcher = pattern.matcher(searchKey); 230 | 231 | if (matcher.find()) 232 | return matcher.group(); 233 | else 234 | return searchKey; 235 | } 236 | 237 | /** 238 | * 是否为淘口令 239 | * 240 | * @param str 241 | * @return 242 | */ 243 | public static boolean isTaobaoTkl(CharSequence str) { 244 | 245 | if(isEmpty(str)) 246 | return false; 247 | 248 | Pattern p = Pattern.compile("[《,¥][0-9,a-z,A-Z]{5,20}[《,¥]"); 249 | Matcher m = p.matcher(str); 250 | return m.find(); 251 | } 252 | 253 | /** 254 | * 检查邮箱格式是否正确 255 | * @param email 256 | * @return 257 | */ 258 | public static boolean checkMail(String email) { 259 | 260 | if(TextUtil.isEmpty(email)) 261 | return false; 262 | 263 | Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"); 264 | Matcher m = p.matcher(email); 265 | return m.find(); 266 | } 267 | 268 | /** 269 | * 按照新浪微博的规则统计字符数 270 | * 好像不是特别准确 271 | * @param c 272 | * @return 273 | */ 274 | public static int calculateWeiboLength(CharSequence c) { 275 | 276 | double len = 0; 277 | for (int i = 0; i < c.length(); i++) { 278 | 279 | int temp = (int) c.charAt(i); 280 | if (temp > 0 && temp < 127) { 281 | 282 | len += 0.5; 283 | } else { 284 | 285 | len++; 286 | } 287 | } 288 | return (int) Math.round(len); 289 | } 290 | 291 | /** 292 | * 判断文本是否包含中文 293 | * @param text 294 | * @return 295 | */ 296 | public static boolean isContainsChinese(CharSequence text){ 297 | 298 | if(isEmpty(text)) 299 | return false; 300 | 301 | for (int i=0; i 0) 356 | sb.append(split); 357 | 358 | sb.append(intArray[i]); 359 | } 360 | 361 | return sb.toString(); 362 | } 363 | 364 | /** 365 | * 过滤字符中的emoji表情,不能保证全部过滤 366 | * @param text 367 | * @return 368 | */ 369 | public static String filterEmoji(String text){ 370 | 371 | if(isEmpty(text)) 372 | return text; 373 | 374 | try{ 375 | 376 | return text.replaceAll("[\\ud83c\\udc00-\\ud83c\\udfff]|[\\ud83d\\udc00-\\ud83d\\udfff]|[\\u2600-\\u27ff]", TEXT_EMPTY); 377 | 378 | }catch(Throwable t){ 379 | 380 | } 381 | 382 | return text; 383 | } 384 | 385 | /** 386 | * 手机号码加* 387 | * @param phoneNum 388 | * @return 389 | */ 390 | public static String getSecretPhoneNum(String phoneNum){ 391 | 392 | phoneNum = TextUtil.filterNull(phoneNum); 393 | return phoneNum.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); 394 | } 395 | 396 | /** 397 | * 自动转换字符空串 398 | * 且保证 start end 在字符串指定范围内 399 | * @param str 400 | * @param start 401 | * @param end 402 | * @return 403 | */ 404 | public static String subStringFilter(String str, int start, int end){ 405 | 406 | str = filterNull(str); 407 | 408 | if(start < 0) 409 | start = 0; 410 | 411 | if(start > str.length() - 1) 412 | start = str.length() - 1; 413 | 414 | if(end < 0) 415 | end = 0; 416 | 417 | if(end > str.length()) 418 | end = str.length(); 419 | 420 | return str.substring(start, end); 421 | 422 | } 423 | } 424 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/util/ViewUtil.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.util; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.drawable.BitmapDrawable; 8 | import android.graphics.drawable.ColorDrawable; 9 | import android.graphics.drawable.Drawable; 10 | import android.os.Build; 11 | import android.support.v4.view.ViewPager; 12 | import android.text.Layout; 13 | import android.text.StaticLayout; 14 | import android.text.TextPaint; 15 | import android.view.Gravity; 16 | import android.view.View; 17 | import android.view.ViewGroup; 18 | import android.view.ViewTreeObserver; 19 | import android.widget.AbsListView; 20 | import android.widget.ExpandableListView; 21 | import android.widget.FrameLayout; 22 | import android.widget.ImageView; 23 | import android.widget.ListView; 24 | import android.widget.Scroller; 25 | import android.widget.TextView; 26 | import java.lang.reflect.Field; 27 | import java.lang.reflect.InvocationTargetException; 28 | import java.lang.reflect.Method; 29 | 30 | /** 31 | * view工具类 32 | */ 33 | public class ViewUtil { 34 | 35 | public static void scaleLayoutParams(View view, float measureW, float measureH, int scaleW, int defScaleH) { 36 | 37 | if (view == null) 38 | return; 39 | 40 | int scaleH; 41 | if (measureW > 0 && measureH > 0) 42 | scaleH = (int) (scaleW * (measureH / measureW)); 43 | else 44 | scaleH = defScaleH; 45 | 46 | ViewGroup.LayoutParams vglp = view.getLayoutParams(); 47 | if (vglp.width != scaleW || vglp.height != scaleH) { 48 | 49 | vglp.width = scaleW; 50 | vglp.height = scaleH; 51 | view.setLayoutParams(vglp); 52 | } 53 | } 54 | 55 | public static void scaleLayoutParamsByH(View view, float measureW, float measureH, int scaleH, int defScaleW){ 56 | 57 | if (view == null) 58 | return; 59 | 60 | int scaleW; 61 | if (measureW > 0 && measureH > 0) 62 | scaleW = (int) (scaleH * (measureW / measureH)); 63 | else 64 | scaleW = defScaleW; 65 | 66 | ViewGroup.LayoutParams vglp = view.getLayoutParams(); 67 | if (vglp.width != scaleW || vglp.height != scaleH) { 68 | 69 | vglp.width = scaleW; 70 | vglp.height = scaleH; 71 | view.setLayoutParams(vglp); 72 | } 73 | } 74 | 75 | public static void addOnGlobalLayoutListener(View view, ViewTreeObserver.OnGlobalLayoutListener lisn) { 76 | 77 | if (view != null && lisn != null) 78 | view.getViewTreeObserver().addOnGlobalLayoutListener(lisn); 79 | } 80 | 81 | /** 82 | * 移除指定view的layout改变监听 83 | * 84 | * @param view 85 | * @param lisn 86 | */ 87 | public static void removeOnGlobalLayoutListener(View view, ViewTreeObserver.OnGlobalLayoutListener lisn) { 88 | 89 | if (view == null || lisn == null) 90 | return; 91 | 92 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) 93 | view.getViewTreeObserver().removeOnGlobalLayoutListener(lisn); 94 | else 95 | view.getViewTreeObserver().removeGlobalOnLayoutListener(lisn); 96 | } 97 | 98 | /** 99 | * 设置文本文字颜色选择器 100 | * 101 | * @param tv 102 | * @param colorStateResId 103 | */ 104 | public static void setTextColorState(TextView tv, int colorStateResId) { 105 | 106 | if (tv == null) 107 | return; 108 | 109 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 110 | tv.setTextColor(tv.getContext().getColorStateList(colorStateResId)); 111 | else 112 | tv.setTextColor(tv.getContext().getResources().getColorStateList(colorStateResId)); 113 | } 114 | 115 | /** 116 | * 设置view的背景资源 117 | * 118 | * @param v 119 | * @param drawable 120 | */ 121 | public static void setViewBackground(View v, Drawable drawable) { 122 | 123 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) 124 | v.setBackground(drawable); 125 | else 126 | v.setBackgroundDrawable(drawable); 127 | } 128 | 129 | /** 130 | * 判断textview是否为空 131 | * 132 | * @param tv 133 | * @return 134 | */ 135 | public static boolean checkTextViewEmpty(TextView tv) { 136 | 137 | if (tv == null) 138 | return true; 139 | 140 | CharSequence text = tv.getText(); 141 | return text == null ? true : text.length() == 0; 142 | } 143 | 144 | /** 145 | * 判断textview trim() 后是否为空 146 | * 147 | * @param tv 148 | * @return 149 | */ 150 | public static boolean checkTextViewTrimEmpty(TextView tv) { 151 | 152 | if (tv == null) 153 | return true; 154 | 155 | String text = tv.getText().toString(); 156 | return text == null ? true : text.trim().length() == 0; 157 | } 158 | 159 | /** 160 | * 获取textview的文本 161 | * 162 | * @param tv 163 | * @return 164 | */ 165 | public static String getTextViewText(TextView tv) { 166 | 167 | if (tv == null) 168 | return TextUtil.TEXT_EMPTY; 169 | 170 | String text = tv.getText().toString(); 171 | return text == null ? TextUtil.TEXT_EMPTY : text; 172 | } 173 | 174 | /** 175 | * 获取textview trim() 后的文本 176 | * 177 | * @param tv 178 | * @return 179 | */ 180 | public static String getTextViewTrimText(TextView tv) { 181 | 182 | if (tv == null) 183 | return TextUtil.TEXT_EMPTY; 184 | 185 | String text = tv.getText().toString(); 186 | return text == null ? TextUtil.TEXT_EMPTY : text.trim(); 187 | } 188 | 189 | /** 190 | * 获取textView 过滤全部空格 包括首尾,中间 191 | * 192 | * @param tv 193 | * @return 194 | */ 195 | public static String getTextViewFilterTrimText(TextView tv) { 196 | 197 | if (tv == null) 198 | return TextUtil.TEXT_EMPTY; 199 | 200 | String text = tv.getText().toString(); 201 | return text == null ? TextUtil.TEXT_EMPTY : text.replaceAll(" ", TextUtil.TEXT_EMPTY); 202 | } 203 | 204 | /** 205 | * 获取imageview src bitmap对象 206 | * 207 | * @param iv 208 | * @return 209 | */ 210 | public static Bitmap getImageViewBitmap(ImageView iv) { 211 | 212 | if (iv == null) 213 | return null; 214 | 215 | if (iv.getDrawable() instanceof BitmapDrawable) 216 | return ((BitmapDrawable) iv.getDrawable()).getBitmap(); 217 | else 218 | return null; 219 | } 220 | 221 | /** 222 | * 显示view 223 | * 224 | * @param v 225 | * @return 226 | */ 227 | public static boolean showView(View v) { 228 | 229 | if (v == null) 230 | return false; 231 | 232 | if (v.getVisibility() == View.VISIBLE) { 233 | 234 | return false; 235 | } else { 236 | 237 | v.setVisibility(View.VISIBLE); 238 | return true; 239 | } 240 | } 241 | 242 | /** 243 | * 是否为显示状态(visible) 244 | * 245 | * @param v 246 | * @return 247 | */ 248 | public static boolean isShow(View v) { 249 | 250 | return v == null ? false : v.getVisibility() == View.VISIBLE; 251 | } 252 | 253 | /** 254 | * 隐藏view 255 | * 256 | * @param v 257 | * @return 258 | */ 259 | public static boolean hideView(View v) { 260 | 261 | if (v == null) 262 | return false; 263 | 264 | if (v.getVisibility() == View.INVISIBLE) { 265 | 266 | return false; 267 | } else { 268 | 269 | v.setVisibility(View.INVISIBLE); 270 | return true; 271 | } 272 | } 273 | 274 | /** 275 | * gone view 276 | * 277 | * @param v 278 | * @return 279 | */ 280 | public static boolean goneView(View v) { 281 | 282 | if (v == null) 283 | return false; 284 | 285 | if (v.getVisibility() == View.GONE) { 286 | 287 | return false; 288 | } else { 289 | 290 | v.setVisibility(View.GONE); 291 | return true; 292 | } 293 | } 294 | 295 | /** 296 | * 显示iamgeview, 并设置指定图片资源 297 | * 298 | * @param iv 299 | * @param imageResId 300 | */ 301 | public static void showImageView(ImageView iv, int imageResId) { 302 | 303 | if (iv.getVisibility() != View.VISIBLE) 304 | iv.setVisibility(View.VISIBLE); 305 | 306 | if (imageResId > 0) { 307 | 308 | iv.setImageResource(imageResId); 309 | } else { 310 | 311 | iv.setImageDrawable(null); 312 | } 313 | } 314 | 315 | /** 316 | * 显示iamgeview, 并设置指定drawable 317 | * 318 | * @param iv 319 | * @param drawable 320 | */ 321 | public static void showImageView(ImageView iv, Drawable drawable) { 322 | 323 | if (iv.getVisibility() != View.VISIBLE) 324 | iv.setVisibility(View.VISIBLE); 325 | 326 | iv.setImageDrawable(drawable); 327 | } 328 | 329 | /** 330 | * 隐藏imageview,并将图片资源清除掉 331 | * 332 | * @param iv 333 | */ 334 | public static void hideImageView(ImageView iv) { 335 | 336 | if (iv.getVisibility() != View.INVISIBLE) 337 | iv.setVisibility(View.INVISIBLE); 338 | 339 | iv.setImageDrawable(null); 340 | } 341 | 342 | /** 343 | * gone imageview,并将图片资源清除掉 344 | * 345 | * @param iv 346 | */ 347 | public static void goneImageView(ImageView iv) { 348 | 349 | if (iv.getVisibility() != View.GONE) 350 | iv.setVisibility(View.GONE); 351 | 352 | iv.setImageDrawable(null); 353 | } 354 | 355 | /** 356 | * 获取该view的快照 357 | * 358 | * @param v 359 | * @return 360 | */ 361 | public static Bitmap snapshot(View v) { 362 | 363 | Bitmap bmp = null; 364 | try { 365 | 366 | bmp = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); 367 | 368 | Canvas canvas = new Canvas(bmp); 369 | canvas.drawColor(Color.WHITE); 370 | v.draw(canvas); 371 | } catch (Throwable throwable) { 372 | 373 | throwable.printStackTrace(); 374 | } 375 | return bmp; 376 | } 377 | 378 | 379 | /** 380 | * 获取ListView,该ListView对公共的样式做了清除 381 | * 382 | * @param context 383 | * @return 384 | */ 385 | public static ListView getCleanListView(Context context, int id) { 386 | 387 | ListView lv = new ListView(context); 388 | lv.setId(id); 389 | lv.setDivider(null); 390 | lv.setDividerHeight(0); 391 | lv.setFooterDividersEnabled(false); 392 | lv.setHeaderDividersEnabled(false); 393 | lv.setSelector(new ColorDrawable(0X00000000)); 394 | lv.setFadingEdgeLength(0); 395 | lv.setScrollingCacheEnabled(false); 396 | lv.setVerticalScrollBarEnabled(false); 397 | lv.setOverScrollMode(View.OVER_SCROLL_NEVER); 398 | return lv; 399 | } 400 | 401 | /** 402 | * 获取ExpandListView,该ListView对公共的样式做了清除 403 | * 404 | * @param context 405 | * @return 406 | */ 407 | public static ExpandableListView getCleanExpandListView(Context context, int id) { 408 | 409 | ExpandableListView elv = new ExpandableListView(context); 410 | elv.setId(id); 411 | elv.setDividerHeight(0); 412 | elv.setDivider(null); 413 | elv.setFadingEdgeLength(0); 414 | elv.setFooterDividersEnabled(false); 415 | elv.setHeaderDividersEnabled(false); 416 | elv.setChildDivider(null); 417 | elv.setSelector(new ColorDrawable(0X00000000)); 418 | elv.setChildIndicator(null); 419 | elv.setGroupIndicator(null); 420 | elv.setScrollingCacheEnabled(false); 421 | elv.setVerticalScrollBarEnabled(false); 422 | elv.setOverScrollMode(View.OVER_SCROLL_NEVER); 423 | return elv; 424 | } 425 | 426 | /** 427 | * 获取FrameLayout 428 | * 429 | * @param context 430 | * @param id 431 | * @return 432 | */ 433 | public static FrameLayout getFrameLayout(Context context, int id) { 434 | 435 | FrameLayout fl = new FrameLayout(context); 436 | fl.setId(id); 437 | return fl; 438 | } 439 | 440 | /** 441 | * 通过反射设置ViewPager左右切换滑动时持续时间 442 | * 443 | * @param viewPager 444 | * @param setDuration 445 | */ 446 | public static void setViewPagerScrollDuration(ViewPager viewPager, final int setDuration) { 447 | 448 | try { 449 | 450 | Field mScroller = ViewPager.class.getDeclaredField("mScroller"); 451 | mScroller.setAccessible(true); 452 | mScroller.set(viewPager, new Scroller(viewPager.getContext()) { 453 | 454 | @Override 455 | public void startScroll(int startX, int startY, int dx, int dy, int duration) { 456 | 457 | super.startScroll(startX, startY, dx, dy, setDuration); 458 | } 459 | 460 | @Override 461 | public void startScroll(int startX, int startY, int dx, int dy) { 462 | 463 | super.startScroll(startX, startY, dx, dy, setDuration); 464 | } 465 | }); 466 | 467 | } catch (Throwable t) { 468 | 469 | t.printStackTrace(); 470 | } 471 | } 472 | 473 | /** 474 | * 测量view的高度,调用该方法后,可以知道view的高宽信息 475 | * 该方法有待验证!!! 476 | * 477 | * @param v 478 | */ 479 | public static void measureView(View v) { 480 | 481 | int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 482 | int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 483 | v.measure(w, h); 484 | } 485 | 486 | /** 487 | * 给ListView设置数据为空时的提示view 488 | * 489 | * @param listView 490 | * @param emptyView 491 | */ 492 | public static void setEmptyListView(ListView listView, View emptyView) { 493 | 494 | FrameLayout.LayoutParams param = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 495 | ViewGroup.LayoutParams.MATCH_PARENT); 496 | param.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; 497 | //param.topMargin = DensityUtil.dip2px(40f); 498 | ((ViewGroup) (listView.getParent())).addView(emptyView, param); 499 | 500 | listView.setEmptyView(emptyView); 501 | ViewUtil.hideView(emptyView); 502 | } 503 | 504 | /** 505 | * 获取view 所在屏幕的位置 506 | * 507 | * @param view 508 | * @return 509 | */ 510 | public static int[] getViewLocation(View view) { 511 | 512 | int[] size = new int[2]; 513 | view.getLocationInWindow(size); 514 | return size; 515 | } 516 | 517 | public static void setLeftDrawable(TextView textView, int resource) { 518 | 519 | if (textView != null) 520 | textView.setCompoundDrawablesWithIntrinsicBounds(resource, 0, 0, 0); 521 | } 522 | 523 | public static void setRightDrawable(TextView textView, int resource) { 524 | 525 | if (textView != null) 526 | textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, resource, 0); 527 | } 528 | 529 | public static void setTopDrawable(TextView textView, int resource) { 530 | 531 | if (textView != null) 532 | textView.setCompoundDrawablesWithIntrinsicBounds(0, resource, 0, 0); 533 | } 534 | 535 | public static void setBottomDrawable(TextView textView, int resource) { 536 | 537 | if (textView != null) 538 | textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, resource); 539 | } 540 | 541 | public static void setCompoundDrawable(TextView textView, int leftResId, int topResId, int rightResId, int btmResId) { 542 | 543 | if (textView != null) 544 | textView.setCompoundDrawablesWithIntrinsicBounds(leftResId, topResId, rightResId, btmResId); 545 | } 546 | 547 | /** 548 | * 清空ListView的缓存View 549 | * 550 | * @param lv 551 | */ 552 | public static void clearListViewRecyclerBin(AbsListView lv) { 553 | 554 | try { 555 | Field localField = AbsListView.class 556 | .getDeclaredField("mRecycler"); 557 | localField.setAccessible(true); 558 | Method localMethod = Class.forName( 559 | "android.widget.AbsListView$RecycleBin") 560 | .getDeclaredMethod("clear", new Class[0]); 561 | localMethod.setAccessible(true); 562 | localMethod.invoke(localField.get(lv), new Object[0]); 563 | 564 | } catch (NoSuchFieldException e1) { 565 | e1.printStackTrace(); 566 | } catch (ClassNotFoundException e2) { 567 | e2.printStackTrace(); 568 | } catch (NoSuchMethodException e3) { 569 | e3.printStackTrace(); 570 | } catch (IllegalAccessException e4) { 571 | e4.printStackTrace(); 572 | } catch (InvocationTargetException e5) { 573 | e5.printStackTrace(); 574 | } 575 | } 576 | 577 | /** 578 | * @param text 579 | * @param deviceWidth in pixels 580 | * @param padding in pixels 581 | * @return 582 | */ 583 | public static int measureTextLineCount(TextPaint myTextPaint, CharSequence text, int deviceWidth, int padding) { 584 | 585 | Layout.Alignment alignment = Layout.Alignment.ALIGN_NORMAL; 586 | 587 | float spacingMultiplier = 1; 588 | float spacingAddition = padding; 589 | boolean includePadding = padding != 0; 590 | if (text == null) 591 | text = TextUtil.TEXT_EMPTY; 592 | 593 | StaticLayout myStaticLayout = new StaticLayout(text, myTextPaint, deviceWidth, alignment, spacingMultiplier, spacingAddition, includePadding); 594 | return myStaticLayout.getLineCount(); 595 | } 596 | } 597 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/vh/DiscoverIndexLevel1ViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.vh; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | import android.widget.ImageView; 6 | import android.widget.RelativeLayout; 7 | import android.widget.TextView; 8 | 9 | import com.zkteam.discover.R; 10 | import com.zkteam.discover.base.ExRvItemViewHolderBase; 11 | import com.zkteam.discover.bean.Oper; 12 | import com.zkteam.discover.util.TextUtil; 13 | 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | 17 | /** 18 | * =========================================================== 19 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 20 | * 邮 箱:18810474975@163.com 21 | * 版 本: 22 | * 创建日期:2018/2/28 下午2:33 23 | * 描 述: 一级栏目ViewHolder 24 | * 修订历史: 25 | * =========================================================== 26 | */ 27 | public class DiscoverIndexLevel1ViewHolder extends ExRvItemViewHolderBase { 28 | 29 | @BindView(R.id.rlRoot) 30 | RelativeLayout mRlRoot; 31 | 32 | @BindView(R.id.tvName) 33 | TextView mTvName; 34 | 35 | @BindView(R.id.ivTip) 36 | ImageView mIvTip; 37 | 38 | public DiscoverIndexLevel1ViewHolder(ViewGroup viewGroup) { 39 | 40 | super(viewGroup, R.layout.page_discover_index_level1_vh); 41 | ButterKnife.bind(this, itemView); 42 | } 43 | 44 | 45 | @Override 46 | protected void initConvertView(View convertView) { 47 | 48 | convertView.setOnClickListener(this); 49 | } 50 | 51 | public void invalidateView(Oper oper, boolean isSelected) { 52 | 53 | mTvName.setText(oper == null ? TextUtil.TEXT_EMPTY : oper.getTitle()); 54 | if (isSelected) 55 | setSelectedStyle(); 56 | else 57 | setNormalStyle(); 58 | } 59 | 60 | public void setSelectedStyle() { 61 | 62 | // mIvTip.setVisibility(View.VISIBLE); 63 | mTvName.setTextColor(0XFFFF2A24); 64 | mTvName.setTextSize(13.4f); 65 | mRlRoot.setBackgroundColor(0XFFFFFF); 66 | } 67 | 68 | public void setNormalStyle() { 69 | 70 | // mIvTip.setVisibility(View.INVISIBLE); 71 | mTvName.setTextColor(0XFF444444); 72 | mTvName.setTextSize(12.5f); 73 | mRlRoot.setBackgroundColor(0XFFF6F6F6); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/vh/DiscoverIndexLevel2BannerViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.vh; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | import com.zkteam.discover.R; 7 | import com.zkteam.discover.base.ExRvItemViewHolderBase; 8 | import com.zkteam.discover.bean.Oper; 9 | import com.zkteam.discover.fresco.FrescoImageView; 10 | import com.zkteam.discover.util.DensityUtil; 11 | import com.zkteam.discover.util.ViewUtil; 12 | 13 | import butterknife.BindView; 14 | import butterknife.ButterKnife; 15 | 16 | /** 17 | * =========================================================== 18 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 19 | * 邮 箱:18810474975@163.com 20 | * 版 本: 21 | * 创建日期:2018/3/1 下午3:06 22 | * 描 述: 第二级banner图片运营位 23 | * 修订历史: 24 | * =========================================================== 25 | */ 26 | public class DiscoverIndexLevel2BannerViewHolder extends ExRvItemViewHolderBase { 27 | 28 | @BindView(R.id.fivCover) 29 | FrescoImageView mAivCover; 30 | 31 | private int mBannerWidth; 32 | 33 | public DiscoverIndexLevel2BannerViewHolder(ViewGroup viewGroup, int bannerWidth) { 34 | 35 | super(viewGroup, R.layout.page_discover_index_level2_vh_banner); 36 | ButterKnife.bind(this, itemView); 37 | mBannerWidth = bannerWidth; 38 | } 39 | 40 | @Override 41 | protected void initConvertView(View convertView) { 42 | 43 | convertView.setOnClickListener(this); 44 | } 45 | 46 | public void invalidateView(Oper oper) { 47 | 48 | if (oper == null) { 49 | 50 | mAivCover.setImageUri((String) null); 51 | } else { 52 | 53 | ViewUtil.scaleLayoutParams(mAivCover, oper.getPic_width(), oper.getPic_height(), mBannerWidth, DensityUtil.dip2px(80f)); 54 | mAivCover.setImageUriByLp(oper.getPic()); 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/vh/DiscoverIndexLevel2MiniViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.vh; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | import android.widget.TextView; 6 | 7 | import com.zkteam.discover.R; 8 | import com.zkteam.discover.base.ExRvItemViewHolderBase; 9 | import com.zkteam.discover.bean.Oper; 10 | import com.zkteam.discover.fresco.FrescoImageView; 11 | import com.zkteam.discover.util.TextUtil; 12 | 13 | import butterknife.BindView; 14 | import butterknife.ButterKnife; 15 | 16 | /** 17 | * =========================================================== 18 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 19 | * 邮 箱:18810474975@163.com 20 | * 版 本: 21 | * 创建日期:2018/2/28 下午7:59 22 | * 描 述:第二级mini小方块运营位 23 | * 修订历史: 24 | * =========================================================== 25 | */ 26 | public class DiscoverIndexLevel2MiniViewHolder extends ExRvItemViewHolderBase { 27 | 28 | @BindView(R.id.fivCover) 29 | FrescoImageView mFivCover; 30 | 31 | @BindView(R.id.tvName) 32 | TextView mTvName; 33 | 34 | public DiscoverIndexLevel2MiniViewHolder(ViewGroup viewGroup) { 35 | 36 | super(viewGroup, R.layout.page_discover_index_level2_vh_mini); 37 | ButterKnife.bind(this, itemView); 38 | } 39 | 40 | @Override 41 | protected void initConvertView(View convertView) { 42 | 43 | convertView.setOnClickListener(this); 44 | } 45 | 46 | public void invalidateView(Oper oper) { 47 | 48 | if (oper == null) { 49 | 50 | mTvName.setText(TextUtil.TEXT_EMPTY); 51 | mFivCover.setImageUriByLp((String) null); 52 | } else { 53 | 54 | mTvName.setText(oper.getTitle()); 55 | mFivCover.setImageUriByLp(oper.getPic()); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/vh/DiscoverIndexLevel2TitleViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.vh; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | import android.widget.TextView; 6 | 7 | import com.zkteam.discover.R; 8 | import com.zkteam.discover.base.ExRvItemViewHolderBase; 9 | import com.zkteam.discover.bean.DiscoverOper; 10 | import com.zkteam.discover.util.TextUtil; 11 | import com.zkteam.discover.util.ViewUtil; 12 | 13 | import butterknife.BindView; 14 | import butterknife.ButterKnife; 15 | 16 | /** 17 | * =========================================================== 18 | * 作 者:大印(高印) Github地址:https://github.com/GaoYin2016 19 | * 邮 箱:18810474975@163.com 20 | * 版 本: 21 | * 创建日期:2018/3/6 下午6:34 22 | * 描 述: 第二级标题栏运营位 23 | * 修订历史: 24 | * =========================================================== 25 | */ 26 | public class DiscoverIndexLevel2TitleViewHolder extends ExRvItemViewHolderBase { 27 | 28 | @BindView(R.id.tvTitle) 29 | TextView mTvTitle; 30 | 31 | @BindView(R.id.tvMore) 32 | TextView mTvMore; 33 | 34 | public DiscoverIndexLevel2TitleViewHolder(ViewGroup viewGroup) { 35 | 36 | super(viewGroup, R.layout.page_discover_index_level2_vh_title); 37 | ButterKnife.bind(this, itemView); 38 | } 39 | 40 | @Override 41 | protected void initConvertView(View convertView) { 42 | 43 | convertView.setOnClickListener(this); 44 | } 45 | 46 | public void invalidateView(DiscoverOper oper) { 47 | 48 | if (oper == null) { 49 | 50 | mTvTitle.setText(TextUtil.TEXT_EMPTY); 51 | ViewUtil.hideView(mTvMore); 52 | } else { 53 | 54 | mTvTitle.setText(oper.getTitle()); 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkteam/discover/vh/ExRvItemViewHolderEmpty.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover.vh; 2 | 3 | import android.support.v7.widget.OrientationHelper; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import com.zkteam.discover.base.ExRvItemViewHolderBase; 9 | 10 | public class ExRvItemViewHolderEmpty extends ExRvItemViewHolderBase { 11 | 12 | private ExRvItemViewHolderEmpty(ViewGroup parent, int orientation) { 13 | 14 | super(getEmptyView(parent, orientation)); 15 | } 16 | 17 | public static ExRvItemViewHolderEmpty newHoriInstance(ViewGroup parent) { 18 | 19 | return new ExRvItemViewHolderEmpty(parent, OrientationHelper.HORIZONTAL); 20 | } 21 | 22 | public static ExRvItemViewHolderEmpty newVertInstance(ViewGroup parent) { 23 | 24 | return new ExRvItemViewHolderEmpty(parent, OrientationHelper.VERTICAL); 25 | } 26 | 27 | private static View getEmptyView(ViewGroup parent, int orientation) { 28 | 29 | View view = new View(parent.getContext()); 30 | 31 | //0表示水平朝向,1表示垂直朝向 32 | // if(orientation == OrientationHelper.VERTICAL) 33 | // view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, 100)); 34 | // else 35 | // view.setLayoutParams(new RecyclerView.LayoutParams(50, RecyclerView.LayoutParams.WRAP_CONTENT)); 36 | view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT)); 37 | return view; 38 | } 39 | 40 | @Override 41 | protected void initConvertView(View convertView) { 42 | 43 | //nothing 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/page_discover_index_level1_vh.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/page_discover_index_level2_vh_banner.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/page_discover_index_level2_vh_mini.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/page_discover_index_level2_vh_title.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 17 | 18 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_page_main_search_left_selected_status.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-xxhdpi/ic_page_main_search_left_selected_status.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_shop_detail_right_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-xxhdpi/ic_shop_detail_right_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #dd3434 4 | #dd3434 5 | #dd3434 6 | #FFE6E6E6 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 分类列表 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 18 | 19 | 22 | 23 | 26 | 27 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/test/java/com/zkteam/discover/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.zkteam.discover; 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 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.0.0' 11 | classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1' 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /discover.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/discover.keystore -------------------------------------------------------------------------------- /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/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 24 10:17:59 CST 2018 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-4.1-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 | -------------------------------------------------------------------------------- /pic/AD24390AAB4429800079CBBE5D04AE5D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/pic/AD24390AAB4429800079CBBE5D04AE5D.png -------------------------------------------------------------------------------- /pic/BCDA22936B6632ED876589BE749F016D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/pic/BCDA22936B6632ED876589BE749F016D.png -------------------------------------------------------------------------------- /pic/FCEDFD139973E5AD8BE18BE0314E814E.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaYinTeamCode/Discover/90bbb277870bacb100419aa3e8deb713ee2b5654/pic/FCEDFD139973E5AD8BE18BE0314E814E.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------