├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── kyle │ │ └── nestedscrolldemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── kyle │ │ │ └── nestedscrolldemo │ │ │ ├── activity │ │ │ ├── AlbumTrackListActivity.java │ │ │ ├── BaseActivity.java │ │ │ ├── ClassifyArticlesActivity.java │ │ │ └── MainActivity.java │ │ │ ├── fragment │ │ │ ├── AbstractBaseFragment.java │ │ │ ├── AlbumDetailInfoFragment.java │ │ │ ├── AlbumFragment.java │ │ │ └── AlbumTracksFragment.java │ │ │ ├── tool │ │ │ ├── SystemBarTintManager.java │ │ │ ├── Tool.java │ │ │ └── UIHelper.java │ │ │ └── widget │ │ │ ├── AppBarStateChangeListener.java │ │ │ ├── PlayerHeadZoomScrollView.java │ │ │ ├── PullZoomBaseView.java │ │ │ ├── PullZoomStickyNavLayout.java │ │ │ ├── RefreshFootView.java │ │ │ ├── RefreshHeaderView.java │ │ │ ├── SimpleRVAdapter.java │ │ │ └── StickyNavLayout.java │ └── res │ │ ├── anim │ │ ├── rotate_reset.xml │ │ └── rotate_roll.xml │ │ ├── drawable-xhdpi │ │ ├── back_ico.png │ │ ├── bg_player_track_blur.png │ │ ├── ic_downswipe.png │ │ ├── ic_more_black.png │ │ ├── ic_more_titlebar.png │ │ ├── ic_player_downswipe_black.png │ │ ├── ic_stars_black.png │ │ ├── ico_refresh_arrow_down.png │ │ ├── ico_refresh_arrow_up.png │ │ ├── icon_default_1_to_1.png │ │ └── white_ico.png │ │ ├── drawable │ │ ├── gradient_white_to_black.xml │ │ ├── xml_player_back.xml │ │ ├── xml_player_back_black.xml │ │ ├── xml_player_more.xml │ │ └── xml_player_more_black.xml │ │ ├── layout │ │ ├── activity_album_detail.xml │ │ ├── activity_classify_articles.xml │ │ ├── activity_main.xml │ │ ├── fragment_album.xml │ │ ├── fragment_album_detail_info.xml │ │ ├── fragment_album_tracks.xml │ │ ├── header_album_detail_info.xml │ │ ├── item_classify_articles_head.xml │ │ ├── layout_demo.xml │ │ ├── layout_load_foot_discovery.xml │ │ ├── layout_load_header_discovery.xml │ │ └── layout_title_bar.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── fraction.xml │ │ ├── integers.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── kyle │ └── nestedscrolldemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | 11 | .idea/vcs.xml 12 | -------------------------------------------------------------------------------- /.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 | Abstraction issuesJava 39 | 40 | 41 | Android > Lint > Correctness 42 | 43 | 44 | Android > Lint > Performance 45 | 46 | 47 | Class structureJava 48 | 49 | 50 | Cloning issuesJava 51 | 52 | 53 | Control FlowGroovy 54 | 55 | 56 | Control flow issuesJava 57 | 58 | 59 | Data flow issuesJava 60 | 61 | 62 | General 63 | 64 | 65 | Groovy 66 | 67 | 68 | Inheritance issuesJava 69 | 70 | 71 | Internationalization issuesJava 72 | 73 | 74 | Java 75 | 76 | 77 | Numeric issuesJava 78 | 79 | 80 | Performance issuesJava 81 | 82 | 83 | Potentially confusing code constructsGroovy 84 | 85 | 86 | Probable bugsJava 87 | 88 | 89 | Security issuesJava 90 | 91 | 92 | Serialization issuesJava 93 | 94 | 95 | Threading issuesJava 96 | 97 | 98 | 99 | 100 | DefaultFileTemplate 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 122 | 123 | 124 | 125 | 126 | 1.8 127 | 128 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NestedScrollDemo 2 | 3 | ## demo1 4 | ### 在 [ Android NestedScrolling机制完全解析 带你玩转嵌套滑动](http://blog.csdn.net/lmj623565791/article/details/52204039) 5 | 的基础上实现了带ViewPager的嵌套滑动,并增加渐变和浸入式效果.
6 | 可用于类似网易云专辑详情页,歌手页这样的页面 7 | 8 | ![这里写图片描述](https://farm5.staticflickr.com/4013/35586396232_11bd04ed13_o.gif) 9 | 10 | ## demo2 11 | ### 类似于支付宝首页,带有下拉刷新功能的嵌套滑动 12 |
13 | 14 | ![这里写图片描述](https://farm5.staticflickr.com/4235/35387004030_8532378a75_o.gif) 15 | 16 |
17 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "kyle.nestedscrolldemo" 8 | minSdkVersion 16 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.1' 28 | compile 'com.astuetz:pagerslidingtabstrip:1.0.1' 29 | compile 'com.android.support:recyclerview-v7:25.3.1' 30 | compile 'com.github.Aspsine:SwipeToLoadLayout:1.0.4' 31 | compile 'com.github.sharish:ShimmerRecyclerView:v1.0' 32 | compile 'com.android.support:design:25.1.0' 33 | testCompile 'junit:junit:4.12' 34 | } 35 | -------------------------------------------------------------------------------- /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/wangrubing/Downloads/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/kyle/nestedscrolldemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo; 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("kyle.nestedscrolldemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/activity/AlbumTrackListActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MoreListActivity.java 3 | * @include classes:MoreListActivity;interfaces:MoreListActivity 4 | * @version 1.0.0 5 | * @data 2013-12-19 6 | */ 7 | package kyle.nestedscrolldemo.activity; 8 | 9 | import android.content.Context; 10 | import android.content.Intent; 11 | import android.os.Bundle; 12 | import android.support.v4.app.FragmentTransaction; 13 | import android.support.v7.app.AppCompatActivity; 14 | import android.view.WindowManager; 15 | 16 | import kyle.nestedscrolldemo.R; 17 | import kyle.nestedscrolldemo.fragment.AlbumFragment; 18 | import kyle.nestedscrolldemo.tool.Tool; 19 | 20 | /** 21 | * @author hongjunmin 22 | * @version 1.0.0 23 | * @name AlbumTrackListActivity 24 | * @desc 专辑内页 25 | */ 26 | public class AlbumTrackListActivity extends AppCompatActivity { 27 | 28 | public static final String TAG_DOWNLOAD_TRACKS_FRAGMENT = "downloadTracksFragment"; 29 | private AlbumFragment mAlbumFragment; 30 | 31 | private boolean isLocal; 32 | 33 | @Override 34 | protected void onCreate(Bundle arg0) { 35 | super.onCreate(arg0); 36 | setContentView(R.layout.activity_album_detail); 37 | if (Tool.isStatusBarTranslucentEnable()) { 38 | //透明状态栏 39 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 40 | } 41 | showAlbumDetailFragment(); 42 | } 43 | 44 | 45 | 46 | private void showAlbumDetailFragment() { 47 | if (mAlbumFragment == null) { 48 | mAlbumFragment = AlbumFragment.newInstance(); 49 | } 50 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); 51 | fragmentTransaction 52 | .replace(R.id.fragment_container, mAlbumFragment);//首个Fragment不执行addToBackStack,防止点击返回键显示空白页的bug 53 | fragmentTransaction.commitAllowingStateLoss(); 54 | } 55 | 56 | 57 | public static void launch(Context c) { 58 | Intent intent = new Intent(c, AlbumTrackListActivity.class); 59 | // intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 60 | c.startActivity(intent); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/activity/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.activity; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Activity; 5 | import android.os.Build; 6 | import android.os.Bundle; 7 | import android.support.annotation.CallSuper; 8 | import android.support.annotation.DrawableRes; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.view.MenuItem; 11 | import android.view.Window; 12 | import android.view.WindowManager; 13 | 14 | import kyle.nestedscrolldemo.R; 15 | import kyle.nestedscrolldemo.tool.SystemBarTintManager; 16 | import kyle.nestedscrolldemo.tool.UIHelper; 17 | 18 | /** 19 | * Created by datong on 17/3/28. 20 | */ 21 | public class BaseActivity extends AppCompatActivity { 22 | 23 | /** 24 | * 是否设置状态栏颜色 25 | */ 26 | private boolean updateStatusBar = true; 27 | 28 | @Override 29 | @CallSuper 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | if(updateStatusBar){ 33 | updateStatusBar(); 34 | } 35 | } 36 | 37 | 38 | public static void initSystemBar(Activity activity) { 39 | 40 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 41 | 42 | setTranslucentStatus(activity, true); 43 | 44 | } 45 | 46 | SystemBarTintManager tintManager = new SystemBarTintManager(activity); 47 | 48 | tintManager.setStatusBarTintEnabled(true); 49 | 50 | // 使用颜色资源 51 | 52 | tintManager.setStatusBarTintResource(R.color.white); 53 | 54 | } 55 | 56 | @TargetApi(19) 57 | 58 | private static void setTranslucentStatus(Activity activity, boolean on) { 59 | 60 | Window win = activity.getWindow(); 61 | 62 | WindowManager.LayoutParams winParams = win.getAttributes(); 63 | 64 | final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 65 | 66 | if (on) { 67 | 68 | winParams.flags |= bits; 69 | 70 | } else { 71 | 72 | winParams.flags &= ~bits; 73 | 74 | } 75 | 76 | win.setAttributes(winParams); 77 | 78 | } 79 | 80 | 81 | @Override 82 | @CallSuper 83 | public boolean onOptionsItemSelected(MenuItem item) { 84 | 85 | if (item.getItemId() == android.R.id.home) { 86 | onBackPressed(); 87 | } 88 | return super.onOptionsItemSelected(item); 89 | } 90 | 91 | @Override 92 | @CallSuper 93 | public void onDestroy() { 94 | super.onDestroy(); 95 | 96 | } 97 | 98 | /** 99 | * 当前Activity是否已经结束了其生命周期 100 | */ 101 | public boolean isInLifeCycle() { 102 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 103 | return !this.isFinishing() && ! this.isDestroyed(); 104 | } else { 105 | return !this.isFinishing(); 106 | } 107 | } 108 | 109 | protected void updateStatusBar() { 110 | updateStatusBar(R.color.red31); 111 | } 112 | 113 | protected void updateStatusBar(@DrawableRes int colorResId) { 114 | UIHelper.initSystemBar(this, colorResId); 115 | } 116 | 117 | @Override 118 | @CallSuper 119 | protected void onResume() { 120 | super.onResume(); 121 | onVisibilityChange(true); 122 | } 123 | 124 | @Override 125 | @CallSuper 126 | protected void onPause() { 127 | super.onPause(); 128 | onVisibilityChange(false); 129 | } 130 | 131 | @CallSuper 132 | protected void onVisibilityChange(boolean visible){ 133 | } 134 | 135 | public void setUpdateStatusBar(boolean updateStatusBar) { 136 | this.updateStatusBar = updateStatusBar; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/activity/ClassifyArticlesActivity.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.activity; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.design.widget.AppBarLayout; 7 | import android.support.v4.view.ViewCompat; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.View; 11 | import android.widget.TextView; 12 | 13 | import com.aspsine.swipetoloadlayout.OnLoadMoreListener; 14 | import com.aspsine.swipetoloadlayout.OnRefreshListener; 15 | import com.aspsine.swipetoloadlayout.SwipeToLoadLayout; 16 | import com.cooltechworks.views.shimmer.ShimmerRecyclerView; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | 21 | import kyle.nestedscrolldemo.R; 22 | import kyle.nestedscrolldemo.tool.Tool; 23 | import kyle.nestedscrolldemo.widget.AppBarStateChangeListener; 24 | import kyle.nestedscrolldemo.widget.RefreshFootView; 25 | import kyle.nestedscrolldemo.widget.RefreshHeaderView; 26 | import kyle.nestedscrolldemo.widget.SimpleRVAdapter; 27 | 28 | import static kyle.nestedscrolldemo.R.id.naviBack; 29 | 30 | public class ClassifyArticlesActivity extends BaseActivity implements OnRefreshListener,OnLoadMoreListener { 31 | 32 | private ShimmerRecyclerView rvArticles; 33 | private RefreshHeaderView refreshHeadView; 34 | private RefreshFootView refreshFootView; 35 | private SwipeToLoadLayout swipeToLoadLayout; 36 | private TextView tvHeadTitle; 37 | private TextView title; 38 | private AppBarLayout appBar; 39 | private SimpleRVAdapter simpleRVAdapter = new SimpleRVAdapter(new String[]{}); 40 | private View naviback; 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setContentView(R.layout.activity_classify_articles); 46 | findViews(); 47 | init(); 48 | } 49 | 50 | private void findViews() { 51 | title = (TextView) findViewById(R.id.title); 52 | tvHeadTitle = (TextView) findViewById(R.id.tv_head_title); 53 | rvArticles = (ShimmerRecyclerView) findViewById(R.id.swipe_target); 54 | swipeToLoadLayout = (SwipeToLoadLayout) findViewById(R.id.swipeToLoadLayout); 55 | refreshHeadView = (RefreshHeaderView) swipeToLoadLayout.getChildAt(0); 56 | refreshFootView = (RefreshFootView) swipeToLoadLayout.getChildAt(2); 57 | refreshHeadView.setBackgroundResource(R.color.gray_d3); 58 | refreshFootView.setBackgroundResource(R.color.gray_d3); 59 | appBar = (AppBarLayout)findViewById(R.id.app_bar_classify); 60 | naviback = findViewById(naviBack); 61 | } 62 | 63 | private void init() { 64 | naviback.setOnClickListener(new View.OnClickListener() { 65 | @Override 66 | public void onClick(View v) { 67 | ClassifyArticlesActivity.this.finish(); 68 | } 69 | }); 70 | /*actionBar.showBottomLine(true);*/ 71 | title.setText("时文精选"); 72 | tvHeadTitle.setText("时文精选"); 73 | rvArticles.setLayoutManager(new LinearLayoutManager(this)); 74 | rvArticles.setAdapter(simpleRVAdapter); 75 | rvArticles.showShimmerAdapter(); 76 | //进入首页并有缓存数据 77 | loadArticles(true); 78 | swipeToLoadLayout.setOnRefreshListener(this); 79 | swipeToLoadLayout.setOnLoadMoreListener(this); 80 | rvArticles.addOnScrollListener(new RecyclerView.OnScrollListener() { 81 | @Override 82 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 83 | if (newState == RecyclerView.SCROLL_STATE_IDLE) { 84 | if (!ViewCompat.canScrollVertically(recyclerView, 1)) { 85 | swipeToLoadLayout.setLoadingMore(true); 86 | } 87 | } 88 | 89 | } 90 | }); 91 | appBar.addOnOffsetChangedListener(new AppBarStateChangeListener() { 92 | 93 | @Override 94 | public void onStateChanged(AppBarLayout appBarLayout, State state) { 95 | swipeToLoadLayout.setRefreshEnabled(state == State.EXPANDED ? true : false); 96 | } 97 | }); 98 | appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { 99 | @Override 100 | public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 101 | float rate = (float) Math.abs(verticalOffset)/appBarLayout.getTotalScrollRange(); 102 | //当appBar中的标题消失时才显示顶部的标题 103 | float alpha = rate<= getResources().getFraction(R.fraction.classify_articles_title_show_rate,1,1) ? 0 : (float) Math.pow(rate,2); 104 | //noinspection Range 105 | title.setAlpha(alpha); 106 | } 107 | }); 108 | } 109 | 110 | 111 | public static void launch(Context context) { 112 | Intent intent = new Intent(context, ClassifyArticlesActivity.class); 113 | context.startActivity(intent); 114 | } 115 | 116 | @Override 117 | public void onLoadMore() { 118 | loadArticles(false); 119 | } 120 | 121 | /** 122 | * @param after true表示下拉更新,false表示上拉加载更多 123 | */ 124 | private void loadArticles(final boolean after) { 125 | swipeToLoadLayout.postDelayed(new Runnable() { 126 | @Override 127 | public void run() { 128 | swipeToLoadLayout.setLoadingMore(false); 129 | swipeToLoadLayout.setRefreshing(false); 130 | if (Tool.isEmpty(simpleRVAdapter.getDataSource())) { 131 | rvArticles.hideShimmerAdapter(); 132 | } 133 | if(after){ 134 | simpleRVAdapter.setDataSource(new String[]{"节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC", 135 | "节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC"}); 136 | }else { 137 | ArrayList newList = new ArrayList(Arrays.asList(simpleRVAdapter.getDataSource())); 138 | newList.add("节目ABC "+System.currentTimeMillis()); 139 | String[] newArray = new String[newList.size()]; 140 | newList.toArray(newArray); 141 | simpleRVAdapter.setDataSource(newArray); 142 | rvArticles.smoothScrollBy(0, Tool.dp2px(getResources(), rvArticles.getResources().getInteger(R.integer.discovery_load_more_offset))); 143 | } 144 | simpleRVAdapter.notifyDataSetChanged(); 145 | } 146 | },1000); 147 | } 148 | 149 | 150 | @Override 151 | public void onRefresh() { 152 | loadArticles(true); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.activity; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import kyle.nestedscrolldemo.R; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | TextView nestedScrollWithViewPager; 13 | TextView nestedScrollWithRefreshView; 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | findViews(); 19 | init(); 20 | 21 | } 22 | 23 | private void findViews() { 24 | nestedScrollWithViewPager = (TextView) findViewById(R.id.nestedScrollWithViewPager); 25 | nestedScrollWithRefreshView = (TextView)findViewById(R.id.nestedScrollWithRefreshView); 26 | } 27 | 28 | private void init() { 29 | nestedScrollWithViewPager.setOnClickListener(new View.OnClickListener() { 30 | @Override 31 | public void onClick(View v) { 32 | AlbumTrackListActivity.launch(v.getContext()); 33 | } 34 | }); 35 | nestedScrollWithRefreshView.setOnClickListener(new View.OnClickListener() { 36 | @Override 37 | public void onClick(View v) { 38 | ClassifyArticlesActivity.launch(v.getContext()); 39 | } 40 | }); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/fragment/AbstractBaseFragment.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | /** 10 | * * Created by hongjunmin on 16/10/21 11 | *为了优化Fragment,简化操作,新建了这个Fragment,参照车听宝项目 12 | * @author hongjunmin 13 | */ 14 | 15 | public abstract class AbstractBaseFragment extends Fragment { 16 | 17 | protected final String TAG = this.getClass().getSimpleName(); 18 | protected View mRootView; 19 | 20 | @Override 21 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 22 | if (mRootView == null) { 23 | mRootView = inflater.inflate(getLayoutResourceId(),null); 24 | findViews(); 25 | init(); 26 | } 27 | ViewGroup parent = (ViewGroup) mRootView.getParent(); 28 | if (parent != null) { 29 | parent.removeView(mRootView); 30 | } 31 | return mRootView; 32 | } 33 | protected abstract int getLayoutResourceId(); 34 | 35 | protected abstract void findViews(); 36 | protected abstract void init(); 37 | 38 | protected View findViewById(int resId) { 39 | return mRootView.findViewById(resId); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/fragment/AlbumDetailInfoFragment.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.fragment; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.View; 5 | import android.widget.LinearLayout; 6 | import android.widget.TextView; 7 | 8 | import kyle.nestedscrolldemo.R; 9 | 10 | /** 11 | * * Created by hongjunmin on 16/10/26 12 | * 13 | * @author hongjunmin 14 | */ 15 | 16 | public class AlbumDetailInfoFragment extends AbstractBaseFragment { 17 | 18 | RecyclerView relatedAlbums; 19 | // head view 20 | LinearLayout tagLayout; 21 | TextView albumIntro; 22 | View toggleExpandIntro; 23 | int recommendMaxLines; 24 | 25 | public AlbumDetailInfoFragment() { 26 | 27 | } 28 | 29 | public static AlbumDetailInfoFragment newInstance() { 30 | AlbumDetailInfoFragment albumDetailFragment = new AlbumDetailInfoFragment(); 31 | return albumDetailFragment; 32 | } 33 | 34 | @Override 35 | protected int getLayoutResourceId() { 36 | return R.layout.fragment_album_detail_info; 37 | } 38 | 39 | @Override 40 | protected void findViews() { 41 | } 42 | 43 | @Override 44 | protected void init() { 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/fragment/AlbumFragment.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.fragment; 2 | 3 | /** 4 | * * Created by hongjunmin on 16/10/21 5 | * 6 | * @author hongjunmin 7 | */ 8 | 9 | import android.app.DownloadManager; 10 | import android.content.Context; 11 | import android.graphics.Color; 12 | import android.support.v4.app.Fragment; 13 | import android.support.v4.app.FragmentManager; 14 | import android.support.v4.app.FragmentStatePagerAdapter; 15 | import android.support.v4.view.ViewCompat; 16 | import android.support.v4.view.ViewPager; 17 | import android.view.LayoutInflater; 18 | import android.view.View; 19 | import android.view.ViewGroup; 20 | import android.widget.ImageView; 21 | import android.widget.LinearLayout; 22 | import android.widget.RelativeLayout; 23 | import android.widget.TextView; 24 | 25 | import com.astuetz.PagerSlidingTabStrip; 26 | 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | import kyle.nestedscrolldemo.R; 31 | import kyle.nestedscrolldemo.tool.Tool; 32 | import kyle.nestedscrolldemo.widget.PullZoomStickyNavLayout; 33 | import kyle.nestedscrolldemo.widget.StickyNavLayout; 34 | 35 | import static kyle.nestedscrolldemo.R.id.naviBack; 36 | 37 | public class AlbumFragment extends AbstractBaseFragment { 38 | 39 | 40 | private static final int REQUEST_LOGIN_FOR_TRACK = 2; 41 | 42 | private static final int REQUEST_LOGIN_FOR_FOLLOW = 50001; 43 | 44 | private int screenHeightPixels; 45 | 46 | private LayoutInflater layoutInflater; 47 | 48 | private Context context; 49 | 50 | 51 | private ImageView fakeNaviBack; 52 | private PagerSlidingTabStrip fragmentsTab; 53 | private ViewPager viewPager; 54 | private StickyNavLayout stickyNav; 55 | private ViewGroup actionLayout; 56 | private LinearLayout fakeActionLayout; 57 | private TextView actionLayoutTitle; 58 | private View statusBarBackGround; 59 | 60 | private AlbumPageFragmentsAdapter fragmentsPagerAdapter; 61 | 62 | private ImageView blurAlbumImage; 63 | 64 | private int actionLayoutHeight; 65 | 66 | 67 | private DownloadManager downloadManager; 68 | 69 | private StickyNavLayout.OnScrollChangeListener onScrollChangeListener = new StickyNavLayout.OnScrollChangeListener() { 70 | @Override 71 | public void onScrollChange(View v, int scrollX, int scrollY, int maxScrollY) { 72 | float scrollPercent = 0; 73 | //条件验证 74 | if (scrollY >= 0 && maxScrollY > 0 && maxScrollY >= scrollY) { 75 | scrollPercent = scrollY * 1f / maxScrollY; 76 | //改变actionLayout透明度 77 | ViewCompat.setAlpha(actionLayout, scrollPercent); 78 | //改变fakeActionLayout透明度 79 | ViewCompat.setAlpha(fakeActionLayout, 1 - scrollPercent); 80 | //设置渐变色,并防止双层显示不美观 81 | int gradualColor = Tool.getBlended(Color.WHITE, Color.BLACK,scrollPercent); 82 | fakeNaviBack.setColorFilter(gradualColor); 83 | if(Tool.isStatusBarTranslucentEnable()){ 84 | //为了更充分的浸入式体验,连乘处理以够降低黑色状态栏显示的程度,从而底部图片得到更多的展示,滑到底时仍完全显示黑色状态栏 85 | ViewCompat.setAlpha(statusBarBackGround, scrollPercent*scrollPercent*scrollPercent); 86 | } 87 | } 88 | } 89 | }; 90 | 91 | 92 | 93 | 94 | public AlbumFragment() { 95 | 96 | } 97 | 98 | public static AlbumFragment newInstance() { 99 | AlbumFragment albumFragment = new AlbumFragment(); 100 | return albumFragment; 101 | } 102 | 103 | protected void findViews() { 104 | //stickyNav 105 | blurAlbumImage = (ImageView)findViewById(R.id.blurAlbumImage); 106 | stickyNav = (StickyNavLayout) findViewById(R.id.stickyNav); 107 | viewPager = (ViewPager) findViewById(R.id.viewpager); 108 | fragmentsTab = (PagerSlidingTabStrip) findViewById(R.id.fragmentsTab); 109 | PullZoomStickyNavLayout pullZoomView = (PullZoomStickyNavLayout) findViewById(R.id.pullZoomView); 110 | pullZoomView.setHeaderContainer((ViewGroup) findViewById(R.id.topView)); 111 | pullZoomView.setZoomView(findViewById(R.id.topView)); 112 | //actionLayout 113 | actionLayout = (ViewGroup) findViewById(R.id.actionLayout); 114 | actionLayoutTitle = (TextView) actionLayout.findViewById(R.id.title); 115 | actionLayoutTitle.setText("沉浸式嵌套滑动 and 渐变"); 116 | statusBarBackGround = actionLayout.findViewById(R.id.statusBarBackGround); 117 | //fakeActionLayout 118 | fakeActionLayout = (LinearLayout) findViewById(R.id.fakeActionLayout); 119 | fakeActionLayout.findViewById(R.id.barRoot).setBackgroundColor(fakeActionLayout.getResources().getColor(R.color.transparent)); 120 | fakeNaviBack = (ImageView) fakeActionLayout.findViewById(naviBack); 121 | fakeNaviBack.setImageResource(R.drawable.white_ico); 122 | fragmentsTab.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 123 | @Override 124 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 125 | 126 | } 127 | 128 | @Override 129 | public void onPageSelected(int position) { 130 | } 131 | 132 | @Override 133 | public void onPageScrollStateChanged(int state) { 134 | 135 | } 136 | }); 137 | fakeNaviBack.setOnClickListener(new View.OnClickListener() { 138 | @Override 139 | public void onClick(View v) { 140 | getActivity().finish(); 141 | } 142 | }); 143 | stickyNav.setOnScrollChangeListener(onScrollChangeListener); 144 | } 145 | 146 | @Override 147 | protected void init() { 148 | //无论是否有数据,返回键可以点击 149 | loadData(); 150 | findViews(); 151 | //沉浸式状态栏 152 | blurAlbumImage.post(new Runnable() { 153 | @Override 154 | public void run() { 155 | actionLayoutHeight = actionLayout.getHeight(); 156 | try { 157 | if (Tool.isStatusBarTranslucentEnable()) { 158 | //已经在AlbumTrackListActivity getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 159 | int statusBarHeight = Tool.getStatusBarHeight(getActivity()); 160 | //返回按钮 161 | findViewById(R.id.contentInfoLayout).setPadding(0, Tool.getStatusBarHeight(getActivity()), 0, 0); 162 | //模糊图 163 | RelativeLayout.LayoutParams blurAlbumImageLayoutParams = (RelativeLayout.LayoutParams) blurAlbumImage.getLayoutParams(); 164 | blurAlbumImageLayoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; 165 | blurAlbumImageLayoutParams.height = Tool.getPixelsFromResource(actionLayout.getResources(), R.dimen.album_fragment_blur_image_height) + statusBarHeight; 166 | blurAlbumImage.setLayoutParams(blurAlbumImageLayoutParams); 167 | //tab 168 | /* LinearLayout.LayoutParams fragmentsTabLayoutParams = (LinearLayout.LayoutParams) fragmentsTab.getLayoutParams(); 169 | fragmentsTabLayoutParams.setMargins(0, statusBarHeight, 0, 0); 170 | fragmentsTab.setLayoutParams(fragmentsTabLayoutParams);*/ 171 | //虽然actionLayout设置了padding 但直到绘制下一帧actionLayout的getHeight()才会返回含padding的值, 172 | fakeActionLayout.setPadding(0, statusBarHeight, 0, 0); 173 | stickyNav.setActionLayoutHeight(actionLayoutHeight + statusBarHeight); 174 | ViewGroup.LayoutParams statusBarBgLayoutParams = statusBarBackGround.getLayoutParams(); 175 | statusBarBgLayoutParams.height = statusBarHeight; 176 | statusBarBackGround.setLayoutParams(statusBarBgLayoutParams); 177 | } else { 178 | stickyNav.setActionLayoutHeight(actionLayoutHeight); 179 | } 180 | }catch (Exception e){ 181 | e.printStackTrace(); 182 | } 183 | } 184 | }); 185 | 186 | //init data 187 | } 188 | 189 | private void loadData() { 190 | doLoadDefaultData(); 191 | } 192 | 193 | private void doLoadDefaultData() { 194 | initData(); 195 | actionLayout.setAlpha(0); 196 | blurAlbumImage.setVisibility(View.VISIBLE); 197 | } 198 | 199 | 200 | 201 | private void initData() { 202 | List fragments = new ArrayList<>(); 203 | fragments.add(AlbumTracksFragment.newInstance()); 204 | fragments.add(AlbumDetailInfoFragment.newInstance()); 205 | fragmentsPagerAdapter = new AlbumPageFragmentsAdapter(getActivity().getSupportFragmentManager(), fragments); 206 | viewPager.setAdapter(fragmentsPagerAdapter); 207 | fragmentsTab.setViewPager(viewPager); 208 | } 209 | 210 | @Override 211 | protected int getLayoutResourceId() { 212 | return R.layout.fragment_album; 213 | } 214 | 215 | private static class AlbumPageFragmentsAdapter extends FragmentStatePagerAdapter { 216 | 217 | private List fragments; 218 | int trackCount; 219 | 220 | public AlbumPageFragmentsAdapter(FragmentManager fm, 221 | List fragments) { 222 | super(fm); 223 | this.fragments = fragments; 224 | } 225 | 226 | 227 | @Override 228 | public Fragment getItem(int position) { 229 | return fragments.get(position); 230 | } 231 | 232 | @Override 233 | public int getCount() { 234 | return fragments.size(); 235 | } 236 | 237 | @Override 238 | public Object instantiateItem(ViewGroup container, final int position) { 239 | return super.instantiateItem(container, position); 240 | } 241 | 242 | @Override 243 | public CharSequence getPageTitle(int position) { 244 | if (position == 0) { 245 | return "节目"; 246 | } else { 247 | return "详情"; 248 | } 249 | } 250 | } 251 | } -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/fragment/AlbumTracksFragment.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.fragment; 2 | 3 | import android.support.v7.widget.LinearLayoutManager; 4 | import android.support.v7.widget.RecyclerView; 5 | 6 | import kyle.nestedscrolldemo.R; 7 | import kyle.nestedscrolldemo.widget.SimpleRVAdapter; 8 | 9 | 10 | /** 11 | * * Created by hongjunmin on 16/10/25 12 | * 13 | * @author hongjunmin 14 | */ 15 | 16 | public class AlbumTracksFragment extends AbstractBaseFragment{ 17 | 18 | private RecyclerView tracks; 19 | 20 | public static AlbumTracksFragment newInstance() { 21 | return new AlbumTracksFragment(); 22 | } 23 | 24 | @Override 25 | protected int getLayoutResourceId() { 26 | return R.layout.fragment_album_tracks; 27 | } 28 | 29 | @Override 30 | protected void findViews() { 31 | tracks = (RecyclerView) findViewById(R.id.tracks); 32 | } 33 | 34 | @Override 35 | protected void init() { 36 | tracks.setLayoutManager(new LinearLayoutManager(getContext())); 37 | tracks.setAdapter(new SimpleRVAdapter(new String[]{"节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC", 38 | "节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC","节目ABC"})); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/tool/SystemBarTintManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 readyState Software Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package kyle.nestedscrolldemo.tool; 18 | 19 | import android.annotation.SuppressLint; 20 | import android.annotation.TargetApi; 21 | import android.app.Activity; 22 | import android.content.Context; 23 | import android.content.res.Configuration; 24 | import android.content.res.Resources; 25 | import android.content.res.TypedArray; 26 | import android.graphics.drawable.Drawable; 27 | import android.os.Build; 28 | import android.util.DisplayMetrics; 29 | import android.util.TypedValue; 30 | import android.view.Gravity; 31 | import android.view.View; 32 | import android.view.ViewConfiguration; 33 | import android.view.ViewGroup; 34 | import android.view.Window; 35 | import android.view.WindowManager; 36 | import android.widget.FrameLayout.LayoutParams; 37 | 38 | import java.lang.reflect.Method; 39 | 40 | /** 41 | * Class to manage status and navigation bar tint effects when using KitKat 42 | * translucent system UI modes. 43 | * 44 | */ 45 | public class SystemBarTintManager { 46 | 47 | static { 48 | // Android allows a system property to override the presence of the navigation bar. 49 | // Used by the emulator. 50 | // See https://github.com/android/platform_frameworks_base/blob/master/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java#L1076 51 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 52 | try { 53 | Class c = Class.forName("android.os.SystemProperties"); 54 | Method m = c.getDeclaredMethod("get", String.class); 55 | m.setAccessible(true); 56 | sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys"); 57 | } catch (Throwable e) { 58 | sNavBarOverride = null; 59 | } 60 | } 61 | } 62 | 63 | 64 | /** 65 | * The default system bar tint color value. 66 | */ 67 | public static final int DEFAULT_TINT_COLOR = 0x99000000; 68 | 69 | private static String sNavBarOverride; 70 | 71 | private final SystemBarConfig mConfig; 72 | private boolean mStatusBarAvailable; 73 | private boolean mNavBarAvailable; 74 | private boolean mStatusBarTintEnabled; 75 | private boolean mNavBarTintEnabled; 76 | private View mStatusBarTintView; 77 | private View mNavBarTintView; 78 | 79 | /** 80 | * Constructor. Call this in the host activity onCreate method after its 81 | * content view has been set. You should always create new instances when 82 | * the host activity is recreated. 83 | * 84 | * @param activity The host activity. 85 | */ 86 | @TargetApi(19) 87 | public SystemBarTintManager(Activity activity) { 88 | 89 | Window win = activity.getWindow(); 90 | ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); 91 | 92 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 93 | // check theme attrs 94 | int[] attrs = {android.R.attr.windowTranslucentStatus, 95 | android.R.attr.windowTranslucentNavigation}; 96 | TypedArray a = activity.obtainStyledAttributes(attrs); 97 | try { 98 | mStatusBarAvailable = a.getBoolean(0, false); 99 | //noinspection ResourceType 100 | mNavBarAvailable = a.getBoolean(1, false); 101 | } finally { 102 | a.recycle(); 103 | } 104 | 105 | // check window flags 106 | WindowManager.LayoutParams winParams = win.getAttributes(); 107 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 108 | if ((winParams.flags & bits) != 0) { 109 | mStatusBarAvailable = true; 110 | } 111 | bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; 112 | if ((winParams.flags & bits) != 0) { 113 | mNavBarAvailable = true; 114 | } 115 | } 116 | 117 | mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); 118 | // device might not have virtual navigation keys 119 | if (!mConfig.hasNavigtionBar()) { 120 | mNavBarAvailable = false; 121 | } 122 | 123 | if (mStatusBarAvailable) { 124 | setupStatusBarView(activity, decorViewGroup); 125 | } 126 | if (mNavBarAvailable) { 127 | setupNavBarView(activity, decorViewGroup); 128 | } 129 | 130 | } 131 | 132 | /** 133 | * Enable tinting of the system status bar. 134 | * 135 | * If the platform is running Jelly Bean or earlier, or translucent system 136 | * UI modes have not been enabled in either the theme or via window flags, 137 | * then this method does nothing. 138 | * 139 | * @param enabled True to enable tinting, false to disable it (default). 140 | */ 141 | public void setStatusBarTintEnabled(boolean enabled) { 142 | mStatusBarTintEnabled = enabled; 143 | if (mStatusBarAvailable) { 144 | mStatusBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE); 145 | } 146 | } 147 | 148 | /** 149 | * Enable tinting of the system navigation bar. 150 | * 151 | * If the platform does not have soft navigation keys, is running Jelly Bean 152 | * or earlier, or translucent system UI modes have not been enabled in either 153 | * the theme or via window flags, then this method does nothing. 154 | * 155 | * @param enabled True to enable tinting, false to disable it (default). 156 | */ 157 | public void setNavigationBarTintEnabled(boolean enabled) { 158 | mNavBarTintEnabled = enabled; 159 | if (mNavBarAvailable) { 160 | mNavBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE); 161 | } 162 | } 163 | 164 | /** 165 | * Apply the specified color tint to all system UI bars. 166 | * 167 | * @param color The color of the background tint. 168 | */ 169 | public void setTintColor(int color) { 170 | setStatusBarTintColor(color); 171 | setNavigationBarTintColor(color); 172 | } 173 | 174 | /** 175 | * Apply the specified drawable or color resource to all system UI bars. 176 | * 177 | * @param res The identifier of the resource. 178 | */ 179 | public void setTintResource(int res) { 180 | setStatusBarTintResource(res); 181 | setNavigationBarTintResource(res); 182 | } 183 | 184 | /** 185 | * Apply the specified drawable to all system UI bars. 186 | * 187 | * @param drawable The drawable to use as the background, or null to remove it. 188 | */ 189 | public void setTintDrawable(Drawable drawable) { 190 | setStatusBarTintDrawable(drawable); 191 | setNavigationBarTintDrawable(drawable); 192 | } 193 | 194 | /** 195 | * Apply the specified alpha to all system UI bars. 196 | * 197 | * @param alpha The alpha to use 198 | */ 199 | public void setTintAlpha(float alpha) { 200 | setStatusBarAlpha(alpha); 201 | setNavigationBarAlpha(alpha); 202 | } 203 | 204 | /** 205 | * Apply the specified color tint to the system status bar. 206 | * 207 | * @param color The color of the background tint. 208 | */ 209 | public void setStatusBarTintColor(int color) { 210 | if (mStatusBarAvailable) { 211 | mStatusBarTintView.setBackgroundColor(color); 212 | } 213 | } 214 | 215 | /** 216 | * Apply the specified drawable or color resource to the system status bar. 217 | * 218 | * @param res The identifier of the resource. 219 | */ 220 | public void setStatusBarTintResource(int res) { 221 | if (mStatusBarAvailable) { 222 | mStatusBarTintView.setBackgroundResource(res); 223 | } 224 | } 225 | 226 | /** 227 | * Apply the specified drawable to the system status bar. 228 | * 229 | * @param drawable The drawable to use as the background, or null to remove it. 230 | */ 231 | @SuppressWarnings("deprecation") 232 | public void setStatusBarTintDrawable(Drawable drawable) { 233 | if (mStatusBarAvailable) { 234 | mStatusBarTintView.setBackgroundDrawable(drawable); 235 | } 236 | } 237 | 238 | /** 239 | * Apply the specified alpha to the system status bar. 240 | * 241 | * @param alpha The alpha to use 242 | */ 243 | @TargetApi(11) 244 | public void setStatusBarAlpha(float alpha) { 245 | if (mStatusBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 246 | mStatusBarTintView.setAlpha(alpha); 247 | } 248 | } 249 | 250 | /** 251 | * Apply the specified color tint to the system navigation bar. 252 | * 253 | * @param color The color of the background tint. 254 | */ 255 | public void setNavigationBarTintColor(int color) { 256 | if (mNavBarAvailable) { 257 | mNavBarTintView.setBackgroundColor(color); 258 | } 259 | } 260 | 261 | /** 262 | * Apply the specified drawable or color resource to the system navigation bar. 263 | * 264 | * @param res The identifier of the resource. 265 | */ 266 | public void setNavigationBarTintResource(int res) { 267 | if (mNavBarAvailable) { 268 | mNavBarTintView.setBackgroundResource(res); 269 | } 270 | } 271 | 272 | /** 273 | * Apply the specified drawable to the system navigation bar. 274 | * 275 | * @param drawable The drawable to use as the background, or null to remove it. 276 | */ 277 | @SuppressWarnings("deprecation") 278 | public void setNavigationBarTintDrawable(Drawable drawable) { 279 | if (mNavBarAvailable) { 280 | mNavBarTintView.setBackgroundDrawable(drawable); 281 | } 282 | } 283 | 284 | /** 285 | * Apply the specified alpha to the system navigation bar. 286 | * 287 | * @param alpha The alpha to use 288 | */ 289 | @TargetApi(11) 290 | public void setNavigationBarAlpha(float alpha) { 291 | if (mNavBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 292 | mNavBarTintView.setAlpha(alpha); 293 | } 294 | } 295 | 296 | /** 297 | * Get the system bar configuration. 298 | * 299 | * @return The system bar configuration for the current device configuration. 300 | */ 301 | public SystemBarConfig getConfig() { 302 | return mConfig; 303 | } 304 | 305 | /** 306 | * Is tinting enabled for the system status bar? 307 | * 308 | * @return True if enabled, False otherwise. 309 | */ 310 | public boolean isStatusBarTintEnabled() { 311 | return mStatusBarTintEnabled; 312 | } 313 | 314 | /** 315 | * Is tinting enabled for the system navigation bar? 316 | * 317 | * @return True if enabled, False otherwise. 318 | */ 319 | public boolean isNavBarTintEnabled() { 320 | return mNavBarTintEnabled; 321 | } 322 | 323 | private void setupStatusBarView(Context context, ViewGroup decorViewGroup) { 324 | mStatusBarTintView = new View(context); 325 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight()); 326 | params.gravity = Gravity.TOP; 327 | if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) { 328 | params.rightMargin = mConfig.getNavigationBarWidth(); 329 | } 330 | mStatusBarTintView.setLayoutParams(params); 331 | mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR); 332 | mStatusBarTintView.setVisibility(View.GONE); 333 | decorViewGroup.addView(mStatusBarTintView); 334 | } 335 | 336 | private void setupNavBarView(Context context, ViewGroup decorViewGroup) { 337 | mNavBarTintView = new View(context); 338 | LayoutParams params; 339 | if (mConfig.isNavigationAtBottom()) { 340 | params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight()); 341 | params.gravity = Gravity.BOTTOM; 342 | } else { 343 | params = new LayoutParams(mConfig.getNavigationBarWidth(), LayoutParams.MATCH_PARENT); 344 | params.gravity = Gravity.RIGHT; 345 | } 346 | mNavBarTintView.setLayoutParams(params); 347 | mNavBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR); 348 | mNavBarTintView.setVisibility(View.GONE); 349 | decorViewGroup.addView(mNavBarTintView); 350 | } 351 | 352 | /** 353 | * Class which describes system bar sizing and other characteristics for the current 354 | * device configuration. 355 | * 356 | */ 357 | public static class SystemBarConfig { 358 | 359 | private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height"; 360 | private static final String NAV_BAR_HEIGHT_RES_NAME = "navigation_bar_height"; 361 | private static final String NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME = "navigation_bar_height_landscape"; 362 | private static final String NAV_BAR_WIDTH_RES_NAME = "navigation_bar_width"; 363 | private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar"; 364 | 365 | private final boolean mTranslucentStatusBar; 366 | private final boolean mTranslucentNavBar; 367 | private final int mStatusBarHeight; 368 | private final int mActionBarHeight; 369 | private final boolean mHasNavigationBar; 370 | private final int mNavigationBarHeight; 371 | private final int mNavigationBarWidth; 372 | private final boolean mInPortrait; 373 | private final float mSmallestWidthDp; 374 | 375 | private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) { 376 | Resources res = activity.getResources(); 377 | mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); 378 | mSmallestWidthDp = getSmallestWidthDp(activity); 379 | mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME); 380 | mActionBarHeight = getActionBarHeight(activity); 381 | mNavigationBarHeight = getNavigationBarHeight(activity); 382 | mNavigationBarWidth = getNavigationBarWidth(activity); 383 | mHasNavigationBar = (mNavigationBarHeight > 0); 384 | mTranslucentStatusBar = translucentStatusBar; 385 | mTranslucentNavBar = traslucentNavBar; 386 | } 387 | 388 | @TargetApi(14) 389 | private int getActionBarHeight(Context context) { 390 | int result = 0; 391 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 392 | TypedValue tv = new TypedValue(); 393 | context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true); 394 | result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); 395 | } 396 | return result; 397 | } 398 | 399 | @TargetApi(14) 400 | private int getNavigationBarHeight(Context context) { 401 | Resources res = context.getResources(); 402 | int result = 0; 403 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 404 | if (hasNavBar(context)) { 405 | String key; 406 | if (mInPortrait) { 407 | key = NAV_BAR_HEIGHT_RES_NAME; 408 | } else { 409 | key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME; 410 | } 411 | return getInternalDimensionSize(res, key); 412 | } 413 | } 414 | return result; 415 | } 416 | 417 | @TargetApi(14) 418 | private int getNavigationBarWidth(Context context) { 419 | Resources res = context.getResources(); 420 | int result = 0; 421 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 422 | if (hasNavBar(context)) { 423 | return getInternalDimensionSize(res, NAV_BAR_WIDTH_RES_NAME); 424 | } 425 | } 426 | return result; 427 | } 428 | 429 | @TargetApi(14) 430 | private boolean hasNavBar(Context context) { 431 | Resources res = context.getResources(); 432 | int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android"); 433 | if (resourceId != 0) { 434 | boolean hasNav = res.getBoolean(resourceId); 435 | // check override flag (see static block) 436 | if ("1".equals(sNavBarOverride)) { 437 | hasNav = false; 438 | } else if ("0".equals(sNavBarOverride)) { 439 | hasNav = true; 440 | } 441 | return hasNav; 442 | } else { // fallback 443 | return !ViewConfiguration.get(context).hasPermanentMenuKey(); 444 | } 445 | } 446 | 447 | private int getInternalDimensionSize(Resources res, String key) { 448 | int result = 0; 449 | int resourceId = res.getIdentifier(key, "dimen", "android"); 450 | if (resourceId > 0) { 451 | result = res.getDimensionPixelSize(resourceId); 452 | } 453 | return result; 454 | } 455 | 456 | @SuppressLint("NewApi") 457 | private float getSmallestWidthDp(Activity activity) { 458 | DisplayMetrics metrics = new DisplayMetrics(); 459 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 460 | activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); 461 | } else { 462 | // TODO this is not correct, but we don't really care pre-kitkat 463 | activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); 464 | } 465 | float widthDp = metrics.widthPixels / metrics.density; 466 | float heightDp = metrics.heightPixels / metrics.density; 467 | return Math.min(widthDp, heightDp); 468 | } 469 | 470 | /** 471 | * Should a navigation bar appear at the bottom of the screen in the current 472 | * device configuration? A navigation bar may appear on the right side of 473 | * the screen in certain configurations. 474 | * 475 | * @return True if navigation should appear at the bottom of the screen, False otherwise. 476 | */ 477 | public boolean isNavigationAtBottom() { 478 | return (mSmallestWidthDp >= 600 || mInPortrait); 479 | } 480 | 481 | /** 482 | * Get the height of the system status bar. 483 | * 484 | * @return The height of the status bar (in pixels). 485 | */ 486 | public int getStatusBarHeight() { 487 | return mStatusBarHeight; 488 | } 489 | 490 | /** 491 | * Get the height of the action bar. 492 | * 493 | * @return The height of the action bar (in pixels). 494 | */ 495 | public int getActionBarHeight() { 496 | return mActionBarHeight; 497 | } 498 | 499 | /** 500 | * Does this device have a system navigation bar? 501 | * 502 | * @return True if this device uses soft key navigation, False otherwise. 503 | */ 504 | public boolean hasNavigtionBar() { 505 | return mHasNavigationBar; 506 | } 507 | 508 | /** 509 | * Get the height of the system navigation bar. 510 | * 511 | * @return The height of the navigation bar (in pixels). If the device does not have 512 | * soft navigation keys, this will always return 0. 513 | */ 514 | public int getNavigationBarHeight() { 515 | return mNavigationBarHeight; 516 | } 517 | 518 | /** 519 | * Get the width of the system navigation bar when it is placed vertically on the screen. 520 | * 521 | * @return The width of the navigation bar (in pixels). If the device does not have 522 | * soft navigation keys, this will always return 0. 523 | */ 524 | public int getNavigationBarWidth() { 525 | return mNavigationBarWidth; 526 | } 527 | 528 | /** 529 | * Get the layout inset for any system UI that appears at the top of the screen. 530 | * 531 | * @param withActionBar True to include the height of the action bar, False otherwise. 532 | * @return The layout inset (in pixels). 533 | */ 534 | public int getPixelInsetTop(boolean withActionBar) { 535 | return (mTranslucentStatusBar ? mStatusBarHeight : 0) + (withActionBar ? mActionBarHeight : 0); 536 | } 537 | 538 | /** 539 | * Get the layout inset for any system UI that appears at the bottom of the screen. 540 | * 541 | * @return The layout inset (in pixels). 542 | */ 543 | public int getPixelInsetBottom() { 544 | if (mTranslucentNavBar && isNavigationAtBottom()) { 545 | return mNavigationBarHeight; 546 | } else { 547 | return 0; 548 | } 549 | } 550 | 551 | /** 552 | * Get the layout inset for any system UI that appears at the right of the screen. 553 | * 554 | * @return The layout inset (in pixels). 555 | */ 556 | public int getPixelInsetRight() { 557 | if (mTranslucentNavBar && !isNavigationAtBottom()) { 558 | return mNavigationBarWidth; 559 | } else { 560 | return 0; 561 | } 562 | } 563 | 564 | } 565 | 566 | } 567 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/tool/Tool.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.tool; 2 | 3 | import android.app.Activity; 4 | import android.content.res.Resources; 5 | import android.graphics.Color; 6 | import android.graphics.Rect; 7 | import android.os.Build; 8 | import android.view.Window; 9 | 10 | /** 11 | * * Created by hongjunmin on 17/7/5 12 | * 13 | * @author hongjunmin 14 | */ 15 | 16 | public class Tool { 17 | 18 | private static int statusBarHeight; 19 | 20 | public static int getBlended(int originalColor, int blendedColor,float blendRatio) { 21 | int newColor = 0; 22 | int originalAlpha = Color.alpha(originalColor); 23 | int originalR = Color.red(originalColor); 24 | int originalG = Color.green(originalColor); 25 | int originalB = Color.blue(originalColor); 26 | int blendedAlpha = Color.alpha(blendedColor); 27 | int blendedR = Color.red(blendedColor); 28 | int blendedG = Color.green(blendedColor); 29 | int blendedB = Color.blue(blendedColor); 30 | int newAlpha = (int) (originalAlpha*(1-blendRatio) +blendedAlpha*blendRatio); 31 | int newR = (int) (originalR*(1-blendRatio) +blendedR*blendRatio); 32 | int newG = (int) (originalG*(1-blendRatio) +blendedG*blendRatio); 33 | int newB = (int) (originalB*(1-blendRatio) +blendedB*blendRatio); 34 | newColor = Color.argb(newAlpha, newR, newG, newB); 35 | return newColor; 36 | } 37 | 38 | /** 39 | * 判断当前设备的系统版本是否支持状态栏透明化,4.4以上才支持 40 | */ 41 | public static boolean isStatusBarTranslucentEnable() { 42 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; 43 | } 44 | 45 | 46 | /** 47 | * 获取状态栏高度 48 | * 49 | * @return 状态栏高度 单位是px,在华为 SCL-AL00上的高度是50px 50 | * 此方法需要在view的runnable当中执行,比如 51 | * blurAlbumImage.post(new Runnable() { 52 | * @Override public void run() { 53 | * int statusBarHeight = Tool.getStatusBarHeight(getActivity()); 54 | * } 55 | * }); 56 | */ 57 | public static int getStatusBarHeight(Activity activity) { 58 | if (statusBarHeight <= 0) { 59 | Rect rect = new Rect(); 60 | Window window = activity.getWindow(); 61 | window.getDecorView().getWindowVisibleDisplayFrame(rect); 62 | statusBarHeight = rect.top; 63 | } 64 | if (statusBarHeight <= 0) { 65 | return Tool.dp2px(activity.getResources(), 16); 66 | } 67 | return statusBarHeight; 68 | } 69 | 70 | /** 71 | * @return int 72 | * @name dip to pixel 73 | * @desc dip to pixel 74 | */ 75 | public static int dp2px(Resources resources, float dpValue) { 76 | final float scale = resources.getDisplayMetrics().density; 77 | return (int) (dpValue * scale + 0.5f); 78 | } 79 | 80 | public static int getPixelsFromResource(Resources resources,int dimensionResourceId){ 81 | return (int)(resources.getDimension(dimensionResourceId)+0.5); 82 | } 83 | 84 | public static boolean isEmpty(T[] array) { 85 | return array == null || array.length == 0; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/tool/UIHelper.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.tool; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.app.Activity; 6 | import android.content.Context; 7 | import android.graphics.Color; 8 | import android.graphics.drawable.Drawable; 9 | import android.os.Build; 10 | import android.support.annotation.NonNull; 11 | import android.support.design.widget.TabLayout; 12 | import android.support.v4.content.ContextCompat; 13 | import android.view.KeyEvent; 14 | import android.view.LayoutInflater; 15 | import android.view.View; 16 | import android.view.ViewGroup; 17 | import android.view.Window; 18 | import android.view.WindowManager; 19 | import android.view.inputmethod.EditorInfo; 20 | import android.view.inputmethod.InputMethodManager; 21 | import android.widget.EditText; 22 | import android.widget.TextView; 23 | import android.widget.Toast; 24 | 25 | /** 26 | * * Created by hongjunmin on 17/3/16 27 | * 28 | * @author hongjunmin 29 | */ 30 | 31 | /** 32 | * UI辅助类,比如自适应drawable, 混色,EditText设置 33 | */ 34 | public class UIHelper { 35 | 36 | /** 37 | * 根据文字大小自适配drawable 38 | * 设置右侧的ico时会有bug,即文字显示不全,推荐使用Textview.setCompoundDrawablesWithIntrinsicBounds 39 | * 如果非要用此方法,就在setText的时候末尾加几个空格 40 | * @param textView 41 | * @param leftDrawable 42 | * @param topDrawable 43 | * @param rightDrawable 44 | * @param bottomDrawable 45 | */ 46 | public static void ajustCompoundDrawableSizeWithText(final TextView textView, final Drawable leftDrawable, final Drawable topDrawable, final Drawable rightDrawable, final Drawable bottomDrawable) { 47 | //API大于11时才能自适应 48 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 49 | textView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { 50 | @Override 51 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { 52 | if(leftDrawable != null){ 53 | leftDrawable.setBounds(0, 0, (int)textView.getTextSize(), (int)textView.getTextSize()); 54 | } 55 | if(topDrawable != null){ 56 | topDrawable.setBounds(0, 0, (int)textView.getTextSize(), (int)textView.getTextSize()); 57 | } 58 | if(rightDrawable != null){ 59 | rightDrawable.setBounds(0, 0, (int)textView.getTextSize(), (int)textView.getTextSize()); 60 | } 61 | if(bottomDrawable != null){ 62 | bottomDrawable.setBounds(0, 0, (int)textView.getTextSize(), (int)textView.getTextSize()); 63 | } 64 | textView.setCompoundDrawables(leftDrawable, topDrawable, rightDrawable, bottomDrawable); 65 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 66 | textView.removeOnLayoutChangeListener(this); 67 | } 68 | } 69 | }); 70 | }else { 71 | textView.setCompoundDrawables(leftDrawable, topDrawable, rightDrawable, bottomDrawable); 72 | } 73 | } 74 | 75 | /** 76 | * 根据文字大小自适配drawable 77 | * 设置右侧的ico时会有bug,即文字显示不全,推荐使用Textview.setCompoundDrawablesWithIntrinsicBounds 78 | * 如果非要用此方法,就在setText的时候末尾加几个空格 79 | * @param textView 80 | * @param leftDrawableResId 81 | * @param topDrawableResId 82 | * @param rightDrawableResId 83 | * @param bottomDrawableResId 84 | */ 85 | public static void ajustCompoundDrawableSizeWithText(final TextView textView, int leftDrawableResId, int topDrawableResId, int rightDrawableResId, int bottomDrawableResId) { 86 | Drawable leftDrawable = null; 87 | Drawable topDrawable = null; 88 | Drawable rightDrawable = null; 89 | Drawable bottomDrawable = null; 90 | 91 | if(leftDrawableResId != 0){ 92 | leftDrawable = ContextCompat.getDrawable(textView.getContext(),leftDrawableResId); 93 | }if(topDrawableResId != 0){ 94 | topDrawable = ContextCompat.getDrawable(textView.getContext(),topDrawableResId); 95 | }if(rightDrawableResId != 0){ 96 | rightDrawable = ContextCompat.getDrawable(textView.getContext(),rightDrawableResId); 97 | }if(bottomDrawableResId != 0) { 98 | bottomDrawable = ContextCompat.getDrawable(textView.getContext(),bottomDrawableResId); 99 | } 100 | ajustCompoundDrawableSizeWithText(textView,leftDrawable,topDrawable,rightDrawable,bottomDrawable); 101 | } 102 | 103 | /** 104 | * 105 | * 简单配置TabLayout的快捷方法 106 | * @param tabLayout 107 | * @param titles 标题数组 108 | * @param layoutResId textView所使用的布局文件,TextView为根节点 109 | */ 110 | public static void setUpTabLayout(TabLayout tabLayout, String[] titles, int layoutResId){ 111 | if(!Tool.isEmpty(titles)){ 112 | for(int i = 0; i= Build.VERSION_CODES.KITKAT) { 230 | setTranslucentStatus(activity, true); 231 | SystemBarTintManager tintManager = new SystemBarTintManager(activity); 232 | tintManager.setStatusBarTintEnabled(true); 233 | // 使用颜色资源 234 | tintManager.setStatusBarTintResource(colorId); 235 | } 236 | } 237 | 238 | private static void setTranslucentStatus(Activity activity, boolean on) { 239 | Window win = activity.getWindow(); 240 | WindowManager.LayoutParams winParams = win.getAttributes(); 241 | final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 242 | if (on) { 243 | 244 | winParams.flags |= bits; 245 | 246 | } else { 247 | 248 | winParams.flags &= ~bits; 249 | 250 | } 251 | win.setAttributes(winParams); 252 | } 253 | 254 | 255 | public static void slide(boolean slideIn, final View view,final ValueAnimator slideInAni,final ValueAnimator slideOutAni) { 256 | view.clearAnimation(); 257 | if (slideIn) { 258 | slideInAni.removeAllUpdateListeners(); 259 | slideInAni.removeAllListeners(); 260 | slideInAni.setTarget(view); 261 | slideInAni.addListener(new Animator.AnimatorListener() { 262 | @Override 263 | public void onAnimationStart(Animator animation) { 264 | 265 | } 266 | 267 | @Override 268 | public void onAnimationEnd(Animator animation) { 269 | view.postDelayed(new Runnable() { 270 | @Override 271 | public void run() { 272 | slide(false, view,slideInAni,slideOutAni); 273 | } 274 | }, 3000); 275 | } 276 | 277 | @Override 278 | public void onAnimationCancel(Animator animation) { 279 | 280 | } 281 | 282 | @Override 283 | public void onAnimationRepeat(Animator animation) { 284 | 285 | } 286 | }); 287 | slideInAni.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 288 | @Override 289 | public void onAnimationUpdate(ValueAnimator animation) { 290 | int animatorValue = Integer.valueOf(animation.getAnimatedValue() + ""); 291 | ViewGroup.LayoutParams params = view.getLayoutParams(); 292 | params.height = animatorValue; 293 | view.setLayoutParams(params); 294 | } 295 | }); 296 | slideInAni.start(); 297 | } else { 298 | slideOutAni.setTarget(view); 299 | slideOutAni.removeAllUpdateListeners(); 300 | slideOutAni.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 301 | @Override 302 | public void onAnimationUpdate(ValueAnimator animation) { 303 | int animatorValue = Integer.valueOf(animation.getAnimatedValue() + ""); 304 | ViewGroup.LayoutParams params = view.getLayoutParams(); 305 | params.height = animatorValue; 306 | view.setLayoutParams(params); 307 | } 308 | }); 309 | slideOutAni.start(); 310 | } 311 | } 312 | } 313 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/widget/AppBarStateChangeListener.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.widget; 2 | 3 | import android.support.design.widget.AppBarLayout; 4 | 5 | public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener { 6 | 7 | public enum State { 8 | EXPANDED, 9 | COLLAPSED, 10 | IDLE 11 | } 12 | 13 | private State mCurrentState = State.IDLE; 14 | 15 | @Override 16 | public final void onOffsetChanged(AppBarLayout appBarLayout, int i) { 17 | if (i == 0) { 18 | if (mCurrentState != State.EXPANDED) { 19 | onStateChanged(appBarLayout, State.EXPANDED); 20 | } 21 | mCurrentState = State.EXPANDED; 22 | } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) { 23 | if (mCurrentState != State.COLLAPSED) { 24 | onStateChanged(appBarLayout, State.COLLAPSED); 25 | } 26 | mCurrentState = State.COLLAPSED; 27 | } else { 28 | if (mCurrentState != State.IDLE) { 29 | onStateChanged(appBarLayout, State.IDLE); 30 | } 31 | mCurrentState = State.IDLE; 32 | } 33 | } 34 | public abstract void onStateChanged(AppBarLayout appBarLayout, State state); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/widget/PlayerHeadZoomScrollView.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.widget; 2 | 3 | import android.animation.ObjectAnimator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Color; 7 | import android.util.AttributeSet; 8 | import android.util.Log; 9 | import android.view.MotionEvent; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.view.animation.DecelerateInterpolator; 13 | import android.view.animation.Interpolator; 14 | import android.widget.ImageView; 15 | import android.widget.ScrollView; 16 | import android.widget.TextView; 17 | 18 | import kyle.nestedscrolldemo.R; 19 | 20 | 21 | /** 22 | * 下拉缩放上方布局,松开回弹的scrollView 23 | */ 24 | 25 | public class PlayerHeadZoomScrollView extends ScrollView { 26 | 27 | // 最大的放大倍数 28 | public static final float DEFAULT_MAX_SCALE_TIMES = 1.8f; 29 | 30 | // 滑动放大系数,系数越大,滑动时放大程度越大 31 | public static final float DEFAULT_SCALE_RATIO = 1.5f; 32 | 33 | // 回弹时间系数,系数越小,回弹越快 34 | public static final float DEFAULT_REPLAY_RATIO = 0.8f; 35 | 36 | public PlayerHeadZoomScrollView(Context context) { 37 | super(context); 38 | } 39 | 40 | public PlayerHeadZoomScrollView(Context context, AttributeSet attrs) { 41 | super(context, attrs); 42 | } 43 | 44 | public PlayerHeadZoomScrollView(Context context, AttributeSet attrs, int defStyleAttr) { 45 | super(context, attrs, defStyleAttr); 46 | } 47 | 48 | private ZoomDirection zoomDirection = ZoomDirection.VERTICAL; 49 | 50 | // 用于记录下拉位置 51 | private float y = 0f; 52 | // zoomView原本的宽高 53 | private int zoomViewWidth = 0; 54 | private int zoomViewHeight = 0; 55 | 56 | // 是否正在放大 57 | private boolean mScaling = false; 58 | 59 | // 放大的view,默认为第一个子view 60 | private View zoomView; 61 | public void setZoomView(View zoomView) { 62 | this.zoomView = zoomView; 63 | } 64 | 65 | // 滑动放大系数,系数越大,滑动时放大程度越大 66 | private float scaleRatio = DEFAULT_SCALE_RATIO; 67 | // 最大的放大倍数 68 | private float maxScaleTimes = DEFAULT_MAX_SCALE_TIMES; 69 | 70 | // 回弹时间系数,系数越小,回弹越快 71 | private float mReplyRatio = DEFAULT_REPLAY_RATIO; 72 | public void setmReplyRatio(float mReplyRatio) { 73 | this.mReplyRatio = mReplyRatio; 74 | } 75 | 76 | @Override 77 | protected void onFinishInflate() { 78 | super.onFinishInflate(); 79 | // 不可过度滚动,否则上移后下拉会出现部分空白的情况 80 | setOverScrollMode(OVER_SCROLL_NEVER); 81 | // 获得默认第一个view 82 | if (getChildAt(0) != null && getChildAt(0) instanceof ViewGroup && zoomView == null) { 83 | ViewGroup vg = (ViewGroup) getChildAt(0); 84 | if (vg.getChildCount() > 0) { 85 | zoomView = vg.getChildAt(0); 86 | } 87 | } 88 | } 89 | 90 | @Override 91 | public boolean onTouchEvent(MotionEvent ev) { 92 | if (zoomViewWidth <= 0 || zoomViewHeight <=0) { 93 | zoomViewWidth = zoomView.getMeasuredWidth(); 94 | zoomViewHeight = zoomView.getMeasuredHeight(); 95 | } 96 | if (zoomView == null || zoomViewWidth <= 0 || zoomViewHeight <= 0) { 97 | return super.onTouchEvent(ev); 98 | } 99 | switch (ev.getAction()) { 100 | case MotionEvent.ACTION_MOVE: 101 | if (!mScaling) { 102 | if (getScrollY() == 0) { 103 | y = ev.getY();//滑动到顶部时,记录位置 104 | } else { 105 | break; 106 | } 107 | } 108 | int distance = (int) ((ev.getY() - y)* scaleRatio); 109 | if (distance < 0) break;//若往下滑动 110 | mScaling = true; 111 | setZoom(distance); 112 | return true; 113 | case MotionEvent.ACTION_UP: 114 | mScaling = false; 115 | replyView(); 116 | break; 117 | } 118 | return super.onTouchEvent(ev); 119 | } 120 | 121 | /**放大view*/ 122 | private void setZoom(float s) { 123 | float scaleTimes = (float) ((zoomViewHeight+s)/(zoomViewHeight*1.0)); 124 | // 如超过最大放大倍数,直接返回 125 | if (scaleTimes > maxScaleTimes || scaleTimes <0) return; 126 | setZoomParamLayout(s); 127 | } 128 | 129 | /**回弹*/ 130 | private void replyView() { 131 | float distance = 0; 132 | if(ZoomDirection.HORIZONTAL.equals(zoomDirection) || ZoomDirection.CIRCLE.equals(zoomDirection)){ 133 | distance = zoomView.getMeasuredWidth() - zoomViewWidth; 134 | } 135 | if(ZoomDirection.VERTICAL.equals(zoomDirection) || ZoomDirection.CIRCLE.equals(zoomDirection)){ 136 | distance = zoomView.getMeasuredHeight() - zoomViewHeight; 137 | } 138 | // 设置动画 139 | ValueAnimator anim = ObjectAnimator.ofFloat(distance, 0.0F).setDuration((long) (distance * mReplyRatio)); 140 | Interpolator interpolator = new DecelerateInterpolator(); 141 | anim.setInterpolator(interpolator); 142 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 143 | @Override 144 | public void onAnimationUpdate(ValueAnimator animation) { 145 | setZoom((Float) animation.getAnimatedValue()); 146 | } 147 | }); 148 | anim.start(); 149 | } 150 | 151 | @Override 152 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { 153 | super.onScrollChanged(l, t, oldl, oldt); 154 | if (onScrollListener!=null) onScrollListener.onScroll(l,t,oldl,oldt); 155 | } 156 | 157 | private OnScrollListener onScrollListener; 158 | public void setOnScrollListener(OnScrollListener onScrollListener) { 159 | this.onScrollListener = onScrollListener; 160 | } 161 | 162 | /**滑动监听*/ 163 | public interface OnScrollListener{ 164 | void onScroll(int scrollX, int scrollY, int oldScrollX, int oldScrollY); 165 | } 166 | 167 | private int lastScrollY = 0; 168 | 169 | @Override 170 | protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { 171 | super.onOverScrolled(scrollX, scrollY, clampedX, clampedY); 172 | if (scrollY>=0) { 173 | float persent = scrollY * 1f / (mByWhichView.getTop() + mByWhichView.getMeasuredHeight()); 174 | int alpha = (int) (255 * persent); 175 | if (alpha > 255){ 176 | alpha = 255; 177 | } 178 | Log.d("dhc", "alpha "+alpha); 179 | int color = Color.argb(alpha,255,255,255); 180 | changeView.setBackgroundColor(color); 181 | 182 | int statusColor = Color.argb(alpha,0,0,0); 183 | statusBgView.setBackgroundColor(statusColor); 184 | 185 | int tmp = 255 - alpha; 186 | int textColor = Color.argb(255,tmp,tmp,tmp); 187 | tvTitle.setTextColor(textColor); 188 | lastScrollY = scrollY; 189 | 190 | if (tmp > 125){ 191 | ivMore.setImageResource(R.drawable.xml_player_more); 192 | ivSwipe.setImageResource(R.drawable.xml_player_back); 193 | }else{ 194 | ivMore.setImageResource(R.drawable.xml_player_more_black); 195 | ivSwipe.setImageResource(R.drawable.xml_player_back_black); 196 | } 197 | } 198 | } 199 | 200 | private View changeView; 201 | 202 | private View mByWhichView; 203 | 204 | private TextView tvTitle; 205 | 206 | private ImageView ivMore; 207 | 208 | private ImageView ivSwipe; 209 | 210 | private View statusBgView; 211 | 212 | public void setNeedChangeView(View view){ 213 | changeView = view; 214 | } 215 | 216 | public void setStatusBgView(View statusBgView){ 217 | this.statusBgView = statusBgView; 218 | } 219 | 220 | public void setupByWhichView(View view) { 221 | mByWhichView = view; 222 | } 223 | 224 | public void setTextView(TextView textView){ 225 | tvTitle = textView; 226 | } 227 | 228 | public void setMoreView(ImageView imageView){ 229 | ivMore = imageView; 230 | } 231 | public void setSwipeView(ImageView imageView){ 232 | ivSwipe = imageView; 233 | } 234 | 235 | 236 | enum ZoomDirection { 237 | 238 | HORIZONTAL(), 239 | VERTICAL(), 240 | CIRCLE(); 241 | 242 | } 243 | 244 | 245 | public ZoomDirection getZoomDirection() { 246 | return zoomDirection; 247 | } 248 | 249 | public void setZoomDirection(ZoomDirection zoomDirection){ 250 | this.zoomDirection = zoomDirection; 251 | } 252 | 253 | private void setZoomParamLayout(float s) { 254 | ViewGroup.LayoutParams layoutParams = zoomView.getLayoutParams(); 255 | if(ZoomDirection.HORIZONTAL.equals(zoomDirection) || ZoomDirection.CIRCLE.equals(zoomDirection)){ 256 | layoutParams.width = (int) (zoomViewWidth + s); 257 | // 设置控件水平居中 258 | ((MarginLayoutParams) layoutParams).setMargins(-(layoutParams.width - zoomViewWidth) / 2, 0, 0, 0); 259 | } 260 | if(ZoomDirection.VERTICAL.equals(zoomDirection) || ZoomDirection.CIRCLE.equals(zoomDirection)){ 261 | layoutParams.height = (int)(zoomViewHeight*((zoomViewWidth+s)/zoomViewWidth)); 262 | } 263 | zoomView.setLayoutParams(layoutParams); 264 | } 265 | } -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/widget/PullZoomBaseView.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | import android.view.ViewConfiguration; 9 | import android.view.ViewGroup; 10 | import android.widget.LinearLayout; 11 | 12 | import static kyle.nestedscrolldemo.widget.PlayerHeadZoomScrollView.DEFAULT_MAX_SCALE_TIMES; 13 | import static kyle.nestedscrolldemo.widget.PlayerHeadZoomScrollView.DEFAULT_REPLAY_RATIO; 14 | import static kyle.nestedscrolldemo.widget.PlayerHeadZoomScrollView.DEFAULT_SCALE_RATIO; 15 | 16 | /** 17 | * 18 | * @author dinus 19 | */ 20 | public abstract class PullZoomBaseView extends LinearLayout { 21 | 22 | // 滑动放大系数,系数越大,滑动时放大程度越大 23 | protected float scaleRatio = DEFAULT_SCALE_RATIO; 24 | 25 | // 最大的放大倍数 26 | protected float maxScaleTimes = DEFAULT_MAX_SCALE_TIMES; 27 | 28 | // 回弹时间系数,系数越小,回弹越快 29 | protected float mReplyRatio = DEFAULT_REPLAY_RATIO; 30 | 31 | public static final int ZOOM_HEADER = 0; 32 | public static final int ZOOM_FOOTER = 1; 33 | 34 | protected T mWrapperView; 35 | protected ViewGroup mHeaderContainer; 36 | protected View mZoomView; 37 | 38 | private float mInitTouchY; 39 | private float mInitTouchX; 40 | private float mLastTouchX; 41 | private float mLastTouchY; 42 | 43 | private boolean isZoomEnable; 44 | private boolean isZooming; 45 | private boolean isPullStart; 46 | 47 | protected int mMode; 48 | private int mTouchSlop; 49 | 50 | private OnPullZoomListener mOnPullZoomListener; 51 | 52 | public PullZoomBaseView(Context context) { 53 | this(context, null); 54 | } 55 | 56 | public PullZoomBaseView(Context context, AttributeSet attrs) { 57 | super(context, attrs); 58 | init(context, attrs); 59 | } 60 | 61 | private void init(Context context, AttributeSet attrs){ 62 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); 63 | mMode = createDefaultPullZoomModel(); 64 | 65 | isZoomEnable = true; 66 | isPullStart = false; 67 | isZooming = false; 68 | } 69 | 70 | @Override 71 | public boolean onTouchEvent(MotionEvent event) { 72 | if (!isZoomEnable) { 73 | return false; 74 | } 75 | 76 | if (event.getEdgeFlags() != 0 && event.getAction() == MotionEvent.ACTION_DOWN) { 77 | return false; 78 | } 79 | return performTouchAction(event); 80 | } 81 | 82 | private boolean performTouchAction(MotionEvent event) { 83 | switch (event.getAction()) { 84 | case MotionEvent.ACTION_DOWN: 85 | // do nothing 86 | // the init action has been done in the function onInterceptTouchEvent 87 | break; 88 | 89 | case MotionEvent.ACTION_MOVE: 90 | if (isPullStart) { 91 | return onPullStartActionMove(event); 92 | } 93 | break; 94 | case MotionEvent.ACTION_UP: 95 | case MotionEvent.ACTION_CANCEL: 96 | if (isPullStart) { 97 | return onPullStartActionCancel(); 98 | } 99 | break; 100 | default: 101 | break; 102 | } 103 | return false; 104 | } 105 | 106 | private boolean onPullStartActionMove(MotionEvent event) { 107 | isZooming = true; 108 | mLastTouchY = event.getY(); 109 | mLastTouchX = event.getX(); 110 | 111 | float scrollValue = mMode == ZOOM_HEADER ? 112 | Math.round(Math.min(mInitTouchY - mLastTouchY, 0) * scaleRatio) 113 | : Math.round(Math.max(mInitTouchY - mLastTouchY, 0) * scaleRatio); 114 | pullZoomEvent(scrollValue); 115 | 116 | if (mOnPullZoomListener != null){ 117 | mOnPullZoomListener.onPullZooming(scrollValue); 118 | } 119 | 120 | return true; 121 | } 122 | 123 | private boolean onPullStartActionCancel() { 124 | isPullStart = false; 125 | if (isZooming){ 126 | isZooming = false; 127 | smoothScrollToTop(); 128 | 129 | if (mOnPullZoomListener != null){ 130 | final float scrollValue = mMode == ZOOM_HEADER ? 131 | Math.round(Math.min(mInitTouchY - mLastTouchY, 0) * scaleRatio) 132 | : Math.round(Math.max(mInitTouchY - mLastTouchY, 0) * scaleRatio); 133 | 134 | mOnPullZoomListener.onPullZoomEnd(scrollValue); 135 | } 136 | } 137 | return true; 138 | } 139 | 140 | @Override 141 | public boolean onInterceptTouchEvent(MotionEvent event) { 142 | 143 | if (!isZoomEnable){ 144 | return false; 145 | } 146 | 147 | if (event.getAction() == MotionEvent.ACTION_MOVE && isPullStart){ 148 | return true; 149 | } 150 | 151 | performInterceptAction(event); 152 | return isPullStart; 153 | } 154 | 155 | private void performInterceptAction(MotionEvent event) { 156 | switch (event.getAction()){ 157 | case MotionEvent.ACTION_DOWN: 158 | if (isReadyZoom()){ 159 | onZoomReadyActionDown(event); 160 | } 161 | break; 162 | 163 | case MotionEvent.ACTION_MOVE: 164 | if (isReadyZoom()) { 165 | onZoomReadyActionMove(event); 166 | } 167 | break; 168 | case MotionEvent.ACTION_UP: 169 | case MotionEvent.ACTION_CANCEL: 170 | // do nothing 171 | // the reset action will be done in the function onTouchEvent 172 | break; 173 | default: 174 | break; 175 | } 176 | } 177 | 178 | private void onZoomReadyActionDown(MotionEvent event) { 179 | mInitTouchY = mLastTouchY = event.getY(); 180 | mInitTouchX = mLastTouchX = event.getX(); 181 | isPullStart = false; 182 | } 183 | 184 | private void onZoomReadyActionMove(MotionEvent event) { 185 | float mCurrentX = event.getX(); 186 | float mCurrentY = event.getY(); 187 | 188 | float xDistance = mCurrentX - mLastTouchX; 189 | float yDistance = mCurrentY - mLastTouchY; 190 | 191 | Log.i("debug", "mMode" + mMode + "yDistance " + yDistance + "xDistance " + xDistance); 192 | if (mMode == ZOOM_HEADER && yDistance > mTouchSlop && yDistance > Math.abs(xDistance) 193 | || mMode == ZOOM_FOOTER && -yDistance > mTouchSlop && -yDistance > Math.abs(xDistance)){ 194 | mLastTouchY = mCurrentY; 195 | mLastTouchX = mCurrentX; 196 | 197 | if (mOnPullZoomListener != null){ 198 | mOnPullZoomListener.onPullStart(); 199 | } 200 | isPullStart = true; 201 | } 202 | } 203 | 204 | public void setModel(int mModel) { 205 | this.mMode = mModel; 206 | } 207 | 208 | public void setOnPullZoomListener(OnPullZoomListener mOnPullZoomListener) { 209 | this.mOnPullZoomListener = mOnPullZoomListener; 210 | } 211 | 212 | public void setIsZoomEnable(boolean isZoomEnable) { 213 | this.isZoomEnable = isZoomEnable; 214 | } 215 | 216 | public void setZoomView(View mZoomView) { 217 | this.mZoomView = mZoomView; 218 | } 219 | 220 | public void setHeaderContainer(ViewGroup mHeaderContainer) { 221 | this.mHeaderContainer = mHeaderContainer; 222 | } 223 | 224 | public boolean isZoomEnable() { 225 | return isZoomEnable; 226 | } 227 | 228 | public boolean isZooming() { 229 | return isZooming; 230 | } 231 | 232 | protected abstract T createWrapperView(Context context, AttributeSet attrs); 233 | 234 | protected abstract int createDefaultPullZoomModel(); 235 | 236 | protected abstract boolean isReadyZoom(); 237 | 238 | /** 239 | * @param scrollValue vertical distance scrolled in pixels 240 | * if scrollValue < 0 ; scroll up 241 | * if scrollValue > 0 ; scroll down 242 | */ 243 | protected abstract void pullZoomEvent(float scrollValue); 244 | 245 | protected abstract void smoothScrollToTop(); 246 | 247 | public interface OnPullZoomListener { 248 | void onPullZooming(float newScrollValue); 249 | 250 | void onPullStart(); 251 | 252 | void onPullZoomEnd(float newScrollValue); 253 | } 254 | 255 | public T getWrappedView(){ 256 | if(mWrapperView == null){ 257 | if(getChildCount()>0){ 258 | mWrapperView = (T) getChildAt(0); 259 | } 260 | } 261 | return mWrapperView; 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/widget/PullZoomStickyNavLayout.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.widget; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.view.animation.DecelerateInterpolator; 9 | import android.view.animation.Interpolator; 10 | import android.widget.ImageView; 11 | 12 | /** 13 | * @author dinus 14 | */ 15 | public class PullZoomStickyNavLayout extends PullZoomBaseView { 16 | 17 | private int originalHeaderHeight; 18 | private Interpolator smoothToTopInterpolator; 19 | private ZoomBackRunnable mZoomBackRunnable; 20 | // 图片原本的高 21 | private int originalImageViewHeight = 0; 22 | 23 | public PullZoomStickyNavLayout(Context context) { 24 | this(context, null); 25 | } 26 | 27 | public PullZoomStickyNavLayout(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | init(); 30 | } 31 | 32 | private void init() { 33 | originalHeaderHeight = 0; 34 | smoothToTopInterpolator = createDefaultInterpolator(); 35 | mZoomBackRunnable = new ZoomBackRunnable(); 36 | } 37 | 38 | private Interpolator createDefaultInterpolator() { 39 | return new DecelerateInterpolator(2.0f); 40 | } 41 | 42 | @SuppressWarnings("ResourceType") 43 | @Override 44 | protected StickyNavLayout createWrapperView(Context context, AttributeSet attrs) { 45 | return null; 46 | } 47 | 48 | @Override 49 | protected int createDefaultPullZoomModel() { 50 | return ZOOM_HEADER; 51 | } 52 | 53 | @Override 54 | protected boolean isReadyZoom() { 55 | if (mMode == ZOOM_HEADER) { 56 | return isFirstItemCompletelyVisible(); 57 | } /*else if (mMode == ZOOM_FOOTER) { 58 | return isLastItemCompletelyVisible(); 59 | }*/ 60 | 61 | return false; 62 | } 63 | 64 | @Override 65 | protected void pullZoomEvent(float scrollValue) { 66 | scrollValue = Math.abs(scrollValue); 67 | float scaleTimes = (getHeaderHeight()+scrollValue)/getHeaderHeight(); 68 | if (scaleTimes > maxScaleTimes || scaleTimes <0) return; 69 | 70 | if (mZoomBackRunnable != null && !mZoomBackRunnable.isFinished()) { 71 | mZoomBackRunnable.abortAnimation(); 72 | } 73 | 74 | if (mHeaderContainer != null) { 75 | ViewGroup.LayoutParams layoutParams = mHeaderContainer.getLayoutParams(); 76 | layoutParams.height = (int) (scrollValue+ getHeaderHeight()); 77 | mHeaderContainer.setLayoutParams(layoutParams); 78 | zoomImageView(scrollValue); 79 | } 80 | 81 | /*if (mMode == ZOOM_FOOTER) { 82 | mWrapperView.scrollToPosition(mWrapperView.getAdapter().getItemCount() - 1); 83 | }*/ 84 | } 85 | 86 | private void zoomImageView(float scrollValue) { 87 | scrollValue = Math.abs(scrollValue); 88 | if(originalImageViewHeight <= 0 && mZoomView instanceof ViewGroup){ 89 | ViewGroup vg = (ViewGroup)mZoomView; 90 | for (int i = 0; i < vg.getChildCount(); i++) { 91 | if (vg.getChildAt(i) instanceof ImageView) { 92 | originalImageViewHeight = vg.getChildAt(i).getMeasuredHeight(); 93 | break; 94 | } 95 | } 96 | } 97 | if(mZoomView instanceof ViewGroup){ 98 | ViewGroup vg = (ViewGroup)mZoomView; 99 | for(int i = 0; i< vg.getChildCount(); i++){ 100 | if(vg.getChildAt(i) instanceof ImageView){ 101 | vg.getChildAt(i).getLayoutParams().height = (int) (originalImageViewHeight +scrollValue); 102 | }else { 103 | vg.getChildAt(i).setTranslationY(scrollValue); 104 | } 105 | } 106 | } 107 | } 108 | 109 | @Override 110 | protected void smoothScrollToTop() { 111 | mZoomBackRunnable.startAnimation(mHeaderContainer.getHeight() / getHeaderHeight()*mReplyRatio); 112 | } 113 | 114 | /*public void setAdapter(RecyclerView.Adapter adapter) { 115 | mWrapperView.setAdapter(adapter); 116 | }*/ 117 | 118 | /* 119 | public void setLayoutManager(RecyclerView.LayoutManager manager) { 120 | mWrapperView.setLayoutManager(manager); 121 | } 122 | */ 123 | 124 | public void setSmoothToTopInterpolator(Interpolator sSmoothToTopInterpolator) { 125 | this.smoothToTopInterpolator = sSmoothToTopInterpolator; 126 | } 127 | 128 | private boolean isFirstItemCompletelyVisible() { 129 | if (getWrappedView() != null) { 130 | return getWrappedView().getScrollY()<=0; 131 | } 132 | return false; 133 | } 134 | 135 | private boolean checkFirstItemCompletelyVisible(RecyclerView.LayoutManager mLayoutManager) { 136 | int firstVisiblePosition = ((RecyclerView.LayoutParams) mLayoutManager.getChildAt(0).getLayoutParams()).getViewPosition(); 137 | if (firstVisiblePosition == 0) { 138 | final View firstVisibleChild = getWrappedView().getChildAt(0); 139 | if (firstVisibleChild != null) { 140 | return firstVisibleChild.getTop() >= getWrappedView().getTop(); 141 | } 142 | } 143 | return false; 144 | } 145 | 146 | /* private boolean isLastItemCompletelyVisible() { 147 | if (mWrapperView != null) { 148 | RecyclerView.Adapter adapter = mWrapperView.getAdapter(); 149 | RecyclerView.LayoutManager mLayoutmanager = mWrapperView.getLayoutManager(); 150 | 151 | if (null == adapter || adapter.getItemCount() == 0) { 152 | return true; 153 | } else if (null == mLayoutmanager || mLayoutmanager.getItemCount() == 0){ 154 | return false; 155 | } else { 156 | return checkLastItemCompletelyVisible(mLayoutmanager); 157 | } 158 | } 159 | 160 | return false; 161 | }*/ 162 | 163 | /* private boolean checkLastItemCompletelyVisible(RecyclerView.LayoutManager mLayoutmanager) { 164 | int lastVisiblePosition = mLayoutmanager.getChildCount() - 1; 165 | int currentLastVisiblePosition = ((RecyclerView.LayoutParams) mLayoutmanager.getChildAt(lastVisiblePosition).getLayoutParams()).getViewPosition(); 166 | if (currentLastVisiblePosition == mLayoutmanager.getItemCount() - 1) { 167 | final View lastVisibleChild = mWrapperView.getChildAt(lastVisiblePosition); 168 | if (lastVisibleChild != null) { 169 | if (mHeaderContainer != null && originalHeaderHeight <= 0) { 170 | originalHeaderHeight = mHeaderContainer.getMeasuredHeight(); 171 | } 172 | return lastVisibleChild.getBottom() <= mWrapperView.getBottom(); 173 | } 174 | } 175 | return false; 176 | }*/ 177 | 178 | @Override 179 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 180 | super.onLayout(changed, l, t, r, b); 181 | } 182 | 183 | private class ZoomBackRunnable implements Runnable { 184 | protected float mDuration; 185 | protected boolean mIsFinished = true; 186 | protected float mScale; 187 | protected long mStartTime; 188 | 189 | ZoomBackRunnable() { 190 | } 191 | 192 | public void abortAnimation() { 193 | mIsFinished = true; 194 | } 195 | 196 | public boolean isFinished() { 197 | return mIsFinished; 198 | } 199 | 200 | public void run() { 201 | if (mZoomView != null && (!mIsFinished) && (mScale > 1.0f)) { 202 | // fix PullToZoomView bug ---dinus 203 | // should not convert the System.currentTimeMillis() to float 204 | // otherwise the value of (System.currentTimeMillis() - mStartTime) will still be zero 205 | float zoomBackProgress = (System.currentTimeMillis() - mStartTime) / mDuration; 206 | ViewGroup.LayoutParams localLayoutParams = mHeaderContainer.getLayoutParams(); 207 | 208 | if (zoomBackProgress > 1.0f) { 209 | localLayoutParams.height = getHeaderHeight(); 210 | mHeaderContainer.setLayoutParams(localLayoutParams); 211 | zoomImageView(0); 212 | mIsFinished = true; 213 | return; 214 | } 215 | 216 | float currentSacle = mScale - (mScale - 1.0F) * smoothToTopInterpolator.getInterpolation(zoomBackProgress); 217 | localLayoutParams.height = (int) (currentSacle * getHeaderHeight()); 218 | mHeaderContainer.setLayoutParams(localLayoutParams); 219 | zoomImageView((currentSacle - 1.0F)* originalImageViewHeight); 220 | post(this); 221 | } 222 | } 223 | 224 | public void startAnimation(float animationDuration) { 225 | if (mZoomView != null) { 226 | mStartTime = System.currentTimeMillis(); 227 | mDuration = animationDuration; 228 | mScale = (float) mHeaderContainer.getHeight() / getHeaderHeight(); 229 | mIsFinished = false; 230 | post(this); 231 | } 232 | } 233 | } 234 | 235 | public int getHeaderHeight() { 236 | if (mHeaderContainer != null && originalHeaderHeight <= 0) { 237 | originalHeaderHeight = mHeaderContainer.getMeasuredHeight(); 238 | } 239 | return originalHeaderHeight; 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/widget/RefreshFootView.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.View; 7 | import android.view.animation.Animation; 8 | import android.view.animation.AnimationUtils; 9 | import android.widget.ImageView; 10 | import android.widget.ProgressBar; 11 | import android.widget.TextView; 12 | 13 | import com.aspsine.swipetoloadlayout.SwipeLoadMoreFooterLayout; 14 | 15 | import kyle.nestedscrolldemo.R; 16 | 17 | /** 18 | * Created by Aspsine on 2015/9/9. 19 | */ 20 | public class RefreshFootView extends SwipeLoadMoreFooterLayout { 21 | 22 | View noFreshingLayout; 23 | 24 | View refreshingingLayout; 25 | 26 | private ImageView ivArrow; 27 | 28 | private TextView tvRefresh; 29 | 30 | private TextView loadMore; 31 | 32 | private ProgressBar progressBar; 33 | 34 | private int mHeaderHeight; 35 | 36 | private Animation rotateUp; 37 | 38 | private Animation rotateDown; 39 | 40 | private int mFooterHeight; 41 | 42 | private boolean rotated = false; 43 | 44 | public RefreshFootView(Context context) { 45 | this(context, null); 46 | } 47 | 48 | public RefreshFootView(Context context, AttributeSet attrs) { 49 | this(context, attrs, 0); 50 | } 51 | 52 | public RefreshFootView(Context context, AttributeSet attrs, int defStyleAttr) { 53 | super(context, attrs, defStyleAttr); 54 | mHeaderHeight = getResources().getDimensionPixelOffset(R.dimen.refresh_header_height); 55 | rotateUp = AnimationUtils.loadAnimation(context, R.anim.rotate_reset); 56 | rotateDown = AnimationUtils.loadAnimation(context, R.anim.rotate_roll); 57 | mFooterHeight = getResources().getDimensionPixelOffset(R.dimen.refresh_foot_height); 58 | } 59 | 60 | @Override 61 | protected void onFinishInflate() { 62 | super.onFinishInflate(); 63 | noFreshingLayout = findViewById(R.id.not_refreshing_layout); 64 | refreshingingLayout = findViewById(R.id.refreshing_layout); 65 | tvRefresh = (TextView) findViewById(R.id.tvRefresh); 66 | ivArrow = (ImageView) findViewById(R.id.ivArrow); 67 | progressBar = (ProgressBar) findViewById(R.id.progressbar); 68 | loadMore = (TextView) findViewById(R.id.tv_load_more); 69 | } 70 | 71 | public void onLoadMore() { 72 | toggleLayout(true); 73 | ivArrow.clearAnimation(); 74 | tvRefresh.setText(""); 75 | } 76 | 77 | @Override 78 | public void onPrepare() { 79 | Log.d("TwitterRefreshHeader", "onPrepare()"); 80 | } 81 | 82 | @Override 83 | public void onMove(int y, boolean isComplete, boolean automatic) { 84 | if (!isComplete) { 85 | toggleLayout(false); 86 | if (-y >= mFooterHeight) { 87 | tvRefresh.setText("松开立即加载更多"); 88 | if (!rotated) { 89 | ivArrow.clearAnimation(); 90 | ivArrow.startAnimation(rotateDown); 91 | rotated = true; 92 | } 93 | } else { 94 | if (rotated) { 95 | ivArrow.clearAnimation(); 96 | ivArrow.startAnimation(rotateUp); 97 | rotated = false; 98 | } 99 | tvRefresh.setText("上拉可以加载更多"); 100 | } 101 | } 102 | } 103 | 104 | @Override 105 | public void onRelease() { 106 | Log.d("TwitterRefreshHeader", "onRelease()"); 107 | } 108 | 109 | private void toggleLayout(boolean isRefreshing) { 110 | noFreshingLayout.setVisibility(isRefreshing ? GONE : VISIBLE); 111 | refreshingingLayout.setVisibility(isRefreshing ? VISIBLE : GONE); 112 | } 113 | 114 | @Override 115 | public void onComplete() { 116 | hideViews(); 117 | } 118 | 119 | @Override 120 | public void onReset() { 121 | hideViews(); 122 | } 123 | 124 | 125 | 126 | private void hideViews(){ 127 | noFreshingLayout.setVisibility(GONE); 128 | refreshingingLayout.setVisibility(GONE); 129 | rotated = false; 130 | ivArrow.clearAnimation(); 131 | tvRefresh.setText(""); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/widget/RefreshHeaderView.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.View; 7 | import android.view.animation.Animation; 8 | import android.view.animation.AnimationUtils; 9 | import android.widget.ImageView; 10 | import android.widget.ProgressBar; 11 | import android.widget.TextView; 12 | 13 | import com.aspsine.swipetoloadlayout.SwipeRefreshHeaderLayout; 14 | 15 | import kyle.nestedscrolldemo.R; 16 | 17 | /** 18 | * Created by Aspsine on 2015/9/9. 19 | */ 20 | public class RefreshHeaderView extends SwipeRefreshHeaderLayout { 21 | 22 | View noFreshingLayout; 23 | 24 | View refreshingingLayout; 25 | 26 | private ImageView ivArrow; 27 | 28 | private TextView tvRefresh; 29 | 30 | private TextView lastRefresh; 31 | 32 | private TextView loadMore; 33 | 34 | private ProgressBar progressBar; 35 | 36 | private int mHeaderHeight; 37 | 38 | private Animation rotateUp; 39 | 40 | private Animation rotateDown; 41 | 42 | private boolean rotated = false; 43 | 44 | private long lastUpdateTimeInMillionSeconds; 45 | 46 | public RefreshHeaderView(Context context) { 47 | this(context, null); 48 | } 49 | 50 | public RefreshHeaderView(Context context, AttributeSet attrs) { 51 | this(context, attrs, 0); 52 | } 53 | 54 | public RefreshHeaderView(Context context, AttributeSet attrs, int defStyleAttr) { 55 | super(context, attrs, defStyleAttr); 56 | mHeaderHeight = getResources().getDimensionPixelOffset(R.dimen.refresh_header_height); 57 | rotateUp = AnimationUtils.loadAnimation(context, R.anim.rotate_roll); 58 | rotateDown = AnimationUtils.loadAnimation(context, R.anim.rotate_reset); 59 | } 60 | 61 | @Override 62 | protected void onFinishInflate() { 63 | super.onFinishInflate(); 64 | noFreshingLayout = findViewById(R.id.not_refreshing_layout); 65 | refreshingingLayout = findViewById(R.id.refreshing_layout); 66 | tvRefresh = (TextView) findViewById(R.id.tvRefresh); 67 | ivArrow = (ImageView) findViewById(R.id.ivArrow); 68 | progressBar = (ProgressBar) findViewById(R.id.progressbar); 69 | loadMore = (TextView) findViewById(R.id.tv_load_more); 70 | lastRefresh = (TextView) findViewById(R.id.lastRefresh); 71 | } 72 | 73 | @Override 74 | public void onRefresh() { 75 | toggleLayout(true); 76 | ivArrow.clearAnimation(); 77 | tvRefresh.setText(""); 78 | } 79 | 80 | @Override 81 | public void onPrepare() { 82 | lastRefresh.setText("上次刷新:"); 83 | Log.d("TwitterRefreshHeader", "onPrepare()"); 84 | } 85 | 86 | @Override 87 | public void onMove(int y, boolean isComplete, boolean automatic) { 88 | if (!isComplete) { 89 | if (y > mHeaderHeight) { 90 | tvRefresh.setText("松开立即刷新"); 91 | if (!rotated) { 92 | ivArrow.clearAnimation(); 93 | ivArrow.startAnimation(rotateUp); 94 | rotated = true; 95 | } 96 | } else if (y < mHeaderHeight) { 97 | if (rotated) { 98 | ivArrow.clearAnimation(); 99 | ivArrow.startAnimation(rotateDown); 100 | rotated = false; 101 | } 102 | tvRefresh.setText("下拉可刷新"); 103 | } 104 | 105 | toggleLayout(false); 106 | } 107 | } 108 | 109 | @Override 110 | public void onRelease() { 111 | Log.d("TwitterRefreshHeader", "onRelease()"); 112 | } 113 | 114 | private void toggleLayout(boolean isRefreshing) { 115 | noFreshingLayout.setVisibility(isRefreshing ? GONE : VISIBLE); 116 | refreshingingLayout.setVisibility(isRefreshing ? VISIBLE : GONE); 117 | } 118 | 119 | @Override 120 | public void onComplete() { 121 | hideViews(); 122 | } 123 | 124 | @Override 125 | public void onReset() { 126 | hideViews(); 127 | } 128 | 129 | 130 | private void hideViews() { 131 | noFreshingLayout.setVisibility(GONE); 132 | refreshingingLayout.setVisibility(GONE); 133 | rotated = false; 134 | ivArrow.clearAnimation(); 135 | tvRefresh.setText(""); 136 | } 137 | 138 | public void setLastUpdateTimeInMillionSeconds(long lastUpdateTimeInMillionSeconds) { 139 | this.lastUpdateTimeInMillionSeconds = lastUpdateTimeInMillionSeconds; 140 | } 141 | 142 | public void hidelastRefresh(){ 143 | lastRefresh.setVisibility(View.GONE); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/widget/SimpleRVAdapter.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.widget; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.Gravity; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import kyle.nestedscrolldemo.R; 10 | 11 | /** 12 | * SimpleRVAdapter to quickly get started with simple Lists in Recyclerview 13 | * 14 | * Usage: 15 | * 16 | * RecyclerView rv = (RecyclerView)findViewById(R.id.rv); 17 | * rv.setLayoutManager(new LinearLayoutManager(getContext())); 18 | * rv.setAdapter(new SimpleRVAdapter(new String[] {"1", "2", "3", "4", "5", "6", "7"})); 19 | * 20 | * @author Sheharyar Naseer 21 | */ 22 | public class SimpleRVAdapter extends RecyclerView.Adapter { 23 | private String[] dataSource; 24 | public SimpleRVAdapter(String[] dataArgs){ 25 | dataSource = dataArgs; 26 | } 27 | 28 | @Override 29 | public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 30 | // create a new view 31 | View view = new TextView(parent.getContext()); 32 | SimpleViewHolder viewHolder = new SimpleViewHolder(view); 33 | return viewHolder; 34 | } 35 | 36 | public static class SimpleViewHolder extends RecyclerView.ViewHolder{ 37 | public TextView textView; 38 | public SimpleViewHolder(View itemView) { 39 | super(itemView); 40 | textView = (TextView) itemView; 41 | } 42 | } 43 | 44 | @Override 45 | public void onBindViewHolder(SimpleViewHolder holder, int position) { 46 | holder.textView.setText(dataSource[position]); 47 | holder.textView.setPadding(30,30,30,30); 48 | RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 49 | layoutParams.setMargins(0,0,0,1); 50 | holder.textView.setLayoutParams(layoutParams); 51 | holder.textView.setGravity(Gravity.CENTER); 52 | holder.textView.setBackgroundResource(R.color.green_A0); 53 | } 54 | 55 | @Override 56 | public int getItemCount() { 57 | return dataSource.length; 58 | } 59 | 60 | public String[] getDataSource() { 61 | return dataSource; 62 | } 63 | 64 | public void setDataSource(String[] dataSource) { 65 | this.dataSource = dataSource; 66 | } 67 | } -------------------------------------------------------------------------------- /app/src/main/java/kyle/nestedscrolldemo/widget/StickyNavLayout.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.support.v4.view.NestedScrollingParent; 6 | import android.support.v4.view.ViewCompat; 7 | import android.support.v4.view.ViewPager; 8 | import android.util.AttributeSet; 9 | import android.util.Log; 10 | import android.view.VelocityTracker; 11 | import android.view.View; 12 | import android.view.ViewConfiguration; 13 | import android.view.ViewGroup; 14 | import android.widget.LinearLayout; 15 | import android.widget.OverScroller; 16 | 17 | import kyle.nestedscrolldemo.R; 18 | 19 | public class StickyNavLayout extends LinearLayout implements NestedScrollingParent 20 | { 21 | 22 | private static final String TAG = "StickyNavLayout"; 23 | 24 | private View mTop; 25 | private View mNav; 26 | private ViewPager mViewPager; 27 | 28 | private int mTopViewHeight; 29 | 30 | private OverScroller mScroller; 31 | private VelocityTracker mVelocityTracker; 32 | private int mTouchSlop; 33 | private int mMaximumVelocity, mMinimumVelocity; 34 | 35 | private float mLastY; 36 | private boolean mDragging; 37 | private int actionLayoutHeight; 38 | private OnScrollChangeListener onScrollChangeListener; 39 | 40 | 41 | 42 | 43 | 44 | public StickyNavLayout(Context context, AttributeSet attrs) 45 | { 46 | super(context, attrs); 47 | setOrientation(LinearLayout.VERTICAL); 48 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StickyNavLayout); 49 | actionLayoutHeight = a.getDimensionPixelSize(R.styleable.StickyNavLayout_actionLayoutHeight, 0); 50 | mScroller = new OverScroller(context); 51 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); 52 | mMaximumVelocity = ViewConfiguration.get(context) 53 | .getScaledMaximumFlingVelocity(); 54 | mMinimumVelocity = ViewConfiguration.get(context) 55 | .getScaledMinimumFlingVelocity(); 56 | 57 | } 58 | 59 | private void initVelocityTrackerIfNotExists() 60 | { 61 | if (mVelocityTracker == null) 62 | { 63 | mVelocityTracker = VelocityTracker.obtain(); 64 | } 65 | } 66 | 67 | private void recycleVelocityTracker() 68 | { 69 | if (mVelocityTracker != null) 70 | { 71 | mVelocityTracker.recycle(); 72 | mVelocityTracker = null; 73 | } 74 | } 75 | 76 | 77 | @Override 78 | protected void onFinishInflate() 79 | { 80 | super.onFinishInflate(); 81 | if (getChildCount() < 3) { 82 | throw new RuntimeException("StickyNavLayout must three child view"); 83 | } 84 | mTop = getChildAt(0); 85 | mNav = getChildAt(1); 86 | View view = getChildAt(2); 87 | if (!(view instanceof ViewPager)) 88 | { 89 | throw new RuntimeException( 90 | "third child of StickyNavLayout should use ViewPager !"); 91 | } 92 | mViewPager = (ViewPager) view; 93 | } 94 | 95 | @Override 96 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 97 | { 98 | //不限制顶部的高度 99 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 100 | getChildAt(0).measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 101 | ViewGroup.LayoutParams params = mViewPager.getLayoutParams(); 102 | params.height = getMeasuredHeight() - mNav.getMeasuredHeight()-actionLayoutHeight; 103 | mViewPager.setLayoutParams(params); 104 | setMeasuredDimension(getMeasuredWidth(), mTop.getMeasuredHeight() + mNav.getMeasuredHeight()+ mViewPager.getMeasuredHeight()); 105 | 106 | } 107 | 108 | @Override 109 | protected void onSizeChanged(int w, int h, int oldw, int oldh) 110 | { 111 | super.onSizeChanged(w, h, oldw, oldh); 112 | mTopViewHeight = mTop.getMeasuredHeight(); 113 | } 114 | 115 | 116 | public void fling(int velocityY) 117 | { 118 | mScroller.fling(0, getScrollY(), 0, velocityY, 0, 0, 0, getMaxScrollHeight()); 119 | invalidate(); 120 | } 121 | 122 | @Override 123 | public void scrollTo(int x, int y) 124 | { 125 | if (y < 0) 126 | { 127 | y = 0; 128 | } 129 | if (y > getMaxScrollHeight()) 130 | { 131 | y = getMaxScrollHeight(); 132 | } 133 | if (y != getScrollY()) 134 | { 135 | super.scrollTo(x, y); 136 | } 137 | if(onScrollChangeListener != null){ 138 | onScrollChangeListener.onScrollChange(this,x,y,getMaxScrollHeight()); 139 | } 140 | } 141 | 142 | @Override 143 | public void computeScroll() 144 | { 145 | if (mScroller.computeScrollOffset()) 146 | { 147 | scrollTo(0, mScroller.getCurrY()); 148 | invalidate(); 149 | } 150 | } 151 | 152 | @Override 153 | public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) 154 | { 155 | Log.e(TAG, "onStartNestedScroll"); 156 | return true; 157 | } 158 | 159 | @Override 160 | public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) 161 | { 162 | Log.e(TAG, "onNestedScrollAccepted"); 163 | } 164 | 165 | @Override 166 | public void onStopNestedScroll(View target) 167 | { 168 | Log.e(TAG, "onStopNestedScroll"); 169 | } 170 | 171 | @Override 172 | public void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) 173 | { 174 | Log.e(TAG, "onNestedScroll"); 175 | } 176 | 177 | @Override 178 | public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) 179 | { 180 | 181 | boolean hiddenTop = dy > 0 && getScrollY() < getMaxScrollHeight(); 182 | boolean showTop = dy < 0 && getScrollY() >= 0 && !ViewCompat.canScrollVertically(target, -1); 183 | 184 | if (hiddenTop || showTop) 185 | { 186 | scrollBy(0, dy); 187 | consumed[1] = dy; 188 | } 189 | Log.e(TAG, "onNestedPreScroll" + " isConsumed "+(hiddenTop || showTop)); 190 | } 191 | 192 | @Override 193 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) 194 | { 195 | Log.e(TAG, "onNestedFling"); 196 | return false; 197 | } 198 | 199 | @Override 200 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) 201 | { 202 | Log.e(TAG, "onNestedPreFling"+"#getScrollY "+ getScrollY()+"#MaxScrollHeight "+getMaxScrollHeight()); 203 | //down - //up+ 204 | if (getScrollY() >= getMaxScrollHeight()) return false; 205 | fling((int) velocityY); 206 | return true; 207 | } 208 | 209 | @Override 210 | public int getNestedScrollAxes() 211 | { 212 | Log.e(TAG, "getNestedScrollAxes"); 213 | return 0; 214 | } 215 | 216 | private int getMaxScrollHeight(){ 217 | return mTopViewHeight-actionLayoutHeight; 218 | } 219 | 220 | public int getActionLayoutHeight() { 221 | return actionLayoutHeight; 222 | } 223 | 224 | public void setActionLayoutHeight(int actionLayoutHeight) { 225 | this.actionLayoutHeight = actionLayoutHeight; 226 | } 227 | 228 | public OnScrollChangeListener getOnScrollChangeListener() { 229 | return onScrollChangeListener; 230 | } 231 | 232 | public void setOnScrollChangeListener(OnScrollChangeListener onScrollChangeListener) { 233 | this.onScrollChangeListener = onScrollChangeListener; 234 | } 235 | 236 | public interface OnScrollChangeListener { 237 | 238 | void onScrollChange(View v, int scrollX, int scrollY, int maxScrollY); 239 | } 240 | 241 | 242 | 243 | } 244 | -------------------------------------------------------------------------------- /app/src/main/res/anim/rotate_reset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/anim/rotate_roll.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/back_ico.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/back_ico.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/bg_player_track_blur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/bg_player_track_blur.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_downswipe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/ic_downswipe.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_more_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/ic_more_black.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_more_titlebar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/ic_more_titlebar.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_player_downswipe_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/ic_player_downswipe_black.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_stars_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/ic_stars_black.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ico_refresh_arrow_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/ico_refresh_arrow_down.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ico_refresh_arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/ico_refresh_arrow_up.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_default_1_to_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/icon_default_1_to_1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/white_ico.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/drawable-xhdpi/white_ico.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/gradient_white_to_black.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/xml_player_back.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/xml_player_back_black.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/xml_player_more.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/xml_player_more_black.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_album_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_classify_articles.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 20 | 21 | 28 | 37 | 40 | 41 | 42 | 43 | 44 | 51 | 54 | 65 | 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 24 | 25 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_album.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 11 | 19 | 25 | 26 | 34 | 41 | 49 | 53 | 63 | 64 | 70 | 82 | 83 | 84 | 85 | 101 | 102 | 106 | 107 | 108 | 109 | 115 | 118 | 119 | 126 | 130 | 133 | 134 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_album_detail_info.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_album_tracks.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/header_album_detail_info.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 13 | 21 | 22 | 30 | 37 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_classify_articles_head.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_demo.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 27 | 28 | 38 | 39 | 40 | 46 | 47 | 53 | 54 | 60 | 61 | 66 | 67 | 68 | 69 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_load_foot_discovery.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 22 | 31 | 32 | 37 | 43 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_load_header_discovery.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 9 | 14 | 21 | 29 | 38 | 39 | 44 | 50 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_title_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ffffffff 4 | #FFF2F2F2 5 | #B3BDC4 6 | 7 | #00ffffff 8 | #00000000 9 | #33000000 10 | #66000000 11 | #80000000 12 | #99000000 13 | #B2000000 14 | #CC000000 15 | #80ffffff 16 | #80ffffff 17 | #33ffffff 18 | #33ffffff 19 | 20 | #ffffffff 21 | #EDEDED 22 | #FF6347 23 | #D3D3D3 24 | #5F9EA0 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 165dp 6 | 51dp 7 | 60dp 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/fraction.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 85% 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | NestedScrollDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/test/java/kyle/nestedscrolldemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package kyle.nestedscrolldemo; 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 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:2.2.2' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | maven { url "https://jitpack.io" } 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjm1fb/NestedScrollDemo/a9b527b544b272663ad3ec728c96de62b41e325e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------