Files
yusheng-android/moduleUtil/src/main/java/com/qxcm/moduleutil/widget/BeautifulNameView.java

110 lines
3.3 KiB
Java
Raw Normal View History

2025-05-15 11:08:23 +08:00
package com.qxcm.moduleutil.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import com.qxcm.moduleutil.R;
import com.qxcm.moduleutil.utils.ImageUtils;
/**
* ProjectName: isolated-island
* Package: com.qpyy.libcommon.widget
* Description: 靓号View(有靓号一定有id特效(靓字+id)有id特效不一是靓号(只显示id))
* Author: 姚闻达
* CreateDate: 2021/3/16
* UpdateUser: 更新者
* UpdateDate: 2021/3/16 9:59
* UpdateRemark: 更新说明
* Version: 1.0
*/
public class BeautifulNameView extends LinearLayout {
private ImageView ivIcon;
private ScanTextView stvBeautiful;
private int textColor;
private int lightColor;
private float textSize;
private int speed;
public BeautifulNameView(Context context) {
this(context, null);
}
public BeautifulNameView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public BeautifulNameView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
private void init(@Nullable AttributeSet attrs) {
LayoutInflater.from(getContext()).inflate(R.layout.view_beautiful_name, this, true);
ivIcon = findViewById(R.id.iv_liang);
stvBeautiful = findViewById(R.id.stv_beautiful_value);
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.BeautifulNameView);
textColor = typedArray.getInt(R.styleable.BeautifulNameView_textColorc, Color.WHITE);
lightColor = typedArray.getInt(R.styleable.BeautifulNameView_lightColor, Color.WHITE);
textSize = typedArray.getDimension(R.styleable.BeautifulNameView_textSizec, 12);
speed = typedArray.getInt(R.styleable.BeautifulNameView_speed, 50);
typedArray.recycle();
stvBeautiful.setTextColor(textColor);
stvBeautiful.setLightColor(lightColor);
stvBeautiful.setTextSize(textSize);
stvBeautiful.setSpeed(speed);
ImageUtils.loadRes(R.mipmap.me_icon_liang, ivIcon);
}
public void setImg(String url) {
if (!TextUtils.isEmpty(url)) {
ImageUtils.loadIcon(url, ivIcon);
}
}
public void setImg(int resId) {
ImageUtils.loadRes(resId, ivIcon);
}
public void setImgVisible(boolean visible) {
ivIcon.setVisibility(visible ? VISIBLE : GONE);
}
public void setTextColor(String color) {
if (TextUtils.isEmpty(color) || !color.startsWith("#")) {
return;
}
stvBeautiful.setTextColor(Color.parseColor(color));
}
public void setTextColor(int color) {
stvBeautiful.setTextColor(color);
}
public void setTextSize(float textSize) {
stvBeautiful.setTextSize(textSize);
}
public void setText(String value) {
if (!TextUtils.isEmpty(value)) {
stvBeautiful.setText(value);
}
}
/**
* 只有服务端返回颜色(id_color字段)才播动效
* @param play
*/
public void setPlay(boolean play) {
stvBeautiful.setScan(play);
}
}