├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app-debug.apk ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── huaqin │ │ └── recyclerviewdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── huaqin │ │ │ └── recyclerviewdemo │ │ │ ├── App.java │ │ │ ├── BaseActivity.java │ │ │ ├── BaseFragment.java │ │ │ ├── BaseToolbarActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── core │ │ │ ├── bean │ │ │ │ └── NewsItem.java │ │ │ ├── contract │ │ │ │ └── NewsContract.java │ │ │ ├── model │ │ │ │ ├── BaseModelCallBack.java │ │ │ │ └── NewsModel.java │ │ │ ├── presenter │ │ │ │ ├── BasePresenter.java │ │ │ │ └── NewsPresenter.java │ │ │ └── view │ │ │ │ ├── BaseView.java │ │ │ │ ├── WelcomeActivity.java │ │ │ │ ├── adapter │ │ │ │ ├── ListGridAdapter.java │ │ │ │ ├── MainFragmentPagerAdapter.java │ │ │ │ ├── NewsAdapter.java │ │ │ │ ├── NewsGridAdapter.java │ │ │ │ ├── StaggeredAdapter.java │ │ │ │ ├── TecentAdapter.java │ │ │ │ ├── TecentHolder.java │ │ │ │ └── ThirdGridAdapter.java │ │ │ │ └── ui │ │ │ │ ├── FragmentFactory.java │ │ │ │ ├── GridFragment.java │ │ │ │ ├── NewsFragment.java │ │ │ │ ├── NewsHorFragment.java │ │ │ │ ├── PullLoadFragment.java │ │ │ │ ├── StaggeredDemoFragment.java │ │ │ │ ├── TencentFragment.java │ │ │ │ └── WebActivity.java │ │ │ ├── retrofit │ │ │ ├── ApiManager.java │ │ │ ├── INewsApi.java │ │ │ └── RetrofitClient.java │ │ │ ├── util │ │ │ ├── Constants.java │ │ │ ├── FileUtil.java │ │ │ ├── ImageLoader.java │ │ │ └── InternetUtil.java │ │ │ └── widget │ │ │ ├── NoScrollGridView.java │ │ │ ├── PicassoImageLoader.java │ │ │ ├── ProgressWebView.java │ │ │ ├── RecyclerWidgetProvider.java │ │ │ └── VpRecyclerView.java │ └── res │ │ ├── drawable-xhdpi │ │ ├── ic_app.png │ │ ├── ic_refresh.png │ │ ├── place_holder.png │ │ ├── tecent_holder.png │ │ ├── welcome.png │ │ └── widget_preview.jpg │ │ ├── drawable │ │ └── progress_bar.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_web.xml │ │ ├── activity_welcome.xml │ │ ├── fragment_grid.xml │ │ ├── fragment_home_ad.xml │ │ ├── fragment_home_banner.xml │ │ ├── fragment_home_category.xml │ │ ├── fragment_home_list.xml │ │ ├── fragment_home_third.xml │ │ ├── fragment_news.xml │ │ ├── fragment_pullload.xml │ │ ├── fragment_staggered.xml │ │ ├── fragment_tencent.xml │ │ ├── list_grid_layout.xml │ │ ├── news_grid_item_layout.xml │ │ ├── news_item_layout.xml │ │ ├── staggered_item_layout.xml │ │ ├── third_grid_layout.xml │ │ ├── toolbar_title_layout.xml │ │ └── widget_layout.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 │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── widget_info.xml │ └── test │ └── java │ └── com │ └── huaqin │ └── recyclerviewdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── 1.gif ├── 2.gif ├── 3.gif ├── 4.gif ├── 5.gif ├── all.gif ├── recyclerview.png ├── widget.gif └── widget_click.gif └── 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/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | Android API 25 Platform 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![这里写图片描述](https://github.com/AdleyLong/RecyclerViewDemo/blob/master/screenshots/all.gif) 2 | ![这里写图片描述](https://github.com/AdleyLong/RecyclerViewDemo/blob/master/screenshots/5.gif) 3 | ![这里写图片描述](https://github.com/AdleyLong/RecyclerViewDemo/blob/master/screenshots/widget.gif) 4 | ![这里写图片描述](https://github.com/AdleyLong/RecyclerViewDemo/blob/master/screenshots/widget_click.gif) -------------------------------------------------------------------------------- /app-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app-debug.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'android-apt' 3 | 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion "25.0.2" 7 | defaultConfig { 8 | applicationId "com.huaqin.recyclerviewdemo" 9 | minSdkVersion 15 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(include: ['*.jar'], dir: 'libs') 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | 29 | compile 'com.android.support:appcompat-v7:25.0.0' 30 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 31 | compile 'com.android.support:design:25.0.0' 32 | compile 'com.android.support:cardview-v7:25.0.0' 33 | compile 'com.jakewharton:butterknife:8.4.0' 34 | compile 'com.squareup.picasso:picasso:2.5.2' 35 | compile 'com.squareup.retrofit2:retrofit:2.1.0' 36 | compile 'com.squareup.retrofit2:converter-gson:2.1.0' 37 | compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0' 38 | compile 'com.squareup.okhttp3:logging-interceptor:3.4.1' 39 | compile 'io.reactivex:rxjava:1.1.6' 40 | compile 'io.reactivex:rxandroid:1.2.1' 41 | compile 'com.jcodecraeer:xrecyclerview:1.2.8' 42 | testCompile 'junit:junit:4.12' 43 | apt 'com.jakewharton:butterknife-compiler:8.4.0' 44 | compile 'com.youth.banner:banner:1.4.8' 45 | 46 | } 47 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/ubuntu/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/huaqin/recyclerviewdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.huaqin.recyclerviewdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/App.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo; 2 | 3 | import android.app.Application; 4 | 5 | /** 6 | * Created by ubuntu on 17-4-13. 7 | */ 8 | 9 | public class App extends Application { 10 | public static App singleton = null; 11 | 12 | private final String TAG = "App"; 13 | 14 | public static App getInstance() { 15 | return singleton; 16 | } 17 | 18 | 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | singleton = this; 23 | 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.widget.Toast; 5 | 6 | /** 7 | * Created by ubuntu on 17-4-13. 8 | */ 9 | 10 | public class BaseActivity extends AppCompatActivity { 11 | /** 12 | * toast弹框 13 | * 14 | * @param toastStr 15 | */ 16 | public void showToast(String toastStr) { 17 | Toast.makeText(this, toastStr, Toast.LENGTH_SHORT).show(); 18 | } 19 | 20 | /** 21 | * toast弹框 22 | * 23 | * @param toastId 24 | */ 25 | public void showToast(int toastId) { 26 | Toast.makeText(this, toastId, Toast.LENGTH_SHORT).show(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.widget.Toast; 5 | 6 | /** 7 | * Created by ubuntu on 17-4-13. 8 | */ 9 | 10 | public class BaseFragment extends Fragment { 11 | 12 | /** 13 | * toast弹框 14 | * @param toastStr 15 | */ 16 | public void showToast(String toastStr){ 17 | Toast.makeText(this.getActivity(),toastStr,Toast.LENGTH_SHORT).show(); 18 | } 19 | 20 | /** 21 | * toast弹框 22 | * @param toastId 23 | */ 24 | public void showToast(int toastId){ 25 | Toast.makeText(this.getActivity(),toastId, Toast.LENGTH_SHORT).show(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/BaseToolbarActivity.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.widget.Toolbar; 6 | import android.view.MenuItem; 7 | import android.view.View; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | /** 12 | * Created by ubuntu on 17-4-13. 13 | */ 14 | 15 | public abstract class BaseToolbarActivity extends BaseActivity { 16 | private Toolbar mToolbar; 17 | private TextView mTitle; 18 | 19 | @Override 20 | protected void onCreate(@Nullable Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | 23 | setContentView(getLayoutId()); 24 | 25 | mToolbar = (Toolbar) findViewById(R.id.toolbar); 26 | mTitle = (TextView) findViewById(R.id.toolbar_title); 27 | if (mToolbar != null) { 28 | setSupportActionBar(mToolbar); 29 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 30 | getSupportActionBar().setDisplayShowTitleEnabled(false); 31 | } 32 | 33 | } 34 | 35 | @Override 36 | public boolean onOptionsItemSelected(MenuItem item) { 37 | if (item.getItemId() == android.R.id.home) { 38 | finish(); 39 | return true; 40 | } 41 | return super.onOptionsItemSelected(item); 42 | } 43 | 44 | public Toolbar getToolbar() { 45 | return (Toolbar) findViewById(R.id.toolbar); 46 | } 47 | 48 | public void setTitle(String title) { 49 | mTitle.setText(title); 50 | } 51 | 52 | public abstract int getLayoutId(); 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.design.widget.TabLayout; 6 | import android.support.v4.view.ViewPager; 7 | import android.support.v7.app.AppCompatActivity; 8 | 9 | import com.huaqin.recyclerviewdemo.core.view.adapter.MainFragmentPagerAdapter; 10 | 11 | import butterknife.BindView; 12 | import butterknife.ButterKnife; 13 | 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | @BindView(R.id.tab_layout) 17 | TabLayout mTabLayout; 18 | @BindView(R.id.viewpager) 19 | ViewPager mViewpager; 20 | 21 | private MainFragmentPagerAdapter mAdapter; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_main); 27 | ButterKnife.bind(this); 28 | 29 | initView(); 30 | } 31 | 32 | /** 33 | * 初始化对象 34 | */ 35 | private void initView() { 36 | mAdapter = new MainFragmentPagerAdapter(getSupportFragmentManager(), this); 37 | mViewpager.setAdapter(mAdapter); 38 | mViewpager.setOffscreenPageLimit(6); 39 | mTabLayout.setupWithViewPager(mViewpager); 40 | // mTabLayout.setTabMode(TabLayout.MODE_FIXED); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/bean/NewsItem.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.bean; 2 | 3 | /** 4 | * Created by ubuntu on 17-4-13. 5 | */ 6 | 7 | public class NewsItem { 8 | 9 | 10 | /** 11 | * postid : CHTCNO4S00038FO9 12 | * url_3w : http://ent.163.com/17/0413/12/CHTCNO4S00038FO9.html 13 | * votecount : 6984 14 | * replyCount : 7767 15 | * skipID : S1491970484761 16 | * ltitle : 白百何出轨第二弹!与男模泰国算命 当街大玩捏臀 17 | * digest : 网易娱乐4月13日报道4月12日,卓伟在直播中曝出大料,出轨女主就是白百何。白百何在泰国会面男模张爱朋,两人贴面喂食泳边嬉戏,上演“一指禅”,画面尺度惊人。今天 18 | * skipType : special 19 | * url : http://3g.163.com/ent/17/0413/12/CHTCNO4S00038FO9.html 20 | * specialID : S1491970484761 21 | * docid : CHTCNO4S00038FO9 22 | * title : 白百何出轨第二弹!与男模泰国算命 当街大玩捏臀 23 | * source : 网易娱乐 24 | * priority : 151 25 | * lmodify : 2017-04-13 13:38:06 26 | * boardid : ent2_bbs 27 | * subtitle : 28 | * imgsrc : http://cms-bucket.nosdn.127.net/ad53a86aef044d0b87e359f7b224fecc20170413121507.png 29 | * ptime : 2017-04-13 12:15:11 30 | */ 31 | 32 | private String postid; 33 | private String url_3w; 34 | private int votecount; 35 | private int replyCount; 36 | private String skipID; 37 | private String ltitle; 38 | private String digest; 39 | private String skipType; 40 | private String url; 41 | private String specialID; 42 | private String docid; 43 | private String title; 44 | private String source; 45 | private int priority; 46 | private String lmodify; 47 | private String boardid; 48 | private String subtitle; 49 | private String imgsrc; 50 | private String ptime; 51 | 52 | public String getPostid() { 53 | return postid; 54 | } 55 | 56 | public void setPostid(String postid) { 57 | this.postid = postid; 58 | } 59 | 60 | public String getUrl_3w() { 61 | return url_3w; 62 | } 63 | 64 | public void setUrl_3w(String url_3w) { 65 | this.url_3w = url_3w; 66 | } 67 | 68 | public int getVotecount() { 69 | return votecount; 70 | } 71 | 72 | public void setVotecount(int votecount) { 73 | this.votecount = votecount; 74 | } 75 | 76 | public int getReplyCount() { 77 | return replyCount; 78 | } 79 | 80 | public void setReplyCount(int replyCount) { 81 | this.replyCount = replyCount; 82 | } 83 | 84 | public String getSkipID() { 85 | return skipID; 86 | } 87 | 88 | public void setSkipID(String skipID) { 89 | this.skipID = skipID; 90 | } 91 | 92 | public String getLtitle() { 93 | return ltitle; 94 | } 95 | 96 | public void setLtitle(String ltitle) { 97 | this.ltitle = ltitle; 98 | } 99 | 100 | public String getDigest() { 101 | return digest; 102 | } 103 | 104 | public void setDigest(String digest) { 105 | this.digest = digest; 106 | } 107 | 108 | public String getSkipType() { 109 | return skipType; 110 | } 111 | 112 | public void setSkipType(String skipType) { 113 | this.skipType = skipType; 114 | } 115 | 116 | public String getUrl() { 117 | return url; 118 | } 119 | 120 | public void setUrl(String url) { 121 | this.url = url; 122 | } 123 | 124 | public String getSpecialID() { 125 | return specialID; 126 | } 127 | 128 | public void setSpecialID(String specialID) { 129 | this.specialID = specialID; 130 | } 131 | 132 | public String getDocid() { 133 | return docid; 134 | } 135 | 136 | public void setDocid(String docid) { 137 | this.docid = docid; 138 | } 139 | 140 | public String getTitle() { 141 | return title; 142 | } 143 | 144 | public void setTitle(String title) { 145 | this.title = title; 146 | } 147 | 148 | public String getSource() { 149 | return source; 150 | } 151 | 152 | public void setSource(String source) { 153 | this.source = source; 154 | } 155 | 156 | public int getPriority() { 157 | return priority; 158 | } 159 | 160 | public void setPriority(int priority) { 161 | this.priority = priority; 162 | } 163 | 164 | public String getLmodify() { 165 | return lmodify; 166 | } 167 | 168 | public void setLmodify(String lmodify) { 169 | this.lmodify = lmodify; 170 | } 171 | 172 | public String getBoardid() { 173 | return boardid; 174 | } 175 | 176 | public void setBoardid(String boardid) { 177 | this.boardid = boardid; 178 | } 179 | 180 | public String getSubtitle() { 181 | return subtitle; 182 | } 183 | 184 | public void setSubtitle(String subtitle) { 185 | this.subtitle = subtitle; 186 | } 187 | 188 | public String getImgsrc() { 189 | return imgsrc; 190 | } 191 | 192 | public void setImgsrc(String imgsrc) { 193 | this.imgsrc = imgsrc; 194 | } 195 | 196 | public String getPtime() { 197 | return ptime; 198 | } 199 | 200 | public void setPtime(String ptime) { 201 | this.ptime = ptime; 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/contract/NewsContract.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.contract; 2 | 3 | import android.app.Activity; 4 | 5 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 6 | import com.huaqin.recyclerviewdemo.core.presenter.BasePresenter; 7 | import com.huaqin.recyclerviewdemo.core.view.BaseView; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by ubuntu on 17-4-13. 13 | */ 14 | 15 | public class NewsContract { 16 | public interface View extends BaseView { 17 | void onSuccess(List list); 18 | 19 | void onFailure(String error); 20 | 21 | } 22 | 23 | 24 | public interface Presenter extends BasePresenter { 25 | void getData(Activity activity); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/model/BaseModelCallBack.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.model; 2 | 3 | /** 4 | * Created by ubuntu on 17-4-13. 5 | */ 6 | 7 | public interface BaseModelCallBack { 8 | void onResponse(T response); 9 | 10 | void onFailure(String error); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/model/NewsModel.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.model; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | 6 | import com.google.gson.JsonArray; 7 | import com.google.gson.JsonObject; 8 | import com.google.gson.annotations.JsonAdapter; 9 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 10 | import com.huaqin.recyclerviewdemo.retrofit.ApiManager; 11 | 12 | import org.json.JSONArray; 13 | import org.json.JSONException; 14 | import org.json.JSONObject; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | import rx.Subscriber; 21 | import rx.android.schedulers.AndroidSchedulers; 22 | import rx.schedulers.Schedulers; 23 | 24 | /** 25 | * Created by ubuntu on 17-4-13. 26 | */ 27 | 28 | public class NewsModel { 29 | private static final String TAG = "NewsModel"; 30 | 31 | public void getData(Activity activity, final BaseModelCallBack callBack) { 32 | ApiManager.getInstance().apiNews() 33 | .getNewsList("T1348648517839", 0, 20) 34 | .subscribeOn(Schedulers.io()) 35 | .observeOn(AndroidSchedulers.mainThread()) 36 | .subscribe(new Subscriber>>() { 37 | @Override 38 | public void onCompleted() { 39 | 40 | } 41 | 42 | @Override 43 | public void onError(Throwable e) { 44 | callBack.onFailure(e.toString()); 45 | } 46 | 47 | @Override 48 | public void onNext(Map> map) { 49 | List list = map.get("T1348648517839"); 50 | callBack.onResponse(list); 51 | } 52 | }); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/presenter/BasePresenter.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.presenter; 2 | 3 | /** 4 | * Created by ubuntu on 17-4-13. 5 | */ 6 | 7 | public interface BasePresenter { 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/presenter/NewsPresenter.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.presenter; 2 | 3 | import android.app.Activity; 4 | 5 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 6 | import com.huaqin.recyclerviewdemo.core.contract.NewsContract; 7 | import com.huaqin.recyclerviewdemo.core.model.BaseModelCallBack; 8 | import com.huaqin.recyclerviewdemo.core.model.NewsModel; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Created by ubuntu on 17-4-13. 14 | */ 15 | 16 | public class NewsPresenter implements NewsContract.Presenter { 17 | 18 | private NewsModel mModel; 19 | private NewsContract.View mView; 20 | 21 | public NewsPresenter(NewsContract.View view) { 22 | mModel = new NewsModel(); 23 | mView = view; 24 | } 25 | 26 | @Override 27 | public void getData(Activity activity) { 28 | mModel.getData(activity, new BaseModelCallBack>() { 29 | 30 | @Override 31 | public void onResponse(List response) { 32 | mView.onSuccess(response); 33 | } 34 | 35 | @Override 36 | public void onFailure(String error) { 37 | mView.onFailure(error); 38 | } 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/BaseView.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view; 2 | 3 | /** 4 | * Created by ubuntu on 17-4-13. 5 | */ 6 | 7 | public interface BaseView { 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/WelcomeActivity.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | 7 | import com.huaqin.recyclerviewdemo.BaseActivity; 8 | import com.huaqin.recyclerviewdemo.MainActivity; 9 | import com.huaqin.recyclerviewdemo.R; 10 | import com.huaqin.recyclerviewdemo.core.presenter.NewsPresenter; 11 | 12 | public class WelcomeActivity extends BaseActivity { 13 | 14 | private static final String TAG = "WelcomeActivity"; 15 | private NewsPresenter mPresenter; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_welcome); 21 | 22 | new Handler().postDelayed(new Runnable() { 23 | @Override 24 | public void run() { 25 | WelcomeActivity.this.startActivity(new Intent(WelcomeActivity.this, MainActivity.class)); 26 | WelcomeActivity.this.finish(); 27 | } 28 | }, 1 * 1000); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/adapter/ListGridAdapter.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.adapter; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.BaseAdapter; 9 | import android.widget.ImageView; 10 | import android.widget.RelativeLayout; 11 | import android.widget.TextView; 12 | 13 | import com.huaqin.recyclerviewdemo.R; 14 | import com.huaqin.recyclerviewdemo.util.Constants; 15 | import com.huaqin.recyclerviewdemo.util.ImageLoader; 16 | 17 | import butterknife.BindView; 18 | import butterknife.ButterKnife; 19 | 20 | /** 21 | * Created by ubuntu on 17-4-14. 22 | */ 23 | 24 | public class ListGridAdapter extends BaseAdapter { 25 | 26 | private LayoutInflater inflater; 27 | private Context mContext; 28 | private Activity mActivity; 29 | 30 | public ListGridAdapter(Context context, Activity activity) { 31 | mContext = context; 32 | mActivity = activity; 33 | this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 34 | } 35 | 36 | @Override 37 | public int getCount() { 38 | return 6; 39 | } 40 | 41 | @Override 42 | public Object getItem(int i) { 43 | return i; 44 | } 45 | 46 | @Override 47 | public long getItemId(int i) { 48 | return i; 49 | } 50 | 51 | @Override 52 | public View getView(final int position, View convertView, ViewGroup viewGroup) { 53 | ViewHolder holder = null; 54 | if (convertView == null) { 55 | convertView = inflater.inflate(R.layout.list_grid_layout, null); 56 | holder = new ViewHolder(convertView); 57 | convertView.setTag(holder); 58 | } else { 59 | holder = (ViewHolder) convertView.getTag(); 60 | } 61 | 62 | ImageLoader.getInstance().showImage(mContext, Constants.mBannerUrls[position], holder.ivContent); 63 | 64 | holder.tvTitle.setText(Constants.mBannerNames[position]); 65 | holder.tvSubtitle.setText(Constants.mSubTitles[position]); 66 | 67 | return convertView; 68 | } 69 | 70 | static class ViewHolder { 71 | @BindView(R.id.iv_content) 72 | ImageView ivContent; 73 | @BindView(R.id.tv_title) 74 | TextView tvTitle; 75 | @BindView(R.id.rl_title) 76 | RelativeLayout rlTitle; 77 | @BindView(R.id.tv_subtitle) 78 | TextView tvSubtitle; 79 | 80 | ViewHolder(View view) { 81 | ButterKnife.bind(this, view); 82 | } 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/adapter/MainFragmentPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentManager; 6 | import android.support.v4.app.FragmentPagerAdapter; 7 | 8 | import com.huaqin.recyclerviewdemo.core.view.ui.FragmentFactory; 9 | 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Created by ubuntu on 17-4-13. 14 | */ 15 | 16 | public class MainFragmentPagerAdapter extends FragmentPagerAdapter { 17 | private Context mContext; 18 | private String tabTitles[] = new String[]{"腾讯视频","垂直","水平", "网格", "瀑布流", "带刷新的" }; 19 | 20 | public MainFragmentPagerAdapter(FragmentManager fm, Context context) { 21 | super(fm); 22 | mContext = context; 23 | } 24 | 25 | 26 | @Override 27 | public Fragment getItem(int position) { 28 | return FragmentFactory.getInstance().createFragment(position); 29 | } 30 | 31 | @Override 32 | public int getCount() { 33 | return tabTitles.length; 34 | } 35 | 36 | @Override 37 | public CharSequence getPageTitle(int position) { 38 | return tabTitles[position]; 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/adapter/NewsAdapter.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.CardView; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.huaqin.recyclerviewdemo.R; 13 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 14 | import com.huaqin.recyclerviewdemo.util.ImageLoader; 15 | import com.squareup.picasso.Picasso; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | import butterknife.BindView; 21 | import butterknife.ButterKnife; 22 | 23 | /** 24 | * Created by ubuntu on 17-4-13. 25 | */ 26 | 27 | public class NewsAdapter extends RecyclerView.Adapter { 28 | 29 | private Context mContext; 30 | private LayoutInflater inflater; 31 | private List mList = new ArrayList<>(); 32 | 33 | public NewsAdapter(Context context, List list) { 34 | this.mContext = context; 35 | inflater = LayoutInflater.from(mContext); 36 | mList.clear(); 37 | mList.addAll(list); 38 | } 39 | 40 | 41 | /** 42 | * add onItemClick begin 43 | */ 44 | public interface OnRecyclerViewItemClickListener { 45 | void onItemClick(View view, int position); 46 | } 47 | 48 | private OnRecyclerViewItemClickListener mOnItemClickListener = null; 49 | 50 | public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) { 51 | mOnItemClickListener = listener; 52 | } 53 | 54 | @Override 55 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 56 | View view = inflater.inflate(R.layout.news_item_layout, parent, false); 57 | return new ViewHolder(view); 58 | } 59 | 60 | @Override 61 | public void onBindViewHolder(ViewHolder holder, final int position) { 62 | String title = mList.get(position).getTitle(); 63 | String imgUrl = mList.get(position).getImgsrc(); 64 | String source = mList.get(position).getSource() + " " + mList.get(position).getPtime(); 65 | 66 | holder.tvTitle.setText(title); 67 | holder.tvSource.setText(source); 68 | 69 | ImageLoader.getInstance().showImage(mContext, imgUrl, holder.ivImg); 70 | 71 | holder.cardview.setOnClickListener(new View.OnClickListener() { 72 | @Override 73 | public void onClick(View v) { 74 | if (mOnItemClickListener != null) { 75 | mOnItemClickListener.onItemClick(v, position); 76 | } 77 | } 78 | }); 79 | } 80 | 81 | @Override 82 | public int getItemCount() { 83 | return mList.size(); 84 | } 85 | 86 | class ViewHolder extends RecyclerView.ViewHolder { 87 | 88 | @BindView(R.id.iv_img) 89 | ImageView ivImg; 90 | @BindView(R.id.tv_title) 91 | TextView tvTitle; 92 | @BindView(R.id.tv_source) 93 | TextView tvSource; 94 | @BindView(R.id.cardview) 95 | CardView cardview; 96 | 97 | public ViewHolder(View itemView) { 98 | super(itemView); 99 | ButterKnife.bind(this, itemView); 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/adapter/NewsGridAdapter.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.CardView; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.huaqin.recyclerviewdemo.R; 13 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 14 | import com.huaqin.recyclerviewdemo.util.ImageLoader; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | import butterknife.BindView; 20 | import butterknife.ButterKnife; 21 | 22 | /** 23 | * Created by ubuntu on 17-4-13. 24 | */ 25 | 26 | public class NewsGridAdapter extends RecyclerView.Adapter { 27 | 28 | private Context mContext; 29 | private LayoutInflater inflater; 30 | private List mList = new ArrayList<>(); 31 | 32 | public NewsGridAdapter(Context context, List list) { 33 | this.mContext = context; 34 | inflater = LayoutInflater.from(mContext); 35 | mList.clear(); 36 | mList.addAll(list); 37 | } 38 | 39 | 40 | /** 41 | * add onItemClick begin 42 | */ 43 | public interface OnRecyclerViewItemClickListener { 44 | void onItemClick(View view, int position); 45 | } 46 | 47 | private OnRecyclerViewItemClickListener mOnItemClickListener = null; 48 | 49 | public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) { 50 | mOnItemClickListener = listener; 51 | } 52 | 53 | @Override 54 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 55 | View view = inflater.inflate(R.layout.news_grid_item_layout, parent, false); 56 | return new ViewHolder(view); 57 | } 58 | 59 | @Override 60 | public void onBindViewHolder(ViewHolder holder, int position) { 61 | final int positionTemp = position + 1; 62 | String title = mList.get(positionTemp).getTitle(); 63 | String imgUrl = mList.get(positionTemp).getImgsrc(); 64 | 65 | holder.tvTitle.setText(title); 66 | ImageLoader.getInstance().showImage(mContext, imgUrl, holder.ivImg); 67 | 68 | holder.cardview.setOnClickListener(new View.OnClickListener() { 69 | @Override 70 | public void onClick(View v) { 71 | if (mOnItemClickListener != null) { 72 | mOnItemClickListener.onItemClick(v, positionTemp); 73 | } 74 | } 75 | }); 76 | } 77 | 78 | @Override 79 | public int getItemCount() { 80 | return mList.size() - 1; 81 | } 82 | 83 | class ViewHolder extends RecyclerView.ViewHolder { 84 | 85 | @BindView(R.id.iv_img) 86 | ImageView ivImg; 87 | @BindView(R.id.tv_title) 88 | TextView tvTitle; 89 | @BindView(R.id.cardview) 90 | CardView cardview; 91 | 92 | public ViewHolder(View itemView) { 93 | super(itemView); 94 | ButterKnife.bind(this, itemView); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/adapter/StaggeredAdapter.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.CardView; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | 11 | import com.huaqin.recyclerviewdemo.R; 12 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 13 | import com.huaqin.recyclerviewdemo.util.ImageLoader; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | import butterknife.BindView; 19 | import butterknife.ButterKnife; 20 | 21 | /** 22 | * Created by ubuntu on 17-4-13. 23 | */ 24 | 25 | public class StaggeredAdapter extends RecyclerView.Adapter { 26 | 27 | private Context mContext; 28 | private LayoutInflater inflater; 29 | private List mUrls; 30 | 31 | public StaggeredAdapter(Context context, List urls) { 32 | this.mContext = context; 33 | inflater = LayoutInflater.from(mContext); 34 | mUrls = urls; 35 | } 36 | 37 | 38 | @Override 39 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 40 | View view = inflater.inflate(R.layout.staggered_item_layout, parent, false); 41 | return new ViewHolder(view); 42 | } 43 | 44 | @Override 45 | public void onBindViewHolder(ViewHolder holder, int position) { 46 | ImageLoader.getInstance().showImage(mContext, mUrls.get(position), holder.ivImg); 47 | } 48 | 49 | @Override 50 | public int getItemCount() { 51 | return mUrls.size(); 52 | } 53 | 54 | class ViewHolder extends RecyclerView.ViewHolder { 55 | 56 | @BindView(R.id.iv_img) 57 | ImageView ivImg; 58 | @BindView(R.id.cardview) 59 | CardView cardview; 60 | 61 | public ViewHolder(View itemView) { 62 | super(itemView); 63 | ButterKnife.bind(this, itemView); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/adapter/TecentAdapter.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.adapter; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.DisplayMetrics; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.AdapterView; 10 | import android.widget.ImageView; 11 | import android.widget.RelativeLayout; 12 | import android.widget.TextView; 13 | import android.widget.Toast; 14 | 15 | import com.huaqin.recyclerviewdemo.util.Constants; 16 | import com.huaqin.recyclerviewdemo.util.ImageLoader; 17 | import com.huaqin.recyclerviewdemo.widget.NoScrollGridView; 18 | import com.huaqin.recyclerviewdemo.widget.PicassoImageLoader; 19 | import com.youth.banner.Banner; 20 | import com.youth.banner.BannerConfig; 21 | import com.youth.banner.listener.OnBannerClickListener; 22 | 23 | import java.util.ArrayList; 24 | import java.util.Arrays; 25 | import java.util.List; 26 | 27 | /** 28 | * Created by ubuntu on 17-4-14. 29 | */ 30 | 31 | public class TecentAdapter extends RecyclerView.Adapter { 32 | 33 | private TecentHolder mHomeHolder; 34 | private Context mContext; 35 | private Activity mActivity; 36 | public Banner mBanner; 37 | 38 | public TecentAdapter(Activity activity, Context context) { 39 | mContext = context; 40 | mHomeHolder = new TecentHolder(context); 41 | mActivity = activity; 42 | } 43 | 44 | @Override 45 | public int getItemViewType(int position) { 46 | 47 | int type = 0; 48 | switch (position) { 49 | case 0: 50 | type = TecentHolder.ITEM_BANNER; 51 | break; 52 | case 1: 53 | type = TecentHolder.ITEM_THIRD; 54 | break; 55 | case 2: 56 | type = TecentHolder.ITEM_CATEGORY; 57 | break; 58 | case 3: 59 | case 5: 60 | type = TecentHolder.ITEM_LIST; 61 | break; 62 | case 4: 63 | type = TecentHolder.ITEM_AD; 64 | break; 65 | } 66 | return type; 67 | } 68 | 69 | 70 | @Override 71 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 72 | return mHomeHolder.getViewHolder(parent, viewType); 73 | } 74 | 75 | @Override 76 | public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) { 77 | 78 | if (holder instanceof TecentHolder.BannerViewHolder) { 79 | List urls = Arrays.asList(Constants.mBannerUrls); 80 | List titles = Arrays.asList(Constants.mBannerNames); 81 | 82 | mBanner = ((TecentHolder.BannerViewHolder) holder).bannerGuideContent; 83 | 84 | ((TecentHolder.BannerViewHolder) holder).bannerGuideContent 85 | .setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE) 86 | .setBannerTitles(titles) 87 | .setImageLoader(new PicassoImageLoader()) 88 | .setImages(urls) 89 | .setDelayTime(2000) 90 | .setIndicatorGravity(BannerConfig.RIGHT) 91 | .setOnBannerClickListener(new OnBannerClickListener() { 92 | @Override 93 | public void OnBannerClick(int position) { 94 | Toast.makeText(mContext, "position=" + (position - 1), Toast.LENGTH_SHORT).show(); 95 | } 96 | }) 97 | .start(); 98 | 99 | } else if (holder instanceof TecentHolder.ThirdViewHolder) { 100 | 101 | NoScrollGridView gridView = ((TecentHolder.ThirdViewHolder) holder).thirdGridView; 102 | ThirdGridAdapter adapter = new ThirdGridAdapter(mContext); 103 | gridView.setAdapter(adapter); 104 | 105 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 106 | @Override 107 | public void onItemClick(AdapterView adapterView, View view, int i, long l) { 108 | Toast.makeText(mContext, "I'm third app", Toast.LENGTH_SHORT).show(); 109 | } 110 | }); 111 | } else if (holder instanceof TecentHolder.AdViewHolder) { 112 | 113 | ImageLoader.getInstance().showImage(mContext, "http://file.juzimi.com/weibopic/jezxmd2.jpg", ((TecentHolder.AdViewHolder) holder).adIv); 114 | ((TecentHolder.AdViewHolder) holder).adIv.setOnClickListener(new View.OnClickListener() { 115 | @Override 116 | public void onClick(View view) { 117 | Toast.makeText(mContext, "I'm ad", Toast.LENGTH_SHORT).show(); 118 | } 119 | }); 120 | } else if (holder instanceof TecentHolder.CategoryViewHolder) { 121 | 122 | TextView cateText = ((TecentHolder.CategoryViewHolder) holder).categoryTv; 123 | TextView titleText = ((TecentHolder.CategoryViewHolder) holder).categoryTitleTv; 124 | TextView subText = ((TecentHolder.CategoryViewHolder) holder).categorySubTv; 125 | ImageView cateIv = ((TecentHolder.CategoryViewHolder) holder).categoryIv; 126 | RelativeLayout rlMore = ((TecentHolder.CategoryViewHolder) holder).rlMore; 127 | 128 | cateText.setText("热门综艺"); 129 | titleText.setText("人名的名义"); 130 | subText.setText("育良书记被揭老底,当场发飙怒指关二代!"); 131 | ImageLoader.getInstance().showImage(mContext, "http://www.people.com.cn/mediafile/pic/20170405/23/8596374254589647023.jpg", cateIv); 132 | 133 | cateIv.setOnClickListener(new View.OnClickListener() { 134 | @Override 135 | public void onClick(View view) { 136 | Toast.makeText(mContext, "I'm big pic", Toast.LENGTH_SHORT).show(); 137 | } 138 | }); 139 | } else if (holder instanceof TecentHolder.ListViewHolder) { 140 | 141 | NoScrollGridView listGridView = ((TecentHolder.ListViewHolder) holder).listGridView; 142 | final ListGridAdapter adapter = new ListGridAdapter(mContext, mActivity); 143 | listGridView.setAdapter(adapter); 144 | } 145 | } 146 | 147 | @Override 148 | public int getItemCount() { 149 | return 6; 150 | } 151 | 152 | public void setBannerPlay(boolean b) { 153 | if (mBanner != null) { 154 | if (b) { 155 | mBanner.startAutoPlay(); 156 | } else { 157 | mBanner.stopAutoPlay(); 158 | } 159 | } 160 | } 161 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/adapter/TecentHolder.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.LinearLayout; 10 | import android.widget.RelativeLayout; 11 | import android.widget.TextView; 12 | 13 | import com.huaqin.recyclerviewdemo.R; 14 | import com.huaqin.recyclerviewdemo.widget.NoScrollGridView; 15 | import com.youth.banner.Banner; 16 | 17 | import butterknife.BindView; 18 | import butterknife.ButterKnife; 19 | 20 | /** 21 | * Created by ubuntu on 17-4-14. 22 | */ 23 | 24 | public class TecentHolder { 25 | public static final int ITEM_BANNER = 0; 26 | public static final int ITEM_THIRD = 1; 27 | public static final int ITEM_CATEGORY = 2; 28 | public static final int ITEM_LIST = 3; 29 | public static final int ITEM_AD = 4; 30 | 31 | private LayoutInflater mLayoutInflater; 32 | 33 | public TecentHolder(Context context) { 34 | mLayoutInflater = LayoutInflater.from(context); 35 | } 36 | 37 | public RecyclerView.ViewHolder getViewHolder(ViewGroup parent, int type) { 38 | switch (type) { 39 | case ITEM_BANNER: 40 | return new BannerViewHolder 41 | (mLayoutInflater.inflate(R.layout.fragment_home_banner, parent, false)); 42 | case ITEM_THIRD: 43 | return new ThirdViewHolder 44 | (mLayoutInflater.inflate(R.layout.fragment_home_third, parent, false)); 45 | case ITEM_CATEGORY: 46 | return new CategoryViewHolder 47 | (mLayoutInflater.inflate(R.layout.fragment_home_category, parent, false)); 48 | case ITEM_LIST: 49 | return new ListViewHolder 50 | (mLayoutInflater.inflate(R.layout.fragment_home_list, parent, false)); 51 | case ITEM_AD: 52 | return new AdViewHolder 53 | (mLayoutInflater.inflate(R.layout.fragment_home_ad, parent, false)); 54 | } 55 | return new BannerViewHolder 56 | (mLayoutInflater.inflate(R.layout.fragment_home_banner, parent, false)); 57 | } 58 | 59 | public class BannerViewHolder extends RecyclerView.ViewHolder { 60 | 61 | @BindView(R.id.banner) 62 | public Banner bannerGuideContent; 63 | @BindView(R.id.ll_banner) 64 | public LinearLayout llBanner; 65 | 66 | public BannerViewHolder(View itemView) { 67 | super(itemView); 68 | ButterKnife.bind(this, itemView); 69 | } 70 | } 71 | 72 | public class ThirdViewHolder extends RecyclerView.ViewHolder { 73 | 74 | @BindView(R.id.third_grid_view) 75 | public NoScrollGridView thirdGridView; 76 | 77 | public ThirdViewHolder(View itemView) { 78 | super(itemView); 79 | ButterKnife.bind(this, itemView); 80 | } 81 | } 82 | 83 | public class CategoryViewHolder extends RecyclerView.ViewHolder { 84 | @BindView(R.id.categoryTv) 85 | public TextView categoryTv; 86 | @BindView(R.id.category_iv) 87 | public ImageView categoryIv; 88 | @BindView(R.id.category_title_tv) 89 | public TextView categoryTitleTv; 90 | @BindView(R.id.category_sub_tv) 91 | public TextView categorySubTv; 92 | @BindView(R.id.rl_more) 93 | public RelativeLayout rlMore; 94 | 95 | public CategoryViewHolder(View itemView) { 96 | super(itemView); 97 | ButterKnife.bind(this, itemView); 98 | } 99 | } 100 | 101 | 102 | public class AdViewHolder extends RecyclerView.ViewHolder { 103 | @BindView(R.id.ad_iv) 104 | public ImageView adIv; 105 | 106 | public AdViewHolder(View itemView) { 107 | super(itemView); 108 | ButterKnife.bind(this, itemView); 109 | } 110 | } 111 | 112 | 113 | public class ListViewHolder extends RecyclerView.ViewHolder { 114 | 115 | @BindView(R.id.list_grid_view) 116 | public NoScrollGridView listGridView; 117 | @BindView(R.id.rl_refresh) 118 | public RelativeLayout rlRefresh; 119 | 120 | public ListViewHolder(View itemView) { 121 | super(itemView); 122 | ButterKnife.bind(this, itemView); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/adapter/ThirdGridAdapter.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.huaqin.recyclerviewdemo.R; 12 | import com.huaqin.recyclerviewdemo.util.ImageLoader; 13 | 14 | /** 15 | * Created by ubuntu on 17-4-14. 16 | */ 17 | 18 | public class ThirdGridAdapter extends BaseAdapter { 19 | 20 | private LayoutInflater inflater; 21 | private Context mContext; 22 | 23 | public ThirdGridAdapter(Context context) { 24 | mContext = context; 25 | this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 26 | } 27 | 28 | @Override 29 | public int getCount() { 30 | return 8; 31 | } 32 | 33 | @Override 34 | public Object getItem(int i) { 35 | return i; 36 | } 37 | 38 | @Override 39 | public long getItemId(int i) { 40 | return i; 41 | } 42 | 43 | @Override 44 | public View getView(int position, View convertView, ViewGroup viewGroup) { 45 | ViewHolder holder = null; 46 | if (convertView == null) { 47 | convertView = inflater.inflate(R.layout.third_grid_layout, null); 48 | holder = new ViewHolder(); 49 | holder.imageView = (ImageView) convertView.findViewById(R.id.third_iv); 50 | holder.textView = (TextView) convertView.findViewById(R.id.third_tv); 51 | convertView.setTag(holder); 52 | } else { 53 | holder = (ViewHolder) convertView.getTag(); 54 | } 55 | 56 | holder.textView.setText("应用0" + position); 57 | // ImageLoader.getInstance().showImage(mContext, "", holder.imageView); 58 | return convertView; 59 | } 60 | 61 | 62 | static class ViewHolder { 63 | ImageView imageView; 64 | TextView textView; 65 | } 66 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/ui/FragmentFactory.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.ui; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | /** 6 | * Created by ubuntu on 17-4-13. 7 | */ 8 | 9 | public class FragmentFactory { 10 | private static FragmentFactory instance; 11 | 12 | public static synchronized FragmentFactory getInstance() { 13 | if (instance == null) { 14 | instance = new FragmentFactory(); 15 | } 16 | 17 | return instance; 18 | } 19 | 20 | public Fragment createFragment(int i) { 21 | Fragment fragment = null; 22 | switch (i) { 23 | case 0: 24 | fragment = TencentFragment.newInstance(); 25 | break; 26 | case 1: 27 | fragment = NewsFragment.newInstance(); 28 | break; 29 | case 2: 30 | fragment = NewsHorFragment.newInstance(); 31 | break; 32 | case 3: 33 | fragment = GridFragment.newInstance(); 34 | break; 35 | case 4: 36 | fragment = StaggeredDemoFragment.newInstance(); 37 | break; 38 | case 5: 39 | fragment = PullLoadFragment.newInstance(); 40 | break; 41 | } 42 | return fragment; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/ui/GridFragment.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.ui; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.widget.GridLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.ProgressBar; 13 | 14 | import com.huaqin.recyclerviewdemo.BaseFragment; 15 | import com.huaqin.recyclerviewdemo.R; 16 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 17 | import com.huaqin.recyclerviewdemo.core.contract.NewsContract; 18 | import com.huaqin.recyclerviewdemo.core.presenter.NewsPresenter; 19 | import com.huaqin.recyclerviewdemo.core.view.adapter.NewsGridAdapter; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import butterknife.BindView; 25 | import butterknife.ButterKnife; 26 | import butterknife.Unbinder; 27 | 28 | /** 29 | * Created by ubuntu on 17-4-13. 30 | */ 31 | 32 | public class GridFragment extends BaseFragment implements NewsContract.View { 33 | private static GridFragment fragment = null; 34 | Unbinder unbinder; 35 | @BindView(R.id.movie_recyclerview) 36 | RecyclerView mRecyclerview; 37 | @BindView(R.id.progressbar) 38 | ProgressBar progressbar; 39 | private NewsGridAdapter mAdapter; 40 | private Context mContext; 41 | private final List mList = new ArrayList<>(); 42 | private NewsPresenter mPresenter; 43 | 44 | public static GridFragment newInstance() { 45 | if (fragment == null) { 46 | fragment = new GridFragment(); 47 | } 48 | return fragment; 49 | } 50 | 51 | @Override 52 | public void onAttach(Context context) { 53 | super.onAttach(context); 54 | mContext = context; 55 | } 56 | 57 | @Nullable 58 | @Override 59 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 60 | View view = inflater.inflate(R.layout.fragment_grid, container, false); 61 | unbinder = ButterKnife.bind(this, view); 62 | return view; 63 | } 64 | 65 | @Override 66 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 67 | super.onViewCreated(view, savedInstanceState); 68 | 69 | mRecyclerview.setVisibility(View.GONE); 70 | progressbar.setVisibility(View.VISIBLE); 71 | 72 | mPresenter = new NewsPresenter(this); 73 | mPresenter.getData(getActivity()); 74 | } 75 | 76 | 77 | private void initView() { 78 | mAdapter = new NewsGridAdapter(mContext, mList); 79 | //设置grid是一行2个 80 | mRecyclerview.setLayoutManager(new GridLayoutManager(mContext, 2)); 81 | mRecyclerview.setAdapter(mAdapter); 82 | mAdapter.setOnItemClickListener(new NewsGridAdapter.OnRecyclerViewItemClickListener() { 83 | @Override 84 | public void onItemClick(View view, int position) { 85 | String url = mList.get(position).getUrl(); 86 | Intent intent = new Intent(getActivity(), WebActivity.class); 87 | intent.putExtra("url", url); 88 | mContext.startActivity(intent); 89 | } 90 | }); 91 | } 92 | 93 | @Override 94 | public void onDestroyView() { 95 | super.onDestroyView(); 96 | unbinder.unbind(); 97 | } 98 | 99 | @Override 100 | public void onSuccess(List list) { 101 | mList.clear(); 102 | mList.addAll(list); 103 | mRecyclerview.setVisibility(View.VISIBLE); 104 | progressbar.setVisibility(View.GONE); 105 | initView(); 106 | } 107 | 108 | @Override 109 | public void onFailure(String error) { 110 | progressbar.setVisibility(View.GONE); 111 | showToast(error); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/ui/NewsFragment.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.ui; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.text.TextUtils; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.ProgressBar; 14 | 15 | import com.huaqin.recyclerviewdemo.BaseFragment; 16 | import com.huaqin.recyclerviewdemo.R; 17 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 18 | import com.huaqin.recyclerviewdemo.core.contract.NewsContract; 19 | import com.huaqin.recyclerviewdemo.core.presenter.NewsPresenter; 20 | import com.huaqin.recyclerviewdemo.core.view.adapter.NewsAdapter; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | import butterknife.BindView; 26 | import butterknife.ButterKnife; 27 | import butterknife.Unbinder; 28 | 29 | /** 30 | * Created by ubuntu on 17-4-13. 31 | */ 32 | 33 | public class NewsFragment extends BaseFragment implements NewsContract.View { 34 | 35 | @BindView(R.id.news_recyclerview) 36 | RecyclerView mRecyclerview; 37 | 38 | private static NewsFragment fragment = null; 39 | Unbinder unbinder; 40 | @BindView(R.id.progressbar) 41 | ProgressBar progressbar; 42 | 43 | private Context mContext; 44 | private final List mList = new ArrayList<>(); 45 | private NewsPresenter mPresenter; 46 | private NewsAdapter mAdapter; 47 | 48 | public static NewsFragment newInstance() { 49 | if (fragment == null) { 50 | fragment = new NewsFragment(); 51 | } 52 | return fragment; 53 | } 54 | 55 | @Override 56 | public void onAttach(Context context) { 57 | super.onAttach(context); 58 | mContext = context; 59 | } 60 | 61 | @Nullable 62 | @Override 63 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 64 | View view = inflater.inflate(R.layout.fragment_news, container, false); 65 | unbinder = ButterKnife.bind(this, view); 66 | return view; 67 | } 68 | 69 | @Override 70 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 71 | super.onViewCreated(view, savedInstanceState); 72 | 73 | //先显示加载框 74 | mRecyclerview.setVisibility(View.GONE); 75 | progressbar.setVisibility(View.VISIBLE); 76 | mPresenter = new NewsPresenter(this); 77 | mPresenter.getData(getActivity()); 78 | 79 | 80 | } 81 | 82 | private void initView() { 83 | mAdapter = new NewsAdapter(mContext, mList); 84 | mRecyclerview.setLayoutManager(new LinearLayoutManager(mContext)); 85 | mRecyclerview.setAdapter(mAdapter); 86 | mAdapter.setOnItemClickListener(new NewsAdapter.OnRecyclerViewItemClickListener() { 87 | @Override 88 | public void onItemClick(View view, int position) { 89 | String url = mList.get(position).getUrl(); 90 | if (TextUtils.isEmpty(url)) { 91 | showToast("除了第一条都可以点击"); 92 | } else { 93 | Intent intent = new Intent(getActivity(), WebActivity.class); 94 | intent.putExtra("url", url); 95 | mContext.startActivity(intent); 96 | } 97 | } 98 | }); 99 | } 100 | 101 | @Override 102 | public void onDestroyView() { 103 | super.onDestroyView(); 104 | unbinder.unbind(); 105 | } 106 | 107 | @Override 108 | public void onSuccess(List list) { 109 | mList.clear(); 110 | mList.addAll(list); 111 | mRecyclerview.setVisibility(View.VISIBLE); 112 | progressbar.setVisibility(View.GONE); 113 | initView(); 114 | } 115 | 116 | @Override 117 | public void onFailure(String error) { 118 | progressbar.setVisibility(View.GONE); 119 | showToast(error); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/ui/NewsHorFragment.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.ui; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.text.TextUtils; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.ProgressBar; 14 | 15 | import com.huaqin.recyclerviewdemo.BaseFragment; 16 | import com.huaqin.recyclerviewdemo.R; 17 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 18 | import com.huaqin.recyclerviewdemo.core.contract.NewsContract; 19 | import com.huaqin.recyclerviewdemo.core.presenter.NewsPresenter; 20 | import com.huaqin.recyclerviewdemo.core.view.adapter.NewsAdapter; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | import butterknife.BindView; 26 | import butterknife.ButterKnife; 27 | import butterknife.Unbinder; 28 | 29 | /** 30 | * Created by ubuntu on 17-4-13. 31 | */ 32 | 33 | public class NewsHorFragment extends BaseFragment implements NewsContract.View { 34 | 35 | @BindView(R.id.news_recyclerview) 36 | RecyclerView mRecyclerview; 37 | 38 | private static NewsHorFragment fragment = null; 39 | Unbinder unbinder; 40 | @BindView(R.id.progressbar) 41 | ProgressBar progressbar; 42 | 43 | private Context mContext; 44 | private final List mList = new ArrayList<>(); 45 | private NewsPresenter mPresenter; 46 | private NewsAdapter mAdapter; 47 | 48 | public static NewsHorFragment newInstance() { 49 | if (fragment == null) { 50 | fragment = new NewsHorFragment(); 51 | } 52 | return fragment; 53 | } 54 | 55 | @Override 56 | public void onAttach(Context context) { 57 | super.onAttach(context); 58 | mContext = context; 59 | } 60 | 61 | @Nullable 62 | @Override 63 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 64 | View view = inflater.inflate(R.layout.fragment_news, container, false); 65 | unbinder = ButterKnife.bind(this, view); 66 | return view; 67 | } 68 | 69 | @Override 70 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 71 | super.onViewCreated(view, savedInstanceState); 72 | 73 | //先显示加载框 74 | mRecyclerview.setVisibility(View.GONE); 75 | progressbar.setVisibility(View.VISIBLE); 76 | mPresenter = new NewsPresenter(this); 77 | mPresenter.getData(getActivity()); 78 | 79 | 80 | } 81 | 82 | private void initView() { 83 | mAdapter = new NewsAdapter(mContext, mList); 84 | LinearLayoutManager manager = new LinearLayoutManager(mContext); 85 | manager.setOrientation(LinearLayoutManager.HORIZONTAL); 86 | mRecyclerview.setLayoutManager(manager); 87 | mRecyclerview.setAdapter(mAdapter); 88 | mAdapter.setOnItemClickListener(new NewsAdapter.OnRecyclerViewItemClickListener() { 89 | @Override 90 | public void onItemClick(View view, int position) { 91 | String url = mList.get(position).getUrl(); 92 | if (TextUtils.isEmpty(url)) { 93 | showToast("除了第一条都可以点击"); 94 | } else { 95 | Intent intent = new Intent(getActivity(), WebActivity.class); 96 | intent.putExtra("url", url); 97 | mContext.startActivity(intent); 98 | } 99 | } 100 | }); 101 | } 102 | 103 | @Override 104 | public void onDestroyView() { 105 | super.onDestroyView(); 106 | unbinder.unbind(); 107 | } 108 | 109 | @Override 110 | public void onSuccess(List list) { 111 | mList.clear(); 112 | mList.addAll(list); 113 | mRecyclerview.setVisibility(View.VISIBLE); 114 | progressbar.setVisibility(View.GONE); 115 | initView(); 116 | } 117 | 118 | @Override 119 | public void onFailure(String error) { 120 | progressbar.setVisibility(View.GONE); 121 | showToast(error); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/ui/PullLoadFragment.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.ui; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.StaggeredGridLayoutManager; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | 14 | import com.huaqin.recyclerviewdemo.R; 15 | import com.huaqin.recyclerviewdemo.core.view.adapter.StaggeredAdapter; 16 | import com.huaqin.recyclerviewdemo.util.Constants; 17 | import com.huaqin.recyclerviewdemo.widget.VpRecyclerView; 18 | import com.jcodecraeer.xrecyclerview.XRecyclerView; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | import butterknife.BindView; 25 | import butterknife.ButterKnife; 26 | import butterknife.Unbinder; 27 | 28 | /** 29 | * Created by ubuntu on 17-4-13. 30 | */ 31 | 32 | public class PullLoadFragment extends Fragment { 33 | 34 | private static PullLoadFragment fragment = null; 35 | Unbinder unbinder; 36 | 37 | @BindView(R.id.recyclerview) 38 | VpRecyclerView mRecyclerview; 39 | private StaggeredAdapter mAdapter; 40 | private Context mContext; 41 | 42 | private List mList = new ArrayList<>(); 43 | 44 | public static PullLoadFragment newInstance() { 45 | if (fragment == null) { 46 | fragment = new PullLoadFragment(); 47 | } 48 | return fragment; 49 | } 50 | 51 | @Override 52 | public void onAttach(Context context) { 53 | super.onAttach(context); 54 | mContext = context; 55 | } 56 | 57 | @Nullable 58 | @Override 59 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 60 | View view = inflater.inflate(R.layout.fragment_pullload, container, false); 61 | unbinder = ButterKnife.bind(this, view); 62 | return view; 63 | } 64 | 65 | @Override 66 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 67 | super.onViewCreated(view, savedInstanceState); 68 | 69 | mList.clear(); 70 | mList.addAll(Arrays.asList(Constants.mUrls)); 71 | mAdapter = new StaggeredAdapter(mContext, mList); 72 | mRecyclerview.setLayoutManager(new StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL)); 73 | mRecyclerview.setAdapter(mAdapter); 74 | mRecyclerview.setHasFixedSize(true); 75 | mRecyclerview.setLoadingListener(new XRecyclerView.LoadingListener() { 76 | @Override 77 | public void onRefresh() { 78 | new Handler().postDelayed(new Runnable() { 79 | @Override 80 | public void run() { 81 | mRecyclerview.refreshComplete(); 82 | mList.clear(); 83 | mList.addAll(Arrays.asList(Constants.mUrls)); 84 | mAdapter.notifyDataSetChanged(); 85 | } 86 | }, 2 * 1000); 87 | } 88 | 89 | @Override 90 | public void onLoadMore() { 91 | new Handler().postDelayed(new Runnable() { 92 | @Override 93 | public void run() { 94 | mRecyclerview.loadMoreComplete(); 95 | mList.addAll(Arrays.asList(Constants.mUrls)); 96 | mAdapter.notifyDataSetChanged(); 97 | } 98 | }, 2 * 1000); 99 | } 100 | }); 101 | } 102 | 103 | @Override 104 | public void onDestroyView() { 105 | super.onDestroyView(); 106 | unbinder.unbind(); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/ui/StaggeredDemoFragment.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.ui; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.support.v7.widget.StaggeredGridLayoutManager; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | 14 | import com.huaqin.recyclerviewdemo.R; 15 | import com.huaqin.recyclerviewdemo.core.view.adapter.StaggeredAdapter; 16 | import com.huaqin.recyclerviewdemo.util.Constants; 17 | 18 | import java.util.Arrays; 19 | 20 | import butterknife.BindView; 21 | import butterknife.ButterKnife; 22 | import butterknife.Unbinder; 23 | 24 | /** 25 | * Created by ubuntu on 17-4-13. 26 | */ 27 | 28 | public class StaggeredDemoFragment extends Fragment { 29 | 30 | private static StaggeredDemoFragment fragment = null; 31 | @BindView(R.id.staggered_recyclerview) 32 | RecyclerView mRecyclerview; 33 | Unbinder unbinder; 34 | private Context mContext; 35 | private StaggeredAdapter mAdapter; 36 | 37 | 38 | public static StaggeredDemoFragment newInstance() { 39 | if (fragment == null) { 40 | fragment = new StaggeredDemoFragment(); 41 | } 42 | return fragment; 43 | } 44 | 45 | @Override 46 | public void onAttach(Context context) { 47 | super.onAttach(context); 48 | mContext = context; 49 | } 50 | 51 | @Nullable 52 | @Override 53 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 54 | View view = inflater.inflate(R.layout.fragment_staggered, container, false); 55 | unbinder = ButterKnife.bind(this, view); 56 | return view; 57 | } 58 | 59 | @Override 60 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 61 | super.onViewCreated(view, savedInstanceState); 62 | 63 | initView(); 64 | } 65 | 66 | private void initView() { 67 | mAdapter = new StaggeredAdapter(mContext, Arrays.asList(Constants.mUrls)); 68 | mRecyclerview.setLayoutManager(new StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL)); 69 | mRecyclerview.setAdapter(mAdapter); 70 | } 71 | 72 | 73 | @Override 74 | public void onDestroyView() { 75 | super.onDestroyView(); 76 | unbinder.unbind(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/ui/TencentFragment.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.ui; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import com.huaqin.recyclerviewdemo.R; 14 | import com.huaqin.recyclerviewdemo.core.view.adapter.TecentAdapter; 15 | 16 | import butterknife.BindView; 17 | import butterknife.ButterKnife; 18 | import butterknife.Unbinder; 19 | 20 | /** 21 | * Created by ubuntu on 17-4-13. 22 | */ 23 | 24 | public class TencentFragment extends Fragment { 25 | 26 | private static TencentFragment fragment = null; 27 | Unbinder unbinder; 28 | 29 | @BindView(R.id.tencent_recyclerview) 30 | RecyclerView mRecyclerview; 31 | private Context mContext; 32 | 33 | public static TencentFragment newInstance() { 34 | if (fragment == null) { 35 | fragment = new TencentFragment(); 36 | } 37 | return fragment; 38 | } 39 | 40 | @Override 41 | public void onAttach(Context context) { 42 | super.onAttach(context); 43 | mContext = context; 44 | } 45 | 46 | @Nullable 47 | @Override 48 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 49 | View view = inflater.inflate(R.layout.fragment_tencent, container, false); 50 | unbinder = ButterKnife.bind(this, view); 51 | return view; 52 | } 53 | 54 | @Override 55 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 56 | super.onViewCreated(view, savedInstanceState); 57 | 58 | mRecyclerview.setLayoutManager(new LinearLayoutManager(mContext)); 59 | mRecyclerview.setAdapter(new TecentAdapter(getActivity(), mContext)); 60 | } 61 | 62 | @Override 63 | public void onDestroyView() { 64 | super.onDestroyView(); 65 | unbinder.unbind(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/core/view/ui/WebActivity.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.core.view.ui; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.widget.RelativeLayout; 7 | 8 | import com.huaqin.recyclerviewdemo.BaseToolbarActivity; 9 | import com.huaqin.recyclerviewdemo.R; 10 | import com.huaqin.recyclerviewdemo.widget.ProgressWebView; 11 | 12 | import butterknife.BindView; 13 | import butterknife.ButterKnife; 14 | 15 | public class WebActivity extends BaseToolbarActivity { 16 | 17 | @BindView(R.id.activity_web_view) 18 | RelativeLayout activityWebView; 19 | private ProgressWebView mWebView; 20 | 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | ButterKnife.bind(this); 26 | 27 | mWebView = new ProgressWebView(this); 28 | activityWebView.addView(mWebView); 29 | 30 | Intent intent = getIntent(); 31 | String actionUrl = intent.getStringExtra("url"); 32 | mWebView.loadUrl(actionUrl); 33 | 34 | initToolBar(); 35 | } 36 | 37 | private void initToolBar() { 38 | setTitle(""); 39 | } 40 | 41 | @Override 42 | public int getLayoutId() { 43 | return R.layout.activity_web; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/retrofit/ApiManager.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.retrofit; 2 | 3 | /** 4 | * Created by ubuntu on 17-4-13. 5 | */ 6 | 7 | public class ApiManager { 8 | 9 | private static ApiManager util = null; 10 | private INewsApi mApiNews; 11 | 12 | /** 13 | * 单例 14 | * 15 | * @return 16 | */ 17 | public static ApiManager getInstance() { 18 | if (util == null) { 19 | util = new ApiManager(); 20 | } 21 | return util; 22 | } 23 | 24 | 25 | /** 26 | * news接口 27 | * 28 | * @return 29 | */ 30 | public INewsApi apiNews() { 31 | if (mApiNews == null) { 32 | mApiNews = RetrofitClient.getInstance().create("http://c.m.163.com", INewsApi.class); 33 | } 34 | return mApiNews; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/retrofit/INewsApi.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.retrofit; 2 | 3 | import com.google.gson.JsonObject; 4 | import com.huaqin.recyclerviewdemo.core.bean.NewsItem; 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONObject; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import retrofit2.http.GET; 13 | import retrofit2.http.Path; 14 | import rx.Observable; 15 | 16 | /** 17 | * Created by ubuntu on 17-4-13. 18 | */ 19 | 20 | public interface INewsApi { 21 | 22 | @GET("/nc/article/list/{explore_id}/{offset}-{limit}.html") 23 | Observable>> getNewsList( 24 | @Path("explore_id") String explore_id, 25 | @Path("offset") int page, 26 | @Path("limit") int limit 27 | 28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/retrofit/RetrofitClient.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.retrofit; 2 | 3 | import android.util.Log; 4 | 5 | import com.huaqin.recyclerviewdemo.App; 6 | import com.huaqin.recyclerviewdemo.util.FileUtil; 7 | import com.huaqin.recyclerviewdemo.util.InternetUtil; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.util.concurrent.TimeUnit; 12 | 13 | import okhttp3.Cache; 14 | import okhttp3.Interceptor; 15 | import okhttp3.OkHttpClient; 16 | import okhttp3.Request; 17 | import okhttp3.Response; 18 | import okhttp3.logging.HttpLoggingInterceptor; 19 | import retrofit2.Retrofit; 20 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 21 | import retrofit2.converter.gson.GsonConverterFactory; 22 | 23 | /** 24 | * Created by ubuntu on 17-4-13. 25 | */ 26 | 27 | public class RetrofitClient { 28 | private final String TAG = "RetrofitClient"; 29 | private static RetrofitClient sNewInstance; 30 | private OkHttpClient okHttpClient; 31 | private int mTimeOut = 60; 32 | 33 | private RetrofitClient() { 34 | initClient(false); 35 | } 36 | 37 | public static RetrofitClient getInstance() { 38 | if (sNewInstance == null) { 39 | sNewInstance = new RetrofitClient(); 40 | } 41 | return sNewInstance; 42 | } 43 | 44 | 45 | private void initClient(boolean addHead) { 46 | //缓存目录 47 | File httpCacheDirectory = new File(FileUtil.getAvailableCacheDir(), "responses"); 48 | Cache cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); 49 | 50 | HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { 51 | @Override 52 | public void log(String message) { 53 | //打印retrofit日志 54 | Log.i("RetrofitLog", "retrofitBack = " + message); 55 | // if(message.contains("UnknownHostException")){ 56 | // LogCat.i("NO network"); 57 | // } 58 | } 59 | }); 60 | loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 61 | if (addHead) { 62 | okHttpClient = new OkHttpClient.Builder() 63 | .addInterceptor(interceptor) 64 | .addInterceptor(loggingInterceptor) 65 | .cache(cache) 66 | .connectTimeout(mTimeOut, TimeUnit.SECONDS) 67 | .readTimeout(mTimeOut, TimeUnit.SECONDS) 68 | .writeTimeout(mTimeOut, TimeUnit.SECONDS) 69 | .build(); 70 | 71 | } else { 72 | okHttpClient = new OkHttpClient.Builder() 73 | .cache(cache) 74 | .addInterceptor(loggingInterceptor) 75 | .connectTimeout(mTimeOut, TimeUnit.SECONDS) 76 | .readTimeout(mTimeOut, TimeUnit.SECONDS) 77 | .writeTimeout(mTimeOut, TimeUnit.SECONDS) 78 | .build(); 79 | } 80 | } 81 | 82 | //设置网络请求缓存 83 | Interceptor interceptor = new Interceptor() { 84 | @Override 85 | public Response intercept(Chain chain) throws IOException { 86 | Request request = chain.request(); 87 | Response response = chain.proceed(request); 88 | 89 | if (InternetUtil.isNetworkConnected(App.singleton)) {//网络正常时 90 | int maxAge = 0 * 60; // 有网络时 设置缓存超时时间0个小时 91 | Log.i(TAG, "has network maxAge=" + maxAge); 92 | response.newBuilder() 93 | .header("Cache-Control", "public, max-age=" + maxAge) 94 | .removeHeader("Pragma")// 清除头信息,因为服务器如果不支持,会返回一些干扰信息,不清除下面无法生效 95 | .build(); 96 | } else { 97 | Log.i(TAG, "no network"); 98 | int maxStale = 60 * 60 * 24 * 28; // 无网络时,设置超时为4周 99 | Log.i(TAG, "has maxStale=" + maxStale); 100 | response.newBuilder() 101 | .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale) 102 | .removeHeader("Pragma") 103 | .build(); 104 | Log.i(TAG, "response build maxStale=" + maxStale); 105 | } 106 | return response; 107 | } 108 | }; 109 | 110 | 111 | public T create(String baseUrl, Class service) { 112 | Retrofit retrofit = new Retrofit.Builder() 113 | .baseUrl(baseUrl) 114 | .client(okHttpClient) 115 | .addConverterFactory(GsonConverterFactory.create()) 116 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 117 | .build(); 118 | return retrofit.create(service); 119 | } 120 | 121 | // public T createByXML(String baseUrl, Class service){ 122 | // Retrofit retrofit = new Retrofit.Builder() 123 | // .baseUrl(baseUrl) 124 | // .client(okHttpClient) 125 | // .addConverterFactory(SimpleXmlConverterFactory.create()) 126 | // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 127 | // .build(); 128 | // return retrofit.create(service); 129 | // } 130 | } 131 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.util; 2 | 3 | /** 4 | * Created by ubuntu on 17-4-13. 5 | */ 6 | 7 | public class Constants { 8 | public static final String[] mUrls = { 9 | "http://file.juzimi.com/weibopic/jizema7.jpg", 10 | "http://file.juzimi.com/weibopic/jezime3.jpg", 11 | "http://file.juzimi.com/weibopic/jizrmx5.jpg", 12 | "http://file.juzimi.com/weibopic/jlzxma7.jpg", 13 | "http://file.juzimi.com/weibopic/jlzump.jpg", 14 | "http://file.juzimi.com/weibopic/jxzlmr2.jpg", 15 | "http://file.juzimi.com/weibopic/jizdmr.jpg", 16 | "http://file.juzimi.com/weibopic/jrzpmd7.jpg", 17 | "http://file.juzimi.com/weibopic/jozemx7.jpg", 18 | "http://file.juzimi.com/weibopic/jizdmx6.jpg", 19 | "http://file.juzimi.com/weibopic/jozumo5.jpg", 20 | "http://file.juzimi.com/weibopic/jozami5.jpg", 21 | "http://file.juzimi.com/weibopic/jrzdma5.jpg", 22 | "http://file.juzimi.com/weibopic/jozrmu4.jpg", 23 | "http://file.juzimi.com/weibopic/jlzpmu5.jpg", 24 | "http://file.juzimi.com/weibopic/jxzeml6.jpg", 25 | "http://file.juzimi.com/weibopic/jlzimx4.jpg", 26 | "http://file.juzimi.com/weibopic/jxzump5.jpg", 27 | "http://file.juzimi.com/weibopic/jizemo3.jpg", 28 | "http://file.juzimi.com/weibopic/jdzrme.jpg", 29 | "http://file.juzimi.com/weibopic/jozemo.jpg" 30 | }; 31 | 32 | public static final String[] mBannerNames = { 33 | "错过那天那张雨", 34 | "彼岸花开三色天", 35 | "基督山伯爵", 36 | "侄子之手", 37 | "夏目友人帐", 38 | "陪我西西里看海" 39 | }; 40 | 41 | public static final String[] mSubTitles = { 42 | "经得住多大的诋毁,才受得住多大的赞美。", 43 | "经得住多大的诋毁,才受得住多大的赞美。", 44 | "经得住多大的诋毁,才受得住多大的赞美。", 45 | "经得住多大的诋毁,才受得住多大的赞美。", 46 | "经得住多大的诋毁,才受得住多大的赞美。", 47 | "陪我到可可西里看一看海,不要未来 只要你来。" 48 | }; 49 | public static final String[] mBannerUrls = { 50 | "http://file.juzimi.com/weibopic/jazrmp3.jpg", 51 | "http://file.juzimi.com/weibopic/jizpma7.jpg", 52 | "http://file.juzimi.com/weibopic/jxzlmx4.jpg", 53 | "http://file.juzimi.com/weibopic/jpzame3.jpg", 54 | "http://file.juzimi.com/weibopic/jizdmu3.jpg", 55 | "http://file.juzimi.com/weibopic/jizlml6.jpg" 56 | }; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/util/FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.util; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.os.Environment; 6 | import android.util.Log; 7 | 8 | import com.huaqin.recyclerviewdemo.App; 9 | 10 | import java.io.BufferedReader; 11 | import java.io.File; 12 | import java.io.FileInputStream; 13 | import java.io.FileNotFoundException; 14 | import java.io.FileOutputStream; 15 | import java.io.IOException; 16 | import java.io.InputStreamReader; 17 | 18 | /** 19 | * Created by ubuntu on 17-4-13. 20 | */ 21 | 22 | public class FileUtil { 23 | private static boolean isExternalStorageWritable() { 24 | String state = Environment.getExternalStorageState(); 25 | return Environment.MEDIA_MOUNTED.equals(state); 26 | } 27 | 28 | public static File getAvailableCacheDir() { 29 | if (isExternalStorageWritable()) { 30 | return App.singleton.getExternalCacheDir(); 31 | } else { 32 | return App.singleton.getCacheDir(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/util/ImageLoader.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.util; 2 | 3 | import android.content.Context; 4 | import android.text.TextUtils; 5 | import android.widget.ImageView; 6 | 7 | import com.huaqin.recyclerviewdemo.R; 8 | import com.squareup.picasso.Picasso; 9 | 10 | /** 11 | * Created by ubuntu on 17-4-13. 12 | */ 13 | 14 | public class ImageLoader { 15 | 16 | private static ImageLoader imageLoader = null; 17 | 18 | public static ImageLoader getInstance() { 19 | if (imageLoader == null) { 20 | imageLoader = new ImageLoader(); 21 | } 22 | return imageLoader; 23 | } 24 | 25 | //网络图片加载 placeholder 26 | public void showImage(Context context, String url, ImageView imageView) { 27 | //要先判断url是否为空,不然Picasso会报异常 28 | if (!TextUtils.isEmpty(url)) { 29 | Picasso 30 | .with(context) 31 | .load(url) 32 | .placeholder(R.drawable.place_holder) 33 | .error(R.drawable.place_holder) 34 | .into(imageView); 35 | } else { 36 | imageView.setImageResource(R.drawable.place_holder); 37 | } 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/util/InternetUtil.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.util; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.DhcpInfo; 6 | import android.net.NetworkInfo; 7 | import android.net.wifi.WifiInfo; 8 | import android.net.wifi.WifiManager; 9 | import android.telephony.TelephonyManager; 10 | import android.util.Log; 11 | 12 | import java.io.BufferedReader; 13 | import java.io.FileInputStream; 14 | import java.io.FileNotFoundException; 15 | import java.io.IOException; 16 | import java.io.InputStreamReader; 17 | import java.io.UnsupportedEncodingException; 18 | import java.lang.reflect.Method; 19 | import java.net.Inet4Address; 20 | import java.net.InetAddress; 21 | import java.net.NetworkInterface; 22 | import java.net.SocketException; 23 | import java.util.ArrayList; 24 | import java.util.Enumeration; 25 | 26 | /** 27 | * Created by ubuntu on 17-4-13. 28 | */ 29 | 30 | public class InternetUtil { 31 | private static final String TAG = InternetUtil.class.getSimpleName(); 32 | //没有网络连接 33 | public static final int NETWORN_NONE = 0; 34 | //wifi连接 35 | public static final int NETWORN_WIFI = 1; 36 | //手机网络数据连接类型 37 | public static final int NETWORN_2G = 2; 38 | public static final int NETWORN_3G = 3; 39 | public static final int NETWORN_4G = 4; 40 | public static final int NETWORN_MOBILE = 5; 41 | 42 | /** 43 | * 判断当前网络是否可用 44 | * 45 | * @param context 46 | * @return 47 | */ 48 | public static boolean isNetworkConnected(Context context) { 49 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService 50 | (Context.CONNECTIVITY_SERVICE); 51 | NetworkInfo ni = connectivityManager.getActiveNetworkInfo(); 52 | return ni != null && ni.isConnectedOrConnecting(); 53 | } 54 | 55 | /** 56 | * 获取当前网络连接类型 57 | * 58 | * @param context 59 | * @return 60 | */ 61 | public static int getNetworkState(Context context) { 62 | //获取系统的网络服务 63 | ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context 64 | .CONNECTIVITY_SERVICE); 65 | 66 | //如果当前没有网络 67 | if (null == connManager) 68 | return NETWORN_NONE; 69 | 70 | //获取当前网络类型,如果为空,返回无网络 71 | NetworkInfo activeNetInfo = connManager.getActiveNetworkInfo(); 72 | if (activeNetInfo == null || !activeNetInfo.isAvailable()) { 73 | return NETWORN_NONE; 74 | } 75 | 76 | // 判断是不是连接的是不是wifi 77 | NetworkInfo wifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 78 | if (null != wifiInfo) { 79 | NetworkInfo.State state = wifiInfo.getState(); 80 | if (null != state) 81 | if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) { 82 | return NETWORN_WIFI; 83 | } 84 | } 85 | 86 | // 如果不是wifi,则判断当前连接的是运营商的哪种网络2g、3g、4g等 87 | NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); 88 | 89 | if (null != networkInfo) { 90 | NetworkInfo.State state = networkInfo.getState(); 91 | String strSubTypeName = networkInfo.getSubtypeName(); 92 | if (null != state) 93 | if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) { 94 | switch (activeNetInfo.getSubtype()) { 95 | //如果是2g类型 96 | case TelephonyManager.NETWORK_TYPE_GPRS: // 联通2g 97 | case TelephonyManager.NETWORK_TYPE_CDMA: // 电信2g 98 | case TelephonyManager.NETWORK_TYPE_EDGE: // 移动2g 99 | case TelephonyManager.NETWORK_TYPE_1xRTT: 100 | case TelephonyManager.NETWORK_TYPE_IDEN: 101 | return NETWORN_2G; 102 | //如果是3g类型 103 | case TelephonyManager.NETWORK_TYPE_EVDO_A: // 电信3g 104 | case TelephonyManager.NETWORK_TYPE_UMTS: 105 | case TelephonyManager.NETWORK_TYPE_EVDO_0: 106 | case TelephonyManager.NETWORK_TYPE_HSDPA: 107 | case TelephonyManager.NETWORK_TYPE_HSUPA: 108 | case TelephonyManager.NETWORK_TYPE_HSPA: 109 | case TelephonyManager.NETWORK_TYPE_EVDO_B: 110 | case TelephonyManager.NETWORK_TYPE_EHRPD: 111 | case TelephonyManager.NETWORK_TYPE_HSPAP: 112 | return NETWORN_3G; 113 | //如果是4g类型 114 | case TelephonyManager.NETWORK_TYPE_LTE: 115 | return NETWORN_4G; 116 | default: 117 | //中国移动 联通 电信 三种3G制式 118 | if (strSubTypeName.equalsIgnoreCase("TD-SCDMA") || strSubTypeName 119 | .equalsIgnoreCase("WCDMA") || strSubTypeName.equalsIgnoreCase 120 | ("CDMA2000")) { 121 | return NETWORN_3G; 122 | } else { 123 | return NETWORN_MOBILE; 124 | } 125 | } 126 | } 127 | } 128 | return NETWORN_NONE; 129 | } 130 | 131 | 132 | /** 133 | * 判断当前是否为gprs网络 134 | * 135 | * @author gut 136 | */ 137 | public static boolean isGPRS(Context context) { 138 | ConnectivityManager connectivityManager = (ConnectivityManager) context 139 | .getSystemService(Context.CONNECTIVITY_SERVICE); 140 | NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); 141 | return activeNetInfo != null 142 | && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE; 143 | } 144 | 145 | /** 146 | * 获取网络类型 147 | * 148 | * @return 149 | */ 150 | public static String getNetWorkType(Context context) { 151 | ConnectivityManager connectMgr = (ConnectivityManager) context 152 | .getSystemService(Context.CONNECTIVITY_SERVICE); 153 | 154 | NetworkInfo info = connectMgr.getActiveNetworkInfo(); 155 | String type = ""; 156 | if (info != null) { 157 | switch (info.getType()) { 158 | case ConnectivityManager.TYPE_WIFI: 159 | type = "WIFI"; 160 | break; 161 | case ConnectivityManager.TYPE_MOBILE: 162 | switch (info.getSubtype()) { 163 | case TelephonyManager.NETWORK_TYPE_LTE: // 4G 164 | case TelephonyManager.NETWORK_TYPE_HSPAP: 165 | case TelephonyManager.NETWORK_TYPE_EHRPD: 166 | type = "4G"; 167 | break; 168 | case TelephonyManager.NETWORK_TYPE_UMTS: // 3G 169 | case TelephonyManager.NETWORK_TYPE_CDMA: 170 | case TelephonyManager.NETWORK_TYPE_EVDO_0: 171 | case TelephonyManager.NETWORK_TYPE_EVDO_A: 172 | case TelephonyManager.NETWORK_TYPE_EVDO_B: 173 | type = "3G"; 174 | break; 175 | case TelephonyManager.NETWORK_TYPE_GPRS: // 2G 176 | case TelephonyManager.NETWORK_TYPE_EDGE: 177 | type = "2G"; 178 | break; 179 | } 180 | break; 181 | } 182 | } 183 | return type; 184 | } 185 | 186 | /** 187 | * 判断是否有网络 188 | * 189 | * @param error 190 | * @return 191 | */ 192 | public static boolean isNoNetwork(String error) { 193 | if (error.contains("UnknownHostException") || error.contains("TimeoutException") || error.contains("ConnectException")) { 194 | return true; 195 | } else { 196 | return false; 197 | } 198 | } 199 | 200 | /** 201 | * 获取ssid信息 202 | * 203 | * @param context 204 | * @return 205 | */ 206 | public static String getSSID(Context context) { 207 | String result = ""; 208 | WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 209 | WifiInfo wifiInfo = wifiManager.getConnectionInfo(); 210 | if (wifiInfo != null) { 211 | result = wifiInfo.getSSID(); 212 | } 213 | return result; 214 | } 215 | 216 | /** 217 | * 获取网关信息 218 | */ 219 | public static String getWifiGateWay(Context context) { 220 | String result = null; 221 | WifiManager wifi_service = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 222 | DhcpInfo dhcpInfo = wifi_service.getDhcpInfo(); 223 | result = long2Ip((long) dhcpInfo.gateway); 224 | return result; 225 | } 226 | 227 | /** 228 | * 将long类型转换成ip 229 | * 230 | * @param ip 231 | * @return 232 | */ 233 | private static String long2Ip(long ip) { 234 | StringBuffer sb = new StringBuffer(); 235 | sb.append(String.valueOf((int) (ip & 255L))); 236 | sb.append('.'); 237 | sb.append(String.valueOf((int) (ip >> 8 & 255L))); 238 | sb.append('.'); 239 | sb.append(String.valueOf((int) (ip >> 16 & 255L))); 240 | sb.append('.'); 241 | sb.append(String.valueOf((int) (ip >> 24 & 255L))); 242 | return sb.toString(); 243 | } 244 | 245 | /** 246 | * 获取网关Mac地址 247 | * 248 | * @param gateWay 249 | * @return 250 | */ 251 | public static String getGateWayMac(String gateWay) { 252 | Log.d(TAG, "getGateWayMac() start gateWay=" + gateWay); 253 | String result = ""; 254 | String gatewaymacfile = readFile("/proc/net/arp"); 255 | if (gatewaymacfile != null && gatewaymacfile.length() > 0) { 256 | String[] tmp = gatewaymacfile.split(gateWay + " "); 257 | if (tmp.length >= 2) { 258 | String temp = tmp[1]; 259 | int test = temp.indexOf(":"); 260 | if (test - 2 >= 0 && test + 15 <= temp.length()) { 261 | result = temp.substring(test - 2, test + 15); 262 | result = result.toLowerCase(); 263 | } else { 264 | Log.d(TAG, "getGateWayMac() string is error temp=" + temp); 265 | } 266 | } else { 267 | Log.d(TAG, "getGateWayMac() not gateWayMac"); 268 | } 269 | } else { 270 | Log.d(TAG, "getGateWayMac() read /proc/net/arp file failed."); 271 | } 272 | 273 | Log.d(TAG, "getGateWayMac() end result=" + result); 274 | return result; 275 | } 276 | 277 | public static String readFile(String filePath) { 278 | StringBuffer result = new StringBuffer(); 279 | String line = null; 280 | 281 | try { 282 | BufferedReader e = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "GBK")); 283 | 284 | while ((line = e.readLine()) != null) { 285 | result.append(line).append("\n"); 286 | } 287 | } catch (UnsupportedEncodingException var8) { 288 | var8.printStackTrace(); 289 | } catch (FileNotFoundException var9) { 290 | var9.printStackTrace(); 291 | } catch (IOException var10) { 292 | var10.printStackTrace(); 293 | } finally { 294 | ; 295 | } 296 | 297 | Log.d(TAG, "readFile() end result=" + result.toString()); 298 | return result.toString(); 299 | } 300 | 301 | /** 302 | * 获取ip地址 303 | * 304 | * @param connectType 305 | * @return 306 | */ 307 | public static String getLocalIP(int connectType) { 308 | Log.d(TAG, "getLocalIP() start"); 309 | String result = ""; 310 | if (connectType == 1) { 311 | result = getSystemProperties("dhcp.eth0.ipaddress"); 312 | } else { 313 | try { 314 | Enumeration ex = NetworkInterface.getNetworkInterfaces(); 315 | 316 | while (ex.hasMoreElements()) { 317 | NetworkInterface intf = (NetworkInterface) ex.nextElement(); 318 | Enumeration enumIPAddr = intf.getInetAddresses(); 319 | 320 | while (enumIPAddr.hasMoreElements()) { 321 | InetAddress inetAddress = (InetAddress) enumIPAddr.nextElement(); 322 | if (!inetAddress.isLoopbackAddress() && inetAddress instanceof 323 | Inet4Address) { 324 | result = inetAddress.getHostAddress().toString(); 325 | break; 326 | } 327 | } 328 | 329 | if (result != null && result.length() > 0) { 330 | break; 331 | } 332 | } 333 | } catch (SocketException var6) { 334 | result = ""; 335 | System.err.print("error"); 336 | } 337 | } 338 | 339 | Log.d(TAG, "getLocalIP() end"); 340 | return result; 341 | } 342 | 343 | public static String getSystemProperties(String key) { 344 | Log.d(TAG, "getSystemProperties() start key=" + key); 345 | String str = null; 346 | 347 | try { 348 | Class e = Class.forName("android.os.SystemProperties"); 349 | Method get = e.getMethod("get", new Class[]{String.class}); 350 | str = (String) get.invoke(e, new Object[]{key}); 351 | } catch (Exception var4) { 352 | var4.printStackTrace(); 353 | } 354 | 355 | Log.d(TAG, "getSystemProperties() end result=" + str); 356 | return str; 357 | } 358 | 359 | public static int getNetworkType(Context context) { 360 | Log.d(TAG, "getNetworkType() start."); 361 | byte result = -1; 362 | ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context 363 | .CONNECTIVITY_SERVICE); 364 | NetworkInfo active = cm.getActiveNetworkInfo(); 365 | if (active != null) { 366 | int type = active.getType(); 367 | switch (type) { 368 | case 0: 369 | result = 4; 370 | break; 371 | case 1: 372 | result = 2; 373 | break; 374 | case 9: 375 | if (hasPPPoEInterface()) { 376 | result = 3; 377 | } else { 378 | result = 1; 379 | } 380 | } 381 | } else { 382 | Log.d(TAG, "getNetworkType() not ActiveNetwork."); 383 | } 384 | 385 | Log.d(TAG, "getNetworkType() end result=" + result); 386 | return result; 387 | } 388 | 389 | private static boolean hasPPPoEInterface() { 390 | Log.d(TAG, "hasPPPoEInterface() start."); 391 | boolean result = false; 392 | ArrayList nameList = new ArrayList(); 393 | 394 | try { 395 | Enumeration nis = NetworkInterface.getNetworkInterfaces(); 396 | 397 | while (nis.hasMoreElements()) { 398 | NetworkInterface i = (NetworkInterface) nis.nextElement(); 399 | nameList.add(i.getName()); 400 | } 401 | } catch (SocketException var4) { 402 | var4.printStackTrace(); 403 | } 404 | 405 | for (int var5 = 0; var5 < nameList.size(); ++var5) { 406 | if (((String) nameList.get(var5)).contains("ppp0")) { 407 | result = true; 408 | break; 409 | } 410 | } 411 | 412 | Log.d(TAG, "hasPPPoEInterface() end result = " + result); 413 | return result; 414 | } 415 | } 416 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/widget/NoScrollGridView.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.GridView; 6 | 7 | /** 8 | * Created by ubuntu on 17-4-14. 9 | */ 10 | 11 | public class NoScrollGridView extends GridView { 12 | 13 | public NoScrollGridView(Context context, AttributeSet attrs, int defStyle) { 14 | super(context, attrs, defStyle); 15 | // TODO Auto-generated constructor stub 16 | } 17 | 18 | public NoScrollGridView(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | // TODO Auto-generated constructor stub 21 | } 22 | 23 | public NoScrollGridView(Context context) { 24 | super(context); 25 | // TODO Auto-generated constructor stub 26 | } 27 | 28 | @Override 29 | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 30 | 31 | int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, 32 | MeasureSpec.AT_MOST); 33 | super.onMeasure(widthMeasureSpec, expandSpec); 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/widget/PicassoImageLoader.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.widget; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | import android.widget.ImageView; 6 | 7 | import com.huaqin.recyclerviewdemo.util.ImageLoader; 8 | 9 | /** 10 | * Created by ubuntu on 17-4-14. 11 | */ 12 | 13 | public class PicassoImageLoader extends com.youth.banner.loader.ImageLoader { 14 | 15 | 16 | @Override 17 | public void displayImage(Context context, Object path, ImageView imageView) { 18 | //要先判断url是否为空,不然Picasso会报异常 19 | String url = (String) path; 20 | ImageLoader.getInstance().showImage(context, url, imageView); 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/widget/ProgressWebView.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.webkit.WebResourceError; 7 | import android.webkit.WebResourceRequest; 8 | import android.webkit.WebSettings; 9 | import android.webkit.WebView; 10 | import android.webkit.WebViewClient; 11 | import android.widget.ProgressBar; 12 | 13 | import com.huaqin.recyclerviewdemo.R; 14 | 15 | /** 16 | * Created by ubuntu on 17-4-13. 17 | */ 18 | 19 | public class ProgressWebView extends WebView { 20 | 21 | private ProgressBar progressbar; 22 | private Context mContext; 23 | 24 | public ProgressWebView(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | mContext = context; 27 | } 28 | 29 | public ProgressWebView(Context context) { 30 | super(context); 31 | mContext = context; 32 | progressbar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal); 33 | progressbar.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 5, 0, 0)); 34 | progressbar.setProgressDrawable(context.getResources().getDrawable(R.drawable.progress_bar)); 35 | addView(progressbar); 36 | //设置 缓存模式 37 | getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); 38 | // 开启 DOM storage API 功能 39 | getSettings().setDomStorageEnabled(true); 40 | setVerticalScrollBarEnabled(false); 41 | setHorizontalScrollBarEnabled(false); 42 | getSettings().setJavaScriptEnabled(true); 43 | setWebChromeClient(new WebChromeClient()); 44 | setWebViewClient(new MyWebViewClient()); 45 | 46 | } 47 | 48 | public class WebChromeClient extends android.webkit.WebChromeClient { 49 | 50 | @Override 51 | public void onProgressChanged(WebView view, int newProgress) { 52 | if (newProgress == 100) { 53 | progressbar.setVisibility(View.GONE); 54 | } else { 55 | if (progressbar.getVisibility() == View.GONE) 56 | progressbar.setVisibility(View.VISIBLE); 57 | progressbar.setProgress(newProgress); 58 | } 59 | super.onProgressChanged(view, newProgress); 60 | } 61 | 62 | } 63 | 64 | private class MyWebViewClient extends WebViewClient { 65 | @Override 66 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 67 | view.setVisibility(View.VISIBLE); 68 | view.loadUrl(url); 69 | return true; 70 | } 71 | 72 | @Override 73 | public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) { 74 | super.doUpdateVisitedHistory(view, url, isReload); 75 | } 76 | 77 | @Override 78 | public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { 79 | super.onReceivedError(view, request, error); 80 | } 81 | 82 | @Override 83 | public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 84 | super.onReceivedError(view, errorCode, description, failingUrl); 85 | } 86 | } 87 | 88 | @Override 89 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { 90 | LayoutParams lp = (LayoutParams) progressbar.getLayoutParams(); 91 | lp.x = l; 92 | lp.y = t; 93 | progressbar.setLayoutParams(lp); 94 | super.onScrollChanged(l, t, oldl, oldt); 95 | } 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/widget/RecyclerWidgetProvider.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.widget; 2 | 3 | import android.app.PendingIntent; 4 | import android.appwidget.AppWidgetManager; 5 | import android.appwidget.AppWidgetProvider; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | import android.util.Log; 10 | import android.widget.RemoteViews; 11 | import android.widget.Toast; 12 | 13 | import com.huaqin.recyclerviewdemo.MainActivity; 14 | import com.huaqin.recyclerviewdemo.R; 15 | import com.huaqin.recyclerviewdemo.core.view.WelcomeActivity; 16 | 17 | /** 18 | * Created by ubuntu on 17-4-24. 19 | */ 20 | 21 | public class RecyclerWidgetProvider extends AppWidgetProvider { 22 | public RecyclerWidgetProvider() { 23 | super(); 24 | } 25 | 26 | @Override 27 | public void onReceive(Context context, Intent intent) { 28 | super.onReceive(context, intent); 29 | } 30 | 31 | /** 32 | * 根据 updatePeriodMillis 定义的定期刷新操作会调用该函数,此外当用户添加 Widget 时也会调用该函数,可以在这里进行必要的初始化操作。 33 | * @param context 34 | * @param appWidgetManager 35 | * @param appWidgetIds 36 | */ 37 | @Override 38 | public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 39 | super.onUpdate(context, appWidgetManager, appWidgetIds); 40 | Log.i("shenlong", "onUpdate"); 41 | for (int i = 0; i < appWidgetIds.length; i++) { 42 | int appWidgetId = appWidgetIds[i]; 43 | Log.i("shenlong", "onUpdate appWidgetId=" + appWidgetId); 44 | Intent intent = new Intent(); 45 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | 46 | Intent.FLAG_ACTIVITY_TASK_ON_HOME); 47 | intent.setClass(context, MainActivity.class); 48 | PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 49 | 50 | // Get the layout for the App Widget and attach an on-click listener 51 | // to the button 52 | RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); 53 | views.setOnClickPendingIntent(R.id.iv_widget, pendingIntent); 54 | 55 | // Tell the AppWidgetManager to perform an update on the current app widget 56 | appWidgetManager.updateAppWidget(appWidgetId, views); 57 | } 58 | } 59 | 60 | 61 | /** 62 | * 当 Widget 被删除时调用该方法。 63 | * 64 | * @param context 65 | * @param appWidgetIds 66 | */ 67 | @Override 68 | public void onDeleted(Context context, int[] appWidgetIds) { 69 | super.onDeleted(context, appWidgetIds); 70 | Toast.makeText(context, "onDeleted", Toast.LENGTH_SHORT).show(); 71 | } 72 | 73 | /** 74 | * 当 Widget 第一次被添加时调用,例如用户添加了两个你的 Widget,那么只有在添加第一个 Widget 时该方法会被调用。 75 | * 所以该方法比较适合执行你所有 Widgets 只需进行一次的操作 76 | * 77 | * @param context 78 | */ 79 | @Override 80 | public void onEnabled(Context context) { 81 | super.onEnabled(context); 82 | } 83 | 84 | /** 85 | * 与 onEnabled 恰好相反,当你的最后一个 Widget 被删除时调用该方法,所以这里用来清理之前在 onEnabled() 中进行的操作。 86 | * 87 | * @param context 88 | */ 89 | @Override 90 | public void onDisabled(Context context) { 91 | super.onDisabled(context); 92 | } 93 | 94 | /** 95 | * 当 Widget 第一次被添加或者大小发生变化时调用该方法,可以在此控制 Widget 元素的显示和隐藏。 96 | * 97 | * @param context 98 | * @param appWidgetManager 99 | * @param appWidgetId 100 | * @param newOptions 101 | */ 102 | @Override 103 | public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) { 104 | super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions); 105 | } 106 | 107 | @Override 108 | public void onRestored(Context context, int[] oldWidgetIds, int[] newWidgetIds) { 109 | super.onRestored(context, oldWidgetIds, newWidgetIds); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/com/huaqin/recyclerviewdemo/widget/VpRecyclerView.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | 7 | import com.jcodecraeer.xrecyclerview.ProgressStyle; 8 | import com.jcodecraeer.xrecyclerview.XRecyclerView; 9 | 10 | /** 11 | * Created by ubuntu on 17-4-13. 12 | */ 13 | 14 | public class VpRecyclerView extends XRecyclerView { 15 | public static final int NONE = 0; 16 | //状态刷新 17 | public static final int REFRESH = 1; 18 | //状态加载更多 19 | public static final int LOADMORE = 2; 20 | private int curState = NONE; 21 | 22 | public VpRecyclerView(Context context) { 23 | super(context); 24 | setRefreshLoadingMoreStyle(); 25 | setOverScrollMode(View.OVER_SCROLL_NEVER); 26 | } 27 | 28 | public VpRecyclerView(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | setRefreshLoadingMoreStyle(); 31 | setOverScrollMode(View.OVER_SCROLL_NEVER); 32 | } 33 | 34 | public VpRecyclerView(Context context, AttributeSet attrs, int defStyle) { 35 | super(context, attrs, defStyle); 36 | setRefreshLoadingMoreStyle(); 37 | setOverScrollMode(View.OVER_SCROLL_NEVER); 38 | } 39 | 40 | /** 41 | * 统一设置下拉刷新及上拉加载更多样式 42 | */ 43 | private void setRefreshLoadingMoreStyle() { 44 | setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); 45 | setLoadingMoreProgressStyle(ProgressStyle.BallSpinFadeLoader); 46 | } 47 | 48 | /** 49 | * 设置没有更多可以加载时不显示上拉加载 50 | */ 51 | public void setLoadingMoreEnabled(boolean b) { 52 | super.setLoadingMoreEnabled(b); 53 | } 54 | 55 | /** 56 | * 刷新完成 57 | */ 58 | public void refreshComplete() { 59 | super.refreshComplete(); 60 | } 61 | 62 | /** 63 | * 加载更多完成 64 | */ 65 | public void loadMoreComplete() { 66 | super.loadMoreComplete(); 67 | } 68 | 69 | /** 70 | * 设置下拉刷新及上拉加载监听 71 | * 72 | * @param listener 73 | */ 74 | public void setLoadingListener(final LoadingListener listener) { 75 | super.setLoadingListener(new XRecyclerView.LoadingListener() { 76 | @Override 77 | public void onRefresh() { 78 | curState = REFRESH; 79 | listener.onRefresh(); 80 | } 81 | 82 | @Override 83 | public void onLoadMore() { 84 | curState = LOADMORE; 85 | listener.onLoadMore(); 86 | } 87 | }); 88 | } 89 | 90 | /** 91 | * 设置当前页及总页数,在刷新完成及加载完成调用 92 | */ 93 | public boolean setCurrentAndTotal(int cur, int total) { 94 | if (cur >= 0 && total >= 0) { 95 | if (cur == total) { 96 | setLoadingMoreEnabled(false); 97 | return true; 98 | } else if (cur < total) { 99 | setLoadingMoreEnabled(true); 100 | } 101 | } 102 | return false; 103 | } 104 | 105 | /** 106 | * loading接口 107 | */ 108 | public interface LoadingListener { 109 | 110 | void onRefresh(); 111 | 112 | void onLoadMore(); 113 | } 114 | 115 | /** 116 | * @param type 刷新完成类型 117 | */ 118 | public void setComplete(int type) { 119 | switch (type) { 120 | case REFRESH: 121 | super.refreshComplete(); 122 | break; 123 | case LOADMORE: 124 | super.loadMoreComplete(); 125 | break; 126 | default: 127 | super.refreshComplete(); 128 | break; 129 | } 130 | curState = NONE; 131 | } 132 | 133 | public void setComplete() { 134 | setComplete(curState); 135 | } 136 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/drawable-xhdpi/ic_app.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/drawable-xhdpi/ic_refresh.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/place_holder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/drawable-xhdpi/place_holder.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/tecent_holder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/drawable-xhdpi/tecent_holder.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/welcome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/drawable-xhdpi/welcome.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/widget_preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/drawable-xhdpi/widget_preview.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/progress_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 19 | 20 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_welcome.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_grid.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home_ad.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home_banner.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home_category.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 18 | 19 | 23 | 24 | 32 | 33 | 41 | 42 | 43 | 44 | 49 | 50 | 54 | 55 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | 20 | 25 | 26 | 30 | 31 | 32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home_third.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_news.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_pullload.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_staggered.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_tencent.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_grid_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 16 | 17 | 22 | 23 | 27 | 28 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/news_grid_item_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 21 | 22 | 30 | 31 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/res/layout/news_item_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 21 | 22 | 30 | 31 | 43 | 44 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /app/src/main/res/layout/staggered_item_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 20 | 21 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/layout/third_grid_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 19 | 20 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/toolbar_title_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/widget_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #e6ab29 4 | #d1940d 5 | #f3d38c 6 | #e6ab29 7 | 8 | 9 | #000000 10 | 11 | #444444 12 | 13 | #9A9A9A 14 | 15 | #F2F2F2 16 | 17 | #FFFFFF 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RecyclerViewDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | 25 | 26 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/xml/widget_info.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | -------------------------------------------------------------------------------- /app/src/test/java/com/huaqin/recyclerviewdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.huaqin.recyclerviewdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.0' 9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Apr 13 09:19:00 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /screenshots/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/screenshots/1.gif -------------------------------------------------------------------------------- /screenshots/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/screenshots/2.gif -------------------------------------------------------------------------------- /screenshots/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/screenshots/3.gif -------------------------------------------------------------------------------- /screenshots/4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/screenshots/4.gif -------------------------------------------------------------------------------- /screenshots/5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/screenshots/5.gif -------------------------------------------------------------------------------- /screenshots/all.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/screenshots/all.gif -------------------------------------------------------------------------------- /screenshots/recyclerview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/screenshots/recyclerview.png -------------------------------------------------------------------------------- /screenshots/widget.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/screenshots/widget.gif -------------------------------------------------------------------------------- /screenshots/widget_click.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdleyLong/RecyclerViewDemo/3bda03022e4df0399684bbe3ed8465d2afb89b4a/screenshots/widget_click.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------