|
|
@@ -6,6 +6,7 @@ import android.support.annotation.Nullable;
|
|
|
import android.support.v4.view.PagerAdapter;
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
import android.util.AttributeSet;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
@@ -14,6 +15,7 @@ import android.widget.RelativeLayout;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
|
|
|
|
@@ -27,6 +29,7 @@ public class CarouselView extends RelativeLayout {
|
|
|
private CarouselAdapter mAdapter;
|
|
|
private int mCurrentItem = 1;
|
|
|
private int mItemCount;
|
|
|
+ private HashMap<Integer, Object> mPositionViewMap = new HashMap<>();
|
|
|
|
|
|
public CarouselView(Context context) {
|
|
|
super(context);
|
|
|
@@ -62,7 +65,7 @@ public class CarouselView extends RelativeLayout {
|
|
|
@Override
|
|
|
public void onPageSelected(int position) {
|
|
|
|
|
|
-// Log.d("Selected", "onPageSelected: " + position);
|
|
|
+ Log.d("Carousel", "onPageSelected: " + position);
|
|
|
mCurrentItem = position;
|
|
|
int display_index = mCurrentItem;
|
|
|
if (position == 0) {
|
|
|
@@ -74,7 +77,8 @@ public class CarouselView extends RelativeLayout {
|
|
|
|
|
|
// 代理方法在此调用避免两端点的索引重复出现
|
|
|
if (mDelegate != null) {
|
|
|
- mDelegate.carouselDidShowItem(self,display_index - 1);
|
|
|
+ View cell = (View) mPositionViewMap.get(position);
|
|
|
+ mDelegate.carouselDidShowItem(self,cell,display_index - 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -84,6 +88,7 @@ public class CarouselView extends RelativeLayout {
|
|
|
@Override
|
|
|
public void onPageScrollStateChanged(int state) {
|
|
|
|
|
|
+ Log.d("Carousel", "onPageScrollStateChanged: " + mCurrentItem);
|
|
|
// 解决两端切换时闪屏
|
|
|
if (state == ViewPager.SCROLL_STATE_IDLE) {
|
|
|
if (mCurrentItem == mPager.getAdapter().getCount() - 1) {
|
|
|
@@ -123,7 +128,7 @@ public class CarouselView extends RelativeLayout {
|
|
|
public interface CarouselDelegate {
|
|
|
|
|
|
void carouselWillShowItem(CarouselView carousel, View cell, int index);
|
|
|
- void carouselDidShowItem(CarouselView carousel, int index);
|
|
|
+ void carouselDidShowItem(CarouselView carousel, View cell, int index);
|
|
|
void carouselWillEndDisplayItem(CarouselView carousel, View cell, int index);
|
|
|
int carouselNumberOfItems(CarouselView carousel);
|
|
|
|
|
|
@@ -164,6 +169,8 @@ public class CarouselView extends RelativeLayout {
|
|
|
@Override
|
|
|
public void destroyItem(ViewGroup container, int position, Object object) {
|
|
|
|
|
|
+ Log.d("Carousel", "destroyItem: " + position + " " + object);
|
|
|
+
|
|
|
View cell = (View) object;
|
|
|
|
|
|
int index = position;
|
|
|
@@ -181,6 +188,8 @@ public class CarouselView extends RelativeLayout {
|
|
|
|
|
|
container.removeView(cell);
|
|
|
mReusePool.add(cell);
|
|
|
+
|
|
|
+ mPositionViewMap.remove(position);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -206,6 +215,7 @@ public class CarouselView extends RelativeLayout {
|
|
|
index = position - 1;
|
|
|
}
|
|
|
|
|
|
+ Log.d("Carousel", "instantiateItem: " + position + " " + cell);
|
|
|
|
|
|
if (mDelegate!= null) {
|
|
|
mDelegate.carouselWillShowItem(self,cell,index);
|
|
|
@@ -213,6 +223,8 @@ public class CarouselView extends RelativeLayout {
|
|
|
|
|
|
container.addView(cell);
|
|
|
|
|
|
+ mPositionViewMap.put(position, cell);
|
|
|
+
|
|
|
return cell;
|
|
|
}
|
|
|
}
|