Skip to content

Commit

Permalink
fix bug: CommonTabLayout first setCurrentTab() cause indicator not show
Browse files Browse the repository at this point in the history
  • Loading branch information
H07000223 committed Dec 11, 2015
1 parent 143bb94 commit b7128e7
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHNAGELOG.md
Expand Up @@ -47,4 +47,8 @@ Version 1.4.2 *(2015-12-9)*

Version 1.4.4 *(2015-12-11)*
----------------------------
* fix bug: CommonTabLayout first setCurrentTab() cause indicator not show

Version 1.4.6 *(2015-12-11)*
----------------------------
* fix bug: CommonTabLayout first setCurrentTab() cause indicator not show
4 changes: 2 additions & 2 deletions FlycoTabLayout_Lib/build.gradle
Expand Up @@ -3,15 +3,15 @@ apply plugin: 'com.android.library'
//apply plugin: 'com.jfrog.bintray'

// 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version
version = "1.4.4"
version = "1.4.6"
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 144
versionCode 146
versionName version
}
buildTypes {
Expand Down
Expand Up @@ -242,7 +242,6 @@ private void addTab(final int position, View tabView) {
public void onClick(View v) {
int position = (Integer) v.getTag();
if (currentTab != position) {
isFirstSet = false;
setCurrentTab(position);
if (listener != null) {
listener.onTabSelect(position);
Expand Down Expand Up @@ -327,16 +326,22 @@ private void calcOffset() {
lp.left = lastTabView.getLeft();
lp.right = lastTabView.getRight();

valueAnimator.setObjectValues(lp, cp);
if (indicatorBounceEnable) {
valueAnimator.setInterpolator(interpolator);
}
// Log.d("AAA", "lp--->" + lp.left + "&" + lp.right);
// Log.d("AAA", "cp--->" + cp.left + "&" + cp.right);
if (lp.left == cp.left && lp.right == cp.right) {
invalidate();
} else {
valueAnimator.setObjectValues(lp, cp);
if (indicatorBounceEnable) {
valueAnimator.setInterpolator(interpolator);
}

if (indicatorAnimDuration < 0) {
indicatorAnimDuration = indicatorBounceEnable ? 500 : 250;
if (indicatorAnimDuration < 0) {
indicatorAnimDuration = indicatorBounceEnable ? 500 : 250;
}
valueAnimator.setDuration(indicatorAnimDuration);
valueAnimator.start();
}
valueAnimator.setDuration(indicatorAnimDuration);
valueAnimator.start();
}

private void calcIndicatorRect() {
Expand All @@ -363,6 +368,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
IndicatorPoint p = (IndicatorPoint) animation.getAnimatedValue();
indicatorRect.left = (int) p.left;
indicatorRect.right = (int) p.right;

if (indicatorWidth < 0) { //indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip

} else {//indicatorWidth大于0时,圆角矩形以及三角形
Expand All @@ -375,7 +381,6 @@ public void onAnimationUpdate(ValueAnimator animation) {
}

private boolean isFirstDraw = true;
private boolean isFirstSet = true;

@Override
protected void onDraw(Canvas canvas) {
Expand Down Expand Up @@ -481,12 +486,7 @@ public void setCurrentTab(int currentTab) {
fragmentChangeManager.setFragments(currentTab);
}
if (indicatorAnimEnable) {
if (isFirstSet) {
invalidate();
isFirstSet = false;
} else {
calcOffset();
}
calcOffset();
} else {
invalidate();
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.Gravity;
Expand Down Expand Up @@ -198,7 +199,6 @@ private void addTab(final int position, View tabView) {
public void onClick(View v) {
int position = (Integer) v.getTag();
if (currentTab != position) {
isFirstSet = false;
setCurrentTab(position);
if (listener != null) {
listener.onTabSelect(position);
Expand Down Expand Up @@ -257,16 +257,22 @@ private void calcOffset() {
lp.left = lastTabView.getLeft();
lp.right = lastTabView.getRight();

valueAnimator.setObjectValues(lp, cp);
if (indicatorBounceEnable) {
valueAnimator.setInterpolator(interpolator);
}
// Log.d("AAA", "lp--->" + lp.left + "&" + lp.right);
// Log.d("AAA", "cp--->" + cp.left + "&" + cp.right);
if (lp.left == cp.left && lp.right == cp.right) {
invalidate();
} else {
valueAnimator.setObjectValues(lp, cp);
if (indicatorBounceEnable) {
valueAnimator.setInterpolator(interpolator);
}

if (indicatorAnimDuration < 0) {
indicatorAnimDuration = indicatorBounceEnable ? 500 : 250;
if (indicatorAnimDuration < 0) {
indicatorAnimDuration = indicatorBounceEnable ? 500 : 250;
}
valueAnimator.setDuration(indicatorAnimDuration);
valueAnimator.start();
}
valueAnimator.setDuration(indicatorAnimDuration);
valueAnimator.start();
}

private void calcIndicatorRect() {
Expand Down Expand Up @@ -331,7 +337,6 @@ public void onAnimationUpdate(ValueAnimator animation) {
}

private boolean isFirstDraw = true;
private boolean isFirstSet = true;

@Override
protected void onDraw(Canvas canvas) {
Expand Down Expand Up @@ -398,12 +403,7 @@ public void setCurrentTab(int currentTab) {
fragmentChangeManager.setFragments(currentTab);
}
if (indicatorAnimEnable) {
if (isFirstSet) {
invalidate();
isFirstSet = false;
} else {
calcOffset();
}
calcOffset();
} else {
invalidate();
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -45,7 +45,7 @@ dependencies{
compile 'com.android.support:support-v4:23.1.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.2@aar'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.4@aar'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.6@aar'
}
```

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Expand Up @@ -44,7 +44,7 @@ dependencies{
compile 'com.android.support:support-v4:23.1.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.2@aar'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.4@aar'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.6@aar'
}
```

Expand Down
3 changes: 1 addition & 2 deletions app/build.gradle
Expand Up @@ -23,8 +23,7 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':FlycoTabLayout_Lib')

// compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.4@aar'
// compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.6@aar'
// compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.2@aar'
// compile 'com.nineoldandroids:library:2.4.0'
}
Expand Up @@ -108,6 +108,7 @@ public void onTabReselect(int position) {
}
});
tl_8.setCurrentTab(2);
tl_3.setCurrentTab(1);

//显示未读红点
tl_1.showDot(2);
Expand Down

0 comments on commit b7128e7

Please sign in to comment.