Skip to content

Commit

Permalink
Add pressAnimate enable
Browse files Browse the repository at this point in the history
  • Loading branch information
peng8350 committed Feb 27, 2018
1 parent 99afe6a commit 2dee0bb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/com/jpeng/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
mTabbar = (JPTabBar) findViewById(tabbar);
mPager = (ViewPager) findViewById(R.id.view_pager);
// mTabbar.setTitles("asd","页面二","页面三","页面四").setNormalIcons(R.mipmap.tab1_normal,R.mipmap.tab2_normal,R.mipmap.tab3_normal,R.mipmap.tab4_normal)
// .setSelectedIcons(R.mipmap.tab1_selected,R.mipmap.tab2_selected,R.mipmap.tab3_selected,R.mipmap.tab4_selected).generate();
mTabbar.setTitles("asd","页面二","页面三","页面四").setNormalIcons(R.mipmap.tab1_normal,R.mipmap.tab2_normal,R.mipmap.tab3_normal,R.mipmap.tab4_normal)
.setSelectedIcons(R.mipmap.tab1_selected,R.mipmap.tab2_selected,R.mipmap.tab3_selected);
// mTabbar.setTabTypeFace("fonts/Jaden.ttf");
mTab1 = new Tab1Pager();
mTab2 = new Tab2Pager();
mTab3 = new Tab3Pager();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/jpeng/demo/Tab4Pager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Override
public void onClick(View view) {
JPTabBar tabBar = (JPTabBar) ((Activity)getContext()).findViewById(R.id.tabbar);
tabBar.setTabTypeFace("");
tabBar.setTabTypeFace("fonts/Jaden.ttf");
}

}
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
android:background="@drawable/tab_bg"
jp:TabMiddleView="@layout/view_mitem"
jp:TabAnimate="Scale"
jp:TabPressAnimateEnable="false"
/>
</RelativeLayout>
21 changes: 14 additions & 7 deletions library/src/main/java/com/jpeng/jptabbar/JPTabBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class JPTabBar extends LinearLayout implements ViewPager.OnPageChangeList
private static final int DEFAULT_SELECT_COLOR = 0xff59D9B9;
//默认是否接受颜色随着字体变化
private static final boolean DEFAULT_ACEEPTFILTER = true;
//默认是否允许按住动画的变化
private static final boolean DEFAULT_PRESSANIMATE = true;
//默认是否开启字体图标渐变动画
private static final boolean DEFAULT_GRADIENT = false;
//默认是否开启页面动画
private static final boolean DEFAULT_PAGEANIMATE = false;
//默认的徽章背景颜色
private static final int DEFAULT_BADGE_COLOR = 0xffff0000;
//默认的徽章字体大小
Expand Down Expand Up @@ -77,10 +83,10 @@ public class JPTabBar extends LinearLayout implements ViewPager.OnPageChangeList
private ViewPager mTabPager;
// 渐变判断(用于滑动的渐变)
private boolean mGradientEnable;
/**
* 是否需要页面滚动动画
*/
//是否需要页面滚动动画
private boolean mPageAnimateEnable;
// 是否需要按住动画
private boolean mPressAnimateEnable;
//判断是否拖了徽章
private boolean mDragedBadge;

Expand Down Expand Up @@ -172,8 +178,9 @@ private void initFromAttribute() {
int badgePadding = DensityUtils.px2dp(mContext, mAttribute.getDimensionPixelOffset(R.styleable.JPTabBar_BadgePadding, DensityUtils.dp2px(mContext, DEFAULT_PADDING)));
int badgeVerMargin = DensityUtils.px2dp(mContext, mAttribute.getDimensionPixelOffset(R.styleable.JPTabBar_BadgeVerticalMargin, DensityUtils.dp2px(mContext, DEFAULT_BADGEVERTICAL_MARGIN)));
int badgeHorMargin = DensityUtils.px2dp(mContext, mAttribute.getDimensionPixelOffset(R.styleable.JPTabBar_BadgeHorizonalMargin, DensityUtils.dp2px(mContext, DEFAULT_BADGEHORIZONAL_MARGIN)));
mPageAnimateEnable = mAttribute.getBoolean(R.styleable.JPTabBar_TabPageAnimateEnable, false);
mGradientEnable = mAttribute.getBoolean(R.styleable.JPTabBar_TabGradientEnable, false);
mPageAnimateEnable = mAttribute.getBoolean(R.styleable.JPTabBar_TabPageAnimateEnable, DEFAULT_PAGEANIMATE);
mGradientEnable = mAttribute.getBoolean(R.styleable.JPTabBar_TabGradientEnable, DEFAULT_GRADIENT);
mPressAnimateEnable = mAttribute.getBoolean(R.styleable.JPTabBar_TabPressAnimateEnable,DEFAULT_PRESSANIMATE);
int hMargin = mAttribute.getDimensionPixelOffset(R.styleable.JPTabBar_TabMiddleHMargin, DensityUtils.dp2px(mContext, DEFAULT_MIDDLEMARGIN));
String typeFacepath = mAttribute.getString(R.styleable.JPTabBar_TabTypeface);
boolean acceptFilter = mAttribute.getBoolean(R.styleable.JPTabBar_TabIconFilter, DEFAULT_ACEEPTFILTER);
Expand Down Expand Up @@ -721,7 +728,7 @@ public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mDragedBadge = (tabItem).getBadgeViewHelper().checkDragging(event);
if (!mDragedBadge && mJPTabItems[mSelectIndex].getAnimater() != null) {
if (!mDragedBadge && mJPTabItems[mSelectIndex].getAnimater() != null&&mPressAnimateEnable) {
mJPTabItems[mSelectIndex].getAnimater().onPressDown(mJPTabItems[mSelectIndex].getIconView(), true);
tabItem.getAnimater().onPressDown((tabItem).getIconView(), false);
}
Expand All @@ -731,7 +738,7 @@ public boolean onTouch(View v, MotionEvent event) {
break;
}
if (!isInRect(v, event) || (mTabSelectLis != null && mTabSelectLis.onInterruptSelect(temp))) {
if (mJPTabItems[mSelectIndex].getAnimater() != null) {
if (mJPTabItems[mSelectIndex].getAnimater() != null&&mPressAnimateEnable) {
mJPTabItems[mSelectIndex].getAnimater().onTouchOut(mJPTabItems[mSelectIndex].getIconView(), true);
tabItem.getAnimater().onTouchOut((tabItem.getIconView()), false);
}
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<enum name="Scale2" value="4"/>
<enum name="None" value="5"/>
</attr>
<attr name="TabPressAnimateEnable" format="boolean"/>
<attr name="TabPageAnimateEnable" format="boolean"/>
<attr name="TabGradientEnable" format="boolean"/>
<attr name="TabMiddleBottomDis" format="dimension|reference"/>
Expand Down

0 comments on commit 2dee0bb

Please sign in to comment.