CarouselViewProject
CarouselViewProject copied to clipboard
issues regarding blur and highlight code onPageScrolled ?
@clkasd pls look into this issue i just change your code to SmartFragmentStatePagerAdapter and then write as it is code of all your adapter class in my class but this is strange now my blur and highlight effects are not working in onPageScroll while onPageScroll listener is getting called but its not producing desired result . how to resolve ?
here is th code :
package com.example.carouselViewProject;
import java.util.ArrayList;
import android.content.Context; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.util.Log; import android.widget.Toast;
import com.nineoldandroids.view.ViewHelper;
public class BottomViewPagerAdapter extends SmartFragmentStatePagerAdapter{ ArrayList<Groups> invitationArrayList; public static final String TAG = "BottomViewPagerAdapter"; private float scale; private boolean IsBlured = false; private static float minAlpha=0.6f; private static float maxAlpha=1f; private static float minDegree=70.0f; private int lastPage; private MyLinearLayout cur = null; private MyLinearLayout next = null; private MyLinearLayout prev = null; private MyLinearLayout prevprev = null; private MyLinearLayout nextnext = null; private boolean swipedLeft=false; FragmentManager fm; Context context; //public OnPageChangeListener onPageChangeListener; public static float getMinDegree() { return minDegree; } public static float getMinAlpha() { return minAlpha; } public static float getMaxAlpha() { return maxAlpha; } public BottomViewPagerAdapter(Context context,FragmentManager fm,ArrayList<Groups> invitationArrayList,boolean drawCenterText) { super(fm); this.fm = fm; this.context = context; // TODO Auto-generated constructor stub this.invitationArrayList = invitationArrayList; }
@Override
public Fragment getItem(int position) {
// TODO Auto-generated method stub
Log.d(TAG,"getItem called");
/*if(arg0 == 0)
{
return FragmentMap0Position.newInstance(arg0);
}
else
{
return FragmentMapPosition.newInstance(arg0);
}*/
if (position == MainActivity.FIRST_PAGE)
scale = MainActivity.BIG_SCALE;
else
{
scale = MainActivity.SMALL_SCALE;
IsBlured=true;
}
cur = getRootView(position);
next = getRootView(position +1);
prev = getRootView(position -1);
return MyFragment.newInstance(position,scale,IsBlured);
//return null;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
lastPage = invitationArrayList.size()-1;
return invitationArrayList.size();
}
OnPageChangeListener onPageChangeListener = new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// TODO Auto-generated method stub
if(lastPage<=position)
{
swipedLeft=true;
}
else if(lastPage>position)
{
swipedLeft=false;
}
lastPage=position;
Toast.makeText(context,"bottom view pager adapter position:"+position,1000).show();
//currentPagePosition = position;
}
@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
// TODO Auto-generated method stub
Log.d(TAG, "onPageScrolled");
//super();
if (positionOffset >= 0f && positionOffset <= 1f)
{
Log.d(TAG, "positionOffset >= 0f && positionOffset <= 1f");
positionOffset=positionOffset*positionOffset;
cur = getRootView(position);
next = getRootView(position +1);
prev = getRootView(position -1);
nextnext=getRootView(position +2);
ViewHelper.setAlpha(cur, maxAlpha-0.5f*positionOffset);
ViewHelper.setAlpha(next, minAlpha+0.5f*positionOffset);
ViewHelper.setAlpha(prev, minAlpha+0.5f*positionOffset);
if(nextnext!=null)
{
//ViewHelper.setAlpha(nextnext, minAlpha);
// ViewHelper.setRotationY(nextnext, -minDegree);
}
if(cur!=null)
{
/* cur.setScaleBoth(MainActivity.BIG_SCALE
- MainActivity.DIFF_SCALE * positionOffset);
ViewHelper.setRotationY(cur, 0);*/
}
if(next!=null)
{
/*next.setScaleBoth(MainActivity.SMALL_SCALE
+ MainActivity.DIFF_SCALE * positionOffset);
ViewHelper.setRotationY(next, -minDegree);*/
}
if(prev!=null)
{
//ViewHelper.setRotationY(prev, minDegree);
}
/*To animate it properly we must understand swipe direction
* this code adjusts the rotation according to direction.
*/
if(swipedLeft)
{
if(next!=null)
//ViewHelper.setRotationY(next, -minDegree+minDegree*positionOffset);
{
}
if(cur!=null)
//ViewHelper.setRotationY(cur, 0+minDegree*positionOffset);
{
}
}
else
{
if(next!=null)
//ViewHelper.setRotationY(next, -minDegree+minDegree*positionOffset);
if(cur!=null)
{
//ViewHelper.setRotationY(cur, 0+minDegree*positionOffset);
}
}
}
if(positionOffset>=1f)
{
Log.d(TAG, "positionOffset >= 1f");
ViewHelper.setAlpha(cur, maxAlpha);
}
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
};
private MyLinearLayout getRootView(int position)
{
MyLinearLayout ly;
try {
ly = (MyLinearLayout)
fm.findFragmentByTag(getFragmentTag(position))
.getView().findViewById(R.id.root);
} catch (Exception e) {
// TODO Auto-generated catch block
return null;
}
if(ly!=null)
return ly;
return null;
}
private String getFragmentTag(int position)
{
return "android:switcher:" + MainActivity.pager.getId() + ":" + position;
}
}