- * 类名 - * 需要 -- - * 可以 -- + * Created by mjj on 2017/6/3 */ -public class BottomItemTab extends BaseTabItem { +public class SpecialTab extends BaseTabItem { private ImageView mIcon; private final TextView mTitle; - private final ImageView mMessages; + private final RoundMessageView mMessages; private int mDefaultDrawable; private int mCheckedDrawable; private int mDefaultTextColor = 0x56000000; private int mCheckedTextColor = 0x56000000; - private boolean isCheck = false; - public BottomItemTab(Context context) { + public SpecialTab(Context context) { this(context, null); } - public BottomItemTab(Context context, AttributeSet attrs) { + public SpecialTab(Context context, AttributeSet attrs) { this(context, attrs, 0); } - public BottomItemTab(Context context, AttributeSet attrs, int defStyleAttr) { + public SpecialTab(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - LayoutInflater.from(context).inflate(R.layout.view_bottom_tab, this, true); + LayoutInflater.from(context).inflate(R.layout.special_tab, this, true); - mIcon = (ImageView) findViewById(R.id.view_bottom_tab_image); - mTitle = (TextView) findViewById(R.id.view_bottom_tab_title); - mMessages = (ImageView) findViewById(R.id.view_bottom_tab_msg); + mIcon = (ImageView) findViewById(R.id.icon); + mTitle = (TextView) findViewById(R.id.title); + mMessages = (RoundMessageView) findViewById(R.id.messages); + } + + @Override + public void setOnClickListener(@Nullable OnClickListener l) { + View view = getChildAt(0); + if (view != null) { + view.setOnClickListener(l); + } } /** @@ -62,18 +68,8 @@ public void initialize(@DrawableRes int drawableRes, @DrawableRes int checkedDra mTitle.setText(title); } - public void setData(@DrawableRes int drawableRes, @DrawableRes int checkedDrawableRes, String title) { - if (isCheck) { - mIcon.setImageResource(checkedDrawableRes); - } else { - mIcon.setImageResource(drawableRes); - } - mTitle.setText(title); - } - @Override public void setChecked(boolean checked) { - isCheck = checked; if (checked) { mIcon.setImageResource(mCheckedDrawable); mTitle.setTextColor(mCheckedTextColor); @@ -85,15 +81,12 @@ public void setChecked(boolean checked) { @Override public void setMessageNumber(int number) { - + mMessages.setMessageNumber(number); } @Override public void setHasMessage(boolean hasMessage) { - if (hasMessage) - mMessages.setVisibility(VISIBLE); - else - mMessages.setVisibility(GONE); + mMessages.setHasMessage(hasMessage); } @Override diff --git a/demo/src/main/java/com/simple/custom/SpecialTabRound.java b/demo/src/main/java/com/simple/custom/SpecialTabRound.java new file mode 100644 index 0000000..72fef86 --- /dev/null +++ b/demo/src/main/java/com/simple/custom/SpecialTabRound.java @@ -0,0 +1,94 @@ +package com.simple.custom; + +import android.content.Context; +import android.support.annotation.ColorInt; +import android.support.annotation.DrawableRes; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bottom.internal.RoundMessageView; +import com.bottom.item.BaseTabItem; +import com.simple.R; + +/** + * Created by mjj on 2017/6/3 + */ +public class SpecialTabRound extends BaseTabItem { + + private ImageView mIcon; + private final TextView mTitle; + private final RoundMessageView mMessages; + + private int mDefaultDrawable; + private int mCheckedDrawable; + + private int mDefaultTextColor = 0x56000000; + private int mCheckedTextColor = 0x56000000; + + public SpecialTabRound(Context context) { + this(context, null); + } + + public SpecialTabRound(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public SpecialTabRound(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + + LayoutInflater.from(context).inflate(R.layout.special_tab_round, this, true); + + mIcon = (ImageView) findViewById(R.id.icon); + mTitle = (TextView) findViewById(R.id.title); + mMessages = (RoundMessageView) findViewById(R.id.messages); + } + + /** + * 方便初始化的方法 + * + * @param drawableRes 默认状态的图标 + * @param checkedDrawableRes 选中状态的图标 + * @param title 标题 + */ + public void initialize(@DrawableRes int drawableRes, @DrawableRes int checkedDrawableRes, String title) { + mDefaultDrawable = drawableRes; + mCheckedDrawable = checkedDrawableRes; + mTitle.setText(title); + } + + @Override + public void setChecked(boolean checked) { + if (checked) { + mIcon.setImageResource(mCheckedDrawable); + mTitle.setTextColor(mCheckedTextColor); + } else { + mIcon.setImageResource(mDefaultDrawable); + mTitle.setTextColor(mDefaultTextColor); + } + } + + @Override + public void setMessageNumber(int number) { + mMessages.setMessageNumber(number); + } + + @Override + public void setHasMessage(boolean hasMessage) { + mMessages.setHasMessage(hasMessage); + } + + @Override + public String getTitle() { + return mTitle.getText().toString(); + } + + public void setTextDefaultColor(@ColorInt int color) { + mDefaultTextColor = color; + } + + public void setTextCheckedColor(@ColorInt int color) { + mCheckedTextColor = color; + } +} diff --git a/demo/src/main/java/com/simple/custom/TestRepeatTab.java b/demo/src/main/java/com/simple/custom/TestRepeatTab.java new file mode 100644 index 0000000..e2a1b83 --- /dev/null +++ b/demo/src/main/java/com/simple/custom/TestRepeatTab.java @@ -0,0 +1,46 @@ +package com.simple.custom; + +import android.animation.ObjectAnimator; +import android.content.Context; +import android.util.AttributeSet; + +import com.simple.R; + +/** + * Created by mjj on 2017/10/19 + *
+ * 测试重复点击的触发 + *
+ */ +public class TestRepeatTab extends OnlyIconItemView { + + public TestRepeatTab(Context context) { + super(context); + } + + public TestRepeatTab(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public TestRepeatTab(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + ObjectAnimator mAnimator; + + @Override + public void onRepeat() { + super.onRepeat(); + + if (mAnimator == null) { + ObjectAnimator animator = ObjectAnimator.ofFloat(findViewById(R.id.icon), "Rotation", 0f, -360f); + animator.setDuration(375); + mAnimator = animator; + } + + if (!mAnimator.isStarted()) { + mAnimator.start(); + } + + } +} diff --git a/demo/src/main/java/com/simple/other/AFragment.java b/demo/src/main/java/com/simple/other/AFragment.java new file mode 100644 index 0000000..edc0e4b --- /dev/null +++ b/demo/src/main/java/com/simple/other/AFragment.java @@ -0,0 +1,34 @@ +package com.simple.other; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class AFragment extends Fragment { + private static final String ARG_C = "content"; + + public static AFragment newInstance(String content) { + Bundle args = new Bundle(); + args.putString(ARG_C, content); + AFragment fragment = new AFragment(); + fragment.setArguments(args); + return fragment; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + String content = getArguments().getString(ARG_C); + TextView textView = new TextView(getContext()); + textView.setTextSize(30); + textView.setGravity(Gravity.CENTER); + textView.setText("Test\n\n" + content); + textView.setBackgroundColor(0xFFececec); + return textView; + } +} diff --git a/demo/src/main/java/com/simple/other/MyViewPagerAdapter.java b/demo/src/main/java/com/simple/other/MyViewPagerAdapter.java new file mode 100644 index 0000000..d1a3021 --- /dev/null +++ b/demo/src/main/java/com/simple/other/MyViewPagerAdapter.java @@ -0,0 +1,25 @@ +package com.simple.other; + +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; + +public class MyViewPagerAdapter extends FragmentPagerAdapter { + + private int size; + + public MyViewPagerAdapter(FragmentManager fm, int size) { + super(fm); + this.size = size; + } + + @Override + public Fragment getItem(int position) { + return AFragment.newInstance(position + ""); + } + + @Override + public int getCount() { + return size; + } +} diff --git a/demo/src/main/java/com/simple/other/NoTouchViewPager.java b/demo/src/main/java/com/simple/other/NoTouchViewPager.java new file mode 100644 index 0000000..7031a56 --- /dev/null +++ b/demo/src/main/java/com/simple/other/NoTouchViewPager.java @@ -0,0 +1,30 @@ +package com.simple.other; + +import android.content.Context; +import android.support.v4.view.ViewPager; +import android.util.AttributeSet; +import android.view.MotionEvent; + +/** + * 使ViewPager不能滑动 + */ +public class NoTouchViewPager extends ViewPager { + + public NoTouchViewPager(Context context) { + super(context); + } + + public NoTouchViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + return false; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent event) { + return false; + } +} diff --git a/demo/src/main/res/drawable/ic_audiotrack_black_24dp.xml b/demo/src/main/res/drawable/ic_audiotrack_black_24dp.xml new file mode 100644 index 0000000..2f5c8ed --- /dev/null +++ b/demo/src/main/res/drawable/ic_audiotrack_black_24dp.xml @@ -0,0 +1,9 @@ +