From fcf98e94db60d311e74899b74f32b4b140f02c68 Mon Sep 17 00:00:00 2001 From: CatherineFXX <648129313@qq.com> Date: Wed, 11 Oct 2017 17:59:03 +0800 Subject: [PATCH] =?UTF-8?q?(#1)=20code=20=E6=B7=BB=E5=8A=A0=E5=9B=BE?= =?UTF-8?q?=E6=96=87=E7=BB=84=E5=90=88=E6=8E=A7=E4=BB=B6TSCombinationButto?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tsui/button/TSCombinationButton.java | 123 ++++++++++++++++++ .../com/zhiyicx/tsui/utils/ConvertUtils.java | 62 +++++++++ .../main/res/drawable/frame_loading_white.xml | 35 +++++ .../selector_button_corner_solid_big.xml | 7 + .../shape_button_corner_disable_solid_big.xml | 10 ++ ...hape_button_corner_disable_solid_small.xml | 9 ++ .../shape_button_corner_normal_solid_big.xml | 10 ++ ...shape_button_corner_normal_solid_small.xml | 10 ++ .../shape_button_corner_press_solid_big.xml | 10 ++ .../shape_button_corner_press_solid_small.xml | 10 ++ .../res/layout/view_combination_button.xml | 57 ++++++++ 11 files changed, 343 insertions(+) create mode 100644 tsui/src/main/java/com/zhiyicx/tsui/button/TSCombinationButton.java create mode 100644 tsui/src/main/java/com/zhiyicx/tsui/utils/ConvertUtils.java create mode 100644 tsui/src/main/res/drawable/frame_loading_white.xml create mode 100644 tsui/src/main/res/drawable/selector_button_corner_solid_big.xml create mode 100644 tsui/src/main/res/drawable/shape_button_corner_disable_solid_big.xml create mode 100644 tsui/src/main/res/drawable/shape_button_corner_disable_solid_small.xml create mode 100644 tsui/src/main/res/drawable/shape_button_corner_normal_solid_big.xml create mode 100644 tsui/src/main/res/drawable/shape_button_corner_normal_solid_small.xml create mode 100644 tsui/src/main/res/drawable/shape_button_corner_press_solid_big.xml create mode 100644 tsui/src/main/res/drawable/shape_button_corner_press_solid_small.xml create mode 100644 tsui/src/main/res/layout/view_combination_button.xml diff --git a/tsui/src/main/java/com/zhiyicx/tsui/button/TSCombinationButton.java b/tsui/src/main/java/com/zhiyicx/tsui/button/TSCombinationButton.java new file mode 100644 index 0000000..3498e27 --- /dev/null +++ b/tsui/src/main/java/com/zhiyicx/tsui/button/TSCombinationButton.java @@ -0,0 +1,123 @@ +package com.zhiyicx.tsui.button; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.zhiyicx.tsui.R; +import com.zhiyicx.tsui.utils.ConvertUtils; + + +/** + * @author LiuChao + * @describe 个人中心的组合控件,图片-文字-图片 + * @date 2017/1/7 + * @contactemail:450127106@qq.com + */ +public class TSCombinationButton extends FrameLayout { + ImageView mCombinedButtonImgLeft; + ImageView mCombinedButtonImgRight; + + TextView mCombinedButtonLeftText; + TextView mCombinedButtonRightText; + View mVLine; + + public TSCombinationButton(Context context, AttributeSet attrs) { + super(context, attrs); + LayoutInflater.from(context).inflate(R.layout.view_combination_button, this); + mCombinedButtonImgLeft = (ImageView) findViewById(R.id.iv_left_img); + mCombinedButtonImgRight = (ImageView) findViewById(R.id.iv_right_img); + mCombinedButtonLeftText = (TextView) findViewById(R.id.tv_left_text); + mCombinedButtonRightText = (TextView) findViewById(R.id.tv_right_text); + mVLine = findViewById(R.id.v_line); + TypedArray array = context.obtainStyledAttributes(attrs, + R.styleable.tsCombinationBtn); + Drawable leftImage = array.getDrawable(R.styleable.tsCombinationBtn_tsLeftImage); + Drawable rightImage = array.getDrawable(R.styleable.tsCombinationBtn_tsRightImage); + String leftText = array.getString(R.styleable.tsCombinationBtn_tsLeftText); + String rightText = array.getString(R.styleable.tsCombinationBtn_tsRightText); + int leftTextColor = array.getColor(R.styleable.tsCombinationBtn_tsLeftTextColor, -1); + int rightTextColor = array.getColor(R.styleable.tsCombinationBtn_tsRightTextColor, -1); + boolean showLine = array.getBoolean(R.styleable.tsCombinationBtn_tsShowLine, true); + int dividerLeftMargin = array.getDimensionPixelSize(R.styleable.tsCombinationBtn_tsDividerLeftMargin, 0); + int dividerRightMargin = array.getDimensionPixelSize(R.styleable.tsCombinationBtn_tsDividerRightMargin, 0); + int leftTextLeftPadding = array.getDimensionPixelOffset(R.styleable.tsCombinationBtn_tsLeftTextLeftPadding, ConvertUtils.dp2px(context, 10)); + array.recycle(); + if (!TextUtils.isEmpty(leftText)) { + mCombinedButtonLeftText.setText(leftText); + } + if (leftTextColor != -1) { + mCombinedButtonLeftText.setTextColor(leftTextColor); + } + if (rightTextColor != -1) { + mCombinedButtonRightText.setTextColor(rightTextColor); + } + if (!TextUtils.isEmpty(rightText)) { + mCombinedButtonRightText.setText(rightText); + } + mCombinedButtonLeftText.setPadding(leftTextLeftPadding, 0, 0, 0); + if (leftImage == null) { + mCombinedButtonImgLeft.setVisibility(GONE); + } else { + mCombinedButtonImgLeft.setVisibility(VISIBLE); + mCombinedButtonImgLeft.setImageDrawable(leftImage); + } + mCombinedButtonImgRight.setImageDrawable(rightImage); + if (showLine) { + mVLine.setVisibility(VISIBLE); + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mVLine.getLayoutParams(); + layoutParams.setMargins(dividerLeftMargin, 0, dividerRightMargin, 0); + } else { + mVLine.setVisibility(INVISIBLE); + } + } + + /** + * 设置左边文字内容 + */ + public void setLeftText(String leftText) { + mCombinedButtonLeftText.setText(leftText); + } + + /** + * 设置右边文字内容 + */ + public void setRightText(String rightText) { + mCombinedButtonRightText.setText(rightText); + } + + /** + * 设置右边文字内容颜色 + */ + public void setRightTextColor(int color) { + mCombinedButtonRightText.setTextColor(color); + } + + public TextView getCombinedButtonRightTextView() { + return mCombinedButtonRightText; + } + + public String getRightText() { + return mCombinedButtonRightText.getText().toString(); + } + + public void setRightImageClickListener(OnClickListener listener) { + mCombinedButtonImgRight.setOnClickListener(listener); + } + + public ImageView getCombinedButtonImgRight() { + return mCombinedButtonImgRight; + } + + public void setRightImage(int res) { + mCombinedButtonImgRight.setImageResource(res); + } +} diff --git a/tsui/src/main/java/com/zhiyicx/tsui/utils/ConvertUtils.java b/tsui/src/main/java/com/zhiyicx/tsui/utils/ConvertUtils.java new file mode 100644 index 0000000..142fd21 --- /dev/null +++ b/tsui/src/main/java/com/zhiyicx/tsui/utils/ConvertUtils.java @@ -0,0 +1,62 @@ +package com.zhiyicx.tsui.utils; + +import android.content.Context; + +/** + * @Describe 转换相关工具类 + * @Author Jungle68 + * @Date 2016/12/15 + * @Contact 335891510@qq.com + */ + +public class ConvertUtils { + + private ConvertUtils() { + throw new UnsupportedOperationException("u can't instantiate me..."); + } + + /** + * dp 转 px + * + * @param dpValue dp值 + * @return px值 + */ + public static int dp2px(Context context, float dpValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dpValue * scale + 0.5f); + } + + /** + * px 转 dp + * + * @param pxValue px值 + * @return dp值 + */ + public static int px2dp(Context context, float pxValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (pxValue / scale + 0.5f); + } + + /** + * sp 转 px + * + * @param spValue sp值 + * @return px值 + */ + public static int sp2px(Context context, float spValue) { + final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; + return (int) (spValue * fontScale + 0.5f); + } + + /** + * px 转 sp + * + * @param pxValue px值 + * @return sp值 + */ + public static int px2sp(Context context, float pxValue) { + final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; + return (int) (pxValue / fontScale + 0.5f); + } + +} diff --git a/tsui/src/main/res/drawable/frame_loading_white.xml b/tsui/src/main/res/drawable/frame_loading_white.xml new file mode 100644 index 0000000..edf9da5 --- /dev/null +++ b/tsui/src/main/res/drawable/frame_loading_white.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tsui/src/main/res/drawable/selector_button_corner_solid_big.xml b/tsui/src/main/res/drawable/selector_button_corner_solid_big.xml new file mode 100644 index 0000000..66243b9 --- /dev/null +++ b/tsui/src/main/res/drawable/selector_button_corner_solid_big.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tsui/src/main/res/drawable/shape_button_corner_disable_solid_big.xml b/tsui/src/main/res/drawable/shape_button_corner_disable_solid_big.xml new file mode 100644 index 0000000..334af10 --- /dev/null +++ b/tsui/src/main/res/drawable/shape_button_corner_disable_solid_big.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/tsui/src/main/res/drawable/shape_button_corner_disable_solid_small.xml b/tsui/src/main/res/drawable/shape_button_corner_disable_solid_small.xml new file mode 100644 index 0000000..884bd89 --- /dev/null +++ b/tsui/src/main/res/drawable/shape_button_corner_disable_solid_small.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/tsui/src/main/res/drawable/shape_button_corner_normal_solid_big.xml b/tsui/src/main/res/drawable/shape_button_corner_normal_solid_big.xml new file mode 100644 index 0000000..600989f --- /dev/null +++ b/tsui/src/main/res/drawable/shape_button_corner_normal_solid_big.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/tsui/src/main/res/drawable/shape_button_corner_normal_solid_small.xml b/tsui/src/main/res/drawable/shape_button_corner_normal_solid_small.xml new file mode 100644 index 0000000..cfa2797 --- /dev/null +++ b/tsui/src/main/res/drawable/shape_button_corner_normal_solid_small.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/tsui/src/main/res/drawable/shape_button_corner_press_solid_big.xml b/tsui/src/main/res/drawable/shape_button_corner_press_solid_big.xml new file mode 100644 index 0000000..b35e068 --- /dev/null +++ b/tsui/src/main/res/drawable/shape_button_corner_press_solid_big.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/tsui/src/main/res/drawable/shape_button_corner_press_solid_small.xml b/tsui/src/main/res/drawable/shape_button_corner_press_solid_small.xml new file mode 100644 index 0000000..b35e068 --- /dev/null +++ b/tsui/src/main/res/drawable/shape_button_corner_press_solid_small.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/tsui/src/main/res/layout/view_combination_button.xml b/tsui/src/main/res/layout/view_combination_button.xml new file mode 100644 index 0000000..2d2417f --- /dev/null +++ b/tsui/src/main/res/layout/view_combination_button.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + +