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
Pedro Oliveira
committed
Feb 26, 2015
1 parent
8912cf7
commit 045e4db
Showing
31 changed files
with
637 additions
and
31 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
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,24 +1,19 @@ | ||
apply plugin: 'com.android.library' | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
android { | ||
compileSdkVersion 21 | ||
buildToolsVersion "21.1.1" | ||
|
||
defaultConfig { | ||
minSdkVersion 7 | ||
targetSdkVersion 21 | ||
versionCode 2 | ||
versionName "1.1" | ||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:1.1.0' | ||
classpath 'com.github.dcendents:android-maven-plugin:1.2' | ||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile 'com.android.support:recyclerview-v7:21.0.0' | ||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} |
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 @@ | ||
/build |
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,26 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 21 | ||
buildToolsVersion "21.1.2" | ||
|
||
defaultConfig { | ||
applicationId "com.poliveira.apps.parallaxrecycleradapter" | ||
minSdkVersion 7 | ||
targetSdkVersion 21 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile project (':library') | ||
compile 'com.android.support:cardview-v7:21.0.3' | ||
} |
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
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 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.poliveira.apps.parallaxrecycleradapter"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:icon="@mipmap/ic_launcher" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
140 changes: 140 additions & 0 deletions
140
example/src/main/java/com/poliveira/apps/parallaxrecycleradapter/MainActivity.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,140 @@ | ||
package com.poliveira.apps.parallaxrecycleradapter; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.poliveira.parallaxrecycleradapter.HeaderLayoutManagerFixed; | ||
import com.poliveira.parallaxrecycleradapter.ParallaxRecyclerAdapter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by poliveira on 26/02/2015. | ||
*/ | ||
public class MainActivity extends Activity { | ||
|
||
private boolean isNormalAdapter = false; | ||
private RecyclerView mRecyclerView; | ||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
mRecyclerView = (RecyclerView) findViewById(R.id.recycler); | ||
createAdapter(mRecyclerView); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
if (isNormalAdapter) { | ||
createCardAdapter(mRecyclerView); | ||
} else { | ||
createAdapter(mRecyclerView); | ||
} | ||
isNormalAdapter = !isNormalAdapter; | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.main, menu); | ||
return super.onCreateOptionsMenu(menu); | ||
} | ||
|
||
private void createCardAdapter(RecyclerView recyclerView) { | ||
final List<String> content = new ArrayList<>(); | ||
for (int i = 0; i < 50; i++) { | ||
content.add("item " + i); | ||
} | ||
final ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<>(content); | ||
HeaderLayoutManagerFixed layoutManagerFixed = new HeaderLayoutManagerFixed(this); | ||
recyclerView.setLayoutManager(layoutManagerFixed); | ||
View header = getLayoutInflater().inflate(R.layout.header, recyclerView, false); | ||
layoutManagerFixed.setHeaderIncrementFixer(header); | ||
adapter.setShouldClipView(false); | ||
adapter.setParallaxHeader(header, recyclerView); | ||
adapter.setData(content); | ||
adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() { | ||
@Override | ||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) { | ||
((ViewHolder) viewHolder).textView.setText(adapter.getData().get(i)); | ||
} | ||
|
||
@Override | ||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | ||
final ViewHolder holder = new ViewHolder(getLayoutInflater().inflate(R.layout.row_recyclerview_cards, viewGroup, false)); | ||
//don't set listeners on onBindViewHolder. For more info check http://androidshenanigans.blogspot.pt/2015/02/viewholder-pattern-common-mistakes.html | ||
holder.textView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Toast.makeText(MainActivity.this, "You clicked '" + adapter.getData().get(holder.getPosition() - (adapter.hasHeader() ? 1 : 0)) + "'", Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
return holder; | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return content.size(); | ||
} | ||
}); | ||
recyclerView.setAdapter(adapter); | ||
} | ||
|
||
private void createAdapter(RecyclerView recyclerView) { | ||
final List<String> content = new ArrayList<>(); | ||
for (int i = 0; i < 50; i++) { | ||
content.add("item " + i); | ||
} | ||
final ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<>(content); | ||
recyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
View header = getLayoutInflater().inflate(R.layout.header, recyclerView, false); | ||
adapter.setParallaxHeader(header, recyclerView); | ||
adapter.setData(content); | ||
adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() { | ||
@Override | ||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) { | ||
((ViewHolder) viewHolder).textView.setText(adapter.getData().get(i)); | ||
} | ||
|
||
@Override | ||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | ||
final ViewHolder holder = new ViewHolder(getLayoutInflater().inflate(R.layout.row_recyclerview, viewGroup, false)); | ||
//don't set listeners on onBindViewHolder. For more info check http://androidshenanigans.blogspot.pt/2015/02/viewholder-pattern-common-mistakes.html | ||
holder.textView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Toast.makeText(MainActivity.this, "You clicked '" + adapter.getData().get(holder.getPosition() - (adapter.hasHeader() ? 1 : 0)) + "'", Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
return holder; | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return content.size(); | ||
} | ||
}); | ||
recyclerView.setAdapter(adapter); | ||
} | ||
|
||
|
||
static class ViewHolder extends RecyclerView.ViewHolder { | ||
public TextView textView; | ||
|
||
public ViewHolder(View itemView) { | ||
super(itemView); | ||
textView = (TextView) itemView.findViewById(R.id.textView); | ||
} | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<view | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
class="android.support.v7.widget.RecyclerView" | ||
android:id="@+id/recycler" | ||
android:layout_gravity="left|top"/> | ||
</FrameLayout> |
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<ImageView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/imageView" | ||
android:src="@drawable/wallpaper" | ||
android:adjustViewBounds="true"/> | ||
</LinearLayout> |
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/textView" | ||
android:layout_gravity="center_horizontal" | ||
android:gravity="center"/> | ||
</LinearLayout> |
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,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="250dp"> | ||
|
||
<android.support.v7.widget.CardView | ||
xmlns:card_view="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/card" | ||
card_view:cardCornerRadius="4dp" | ||
android:layout_margin="15dp" | ||
card_view:cardBackgroundColor="#ffb7f0ff"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/textView" | ||
android:layout_gravity="center" | ||
android:gravity="center"/> | ||
</android.support.v7.widget.CardView> | ||
|
||
|
||
</FrameLayout> |
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:title="Change Adapter"/> | ||
</menu> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="AppTheme" parent="android:Theme.Material.Light"> | ||
</style> | ||
</resources> |
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 @@ | ||
<resources> | ||
<string name="app_name">ParallaxRecyclerAdapter</string> | ||
</resources> |
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,8 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
</style> | ||
|
||
</resources> |
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 @@ | ||
# Project-wide Gradle settings. | ||
|
||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
|
||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
|
||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
# Default value: -Xmx10248m -XX:MaxPermSize=256m | ||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 | ||
|
||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true |
Binary file not shown.
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 @@ | ||
#Wed Apr 10 15:27:10 PDT 2013 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip |
Oops, something went wrong.