├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── sunger │ │ └── net │ │ └── org │ │ └── coordinatorlayoutdemos │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── sunger │ │ │ └── net │ │ │ └── org │ │ │ └── coordinatorlayoutdemos │ │ │ ├── activity │ │ │ ├── BaseCompatActivity.java │ │ │ ├── HeaderViewPagerActivty.java │ │ │ ├── HideToolBarActivity.java │ │ │ ├── JianShuActivity.java │ │ │ └── MainActivity.java │ │ │ ├── adapter │ │ │ ├── LoadAdatper.java │ │ │ ├── MainTabAdapter.java │ │ │ ├── MyAdapter.java │ │ │ └── RecyclerAdapter.java │ │ │ ├── behavior │ │ │ ├── QuickHideBehavior.java │ │ │ └── ScrollingFabBehavior.java │ │ │ ├── fragment │ │ │ ├── NestedscrollFragment.java │ │ │ ├── RecyclerFragment.java │ │ │ ├── RecyclerGridFragment.java │ │ │ ├── RecyclerLinearFragment.java │ │ │ └── RecyclerStaggeredFragment.java │ │ │ ├── refresh │ │ │ ├── BaseLoadMoreRecyclerAdapter.java │ │ │ └── OnRecycleViewScrollListener.java │ │ │ ├── utils │ │ │ ├── SystemBarTintManager.java │ │ │ └── Utils.java │ │ │ └── widget │ │ │ └── ProgressWheel.java │ └── res │ │ ├── drawable-nodpi │ │ └── iconfont_downgrey.png │ │ ├── drawable-v21 │ │ ├── ic_menu_camera.xml │ │ ├── ic_menu_gallery.xml │ │ ├── ic_menu_manage.xml │ │ ├── ic_menu_send.xml │ │ ├── ic_menu_share.xml │ │ └── ic_menu_slideshow.xml │ │ ├── drawable │ │ └── side_nav_bar.xml │ │ ├── layout │ │ ├── activity_header_viewpager.xml │ │ ├── activity_main.xml │ │ ├── activity_recycler_hidden_toolbar.xml │ │ ├── activity_scroller_hidden_toolbar.xml │ │ ├── app_bar_main.xml │ │ ├── fragment_nestedscroll.xml │ │ ├── fragment_recyclerview.xml │ │ ├── fragment_recyclerview2.xml │ │ ├── item.xml │ │ ├── item_view_load_more.xml │ │ ├── nav_header_main.xml │ │ ├── recyclerview_header.xml │ │ ├── view_footer_action.xml │ │ ├── view_header.xml │ │ └── view_pager_header.xml │ │ ├── menu │ │ ├── activity_main_drawer.xml │ │ └── main.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-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── drawables.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── sunger │ └── net │ └── org │ └── coordinatorlayoutdemos │ └── ExampleUnitTest.java ├── art ├── 1.gif ├── 2.gif ├── 3.gif ├── 4.gif └── 5.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | CoordinatorLayoutDemos -------------------------------------------------------------------------------- /.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/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.7 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoordinatorLayoutDemos 2 | 3 | Some view effects base on CoordinatorLayout 4 | 5 | 1.Used CollapsingToolbarLayout to achieve HeaderViewPager 6 | 7 | ![1](https://github.com/sungerk/CoordinatorLayoutDemos/blob/master/art/4.gif) 8 | 9 | ![2](https://github.com/sungerk/CoordinatorLayoutDemos/blob/master/art/5.gif) 10 | 11 | 2.TabLayoutViewPager hide or show Toolbar follow your's gesture.
12 | 13 | pulltorefresh and loadmore depend on [XRecyclerView](https://github.com/jianghejie/XRecyclerView)
14 | 15 | custom Coordinatorlayout.Behavior to achieve hide or show FloatingActionButton 16 | 17 | 18 | ![3](https://github.com/sungerk/CoordinatorLayoutDemos/blob/master/art/1.gif) 19 | 20 | 3.used custom Coordinatorlayout.Behavior achieve hide or show Toolbar android FootView quickly which liked JianShu 21 | ![4](https://github.com/sungerk/CoordinatorLayoutDemos/blob/master/art/2.gif) 22 | 23 | ![5](https://github.com/sungerk/CoordinatorLayoutDemos/blob/master/art/3.gif) 24 | 25 | License 26 | ------- 27 | 28 | Copyright 2015 sunger 29 | 30 | Licensed under the Apache License, Version 2.0 (the "License"); 31 | you may not use this file except in compliance with the License. 32 | You may obtain a copy of the License at 33 | 34 | http://www.apache.org/licenses/LICENSE-2.0 35 | 36 | Unless required by applicable law or agreed to in writing, software 37 | distributed under the License is distributed on an "AS IS" BASIS, 38 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | See the License for the specific language governing permissions and 40 | limitations under the License. 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "sunger.net.org.coordinatorlayoutdemos" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 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 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'com.android.support:design:23.1.1' 27 | compile 'com.jcodecraeer:xrecyclerview:1.2.6' 28 | 29 | } 30 | -------------------------------------------------------------------------------- /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 C:\Dev\Android\androidSdk/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/sunger/net/org/coordinatorlayoutdemos/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/activity/BaseCompatActivity.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.activity; 2 | 3 | import android.os.Build; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.Toolbar; 7 | import android.util.TypedValue; 8 | import android.view.View; 9 | import android.view.Window; 10 | import android.view.WindowManager; 11 | 12 | import sunger.net.org.coordinatorlayoutdemos.R; 13 | import sunger.net.org.coordinatorlayoutdemos.utils.SystemBarTintManager; 14 | 15 | 16 | /** 17 | * Created by sunger on 2015/10/27. 18 | */ 19 | public class BaseCompatActivity extends AppCompatActivity { 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setStateBarColor(R.color.colorPrimary); 25 | } 26 | 27 | protected void setStateBarColor(int resId) { 28 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 29 | Window win = getWindow(); 30 | WindowManager.LayoutParams winParams = win.getAttributes(); 31 | final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 32 | winParams.flags |= bits; 33 | win.setAttributes(winParams); 34 | SystemBarTintManager tintManager = new SystemBarTintManager(this); 35 | tintManager.setStatusBarTintEnabled(true); 36 | tintManager.setStatusBarTintResource(resId); 37 | tintManager.setStatusBarDarkMode(true, this); 38 | } 39 | } 40 | 41 | 42 | protected void setUpCommonBackTooblBar(int toolbarId, String title) { 43 | Toolbar mToolbar = (Toolbar) findViewById(toolbarId); 44 | mToolbar.setTitle(title); 45 | setSupportActionBar(mToolbar); 46 | toobarAsBackButton(mToolbar); 47 | } 48 | 49 | protected void setUpCommonBackTooblBar(int toolbarId, int titleId) { 50 | setUpCommonBackTooblBar(toolbarId, getString(titleId)); 51 | } 52 | 53 | public int getActionBarSize() { 54 | TypedValue tv = new TypedValue(); 55 | if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { 56 | return TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); 57 | } 58 | return 0; 59 | } 60 | 61 | 62 | public View getRootView() { 63 | return findViewById(android.R.id.content); 64 | } 65 | 66 | 67 | /** 68 | * toolbar点击返回,模拟系统返回 69 | * 设置toolbar 为箭头按钮 70 | * app:navigationIcon="?attr/homeAsUpIndicator" 71 | * 72 | * @param toolbar 73 | */ 74 | public void toobarAsBackButton(Toolbar toolbar) { 75 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 76 | getSupportActionBar().setDisplayShowHomeEnabled(true); 77 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 78 | @Override 79 | public void onClick(View v) { 80 | onBackPressed(); 81 | } 82 | }); 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/activity/HeaderViewPagerActivty.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.AppBarLayout; 5 | import android.support.design.widget.CollapsingToolbarLayout; 6 | import android.support.design.widget.TabLayout; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v4.view.ViewPager; 9 | import android.support.v4.widget.SwipeRefreshLayout; 10 | import android.support.v7.widget.Toolbar; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import sunger.net.org.coordinatorlayoutdemos.R; 16 | import sunger.net.org.coordinatorlayoutdemos.adapter.MainTabAdapter; 17 | import sunger.net.org.coordinatorlayoutdemos.fragment.NestedscrollFragment; 18 | import sunger.net.org.coordinatorlayoutdemos.fragment.RecyclerFragment; 19 | import sunger.net.org.coordinatorlayoutdemos.utils.Utils; 20 | 21 | /** 22 | * Created by sunger on 15/12/15. 23 | */ 24 | public class HeaderViewPagerActivty extends BaseCompatActivity implements SwipeRefreshLayout.OnRefreshListener, AppBarLayout.OnOffsetChangedListener { 25 | private ViewPager mViewPager; 26 | private TabLayout mTabLayout; 27 | private MainTabAdapter mAdapter; 28 | private SwipeRefreshLayout mSwipeRefreshLayout; 29 | private AppBarLayout appBarLayout; 30 | private RecyclerFragment fragment; 31 | private Toolbar toolbar; 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_header_viewpager); 37 | 38 | CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById( 39 | R.id.collapse_toolbar); 40 | collapsingToolbar.setTitleEnabled(false); 41 | appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout); 42 | appBarLayout.addOnOffsetChangedListener(this); 43 | 44 | mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); 45 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 100); 46 | mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary); 47 | mSwipeRefreshLayout.setOnRefreshListener(this); 48 | 49 | toolbar = (Toolbar) findViewById(R.id.toolbar); 50 | 51 | //set the toolbar 52 | int toolbar_hight = Utils.getToolbarHeight(this) * 2; 53 | CollapsingToolbarLayout.LayoutParams params = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams(); 54 | params.height = toolbar_hight; 55 | toolbar.setLayoutParams(params); 56 | 57 | setUpCommonBackTooblBar(R.id.toolbar, "HeaderViewPager"); 58 | mViewPager = (ViewPager) findViewById(R.id.view_pager); 59 | mTabLayout = (TabLayout) findViewById(R.id.tab_layout); 60 | 61 | List fragments = new ArrayList<>(); 62 | fragment = new RecyclerFragment(); 63 | fragments.add(fragment); 64 | fragments.add(new NestedscrollFragment()); 65 | fragments.add(new NestedscrollFragment()); 66 | 67 | List titles = new ArrayList<>(); 68 | titles.add("Item1"); 69 | titles.add("Item2"); 70 | titles.add("Item3"); 71 | 72 | mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(0))); 73 | mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(1))); 74 | mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(2))); 75 | 76 | 77 | mAdapter = new MainTabAdapter(getSupportFragmentManager(), fragments, titles); 78 | mViewPager.setAdapter(mAdapter); 79 | mTabLayout.setupWithViewPager(mViewPager); 80 | mTabLayout.setTabsFromPagerAdapter(mAdapter); 81 | } 82 | 83 | 84 | @Override 85 | public void onOffsetChanged(AppBarLayout appBarLayout, int i) { 86 | mSwipeRefreshLayout.setEnabled(i == 0); 87 | float alpha = (float) Math.abs(i) / (float) appBarLayout.getTotalScrollRange() * 1.0f; 88 | toolbar.setAlpha(alpha); 89 | } 90 | 91 | 92 | @Override 93 | public void onRefresh() { 94 | if(mViewPager.getCurrentItem()==0) { 95 | fragment.refresh(); 96 | } 97 | mSwipeRefreshLayout.postDelayed(new Runnable() { 98 | @Override 99 | public void run() { 100 | mSwipeRefreshLayout.setRefreshing(false); 101 | } 102 | }, 2000); 103 | 104 | } 105 | 106 | @Override 107 | protected void onResume() { 108 | super.onResume(); 109 | appBarLayout.addOnOffsetChangedListener(this); 110 | } 111 | 112 | @Override 113 | protected void onPause() { 114 | super.onPause(); 115 | appBarLayout.removeOnOffsetChangedListener(this); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/activity/HideToolBarActivity.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.support.v7.widget.Toolbar; 7 | 8 | import java.util.ArrayList; 9 | 10 | import sunger.net.org.coordinatorlayoutdemos.R; 11 | import sunger.net.org.coordinatorlayoutdemos.adapter.RecyclerAdapter; 12 | 13 | /** 14 | * Created by Administrator on 2015/12/17. 15 | */ 16 | public class HideToolBarActivity extends BaseCompatActivity { 17 | private ArrayList stringArrayList; 18 | private RecyclerView recyclerView; 19 | private RecyclerAdapter adapter; 20 | 21 | @SuppressWarnings("ConstantConditions") 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_recycler_hidden_toolbar); 26 | 27 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 28 | setSupportActionBar(toolbar); 29 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 30 | 31 | recyclerView = (RecyclerView) findViewById(R.id.list); 32 | recyclerView.setHasFixedSize(true); 33 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 34 | recyclerView.setLayoutManager(layoutManager); 35 | 36 | setData(); //adding data to array list 37 | adapter = new RecyclerAdapter(this, stringArrayList); 38 | recyclerView.setAdapter(adapter); 39 | 40 | } 41 | 42 | private void setData() { 43 | stringArrayList = new ArrayList<>(); 44 | 45 | for (int i = 0; i < 100; i++) { 46 | stringArrayList.add("Item " + (i + 1)); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/activity/JianShuActivity.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.activity; 2 | 3 | import android.os.Bundle; 4 | 5 | import sunger.net.org.coordinatorlayoutdemos.R; 6 | 7 | 8 | public class JianShuActivity extends BaseCompatActivity { 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.activity_scroller_hidden_toolbar); 13 | setUpCommonBackTooblBar(R.id.toolbar, "简书效果"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.design.widget.NavigationView; 6 | import android.support.design.widget.TabLayout; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v4.view.GravityCompat; 9 | import android.support.v4.view.ViewPager; 10 | import android.support.v4.widget.DrawerLayout; 11 | import android.support.v7.app.ActionBarDrawerToggle; 12 | import android.support.v7.widget.Toolbar; 13 | import android.view.Menu; 14 | import android.view.MenuItem; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | import sunger.net.org.coordinatorlayoutdemos.R; 20 | import sunger.net.org.coordinatorlayoutdemos.adapter.MainTabAdapter; 21 | import sunger.net.org.coordinatorlayoutdemos.fragment.NestedscrollFragment; 22 | import sunger.net.org.coordinatorlayoutdemos.fragment.RecyclerGridFragment; 23 | import sunger.net.org.coordinatorlayoutdemos.fragment.RecyclerLinearFragment; 24 | import sunger.net.org.coordinatorlayoutdemos.fragment.RecyclerStaggeredFragment; 25 | 26 | public class MainActivity extends BaseCompatActivity 27 | implements NavigationView.OnNavigationItemSelectedListener { 28 | private ViewPager mViewPager; 29 | private TabLayout mTabLayout; 30 | private MainTabAdapter mAdapter; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar); 37 | setSupportActionBar(toolbar); 38 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 39 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 40 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 41 | drawer.setDrawerListener(toggle); 42 | toggle.syncState(); 43 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 44 | navigationView.setNavigationItemSelectedListener(this); 45 | mViewPager = (ViewPager) findViewById(R.id.view_pager); 46 | mTabLayout = (TabLayout) findViewById(R.id.tab_layout); 47 | 48 | List fragments = new ArrayList<>(); 49 | fragments.add(new RecyclerLinearFragment()); 50 | fragments.add(new RecyclerGridFragment()); 51 | fragments.add(new RecyclerStaggeredFragment()); 52 | fragments.add(new NestedscrollFragment()); 53 | 54 | List titles = new ArrayList<>(); 55 | titles.add("RecyclerLinear"); 56 | titles.add("RecyclerGrid"); 57 | titles.add("RecyclerStaggered"); 58 | titles.add("Nestedscroll"); 59 | 60 | mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(0))); 61 | mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(1))); 62 | mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(2))); 63 | mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(3))); 64 | 65 | 66 | mAdapter = new MainTabAdapter(getSupportFragmentManager(), fragments, titles); 67 | mViewPager.setAdapter(mAdapter); 68 | mTabLayout.setupWithViewPager(mViewPager); 69 | mTabLayout.setTabsFromPagerAdapter(mAdapter); 70 | } 71 | 72 | @Override 73 | public void onBackPressed() { 74 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 75 | if (drawer.isDrawerOpen(GravityCompat.START)) { 76 | drawer.closeDrawer(GravityCompat.START); 77 | } else { 78 | super.onBackPressed(); 79 | } 80 | } 81 | 82 | @Override 83 | public boolean onCreateOptionsMenu(Menu menu) { 84 | // Inflate the menu; this adds items to the action bar if it is present. 85 | getMenuInflater().inflate(R.menu.main, menu); 86 | return true; 87 | } 88 | 89 | @Override 90 | public boolean onOptionsItemSelected(MenuItem item) { 91 | // Handle action bar item clicks here. The action bar will 92 | // automatically handle clicks on the Home/Up button, so long 93 | // as you specify a parent activity in AndroidManifest.xml. 94 | int id = item.getItemId(); 95 | 96 | //noinspection SimplifiableIfStatement 97 | if (id == R.id.action_settings) { 98 | return true; 99 | } 100 | 101 | return super.onOptionsItemSelected(item); 102 | } 103 | 104 | @SuppressWarnings("StatementWithEmptyBody") 105 | @Override 106 | public boolean onNavigationItemSelected(MenuItem item) { 107 | // Handle navigation view item clicks here. 108 | int id = item.getItemId(); 109 | 110 | if (id == R.id.nav_camera) { 111 | // Handle the camera action 112 | } else if (id == R.id.nav_scroller_hidden_toolbar) { 113 | startActivity(new Intent(this, JianShuActivity.class)); 114 | 115 | 116 | } else if (id == R.id.nav_recycler_hidden_toolbar) { 117 | startActivity(new Intent(this, HideToolBarActivity.class)); 118 | } else if (id == R.id.nav_viewpager) { 119 | startActivity(new Intent(this, HeaderViewPagerActivty.class)); 120 | } else if (id == R.id.nav_share) { 121 | 122 | } else if (id == R.id.nav_send) { 123 | 124 | } 125 | 126 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 127 | drawer.closeDrawer(GravityCompat.START); 128 | return true; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/adapter/LoadAdatper.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import sunger.net.org.coordinatorlayoutdemos.R; 10 | import sunger.net.org.coordinatorlayoutdemos.refresh.BaseLoadMoreRecyclerAdapter; 11 | 12 | /** 13 | * Created by sunger on 2015/12/17. 14 | */ 15 | public class LoadAdatper extends BaseLoadMoreRecyclerAdapter { 16 | 17 | public LoadAdatper( ) { 18 | } 19 | 20 | @Override 21 | public ViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) { 22 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false); 23 | return new ViewHolder(view); 24 | } 25 | 26 | @Override 27 | public void onBindItemViewHolder(ViewHolder holder, int position) { 28 | try{ 29 | holder.mTextView.setText(getItem(position)); 30 | }catch (Exception e){ 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | public static class ViewHolder extends RecyclerView.ViewHolder { 36 | public TextView mTextView; 37 | public ViewHolder(View view) { 38 | super(view); 39 | mTextView = (TextView) view.findViewById(R.id.text); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/adapter/MainTabAdapter.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.adapter; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentStatePagerAdapter; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by sunger on 2015/12/15. 11 | */ 12 | public class MainTabAdapter extends FragmentStatePagerAdapter { 13 | private List listFragment; 14 | private List listTitle; 15 | 16 | public MainTabAdapter(FragmentManager fm,List listFragment,List listTitle) { 17 | super(fm); 18 | this.listFragment=listFragment; 19 | this.listTitle=listTitle; 20 | } 21 | 22 | @Override 23 | public Fragment getItem(int position) { 24 | return listFragment.get(position); 25 | } 26 | 27 | @Override 28 | public int getCount() { 29 | return listFragment.size(); 30 | } 31 | 32 | @Override 33 | public CharSequence getPageTitle(int position) { 34 | return listTitle.get(position); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/adapter/MyAdapter.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import java.util.ArrayList; 10 | 11 | import sunger.net.org.coordinatorlayoutdemos.R; 12 | 13 | /** 14 | * Created by jianghejie on 15/11/26. 15 | */ 16 | public class MyAdapter extends RecyclerView.Adapter { 17 | public ArrayList datas = null; 18 | 19 | public MyAdapter(ArrayList datas) { 20 | this.datas = datas; 21 | } 22 | 23 | @Override 24 | public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { 25 | View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false); 26 | ViewHolder vh = new ViewHolder(view); 27 | return vh; 28 | } 29 | 30 | @Override 31 | public void onBindViewHolder(ViewHolder viewHolder, int position) { 32 | viewHolder.mTextView.setText(datas.get(position)); 33 | } 34 | 35 | @Override 36 | public int getItemCount() { 37 | return datas.size(); 38 | } 39 | 40 | public static class ViewHolder extends RecyclerView.ViewHolder { 41 | public TextView mTextView; 42 | 43 | public ViewHolder(View view) { 44 | super(view); 45 | mTextView = (TextView) view.findViewById(R.id.text); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/adapter/RecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.adapter; 2 | 3 | import android.app.Activity; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import java.util.List; 11 | 12 | public class RecyclerAdapter extends RecyclerView.Adapter { 13 | 14 | private List friends; 15 | private Activity activity; 16 | 17 | public RecyclerAdapter(Activity activity, List friends) { 18 | this.friends = friends; 19 | this.activity = activity; 20 | } 21 | 22 | @Override 23 | public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { 24 | 25 | //inflate your layout and pass it to view holder 26 | LayoutInflater inflater = activity.getLayoutInflater(); 27 | View view = inflater.inflate(android.R.layout.simple_list_item_1, viewGroup, false); 28 | ViewHolder viewHolder = new ViewHolder(view); 29 | 30 | return viewHolder; 31 | } 32 | 33 | @Override 34 | public void onBindViewHolder(ViewHolder viewHolder, int position) { 35 | 36 | viewHolder.item.setText(friends.get(position)); 37 | } 38 | 39 | @Override 40 | public int getItemCount() { 41 | return (null != friends ? friends.size() : 0); 42 | } 43 | 44 | /** 45 | * View holder to display each RecylerView item 46 | */ 47 | protected class ViewHolder extends RecyclerView.ViewHolder { 48 | private TextView item; 49 | 50 | public ViewHolder(View view) { 51 | super(view); 52 | item = (TextView) view.findViewById(android.R.id.text1); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/behavior/QuickHideBehavior.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.behavior; 2 | 3 | import android.animation.ObjectAnimator; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.support.design.widget.AppBarLayout; 7 | import android.support.design.widget.CoordinatorLayout; 8 | import android.support.design.widget.FloatingActionButton; 9 | import android.support.v4.view.ViewCompat; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | 14 | import sunger.net.org.coordinatorlayoutdemos.R; 15 | 16 | 17 | /** 18 | * Simple scrolling behavior that monitors nested events in the scrolling 19 | * container to implement a quick hide/show for the attached view. 20 | */ 21 | public class QuickHideBehavior extends CoordinatorLayout.Behavior { 22 | 23 | private static final int DIRECTION_UP = 1; 24 | private static final int DIRECTION_DOWN = -1; 25 | 26 | /* Tracking direction of user motion */ 27 | private int mScrollingDirection; 28 | /* Tracking last threshold crossed */ 29 | private int mScrollTrigger; 30 | 31 | /* Accumulated scroll distance */ 32 | private int mScrollDistance; 33 | /* Distance threshold to trigger animation */ 34 | private int mScrollThreshold; 35 | 36 | 37 | private ObjectAnimator mAnimator; 38 | 39 | //Required to instantiate as a default behavior 40 | public QuickHideBehavior() { 41 | } 42 | 43 | //Required to attach behavior via XML 44 | public QuickHideBehavior(Context context, AttributeSet attrs) { 45 | super(context, attrs); 46 | 47 | TypedArray a = context.getTheme() 48 | .obtainStyledAttributes(new int[] {R.attr.actionBarSize}); 49 | //Use half the standard action bar height 50 | mScrollThreshold = a.getDimensionPixelSize(0, 0) / 2; 51 | a.recycle(); 52 | } 53 | 54 | //Called before a nested scroll event. Return true to declare interest 55 | @Override 56 | public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, 57 | View child, View directTargetChild, View target, 58 | int nestedScrollAxes) { 59 | //We have to declare interest in the scroll to receive further events 60 | return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0; 61 | } 62 | 63 | //Called before the scrolling child consumes the event 64 | // We can steal all/part of the event by filling in the consumed array 65 | @Override 66 | public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, 67 | View child, View target, 68 | int dx, int dy, 69 | int[] consumed) { 70 | //Determine direction changes here 71 | if (dy > 0 && mScrollingDirection != DIRECTION_UP) { 72 | mScrollingDirection = DIRECTION_UP; 73 | mScrollDistance = 0; 74 | } else if (dy < 0 && mScrollingDirection != DIRECTION_DOWN) { 75 | mScrollingDirection = DIRECTION_DOWN; 76 | mScrollDistance = 0; 77 | } 78 | } 79 | 80 | //Called after the scrolling child consumes the event, with amount consumed 81 | @Override 82 | public void onNestedScroll(CoordinatorLayout coordinatorLayout, 83 | View child, View target, 84 | int dxConsumed, int dyConsumed, 85 | int dxUnconsumed, int dyUnconsumed) { 86 | //Consumed distance is the actual distance traveled by the scrolling view 87 | mScrollDistance += dyConsumed; 88 | if (mScrollDistance > mScrollThreshold 89 | && mScrollTrigger != DIRECTION_UP) { 90 | //Hide the target view 91 | mScrollTrigger = DIRECTION_UP; 92 | restartAnimator(child, getTargetHideValue(coordinatorLayout, child)); 93 | } else if (mScrollDistance < -mScrollThreshold 94 | && mScrollTrigger != DIRECTION_DOWN) { 95 | //Return the target view 96 | mScrollTrigger = DIRECTION_DOWN; 97 | restartAnimator(child, 0f); 98 | } 99 | } 100 | 101 | //Called after the scrolling child handles the fling 102 | @Override 103 | public boolean onNestedFling(CoordinatorLayout coordinatorLayout, 104 | View child, View target, 105 | float velocityX, float velocityY, 106 | boolean consumed) { 107 | //We only care when the target view is already handling the fling 108 | if (consumed) { 109 | if (velocityY > 0 && mScrollTrigger != DIRECTION_UP) { 110 | mScrollTrigger = DIRECTION_UP; 111 | restartAnimator(child, getTargetHideValue(coordinatorLayout, child)); 112 | } else if (velocityY < 0 && mScrollTrigger != DIRECTION_DOWN) { 113 | mScrollTrigger = DIRECTION_DOWN; 114 | restartAnimator(child, 0f); 115 | } 116 | } 117 | 118 | return false; 119 | } 120 | 121 | /* Helper Methods */ 122 | 123 | //Helper to trigger hide/show animation 124 | private void restartAnimator(View target, float value) { 125 | if (mAnimator != null) { 126 | mAnimator.cancel(); 127 | mAnimator = null; 128 | } 129 | 130 | mAnimator = ObjectAnimator 131 | .ofFloat(target, View.TRANSLATION_Y, value) 132 | .setDuration(250); 133 | mAnimator.start(); 134 | } 135 | 136 | private float getTargetHideValue(ViewGroup parent, View target) { 137 | if (target instanceof AppBarLayout) { 138 | return -target.getHeight(); 139 | } else if (target instanceof FloatingActionButton) { 140 | return parent.getHeight() - target.getTop(); 141 | }else { 142 | return target.getHeight(); 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/behavior/ScrollingFabBehavior.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.behavior; 2 | 3 | import android.content.Context; 4 | import android.support.design.widget.AppBarLayout; 5 | import android.support.design.widget.CoordinatorLayout; 6 | import android.support.design.widget.FloatingActionButton; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | 10 | import sunger.net.org.coordinatorlayoutdemos.utils.Utils; 11 | 12 | /** 13 | * Created by sunger on 2015/12/15. 14 | */ 15 | public class ScrollingFabBehavior extends CoordinatorLayout.Behavior { 16 | private int toolbarHeight; 17 | 18 | public ScrollingFabBehavior(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | this.toolbarHeight = Utils.getToolbarHeight(context); 21 | } 22 | 23 | @Override 24 | public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton fab, View dependency) { 25 | return dependency instanceof AppBarLayout; 26 | } 27 | 28 | @Override 29 | public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton fab, View dependency) { 30 | if (dependency instanceof AppBarLayout) { 31 | CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); 32 | int fabBottomMargin = lp.bottomMargin; 33 | int distanceToScroll = fab.getHeight() + fabBottomMargin; 34 | float ratio = (float)dependency.getY()/(float)toolbarHeight; 35 | fab.setTranslationY(-distanceToScroll * ratio); 36 | } 37 | return true; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/fragment/NestedscrollFragment.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import java.util.ArrayList; 12 | 13 | import sunger.net.org.coordinatorlayoutdemos.R; 14 | import sunger.net.org.coordinatorlayoutdemos.adapter.RecyclerAdapter; 15 | 16 | /** 17 | * Created by sunger on 2015/12/15. 18 | */ 19 | public class NestedscrollFragment extends Fragment { 20 | 21 | private ArrayList stringArrayList; 22 | private RecyclerView recyclerView; 23 | private RecyclerAdapter adapter; 24 | @Nullable 25 | @Override 26 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 27 | View view = inflater.inflate(R.layout.fragment_nestedscroll, container, false); 28 | return view; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/fragment/RecyclerFragment.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import java.util.ArrayList; 12 | 13 | import sunger.net.org.coordinatorlayoutdemos.R; 14 | import sunger.net.org.coordinatorlayoutdemos.adapter.LoadAdatper; 15 | import sunger.net.org.coordinatorlayoutdemos.refresh.OnRecycleViewScrollListener; 16 | 17 | /** 18 | * Created by sunger on 15/12/16. 19 | */ 20 | public class RecyclerFragment extends Fragment { 21 | private RecyclerView recyclerView; 22 | private LoadAdatper adapter; 23 | 24 | @Override 25 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 26 | return inflater.inflate(R.layout.fragment_recyclerview2, container, false); 27 | } 28 | 29 | @Override 30 | public void onViewCreated(View view, Bundle savedInstanceState) { 31 | super.onViewCreated(view, savedInstanceState); 32 | recyclerView = (RecyclerView) getView().findViewById(R.id.recyclerview); 33 | recyclerView.setHasFixedSize(true); 34 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 35 | recyclerView.setLayoutManager(layoutManager); 36 | adapter = new LoadAdatper(); 37 | recyclerView.setAdapter(adapter); 38 | adapter.setHasMoreData(true); 39 | recyclerView.addOnScrollListener(new OnRecycleViewScrollListener() { 40 | @Override 41 | public void onLoadMore() { 42 | adapter.setHasFooter(true); 43 | recyclerView.scrollToPosition(adapter.getItemCount() - 1); 44 | recyclerView.postDelayed(new Runnable() { 45 | @Override 46 | public void run() { 47 | ArrayList dataList = new ArrayList(); 48 | for (int i = 0; i < 10; i++) { 49 | dataList.add("Item " + (i + 1)); 50 | } 51 | if (adapter.getItemCount() > 30) { 52 | adapter.setHasMoreDataAndFooter(false, true); 53 | } else { 54 | adapter.appendToList(dataList); 55 | adapter.setHasMoreDataAndFooter(true, true); 56 | adapter.notifyDataSetChanged(); 57 | } 58 | } 59 | }, 2000); 60 | } 61 | }); 62 | refresh(); 63 | } 64 | 65 | 66 | public void refresh() { 67 | adapter.showHeader(); 68 | recyclerView.postDelayed(new Runnable() { 69 | @Override 70 | public void run() { 71 | ArrayList dataList = new ArrayList(); 72 | for (int i = 0; i < 10; i++) { 73 | dataList.add("Item " + (i + 1)); 74 | } 75 | adapter.getList().clear(); 76 | adapter.appendToList(dataList); 77 | adapter.hideHeader(); 78 | } 79 | }, 1000); 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/fragment/RecyclerGridFragment.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v7.widget.GridLayoutManager; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.jcodecraeer.xrecyclerview.ProgressStyle; 12 | import com.jcodecraeer.xrecyclerview.XRecyclerView; 13 | 14 | import java.util.ArrayList; 15 | 16 | import sunger.net.org.coordinatorlayoutdemos.R; 17 | import sunger.net.org.coordinatorlayoutdemos.adapter.MyAdapter; 18 | 19 | /** 20 | * Created by sunger on 2015/12/15. 21 | */ 22 | public class RecyclerGridFragment extends Fragment { 23 | private XRecyclerView mRecyclerView; 24 | private MyAdapter mAdapter; 25 | private ArrayList listData; 26 | private int refreshTime = 0; 27 | private int times = 0; 28 | private View header; 29 | 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 32 | header = inflater.inflate(R.layout.recyclerview_header, container, false); 33 | return inflater.inflate(R.layout.fragment_recyclerview, container, false); 34 | } 35 | 36 | @Override 37 | public void onViewCreated(View view, Bundle savedInstanceState) { 38 | super.onViewCreated(view, savedInstanceState); 39 | mRecyclerView = (XRecyclerView) getView().findViewById(R.id.recyclerview); 40 | GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 3); 41 | 42 | mRecyclerView.setLayoutManager(layoutManager); 43 | 44 | mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); 45 | mRecyclerView.setLaodingMoreProgressStyle(ProgressStyle.BallRotate); 46 | mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey); 47 | mRecyclerView.addHeaderView(header); 48 | 49 | mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() { 50 | @Override 51 | public void onRefresh() { 52 | refreshTime++; 53 | times = 0; 54 | new Handler().postDelayed(new Runnable() { 55 | public void run() { 56 | 57 | listData.clear(); 58 | for (int i = 0; i < 20; i++) { 59 | listData.add("item" + i + "after " + refreshTime + " times of refresh"); 60 | } 61 | mAdapter.notifyDataSetChanged(); 62 | mRecyclerView.refreshComplete(); 63 | } 64 | 65 | }, 1000); //refresh data here 66 | } 67 | 68 | @Override 69 | public void onLoadMore() { 70 | if (times < 2) { 71 | new Handler().postDelayed(new Runnable() { 72 | public void run() { 73 | mRecyclerView.loadMoreComplete(); 74 | for (int i = 0; i < 20; i++) { 75 | listData.add("item" + (i + listData.size())); 76 | } 77 | mAdapter.notifyDataSetChanged(); 78 | mRecyclerView.refreshComplete(); 79 | } 80 | }, 1000); 81 | } else { 82 | new Handler().postDelayed(new Runnable() { 83 | public void run() { 84 | 85 | mAdapter.notifyDataSetChanged(); 86 | mRecyclerView.loadMoreComplete(); 87 | } 88 | }, 1000); 89 | } 90 | times++; 91 | } 92 | }); 93 | 94 | listData = new ArrayList(); 95 | for (int i = 0; i < 20; i++) { 96 | listData.add("item" + (i + listData.size())); 97 | } 98 | mAdapter = new MyAdapter(listData); 99 | 100 | mRecyclerView.setAdapter(mAdapter); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/fragment/RecyclerLinearFragment.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.jcodecraeer.xrecyclerview.ProgressStyle; 12 | import com.jcodecraeer.xrecyclerview.XRecyclerView; 13 | 14 | import java.util.ArrayList; 15 | 16 | import sunger.net.org.coordinatorlayoutdemos.R; 17 | import sunger.net.org.coordinatorlayoutdemos.adapter.MyAdapter; 18 | 19 | /** 20 | * Created by sunger on 2015/12/15. 21 | */ 22 | public class RecyclerLinearFragment extends Fragment { 23 | private XRecyclerView mRecyclerView; 24 | private MyAdapter mAdapter; 25 | private ArrayList listData; 26 | private int refreshTime = 0; 27 | private int times = 0; 28 | private View header; 29 | 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 32 | header = inflater.inflate(R.layout.recyclerview_header, container, false); 33 | return inflater.inflate(R.layout.fragment_recyclerview, container, false); 34 | } 35 | 36 | @Override 37 | public void onViewCreated(View view, Bundle savedInstanceState) { 38 | super.onViewCreated(view, savedInstanceState); 39 | mRecyclerView = (XRecyclerView) getView().findViewById(R.id.recyclerview); 40 | LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); 41 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 42 | mRecyclerView.setLayoutManager(layoutManager); 43 | 44 | mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); 45 | mRecyclerView.setLaodingMoreProgressStyle(ProgressStyle.SemiCircleSpin); 46 | mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey); 47 | 48 | mRecyclerView.addHeaderView(header); 49 | 50 | mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() { 51 | @Override 52 | public void onRefresh() { 53 | refreshTime++; 54 | times = 0; 55 | new Handler().postDelayed(new Runnable() { 56 | public void run() { 57 | listData.clear(); 58 | for (int i = 0; i < 15; i++) { 59 | listData.add("item" + i + "after " + refreshTime + " times of refresh"); 60 | } 61 | mAdapter.notifyDataSetChanged(); 62 | mRecyclerView.refreshComplete(); 63 | } 64 | 65 | }, 1000); //refresh data here 66 | } 67 | 68 | @Override 69 | public void onLoadMore() { 70 | if (times < 2) { 71 | new Handler().postDelayed(new Runnable() { 72 | public void run() { 73 | mRecyclerView.loadMoreComplete(); 74 | for (int i = 0; i < 15; i++) { 75 | listData.add("item" + (i + listData.size())); 76 | } 77 | mAdapter.notifyDataSetChanged(); 78 | mRecyclerView.refreshComplete(); 79 | } 80 | }, 1000); 81 | } else { 82 | new Handler().postDelayed(new Runnable() { 83 | public void run() { 84 | 85 | mAdapter.notifyDataSetChanged(); 86 | mRecyclerView.loadMoreComplete(); 87 | } 88 | }, 1000); 89 | } 90 | times++; 91 | } 92 | }); 93 | 94 | listData = new ArrayList(); 95 | for (int i = 0; i < 15; i++) { 96 | listData.add("item" + (i + listData.size())); 97 | } 98 | mAdapter = new MyAdapter(listData); 99 | 100 | mRecyclerView.setAdapter(mAdapter); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/fragment/RecyclerStaggeredFragment.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.StaggeredGridLayoutManager; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import com.jcodecraeer.xrecyclerview.ProgressStyle; 13 | import com.jcodecraeer.xrecyclerview.XRecyclerView; 14 | 15 | import java.util.ArrayList; 16 | 17 | import sunger.net.org.coordinatorlayoutdemos.R; 18 | import sunger.net.org.coordinatorlayoutdemos.adapter.MyAdapter; 19 | 20 | /** 21 | * Created by sunger on 2015/12/15. 22 | */ 23 | public class RecyclerStaggeredFragment extends Fragment { 24 | private XRecyclerView mRecyclerView; 25 | private MyAdapter mAdapter; 26 | private ArrayList listData; 27 | private int refreshTime = 0; 28 | private int times = 0; 29 | private View header; 30 | 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 33 | header = inflater.inflate(R.layout.recyclerview_header, container, false); 34 | return inflater.inflate(R.layout.fragment_recyclerview, container, false); 35 | } 36 | 37 | 38 | @Override 39 | public void onViewCreated(View view, Bundle savedInstanceState) { 40 | super.onViewCreated(view, savedInstanceState); 41 | mRecyclerView = (XRecyclerView) getView().findViewById(R.id.recyclerview); 42 | StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, 43 | StaggeredGridLayoutManager.VERTICAL); 44 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 45 | mRecyclerView.setLayoutManager(layoutManager); 46 | 47 | mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); 48 | mRecyclerView.setLaodingMoreProgressStyle(ProgressStyle.BallRotate); 49 | mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey); 50 | mRecyclerView.addHeaderView(header); 51 | 52 | mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() { 53 | @Override 54 | public void onRefresh() { 55 | refreshTime++; 56 | times = 0; 57 | new Handler().postDelayed(new Runnable() { 58 | public void run() { 59 | 60 | listData.clear(); 61 | for (int i = 0; i < 25; i++) { 62 | listData.add("item" + i + "after " + refreshTime + " times of refresh"); 63 | } 64 | mAdapter.notifyDataSetChanged(); 65 | mRecyclerView.refreshComplete(); 66 | } 67 | 68 | }, 1000); //refresh data here 69 | } 70 | 71 | @Override 72 | public void onLoadMore() { 73 | if (times < 2) { 74 | new Handler().postDelayed(new Runnable() { 75 | public void run() { 76 | mRecyclerView.loadMoreComplete(); 77 | for (int i = 0; i < 25; i++) { 78 | listData.add("item" + (i + listData.size())); 79 | } 80 | mAdapter.notifyDataSetChanged(); 81 | mRecyclerView.refreshComplete(); 82 | } 83 | }, 1000); 84 | } else { 85 | new Handler().postDelayed(new Runnable() { 86 | public void run() { 87 | 88 | mAdapter.notifyDataSetChanged(); 89 | mRecyclerView.loadMoreComplete(); 90 | } 91 | }, 1000); 92 | } 93 | times++; 94 | } 95 | }); 96 | 97 | listData = new ArrayList(); 98 | for (int i = 0; i < 25; i++) { 99 | listData.add("item" + (i + listData.size())); 100 | } 101 | mAdapter = new MyAdapter(listData); 102 | 103 | mRecyclerView.setAdapter(mAdapter); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/refresh/BaseLoadMoreRecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.refresh; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import java.util.LinkedList; 10 | import java.util.List; 11 | 12 | import sunger.net.org.coordinatorlayoutdemos.R; 13 | import sunger.net.org.coordinatorlayoutdemos.widget.ProgressWheel; 14 | 15 | 16 | /** 17 | * Created on 15/8/23. 18 | */ 19 | public abstract class BaseLoadMoreRecyclerAdapter extends RecyclerView.Adapter { 20 | public static final int TYPE_ITEM = 0; 21 | public static final int TYPE_FOOTER = 1; 22 | public static final int TYPE_HEADER = 2; 23 | private boolean hasHeader = false; 24 | private boolean hasFooter; 25 | private boolean hasMoreData; 26 | 27 | private final List mList = new LinkedList(); 28 | 29 | public static class FooterViewHolder extends RecyclerView.ViewHolder { 30 | public final ProgressWheel mProgressView; 31 | public final TextView mTextView; 32 | 33 | public FooterViewHolder(View view) { 34 | super(view); 35 | mProgressView = (ProgressWheel) view.findViewById(R.id.progress_view); 36 | mTextView = (TextView) view.findViewById(R.id.tv_content); 37 | } 38 | } 39 | 40 | 41 | public static class HeaderViewHolder extends RecyclerView.ViewHolder { 42 | public final TextView mTextView; 43 | 44 | public HeaderViewHolder(View view) { 45 | super(view); 46 | mTextView = (TextView) view.findViewById(R.id.tv_content); 47 | } 48 | } 49 | 50 | public abstract VH onCreateItemViewHolder(ViewGroup parent, int viewType); 51 | 52 | @Override 53 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 54 | if (viewType == TYPE_FOOTER) {//底部 加载view 55 | View view = LayoutInflater.from(parent.getContext()) 56 | .inflate(R.layout.item_view_load_more, parent, false); 57 | return new FooterViewHolder(view); 58 | } else if (viewType == TYPE_HEADER) { 59 | View view = LayoutInflater.from(parent.getContext()) 60 | .inflate(R.layout.item_view_load_more, parent, false); 61 | return new HeaderViewHolder(view); 62 | } else { 63 | return onCreateItemViewHolder(parent, viewType); 64 | } 65 | } 66 | 67 | public abstract void onBindItemViewHolder(final VH holder, int position); 68 | 69 | @Override 70 | @SuppressWarnings("unchecked") 71 | public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { 72 | if (holder instanceof FooterViewHolder) { 73 | //没有更多数据 74 | if (hasMoreData) { 75 | ((FooterViewHolder) holder).mProgressView.setVisibility(View.VISIBLE); 76 | ((FooterViewHolder) holder).mTextView.setText("正在加载。。。"); 77 | } else { 78 | ((FooterViewHolder) holder).mProgressView.setVisibility(View.GONE); 79 | ((FooterViewHolder) holder).mTextView.setText("没有更多数据了。。。。"); 80 | } 81 | } else if (holder instanceof HeaderViewHolder) { 82 | ((HeaderViewHolder) holder).mTextView.setText("正在加载。。。"); 83 | } else { 84 | onBindItemViewHolder((VH) holder, position); 85 | } 86 | } 87 | 88 | 89 | @Override 90 | public int getItemViewType(int position) { 91 | 92 | if (position == getBasicItemCount() && hasFooter) { 93 | return TYPE_FOOTER; 94 | } 95 | if (position == 0 && hasHeader) 96 | return TYPE_HEADER; 97 | return TYPE_ITEM; 98 | } 99 | 100 | public List getList() { 101 | return mList; 102 | } 103 | 104 | public void appendToList(List list) { 105 | if (list == null) { 106 | return; 107 | } 108 | mList.addAll(list); 109 | } 110 | 111 | public void append(T t) { 112 | if (t == null) { 113 | return; 114 | } 115 | mList.add(t); 116 | } 117 | 118 | public void appendToTop(T item) { 119 | if (item == null) { 120 | return; 121 | } 122 | mList.add(0, item); 123 | } 124 | 125 | public void appendToTopList(List list) { 126 | if (list == null) { 127 | return; 128 | } 129 | mList.addAll(0, list); 130 | } 131 | 132 | 133 | public void remove(int position) { 134 | if (position < mList.size() - 1 && position >= 0) { 135 | mList.remove(position); 136 | } 137 | } 138 | 139 | public void clear() { 140 | mList.clear(); 141 | } 142 | 143 | private int getBasicItemCount() { 144 | return mList.size(); 145 | } 146 | 147 | @Override 148 | public int getItemCount() { 149 | return getBasicItemCount() + (hasFooter ? 1 : 0) + (hasHeader ? 1 : 0); 150 | } 151 | 152 | public T getItem(int position) { 153 | if (position > mList.size() - 1) { 154 | return null; 155 | } 156 | return mList.get(position); 157 | } 158 | 159 | @Override 160 | public long getItemId(int position) { 161 | return position; 162 | } 163 | 164 | 165 | public void setHasFooter(boolean hasFooter) { 166 | if (this.hasFooter != hasFooter) { 167 | this.hasFooter = hasFooter; 168 | notifyDataSetChanged(); 169 | } 170 | } 171 | 172 | public void showHeader() { 173 | if (!hasHeader) { 174 | this.hasHeader = true; 175 | this.hasFooter = false; 176 | this.hasMoreData=true; 177 | notifyDataSetChanged(); 178 | } 179 | } 180 | 181 | 182 | public void hideHeader() { 183 | if (hasHeader) { 184 | this.hasHeader = false; 185 | this.hasFooter = false; 186 | notifyDataSetChanged(); 187 | } 188 | } 189 | 190 | public void setHasMoreData(boolean isMoreData) { 191 | if (this.hasMoreData != isMoreData) { 192 | this.hasMoreData = isMoreData; 193 | notifyDataSetChanged(); 194 | } 195 | } 196 | 197 | public void setHasMoreDataAndFooter(boolean hasMoreData, boolean hasFooter) { 198 | if (this.hasMoreData != hasMoreData || this.hasFooter != hasFooter) { 199 | this.hasMoreData = hasMoreData; 200 | this.hasFooter = hasFooter; 201 | notifyDataSetChanged(); 202 | } 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/refresh/OnRecycleViewScrollListener.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.refresh; 2 | 3 | /* 4 | * Copyright (C) 2015 Jorge Castillo Pérez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * modify from https://github.com/JorgeCastilloPrz/Mirage 19 | */ 20 | 21 | 22 | import android.support.v7.widget.GridLayoutManager; 23 | import android.support.v7.widget.LinearLayoutManager; 24 | import android.support.v7.widget.RecyclerView; 25 | import android.support.v7.widget.StaggeredGridLayoutManager; 26 | 27 | public abstract class OnRecycleViewScrollListener extends RecyclerView.OnScrollListener { 28 | /** 29 | * 当前RecyclerView类型 30 | */ 31 | protected LayoutManagerType layoutManagerType; 32 | 33 | /** 34 | * 最后一个的位置 35 | */ 36 | private int[] lastPositions; 37 | 38 | /** 39 | * 最后一个可见的item的位置 40 | */ 41 | private int lastVisibleItemPosition; 42 | 43 | /** 44 | * 当前滑动的状态 45 | */ 46 | private int currentScrollState = 0; 47 | 48 | @Override 49 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 50 | super.onScrolled(recyclerView, dx, dy); 51 | 52 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); 53 | 54 | if (layoutManagerType == null) { 55 | if (layoutManager instanceof LinearLayoutManager) { 56 | layoutManagerType = LayoutManagerType.LinearLayout; 57 | } else if (layoutManager instanceof GridLayoutManager) { 58 | layoutManagerType = LayoutManagerType.GridLayout; 59 | } else if (layoutManager instanceof StaggeredGridLayoutManager) { 60 | layoutManagerType = LayoutManagerType.StaggeredGridLayout; 61 | } else { 62 | throw new RuntimeException( 63 | "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager"); 64 | } 65 | } 66 | 67 | switch (layoutManagerType) { 68 | case LinearLayout: 69 | lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition(); 70 | break; 71 | case GridLayout: 72 | lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition(); 73 | break; 74 | case StaggeredGridLayout: 75 | StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager; 76 | if (lastPositions == null) { 77 | lastPositions = new int[staggeredGridLayoutManager.getSpanCount()]; 78 | } 79 | staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions); 80 | lastVisibleItemPosition = findMax(lastPositions); 81 | break; 82 | } 83 | } 84 | 85 | @Override 86 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 87 | super.onScrollStateChanged(recyclerView, newState); 88 | currentScrollState = newState; 89 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); 90 | int visibleItemCount = layoutManager.getChildCount(); 91 | int totalItemCount = layoutManager.getItemCount(); 92 | if ((visibleItemCount > 0 && currentScrollState == RecyclerView.SCROLL_STATE_IDLE && (lastVisibleItemPosition) >= totalItemCount - 1)) { 93 | onLoadMore(); 94 | } 95 | } 96 | 97 | /** 98 | * 取数组中最大值 99 | * 100 | * @param lastPositions 101 | * @return 102 | */ 103 | private int findMax(int[] lastPositions) { 104 | int max = lastPositions[0]; 105 | for (int value : lastPositions) { 106 | if (value > max) { 107 | max = value; 108 | } 109 | } 110 | 111 | return max; 112 | } 113 | 114 | 115 | public static enum LayoutManagerType { 116 | LinearLayout, 117 | StaggeredGridLayout, 118 | GridLayout 119 | } 120 | 121 | public abstract void onLoadMore(); 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/utils/SystemBarTintManager.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.annotation.TargetApi; 5 | import android.app.Activity; 6 | import android.content.Context; 7 | import android.content.res.Configuration; 8 | import android.content.res.Resources; 9 | import android.content.res.TypedArray; 10 | import android.graphics.drawable.Drawable; 11 | import android.os.Build; 12 | import android.util.DisplayMetrics; 13 | import android.util.TypedValue; 14 | import android.view.Gravity; 15 | import android.view.View; 16 | import android.view.ViewConfiguration; 17 | import android.view.ViewGroup; 18 | import android.view.Window; 19 | import android.view.WindowManager; 20 | import android.widget.FrameLayout.LayoutParams; 21 | 22 | import java.lang.reflect.Field; 23 | import java.lang.reflect.Method; 24 | 25 | /** 26 | * Created by Administrator on 2015/11/2. 27 | */ 28 | public class SystemBarTintManager { 29 | /** 30 | * The default system bar tint color value. 31 | */ 32 | public static final int DEFAULT_TINT_COLOR = 0x99000000; 33 | 34 | private final SystemBarConfig mConfig; 35 | private boolean mStatusBarAvailable; 36 | private boolean mNavBarAvailable; 37 | private boolean mStatusBarTintEnabled; 38 | private boolean mNavBarTintEnabled; 39 | private View mStatusBarTintView; 40 | private View mNavBarTintView; 41 | private static boolean sIsMiuiV6; 42 | private static String sNavBarOverride = null; 43 | 44 | static { 45 | Method methodGetter = null; 46 | try { 47 | Class sysClass = Class.forName("android.os.SystemProperties"); 48 | methodGetter = sysClass.getDeclaredMethod("get", String.class); 49 | sIsMiuiV6 = "V6".equals((String) methodGetter.invoke(sysClass, "ro.miui.ui.version.name")); 50 | } catch (Exception e) { 51 | e.printStackTrace(); 52 | } finally { 53 | if (methodGetter != null) { 54 | try { 55 | sNavBarOverride = (String) methodGetter.invoke(null, "qemu.hw.mainkeys"); 56 | } catch (Exception e) { 57 | e.printStackTrace(); 58 | sNavBarOverride = null; 59 | } 60 | } 61 | } 62 | } 63 | 64 | /** 65 | * @param activity The host activity. 66 | */ 67 | @TargetApi(19) 68 | public SystemBarTintManager(Activity activity) { 69 | 70 | 71 | Window win = activity.getWindow(); 72 | ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); 73 | 74 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 75 | // check theme attrs 76 | int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; 77 | TypedArray a = activity.obtainStyledAttributes(attrs); 78 | try { 79 | mStatusBarAvailable = a.getBoolean(0, false); 80 | mNavBarAvailable = a.getBoolean(1, false); 81 | } finally { 82 | a.recycle(); 83 | } 84 | 85 | // check window flags 86 | WindowManager.LayoutParams winParams = win.getAttributes(); 87 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 88 | if ((winParams.flags & bits) != 0) { 89 | mStatusBarAvailable = true; 90 | } 91 | bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; 92 | if ((winParams.flags & bits) != 0) { 93 | mNavBarAvailable = true; 94 | } 95 | } 96 | 97 | mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); 98 | // device might not have virtual navigation keys 99 | if (!mConfig.hasNavigtionBar()) { 100 | mNavBarAvailable = false; 101 | } 102 | 103 | if (mStatusBarAvailable) { 104 | setupStatusBarView(activity, decorViewGroup); 105 | } 106 | if (mNavBarAvailable) { 107 | setupNavBarView(activity, decorViewGroup); 108 | } 109 | 110 | } 111 | 112 | /** 113 | * Enable tinting of the system status bar. 114 | * 115 | * @param enabled True to enable tinting, false to disable it (default). 116 | */ 117 | public void setStatusBarTintEnabled(boolean enabled) { 118 | mStatusBarTintEnabled = enabled; 119 | if (mStatusBarAvailable) { 120 | mStatusBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE); 121 | } 122 | } 123 | 124 | /** 125 | * set status bar darkmode 126 | * 127 | * @param darkmode 128 | * @param activity 129 | */ 130 | public void setStatusBarDarkMode(boolean darkmode, Activity activity) { 131 | if (sIsMiuiV6) { 132 | Class clazz = activity.getWindow().getClass(); 133 | try { 134 | int darkModeFlag = 0; 135 | Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); 136 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); 137 | darkModeFlag = field.getInt(layoutParams); 138 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); 139 | extraFlagField.invoke(activity.getWindow(), darkmode ? darkModeFlag : 0, darkModeFlag); 140 | } catch (Exception e) { 141 | e.printStackTrace(); 142 | } 143 | } 144 | } 145 | 146 | /** 147 | * Enable tinting of the system navigation bar. 148 | * 149 | * @param enabled True to enable tinting, false to disable it (default). 150 | */ 151 | public void setNavigationBarTintEnabled(boolean enabled) { 152 | mNavBarTintEnabled = enabled; 153 | if (mNavBarAvailable) { 154 | mNavBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE); 155 | } 156 | } 157 | 158 | /** 159 | * Apply the specified color tint to all system UI bars. 160 | * 161 | * @param color The color of the background tint. 162 | */ 163 | public void setTintColor(int color) { 164 | setStatusBarTintColor(color); 165 | setNavigationBarTintColor(color); 166 | } 167 | 168 | /** 169 | * Apply the specified drawable or color resource to all system UI bars. 170 | * 171 | * @param res The identifier of the resource. 172 | */ 173 | public void setTintResource(int res) { 174 | setStatusBarTintResource(res); 175 | setNavigationBarTintResource(res); 176 | } 177 | 178 | /** 179 | * Apply the specified drawable to all system UI bars. 180 | * 181 | * @param drawable The drawable to use as the background, or null to remove it. 182 | */ 183 | public void setTintDrawable(Drawable drawable) { 184 | setStatusBarTintDrawable(drawable); 185 | setNavigationBarTintDrawable(drawable); 186 | } 187 | 188 | /** 189 | * Apply the specified alpha to all system UI bars. 190 | * 191 | * @param alpha The alpha to use 192 | */ 193 | public void setTintAlpha(float alpha) { 194 | setStatusBarAlpha(alpha); 195 | setNavigationBarAlpha(alpha); 196 | } 197 | 198 | /** 199 | * Apply the specified color tint to the system status bar. 200 | * 201 | * @param color The color of the background tint. 202 | */ 203 | public void setStatusBarTintColor(int color) { 204 | if (mStatusBarAvailable) { 205 | mStatusBarTintView.setBackgroundColor(color); 206 | } 207 | } 208 | 209 | /** 210 | * Apply the specified drawable or color resource to the system status bar. 211 | * 212 | * @param res The identifier of the resource. 213 | */ 214 | public void setStatusBarTintResource(int res) { 215 | if (mStatusBarAvailable) { 216 | mStatusBarTintView.setBackgroundResource(res); 217 | } 218 | } 219 | 220 | /** 221 | * Apply the specified drawable to the system status bar. 222 | * 223 | * @param drawable The drawable to use as the background, or null to remove it. 224 | */ 225 | @SuppressWarnings("deprecation") 226 | public void setStatusBarTintDrawable(Drawable drawable) { 227 | if (mStatusBarAvailable) { 228 | mStatusBarTintView.setBackgroundDrawable(drawable); 229 | } 230 | } 231 | 232 | /** 233 | * Apply the specified alpha to the system status bar. 234 | * 235 | * @param alpha The alpha to use 236 | */ 237 | @TargetApi(11) 238 | public void setStatusBarAlpha(float alpha) { 239 | if (mStatusBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 240 | mStatusBarTintView.setAlpha(alpha); 241 | } 242 | } 243 | 244 | /** 245 | * Apply the specified color tint to the system navigation bar. 246 | * 247 | * @param color The color of the background tint. 248 | */ 249 | public void setNavigationBarTintColor(int color) { 250 | if (mNavBarAvailable) { 251 | mNavBarTintView.setBackgroundColor(color); 252 | } 253 | } 254 | 255 | /** 256 | * Apply the specified drawable or color resource to the system navigation bar. 257 | * 258 | * @param res The identifier of the resource. 259 | */ 260 | public void setNavigationBarTintResource(int res) { 261 | if (mNavBarAvailable) { 262 | mNavBarTintView.setBackgroundResource(res); 263 | } 264 | } 265 | 266 | /** 267 | * Apply the specified drawable to the system navigation bar. 268 | * 269 | * @param drawable The drawable to use as the background, or null to remove it. 270 | */ 271 | @SuppressWarnings("deprecation") 272 | public void setNavigationBarTintDrawable(Drawable drawable) { 273 | if (mNavBarAvailable) { 274 | mNavBarTintView.setBackgroundDrawable(drawable); 275 | } 276 | } 277 | 278 | /** 279 | * Apply the specified alpha to the system navigation bar. 280 | * 281 | * @param alpha The alpha to use 282 | */ 283 | @TargetApi(11) 284 | public void setNavigationBarAlpha(float alpha) { 285 | if (mNavBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 286 | mNavBarTintView.setAlpha(alpha); 287 | } 288 | } 289 | 290 | /** 291 | * Get the system bar configuration. 292 | * 293 | * @return The system bar configuration for the current device configuration. 294 | */ 295 | public SystemBarConfig getConfig() { 296 | return mConfig; 297 | } 298 | 299 | /** 300 | * Is tinting enabled for the system status bar? 301 | * 302 | * @return True if enabled, False otherwise. 303 | */ 304 | public boolean isStatusBarTintEnabled() { 305 | return mStatusBarTintEnabled; 306 | } 307 | 308 | /** 309 | * Is tinting enabled for the system navigation bar? 310 | * 311 | * @return True if enabled, False otherwise. 312 | */ 313 | public boolean isNavBarTintEnabled() { 314 | return mNavBarTintEnabled; 315 | } 316 | 317 | private void setupStatusBarView(Context context, ViewGroup decorViewGroup) { 318 | mStatusBarTintView = new View(context); 319 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight()); 320 | params.gravity = Gravity.TOP; 321 | if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) { 322 | params.rightMargin = mConfig.getNavigationBarWidth(); 323 | } 324 | mStatusBarTintView.setLayoutParams(params); 325 | mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR); 326 | mStatusBarTintView.setVisibility(View.GONE); 327 | decorViewGroup.addView(mStatusBarTintView); 328 | } 329 | 330 | private void setupNavBarView(Context context, ViewGroup decorViewGroup) { 331 | mNavBarTintView = new View(context); 332 | LayoutParams params; 333 | if (mConfig.isNavigationAtBottom()) { 334 | params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight()); 335 | params.gravity = Gravity.BOTTOM; 336 | } else { 337 | params = new LayoutParams(mConfig.getNavigationBarWidth(), LayoutParams.MATCH_PARENT); 338 | params.gravity = Gravity.RIGHT; 339 | } 340 | mNavBarTintView.setLayoutParams(params); 341 | mNavBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR); 342 | mNavBarTintView.setVisibility(View.GONE); 343 | decorViewGroup.addView(mNavBarTintView); 344 | } 345 | 346 | public static class SystemBarConfig { 347 | 348 | private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height"; 349 | private static final String NAV_BAR_HEIGHT_RES_NAME = "navigation_bar_height"; 350 | private static final String NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME = "navigation_bar_height_landscape"; 351 | private static final String NAV_BAR_WIDTH_RES_NAME = "navigation_bar_width"; 352 | private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar"; 353 | 354 | private final boolean mTranslucentStatusBar; 355 | private final boolean mTranslucentNavBar; 356 | private final int mStatusBarHeight; 357 | private final int mActionBarHeight; 358 | private final boolean mHasNavigationBar; 359 | private final int mNavigationBarHeight; 360 | private final int mNavigationBarWidth; 361 | private final boolean mInPortrait; 362 | private final float mSmallestWidthDp; 363 | 364 | private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) { 365 | Resources res = activity.getResources(); 366 | mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); 367 | mSmallestWidthDp = getSmallestWidthDp(activity); 368 | mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME); 369 | mActionBarHeight = getActionBarHeight(activity); 370 | mNavigationBarHeight = getNavigationBarHeight(activity); 371 | mNavigationBarWidth = getNavigationBarWidth(activity); 372 | mHasNavigationBar = (mNavigationBarHeight > 0); 373 | mTranslucentStatusBar = translucentStatusBar; 374 | mTranslucentNavBar = traslucentNavBar; 375 | } 376 | 377 | @TargetApi(14) 378 | private int getActionBarHeight(Context context) { 379 | int result = 0; 380 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 381 | TypedValue tv = new TypedValue(); 382 | context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true); 383 | result = context.getResources().getDimensionPixelSize(tv.resourceId); 384 | } 385 | return result; 386 | } 387 | 388 | @TargetApi(14) 389 | private int getNavigationBarHeight(Context context) { 390 | Resources res = context.getResources(); 391 | int result = 0; 392 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 393 | if (!hasNavBar(context)) { 394 | String key; 395 | if (mInPortrait) { 396 | key = NAV_BAR_HEIGHT_RES_NAME; 397 | } else { 398 | key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME; 399 | } 400 | return getInternalDimensionSize(res, key); 401 | } 402 | } 403 | return result; 404 | } 405 | 406 | @TargetApi(14) 407 | private int getNavigationBarWidth(Context context) { 408 | Resources res = context.getResources(); 409 | int result = 0; 410 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 411 | if (!hasNavBar(context)) { 412 | return getInternalDimensionSize(res, NAV_BAR_WIDTH_RES_NAME); 413 | } 414 | } 415 | return result; 416 | } 417 | 418 | private int getInternalDimensionSize(Resources res, String key) { 419 | int result = 0; 420 | int resourceId = res.getIdentifier(key, "dimen", "android"); 421 | if (resourceId > 0) { 422 | result = res.getDimensionPixelSize(resourceId); 423 | } 424 | return result; 425 | } 426 | 427 | @SuppressLint("NewApi") 428 | private float getSmallestWidthDp(Activity activity) { 429 | DisplayMetrics metrics = new DisplayMetrics(); 430 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 431 | activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); 432 | } else { 433 | // TODO this is not correct, but we don't really care pre-kitkat 434 | activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); 435 | } 436 | float widthDp = metrics.widthPixels / metrics.density; 437 | float heightDp = metrics.heightPixels / metrics.density; 438 | return Math.min(widthDp, heightDp); 439 | } 440 | 441 | /** 442 | * Should a navigation bar appear at the bottom of the screen in the current 443 | * device configuration? A navigation bar may appear on the right side of 444 | * the screen in certain configurations. 445 | * 446 | * @return True if navigation should appear at the bottom of the screen, False otherwise. 447 | */ 448 | public boolean isNavigationAtBottom() { 449 | return (mSmallestWidthDp >= 600 || mInPortrait); 450 | } 451 | 452 | /** 453 | * Get the height of the system status bar. 454 | * 455 | * @return The height of the status bar (in pixels). 456 | */ 457 | public int getStatusBarHeight() { 458 | return mStatusBarHeight; 459 | } 460 | 461 | /** 462 | * Get the height of the action bar. 463 | * 464 | * @return The height of the action bar (in pixels). 465 | */ 466 | public int getActionBarHeight() { 467 | return mActionBarHeight; 468 | } 469 | 470 | /** 471 | * Does this device have a system navigation bar? 472 | * 473 | * @return True if this device uses soft key navigation, False otherwise. 474 | */ 475 | public boolean hasNavigtionBar() { 476 | return mHasNavigationBar; 477 | } 478 | 479 | /** 480 | * Get the height of the system navigation bar. 481 | * 482 | * @return The height of the navigation bar (in pixels). If the device does not have 483 | * soft navigation keys, this will always return 0. 484 | */ 485 | public int getNavigationBarHeight() { 486 | return mNavigationBarHeight; 487 | } 488 | 489 | /** 490 | * Get the width of the system navigation bar when it is placed vertically on the screen. 491 | * 492 | * @return The width of the navigation bar (in pixels). If the device does not have 493 | * soft navigation keys, this will always return 0. 494 | */ 495 | public int getNavigationBarWidth() { 496 | return mNavigationBarWidth; 497 | } 498 | 499 | /** 500 | * Get the layout inset for any system UI that appears at the top of the screen. 501 | * 502 | * @param withActionBar True to include the height of the action bar, False otherwise. 503 | * @return The layout inset (in pixels). 504 | */ 505 | public int getPixelInsetTop(boolean withActionBar) { 506 | return (mTranslucentStatusBar ? mStatusBarHeight : 0) + (withActionBar ? mActionBarHeight : 0); 507 | } 508 | 509 | /** 510 | * Get the layout inset for any system UI that appears at the bottom of the screen. 511 | * 512 | * @return The layout inset (in pixels). 513 | */ 514 | public int getPixelInsetBottom() { 515 | if (mTranslucentNavBar && isNavigationAtBottom()) { 516 | return mNavigationBarHeight; 517 | } else { 518 | return 0; 519 | } 520 | } 521 | 522 | /** 523 | * Get the layout inset for any system UI that appears at the right of the screen. 524 | * 525 | * @return The layout inset (in pixels). 526 | */ 527 | public int getPixelInsetRight() { 528 | if (mTranslucentNavBar && !isNavigationAtBottom()) { 529 | return mNavigationBarWidth; 530 | } else { 531 | return 0; 532 | } 533 | } 534 | 535 | private boolean hasNavBar(Context context) { 536 | Resources res = context.getResources(); 537 | int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android"); 538 | if (resourceId != 0) { 539 | boolean hasNav = res.getBoolean(resourceId); 540 | // check override flag (see static block) 541 | if ("1".equals(sNavBarOverride)) { 542 | hasNav = false; 543 | } else if ("0".equals(sNavBarOverride)) { 544 | hasNav = true; 545 | } 546 | return hasNav; 547 | } else { // fallback 548 | return !hasPermanentMenuKey(context); 549 | } 550 | } 551 | 552 | private boolean hasPermanentMenuKey(Context cxt) { 553 | try { 554 | WindowManager wm = (WindowManager) cxt.getSystemService(Context.WINDOW_SERVICE); 555 | 556 | ViewConfiguration config = ViewConfiguration.get(cxt); 557 | Field menuKeyField = ViewConfiguration.class 558 | .getDeclaredField("sHasPermanentMenuKey"); 559 | if (menuKeyField != null) { 560 | menuKeyField.setAccessible(true); 561 | return menuKeyField.getBoolean(config); 562 | } 563 | } catch (Exception e) { 564 | e.printStackTrace(); 565 | } 566 | 567 | return false; 568 | } 569 | 570 | } 571 | 572 | } -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.utils; 2 | 3 | /** 4 | * Created by sunger on 2015/12/15. 5 | */ 6 | 7 | import android.content.Context; 8 | import android.content.res.TypedArray; 9 | 10 | import sunger.net.org.coordinatorlayoutdemos.R; 11 | 12 | public class Utils { 13 | 14 | public static int getToolbarHeight(Context context) { 15 | final TypedArray styledAttributes = context.getTheme().obtainStyledAttributes( 16 | new int[]{R.attr.actionBarSize}); 17 | int toolbarHeight = (int) styledAttributes.getDimension(0, 0); 18 | styledAttributes.recycle(); 19 | 20 | return toolbarHeight; 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/sunger/net/org/coordinatorlayoutdemos/widget/ProgressWheel.java: -------------------------------------------------------------------------------- 1 | package sunger.net.org.coordinatorlayoutdemos.widget; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.Paint.Style; 9 | import android.graphics.RectF; 10 | import android.os.Build; 11 | import android.os.Parcel; 12 | import android.os.Parcelable; 13 | import android.os.SystemClock; 14 | import android.provider.Settings; 15 | import android.util.AttributeSet; 16 | import android.util.DisplayMetrics; 17 | import android.util.TypedValue; 18 | import android.view.View; 19 | 20 | import sunger.net.org.coordinatorlayoutdemos.R; 21 | 22 | 23 | /** 24 | * Created by sunger on 2015/10/30. 25 | */ 26 | public class ProgressWheel extends View { 27 | private static final String TAG = ProgressWheel.class.getSimpleName(); 28 | private final int barLength = 16; 29 | private final int barMaxLength = 270; 30 | private final long pauseGrowingTime = 200; 31 | /** 32 | * ********* 33 | * DEFAULTS * 34 | * ********** 35 | */ 36 | //Sizes (with defaults in DP) 37 | private int circleRadius = 28; 38 | private int barWidth = 4; 39 | private int rimWidth = 4; 40 | private boolean fillRadius = false; 41 | private double timeStartGrowing = 0; 42 | private double barSpinCycleTime = 460; 43 | private float barExtraLength = 0; 44 | private boolean barGrowingFromFront = true; 45 | private long pausedTimeWithoutGrowing = 0; 46 | //Colors (with defaults) 47 | private int barColor = 0xAA000000; 48 | private int rimColor = 0x00FFFFFF; 49 | 50 | //Paints 51 | private Paint barPaint = new Paint(); 52 | private Paint rimPaint = new Paint(); 53 | 54 | //Rectangles 55 | private RectF circleBounds = new RectF(); 56 | 57 | //Animation 58 | //The amount of degrees per second 59 | private float spinSpeed = 230.0f; 60 | //private float spinSpeed = 120.0f; 61 | // The last time the spinner was animated 62 | private long lastTimeAnimated = 0; 63 | 64 | private boolean linearProgress; 65 | 66 | private float mProgress = 0.0f; 67 | private float mTargetProgress = 0.0f; 68 | private boolean isSpinning = false; 69 | 70 | private ProgressCallback callback; 71 | 72 | private boolean shouldAnimate; 73 | 74 | /** 75 | * The constructor for the ProgressWheel 76 | */ 77 | public ProgressWheel(Context context, AttributeSet attrs) { 78 | super(context, attrs); 79 | 80 | parseAttributes(context.obtainStyledAttributes(attrs, R.styleable.ProgressWheel)); 81 | 82 | setAnimationEnabled(); 83 | } 84 | 85 | /** 86 | * The constructor for the ProgressWheel 87 | */ 88 | public ProgressWheel(Context context) { 89 | super(context); 90 | setAnimationEnabled(); 91 | } 92 | 93 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private void setAnimationEnabled() { 94 | int currentApiVersion = Build.VERSION.SDK_INT; 95 | 96 | float animationValue; 97 | if (currentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 98 | animationValue = Settings.Global.getFloat(getContext().getContentResolver(), 99 | Settings.Global.ANIMATOR_DURATION_SCALE, 1); 100 | } else { 101 | animationValue = Settings.System.getFloat(getContext().getContentResolver(), 102 | Settings.System.ANIMATOR_DURATION_SCALE, 1); 103 | } 104 | 105 | shouldAnimate = animationValue != 0; 106 | } 107 | 108 | //---------------------------------- 109 | //Setting up stuff 110 | //---------------------------------- 111 | 112 | @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 113 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 114 | 115 | int viewWidth = circleRadius + this.getPaddingLeft() + this.getPaddingRight(); 116 | int viewHeight = circleRadius + this.getPaddingTop() + this.getPaddingBottom(); 117 | 118 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); 119 | int widthSize = MeasureSpec.getSize(widthMeasureSpec); 120 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); 121 | int heightSize = MeasureSpec.getSize(heightMeasureSpec); 122 | 123 | int width; 124 | int height; 125 | 126 | //Measure Width 127 | if (widthMode == MeasureSpec.EXACTLY) { 128 | //Must be this size 129 | width = widthSize; 130 | } else if (widthMode == MeasureSpec.AT_MOST) { 131 | //Can't be bigger than... 132 | width = Math.min(viewWidth, widthSize); 133 | } else { 134 | //Be whatever you want 135 | width = viewWidth; 136 | } 137 | 138 | //Measure Height 139 | if (heightMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.EXACTLY) { 140 | //Must be this size 141 | height = heightSize; 142 | } else if (heightMode == MeasureSpec.AT_MOST) { 143 | //Can't be bigger than... 144 | height = Math.min(viewHeight, heightSize); 145 | } else { 146 | //Be whatever you want 147 | height = viewHeight; 148 | } 149 | 150 | setMeasuredDimension(width, height); 151 | } 152 | 153 | /** 154 | * Use onSizeChanged instead of onAttachedToWindow to get the dimensions of the view, 155 | * because this method is called after measuring the dimensions of MATCH_PARENT & WRAP_CONTENT. 156 | * Use this dimensions to setup the bounds and paints. 157 | */ 158 | @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { 159 | super.onSizeChanged(w, h, oldw, oldh); 160 | 161 | setupBounds(w, h); 162 | setupPaints(); 163 | invalidate(); 164 | } 165 | 166 | /** 167 | * Set the properties of the paints we're using to 168 | * draw the progress wheel 169 | */ 170 | private void setupPaints() { 171 | barPaint.setColor(barColor); 172 | barPaint.setAntiAlias(true); 173 | barPaint.setStyle(Style.STROKE); 174 | barPaint.setStrokeWidth(barWidth); 175 | 176 | rimPaint.setColor(rimColor); 177 | rimPaint.setAntiAlias(true); 178 | rimPaint.setStyle(Style.STROKE); 179 | rimPaint.setStrokeWidth(rimWidth); 180 | } 181 | 182 | /** 183 | * Set the bounds of the component 184 | */ 185 | private void setupBounds(int layout_width, int layout_height) { 186 | int paddingTop = getPaddingTop(); 187 | int paddingBottom = getPaddingBottom(); 188 | int paddingLeft = getPaddingLeft(); 189 | int paddingRight = getPaddingRight(); 190 | 191 | if (!fillRadius) { 192 | // Width should equal to Height, find the min value to setup the circle 193 | int minValue = Math.min(layout_width - paddingLeft - paddingRight, 194 | layout_height - paddingBottom - paddingTop); 195 | 196 | int circleDiameter = Math.min(minValue, circleRadius * 2 - barWidth * 2); 197 | 198 | // Calc the Offset if needed for centering the wheel in the available space 199 | int xOffset = (layout_width - paddingLeft - paddingRight - circleDiameter) / 2 + paddingLeft; 200 | int yOffset = (layout_height - paddingTop - paddingBottom - circleDiameter) / 2 + paddingTop; 201 | 202 | circleBounds = 203 | new RectF(xOffset + barWidth, yOffset + barWidth, xOffset + circleDiameter - barWidth, 204 | yOffset + circleDiameter - barWidth); 205 | } else { 206 | circleBounds = new RectF(paddingLeft + barWidth, paddingTop + barWidth, 207 | layout_width - paddingRight - barWidth, layout_height - paddingBottom - barWidth); 208 | } 209 | } 210 | 211 | /** 212 | * Parse the attributes passed to the view from the XML 213 | * 214 | * @param a the attributes to parse 215 | */ 216 | private void parseAttributes(TypedArray a) { 217 | // We transform the default values from DIP to pixels 218 | DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); 219 | barWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, barWidth, metrics); 220 | rimWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rimWidth, metrics); 221 | circleRadius = 222 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, circleRadius, metrics); 223 | 224 | circleRadius = 225 | (int) a.getDimension(R.styleable.ProgressWheel_matProg_circleRadius, circleRadius); 226 | 227 | fillRadius = a.getBoolean(R.styleable.ProgressWheel_matProg_fillRadius, false); 228 | 229 | barWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_barWidth, barWidth); 230 | 231 | rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_rimWidth, rimWidth); 232 | 233 | float baseSpinSpeed = 234 | a.getFloat(R.styleable.ProgressWheel_matProg_spinSpeed, spinSpeed / 360.0f); 235 | spinSpeed = baseSpinSpeed * 360; 236 | 237 | barSpinCycleTime = 238 | a.getInt(R.styleable.ProgressWheel_matProg_barSpinCycleTime, (int) barSpinCycleTime); 239 | 240 | barColor = a.getColor(R.styleable.ProgressWheel_matProg_barColor, barColor); 241 | 242 | rimColor = a.getColor(R.styleable.ProgressWheel_matProg_rimColor, rimColor); 243 | 244 | linearProgress = a.getBoolean(R.styleable.ProgressWheel_matProg_linearProgress, false); 245 | 246 | if (a.getBoolean(R.styleable.ProgressWheel_matProg_progressIndeterminate, false)) { 247 | spin(); 248 | } 249 | 250 | // Recycle 251 | a.recycle(); 252 | } 253 | 254 | public void setCallback(ProgressCallback progressCallback) { 255 | callback = progressCallback; 256 | 257 | if (!isSpinning) { 258 | runCallback(); 259 | } 260 | } 261 | 262 | //---------------------------------- 263 | //Animation stuff 264 | //---------------------------------- 265 | 266 | protected void onDraw(Canvas canvas) { 267 | super.onDraw(canvas); 268 | 269 | canvas.drawArc(circleBounds, 360, 360, false, rimPaint); 270 | 271 | boolean mustInvalidate = false; 272 | 273 | if (!shouldAnimate) { 274 | return; 275 | } 276 | 277 | if (isSpinning) { 278 | //Draw the spinning bar 279 | mustInvalidate = true; 280 | 281 | long deltaTime = (SystemClock.uptimeMillis() - lastTimeAnimated); 282 | float deltaNormalized = deltaTime * spinSpeed / 1000.0f; 283 | 284 | updateBarLength(deltaTime); 285 | 286 | mProgress += deltaNormalized; 287 | if (mProgress > 360) { 288 | mProgress -= 360f; 289 | 290 | // A full turn has been completed 291 | // we run the callback with -1 in case we want to 292 | // do something, like changing the color 293 | runCallback(-1.0f); 294 | } 295 | lastTimeAnimated = SystemClock.uptimeMillis(); 296 | 297 | float from = mProgress - 90; 298 | float length = barLength + barExtraLength; 299 | 300 | if (isInEditMode()) { 301 | from = 0; 302 | length = 135; 303 | } 304 | 305 | canvas.drawArc(circleBounds, from, length, false, barPaint); 306 | } else { 307 | float oldProgress = mProgress; 308 | 309 | if (mProgress != mTargetProgress) { 310 | //We smoothly increase the progress bar 311 | mustInvalidate = true; 312 | 313 | float deltaTime = (float) (SystemClock.uptimeMillis() - lastTimeAnimated) / 1000; 314 | float deltaNormalized = deltaTime * spinSpeed; 315 | 316 | mProgress = Math.min(mProgress + deltaNormalized, mTargetProgress); 317 | lastTimeAnimated = SystemClock.uptimeMillis(); 318 | } 319 | 320 | if (oldProgress != mProgress) { 321 | runCallback(); 322 | } 323 | 324 | float offset = 0.0f; 325 | float progress = mProgress; 326 | if (!linearProgress) { 327 | float factor = 2.0f; 328 | offset = (float) (1.0f - Math.pow(1.0f - mProgress / 360.0f, 2.0f * factor)) * 360.0f; 329 | progress = (float) (1.0f - Math.pow(1.0f - mProgress / 360.0f, factor)) * 360.0f; 330 | } 331 | 332 | if (isInEditMode()) { 333 | progress = 360; 334 | } 335 | 336 | canvas.drawArc(circleBounds, offset - 90, progress, false, barPaint); 337 | } 338 | 339 | if (mustInvalidate) { 340 | invalidate(); 341 | } 342 | } 343 | 344 | @Override protected void onVisibilityChanged(View changedView, int visibility) { 345 | super.onVisibilityChanged(changedView, visibility); 346 | 347 | if (visibility == VISIBLE) { 348 | lastTimeAnimated = SystemClock.uptimeMillis(); 349 | } 350 | } 351 | 352 | private void updateBarLength(long deltaTimeInMilliSeconds) { 353 | if (pausedTimeWithoutGrowing >= pauseGrowingTime) { 354 | timeStartGrowing += deltaTimeInMilliSeconds; 355 | 356 | if (timeStartGrowing > barSpinCycleTime) { 357 | // We completed a size change cycle 358 | // (growing or shrinking) 359 | timeStartGrowing -= barSpinCycleTime; 360 | //if(barGrowingFromFront) { 361 | pausedTimeWithoutGrowing = 0; 362 | //} 363 | barGrowingFromFront = !barGrowingFromFront; 364 | } 365 | 366 | float distance = 367 | (float) Math.cos((timeStartGrowing / barSpinCycleTime + 1) * Math.PI) / 2 + 0.5f; 368 | float destLength = (barMaxLength - barLength); 369 | 370 | if (barGrowingFromFront) { 371 | barExtraLength = distance * destLength; 372 | } else { 373 | float newLength = destLength * (1 - distance); 374 | mProgress += (barExtraLength - newLength); 375 | barExtraLength = newLength; 376 | } 377 | } else { 378 | pausedTimeWithoutGrowing += deltaTimeInMilliSeconds; 379 | } 380 | } 381 | 382 | /** 383 | * Check if the wheel is currently spinning 384 | */ 385 | 386 | public boolean isSpinning() { 387 | return isSpinning; 388 | } 389 | 390 | /** 391 | * Reset the count (in increment mode) 392 | */ 393 | public void resetCount() { 394 | mProgress = 0.0f; 395 | mTargetProgress = 0.0f; 396 | invalidate(); 397 | } 398 | 399 | /** 400 | * Turn off spin mode 401 | */ 402 | public void stopSpinning() { 403 | isSpinning = false; 404 | mProgress = 0.0f; 405 | mTargetProgress = 0.0f; 406 | invalidate(); 407 | } 408 | 409 | /** 410 | * Puts the view on spin mode 411 | */ 412 | public void spin() { 413 | lastTimeAnimated = SystemClock.uptimeMillis(); 414 | isSpinning = true; 415 | invalidate(); 416 | } 417 | 418 | private void runCallback(float value) { 419 | if (callback != null) { 420 | callback.onProgressUpdate(value); 421 | } 422 | } 423 | 424 | private void runCallback() { 425 | if (callback != null) { 426 | float normalizedProgress = (float) Math.round(mProgress * 100 / 360.0f) / 100; 427 | callback.onProgressUpdate(normalizedProgress); 428 | } 429 | } 430 | 431 | /** 432 | * Set the progress to a specific value, 433 | * the bar will be set instantly to that value 434 | * 435 | * @param progress the progress between 0 and 1 436 | */ 437 | public void setInstantProgress(float progress) { 438 | if (isSpinning) { 439 | mProgress = 0.0f; 440 | isSpinning = false; 441 | } 442 | 443 | if (progress > 1.0f) { 444 | progress -= 1.0f; 445 | } else if (progress < 0) { 446 | progress = 0; 447 | } 448 | 449 | if (progress == mTargetProgress) { 450 | return; 451 | } 452 | 453 | mTargetProgress = Math.min(progress * 360.0f, 360.0f); 454 | mProgress = mTargetProgress; 455 | lastTimeAnimated = SystemClock.uptimeMillis(); 456 | invalidate(); 457 | } 458 | 459 | // Great way to save a view's state http://stackoverflow.com/a/7089687/1991053 460 | @Override public Parcelable onSaveInstanceState() { 461 | Parcelable superState = super.onSaveInstanceState(); 462 | 463 | WheelSavedState ss = new WheelSavedState(superState); 464 | 465 | // We save everything that can be changed at runtime 466 | ss.mProgress = this.mProgress; 467 | ss.mTargetProgress = this.mTargetProgress; 468 | ss.isSpinning = this.isSpinning; 469 | ss.spinSpeed = this.spinSpeed; 470 | ss.barWidth = this.barWidth; 471 | ss.barColor = this.barColor; 472 | ss.rimWidth = this.rimWidth; 473 | ss.rimColor = this.rimColor; 474 | ss.circleRadius = this.circleRadius; 475 | ss.linearProgress = this.linearProgress; 476 | ss.fillRadius = this.fillRadius; 477 | 478 | return ss; 479 | } 480 | 481 | @Override public void onRestoreInstanceState(Parcelable state) { 482 | if (!(state instanceof WheelSavedState)) { 483 | super.onRestoreInstanceState(state); 484 | return; 485 | } 486 | 487 | WheelSavedState ss = (WheelSavedState) state; 488 | super.onRestoreInstanceState(ss.getSuperState()); 489 | 490 | this.mProgress = ss.mProgress; 491 | this.mTargetProgress = ss.mTargetProgress; 492 | this.isSpinning = ss.isSpinning; 493 | this.spinSpeed = ss.spinSpeed; 494 | this.barWidth = ss.barWidth; 495 | this.barColor = ss.barColor; 496 | this.rimWidth = ss.rimWidth; 497 | this.rimColor = ss.rimColor; 498 | this.circleRadius = ss.circleRadius; 499 | this.linearProgress = ss.linearProgress; 500 | this.fillRadius = ss.fillRadius; 501 | 502 | this.lastTimeAnimated = SystemClock.uptimeMillis(); 503 | } 504 | 505 | /** 506 | * @return the current progress between 0.0 and 1.0, 507 | * if the wheel is indeterminate, then the result is -1 508 | */ 509 | public float getProgress() { 510 | return isSpinning ? -1 : mProgress / 360.0f; 511 | } 512 | 513 | //---------------------------------- 514 | //Getters + setters 515 | //---------------------------------- 516 | 517 | /** 518 | * Set the progress to a specific value, 519 | * the bar will smoothly animate until that value 520 | * 521 | * @param progress the progress between 0 and 1 522 | */ 523 | public void setProgress(float progress) { 524 | if (isSpinning) { 525 | mProgress = 0.0f; 526 | isSpinning = false; 527 | 528 | runCallback(); 529 | } 530 | 531 | if (progress > 1.0f) { 532 | progress -= 1.0f; 533 | } else if (progress < 0) { 534 | progress = 0; 535 | } 536 | 537 | if (progress == mTargetProgress) { 538 | return; 539 | } 540 | 541 | // If we are currently in the right position 542 | // we set again the last time animated so the 543 | // animation starts smooth from here 544 | if (mProgress == mTargetProgress) { 545 | lastTimeAnimated = SystemClock.uptimeMillis(); 546 | } 547 | 548 | mTargetProgress = Math.min(progress * 360.0f, 360.0f); 549 | 550 | invalidate(); 551 | } 552 | 553 | /** 554 | * Sets the determinate progress mode 555 | * 556 | * @param isLinear if the progress should increase linearly 557 | */ 558 | public void setLinearProgress(boolean isLinear) { 559 | linearProgress = isLinear; 560 | if (!isSpinning) { 561 | invalidate(); 562 | } 563 | } 564 | 565 | /** 566 | * @return the radius of the wheel in pixels 567 | */ 568 | public int getCircleRadius() { 569 | return circleRadius; 570 | } 571 | 572 | /** 573 | * Sets the radius of the wheel 574 | * 575 | * @param circleRadius the expected radius, in pixels 576 | */ 577 | public void setCircleRadius(int circleRadius) { 578 | this.circleRadius = circleRadius; 579 | if (!isSpinning) { 580 | invalidate(); 581 | } 582 | } 583 | 584 | /** 585 | * @return the width of the spinning bar 586 | */ 587 | public int getBarWidth() { 588 | return barWidth; 589 | } 590 | 591 | /** 592 | * Sets the width of the spinning bar 593 | * 594 | * @param barWidth the spinning bar width in pixels 595 | */ 596 | public void setBarWidth(int barWidth) { 597 | this.barWidth = barWidth; 598 | if (!isSpinning) { 599 | invalidate(); 600 | } 601 | } 602 | 603 | /** 604 | * @return the color of the spinning bar 605 | */ 606 | public int getBarColor() { 607 | return barColor; 608 | } 609 | 610 | /** 611 | * Sets the color of the spinning bar 612 | * 613 | * @param barColor The spinning bar color 614 | */ 615 | public void setBarColor(int barColor) { 616 | this.barColor = barColor; 617 | setupPaints(); 618 | if (!isSpinning) { 619 | invalidate(); 620 | } 621 | } 622 | 623 | /** 624 | * @return the color of the wheel's contour 625 | */ 626 | public int getRimColor() { 627 | return rimColor; 628 | } 629 | 630 | /** 631 | * Sets the color of the wheel's contour 632 | * 633 | * @param rimColor the color for the wheel 634 | */ 635 | public void setRimColor(int rimColor) { 636 | this.rimColor = rimColor; 637 | setupPaints(); 638 | if (!isSpinning) { 639 | invalidate(); 640 | } 641 | } 642 | 643 | /** 644 | * @return the base spinning speed, in full circle turns per second 645 | * (1.0 equals on full turn in one second), this value also is applied for 646 | * the smoothness when setting a progress 647 | */ 648 | public float getSpinSpeed() { 649 | return spinSpeed / 360.0f; 650 | } 651 | 652 | /** 653 | * Sets the base spinning speed, in full circle turns per second 654 | * (1.0 equals on full turn in one second), this value also is applied for 655 | * the smoothness when setting a progress 656 | * 657 | * @param spinSpeed the desired base speed in full turns per second 658 | */ 659 | public void setSpinSpeed(float spinSpeed) { 660 | this.spinSpeed = spinSpeed * 360.0f; 661 | } 662 | 663 | /** 664 | * @return the width of the wheel's contour in pixels 665 | */ 666 | public int getRimWidth() { 667 | return rimWidth; 668 | } 669 | 670 | /** 671 | * Sets the width of the wheel's contour 672 | * 673 | * @param rimWidth the width in pixels 674 | */ 675 | public void setRimWidth(int rimWidth) { 676 | this.rimWidth = rimWidth; 677 | if (!isSpinning) { 678 | invalidate(); 679 | } 680 | } 681 | 682 | public interface ProgressCallback { 683 | /** 684 | * Method to call when the progress reaches a value 685 | * in order to avoid float precision issues, the progress 686 | * is rounded to a float with two decimals. 687 | * 688 | * In indeterminate mode, the callback is called each time 689 | * the wheel completes an animation cycle, with, the progress value is -1.0f 690 | * 691 | * @param progress a double value between 0.00 and 1.00 both included 692 | */ 693 | public void onProgressUpdate(float progress); 694 | } 695 | 696 | static class WheelSavedState extends BaseSavedState { 697 | //required field that makes Parcelables from a Parcel 698 | public static final Creator CREATOR = 699 | new Creator() { 700 | public WheelSavedState createFromParcel(Parcel in) { 701 | return new WheelSavedState(in); 702 | } 703 | 704 | public WheelSavedState[] newArray(int size) { 705 | return new WheelSavedState[size]; 706 | } 707 | }; 708 | float mProgress; 709 | float mTargetProgress; 710 | boolean isSpinning; 711 | float spinSpeed; 712 | int barWidth; 713 | int barColor; 714 | int rimWidth; 715 | int rimColor; 716 | int circleRadius; 717 | boolean linearProgress; 718 | boolean fillRadius; 719 | 720 | WheelSavedState(Parcelable superState) { 721 | super(superState); 722 | } 723 | 724 | private WheelSavedState(Parcel in) { 725 | super(in); 726 | this.mProgress = in.readFloat(); 727 | this.mTargetProgress = in.readFloat(); 728 | this.isSpinning = in.readByte() != 0; 729 | this.spinSpeed = in.readFloat(); 730 | this.barWidth = in.readInt(); 731 | this.barColor = in.readInt(); 732 | this.rimWidth = in.readInt(); 733 | this.rimColor = in.readInt(); 734 | this.circleRadius = in.readInt(); 735 | this.linearProgress = in.readByte() != 0; 736 | this.fillRadius = in.readByte() != 0; 737 | } 738 | 739 | @Override public void writeToParcel(Parcel out, int flags) { 740 | super.writeToParcel(out, flags); 741 | out.writeFloat(this.mProgress); 742 | out.writeFloat(this.mTargetProgress); 743 | out.writeByte((byte) (isSpinning ? 1 : 0)); 744 | out.writeFloat(this.spinSpeed); 745 | out.writeInt(this.barWidth); 746 | out.writeInt(this.barColor); 747 | out.writeInt(this.rimWidth); 748 | out.writeInt(this.rimColor); 749 | out.writeInt(this.circleRadius); 750 | out.writeByte((byte) (linearProgress ? 1 : 0)); 751 | out.writeByte((byte) (fillRadius ? 1 : 0)); 752 | } 753 | } 754 | } 755 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/iconfont_downgrey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sungerk/CoordinatorLayoutDemos/55629309b6b41abe86c23345ff90b47cdb64a6dc/app/src/main/res/drawable-nodpi/iconfont_downgrey.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_camera.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_gallery.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_manage.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_send.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_share.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_slideshow.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/side_nav_bar.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_header_viewpager.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 16 | 22 | 23 | 30 | 31 | 32 | 33 | 42 | 43 | 52 | 53 | 54 | 55 | 56 | 57 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_recycler_hidden_toolbar.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 16 | 17 | 21 | 22 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_scroller_hidden_toolbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 16 | 17 | 22 | 23 | 24 | 25 | 30 | 31 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/app_bar_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 20 | 21 | 28 | 29 | 30 | 31 | 36 | 37 | 38 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_nestedscroll.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_recyclerview.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_recyclerview2.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 13 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_view_load_more.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 15 | 16 | 22 | 23 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/nav_header_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 20 | 21 | 27 | 28 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recyclerview_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_footer_action.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 20 | 21 | 22 | 23 | 33 | 34 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_pager_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_main_drawer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 12 | 13 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sungerk/CoordinatorLayoutDemos/55629309b6b41abe86c23345ff90b47cdb64a6dc/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sungerk/CoordinatorLayoutDemos/55629309b6b41abe86c23345ff90b47cdb64a6dc/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sungerk/CoordinatorLayoutDemos/55629309b6b41abe86c23345ff90b47cdb64a6dc/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sungerk/CoordinatorLayoutDemos/55629309b6b41abe86c23345ff90b47cdb64a6dc/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sungerk/CoordinatorLayoutDemos/55629309b6b41abe86c23345ff90b47cdb64a6dc/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | > 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /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 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #303F9F 7 | 8 | #3F51B5 9 | #FFFFFF 10 | #000000 11 | #999999 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 160dp 5 | 6 | 16dp 7 | 16dp 8 | 16dp 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/drawables.xml: -------------------------------------------------------------------------------- 1 | 2 | @android:drawable/ic_menu_camera 3 | @android:drawable/ic_menu_gallery 4 | @android:drawable/ic_menu_slideshow 5 | @android:drawable/ic_menu_manage 6 | @android:drawable/ic_menu_share 7 | @android:drawable/ic_menu_send 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CoordinatorLayoutDemos 3 | 4 | Open navigation drawer 5 | Close navigation drawer 6 | 7 | Settings 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, 12 | and distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by 15 | the copyright owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all 18 | other entities that control, are controlled by, or are under common 19 | control with that entity. For the purposes of this definition, 20 | "control" means (i) the power, direct or indirect, to cause the 21 | direction or management of such entity, whether by contract or 22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 23 | outstanding shares, or (iii) beneficial ownership of such entity. 24 | 25 | "You" (or "Your") shall mean an individual or Legal Entity 26 | exercising permissions granted by this License. 27 | 28 | "Source" form shall mean the preferred form for making modifications, 29 | including but not limited to software source code, documentation 30 | source, and configuration files. 31 | 32 | "Object" form shall mean any form resulting from mechanical 33 | transformation or translation of a Source form, including but 34 | not limited to compiled object code, generated documentation, 35 | and conversions to other media types. 36 | 37 | "Work" shall mean the work of authorship, whether in Source or 38 | Object form, made available under the License, as indicated by a 39 | copyright notice that is included in or attached to the work 40 | (an example is provided in the Appendix below). 41 | 42 | "Derivative Works" shall mean any work, whether in Source or Object 43 | form, that is based on (or derived from) the Work and for which the 44 | editorial revisions, annotations, elaborations, or other modifications 45 | represent, as a whole, an original work of authorship. For the purposes 46 | of this License, Derivative Works shall not include works that remain 47 | separable from, or merely link (or bind by name) to the interfaces of, 48 | the Work and Derivative Works thereof. 49 | 50 | "Contribution" shall mean any work of authorship, including 51 | the original version of the Work and any modifications or additions 52 | to that Work or Derivative Works thereof, that is intentionally 53 | submitted to Licensor for inclusion in the Work by the copyright owner 54 | or by an individual or Legal Entity authorized to submit on behalf of 55 | the copyright owner. For the purposes of this definition, "submitted" 56 | means any form of electronic, verbal, or written communication sent 57 | to the Licensor or its representatives, including but not limited to 58 | communication on electronic mailing lists, source code control systems, 59 | and issue tracking systems that are managed by, or on behalf of, the 60 | Licensor for the purpose of discussing and improving the Work, but 61 | excluding communication that is conspicuously marked or otherwise 62 | designated in writing by the copyright owner as "Not a Contribution." 63 | 64 | "Contributor" shall mean Licensor and any individual or Legal Entity 65 | on behalf of whom a Contribution has been received by Licensor and 66 | subsequently incorporated within the Work. 67 | 68 | 2. Grant of Copyright License. Subject to the terms and conditions of 69 | this License, each Contributor hereby grants to You a perpetual, 70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 71 | copyright license to reproduce, prepare Derivative Works of, 72 | publicly display, publicly perform, sublicense, and distribute the 73 | Work and such Derivative Works in Source or Object form. 74 | 75 | 3. Grant of Patent License. Subject to the terms and conditions of 76 | this License, each Contributor hereby grants to You a perpetual, 77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 78 | (except as stated in this section) patent license to make, have made, 79 | use, offer to sell, sell, import, and otherwise transfer the Work, 80 | where such license applies only to those patent claims licensable 81 | by such Contributor that are necessarily infringed by their 82 | Contribution(s) alone or by combination of their Contribution(s) 83 | with the Work to which such Contribution(s) was submitted. If You 84 | institute patent litigation against any entity (including a 85 | cross-claim or counterclaim in a lawsuit) alleging that the Work 86 | or a Contribution incorporated within the Work constitutes direct 87 | or contributory patent infringement, then any patent licenses 88 | granted to You under this License for that Work shall terminate 89 | as of the date such litigation is filed. 90 | 91 | 4. Redistribution. You may reproduce and distribute copies of the 92 | Work or Derivative Works thereof in any medium, with or without 93 | modifications, and in Source or Object form, provided that You 94 | meet the following conditions: 95 | 96 | (a) You must give any other recipients of the Work or 97 | Derivative Works a copy of this License; and 98 | 99 | (b) You must cause any modified files to carry prominent notices 100 | stating that You changed the files; and 101 | 102 | (c) You must retain, in the Source form of any Derivative Works 103 | that You distribute, all copyright, patent, trademark, and 104 | attribution notices from the Source form of the Work, 105 | excluding those notices that do not pertain to any part of 106 | the Derivative Works; and 107 | 108 | (d) If the Work includes a "NOTICE" text file as part of its 109 | distribution, then any Derivative Works that You distribute must 110 | include a readable copy of the attribution notices contained 111 | within such NOTICE file, excluding those notices that do not 112 | pertain to any part of the Derivative Works, in at least one 113 | of the following places: within a NOTICE text file distributed 114 | as part of the Derivative Works; within the Source form or 115 | documentation, if provided along with the Derivative Works; or, 116 | within a display generated by the Derivative Works, if and 117 | wherever such third-party notices normally appear. The contents 118 | of the NOTICE file are for informational purposes only and 119 | do not modify the License. You may add Your own attribution 120 | notices within Derivative Works that You distribute, alongside 121 | or as an addendum to the NOTICE text from the Work, provided 122 | that such additional attribution notices cannot be construed 123 | as modifying the License. 124 | 125 | You may add Your own copyright statement to Your modifications and 126 | may provide additional or different license terms and conditions 127 | for use, reproduction, or distribution of Your modifications, or 128 | for any such Derivative Works as a whole, provided Your use, 129 | reproduction, and distribution of the Work otherwise complies with 130 | the conditions stated in this License. 131 | 132 | 5. Submission of Contributions. Unless You explicitly state otherwise, 133 | any Contribution intentionally submitted for inclusion in the Work 134 | by You to the Licensor shall be under the terms and conditions of 135 | this License, without any additional terms or conditions. 136 | Notwithstanding the above, nothing herein shall supersede or modify 137 | the terms of any separate license agreement you may have executed 138 | with Licensor regarding such Contributions. 139 | 140 | 6. Trademarks. This License does not grant permission to use the trade 141 | names, trademarks, service marks, or product names of the Licensor, 142 | except as required for reasonable and customary use in describing the 143 | origin of the Work and reproducing the content of the NOTICE file. 144 | 145 | 7. Disclaimer of Warranty. Unless required by applicable law or 146 | agreed to in writing, Licensor provides the Work (and each 147 | Contributor provides its Contributions) on an "AS IS" BASIS, 148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 149 | implied, including, without limitation, any warranties or conditions 150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 151 | PARTICULAR PURPOSE. You are solely responsible for determining the 152 | appropriateness of using or redistributing the Work and assume any 153 | risks associated with Your exercise of permissions under this License. 154 | 155 | 8. Limitation of Liability. In no event and under no legal theory, 156 | whether in tort (including negligence), contract, or otherwise, 157 | unless required by applicable law (such as deliberate and grossly 158 | negligent acts) or agreed to in writing, shall any Contributor be 159 | liable to You for damages, including any direct, indirect, special, 160 | incidental, or consequential damages of any character arising as a 161 | result of this License or out of the use or inability to use the 162 | Work (including but not limited to damages for loss of goodwill, 163 | work stoppage, computer failure or malfunction, or any and all 164 | other commercial damages or losses), even if such Contributor 165 | has been advised of the possibility of such damages. 166 | 167 | 9. Accepting Warranty or Additional Liability. While redistributing 168 | the Work or Derivative Works thereof, You may choose to offer, 169 | and charge a fee for, acceptance of support, warranty, indemnity, 170 | or other liability obligations and/or rights consistent with this 171 | License. However, in accepting such obligations, You may act only 172 | on Your own behalf and on Your sole responsibility, not on behalf 173 | of any other Contributor, and only if You agree to indemnify, 174 | defend, and hold each Contributor harmless for any liability 175 | incurred by, or claims asserted against, such Contributor by reason 176 | of your accepting any such warranty or additional liability. 177 | 178 | 179 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |