├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── dictionaries
│ └── Jaeger.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_logo.png
│ │ │ │ ├── ic_play.png
│ │ │ │ ├── ic_cloud.png
│ │ │ │ ├── ic_pause.png
│ │ │ │ ├── ic_poetry.png
│ │ │ │ ├── ic_logo_text.png
│ │ │ │ ├── ic_media_play.png
│ │ │ │ ├── ic_default_cover.png
│ │ │ │ ├── ic_arrow_back_white_48dp.png
│ │ │ │ └── shape.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── layout
│ │ │ │ ├── fragment_listen.xml
│ │ │ │ ├── test.xml
│ │ │ │ ├── fragment_sujin.xml
│ │ │ │ ├── toolbar.xml
│ │ │ │ ├── content_main.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── title_bar.xml
│ │ │ │ ├── activity_splash.xml
│ │ │ │ ├── list_item_article.xml
│ │ │ │ └── activity_article_detail.xml
│ │ │ └── layout-xlarge
│ │ │ │ └── list_item_article.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── jaeger
│ │ │ │ └── listenrain
│ │ │ │ ├── ListenerRainApplication.java
│ │ │ │ ├── base
│ │ │ │ ├── BaseFragment.java
│ │ │ │ ├── AbstractBaseActivity.java
│ │ │ │ ├── AbstractBaseFragment.java
│ │ │ │ ├── BaseRecycleAdapter.java
│ │ │ │ └── BaseActivity.java
│ │ │ │ ├── fragment
│ │ │ │ ├── ListenFragment.java
│ │ │ │ └── SujinFragment.java
│ │ │ │ ├── activity
│ │ │ │ ├── SplashActivity.java
│ │ │ │ ├── ArticleDetailActivity.java
│ │ │ │ └── MainActivity.java
│ │ │ │ ├── entity
│ │ │ │ └── Article.java
│ │ │ │ ├── widget
│ │ │ │ ├── CustomScrollView.java
│ │ │ │ ├── TitleBar.java
│ │ │ │ ├── FooterView.java
│ │ │ │ ├── HeaderView.java
│ │ │ │ └── RefreshLayout.java
│ │ │ │ └── adapter
│ │ │ │ └── ArticleItemAdapter.java
│ │ └── AndroidManifest.xml
│ └── test
│ │ └── java
│ │ └── com
│ │ └── jaeger
│ │ └── listeningrain
│ │ └── ExampleUnitTest.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── ListenRain.iml
├── ListeningRain.iml
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | ListenRain
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/drawable/ic_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/drawable/ic_play.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_cloud.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/drawable/ic_cloud.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_pause.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/drawable/ic_pause.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_poetry.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/drawable/ic_poetry.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_logo_text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/drawable/ic_logo_text.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_media_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/drawable/ic_media_play.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_default_cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/drawable/ic_default_cover.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_arrow_back_white_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/laobie/ListenRain/HEAD/app/src/main/res/drawable/ic_arrow_back_white_48dp.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/dictionaries/Jaeger.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | listenrain
5 | sujin
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 听雨
3 | Settings
4 | 素锦
5 | 听雨
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 12 09:20:18 CST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 180dp
6 | 16dp
7 |
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/jaeger/listeningrain/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #262626
4 | #262626
5 | #ffffff
6 | #262626
7 | #ffffff
8 | #96262626
9 | #50000000
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_listen.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/test.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_sujin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/ListenerRainApplication.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain;
2 |
3 | import android.app.Application;
4 |
5 | import com.avos.avoscloud.AVOSCloud;
6 | import com.facebook.drawee.backends.pipeline.Fresco;
7 |
8 | /**
9 | * Created by Jaeger on 15/9/29.
10 | * ListenRain
11 | */
12 | public class ListenerRainApplication extends Application {
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 | Fresco.initialize(this);
17 | AVOSCloud.initialize(this, "39GbpyDQQ3aqNOwrrAcVwzNP", "0lz3QXUthcqm8EKUulT6Y9CT");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.base;
2 |
3 | import android.view.View;
4 | import android.widget.Toast;
5 |
6 | /**
7 | * Created by Jaeger on 15/9/15.
8 | * ListenRain
9 | */
10 | public class BaseFragment extends AbstractBaseFragment {
11 | @Override
12 | protected int setRootViewResId() {
13 | return 0;
14 | }
15 |
16 | @Override
17 | protected void beforeInitView() {
18 |
19 | }
20 |
21 | @Override
22 | protected void initView() {
23 |
24 | }
25 |
26 | @Override
27 | protected void setViewStatus() {
28 |
29 | }
30 |
31 | @Override
32 | public void onClick(View v) {
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Jaeger/Developer/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 |
--------------------------------------------------------------------------------
/.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/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #### ListenRain/听雨
2 |
3 |
4 | 『听雨』前段时间学习python爬虫练手的一个项目,通过python抓取网站[素锦](http://guo.lu/)上的内容,上传到LeanCloud后端云上,然后再通过app访问服务器获得数据,在客户端上显示文章内容。
5 |
6 | 目前App完成一半多,后面还会继续开发,定位为一个伪文艺的App。:)
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ---
16 | 技术细节:
17 |
18 | 1. 后端使用[LeanCloud](https://leancloud.cn/)后端服务,省去了服务器端的开发,具体使用细节请访问官网阅读文档。
19 | 2. 图片显示使用的是facebook的开源图片加载库[fresco](https://github.com/facebook/fresco),文档请访问:[英文](http://frescolib.org/)、[中文](http://fresco-cn.org/)。(需要科学上网)
20 | 3. 下拉刷新和上拉加载是自定义的一个刷新控件,具体请查看源码。
21 |
22 | 暂时就这么多,后期开发再更新,python爬虫代码等我整理后再发出来。:)
23 |
24 | ---
25 |
26 | **App下载地址:[http://fir.im/kv64](http://fir.im/kv64)**
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/fragment/ListenFragment.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.fragment;
2 |
3 | import android.view.View;
4 |
5 | import com.jaeger.listenrain.R;
6 | import com.jaeger.listenrain.base.BaseFragment;
7 |
8 | /**
9 | * Created by Jaeger on 15/9/29.
10 | * ListenRain
11 | */
12 | public class ListenFragment extends BaseFragment {
13 | @Override
14 | protected int setRootViewResId() {
15 | return R.layout.fragment_listen;
16 | }
17 |
18 | @Override
19 | protected void beforeInitView() {
20 | super.beforeInitView();
21 | }
22 |
23 | @Override
24 | protected void initView() {
25 | super.initView();
26 | }
27 |
28 | @Override
29 | protected void setViewStatus() {
30 | super.setViewStatus();
31 | }
32 |
33 | @Override
34 | public void onClick(View v) {
35 | super.onClick(v);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
23 |
24 |
--------------------------------------------------------------------------------
/ListenRain.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/ListeningRain.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/base/AbstractBaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.base;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.Window;
8 |
9 | /**
10 | * Created by Jaeger on 15/9/15.
11 | * ListenRain
12 | */
13 | public abstract class AbstractBaseActivity extends AppCompatActivity {
14 | @Override
15 | protected void onCreate(@Nullable Bundle savedInstanceState) {
16 | initIntentParam(getIntent());
17 | beforeInitView();
18 | super.onCreate(savedInstanceState);
19 | initView();
20 | setViewStatus();
21 | }
22 |
23 | // 初始化传入的参数
24 | protected abstract void initIntentParam(Intent intent);
25 |
26 | // 加载View之前的处理事件
27 | protected abstract void beforeInitView();
28 |
29 | // 加载视图
30 | protected abstract void initView();
31 |
32 | // 设置View状态,包含触发事件
33 | protected abstract void setViewStatus();
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/activity/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Handler;
5 |
6 | import com.jaeger.listenrain.R;
7 | import com.jaeger.listenrain.base.BaseActivity;
8 |
9 | /**
10 | * Created by Jaeger on 15/9/14.
11 | * ListeningRain
12 | */
13 | public class SplashActivity extends BaseActivity {
14 |
15 | @Override
16 | protected void initView() {
17 | super.initView();
18 | setContentView(R.layout.activity_splash);
19 | }
20 |
21 | @Override
22 | protected void setViewStatus() {
23 | toNextPage();
24 | }
25 |
26 | private void toNextPage() {
27 | Handler handler = new Handler();
28 | handler.postDelayed(new Runnable() {
29 | @Override
30 | public void run() {
31 | Intent intent = new Intent(SplashActivity.this, MainActivity.class);
32 | startActivity(intent);
33 | finish();
34 | }
35 | }, 1500);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/title_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
20 |
21 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_splash.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
18 |
19 |
24 |
25 |
26 |
27 |
28 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 |
5 |
6 | compileSdkVersion 23
7 | buildToolsVersion '23.0.2'
8 |
9 | defaultConfig {
10 | applicationId "com.jaeger.listenrain"
11 | minSdkVersion 14
12 | targetSdkVersion 23
13 | versionCode 1
14 | versionName "1.0"
15 | }
16 |
17 | packagingOptions {
18 | exclude 'META-INF/LICENSE.txt'
19 | exclude 'META-INF/NOTICE.txt'
20 | }
21 | lintOptions {
22 | abortOnError false
23 | }
24 |
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 | }
32 |
33 | dependencies {
34 | compile fileTree(include: ['*.jar'], dir: 'libs')
35 | testCompile 'junit:junit:4.12'
36 | compile 'com.android.support:appcompat-v7:23.0.1'
37 | compile 'com.android.support:design:23.0.1'
38 | compile 'com.android.support:support-v4:23.0.1'
39 | compile 'com.android.support:recyclerview-v7:23.0.1'
40 | compile 'cn.leancloud.android:avoscloud-sdk:v3.+'
41 | compile 'com.facebook.fresco:fresco:0.6.0+'
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
27 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/entity/Article.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by Jaeger on 15/9/29.
7 | * ListenRain
8 | */
9 | public class Article implements Serializable {
10 | private String title;
11 | private String coverUrl;
12 | private String date;
13 | private String content;
14 |
15 | public String getContent() {
16 | return content;
17 | }
18 |
19 | public void setContent(String content) {
20 | this.content = content;
21 | }
22 |
23 | public Article(String title, String content, String coverUrl, String date) {
24 |
25 | this.title = title;
26 | this.content = content;
27 | this.coverUrl = coverUrl;
28 | this.date = date;
29 | }
30 |
31 | public String getTitle() {
32 | return title;
33 | }
34 |
35 | public void setTitle(String title) {
36 | this.title = title;
37 | }
38 |
39 | public String getCoverUrl() {
40 | return coverUrl;
41 | }
42 |
43 | public void setCoverUrl(String coverUrl) {
44 | this.coverUrl = coverUrl;
45 | }
46 |
47 | public String getDate() {
48 | return date;
49 | }
50 |
51 | public void setDate(String date) {
52 | this.date = date;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/widget/CustomScrollView.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.ScrollView;
6 |
7 | /**
8 | * Created by Jaeger on 15/10/8.
9 | * ListenRain
10 | */
11 | public class CustomScrollView extends ScrollView {
12 | private OnScrollListener onScrollListener;
13 |
14 |
15 | public CustomScrollView(Context context) {
16 | super(context);
17 | }
18 |
19 | public CustomScrollView(Context context, AttributeSet attrs) {
20 | super(context, attrs);
21 | }
22 |
23 | public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
24 | super(context, attrs, defStyleAttr);
25 | }
26 |
27 | public void setScrollListener(OnScrollListener onScrollListener) {
28 | this.onScrollListener = onScrollListener;
29 | }
30 |
31 | @Override
32 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
33 | super.onLayout(changed, l, t, r, b);
34 | }
35 |
36 | @Override
37 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
38 | super.onScrollChanged(l, t, oldl, oldt);
39 | if (onScrollListener != null) {
40 | onScrollListener.onScrollChanged(l, t, oldl, oldt);
41 | }
42 | }
43 |
44 | public interface OnScrollListener {
45 | void onScrollChanged(int x, int y, int oldX, int OldY);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_article.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
20 |
21 |
22 |
35 |
36 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_article_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
19 |
20 |
21 |
28 |
29 |
30 |
39 |
40 |
41 |
42 |
43 |
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/base/AbstractBaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.base;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.Toast;
12 |
13 | /**
14 | * Created by Jaeger on 15/9/15.
15 | * ListenRain
16 | */
17 | public abstract class AbstractBaseFragment extends Fragment implements View.OnClickListener {
18 | protected Context context;
19 | protected View rootView;
20 |
21 | @Override
22 | public void onAttach(Context context) {
23 | this.context = context;
24 | super.onAttach(context);
25 | }
26 |
27 | @Override
28 | public void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | }
31 |
32 | @Nullable
33 | @Override
34 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
35 | rootView = inflater.inflate(setRootViewResId(), container, false);
36 | return rootView;
37 | }
38 |
39 | @Override
40 | public void onActivityCreated(Bundle savedInstanceState) {
41 | super.onActivityCreated(savedInstanceState);
42 | beforeInitView();
43 | initView();
44 | setViewStatus();
45 | }
46 |
47 | protected abstract int setRootViewResId();
48 |
49 | protected abstract void beforeInitView();
50 |
51 | protected abstract void initView();
52 |
53 | protected abstract void setViewStatus();
54 |
55 | protected void showToastS(CharSequence text) {
56 | Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
57 | }
58 |
59 | protected void showToastL(CharSequence text) {
60 | Toast.makeText(context, text, Toast.LENGTH_LONG).show();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/base/BaseRecycleAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.base;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.support.v7.widget.RecyclerView.Adapter;
6 | import android.support.v7.widget.RecyclerView.ViewHolder;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | /**
12 | * Created by Jaeger on 15/11/17.
13 | * ListenRain
14 | */
15 | public class BaseRecycleAdapter extends Adapter {
16 | protected Context context;
17 | protected LayoutInflater inflater;
18 | protected OnItemClickListener onItemClickListener;
19 |
20 | public BaseRecycleAdapter(Context context) {
21 | this.context = context;
22 | inflater = LayoutInflater.from(context);
23 | }
24 |
25 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
26 | return null;
27 | }
28 |
29 | @Override
30 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
31 |
32 | }
33 |
34 | @Override
35 | public int getItemCount() {
36 | return 0;
37 | }
38 |
39 | public interface OnItemClickListener {
40 | void onItemClick(View view, int position);
41 | }
42 |
43 | public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
44 | this.onItemClickListener = onItemClickListener;
45 | }
46 |
47 | protected class BaseViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
48 |
49 | public BaseViewHolder(View itemView) {
50 | super(itemView);
51 | itemView.setOnClickListener(this);
52 | }
53 |
54 | @Override
55 | public void onClick(View v) {
56 | if (onItemClickListener != null) {
57 | onItemClickListener.onItemClick(v, getLayoutPosition());
58 | }
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-xlarge/list_item_article.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
20 |
21 |
37 |
38 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/adapter/ArticleItemAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.adapter;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.TextView;
9 |
10 | import com.facebook.drawee.view.SimpleDraweeView;
11 | import com.jaeger.listenrain.R;
12 | import com.jaeger.listenrain.base.BaseRecycleAdapter;
13 | import com.jaeger.listenrain.entity.Article;
14 |
15 | import java.util.List;
16 |
17 | /**
18 | * Created by Jaeger on 15/8/6.
19 | * ListenRain
20 | */
21 | public class ArticleItemAdapter extends BaseRecycleAdapter {
22 |
23 | private List articles;
24 |
25 | public ArticleItemAdapter(Context context, List articles) {
26 | super(context);
27 | this.articles = articles;
28 | }
29 |
30 | @Override
31 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
32 | return new ArticleBaseViewHolder(inflater.inflate(R.layout.list_item_article, parent, false));
33 | }
34 |
35 | @Override
36 | public void onBindViewHolder(android.support.v7.widget.RecyclerView.ViewHolder viewHolder, final int position) {
37 | ArticleBaseViewHolder articleViewHolder = (ArticleBaseViewHolder) viewHolder;
38 | Article article = articles.get(position);
39 | articleViewHolder.tvTitle.setText(article.getTitle());
40 | articleViewHolder.tvDate.setText(article.getDate());
41 | articleViewHolder.ivCover.setImageURI(Uri.parse(article.getCoverUrl()));
42 | }
43 |
44 | @Override
45 | public int getItemCount() {
46 | return articles.size();
47 | }
48 |
49 | public class ArticleBaseViewHolder extends BaseViewHolder {
50 |
51 | SimpleDraweeView ivCover;
52 | TextView tvTitle;
53 | TextView tvDate;
54 |
55 | public ArticleBaseViewHolder(View view) {
56 | super(view);
57 | ivCover = (SimpleDraweeView) view.findViewById(R.id.iv_cover);
58 | tvTitle = (TextView) view.findViewById(R.id.tv_title);
59 | tvDate = (TextView) view.findViewById(R.id.tv_date);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/widget/TitleBar.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.widget;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.drawable.ColorDrawable;
6 | import android.util.AttributeSet;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.widget.ImageView;
10 | import android.widget.LinearLayout;
11 | import android.widget.TextView;
12 |
13 | import com.jaeger.listenrain.R;
14 |
15 | /**
16 | * Created by Jaeger on 15/10/8.
17 | * ListenRain
18 | */
19 | public class TitleBar extends LinearLayout {
20 | private Context context;
21 | private LinearLayout rootLayout;
22 | private TextView tvTitle;
23 | private ImageView ivBack;
24 |
25 |
26 | public TitleBar(Context context) {
27 | super(context);
28 | init(context);
29 | }
30 |
31 | public TitleBar(Context context, AttributeSet attrs) {
32 | super(context, attrs);
33 | init(context);
34 | }
35 |
36 | public TitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
37 | super(context, attrs, defStyleAttr);
38 | init(context);
39 | }
40 |
41 | private void init(final Context context) {
42 | this.context = context;
43 | LayoutInflater.from(context).inflate(R.layout.title_bar, this);
44 | rootLayout = (LinearLayout) findViewById(R.id.root);
45 | tvTitle = (TextView) findViewById(R.id.tv_title);
46 | ivBack = (ImageView) findViewById(R.id.iv_back);
47 | ivBack.setOnClickListener(new OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | if (context instanceof Activity) {
51 | Activity activity = (Activity) context;
52 | activity.onBackPressed();
53 | }
54 | }
55 | });
56 | setColor(true);
57 |
58 | }
59 |
60 | public void setTitle(CharSequence title) {
61 | tvTitle.setText(title);
62 | }
63 |
64 |
65 | public void setColor(boolean transparent) {
66 | if (transparent) {
67 | rootLayout.setBackground(context.getResources().getDrawable(R.color.gray_80));
68 | } else {
69 | rootLayout.setBackground(new ColorDrawable(context.getResources().getColor(R.color.gray)));
70 | }
71 |
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/activity/ArticleDetailActivity.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.activity;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.view.View;
6 | import android.widget.TextView;
7 |
8 | import com.facebook.drawee.view.SimpleDraweeView;
9 | import com.jaeger.listenrain.R;
10 | import com.jaeger.listenrain.base.BaseActivity;
11 | import com.jaeger.listenrain.entity.Article;
12 | import com.jaeger.listenrain.widget.CustomScrollView;
13 | import com.jaeger.listenrain.widget.TitleBar;
14 |
15 | /**
16 | * Created by Jaeger on 15/9/30.
17 | * ListenRain
18 | */
19 | public class ArticleDetailActivity extends BaseActivity {
20 | private SimpleDraweeView ivCover;
21 | private TitleBar titleBar;
22 | private CustomScrollView svRoot;
23 | private TextView tvContent;
24 | private Article article;
25 |
26 |
27 | @Override
28 | protected void initIntentParam(Intent intent) {
29 | article = (Article) intent.getSerializableExtra("article");
30 | }
31 |
32 | @Override
33 | protected void beforeInitView() {
34 | super.beforeInitView();
35 |
36 | }
37 |
38 |
39 | @Override
40 | protected void initView() {
41 |
42 | setContentView(R.layout.activity_article_detail);
43 | titleBar = (TitleBar) findViewById(R.id.title_bar);
44 | tvContent = (TextView) findViewById(R.id.tv_content);
45 | ivCover = (SimpleDraweeView) findViewById(R.id.iv_cover);
46 | svRoot = (CustomScrollView) findViewById(R.id.sv_root);
47 | }
48 |
49 | @Override
50 | protected void setViewStatus() {
51 | titleBar.setTitle(article.getTitle());
52 | tvContent.setText(article.getContent());
53 | ivCover.setImageURI(Uri.parse(article.getCoverUrl()));
54 |
55 |
56 | svRoot.setScrollListener(new CustomScrollView.OnScrollListener() {
57 | @Override
58 | public void onScrollChanged(int x, int y, int oldX, int OldY) {
59 | if (svRoot.getScrollY() >= (ivCover.getHeight() - titleBar.getHeight())) {
60 | titleBar.setColor(false);
61 | } else {
62 | titleBar.setColor(true);
63 | }
64 |
65 | }
66 | });
67 | }
68 |
69 | @Override
70 | public void onClick(View v) {
71 | super.onClick(v);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Build;
5 | import android.support.design.widget.TabLayout;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentStatePagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 | import android.view.ViewGroup;
11 | import android.view.WindowManager;
12 |
13 | import com.jaeger.listenrain.R;
14 | import com.jaeger.listenrain.base.BaseActivity;
15 | import com.jaeger.listenrain.fragment.ListenFragment;
16 | import com.jaeger.listenrain.fragment.SujinFragment;
17 |
18 | import java.util.HashMap;
19 | import java.util.Map;
20 |
21 | public class MainActivity extends BaseActivity {
22 | private ViewPager vpHomePage;
23 | private TabLayout tabPageTitle;
24 | private Map mapFragment = new HashMap<>();
25 | private String[] pageTitle;
26 |
27 | @Override
28 | protected void initIntentParam(Intent intent) {
29 | super.initIntentParam(intent);
30 | }
31 |
32 | @Override
33 | protected void beforeInitView() {
34 | smoothSwitchScreen();
35 | pageTitle = new String[]{getString(R.string.sujin), getString(R.string.listen_rain)};
36 | }
37 |
38 | @Override
39 | protected void initView() {
40 | setContentView(R.layout.activity_main);
41 | vpHomePage = (ViewPager) findViewById(R.id.vp_home_page);
42 | tabPageTitle = (TabLayout) findViewById(R.id.tab_page_title);
43 | }
44 |
45 | @Override
46 | protected void setViewStatus() {
47 | vpHomePage.setAdapter(new HomePageAdapter(getSupportFragmentManager()));
48 | tabPageTitle.setupWithViewPager(vpHomePage);
49 | }
50 |
51 | private void smoothSwitchScreen() {
52 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
53 | ViewGroup rootView = ((ViewGroup) this.findViewById(android.R.id.content));
54 | int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
55 | int statusBarHeight = getResources().getDimensionPixelSize(resourceId);
56 | rootView.setPadding(0, statusBarHeight, 0, 0);
57 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
58 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
59 | }
60 | }
61 |
62 | private Fragment switchFragment(int position) {
63 | Fragment fragment = mapFragment.get(position);
64 | if (fragment == null) {
65 | switch (position) {
66 | case 0:
67 | fragment = new SujinFragment();
68 | break;
69 | case 1:
70 | fragment = new ListenFragment();
71 | break;
72 | }
73 | mapFragment.put(position, fragment);
74 | }
75 | return fragment;
76 | }
77 |
78 | @Override
79 | public void onBackPressed() {
80 | Intent intent = new Intent(Intent.ACTION_MAIN);
81 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
82 | intent.addCategory(Intent.CATEGORY_HOME);
83 | startActivity(intent);
84 | }
85 |
86 | private class HomePageAdapter extends FragmentStatePagerAdapter {
87 |
88 | public HomePageAdapter(FragmentManager fm) {
89 | super(fm);
90 | }
91 |
92 | @Override
93 | public Fragment getItem(int position) {
94 | return switchFragment(position);
95 | }
96 |
97 | @Override
98 | public int getCount() {
99 | return 2;
100 | }
101 |
102 | @Override
103 | public CharSequence getPageTitle(int position) {
104 | return pageTitle[position];
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.base;
2 |
3 |
4 | import android.content.Intent;
5 | import android.os.Build;
6 | import android.support.v7.app.ActionBar;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.view.WindowManager;
12 | import android.widget.LinearLayout;
13 | import android.widget.Toast;
14 |
15 | import com.jaeger.listenrain.R;
16 |
17 | /**
18 | * Created by Jaeger on 15/9/15.
19 | * ListenRain
20 | */
21 | public class BaseActivity extends AbstractBaseActivity implements View.OnClickListener {
22 |
23 | @Override
24 | protected void initIntentParam(Intent intent) {
25 |
26 | }
27 |
28 | @Override
29 | protected void beforeInitView() {
30 |
31 | }
32 |
33 | @Override
34 | protected void initView() {
35 |
36 | }
37 |
38 | @Override
39 | protected void setViewStatus() {
40 |
41 | }
42 |
43 | @Override
44 | public void setContentView(int layoutResID) {
45 | super.setContentView(layoutResID);
46 | setStatusBarColor();
47 | }
48 |
49 |
50 | @Override
51 | public boolean onCreateOptionsMenu(Menu menu) {
52 | return super.onCreateOptionsMenu(menu);
53 | }
54 |
55 | @Override
56 | public boolean onOptionsItemSelected(MenuItem item) {
57 | switch (item.getItemId()) {
58 | case android.R.id.home:
59 | onBackPressed();
60 | break;
61 | default:
62 | break;
63 | }
64 | return super.onOptionsItemSelected(item);
65 | }
66 |
67 | protected void hideActionBar() {
68 | ActionBar actionBar = getSupportActionBar();
69 | if (actionBar != null) {
70 | actionBar.hide();
71 | }
72 | }
73 |
74 | protected void showBack() {
75 | ActionBar actionBar = getSupportActionBar();
76 | if (actionBar != null) {
77 | actionBar.setDisplayHomeAsUpEnabled(true);
78 | }
79 | }
80 |
81 | protected void setTitle(String title) {
82 | ActionBar actionBar = getSupportActionBar();
83 | if (actionBar != null && actionBar.isShowing()) {
84 | actionBar.setTitle(title);
85 | }
86 | }
87 |
88 | protected void showToastS(CharSequence text) {
89 | Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
90 | }
91 |
92 | protected void showToastL(CharSequence text) {
93 | Toast.makeText(this, text, Toast.LENGTH_LONG).show();
94 | }
95 |
96 | /**
97 | * 默认是不需要重写该方法
98 | * 当需要设置不同的状态栏颜色时,重写改方法就行
99 | */
100 | protected void setStatusBarColor() {
101 | translucentBar(R.color.colorPrimary);
102 | }
103 |
104 |
105 | /**
106 | * 状态栏变色处理 4.4以上
107 | *
108 | * @param color 状态栏颜色
109 | * 4.4状态栏显示为改颜色
110 | * 5.0自动会加上半透明效果
111 | */
112 | public void translucentBar(int color) {
113 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
114 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
115 | // 获取状态栏高度
116 | int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
117 | int statusBarHeight = getResources().getDimensionPixelSize(resourceId);
118 | // 绘制一个和状态栏一样高的矩形,并添加到视图中
119 | View rectView = new View(this);
120 | LinearLayout.LayoutParams params
121 | = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
122 | rectView.setLayoutParams(params);
123 | rectView.setBackgroundColor(getResources().getColor(color));
124 | // 添加矩形View到布局中
125 | ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
126 | decorView.addView(rectView);
127 | // 设置根布局的参数
128 | ViewGroup rootView = (ViewGroup) ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
129 | rootView.setFitsSystemWindows(true);
130 | rootView.setClipToPadding(true);
131 | }
132 | }
133 |
134 | @Override
135 | public void onClick(View v) {
136 |
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/fragment/SujinFragment.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.fragment;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.View;
7 |
8 | import com.avos.avoscloud.AVException;
9 | import com.avos.avoscloud.AVObject;
10 | import com.avos.avoscloud.AVQuery;
11 | import com.avos.avoscloud.FindCallback;
12 | import com.jaeger.listenrain.R;
13 | import com.jaeger.listenrain.activity.ArticleDetailActivity;
14 | import com.jaeger.listenrain.adapter.ArticleItemAdapter;
15 | import com.jaeger.listenrain.base.BaseFragment;
16 | import com.jaeger.listenrain.base.BaseRecycleAdapter;
17 | import com.jaeger.listenrain.entity.Article;
18 | import com.jaeger.listenrain.widget.RefreshLayout;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | /**
24 | * Created by Jaeger on 15/8/6.
25 | * ListenRain
26 | */
27 | public class SujinFragment extends BaseFragment {
28 | private RefreshLayout refreshLayout;
29 | private RecyclerView rvArticles;
30 | private ArticleItemAdapter adapter;
31 | private ArrayList articles = new ArrayList<>();
32 | int page = 0;
33 |
34 | @Override
35 | protected int setRootViewResId() {
36 | return R.layout.fragment_sujin;
37 | }
38 |
39 | @Override
40 | protected void beforeInitView() {
41 | super.beforeInitView();
42 | }
43 |
44 | @Override
45 | protected void initView() {
46 | rvArticles = (RecyclerView) rootView.findViewById(R.id.rv_articles);
47 | refreshLayout = (RefreshLayout) rootView.findViewById(R.id.rl_root);
48 | }
49 |
50 | @Override
51 | protected void setViewStatus() {
52 | rvArticles.setLayoutManager(new LinearLayoutManager(getActivity()));
53 | adapter = new ArticleItemAdapter(getActivity(), articles);
54 | rvArticles.setAdapter(adapter);
55 | refreshLayout.setOnRefreshListener(new RefreshLayout.OnRefreshListener() {
56 | @Override
57 | public void onRefreshing() {
58 | page = 0;
59 | articles.clear();
60 | getArticleList();
61 | }
62 |
63 | public void onLoading() {
64 | page++;
65 | getArticleList();
66 | }
67 |
68 | });
69 | adapter.setOnItemClickListener(new BaseRecycleAdapter.OnItemClickListener() {
70 | @Override
71 | public void onItemClick(View view, int position) {
72 | Intent intent = new Intent(context, ArticleDetailActivity.class);
73 | intent.putExtra("article", articles.get(position));
74 | context.startActivity(intent);
75 | }
76 | });
77 |
78 | }
79 |
80 | @Override
81 | public void onResume() {
82 | super.onResume();
83 | }
84 |
85 | private void getArticleList() {
86 | AVQuery query = AVQuery.getQuery("ArticleCloud");
87 | query.orderByDescending("index");
88 | query.setLimit(10);
89 | query.setSkip(page * 10);
90 | query.findInBackground(new FindCallback() {
91 | @Override
92 | public void done(List list, AVException e) {
93 | if (e == null) {
94 | Article article;
95 | for (AVObject avObject : list) {
96 | String title = avObject.getString("title");
97 | String content = avObject.getString("content");
98 | String coverUrl = avObject.getAVFile("cover").getUrl();
99 | String date = avObject.getString("date");
100 | article = new Article(title, content, coverUrl, date);
101 | articles.add(article);
102 | }
103 |
104 | adapter.notifyDataSetChanged();
105 | refreshLayout.finishRefreshing();
106 | } else {
107 | showToastS(e.getMessage());
108 | }
109 | }
110 | });
111 | }
112 |
113 |
114 | @Override
115 | public void onClick(View v) {
116 | switch (v.getId()) {
117 | default:
118 | break;
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/widget/FooterView.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Path;
7 | import android.util.AttributeSet;
8 | import android.util.TypedValue;
9 | import android.view.View;
10 |
11 | /**
12 | * Created by Jaeger on 15/10/10.
13 | * ListenRain
14 | */
15 | public class FooterView extends View {
16 | private static float PULL_HEIGHT;
17 | private Context context;
18 | private Status status;
19 | private Path mPath;
20 | private Paint mPaint;
21 | private Paint textPaint;
22 |
23 | public boolean isRefresh() {
24 | return refresh;
25 | }
26 |
27 | public void setRefresh(boolean refresh) {
28 | this.refresh = refresh;
29 | }
30 |
31 | private boolean refresh;
32 | private static int COLOR_GRAY = 0xFF262626;
33 | private static int COLOR_WHITE = 0xFFffffff;
34 |
35 |
36 | private enum Status {
37 | PULL_DOWN,
38 | DRAG_DOWN,
39 | REL_DRAG,
40 | REFRESH;
41 |
42 | @Override
43 | public String toString() {
44 | switch (this) {
45 | case PULL_DOWN:
46 | return "pull down";
47 | case DRAG_DOWN:
48 | return "drag down";
49 | default:
50 | return "unknown state";
51 | }
52 | }
53 | }
54 |
55 | public FooterView(Context context, AttributeSet attrs) {
56 | super(context, attrs);
57 | init(context);
58 | }
59 |
60 | public FooterView(Context context) {
61 | super(context);
62 | init(context);
63 | }
64 |
65 |
66 | public FooterView(Context context, AttributeSet attrs, int defStyleAttr) {
67 | super(context, attrs, defStyleAttr);
68 | init(context);
69 | }
70 |
71 | private void init(Context context) {
72 | this.context = context;
73 |
74 | PULL_HEIGHT = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, context.getResources().getDisplayMetrics());
75 | mPaint = new Paint();
76 | mPaint.setAntiAlias(true);
77 | mPaint.setStyle(Paint.Style.FILL);
78 | mPaint.setColor(COLOR_GRAY);
79 | mPath = new Path();
80 |
81 | textPaint = new Paint();
82 | textPaint.setStyle(Paint.Style.FILL);
83 | textPaint.setTextSize(25f);
84 | textPaint.setAntiAlias(true);
85 | textPaint.setTextAlign(Paint.Align.CENTER);
86 | textPaint.setColor(COLOR_WHITE);
87 | }
88 |
89 | @Override
90 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
91 | super.onLayout(changed, left, top, right, bottom);
92 | if (changed) {
93 | if (getHeight() > PULL_HEIGHT) {
94 | status = Status.DRAG_DOWN;
95 | } else {
96 | status = Status.PULL_DOWN;
97 | }
98 | if (isRefresh()) {
99 | status = Status.REFRESH;
100 | }
101 | }
102 | }
103 |
104 | @Override
105 | protected void onDraw(Canvas canvas) {
106 | super.onDraw(canvas);
107 | switch (status) {
108 | case PULL_DOWN:
109 | canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint);
110 | break;
111 | case DRAG_DOWN:
112 | canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint);
113 | canvas.drawText("放开加载更多", (float) getWidth() / 2, (float) (getHeight() / 2), textPaint);
114 | break;
115 | case REFRESH:
116 | drawRefreshing(canvas, getRefRation());
117 | invalidate();
118 | // canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint);
119 | break;
120 |
121 | }
122 | }
123 |
124 |
125 | private void drawRefreshing(Canvas canvas, float ration) {
126 | int n = (int) (ration * 3);
127 | StringBuilder temp = new StringBuilder();
128 | for (int i = 0; i < n + 1; i++) {
129 | temp.append(".");
130 | }
131 | canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint);
132 | canvas.drawText("正在加载" + temp.toString(), (float) getWidth() / 2, (float) (getHeight() / 2), textPaint);
133 | }
134 |
135 | private long mRefStart;
136 | private long REFRESH_DUR = 2000;
137 |
138 | private float getRefRation() {
139 | if (refresh) {
140 | return ((System.currentTimeMillis() - mRefStart) % REFRESH_DUR) / (float) REFRESH_DUR;
141 | } else {
142 | status = status.REL_DRAG;
143 | return 1;
144 | }
145 |
146 | }
147 |
148 | public void startRefresh() {
149 | refresh = true;
150 | status = Status.REFRESH;
151 | mRefStart = System.currentTimeMillis();
152 | requestLayout();
153 |
154 | }
155 |
156 | }
157 |
--------------------------------------------------------------------------------
/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/widget/HeaderView.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Path;
7 | import android.graphics.RectF;
8 | import android.util.AttributeSet;
9 | import android.util.TypedValue;
10 | import android.view.View;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by Jaeger on 15-7-22.
15 | * ListenRain
16 | */
17 | public class HeaderView extends View {
18 |
19 | private TextView test;
20 | private static int PULL_HEIGHT;
21 |
22 | private boolean isRefresh;
23 |
24 | private int mWidth;
25 | private int mHeight;
26 |
27 | private Paint mBackPaint;
28 | private Paint mFrontPain;
29 | private Paint textPaint;
30 | private Path mPath;
31 |
32 |
33 | public HeaderView(Context context) {
34 | this(context, null, 0);
35 | }
36 |
37 | public HeaderView(Context context, AttributeSet attrs) {
38 | this(context, attrs, 0);
39 | }
40 |
41 | public HeaderView(Context context, AttributeSet attrs, int defStyleAttr) {
42 | super(context, attrs, defStyleAttr);
43 | init(context);
44 | }
45 |
46 |
47 | private void init(Context context) {
48 | PULL_HEIGHT = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, context.getResources().getDisplayMetrics());
49 | radius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, context.getResources().getDisplayMetrics()) / 2;
50 |
51 | mBackPaint = new Paint();
52 | mBackPaint.setAntiAlias(true);
53 | mBackPaint.setStyle(Paint.Style.FILL);
54 | mBackPaint.setColor(0xFF262626);
55 |
56 | mFrontPain = new Paint();
57 | mFrontPain.setStyle(Paint.Style.STROKE);
58 | mFrontPain.setStrokeWidth(3);
59 | mFrontPain.setAntiAlias(true);
60 | mFrontPain.setColor(0xFFffffff);
61 |
62 | textPaint = new Paint();
63 | textPaint.setStyle(Paint.Style.FILL);
64 | textPaint.setTextSize(25f);
65 | textPaint.setAntiAlias(true);
66 | textPaint.setTextAlign(Paint.Align.CENTER);
67 | textPaint.setColor(0xFFffffff);
68 |
69 | mPath = new Path();
70 |
71 | }
72 |
73 | private AnimatorStatus mStatus = AnimatorStatus.PULL_DOWN;
74 |
75 | private enum AnimatorStatus {
76 | PULL_DOWN,
77 | DRAG_DOWN,
78 | REL_DRAG,
79 | REFRESH;
80 |
81 | @Override
82 | public String toString() {
83 | switch (this) {
84 | case PULL_DOWN:
85 | return "pull down";
86 | case DRAG_DOWN:
87 | return "drag down";
88 | default:
89 | return "unknown state";
90 | }
91 | }
92 | }
93 |
94 |
95 | @Override
96 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
97 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
98 | }
99 |
100 | @Override
101 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
102 | super.onLayout(changed, left, top, right, bottom);
103 | if (changed) {
104 | mWidth = getWidth();
105 | mHeight = getHeight();
106 | if (mHeight < PULL_HEIGHT) {
107 | mStatus = AnimatorStatus.PULL_DOWN;
108 | } else {
109 | mStatus = AnimatorStatus.DRAG_DOWN;
110 | }
111 | if (isRefresh) {
112 | mStatus = AnimatorStatus.REFRESH;
113 | }
114 | }
115 | }
116 |
117 | @Override
118 | protected void onDraw(Canvas canvas) {
119 | super.onDraw(canvas);
120 | switch (mStatus) {
121 | case DRAG_DOWN:
122 | canvas.drawRect(0, 0, mWidth, mHeight, mBackPaint);
123 | canvas.drawText("放开开始刷新", (float) mWidth / 2, (float) (mHeight / 2), textPaint);
124 | break;
125 | case PULL_DOWN:
126 | canvas.drawRect(0, 0, mWidth, mHeight, mBackPaint);
127 | break;
128 | // case DRAG_DOWN:
129 | // drawDrag(canvas);
130 | // break;
131 | case REFRESH:
132 | drawRefreshing(canvas, getRefRation());
133 | invalidate();
134 | break;
135 | case REL_DRAG:
136 | // drawRelDrag(canvas);
137 | break;
138 | }
139 | }
140 |
141 |
142 | // private void drawDrag(Canvas canvas) {
143 | // canvas.drawRect(0, 0, mWidth, PULL_HEIGHT, mBackPaint);
144 | // mPath.reset();
145 | // mPath.moveTo(0, PULL_HEIGHT);
146 | // mPath.quadTo(mTouchX, PULL_HEIGHT + (mHeight - PULL_HEIGHT) * 2, mWidth, PULL_HEIGHT);
147 | // canvas.drawPath(mPath, mBackPaint);
148 | // }
149 |
150 | private int radius;
151 | private long mRefStart;
152 | private long mRefStop;
153 | private long REFRESH_DUR = 10000;
154 | double angle = 0;
155 | double angle1 = 0;
156 | int x0;
157 | int y0;
158 | int x;
159 | int y;
160 | RectF oval;
161 |
162 | private void drawRefreshing(Canvas canvas, float ration) {
163 | canvas.drawRect(0, 0, mWidth, PULL_HEIGHT, mBackPaint);
164 |
165 | mFrontPain.setStrokeWidth(5);
166 | oval = new RectF(mWidth / 2 - radius, PULL_HEIGHT / 2 - radius, mWidth / 2 + radius, PULL_HEIGHT / 2 + radius);
167 | canvas.drawArc(oval, 0, 360, true, mFrontPain);
168 |
169 | x0 = mWidth / 2;
170 | y0 = PULL_HEIGHT / 2;
171 |
172 | mFrontPain.setStrokeWidth(3);
173 |
174 | angle = ration * Math.PI * 24;
175 | x = (int) (x0 + radius * Math.cos(angle) * 0.9);
176 | y = (int) (y0 + radius * Math.sin(angle) * 0.9);
177 | mPath.reset();
178 | mPath.moveTo(x0, y0);
179 | mPath.lineTo(x, y);
180 | canvas.drawPath(mPath, mFrontPain);
181 |
182 | angle1 = ration * 2 * Math.PI;
183 | x = (int) (x0 + radius * Math.cos(angle1) * 0.6);
184 | y = (int) (y0 + radius * Math.sin(angle1) * 0.6);
185 | mPath.reset();
186 | mPath.moveTo(x0, y0);
187 | mPath.lineTo(x, y);
188 | canvas.drawPath(mPath, mFrontPain);
189 | }
190 |
191 | private void drawRefresh(Canvas canvas, float ration) {
192 | canvas.drawRect(0, 0, mWidth, PULL_HEIGHT, mBackPaint);
193 | RectF oval = new RectF(mWidth / 2 - radius, PULL_HEIGHT / 2 - radius, mWidth / 2 + radius, PULL_HEIGHT / 2 + radius);
194 | canvas.drawArc(oval, 0, 360, true, mFrontPain);
195 | if (ration != 1) {
196 | int rad = (int) (ration * 1440);
197 | oval = new RectF(mWidth / 2 - radius, PULL_HEIGHT / 2 - radius, mWidth / 2 + radius, PULL_HEIGHT / 2 + radius);
198 | canvas.drawArc(oval, 0, rad % 360, true, mFrontPain);
199 | }
200 |
201 | // canvas.drawRect(0, 0, mWidth, PULL_HEIGHT, mBackPaint);
202 | // if (ration != 1) {
203 | // int r = (int) (ration * radius);
204 | // int leftX = (int) (ration * mWidth);
205 | // RectF oval = new RectF(leftX, PULL_HEIGHT / 2 - r / 2, leftX + r, PULL_HEIGHT / 2 + r / 2);
206 | // canvas.drawArc(oval, 0, 360, true, mFrontPain);
207 | // }
208 |
209 |
210 | }
211 |
212 | private float getRefRation() {
213 | if (isRefresh) {
214 | return ((System.currentTimeMillis() - mRefStart) % REFRESH_DUR) / (float) REFRESH_DUR;
215 | } else {
216 | mStatus = AnimatorStatus.REL_DRAG;
217 | return 1;
218 | }
219 |
220 | }
221 |
222 | private void drawRelDrag(Canvas canvas) {
223 | canvas.drawRect(0, 0, mWidth, PULL_HEIGHT, mBackPaint);
224 | // canvas.drawRect(0, 0, mWidth, PULL_HEIGHT, mBackPaint);
225 | // mPath.reset();
226 | // mPath.moveTo(0, PULL_HEIGHT);
227 | // mPath.quadTo(mTouchX, PULL_HEIGHT - 100, mWidth, PULL_HEIGHT);
228 | // canvas.drawPath(mPath, mFrontPain);
229 | // ValueAnimator animator = ValueAnimator.ofFloat(PULL_HEIGHT, PULL_HEIGHT - 50, PULL_HEIGHT);
230 | // animator.setDuration(1000);
231 | // animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
232 | // @Override
233 | // public void onAnimationUpdate(ValueAnimator valueAnimator) {
234 | // float val = (float) valueAnimator.getAnimatedValue();
235 | // mPath.quadTo(mTouchX,PULL_HEIGHT-val,mWidth,PULL_HEIGHT);
236 | // canvas.drawPath(mPath,mFrontPain);
237 | // }
238 | // });
239 | // animator.start();
240 | }
241 |
242 | protected void startRefresh() {
243 | isRefresh = true;
244 | mStatus = AnimatorStatus.REFRESH;
245 | mRefStart = System.currentTimeMillis();
246 | mRefStop = mRefStart + REFRESH_DUR;
247 | requestLayout();
248 | // invalidate();
249 | }
250 |
251 | protected void relaseDrag() {
252 | mStatus = AnimatorStatus.REL_DRAG;
253 | requestLayout();
254 | }
255 |
256 | public void setIsRefresh(boolean isRefresh) {
257 | this.isRefresh = isRefresh;
258 | }
259 | }
260 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jaeger/listenrain/widget/RefreshLayout.java:
--------------------------------------------------------------------------------
1 | package com.jaeger.listenrain.widget;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.support.v4.view.ViewCompat;
6 | import android.util.AttributeSet;
7 | import android.util.TypedValue;
8 | import android.view.Gravity;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.view.animation.DecelerateInterpolator;
12 | import android.widget.FrameLayout;
13 | /**
14 | * Created by Jaeger on 15-7-22.
15 | * RefreshLayout
16 | */
17 | public class RefreshLayout extends FrameLayout {
18 | private final static int PULL_DOWN_MODE = 1;
19 | private final static int PULL_UP_MODE = -1;
20 | private int Mode = PULL_DOWN_MODE;
21 | private Context context;
22 | private OnRefreshListener onRefreshListener;
23 | private View childView;
24 | private HeaderView headerView;
25 | private FooterView footerView;
26 |
27 |
28 | private boolean mIsRefreshing;
29 | private ValueAnimator mUpBackAnimator;
30 | private float mTouchStartY;
31 | private float mTouchCurY;
32 | private float PULL_HEIGHT;
33 | private int HEADER_HEIGHT;
34 |
35 | public RefreshLayout(Context context) {
36 | this(context, null, 0);
37 | }
38 |
39 | public RefreshLayout(Context context, AttributeSet attrs) {
40 | this(context, attrs, 0);
41 | }
42 |
43 | public RefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
44 | super(context, attrs, defStyleAttr);
45 | init(context);
46 | }
47 |
48 |
49 | private void init(Context context) {
50 | this.context = context;
51 | PULL_HEIGHT = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150, context.getResources().getDisplayMetrics());
52 | HEADER_HEIGHT = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, context.getResources().getDisplayMetrics());
53 | if (getChildCount() > 1) {
54 | throw new RuntimeException("you can only attach one child");
55 | }
56 | this.post(new Runnable() {
57 | @Override
58 | public void run() {
59 | childView = getChildAt(0);
60 | addHeaderView();
61 | addFooterView();
62 | autoRefresh();
63 |
64 |
65 | }
66 | });
67 |
68 | }
69 |
70 | private void addHeaderView() {
71 | headerView = new HeaderView(context);
72 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, 0);
73 | params.gravity = Gravity.TOP;
74 | headerView.setLayoutParams(params);
75 | addView(headerView);
76 |
77 | }
78 |
79 | private void addFooterView() {
80 | footerView = new FooterView(context);
81 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, 0);
82 | params.gravity = Gravity.BOTTOM;
83 | footerView.setLayoutParams(params);
84 | addView(footerView);
85 | }
86 |
87 | @Override
88 | public boolean onInterceptTouchEvent(MotionEvent ev) {
89 | if (mIsRefreshing) {
90 | return true;
91 | }
92 | switch (ev.getAction()) {
93 | case MotionEvent.ACTION_DOWN:
94 | mTouchStartY = ev.getY();
95 | break;
96 | case MotionEvent.ACTION_MOVE:
97 | mTouchCurY = ev.getY();
98 | float dy = mTouchCurY - mTouchStartY;
99 | if (childView != null) {
100 | if (dy > 0 && !ViewCompat.canScrollVertically(childView, -1)) {
101 | return true;
102 | }
103 | if (dy < 0 && !ViewCompat.canScrollVertically(childView, 1)) {
104 | return true;
105 | }
106 | }
107 | return false;
108 | default:
109 | break;
110 | }
111 | return super.onInterceptTouchEvent(ev);
112 | }
113 |
114 | @Override
115 | public boolean onTouchEvent(MotionEvent event) {
116 | if (mIsRefreshing) {
117 | return false;
118 | }
119 | switch (event.getAction()) {
120 | case MotionEvent.ACTION_DOWN:
121 | return true;
122 | case MotionEvent.ACTION_MOVE:
123 | mIsRefreshing = false;
124 | mTouchCurY = event.getY();
125 | float dy = mTouchCurY - mTouchStartY;
126 | Mode = dy > 0 ? PULL_DOWN_MODE : PULL_UP_MODE;
127 | dy = Math.min(PULL_HEIGHT * 2, Math.abs(dy));
128 | int refreshViewHeight = (int) (new DecelerateInterpolator(10).getInterpolation(dy / PULL_HEIGHT / 2) * dy / 2);
129 | float moveDistance = Mode == PULL_DOWN_MODE ? refreshViewHeight : -refreshViewHeight;
130 | if (childView != null) {
131 | if (Mode == PULL_DOWN_MODE && !isChildViewCanScrollDown()) {
132 | childView.setTranslationY(moveDistance);
133 | headerView.getLayoutParams().height = refreshViewHeight;
134 | headerView.requestLayout();
135 | } else if (Mode == PULL_UP_MODE && !isChildViewCanScrollUp()) {
136 | childView.setTranslationY(moveDistance);
137 | footerView.getLayoutParams().height = refreshViewHeight;
138 | footerView.requestLayout();
139 | }
140 | }
141 | break;
142 | case MotionEvent.ACTION_UP:
143 | case MotionEvent.ACTION_CANCEL:
144 | if (childView != null) {
145 | float height = Math.abs(childView.getTranslationY());
146 | if (height > HEADER_HEIGHT) {
147 | switch (Mode) {
148 | case PULL_DOWN_MODE:
149 | startRefresh(height);
150 | break;
151 | case PULL_UP_MODE:
152 | startLoad(height);
153 | break;
154 | default:
155 | break;
156 | }
157 | } else {
158 | backToAnimator();
159 | }
160 | }
161 | }
162 |
163 | return super.onTouchEvent(event);
164 | }
165 |
166 |
167 | private void startRefresh(float height) {
168 | mIsRefreshing = true;
169 | mUpBackAnimator = ValueAnimator.ofFloat(height, HEADER_HEIGHT);
170 | mUpBackAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
171 | @Override
172 | public void onAnimationUpdate(ValueAnimator animation) {
173 | float val = (float) animation.getAnimatedValue();
174 | childView.setTranslationY(val);
175 | headerView.getLayoutParams().height = (int) val;
176 | headerView.requestLayout();
177 | if (val == HEADER_HEIGHT) {
178 | headerView.startRefresh();
179 | if (onRefreshListener != null) {
180 | onRefreshListener.onRefreshing();
181 | }
182 | }
183 | }
184 | });
185 | mUpBackAnimator.setDuration(500);
186 | mUpBackAnimator.start();
187 | }
188 |
189 | private void startLoad(float height) {
190 | mIsRefreshing = true;
191 | height = -height;
192 | mUpBackAnimator = ValueAnimator.ofFloat(height, -HEADER_HEIGHT);
193 | mUpBackAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
194 | @Override
195 | public void onAnimationUpdate(ValueAnimator animation) {
196 | float val = (float) animation.getAnimatedValue();
197 | childView.setTranslationY(val);
198 | footerView.getLayoutParams().height = (int) -val;
199 | footerView.requestLayout();
200 | if (val == -HEADER_HEIGHT) {
201 | footerView.startRefresh();
202 | if (onRefreshListener != null) {
203 | onRefreshListener.onLoading();
204 | }
205 | }
206 | }
207 | });
208 | mUpBackAnimator.setDuration(500);
209 | mUpBackAnimator.start();
210 |
211 |
212 | }
213 |
214 | public void autoRefresh() {
215 | if (childView != null) {
216 | mIsRefreshing = true;
217 | childView.setTranslationY(HEADER_HEIGHT);
218 | headerView.getLayoutParams().height = HEADER_HEIGHT;
219 | headerView.requestLayout();
220 | headerView.startRefresh();
221 | if (onRefreshListener != null) {
222 | onRefreshListener.onRefreshing();
223 | }
224 | }
225 | }
226 |
227 | public void finishRefreshing() {
228 | switch (Mode) {
229 | case PULL_DOWN_MODE:
230 | headerView.setIsRefresh(false);
231 | break;
232 | case PULL_UP_MODE:
233 | footerView.setRefresh(false);
234 | break;
235 | }
236 | mIsRefreshing = false;
237 | backToAnimator();
238 |
239 | }
240 |
241 | public void setOnRefreshListener(OnRefreshListener onRefreshListener) {
242 | this.onRefreshListener = onRefreshListener;
243 | }
244 |
245 | public interface OnRefreshListener {
246 | void onRefreshing();
247 |
248 | // void completeRefresh();
249 |
250 | void onLoading();
251 |
252 | }
253 |
254 |
255 | private boolean isChildViewCanScrollDown() {
256 | return childView != null && ViewCompat.canScrollVertically(childView, -1);
257 | }
258 |
259 | private boolean isChildViewCanScrollUp() {
260 | return childView != null && ViewCompat.canScrollVertically(childView, 1);
261 | }
262 |
263 | private void backToAnimator() {
264 | mUpBackAnimator = ValueAnimator.ofFloat(childView.getTranslationY(), 0);
265 | mUpBackAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
266 | @Override
267 | public void onAnimationUpdate(ValueAnimator animation) {
268 | float val = (float) animation.getAnimatedValue();
269 | childView.setTranslationY(val);
270 |
271 | if (Mode == PULL_DOWN_MODE) {
272 | headerView.getLayoutParams().height = (int) val;
273 | headerView.requestLayout();
274 | } else {
275 | footerView.getLayoutParams().height = (int) -val;
276 | footerView.requestLayout();
277 | }
278 | }
279 | });
280 | mUpBackAnimator.setDuration(500);
281 | mUpBackAnimator.start();
282 | }
283 |
284 | }
285 |
--------------------------------------------------------------------------------