├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── AutoHideHeaderExample.iml ├── CHANGELOG.md ├── README.md ├── androidautohideheader ├── LICENSE.txt ├── androidautohideheader.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── vcaen │ │ └── androidautohideheader │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── vcaen │ │ └── androidautohideheader │ │ └── AutoHideHeaderLayout.java │ └── res │ └── values │ ├── attrs.xml │ ├── ids.xml │ └── strings.xml ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── vcaen │ │ └── mytestapplication │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── vcaen │ │ └── mytestapplication │ │ └── MainActivity.java │ └── res │ ├── drawable │ └── bg.jpg │ ├── layout │ ├── activity_main.xml │ ├── header.xml │ └── list_item.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── example.gif ├── example_screencast.mp4 ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | 9 | local.properties -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | AutoHideHeaderExample -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 24 | 25 | 37 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 64 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AutoHideHeaderExample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | #Change Log 2 | 3 | ## Version 1.2 4 | 5 | * Added option to fix the header 6 | * Java * 7 | ```java 8 | autoHideHeaderLayout.setFixed(Boolean) 9 | ``` 10 | 11 | * XML * 12 | ```xml 13 | app:fixed="true" 14 | ``` 15 | 16 | 17 | * Added option to fix the header if the Body is smaller than the view 18 | * Java * 19 | ```java 20 | autoHideHeaderLayout.setFixedIfChildSmall(Boolean) 21 | ``` 22 | 23 | * XML * 24 | ```xml 25 | app:fixedIfChildSmall="true" 26 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidAutoHideHeader 2 | [ ![Download](https://api.bintray.com/packages/vcaen/maven/androidautohideheader/images/download.svg) ](https://bintray.com/vcaen/maven/androidautohideheader/_latestVersion) 3 | [ ![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-AndroidAutoHideHeader-blue.svg?style=flat)](http://android-arsenal.com/details/1/2285) 4 | 5 | A layout that hide the header when the body is scrolled down and reveal it when the header is scrolled up 6 | 7 | ## Demo 8 | 9 | ![Demo gif](https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/master/example.gif) 10 | 11 | 12 | ## Import it ! 13 | 14 | 15 | In your gradle "app" : 16 | 17 | ``` 18 | dependencies { 19 | compile 'com.vcaen:androidautohideheader:1.2' 20 | } 21 | ``` 22 | 23 | 24 | ## Usage 25 | 26 | ### Basics 27 | 28 | #### Programmatically 29 | In you xml, add the '''AutoHideHeaderLayout''' : 30 | 31 | ```xml 32 | 39 | ``` 40 | 41 | Then in your java code : 42 | ```java 43 | AutoHideHeaderLayout view = (AutoHideHeaderLayout) findViewById(R.id.autohideview); 44 | ListView listView = new ListView(this); 45 | view.setHeader(R.layout.header); // You can also set the View object 46 | view.setBodyView(listView); 47 | ``` 48 | 49 | #### XML Only 50 | 51 | You can add the children directly into the XML by adding them inside the ```AutoHideHeaderLayout``` : 52 | ```xml 53 | 58 | 59 | 63 | 64 | 67 | 68 | 73 | 74 | 75 | 76 | 79 | 80 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | ``` 91 | ### Options : 92 | 93 | The following options are available : 94 | 95 | * Fix the header 96 | 97 | *Java* 98 | ```java 99 | autoHideHeaderLayout.setFixed(Boolean) 100 | ``` 101 | 102 | *XML* 103 | ```xml 104 | app:fixed="true" 105 | ``` 106 | 107 | 108 | * Fix the header if the child is smaller than the view. Only works if the child has height set at ```wrap_content``` 109 | 110 | *Java* 111 | ```java 112 | autoHideHeaderLayout.setFixedIfChildSmall(Boolean) 113 | ``` 114 | 115 | *XML* 116 | ```xml 117 | app:fixedIfChildSmall="true" 118 | ``` 119 | 120 | 121 | ## License 122 | 123 | The MIT License (MIT) 124 | 125 | Copyright (c) 2015 Vadim Caen 126 | 127 | Permission is hereby granted, free of charge, to any person obtaining a copy 128 | of this software and associated documentation files (the "Software"), to deal 129 | in the Software without restriction, including without limitation the rights 130 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 131 | copies of the Software, and to permit persons to whom the Software is 132 | furnished to do so, subject to the following conditions: 133 | 134 | The above copyright notice and this permission notice shall be included in all 135 | copies or substantial portions of the Software. 136 | 137 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 138 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 139 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 140 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 141 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 142 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 143 | SOFTWARE 144 | -------------------------------------------------------------------------------- /androidautohideheader/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Vadim Caen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /androidautohideheader/androidautohideheader.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /androidautohideheader/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.jfrog.bintray' 3 | 4 | ext { 5 | bintrayRepo = 'maven' 6 | bintrayName = 'androidautohideheader' 7 | 8 | publishedGroupId = 'com.vcaen' 9 | libraryName = 'AndroidAutoHideHeader' 10 | artifact = 'androidautohideheader' 11 | 12 | libraryDescription = 'A Header that hide on ScrollDown and reveal on ScrollUp' 13 | 14 | siteUrl = 'https://github.com/vcaen/AndroidAutoHideHeader' 15 | gitUrl = 'https://github.com/vcaen/AndroidAutoHideHeader.git' 16 | 17 | libraryVersion = '1.2' 18 | 19 | developerId = 'vcaen' 20 | developerName = 'Vadim Caen' 21 | developerEmail = 'vadimcaen@gmail.com' 22 | 23 | licenseName = 'MIT License (MIT)' 24 | licenseUrl = 'opensource.org/licenses/MIT' 25 | allLicenses = ["MIT"] 26 | } 27 | 28 | android { 29 | compileSdkVersion 22 30 | buildToolsVersion "22.0.1" 31 | defaultPublishConfig "release" 32 | 33 | defaultConfig { 34 | minSdkVersion 15 35 | targetSdkVersion 22 36 | versionCode 3 37 | versionName "1.2" 38 | } 39 | buildTypes { 40 | release { 41 | minifyEnabled false 42 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 43 | } 44 | } 45 | } 46 | 47 | 48 | 49 | dependencies { 50 | compile fileTree(dir: 'libs', include: ['*.jar']) 51 | compile 'com.android.support:appcompat-v7:22.2.0' 52 | } 53 | 54 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' 55 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' 56 | 57 | -------------------------------------------------------------------------------- /androidautohideheader/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/vcaen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /androidautohideheader/src/androidTest/java/com/vcaen/androidautohideheader/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.vcaen.androidautohideheader; 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 | } -------------------------------------------------------------------------------- /androidautohideheader/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /androidautohideheader/src/main/java/com/vcaen/androidautohideheader/AutoHideHeaderLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Vadim Caen 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.vcaen.androidautohideheader; 26 | 27 | import android.content.Context; 28 | import android.content.res.TypedArray; 29 | import android.util.AttributeSet; 30 | import android.util.Log; 31 | import android.view.LayoutInflater; 32 | import android.view.MotionEvent; 33 | import android.view.View; 34 | import android.view.ViewGroup; 35 | import android.widget.FrameLayout; 36 | import android.widget.RelativeLayout; 37 | 38 | 39 | public class AutoHideHeaderLayout extends RelativeLayout { 40 | 41 | 42 | private static final long MIN_EVENT_TIME = 200; 43 | private static final long ANIMATION_DURATION = 200; 44 | 45 | enum HeaderState { 46 | HIDDEN, 47 | OPENING, 48 | OPENED 49 | } 50 | 51 | private boolean _fixedIfChildSmall = true; 52 | private boolean _fixed = false; 53 | 54 | 55 | View _headerLayout; 56 | BodyLayout _bodyLayout; 57 | HeaderState _state; 58 | 59 | public AutoHideHeaderLayout(Context context) { 60 | this(context, null); 61 | } 62 | 63 | 64 | public AutoHideHeaderLayout(Context context, AttributeSet attrs) { 65 | this(context, attrs, 0); 66 | } 67 | 68 | public AutoHideHeaderLayout(Context context, AttributeSet attrs, int defStyleAttr) { 69 | super(context, attrs, defStyleAttr); 70 | _state = HeaderState.OPENED; 71 | createBody(context); 72 | 73 | 74 | if (attrs != null) { 75 | TypedArray a = context.getTheme().obtainStyledAttributes( 76 | attrs, 77 | R.styleable.AutoHideHeaderLayout, 78 | 0, 0); 79 | 80 | try { 81 | setFixed(a.getBoolean(R.styleable.AutoHideHeaderLayout_fixed, false)); 82 | setFixedIfChildSmall(a.getBoolean(R.styleable.AutoHideHeaderLayout_fixedIfChildSmall, true)); 83 | } finally { 84 | a.recycle(); 85 | } 86 | } 87 | } 88 | 89 | private void createBody(Context context) { 90 | _bodyLayout = new BodyLayout(context); 91 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 92 | _bodyLayout.setLayoutParams(params); 93 | addView(_bodyLayout); 94 | } 95 | 96 | 97 | /** 98 | * Set the header view. The view should have a fixed height. 99 | * 100 | * @param header The {@link View} representing the header 101 | */ 102 | public void setHeader(View header) { 103 | if (_headerLayout != null) { 104 | removeView(_headerLayout); 105 | } 106 | _headerLayout = header; 107 | if (header != null) { 108 | header.setId(R.id.header); 109 | _headerLayout.setY(getY()); 110 | addView(header, 0); 111 | _bodyLayout.setY(_headerLayout.getY() + _headerLayout.getHeight()); 112 | requestLayout(); 113 | } 114 | } 115 | 116 | /** 117 | * Set the header view. The view should have a fixed height. 118 | * 119 | * @param id The id of the layout representing the Header 120 | */ 121 | public void setHeader(int id) { 122 | View header = LayoutInflater.from(getContext()).inflate(id, this, false); 123 | setHeader(header); 124 | } 125 | 126 | /** 127 | * Set the Body which will be under the Header 128 | * 129 | * @param bodyView The {@link View} representing the body 130 | */ 131 | public void setBodyView(View bodyView) { 132 | _bodyLayout.setInnerView(bodyView); 133 | requestLayout(); 134 | } 135 | 136 | public void setFixed(boolean fixed) { 137 | _fixed = fixed; 138 | } 139 | 140 | public void setFixedIfChildSmall(boolean fixedIfChildSmall) { 141 | _fixedIfChildSmall = fixedIfChildSmall; 142 | } 143 | 144 | @Override public void addView(View child) { 145 | if (getChildCount() <= 2) { 146 | super.addView(child); 147 | } 148 | } 149 | 150 | @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { 151 | super.onLayout(changed, l, t, r, b); 152 | 153 | for (int i = 0; i < getChildCount(); i++) { 154 | View child = getChildAt(i); 155 | if (!(child instanceof BodyLayout)) { 156 | if (_headerLayout == null) { 157 | removeView(child); 158 | setHeader(child); 159 | } else if (!_bodyLayout.hasInnerView()) { 160 | removeView(child); 161 | setBodyView(child); 162 | } else if (i > 1) { 163 | removeViewAt(i); 164 | } 165 | } 166 | } 167 | 168 | if (isInEditMode()) return; 169 | _bodyLayout.setY(_headerLayout.getY() + _headerLayout.getHeight()); 170 | } 171 | 172 | /** 173 | * The body handling the touch events 174 | */ 175 | class BodyLayout extends FrameLayout { 176 | 177 | 178 | float movedDistance; 179 | private View _innerView; 180 | private float _origY; 181 | private float _origHeaderY; 182 | private float _origBodyY; 183 | 184 | public BodyLayout(Context context) { 185 | super(context); 186 | } 187 | 188 | 189 | @Override public boolean dispatchTouchEvent(MotionEvent event) { 190 | 191 | if (!_fixed && (_fixedIfChildSmall && _innerView.getHeight() > getHeight() - _headerLayout.getHeight() || !_fixedIfChildSmall)) { 192 | movedDistance = event.getRawY() - _origY; 193 | switch (event.getAction()) { 194 | case MotionEvent.ACTION_DOWN: 195 | _origY = event.getRawY(); 196 | _origBodyY = getY(); 197 | _origHeaderY = _headerLayout.getY(); 198 | break; 199 | case MotionEvent.ACTION_MOVE: 200 | Log.d("MovedDistance", "State : " + _state.name() + " Distance : " + movedDistance); 201 | 202 | if (_state == HeaderState.OPENING || _state == HeaderState.HIDDEN && movedDistance > 1 || _state == HeaderState.OPENED && movedDistance < -1) { 203 | 204 | 205 | if (_state != HeaderState.OPENED && _headerLayout.getY() + _headerLayout.getHeight() >= AutoHideHeaderLayout.this.getY() + _headerLayout.getHeight()) { 206 | 207 | // The header is OPENED, we reset the event as it was a down event and pass it to the child view 208 | _state = HeaderState.OPENED; 209 | Log.d("State", _state.name()); 210 | event.setAction(MotionEvent.ACTION_DOWN); 211 | _origY = event.getRawY(); 212 | _origBodyY = getY(); 213 | _origHeaderY = _headerLayout.getY(); 214 | return super.dispatchTouchEvent(event); 215 | 216 | } else if (_state != HeaderState.HIDDEN && _headerLayout.getY() + _headerLayout.getHeight() <= AutoHideHeaderLayout.this.getY()) { 217 | 218 | // The header is HIDDEN, we reset the event as it was a down event and pass it to the child view 219 | _state = HeaderState.HIDDEN; 220 | Log.d("State", _state.name()); 221 | event.setAction(MotionEvent.ACTION_DOWN); 222 | _origY = event.getRawY(); 223 | _origBodyY = getY(); 224 | _origHeaderY = _headerLayout.getY(); 225 | return super.dispatchTouchEvent(event); 226 | 227 | } else { 228 | 229 | // We follow the touch gestur 230 | _state = HeaderState.OPENING; 231 | Log.d("State", _state.name()); 232 | 233 | 234 | if (_origHeaderY + movedDistance > AutoHideHeaderLayout.this.getY()) { 235 | // if the movement if greater than the place where the views should be, 236 | // (the top of the parent view) we block it to the desired position 237 | 238 | Log.d("State", "1"); 239 | _headerLayout.setY(AutoHideHeaderLayout.this.getY()); 240 | setY(AutoHideHeaderLayout.this.getY() + _headerLayout.getHeight()); 241 | 242 | } else if (_origHeaderY + movedDistance < AutoHideHeaderLayout.this.getY() - _headerLayout.getHeight()) { 243 | // if the movement if greater than the place where the views should be, 244 | // (the top of the parent view) we block it to the desired position, 245 | // with the header hidden on top of the body 246 | Log.d("State", "2"); 247 | _headerLayout.setY(AutoHideHeaderLayout.this.getY() - _headerLayout.getHeight()); 248 | setY(AutoHideHeaderLayout.this.getY()); 249 | 250 | } else { 251 | 252 | // Just move the body and header as much as the touch gesture 253 | Log.d("State", "3"); 254 | setY(_origBodyY + movedDistance); 255 | _headerLayout.setY(_origHeaderY + movedDistance); 256 | } 257 | } 258 | } 259 | case MotionEvent.ACTION_UP: 260 | case MotionEvent.ACTION_CANCEL: 261 | // Handle the fling gesture 262 | long time = event.getEventTime() - event.getDownTime(); 263 | if (time < MIN_EVENT_TIME) { 264 | if (Math.abs(movedDistance) < _headerLayout.getHeight()) { 265 | if (movedDistance > 0) { 266 | _headerLayout.animate().y(AutoHideHeaderLayout.this.getY()).setDuration(ANIMATION_DURATION).start(); 267 | _bodyLayout.animate().y(AutoHideHeaderLayout.this.getY() + _headerLayout.getHeight()).setDuration(ANIMATION_DURATION).start(); 268 | } else if (movedDistance < 0) { 269 | _headerLayout.animate().y(AutoHideHeaderLayout.this.getY() - _headerLayout.getHeight()).setDuration(ANIMATION_DURATION).start(); 270 | _bodyLayout.animate().y(AutoHideHeaderLayout.this.getY()).setDuration(ANIMATION_DURATION).start(); 271 | } 272 | } 273 | 274 | } 275 | 276 | } 277 | } 278 | return super.dispatchTouchEvent(event); 279 | } 280 | 281 | 282 | public void setInnerView(View innerView) { 283 | if (_innerView != null) { 284 | removeView(_innerView); 285 | } 286 | _innerView = innerView; 287 | if (innerView != null) { 288 | addView(innerView); 289 | 290 | } 291 | } 292 | 293 | public boolean hasInnerView() { 294 | return _innerView != null; 295 | } 296 | } 297 | 298 | public static class LayoutParams extends RelativeLayout.LayoutParams { 299 | 300 | public LayoutParams(Context c, AttributeSet attrs) { 301 | super(c, attrs); 302 | } 303 | 304 | public LayoutParams(int w, int h) { 305 | super(w, h); 306 | } 307 | 308 | public LayoutParams(ViewGroup.LayoutParams source) { 309 | super(source); 310 | } 311 | 312 | public LayoutParams(MarginLayoutParams source) { 313 | super(source); 314 | } 315 | 316 | public LayoutParams(RelativeLayout.LayoutParams source) { 317 | super(source); 318 | } 319 | } 320 | 321 | } 322 | -------------------------------------------------------------------------------- /androidautohideheader/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /androidautohideheader/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /androidautohideheader/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidAutoHideHeader 3 | 4 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "fr.vadimcaen.mytestapplication" 9 | minSdkVersion 22 10 | targetSdkVersion 22 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 | compile 'com.android.support:appcompat-v7:22.2.0' 25 | compile 'com.android.support:cardview-v7:22.2.0' 26 | compile project(':androidautohideheader') 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/vcaen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/vcaen/mytestapplication/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.vcaen.mytestapplication; 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 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/vcaen/mytestapplication/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.vcaen.mytestapplication; 2 | 3 | import android.support.v7.app.ActionBarActivity; 4 | import android.os.Bundle; 5 | import android.view.Menu; 6 | import android.view.MenuItem; 7 | import android.view.ViewGroup; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.ListView; 10 | 11 | import com.vcaen.androidautohideheader.AutoHideHeaderLayout; 12 | 13 | 14 | public class MainActivity extends ActionBarActivity { 15 | 16 | String[] mockValues = new String[4]; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | 21 | for (int i = 0; i < mockValues.length; i++) { 22 | mockValues[i] = "Mock Value " + i; 23 | } 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_main); 26 | 27 | AutoHideHeaderLayout view = (AutoHideHeaderLayout) findViewById(R.id.autohideview); 28 | ListView listView = new ListView(this); 29 | listView.setLayoutParams(new AutoHideHeaderLayout.LayoutParams(AutoHideHeaderLayout.LayoutParams.MATCH_PARENT, AutoHideHeaderLayout.LayoutParams.WRAP_CONTENT)); 30 | listView.setAdapter(new ArrayAdapter<>(this, R.layout.list_item, R.id.info_text, mockValues)); 31 | listView.setDividerHeight(10); 32 | view.setHeader(R.layout.header); 33 | view.setBodyView(listView); 34 | 35 | 36 | } 37 | 38 | 39 | 40 | @Override 41 | public boolean onCreateOptionsMenu(Menu menu) { 42 | // Inflate the menu; this adds items to the action bar if it is present. 43 | getMenuInflater().inflate(R.menu.menu_main, menu); 44 | return true; 45 | } 46 | 47 | @Override 48 | public boolean onOptionsItemSelected(MenuItem item) { 49 | // Handle action bar item clicks here. The action bar will 50 | // automatically handle clicks on the Home/Up button, so long 51 | // as you specify a parent activity in AndroidManifest.xml. 52 | int id = item.getItemId(); 53 | 54 | //noinspection SimplifiableIfStatement 55 | if (id == R.id.action_settings) { 56 | return true; 57 | } 58 | 59 | return super.onOptionsItemSelected(item); 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/ac3b00132146d14c7eead0b0a3ba611c7e5b6aa8/app/src/main/res/drawable/bg.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/header.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/ac3b00132146d14c7eead0b0a3ba611c7e5b6aa8/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/ac3b00132146d14c7eead0b0a3ba611c7e5b6aa8/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/ac3b00132146d14c7eead0b0a3ba611c7e5b6aa8/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/ac3b00132146d14c7eead0b0a3ba611c7e5b6aa8/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MyTestApplication 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.2.3' 9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' 10 | classpath 'com.github.dcendents:android-maven-plugin:1.2' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/ac3b00132146d14c7eead0b0a3ba611c7e5b6aa8/example.gif -------------------------------------------------------------------------------- /example_screencast.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/ac3b00132146d14c7eead0b0a3ba611c7e5b6aa8/example_screencast.mp4 -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/ac3b00132146d14c7eead0b0a3ba611c7e5b6aa8/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcaen/AndroidAutoHideHeader/ac3b00132146d14c7eead0b0a3ba611c7e5b6aa8/gradlew -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':androidautohideheader' 2 | 3 | --------------------------------------------------------------------------------