From 2dee0bb49a5d4be8dc6766c357c8cabd47ff0858 Mon Sep 17 00:00:00 2001 From: Jpeng Date: Tue, 27 Feb 2018 20:44:14 +0800 Subject: [PATCH] Add pressAnimate enable --- .../java/com/jpeng/demo/MainActivity.java | 5 +++-- .../main/java/com/jpeng/demo/Tab4Pager.java | 2 +- app/src/main/res/layout/activity_main.xml | 1 + .../java/com/jpeng/jptabbar/JPTabBar.java | 21 ++++++++++++------- library/src/main/res/values/attrs.xml | 1 + 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/jpeng/demo/MainActivity.java b/app/src/main/java/com/jpeng/demo/MainActivity.java index 8cc737d..18d5cdd 100644 --- a/app/src/main/java/com/jpeng/demo/MainActivity.java +++ b/app/src/main/java/com/jpeng/demo/MainActivity.java @@ -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(); diff --git a/app/src/main/java/com/jpeng/demo/Tab4Pager.java b/app/src/main/java/com/jpeng/demo/Tab4Pager.java index 1e1108b..bd4b1ed 100644 --- a/app/src/main/java/com/jpeng/demo/Tab4Pager.java +++ b/app/src/main/java/com/jpeng/demo/Tab4Pager.java @@ -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"); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f69a7ac..ab86af0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -26,5 +26,6 @@ android:background="@drawable/tab_bg" jp:TabMiddleView="@layout/view_mitem" jp:TabAnimate="Scale" + jp:TabPressAnimateEnable="false" /> diff --git a/library/src/main/java/com/jpeng/jptabbar/JPTabBar.java b/library/src/main/java/com/jpeng/jptabbar/JPTabBar.java index ac833ed..3b27afe 100644 --- a/library/src/main/java/com/jpeng/jptabbar/JPTabBar.java +++ b/library/src/main/java/com/jpeng/jptabbar/JPTabBar.java @@ -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; //默认的徽章字体大小 @@ -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; @@ -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); @@ -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); } @@ -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); } diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index f523c18..739fdf4 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -17,6 +17,7 @@ +