-
Notifications
You must be signed in to change notification settings - Fork 0
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
11 changed files
with
426 additions
and
49 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...src/main/java/com/depromeet/hanriver/hanrivermeetup/fragment/meeting/map/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,14 @@ | ||
package com.depromeet.hanriver.hanrivermeetup.fragment.meeting.map; | ||
|
||
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
...rc/main/java/com/depromeet/hanriver/hanrivermeetup/fragment/meeting/map/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.depromeet.hanriver.hanrivermeetup.fragment.meeting.map; | ||
|
||
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; | ||
|
||
import com.depromeet.hanriver.hanrivermeetup.R; | ||
|
||
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.tour_event_info_card, container, false); | ||
mCardView = 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
.../com/depromeet/hanriver/hanrivermeetup/fragment/meeting/map/CardFragmentPagerAdapter.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.depromeet.hanriver.hanrivermeetup.fragment.meeting.map; | ||
|
||
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 CardFragmentPagerAdapter extends FragmentStatePagerAdapter implements CardAdapter { | ||
|
||
private List<CardFragment> mFragments; | ||
private float mBaseElevation; | ||
|
||
public CardFragmentPagerAdapter(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); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/depromeet/hanriver/hanrivermeetup/fragment/meeting/map/CardItem.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,19 @@ | ||
package com.depromeet.hanriver.hanrivermeetup.fragment.meeting.map; | ||
|
||
public class CardItem { | ||
private String mTextResource; | ||
private String mTitleResource; | ||
|
||
public CardItem(String title, String text) { | ||
mTitleResource = title; | ||
mTextResource = text; | ||
} | ||
|
||
public String getText() { | ||
return mTextResource; | ||
} | ||
|
||
public String getTitle() { | ||
return mTitleResource; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...ain/java/com/depromeet/hanriver/hanrivermeetup/fragment/meeting/map/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,80 @@ | ||
package com.depromeet.hanriver.hanrivermeetup.fragment.meeting.map; | ||
|
||
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 android.widget.TextView; | ||
|
||
import com.depromeet.hanriver.hanrivermeetup.R; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CardPagerAdapter extends PagerAdapter implements CardAdapter { | ||
|
||
private List<CardView> mViews; | ||
private List<CardItem> mData; | ||
private float mBaseElevation; | ||
|
||
public CardPagerAdapter() { | ||
mData = new ArrayList<>(); | ||
mViews = new ArrayList<>(); | ||
} | ||
|
||
public void addCardItem(CardItem item) { | ||
mViews.add(null); | ||
mData.add(item); | ||
} | ||
|
||
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.tour_event_info_card, container, false); | ||
container.addView(view); | ||
bind(mData.get(position), view); | ||
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); | ||
} | ||
|
||
private void bind(CardItem item, View view) { | ||
TextView titleTextView = view.findViewById(R.id.title); | ||
TextView addressTextView = view.findViewById(R.id.address); | ||
titleTextView.setText(item.getTitle()); | ||
addressTextView.setText(item.getText()); | ||
} | ||
|
||
} |
108 changes: 108 additions & 0 deletions
108
...in/java/com/depromeet/hanriver/hanrivermeetup/fragment/meeting/map/ShadowTransformer.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,108 @@ | ||
package com.depromeet.hanriver.hanrivermeetup.fragment.meeting.map; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.widget.CardView; | ||
import android.view.View; | ||
|
||
public class ShadowTransformer implements ViewPager.OnPageChangeListener, ViewPager.PageTransformer { | ||
|
||
private ViewPager mViewPager; | ||
private CardAdapter mAdapter; | ||
private float mLastOffset; | ||
private boolean mScalingEnabled; | ||
|
||
public ShadowTransformer(ViewPager viewPager, CardAdapter adapter) { | ||
mViewPager = viewPager; | ||
viewPager.addOnPageChangeListener(this); | ||
mAdapter = adapter; | ||
} | ||
|
||
public void enableScaling(boolean enable) { | ||
if (mScalingEnabled && !enable) { | ||
// shrink main card | ||
CardView currentCard = mAdapter.getCardViewAt(mViewPager.getCurrentItem()); | ||
if (currentCard != null) { | ||
currentCard.animate().scaleY(1); | ||
currentCard.animate().scaleX(1); | ||
} | ||
}else if(!mScalingEnabled && enable){ | ||
// grow main card | ||
CardView currentCard = mAdapter.getCardViewAt(mViewPager.getCurrentItem()); | ||
if (currentCard != null) { | ||
currentCard.animate().scaleY(1.1f); | ||
currentCard.animate().scaleX(1.1f); | ||
} | ||
} | ||
|
||
mScalingEnabled = enable; | ||
} | ||
|
||
@Override | ||
public void transformPage(View page, float position) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | ||
int realCurrentPosition; | ||
int nextPosition; | ||
float baseElevation = mAdapter.getBaseElevation(); | ||
float realOffset; | ||
boolean goingLeft = mLastOffset > positionOffset; | ||
|
||
// If we're going backwards, onPageScrolled receives the last position | ||
// instead of the current one | ||
if (goingLeft) { | ||
realCurrentPosition = position + 1; | ||
nextPosition = position; | ||
realOffset = 1 - positionOffset; | ||
} else { | ||
nextPosition = position + 1; | ||
realCurrentPosition = position; | ||
realOffset = positionOffset; | ||
} | ||
|
||
// Avoid crash on overscroll | ||
if (nextPosition > mAdapter.getCount() - 1 | ||
|| realCurrentPosition > mAdapter.getCount() - 1) { | ||
return; | ||
} | ||
|
||
CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition); | ||
|
||
// This might be null if a fragment is being used | ||
// and the views weren't created yet | ||
if (currentCard != null) { | ||
if (mScalingEnabled) { | ||
currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset))); | ||
currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset))); | ||
} | ||
currentCard.setCardElevation((baseElevation + baseElevation | ||
* (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset))); | ||
} | ||
|
||
CardView nextCard = mAdapter.getCardViewAt(nextPosition); | ||
|
||
// We might be scrolling fast enough so that the next (or previous) card | ||
// was already destroyed or a fragment might not have been created yet | ||
if (nextCard != null) { | ||
if (mScalingEnabled) { | ||
nextCard.setScaleX((float) (1 + 0.1 * (realOffset))); | ||
nextCard.setScaleY((float) (1 + 0.1 * (realOffset))); | ||
} | ||
nextCard.setCardElevation((baseElevation + baseElevation | ||
* (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset))); | ||
} | ||
|
||
mLastOffset = positionOffset; | ||
} | ||
|
||
@Override | ||
public void onPageSelected(int position) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPageScrollStateChanged(int state) { | ||
|
||
} | ||
} |
Oops, something went wrong.