Skip to content

Commit

Permalink
Merge pull request #12 from lightSky/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
lightSky committed Aug 11, 2015
2 parents 433ae1b + 0aeb786 commit 0ae34a9
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 39 deletions.
3 changes: 1 addition & 2 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "cn.lightsky.customeviewdemo"
minSdkVersion 11
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0"
Expand All @@ -25,6 +25,5 @@ android {
}

dependencies {
// compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package cn.lightsky.infiniteindicator;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;

import cn.light.sky.infiniteindicatordemo.R;
import cn.lightsky.infiniteindicator.indicator.CircleIndicator;
import cn.lightsky.infiniteindicator.slideview.BaseSliderView;
import cn.lightsky.infiniteindicator.slideview.DefaultSliderView;

import java.util.ArrayList;
import java.util.HashMap;

public class DefaultCircleIndicatorActivity extends FragmentActivity implements BaseSliderView.OnSliderClickListener{
private InfiniteIndicatorLayout mCustoemIndicatorLayout;
private ArrayList<PageInfo> viewInfos;
Expand Down Expand Up @@ -61,12 +62,29 @@ private void testCircleIndicator() {
textSliderView
.image(url_maps.get(name))
.setScaleType(BaseSliderView.ScaleType.Fit)
.showImageResForEmpty(R.drawable.ic_launcher)
.setOnSliderClickListener(this);
textSliderView.getBundle()
.putString("extra",name);
.putString("extra", name);
mDefaultIndicator.addSlider(textSliderView);
}
mDefaultIndicator.setIndicatorPosition(InfiniteIndicatorLayout.IndicatorPosition.Center_Bottom);
mDefaultIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Log.i("TAG","onPage Scrolled .......");
}

@Override
public void onPageSelected(int position) {
Log.i("TAG","onPage onPageSelected .......");
}

@Override
public void onPageScrollStateChanged(int state) {
Log.i("TAG","onPage onPageScrollStateChanged .......");
}
});
}

private void testCustomeCircleIndicator() {
Expand All @@ -76,6 +94,7 @@ private void testCustomeCircleIndicator() {
textSliderView
.image(url_maps.get(name))
.setScaleType(BaseSliderView.ScaleType.Fit)
.showImageResForError(R.drawable.ic_launcher)
.setOnSliderClickListener(this);
textSliderView.getBundle()
.putString("extra",name);
Expand Down
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "1.0.1"
version = "1.0.3"

android {
compileSdkVersion 21
buildToolsVersion "20.0.0"

defaultConfig {
resourcePrefix "lightsky"
minSdkVersion 11
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0"
versionCode 4
versionName "1.0.3"
}
buildTypes {
release {
Expand Down
4 changes: 3 additions & 1 deletion library/library.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="cn.lightsky.infiniteindicator" external.system.module.version="1.0.0" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="cn.lightsky.infiniteindicator" external.system.module.version="1.0.3" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -84,7 +84,9 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.animation.Interpolator;
import android.widget.RelativeLayout;

import java.lang.ref.WeakReference;
import java.lang.reflect.Field;

import cn.lightsky.infiniteindicator.indicator.PageIndicator;
Expand All @@ -26,6 +27,7 @@
* Thanks to: https://github.com/Trinea/android-auto-scroll-view-pager
*/
public class InfiniteIndicatorLayout extends RelativeLayout implements RecyclingPagerAdapter.DataChangeListener {
private final ScrollHandler handler;
private PageIndicator mIndicator;
private ViewPager mViewPager;
private Context mContext;
Expand Down Expand Up @@ -73,7 +75,6 @@ public class InfiniteIndicatorLayout extends RelativeLayout implements Recycling
// private boolean isBorderAnimation = true;

public static final int MSG_WHAT = 0;
private Handler handler;
private boolean isAutoScroll = false;
private boolean isStopByTouch = false;
private float touchX = 0f, downX = 0f;
Expand Down Expand Up @@ -114,11 +115,11 @@ else if(indicatorType == 1)
else
LayoutInflater.from(context).inflate(R.layout.layout_anim_line_indicator, this, true);

handler = new ScrollHandler(this);
mViewPager = (ViewPager) findViewById(R.id.view_pager);
mRecyleAdapter = new RecyleAdapter(mContext);
mRecyleAdapter.setDataChangeListener(this);
mViewPager.setAdapter(mRecyleAdapter);
handler = new ScrollHandler();
setViewPagerScroller();

}
Expand Down Expand Up @@ -182,6 +183,11 @@ private void sendScrollMessage(long delayTimeInMills) {
handler.sendEmptyMessageDelayed(MSG_WHAT, delayTimeInMills);
}

private void sendScrollMessage() {
/** remove messages before, keeps one message is running at most **/
sendScrollMessage(interval);
}

/**
* modify duration of ViewPager
*/
Expand Down Expand Up @@ -263,8 +269,6 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
return super.dispatchTouchEvent(ev);
}
}
getParent().requestDisallowInterceptTouchEvent(true);

return super.dispatchTouchEvent(ev);
}

Expand All @@ -274,22 +278,31 @@ public void notifyDataChange() {
mIndicator.notifyDataSetChanged();
}

private class ScrollHandler extends Handler {
public static class ScrollHandler extends Handler{
public WeakReference<InfiniteIndicatorLayout> mLeakActivityRef;

public ScrollHandler(InfiniteIndicatorLayout infiniteIndicatorLayout) {
mLeakActivityRef = new WeakReference<InfiniteIndicatorLayout>(infiniteIndicatorLayout);
}

@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);

switch (msg.what) {
case MSG_WHAT:
scrollOnce();
sendScrollMessage(interval);
default:
break;
InfiniteIndicatorLayout infiniteIndicatorLayout = mLeakActivityRef.get();
if(infiniteIndicatorLayout != null){
switch (msg.what) {
case MSG_WHAT:
infiniteIndicatorLayout.scrollOnce();
infiniteIndicatorLayout.sendScrollMessage();
default:
break;
}
}
}
}


/**
* get auto scroll interval time in milliseconds, default is {@link #DEFAULT_INTERVAL}
*
Expand Down Expand Up @@ -429,4 +442,14 @@ public void setCustomIndicator(PageIndicator indicator) {
// startAutoScroll();
}

public void setOnPageChangeListener(ViewPager.OnPageChangeListener onPageChangeListener){
if(onPageChangeListener!=null)
mIndicator.setOnPageChangeListener(onPageChangeListener);
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
handler.removeCallbacksAndMessages(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static android.support.v4.view.ViewPager.OnPageChangeListener;

public class AnimIndicator extends LinearLayout implements PageIndicator{
public class AnimIndicator extends LinearLayout implements PageIndicator {

private final static int DEFAULT_INDICATOR_WIDTH = 5;

Expand Down Expand Up @@ -124,7 +124,7 @@ public void notifyDataSetChanged() {

@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
int positionOffsetPixels) {
if (mViewPagerOnPageChangeListener != null) {
mViewPagerOnPageChangeListener.onPageScrolled(position, positionOffset,
positionOffsetPixels);
Expand All @@ -137,12 +137,12 @@ public void onPageSelected(int position) {
mViewPagerOnPageChangeListener.onPageSelected(position);
}

if(getChildAt(((RecyleAdapter) mViewPager.getAdapter()).getPosition(mCurrentPage))==null)
if (getRealChildAt(mCurrentPage) == null)
return;

mAnimationIn.setTarget(getChildAt(((RecyleAdapter) mViewPager.getAdapter()).getPosition(mCurrentPage)));
mAnimationIn.setTarget(getRealChildAt(mCurrentPage));
mAnimationIn.start();
mAnimationOut.setTarget(getChildAt(((RecyleAdapter) mViewPager.getAdapter()).getPosition(position)));
mAnimationOut.setTarget(getRealChildAt(position));
mAnimationOut.start();

mCurrentPage = position;
Expand All @@ -158,32 +158,36 @@ public void onPageScrollStateChanged(int state) {
private void createIndicators(ViewPager viewPager) {
removeAllViews();

if(((RecyleAdapter)viewPager.getAdapter())==null) {
if (((RecyleAdapter) viewPager.getAdapter()) == null) {
return;
}

int count = ((RecyleAdapter)viewPager.getAdapter()).getRealCount();
int count = ((RecyleAdapter) viewPager.getAdapter()).getRealCount();
if (count <= 1) {
return;
}

for (int i = 0; i < count; i++) {
View Indicator = new View(getContext());
Indicator.setBackgroundResource(mIndicatorBackground);
addView(Indicator, mIndicatorWidth, mIndicatorHeight);
LayoutParams lp = (LayoutParams) Indicator.getLayoutParams();
View indicator = new View(getContext());
indicator.setBackgroundResource(mIndicatorBackground);
addView(indicator, mIndicatorWidth, mIndicatorHeight);
LayoutParams lp = (LayoutParams) indicator.getLayoutParams();
lp.leftMargin = mIndicatorMargin;
lp.rightMargin = mIndicatorMargin;
Indicator.setLayoutParams(lp);
indicator.setLayoutParams(lp);

mAnimationOut.setTarget(Indicator);
mAnimationOut.setTarget(indicator);
mAnimationOut.start();
}

mAnimationOut.setTarget(getChildAt(mCurrentPage));
mAnimationOut.setTarget(getRealChildAt(mCurrentPage));
mAnimationOut.start();
}

private View getRealChildAt(int position) {
return getChildAt(((RecyleAdapter) mViewPager.getAdapter()).getPosition(position));
}

private class ReverseInterpolator implements Interpolator {
@Override
public float getInterpolation(float value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public int getCount() {

@Override
public View getView(final int position, View convertView, ViewGroup container) {
BaseSliderView sliderView = ((BaseSliderView) mSlederViews.get(getPosition(position)));
return ((BaseSliderView) mSlederViews.get(getPosition(position))).getView();
}

Expand All @@ -71,7 +70,6 @@ public void removeSliderAt(int position) {

public void removeAllSliders() {
mSlederViews.clear();
mDataChangeListener.notifyDataChange();
notifyDataSetChanged();
}

Expand Down

0 comments on commit 0ae34a9

Please sign in to comment.