-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.gradle | ||
.idea | ||
build/ | ||
*.iml | ||
|
||
# Ignore Gradle GUI config | ||
gradle-app.setting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:0.12.+' | ||
} | ||
} | ||
def isReleaseBuild() { | ||
return version.contains("SNAPSHOT") == false | ||
} | ||
allprojects { | ||
version = VERSION_NAME | ||
group = GROUP | ||
repositories { | ||
mavenCentral() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
VERSION_NAME=0.1.0 | ||
GROUP=com.eowise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Mon Sep 22 01:04:39 CEST 2014 | ||
#Mon Sep 22 01:26:00 CEST 2014 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip | ||
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build/ | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
dependencies { | ||
compile 'com.android.support:recyclerview-v7:+' | ||
} | ||
|
||
android { | ||
compileSdkVersion 'android-L' | ||
buildToolsVersion '20.0.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.eowise.recyclerview.stickyheaders"> | ||
|
||
</manifest> |
12 changes: 12 additions & 0 deletions
12
library/src/main/java/com/eowise/recyclerview/stickyheaders/StickyHeadersAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.eowise.recyclerview.stickyheaders; | ||
|
||
import android.view.ViewGroup; | ||
|
||
public interface StickyHeadersAdapter<ItemViewHolder extends android.support.v7.widget.RecyclerView.ViewHolder, HeaderViewHolder extends android.support.v7.widget.RecyclerView.ViewHolder> { | ||
|
||
HeaderViewHolder onCreateViewHolder(ViewGroup parent); | ||
|
||
void onBindViewHolder(HeaderViewHolder headerViewHolder, ItemViewHolder itemViewHolder, int position); | ||
|
||
long getHeaderId(ItemViewHolder viewHolder, int position); | ||
} |
62 changes: 62 additions & 0 deletions
62
library/src/main/java/com/eowise/recyclerview/stickyheaders/StickyHeadersItemDecoration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.eowise.recyclerview.stickyheaders; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Rect; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
/** | ||
* Created by aurel on 22/09/14. | ||
*/ | ||
public class StickyHeadersItemDecoration extends RecyclerView.ItemDecoration { | ||
|
||
private final StickyHeadersAdapter adapter; | ||
private final RecyclerView.ViewHolder headerViewHolder; | ||
|
||
private final int itemHeight; | ||
|
||
public StickyHeadersItemDecoration(StickyHeadersAdapter adapter, RecyclerView parent) { | ||
this.adapter = adapter; | ||
this.headerViewHolder = adapter.onCreateViewHolder(parent); | ||
|
||
int widthSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.MATCH_PARENT, View.MeasureSpec.AT_MOST); | ||
int heightSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED); | ||
headerViewHolder.itemView.measure(widthSpec, heightSpec); | ||
itemHeight = headerViewHolder.itemView.getMeasuredHeight(); | ||
} | ||
|
||
@Override | ||
public void onDrawOver(Canvas c, RecyclerView parent) { | ||
final int childCount = parent.getChildCount(); | ||
View header = headerViewHolder.itemView; | ||
|
||
if (!header.isLaidOut()) { | ||
int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); | ||
int heightSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED); | ||
header.measure(widthSpec, heightSpec); | ||
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); | ||
} | ||
|
||
for (int i = 0; i < childCount; i++) { | ||
final View child = parent.getChildAt(i); | ||
float y = child.getY() < itemHeight ? 0 : child.getY() - itemHeight; | ||
y = child.getY() + child.getHeight() < itemHeight ? y - (itemHeight - (child.getY() + child.getHeight())) : y; | ||
final RecyclerView.ViewHolder itemViewHolder = parent.getChildViewHolder(child); | ||
|
||
adapter.onBindViewHolder(headerViewHolder, itemViewHolder, itemViewHolder.getPosition()); | ||
|
||
c.save(); | ||
c.translate(0, y); | ||
header.draw(c); | ||
c.restore(); | ||
} | ||
} | ||
|
||
@Override | ||
public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { | ||
|
||
outRect.set(0, itemHeight, 0, 0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include 'library' |