-
Notifications
You must be signed in to change notification settings - Fork 608
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
0 parents
commit fbd6714
Showing
33 changed files
with
845 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
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,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.1" | ||
|
||
defaultConfig { | ||
applicationId "com.github.rubensousa.viewpagercards" | ||
minSdkVersion 14 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:design:24.2.0' | ||
compile 'com.android.support:appcompat-v7:24.2.0' | ||
compile 'com.android.support:cardview-v7:24.2.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,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /home/ruben/Android/Sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
app/src/androidTest/java/com/github/rubensousa/viewpagercards/ApplicationTest.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,13 @@ | ||
package com.github.rubensousa.viewpagercards; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.github.rubensousa.viewpagercards"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
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> |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/github/rubensousa/viewpagercards/CardAdapter.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,15 @@ | ||
package com.github.rubensousa.viewpagercards; | ||
|
||
|
||
import android.support.v7.widget.CardView; | ||
|
||
public interface CardAdapter { | ||
|
||
int MAX_ELEVATION_FACTOR = 8; | ||
|
||
float getBaseElevation(); | ||
|
||
CardView getCardViewAt(int position); | ||
|
||
int getCount(); | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/github/rubensousa/viewpagercards/CardFragment.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,30 @@ | ||
package com.github.rubensousa.viewpagercards; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.widget.CardView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
|
||
public class CardFragment extends Fragment { | ||
|
||
private CardView mCardView; | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
View view = inflater.inflate(R.layout.adapter, container, false); | ||
mCardView = (CardView) view.findViewById(R.id.cardView); | ||
mCardView.setMaxCardElevation(mCardView.getCardElevation() | ||
* CardAdapter.MAX_ELEVATION_FACTOR); | ||
return view; | ||
} | ||
|
||
public CardView getCardView() { | ||
return mCardView; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/com/github/rubensousa/viewpagercards/CardFragmentAdapter.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,59 @@ | ||
package com.github.rubensousa.viewpagercards; | ||
|
||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentStatePagerAdapter; | ||
import android.support.v7.widget.CardView; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CardFragmentAdapter extends FragmentStatePagerAdapter implements CardAdapter { | ||
|
||
private List<CardFragment> mFragments; | ||
private float mBaseElevation; | ||
|
||
public CardFragmentAdapter(FragmentManager fm, float baseElevation) { | ||
super(fm); | ||
mFragments = new ArrayList<>(); | ||
mBaseElevation = baseElevation; | ||
|
||
for(int i = 0; i< 5; i++){ | ||
addCardFragment(new CardFragment()); | ||
} | ||
} | ||
|
||
@Override | ||
public float getBaseElevation() { | ||
return mBaseElevation; | ||
} | ||
|
||
@Override | ||
public CardView getCardViewAt(int position) { | ||
return mFragments.get(position).getCardView(); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return mFragments.size(); | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
return mFragments.get(position); | ||
} | ||
|
||
@Override | ||
public Object instantiateItem(ViewGroup container, int position) { | ||
Object fragment = super.instantiateItem(container, position); | ||
mFragments.set(position, (CardFragment) fragment); | ||
return fragment; | ||
} | ||
|
||
public void addCardFragment(CardFragment fragment) { | ||
mFragments.add(fragment); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
app/src/main/java/com/github/rubensousa/viewpagercards/CardPagerAdapter.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,70 @@ | ||
package com.github.rubensousa.viewpagercards; | ||
|
||
import android.support.v4.view.PagerAdapter; | ||
import android.support.v7.widget.CardView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CardPagerAdapter extends PagerAdapter implements CardAdapter { | ||
|
||
private List<CardView> mViews; | ||
private List<String> mData; | ||
private float mBaseElevation; | ||
|
||
public CardPagerAdapter() { | ||
|
||
mData = new ArrayList<>(); | ||
mViews = new ArrayList<>(); | ||
|
||
for (int i = 0; i < 5; i++) { | ||
mData.add(""); | ||
mViews.add(null); | ||
} | ||
} | ||
|
||
public float getBaseElevation() { | ||
return mBaseElevation; | ||
} | ||
|
||
@Override | ||
public CardView getCardViewAt(int position) { | ||
return mViews.get(position); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return mData.size(); | ||
} | ||
|
||
@Override | ||
public boolean isViewFromObject(View view, Object object) { | ||
return view == object; | ||
} | ||
|
||
@Override | ||
public Object instantiateItem(ViewGroup container, int position) { | ||
View view = LayoutInflater.from(container.getContext()) | ||
.inflate(R.layout.adapter, container, false); | ||
container.addView(view); | ||
CardView cardView = (CardView) view.findViewById(R.id.cardView); | ||
|
||
if (mBaseElevation == 0) { | ||
mBaseElevation = cardView.getCardElevation(); | ||
} | ||
|
||
cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR); | ||
mViews.set(position, cardView); | ||
return view; | ||
} | ||
|
||
@Override | ||
public void destroyItem(ViewGroup container, int position, Object object) { | ||
container.removeView((View) object); | ||
mViews.set(position, null); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
app/src/main/java/com/github/rubensousa/viewpagercards/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,61 @@ | ||
package com.github.rubensousa.viewpagercards; | ||
|
||
import android.content.Context; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.DisplayMetrics; | ||
import android.view.View; | ||
import android.widget.Button; | ||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
private Button mButton; | ||
private ViewPager mViewPager; | ||
|
||
private CardPagerAdapter mCardAdapter; | ||
private ShadowTransformer mCardShadowTransformer; | ||
private CardFragmentAdapter mFragmentCardAdapter; | ||
private ShadowTransformer mFragmentCardShadowTransformer; | ||
|
||
private boolean mShowingFragments = false; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
mViewPager = (ViewPager) findViewById(R.id.viewPager); | ||
mButton = (Button) findViewById(R.id.cardTypeBtn); | ||
mButton.setOnClickListener(this); | ||
|
||
mCardAdapter = new CardPagerAdapter(); | ||
mFragmentCardAdapter = new CardFragmentAdapter(getSupportFragmentManager(), | ||
dpToPixels(2, this)); | ||
|
||
mCardShadowTransformer = new ShadowTransformer(mViewPager, mCardAdapter); | ||
mFragmentCardShadowTransformer = new ShadowTransformer(mViewPager, mFragmentCardAdapter); | ||
|
||
mViewPager.setAdapter(mCardAdapter); | ||
mViewPager.setPageTransformer(false, mCardShadowTransformer); | ||
mViewPager.setOffscreenPageLimit(2); | ||
} | ||
|
||
@Override | ||
public void onClick(View view) { | ||
if (!mShowingFragments) { | ||
mButton.setText("Views"); | ||
mViewPager.setAdapter(mFragmentCardAdapter); | ||
mViewPager.setPageTransformer(false, mFragmentCardShadowTransformer); | ||
} else { | ||
mButton.setText("Fragments"); | ||
mViewPager.setAdapter(mCardAdapter); | ||
mViewPager.setPageTransformer(false, mCardShadowTransformer); | ||
} | ||
|
||
mShowingFragments = !mShowingFragments; | ||
} | ||
|
||
public static float dpToPixels(int dp, Context context) { | ||
return dp * (context.getResources().getDisplayMetrics().density); | ||
} | ||
} |
Oops, something went wrong.