wangkai

添加短视频

Showing 38 changed files with 4513 additions and 53 deletions

Too many changes to show.

To preserve performance only 38 of 38+ files are displayed.

1 1
2 package com.wd.fastcoding.app; 2 package com.wd.fastcoding.app;
3 3
  4 +import com.hjq.toast.Toaster;
4 import com.wd.capability.network.RetrofitClient; 5 import com.wd.capability.network.RetrofitClient;
5 import com.wd.capability.router.ArouteInit; 6 import com.wd.capability.router.ArouteInit;
6 import com.wd.common.base.BaseApplication; 7 import com.wd.common.base.BaseApplication;
@@ -33,6 +34,8 @@ public class MyApplication extends BaseApplication { @@ -33,6 +34,8 @@ public class MyApplication extends BaseApplication {
33 * 初始化第三方库 34 * 初始化第三方库
34 */ 35 */
35 private void initLibs() { 36 private void initLibs() {
  37 + // 初始化 Toast 框架
  38 + Toaster.init(this);
36 // 路由初始化,主线程立即调用 39 // 路由初始化,主线程立即调用
37 ArouteInit.getInstance().init(this); 40 ArouteInit.getInstance().init(this);
38 // 网络请求初始化,主线程立即调用 41 // 网络请求初始化,主线程立即调用
@@ -79,7 +79,7 @@ @@ -79,7 +79,7 @@
79 79
80 </com.wd.common.widget.CustomSmartRefreshLayout> 80 </com.wd.common.widget.CustomSmartRefreshLayout>
81 81
82 - <com.wd.common.widget.progress.PageLoadingView 82 + <com.wd.common.progress.PageLoadingView
83 android:id="@+id/loading_view" 83 android:id="@+id/loading_view"
84 android:layout_width="wrap_content" 84 android:layout_width="wrap_content"
85 android:layout_height="wrap_content" 85 android:layout_height="wrap_content"
@@ -68,6 +68,7 @@ import com.wd.common.listener.AddFavoriteLabelCallback; @@ -68,6 +68,7 @@ import com.wd.common.listener.AddFavoriteLabelCallback;
68 import com.wd.common.net.NetStateChangeReceiver; 68 import com.wd.common.net.NetStateChangeReceiver;
69 import com.wd.common.utils.CommonVarUtils; 69 import com.wd.common.utils.CommonVarUtils;
70 import com.wd.common.utils.HistoryDataHelper; 70 import com.wd.common.utils.HistoryDataHelper;
  71 +import com.wd.common.utils.MyShareUtils;
71 import com.wd.common.utils.PDUtils; 72 import com.wd.common.utils.PDUtils;
72 import com.wd.common.utils.ProcessUtils; 73 import com.wd.common.utils.ProcessUtils;
73 import com.wd.common.utils.ToolsUtil; 74 import com.wd.common.utils.ToolsUtil;
@@ -1782,10 +1783,10 @@ public class ArticleDetailActivity extends BaseActivity implements View.OnClickL @@ -1782,10 +1783,10 @@ public class ArticleDetailActivity extends BaseActivity implements View.OnClickL
1782 transparentBean.setPageName(articlePageName); 1783 transparentBean.setPageName(articlePageName);
1783 transparentBean.setPageId(articlePageName); 1784 transparentBean.setPageId(articlePageName);
1784 //统一赋值,减少重复代码,底部评论、互动 1785 //统一赋值,减少重复代码,底部评论、互动
1785 -// MyShareUtils.setTransparentBean(transparentBean,newsDetailBean); 1786 + MyShareUtils.setTransparentBean(transparentBean,newsDetailBean);
1786 //分享 1787 //分享
1787 mShareBean = new ShareBean(); 1788 mShareBean = new ShareBean();
1788 -// MyShareUtils.setShareData(mShareBean,newsDetailBean); 1789 + MyShareUtils.setShareData(mShareBean,newsDetailBean);
1789 //隐藏收藏按钮 1790 //隐藏收藏按钮
1790 // mShareBean.setShowCollect(-1); 1791 // mShareBean.setShowCollect(-1);
1791 transparentBean.setShareBean(mShareBean); 1792 transparentBean.setShareBean(mShareBean);
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 xmlns:app="http://schemas.android.com/apk/res-auto" 6 xmlns:app="http://schemas.android.com/apk/res-auto"
7 tools:ignore="MissingDefaultResource"> 7 tools:ignore="MissingDefaultResource">
8 8
9 - <com.people.player.widget.VideoAndLivePlayerView 9 + <com.wd.player.widget.VideoAndLivePlayerView
10 android:id="@+id/playerView" 10 android:id="@+id/playerView"
11 android:layout_width="wrap_content" 11 android:layout_width="wrap_content"
12 android:layout_height="wrap_content" 12 android:layout_height="wrap_content"
  1 +
  2 +package com.wd.common.dialog;
  3 +
  4 +import android.app.Dialog;
  5 +import android.content.Context;
  6 +import android.os.Bundle;
  7 +import android.text.TextUtils;
  8 +import android.view.View;
  9 +import android.view.ViewGroup;
  10 +import android.view.Window;
  11 +import android.widget.ImageView;
  12 +import android.widget.TextView;
  13 +
  14 +import androidx.annotation.NonNull;
  15 +import androidx.constraintlayout.widget.ConstraintLayout;
  16 +
  17 +import com.wd.common.viewclick.BaseClickListener;
  18 +import com.wd.fastcoding.base.R;
  19 +import com.wd.foundation.bean.utils.TimeUtil;
  20 +
  21 +
  22 +/**
  23 + * 详情对话框
  24 + *
  25 + * @author lvjinhui
  26 + */
  27 +public class ViewDetailsDialog extends Dialog {
  28 +
  29 + // 作者
  30 + private final String authorName;
  31 +
  32 + // 标题
  33 + private final String newsTitle;
  34 +
  35 + // 描述
  36 + private final String newIntroduction;
  37 +
  38 + /**
  39 + * 时间
  40 + */
  41 + private String time;
  42 +
  43 + public ViewDetailsDialog(@NonNull Context context, String authorName, String newsTitle,
  44 + String newIntroduction, String time) {
  45 + super(context, R.style.DialogBackgroundNull);
  46 + this.authorName = authorName;
  47 + this.newsTitle = newsTitle;
  48 + this.newIntroduction = newIntroduction;
  49 + this.time = time;
  50 + }
  51 +
  52 + @Override
  53 + protected void onCreate(Bundle savedInstanceState) {
  54 + super.onCreate(savedInstanceState);
  55 + setContentView(R.layout.dialog_short_video_describe);
  56 + initOption();
  57 + initView();
  58 + }
  59 +
  60 + private void initOption() {
  61 + Window window = getWindow();
  62 + if (window != null) {
  63 + window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  64 + window.setDimAmount(0);
  65 + window.setBackgroundDrawableResource(android.R.color.transparent);
  66 + }
  67 + }
  68 +
  69 + private void initView() {
  70 +
  71 + TextView tv_author = findViewById(R.id.tv_author);
  72 + TextView tv_title = findViewById(R.id.tv_title);
  73 + TextView tv_description = findViewById(R.id.tv_description);
  74 + TextView timeTv = findViewById(R.id.tv_time);
  75 + ImageView iv_close = findViewById(R.id.iv_close);
  76 + ConstraintLayout clEmptyArea = findViewById(R.id.clEmptyArea);
  77 + if (!TextUtils.isEmpty(authorName)) {
  78 + if (tv_author != null) {
  79 + tv_author.setText(authorName);
  80 + }
  81 + }
  82 + if (!TextUtils.isEmpty(newsTitle)) {
  83 + if (tv_title != null) {
  84 + tv_title.setText(newsTitle);
  85 + }
  86 + }
  87 + if (!TextUtils.isEmpty(newIntroduction)) {
  88 + if (tv_description != null) {
  89 + tv_description.setVisibility(View.VISIBLE);
  90 + tv_description.setText(newIntroduction);
  91 + }
  92 + }else {
  93 + if (tv_description != null) {
  94 + tv_description.setVisibility(View.GONE);
  95 + }
  96 + }
  97 +
  98 + //设置时间
  99 + if (TextUtils.isEmpty(time)) {
  100 + timeTv.setVisibility(View.GONE);
  101 + }else {
  102 + timeTv.setVisibility(View.VISIBLE);
  103 + //不需要走统一规则,目前接口返回的就是具体时间格式
  104 + //yyyy-MM-dd HH:mm:ss ----> yyyy-MM-dd HH:mm
  105 + time = TimeUtil.transFormTime3(time);
  106 + timeTv.setText(time);
  107 + }
  108 + if (iv_close != null) {
  109 + iv_close.setOnClickListener(new View.OnClickListener() {
  110 + @Override
  111 + public void onClick(View v) {
  112 + dismiss();
  113 + }
  114 + });
  115 + }
  116 + if (clEmptyArea != null){
  117 + clEmptyArea.setOnClickListener(new BaseClickListener() {
  118 + @Override
  119 + protected void onNoDoubleClick(View v) {
  120 + dismiss();
  121 + }
  122 + });
  123 + }
  124 + }
  125 +
  126 +}
  1 +/*
  2 + * Copyright (c) People Technologies Co., Ltd. 2019-2022. All rights reserved.
  3 + */
  4 +
  5 +package com.wd.common.listener;
  6 +
  7 +import android.os.Handler;
  8 +import android.os.Looper;
  9 +import android.os.SystemClock;
  10 +import android.view.MotionEvent;
  11 +import android.view.View;
  12 +
  13 +/**
  14 + * 描述:
  15 + *
  16 + * @author : lvjinhui
  17 + * @since: 2022/7/7
  18 + */
  19 +public class MyClickListener implements View.OnTouchListener {
  20 + /**
  21 + * 双击间四百毫秒延时
  22 + */
  23 + private static int timeout = 400;
  24 +
  25 + /**
  26 + * 点击的时间间隔
  27 + */
  28 + private static long INTERVAL = 300;
  29 +
  30 + /**
  31 + * 记录上一次的点击时间
  32 + */
  33 + private long lastClickTime = 0;
  34 +
  35 + /**
  36 + * 记录连续点击次数
  37 + */
  38 + private int clickCount = 0;
  39 +
  40 + private boolean continuouslyClick;
  41 +
  42 + private Handler handler;
  43 +
  44 + private MyClickCallBack myClickCallBack;
  45 +
  46 + public interface MyClickCallBack {
  47 + /**
  48 + * 点击一次的回调
  49 + */
  50 + void oneClick();
  51 +
  52 + /**
  53 + * 双击
  54 + */
  55 + void continuousClick();
  56 + }
  57 +
  58 + public MyClickListener(MyClickCallBack myClickCallBack) {
  59 + this.myClickCallBack = myClickCallBack;
  60 + handler = new Handler(Looper.getMainLooper());
  61 + clickCount = 0;
  62 + }
  63 +
  64 + @Override
  65 + public boolean onTouch(View v, MotionEvent event) {
  66 + if (event.getAction() == MotionEvent.ACTION_DOWN) {
  67 + // 获取点击时间
  68 + long currTime = SystemClock.uptimeMillis();
  69 + // 判断点击之间的时间差
  70 + long interval = currTime - lastClickTime;
  71 + lastClickTime = currTime;
  72 + clickCount++;
  73 + if (interval < INTERVAL) {
  74 + // 处于连续点击中
  75 + continuouslyClick = true;
  76 + } else {
  77 + continuouslyClick = false;
  78 + // 清零
  79 + clickCount = 1;
  80 + }
  81 + handler.postDelayed(new Runnable() {
  82 + @Override
  83 + public void run() {
  84 + if (clickCount == 1){
  85 + //只点击1次,触发暂停/播放操作
  86 + myClickCallBack.oneClick();
  87 + }else {
  88 + //连续点击中 +1 次
  89 + myClickCallBack.continuousClick();
  90 + }
  91 + // 清空handler延时,并防内存泄漏
  92 + handler.removeCallbacksAndMessages(null);
  93 + }
  94 + // 延时timeout后执行run方法中的代码
  95 + }, timeout);
  96 + }
  97 + // 让点击事件继续传播,方便再给View添加其他事件监听
  98 + return false;
  99 + }
  100 +}
  1 +package com.wd.common.listener;
  2 +
  3 +import android.view.GestureDetector;
  4 +import android.view.MotionEvent;
  5 +
  6 +import com.wd.base.log.Logger;
  7 +
  8 +
  9 +/**
  10 + * Time:2023/11/8
  11 + * Author:ypf
  12 + * Description:简化版手势类回调
  13 + */
  14 +public interface SimpleGestureDetectorListener extends GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
  15 +
  16 + String TAG = "SimpleGestureDetectorLi";
  17 +
  18 + @Override
  19 + default boolean onSingleTapConfirmed(MotionEvent e) {
  20 + Logger.t(TAG).i("onSingleTapConfirmed");
  21 + return true;
  22 + }
  23 +
  24 + @Override
  25 + default boolean onDoubleTap(MotionEvent e) {
  26 + Logger.t(TAG).i("onDoubleTap");
  27 + return true;
  28 + }
  29 +
  30 + @Override
  31 + default boolean onDoubleTapEvent(MotionEvent e) {
  32 + Logger.t(TAG).i("onDoubleTapEvent");
  33 + return true;
  34 + }
  35 +
  36 + @Override
  37 + default boolean onDown(MotionEvent e) {
  38 + Logger.t(TAG).i("onDown");
  39 + return true;
  40 + }
  41 +
  42 + @Override
  43 + default void onShowPress(MotionEvent e) {
  44 + Logger.t(TAG).i("onShowPress");
  45 + }
  46 +
  47 + @Override
  48 + default boolean onSingleTapUp(MotionEvent e) {
  49 + Logger.t(TAG).i("onSingleTapUp");
  50 + return true;
  51 + }
  52 +
  53 + @Override
  54 + default boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
  55 + Logger.t(TAG).i("onScroll");
  56 + return true;
  57 + }
  58 +
  59 + @Override
  60 + default void onLongPress(MotionEvent e) {
  61 + Logger.t(TAG).i("onLongPress");
  62 + }
  63 +
  64 + @Override
  65 + default boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
  66 + Logger.t(TAG).i("onFling");
  67 + return true;
  68 + }
  69 +
  70 +}
  1 +
  2 +package com.wd.common.utils;
  3 +
  4 +
  5 +import android.content.Context;
  6 +import android.graphics.Bitmap;
  7 +import android.graphics.BitmapFactory;
  8 +import android.graphics.Canvas;
  9 +import android.graphics.Paint;
  10 +
  11 +import com.bumptech.glide.load.engine.DiskCacheStrategy;
  12 +import com.bumptech.glide.request.RequestOptions;
  13 +import com.bumptech.glide.request.target.SimpleTarget;
  14 +import com.wd.foundation.bean.comment.TransparentBean;
  15 +import com.wd.foundation.bean.convenience.AskItemDetail;
  16 +import com.wd.foundation.bean.custom.comp.AudioBean;
  17 +import com.wd.foundation.bean.custom.comp.ChannelInfoBean;
  18 +import com.wd.foundation.bean.custom.content.ContentBean;
  19 +import com.wd.foundation.bean.custom.content.ContentTypeConstant;
  20 +import com.wd.foundation.bean.custom.content.PeopleMasterBean;
  21 +import com.wd.foundation.bean.custom.content.RelInfoBean;
  22 +import com.wd.foundation.bean.custom.share.ShareBean;
  23 +import com.wd.foundation.bean.mail.LiveInfo;
  24 +import com.wd.foundation.bean.mail.ShareInfo;
  25 +import com.wd.foundation.bean.mail.VideoInfo;
  26 +import com.wd.foundation.bean.response.NewsDetailBean;
  27 +import com.wd.foundation.bean.response.PhotoBean;
  28 +import com.wd.foundation.bean.utils.TimeFormater;
  29 +import com.wd.foundation.bean.utils.TimeUtil;
  30 +import com.wd.foundation.wdkit.constant.Constants;
  31 +import com.wd.foundation.wdkit.file.MyFileUtils;
  32 +import com.wd.foundation.wdkit.image.GlideApp;
  33 +import com.wd.foundation.wdkit.utils.SpUtils;
  34 +import com.wd.foundation.wdkitcore.tools.ArrayUtils;
  35 +import com.wd.foundation.wdkitcore.tools.StringUtils;
  36 +
  37 +import java.io.File;
  38 +import java.io.FileInputStream;
  39 +import java.io.IOException;
  40 +import java.text.ParseException;
  41 +import java.util.Date;
  42 +import java.util.List;
  43 +
  44 +
  45 +/**
  46 + * @author LiuKun
  47 + * @date 2023/5/13 16:11
  48 + * @Description:分享工具类
  49 + */
  50 +public class MyShareUtils {
  51 +
  52 + public static final String SHARE_PATH = "shareDataIcon";
  53 +
  54 + private static final String SHARE_FILE_NAME = "shareIcon";
  55 +
  56 + private MyShareUtils() {
  57 + }
  58 +
  59 +
  60 + /**
  61 + * 保存分享封面到本地
  62 + */
  63 + public static String saveShareIcon(Bitmap bitmap) {
  64 + String s = MyFileUtils.saveBitmap(bitmap, SHARE_PATH, SHARE_FILE_NAME);
  65 + return s;
  66 + }
  67 +
  68 +
  69 + public static String getSharePath() {
  70 + return MyFileUtils.getBasePath() + File.separator + SHARE_PATH + File.separator + SHARE_FILE_NAME + ".jpg";
  71 + }
  72 +
  73 + /**
  74 + * 删除下载的分享图标,避免下载失败,使用到上一个内容的图片
  75 + */
  76 + public static void delShareLoadIcon() {
  77 + String sharePath = getSharePath();
  78 + File file = new File(sharePath);
  79 + if (file.exists()) {
  80 + file.delete();
  81 + }
  82 + }
  83 +
  84 + /**
  85 + * 获取下载到本地的图片的bitmap
  86 + */
  87 + public static Bitmap getBitmap() {
  88 + FileInputStream fis = null;
  89 + Bitmap bitmap = null;
  90 + try {
  91 + fis = new FileInputStream(getSharePath());
  92 + bitmap = BitmapFactory.decodeStream(fis);
  93 + } catch (Exception e) {
  94 + e.printStackTrace();
  95 + }finally {
  96 + if(fis != null){
  97 + try{
  98 + fis.close();
  99 + }catch (IOException e){
  100 + e.printStackTrace();
  101 + }
  102 + }
  103 + }
  104 +
  105 + return bitmap;
  106 + }
  107 +
  108 + /**
  109 + * 添加底色
  110 + */
  111 + public static Bitmap setBitmapBackgroundColor(Bitmap bitmap, int color) {
  112 + Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
  113 + Canvas canvas = new Canvas(newBitmap);
  114 + canvas.drawColor(color);
  115 + Paint paint = new Paint();
  116 + canvas.drawBitmap(bitmap, 0, 0, paint);
  117 + return newBitmap;
  118 + }
  119 +
  120 +
  121 + public static void loadBitmapListener(Context mContext, String url, SimpleTarget<Bitmap> listener, int errorResourceId, int placeholderResourceId) {
  122 + if (mContext == null) {
  123 + return;
  124 + }
  125 + RequestOptions mRequestOptions = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.DATA)
  126 + .error(errorResourceId).placeholder(placeholderResourceId).dontAnimate();
  127 + GlideApp.with(mContext).asBitmap().load(url).apply(mRequestOptions).into(listener);
  128 + }
  129 +
  130 + /**
  131 + * 详情数据设置给分享
  132 + * @param shareData
  133 + * @param detailBean
  134 + */
  135 + public static void setShareData(ShareBean shareData, NewsDetailBean detailBean){
  136 + if (shareData != null && detailBean != null) {
  137 + //类型
  138 + String newsType = detailBean.getNewsType();
  139 + shareData.setContentType(newsType);
  140 + //来源
  141 + String newsSource = detailBean.getNewsSource();
  142 + String newsSourceName = detailBean.getNewsSourceName();
  143 + shareData.setNewsSource(newsSource);
  144 + shareData.setNewsSourceName(newsSourceName);
  145 + shareData.setSpecialColumnId(detailBean.getSpecialColumnId());
  146 + shareData.setRmhPlatform(detailBean.rmhPlatform);
  147 + //处理分享时间
  148 + String publishTime = detailBean.getPublishTime();
  149 + if(StringUtils.isEqual("2",detailBean.getNewsType()) &&
  150 + detailBean.getLiveInfo() != null){
  151 + //是直播
  152 + LiveInfo liveInfo = detailBean.getLiveInfo();
  153 + if (Constants.LIVE_WAIT.equals(liveInfo.getLiveState()) &&
  154 + StringUtils.isNotBlank(liveInfo.getPlanStartTime())) {
  155 + //预约,取计划直播时间
  156 + publishTime = liveInfo.getPlanStartTime();
  157 + }else if(StringUtils.isNotBlank(liveInfo.getStartTime())){
  158 + //直播中或结束,取直播开始时间
  159 + publishTime = liveInfo.getStartTime();
  160 + }
  161 + }
  162 + shareData.setPublishTime(publishTime);
  163 + //海报标题、简介和分享出去的链接有区别
  164 + shareData.setPosterTitle(detailBean.getNewsTitle());
  165 + shareData.setPosterSummary(detailBean.getNewsSummary());
  166 + //点赞样式
  167 + int likesStyle = detailBean.getLikesStyle();
  168 + shareData.setLikesStyle(likesStyle);
  169 + //稿件的样式
  170 + shareData.setAppStyle(detailBean.getAppStyle());
  171 + //是否开启点赞
  172 + shareData.setOpenLikes(detailBean.getOpenLikes());
  173 + //是否重点稿件
  174 + shareData.setKeyArticle(detailBean.getKeyArticle());
  175 + //是否领导人文章 0 否,1 是,不存在就传0
  176 + shareData.setLeaderArticle(detailBean.getLeaderArticle());
  177 + //rmhInfo
  178 + PeopleMasterBean rmhInfo = detailBean.getRmhInfo();
  179 + String userId = "";
  180 + if (rmhInfo != null){
  181 + shareData.setMasterHead(rmhInfo.getRmhHeadUrl());
  182 + shareData.setMasterName(rmhInfo.getRmhName());
  183 + shareData.setMasterIntroduction(rmhInfo.getRmhDesc());
  184 + shareData.setPosterShareControl(rmhInfo.getPosterShareControl());
  185 + userId = rmhInfo.getUserId();
  186 + shareData.setAuthIcon(rmhInfo.getAuthIcon());
  187 + }else {
  188 + shareData.setPosterShareControl("1");
  189 + }
  190 + //id
  191 + shareData.setContentId(detailBean.getNewsId());
  192 + //CMS 的不可以举报,判断是否可以举报
  193 + if (Constants.CONTENT_SOURCE_CMS == detailBean.rmhPlatform||"13".equals(detailBean.getNewsType())
  194 + || userId.equals(SpUtils.getUserId())){
  195 + shareData.setShowReport(false);
  196 + }else {
  197 + shareData.setShowReport(true);
  198 + }
  199 + /**
  200 + * 增加评论海报封面图
  201 + */
  202 + if (detailBean.getFullColumnImgUrls().size() > 0){
  203 + shareData.setFullColumnImgUrl(detailBean.getFullColumnImgUrls().get(0).url);
  204 + }
  205 + /**
  206 + * 关联关系
  207 + */
  208 + RelInfoBean reLInfo = detailBean.getReLInfo();
  209 + if (reLInfo != null) {
  210 + shareData.setRelType(reLInfo.getRelType());
  211 + shareData.setContentRelId(reLInfo.getRelId());
  212 + shareData.setTargetRelId(reLInfo.getRelId());
  213 + shareData.setTargetRelType(reLInfo.getRelType());
  214 + shareData.setChannelId(reLInfo.getChannelId());
  215 + }
  216 +
  217 + /**
  218 + * 分享信息
  219 + */
  220 + ShareInfo shareInfo = detailBean.getShareInfo();
  221 + if (shareInfo != null){
  222 + //分享链接
  223 + shareData.setShareUrl(shareInfo.getShareUrl());
  224 + //分享标题
  225 + if (String.valueOf(ContentTypeConstant.URL_TYPE_TWO).equals(newsType)){
  226 + //直播状态拼接
  227 + String retStatus = dealLiveStatus(detailBean);
  228 + shareData.setTitle(retStatus + shareInfo.getShareTitle());
  229 + }else {
  230 + shareData.setTitle(shareInfo.getShareTitle());
  231 + }
  232 +
  233 + //分享简介
  234 + shareData.setDescription(shareInfo.getShareSummary());
  235 + //分享图标
  236 + shareData.setImageUrl(shareInfo.getShareCoverUrl());
  237 + //分享海报图片
  238 + shareData.setSharePosterCoverUrl(shareInfo.getSharePosterCoverUrl());
  239 + //显示CMS配置的海报
  240 + shareData.setSharePosterStyle(shareInfo.getSharePosterStyle());
  241 + //分享海报开关
  242 + shareData.setSharePosterOpen(shareInfo.getSharePosterOpen());
  243 + shareData.setShareOpen(shareInfo.getShareOpen());
  244 +
  245 + }else {
  246 + shareData.setShareOpen("0");
  247 + }
  248 + /**
  249 + * 视频列表
  250 + */
  251 + if ((String.valueOf(ContentTypeConstant.URL_TYPE_ONE)).equals(newsType)){
  252 + //点播
  253 + List<VideoInfo> videoInfo = detailBean.getVideoInfo();
  254 + if (videoInfo != null && videoInfo.size() > 0 && videoInfo.get(0) != null){
  255 + String duration = videoInfo.get(0).getVideoDuration();
  256 + try {
  257 + String videoTime = TimeFormater.formatMs(Integer.parseInt(duration) * 1000);
  258 + shareData.setVideoTime(videoTime);
  259 + }catch (Exception e){
  260 + e.printStackTrace();
  261 + }
  262 + }
  263 + }else if ((String.valueOf(ContentTypeConstant.URL_TYPE_NINE)).equals(newsType)){
  264 + //图集
  265 + List<PhotoBean> photoList = detailBean.getPhotoList();;
  266 + if (ArrayUtils.isNotEmpty(photoList)){
  267 + int size = photoList.size();
  268 + shareData.setPicNumber(size);
  269 + //描述字段: 选取稿件摘要,没有取第一张有图注的图片的图注,若都没有隐藏不展示
  270 + PhotoBean photoBean = photoList.get(0);
  271 + if (StringUtils.isBlank(detailBean.getNewsSummary()) && photoBean != null) {
  272 + shareData.setPosterSummary(photoBean.getPicDesc());
  273 + }
  274 + }
  275 + }else if ((String.valueOf(ContentTypeConstant.URL_TYPE_THIRTEEN)).equals(newsType)){
  276 + //音频
  277 + List<AudioBean> audioBeanList = detailBean.getAudioList();
  278 + try {
  279 + if (ArrayUtils.isNotEmpty(audioBeanList)){
  280 + AudioBean audioBean = audioBeanList.get(0);
  281 + if (null != audioBean){
  282 + int duration = audioBean.getDuration();
  283 + String videoTime = TimeFormater.formatMs(duration * 1000);
  284 + shareData.setVideoTime(videoTime);
  285 + }
  286 + }
  287 + }catch (Exception e){
  288 + e.printStackTrace();
  289 + }
  290 + //音频 选取稿件摘要,没有取正文字段
  291 + if (StringUtils.isBlank(detailBean.getNewsSummary())) {
  292 + shareData.setPosterSummary(detailBean.getNewsContent());
  293 + }
  294 + }else if ((String.valueOf(ContentTypeConstant.URL_TYPE_EIGHT)).equals(newsType)){
  295 + //文章 选取稿件摘要,没有取正文字段 ( 注意不要取到图注 )
  296 + if (StringUtils.isBlank(detailBean.getNewsSummary())) {
  297 + shareData.setPosterSummary(detailBean.getNewsContent());
  298 + }
  299 + }
  300 +
  301 + }
  302 + }
  303 +
  304 + /**
  305 + * 详情数据设置给分享
  306 + * @param shareData
  307 + * @param detailBean
  308 + */
  309 + public static void setShareData(ShareBean shareData, AskItemDetail detailBean, String description){
  310 + if (shareData != null && detailBean != null) {
  311 + //类型
  312 + shareData.setContentType(String.valueOf(ContentTypeConstant.URL_TYPE_SIXTEEN));
  313 + //来源
  314 +// String newsSource = detailBean.getNewsSource();
  315 +// String newsSourceName = detailBean.getNewsSourceName();
  316 +// shareData.setNewsSource(newsSource);
  317 +// shareData.setNewsSourceName(newsSourceName);
  318 + shareData.setRmhPlatform(detailBean.rmhPlatform);
  319 + //设置点赞、收藏可见,默认未点赞,根据接口查询状态
  320 + shareData.setShowLike(0);
  321 + shareData.setShowCollect(0);
  322 + //海报标题、简介和分享出去的链接有区别
  323 + shareData.setPosterTitle(detailBean.title);
  324 + shareData.setPosterSummary(detailBean.content);
  325 + //点赞样式
  326 + int likesStyle = Integer.parseInt(detailBean.likesStyle);
  327 + shareData.setLikesStyle(likesStyle);
  328 + //是否重点稿件
  329 + shareData.setKeyArticle(detailBean.keyArticle);
  330 + //是否领导人文章 0 否,1 是,不存在就传0
  331 + shareData.setLeaderArticle(detailBean.leaderArticle);
  332 +// //rmhInfo
  333 +// PeopleMasterBean rmhInfo = detailBean.getRmhInfo();
  334 +// if (rmhInfo != null){
  335 +// shareData.setMasterHead(rmhInfo.getRmhHeadUrl());
  336 +// shareData.setMasterName(rmhInfo.getRmhName());
  337 +// shareData.setPosterShareControl(rmhInfo.getPosterShareControl());
  338 +// }else {
  339 + shareData.setPosterShareControl("1");
  340 +// }
  341 + //id
  342 + shareData.setContentId(String.valueOf(detailBean.getAskId()));
  343 + shareData.setShowLike(Integer.parseInt(detailBean.openLikes));
  344 +// //是否可以举报
  345 +// if (CONTENT_SOURCE_RMRB.equals(newsSource)){
  346 +// shareData.setShowReport(true);
  347 +// }else {
  348 + shareData.setShowReport(false);
  349 +// }
  350 +// /**
  351 +// * 关联关系
  352 +// */
  353 +// RelInfoBean reLInfo = detailBean.getReLInfo();
  354 +// if (reLInfo != null) {
  355 +// shareData.setRelType(reLInfo.getRelType());
  356 +// shareData.setContentRelId(reLInfo.getRelId());
  357 +// shareData.setTargetRelId(reLInfo.getRelId());
  358 +// shareData.setTargetRelType(reLInfo.getRelType());
  359 +// }
  360 +
  361 + /**
  362 + * 分享信息
  363 + */
  364 + ShareInfo shareInfo = detailBean.shareInfo;
  365 + if (shareInfo != null){
  366 + //分享链接
  367 + shareData.setShareUrl(shareInfo.getShareUrl());
  368 +// //分享标题
  369 +// if (String.valueOf(ContentTypeConstant.URL_TYPE_TWO).equals(detailBean.newsType)){
  370 +// //直播状态拼接
  371 +// String retStatus = dealLiveStatus(detailBean);
  372 +// shareData.setTitle(retStatus + shareInfo.getShareTitle());
  373 +// }else {
  374 + shareData.setTitle(shareInfo.getShareTitle());
  375 +// }
  376 +
  377 + //分享简介
  378 + shareData.setDescription(description);
  379 + //分享图标
  380 +// shareData.setImageUrl(shareInfo.getShareCoverUrl());
  381 + //分享海报图片
  382 + shareData.setSharePosterCoverUrl(shareInfo.getSharePosterCoverUrl());
  383 + //显示CMS配置的海报
  384 + shareData.setSharePosterStyle(shareInfo.getSharePosterStyle());
  385 + //分享海报开关
  386 + shareData.setSharePosterOpen(shareInfo.getSharePosterOpen());
  387 + shareData.setShareOpen(shareInfo.getShareOpen());
  388 + }else {
  389 + shareData.setShareOpen("0");
  390 + }
  391 +// /**
  392 +// * 视频列表
  393 +// */
  394 +// if ((String.valueOf(ContentTypeConstant.URL_TYPE_ONE)).equals(detailBean.newsType)){
  395 +// //点播
  396 +// List<VideoInfo> videoInfo = detailBean.getVideoInfo();
  397 +// if (videoInfo != null && videoInfo.get(0) != null){
  398 +// String duration = videoInfo.get(0).getVideoDuration();
  399 +// try {
  400 +// String videoTime = TimeFormater.formatMs(Integer.parseInt(duration) * 1000);
  401 +// shareData.setVideoTime(videoTime);
  402 +// }catch (Exception e){
  403 +// e.printStackTrace();
  404 +// }
  405 +// }
  406 +// }else if ((String.valueOf(ContentTypeConstant.URL_TYPE_NINE)).equals(newsType)){
  407 +// List<PhotoBean> photoList = detailBean.getPhotoList();;
  408 +// if (!ArrayUtils.isEmpty(photoList)){
  409 +// int size = photoList.size();
  410 +// shareData.setPicNumber(size);
  411 +// }
  412 +// }
  413 +
  414 +
  415 + }
  416 + }
  417 +
  418 + /**
  419 + * 详情数据设置给分享
  420 + * @param shareData
  421 + * @param contentBean
  422 + */
  423 + public static void setShareData(ShareBean shareData, ContentBean contentBean){
  424 + if (shareData != null && contentBean != null) {
  425 + //类型
  426 + String newsType = contentBean.getObjectType();
  427 + shareData.setContentType(newsType);
  428 + //来源
  429 + String newsSource = contentBean.getNewsAuthor();
  430 + String newsSourceName = contentBean.getSource();
  431 + shareData.setNewsSource(newsSource);
  432 + shareData.setNewsSourceName(newsSourceName);
  433 + shareData.setRmhPlatform(contentBean.getRmhPlatform());
  434 + //稿件的样式
  435 + shareData.setAppStyle(contentBean.getAppStyle());
  436 + //处理分享时间
  437 + String publishTime = contentBean.getPublishTime();
  438 + if(StringUtils.isEqual("2",contentBean.getObjectType()) &&
  439 + contentBean.getLiveInfo() != null &&
  440 + StringUtils.isNotBlank(contentBean.getLiveInfo().liveStartTime)){
  441 + //是直播(暂加直播预约类型,和iOS保持一致)
  442 + LiveInfo liveInfo = contentBean.getLiveInfo();
  443 + //bff都通过liveStartTime赋值
  444 + Date date = null;
  445 + try {
  446 + date = TimeUtil.datetimeFormat.parse(liveInfo.liveStartTime);
  447 + publishTime = date.getTime()+"";
  448 + } catch (ParseException e) {
  449 + e.printStackTrace();
  450 + }
  451 + }
  452 + shareData.setPublishTime(publishTime);
  453 + //海报标题、简介和分享出去的链接有区别
  454 + shareData.setPosterTitle(contentBean.getNewsTitle());
  455 + shareData.setPosterSummary(contentBean.getNewsSummary());
  456 + //点赞样式
  457 + int likesStyle = contentBean.getLikeStyle();
  458 + shareData.setLikesStyle(likesStyle);
  459 + //是否重点稿件
  460 + shareData.setKeyArticle(contentBean.getKeyArticle());
  461 + //是否领导人文章 0 否,1 是,不存在就传0
  462 + shareData.setLeaderArticle(contentBean.getLeaderArticle());
  463 + //rmhInfo
  464 + PeopleMasterBean rmhInfo = contentBean.getRmhInfo();
  465 + String userId = "";
  466 + if (rmhInfo != null){
  467 + shareData.setMasterHead(rmhInfo.getRmhHeadUrl());
  468 + shareData.setMasterName(rmhInfo.getRmhName());
  469 + shareData.setMasterIntroduction(rmhInfo.getRmhDesc());
  470 + //号主的不一样 0有分享海报权限,1无分享海报权限
  471 + shareData.setPosterShareControl(rmhInfo.getPosterShareControl());
  472 + userId = rmhInfo.getUserId();
  473 + shareData.setAuthIcon(rmhInfo.getAuthIcon());
  474 + }else {
  475 + shareData.setPosterShareControl("1");
  476 + }
  477 + //id
  478 + shareData.setContentId(contentBean.getObjectId());
  479 + shareData.setShowLike(contentBean.getOpenLikes());
  480 + //判断是否可以举报
  481 + if (Constants.CONTENT_SOURCE_CMS == contentBean.getRmhPlatform() ||"13".equals(newsType)
  482 + || userId.equals(SpUtils.getUserId())){
  483 + shareData.setShowReport(false);
  484 + }else {
  485 + shareData.setShowReport(true);
  486 + }
  487 + //点赞状态、收藏状态
  488 +// shareData.setShowLike();
  489 + /**
  490 + * 关联关系
  491 + */
  492 + RelInfoBean reLInfo = contentBean.getReLInfo();
  493 + if (reLInfo != null) {
  494 + shareData.setRelType(reLInfo.getRelType());
  495 + shareData.setContentRelId(reLInfo.getRelId());
  496 + shareData.setTargetRelId(reLInfo.getRelId());
  497 + shareData.setTargetRelType(reLInfo.getRelType());
  498 + }
  499 +
  500 + ChannelInfoBean channelInfoBean = contentBean.getChannelInfoBean();
  501 + if (channelInfoBean != null ){
  502 + shareData.setChannelId(channelInfoBean.getChannelId());
  503 + }
  504 +
  505 + /**
  506 + * 分享信息
  507 + */
  508 + ShareInfo shareInfo = contentBean.getShareInfo();
  509 + if (shareInfo != null){
  510 + //分享链接
  511 + shareData.setShareUrl(shareInfo.getShareUrl());
  512 + //分享标题
  513 + if (String.valueOf(ContentTypeConstant.URL_TYPE_TWO).equals(newsType)){
  514 + //直播状态拼接
  515 + String retStatus = dealLiveStatus(contentBean);
  516 + shareData.setTitle(retStatus + shareInfo.getShareTitle());
  517 + }else {
  518 + shareData.setTitle(shareInfo.getShareTitle());
  519 + }
  520 +
  521 + //分享简介
  522 + shareData.setDescription(shareInfo.getShareSummary());
  523 + //分享图标
  524 + shareData.setImageUrl(shareInfo.getShareCoverUrl());
  525 + //分享海报图片
  526 + shareData.setSharePosterCoverUrl(shareInfo.getSharePosterCoverUrl());
  527 + //显示CMS配置的海报
  528 + shareData.setSharePosterStyle(shareInfo.getSharePosterStyle());
  529 + //分享海报开关
  530 + shareData.setSharePosterOpen(shareInfo.getSharePosterOpen());
  531 + shareData.setShareOpen(shareInfo.getShareOpen());
  532 + }else {
  533 + shareData.setShareOpen("0");
  534 + }
  535 + /**
  536 + * 视频列表
  537 + */
  538 + if ((String.valueOf(ContentTypeConstant.URL_TYPE_ONE)).equals(newsType)){
  539 + //点播
  540 + VideoInfo videoInfo = contentBean.getVideoInfo();
  541 + if (videoInfo != null ){
  542 + String duration = videoInfo.getVideoDuration();
  543 + try {
  544 + String videoTime = TimeFormater.formatMs(Integer.parseInt(duration) * 1000);
  545 + shareData.setVideoTime(videoTime);
  546 + }catch (Exception e){
  547 + e.printStackTrace();
  548 + }
  549 + }
  550 + }else if ((String.valueOf(ContentTypeConstant.URL_TYPE_NINE)).equals(newsType)){
  551 + String size = contentBean.getPhotoNum();
  552 + try{
  553 + Integer sizeValue = Integer.valueOf(size);
  554 + shareData.setPicNumber(sizeValue);
  555 + }catch (Exception e){
  556 + e.printStackTrace();
  557 + }
  558 +
  559 + }
  560 +
  561 +
  562 + }
  563 + }
  564 + /**
  565 + * 处理下直播状态、拼接到分享标题
  566 + */
  567 + private static String dealLiveStatus(NewsDetailBean detailBean){
  568 + String status = "";
  569 + if (detailBean != null && detailBean.getLiveInfo() != null){
  570 + String liveStatus = detailBean.getLiveInfo().getLiveState();
  571 + if (!StringUtils.isBlank(liveStatus)){
  572 + if (Constants.LIVE_END.equals(liveStatus)){
  573 + status = "[直播回放]";
  574 + }else if (Constants.LIVE_RUNNING.equals(liveStatus)){
  575 + status = "[正在直播]";
  576 + }else if (Constants.LIVE_WAIT.equals(liveStatus)){
  577 + status = "[直播预约]";
  578 + }
  579 + }
  580 + }
  581 + return status;
  582 + }
  583 +
  584 + /**
  585 + * 处理下直播状态、拼接到分享标题
  586 + */
  587 + private static String dealLiveStatus(ContentBean contentBean){
  588 + String status = "";
  589 + if (contentBean != null && contentBean.getLiveInfo() != null){
  590 + String liveStatus = contentBean.getLiveInfo().getLiveState();
  591 + if (!StringUtils.isBlank(liveStatus)){
  592 + if (Constants.LIVE_END.equals(liveStatus)){
  593 + status = "[直播回放]";
  594 + }else if (Constants.LIVE_RUNNING.equals(liveStatus)){
  595 + status = "[正在直播]";
  596 + }else if (Constants.LIVE_WAIT.equals(liveStatus)){
  597 + status = "[直播预约]";
  598 + }
  599 + }
  600 + }
  601 + return status;
  602 + }
  603 +
  604 + /**
  605 + * 统一设置数据,减少代码量
  606 + * @param transparentBean
  607 + * @param newsDetailBean
  608 + */
  609 + public static void setTransparentBean(TransparentBean transparentBean, NewsDetailBean newsDetailBean){
  610 + if (transparentBean != null && newsDetailBean != null){
  611 + transparentBean.setContentId(newsDetailBean.getNewsId());
  612 + transparentBean.setContentType(newsDetailBean.getNewsType());
  613 + transparentBean.setPreCommentFlag(newsDetailBean.getPreCommentFlag());
  614 + //是否可以点赞 1:是 0:否
  615 + transparentBean.setOpenLikes(newsDetailBean.getOpenLikes());
  616 + transparentBean.setLikesStyle(newsDetailBean.getLikesStyle());
  617 + //稿件的样式
  618 + transparentBean.setAppStyle(newsDetailBean.getAppStyle());
  619 + //迭代二新增
  620 + transparentBean.setContentTitle(newsDetailBean.getNewsTitle());
  621 + transparentBean.setKeyArticle(newsDetailBean.getKeyArticle());
  622 + //是否领导人文章 0 否,1 是,不存在就传0
  623 + transparentBean.setLeaderArticle(newsDetailBean.getLeaderArticle());
  624 + //评论开关设置
  625 + transparentBean.setOpenComment(newsDetailBean.getOpenComment());
  626 + transparentBean.setCommentDisplay(newsDetailBean.getCommentDisplay());
  627 + transparentBean.setCommentEntryFlag(newsDetailBean.getCommentEntryFlag());
  628 + transparentBean.setRmhPlatform(newsDetailBean.rmhPlatform);
  629 + //是否开启最佳评论
  630 + transparentBean.setBestNoticer(newsDetailBean.getBestNoticer());
  631 + transparentBean.setMenuShow(newsDetailBean.getMenuShow());
  632 + //设置频道id
  633 + if(StringUtils.isNotEmpty(newsDetailBean.getChannelId())){
  634 + transparentBean.setChannelId(newsDetailBean.getChannelId());
  635 + }
  636 + RelInfoBean reLInfo = newsDetailBean.getReLInfo();
  637 + //内容关系
  638 + if (null != reLInfo) {
  639 + //迭代二新增
  640 + transparentBean.setTargetRelObjectId(reLInfo.getRelObjectId());
  641 + transparentBean.setTargetRelId(reLInfo.getRelId());
  642 + transparentBean.setTargetRelType(reLInfo.getRelType());
  643 + transparentBean.setRelType(reLInfo.getRelType());
  644 + transparentBean.setContentRelId(reLInfo.getRelId());
  645 + transparentBean.setChannelId(reLInfo.getChannelId());
  646 + }
  647 + }
  648 + }
  649 +
  650 + /**
  651 + * 统一设置数据,减少代码量
  652 + * @param transparentBean
  653 + * @param askItemDetail
  654 + */
  655 + public static void setTransparentBean(TransparentBean transparentBean, AskItemDetail askItemDetail){
  656 + if (transparentBean != null && askItemDetail != null){
  657 + transparentBean.setContentId(String.valueOf(askItemDetail.getAskId()));
  658 + transparentBean.setContentType(String.valueOf(ContentTypeConstant.URL_TYPE_SIXTEEN));
  659 + transparentBean.setPreCommentFlag(Integer.parseInt(askItemDetail.preCommentFlag));
  660 + //是否可以点赞 1:是 0:否
  661 + transparentBean.setOpenLikes(Integer.parseInt(askItemDetail.openLikes));
  662 + transparentBean.setLikesStyle(Integer.parseInt(askItemDetail.likesStyle));
  663 + //迭代二新增
  664 + transparentBean.setContentTitle(askItemDetail.title);
  665 + transparentBean.setKeyArticle(askItemDetail.keyArticle);
  666 + //是否领导人文章 0 否,1 是,不存在就传0
  667 + transparentBean.setLeaderArticle(askItemDetail.leaderArticle);
  668 + //评论开关设置
  669 + transparentBean.setOpenComment(Integer.parseInt(askItemDetail.openComment));
  670 + transparentBean.setCommentDisplay(Integer.parseInt(askItemDetail.commentDisplay));
  671 +// transparentBean.setCommentEntryFlag(askItemDetail.getCommentEntryFlag());
  672 +// RelInfoBean reLInfo = askItemDetail.getReLInfo();
  673 +// //内容关系
  674 +// if (null != reLInfo) {
  675 +// //迭代二新增
  676 +// transparentBean.setTargetRelObjectId(reLInfo.getRelObjectId());
  677 +// transparentBean.setTargetRelId(reLInfo.getRelId());
  678 +// transparentBean.setTargetRelType(reLInfo.getRelType());
  679 +// transparentBean.setRelType(reLInfo.getRelType());
  680 +// transparentBean.setContentRelId(reLInfo.getRelId());
  681 +// }
  682 + }
  683 + }
  684 +
  685 +}
  1 +package com.wd.common.utils;
  2 +
  3 +import android.app.Activity;
  4 +import android.content.pm.PackageManager;
  5 +import android.os.Build;
  6 +
  7 +/**
  8 + * Time:2023/5/17
  9 + * Author:ypf
  10 + * Description:画中画工具类
  11 + */
  12 +public class PipUtils {
  13 +
  14 +
  15 + /**
  16 + * 判断是否支持画中画
  17 + *
  18 + * @return 是否支持画中画
  19 + */
  20 + public static boolean supportPictureInPicture(Activity activity) {
  21 + if (activity == null) {
  22 + return false;
  23 + }
  24 + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
  25 + }
  26 +
  27 + /**
  28 + * 判断当前是否处于小窗模式
  29 + *
  30 + * @return 是否支持画中画
  31 + */
  32 + public static boolean isInPictureInPictureMode(Activity activity) {
  33 + if (activity == null) {
  34 + return false;
  35 + }
  36 + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && activity.isInPictureInPictureMode();
  37 + }
  38 +
  39 +}
@@ -42,6 +42,7 @@ import com.wd.foundation.wdkitcore.livedata.LiveDataBus; @@ -42,6 +42,7 @@ import com.wd.foundation.wdkitcore.livedata.LiveDataBus;
42 import com.wd.foundation.wdkitcore.thread.ThreadPoolUtils; 42 import com.wd.foundation.wdkitcore.thread.ThreadPoolUtils;
43 import com.wd.foundation.wdkitcore.tools.AppContext; 43 import com.wd.foundation.wdkitcore.tools.AppContext;
44 import com.wd.foundation.wdkitcore.tools.ArrayUtils; 44 import com.wd.foundation.wdkitcore.tools.ArrayUtils;
  45 +import com.wd.foundation.wdkitcore.tools.JsonUtils;
45 import com.wd.foundation.wdkitcore.tools.ResUtils; 46 import com.wd.foundation.wdkitcore.tools.ResUtils;
46 import com.wd.foundation.wdkitcore.tools.StringUtils; 47 import com.wd.foundation.wdkitcore.tools.StringUtils;
47 48
@@ -249,55 +250,55 @@ public class ProcessUtils implements IntentConstants { @@ -249,55 +250,55 @@ public class ProcessUtils implements IntentConstants {
249 String contentId = content.getObjectId(); 250 String contentId = content.getObjectId();
250 if (ContentTypeConstant.URL_TYPE_ZERO == type) { 251 if (ContentTypeConstant.URL_TYPE_ZERO == type) {
251 // 不跳转 252 // 不跳转
252 -// } else if (ContentTypeConstant.URL_TYPE_ONE == type) {  
253 -// // 点播  
254 -// String videoUrl = "";  
255 -// String firstFrameImageUri = "";  
256 -// if (content.getVideoInfo() != null) {  
257 -// videoUrl = content.getVideoInfo().videoUrl;  
258 -// firstFrameImageUri = content.getVideoInfo().firstFrameImageUri;  
259 -// }  
260 -// String pageId = "";  
261 -// if (StringUtils.isNotBlank(content.getPageId())) {  
262 -// pageId = content.getPageId();  
263 -// }  
264 -// String channelId = "";  
265 -// if (content.getChannelInfoBean() != null) {  
266 -// channelId = content.getChannelInfoBean().getChannelId();  
267 -// }  
268 -// String topicId = "";  
269 -// if (content.getTopicInfoBean() != null) {  
270 -// topicId = content.getTopicInfoBean().getTopicId();  
271 -// }  
272 -// VodDetailIntentBean intentBean = new VodDetailIntentBean();  
273 -// intentBean.setPageId(pageId);  
274 -// intentBean.setContentId(contentId);  
275 -// intentBean.setContentType(content.getObjectType());  
276 -// intentBean.setVideoUrl(videoUrl);  
277 -// intentBean.setChannelId(channelId);  
278 -// intentBean.setTopicId(topicId);  
279 -// intentBean.setRecommend(content.getRecommend() == 1);  
280 -// intentBean.setCompId(content.getCompId());  
281 -// //搜索keyWord  
282 -// intentBean.setKeyWord(content.getKeyWord());  
283 -// // 浏览历史、收藏页面、站内信(预约直播列表、推送消息记录列表)  
284 -// intentBean.setFrom(content.getFromPage());  
285 -// // 处理来自哪个页面  
286 -// dealIntentBeanRequestType(intentBean, content);  
287 -// //站内信(预约直播列表、推送消息记录列表)  
288 -// intentBean.localFiledIdType = content.getNewsTitle();  
289 -// //添加关联关系  
290 -// intentBean.setRelType(content.getRelType() + "");  
291 -// intentBean.setContentRelId(content.getRelId());  
292 -// // 是否滚动到底部  
293 -// intentBean.setScrollToBottom(content.getScrollToBottom());  
294 -// // 从列表点击进去观看第一条需要首帧图  
295 -// intentBean.setFirstFrameImageUri(firstFrameImageUri);  
296 -// // 子线程加载下图片进行缓存  
297 -// preloadImage(firstFrameImageUri);  
298 -//// // 处理埋点字段 253 + } else if (ContentTypeConstant.URL_TYPE_ONE == type) {
  254 + // 点播
  255 + String videoUrl = "";
  256 + String firstFrameImageUri = "";
  257 + if (content.getVideoInfo() != null) {
  258 + videoUrl = content.getVideoInfo().videoUrl;
  259 + firstFrameImageUri = content.getVideoInfo().firstFrameImageUri;
  260 + }
  261 + String pageId = "";
  262 + if (StringUtils.isNotBlank(content.getPageId())) {
  263 + pageId = content.getPageId();
  264 + }
  265 + String channelId = "";
  266 + if (content.getChannelInfoBean() != null) {
  267 + channelId = content.getChannelInfoBean().getChannelId();
  268 + }
  269 + String topicId = "";
  270 + if (content.getTopicInfoBean() != null) {
  271 + topicId = content.getTopicInfoBean().getTopicId();
  272 + }
  273 + VodDetailIntentBean intentBean = new VodDetailIntentBean();
  274 + intentBean.setPageId(pageId);
  275 + intentBean.setContentId(contentId);
  276 + intentBean.setContentType(content.getObjectType());
  277 + intentBean.setVideoUrl(videoUrl);
  278 + intentBean.setChannelId(channelId);
  279 + intentBean.setTopicId(topicId);
  280 + intentBean.setRecommend(content.getRecommend() == 1);
  281 + intentBean.setCompId(content.getCompId());
  282 + //搜索keyWord
  283 + intentBean.setKeyWord(content.getKeyWord());
  284 + // 浏览历史、收藏页面、站内信(预约直播列表、推送消息记录列表)
  285 + intentBean.setFrom(content.getFromPage());
  286 + // 处理来自哪个页面
  287 + dealIntentBeanRequestType(intentBean, content);
  288 + //站内信(预约直播列表、推送消息记录列表)
  289 + intentBean.localFiledIdType = content.getNewsTitle();
  290 + //添加关联关系
  291 + intentBean.setRelType(content.getRelType() + "");
  292 + intentBean.setContentRelId(content.getRelId());
  293 + // 是否滚动到底部
  294 + intentBean.setScrollToBottom(content.getScrollToBottom());
  295 + // 从列表点击进去观看第一条需要首帧图
  296 + intentBean.setFirstFrameImageUri(firstFrameImageUri);
  297 + // 子线程加载下图片进行缓存
  298 + preloadImage(firstFrameImageUri);
  299 +// // 处理埋点字段
299 // dealTrackField(intentBean, content); 300 // dealTrackField(intentBean, content);
300 -// goVideoDetail(intentBean); 301 + goVideoDetail(intentBean);
301 // } else if (ContentTypeConstant.URL_TYPE_TWO == type) { 302 // } else if (ContentTypeConstant.URL_TYPE_TWO == type) {
302 // // 直播 303 // // 直播
303 // //每次调接口,调完接口带数据进入直播详情 304 // //每次调接口,调完接口带数据进入直播详情
@@ -450,6 +451,21 @@ public class ProcessUtils implements IntentConstants { @@ -450,6 +451,21 @@ public class ProcessUtils implements IntentConstants {
450 } 451 }
451 452
452 453
  454 +
  455 + /**
  456 + * 跳转点播详情页
  457 + */
  458 + public static void goVideoDetail(VodDetailIntentBean intentBean) {
  459 +
  460 + // 拦截画中画
  461 + interceptorPictureInPicture();
  462 +
  463 + ActionBean actionBean = new ActionBean();
  464 + actionBean.paramBean.pageID = RouterConstants.PATH_VIDEO_DETAIL;
  465 + actionBean.paramBean.params = JsonUtils.convertObjectToJson(intentBean);
  466 + WdRouterRule.getInstance().processAction(AppContext.getContext(), actionBean);
  467 + }
  468 +
453 /** 469 /**
454 * 跳转H5页 470 * 跳转H5页
455 * 471 *
@@ -24,11 +24,13 @@ import androidx.core.content.FileProvider; @@ -24,11 +24,13 @@ import androidx.core.content.FileProvider;
24 import com.wd.common.listener.AddFavoriteLabelCallback; 24 import com.wd.common.listener.AddFavoriteLabelCallback;
25 import com.wd.fastcoding.base.R; 25 import com.wd.fastcoding.base.R;
26 import com.wd.foundation.bean.collect.CollectContentBean; 26 import com.wd.foundation.bean.collect.CollectContentBean;
  27 +import com.wd.foundation.wdkit.utils.ScreenUtils;
27 import com.wd.foundation.wdkitcore.constant.BaseConstants; 28 import com.wd.foundation.wdkitcore.constant.BaseConstants;
28 import com.wd.foundation.wdkit.file.MyFileUtils; 29 import com.wd.foundation.wdkit.file.MyFileUtils;
29 import com.wd.foundation.wdkit.perloader.DeviceHelper; 30 import com.wd.foundation.wdkit.perloader.DeviceHelper;
30 import com.wd.foundation.wdkit.statusbar.StatusBarCompat; 31 import com.wd.foundation.wdkit.statusbar.StatusBarCompat;
31 import com.wd.foundation.wdkit.statusbar.StatusBarStyleEnum; 32 import com.wd.foundation.wdkit.statusbar.StatusBarStyleEnum;
  33 +import com.wd.foundation.wdkitcore.tools.AppContext;
32 import com.wd.foundation.wdkitcore.tools.ResUtils; 34 import com.wd.foundation.wdkitcore.tools.ResUtils;
33 import com.yalantis.ucrop.UCrop; 35 import com.yalantis.ucrop.UCrop;
34 36
@@ -352,6 +354,18 @@ public class ToolsUtil { @@ -352,6 +354,18 @@ public class ToolsUtil {
352 } 354 }
353 355
354 /** 356 /**
  357 + * 浮点型数据比较大小
  358 + *
  359 + * @param number1
  360 + * @param number2
  361 + * @return 比较结果
  362 + */
  363 + public static boolean isEqual(double number1, double number2) {
  364 + double diff = 1e-2f;
  365 + return Math.abs(number1 - number2) < diff;
  366 + }
  367 +
  368 + /**
355 * 提供精确的除法运算 369 * 提供精确的除法运算
356 * 370 *
357 * @param v1 被除数 371 * @param v1 被除数
@@ -745,4 +759,25 @@ public class ToolsUtil { @@ -745,4 +759,25 @@ public class ToolsUtil {
745 } 759 }
746 // CollectDialog.createDialog(context, contentList, addFavoriteLabelCallback).show(); 760 // CollectDialog.createDialog(context, contentList, addFavoriteLabelCallback).show();
747 } 761 }
  762 +
  763 + /**
  764 + * 是否16:9小屏
  765 + */
  766 + private static Boolean isSmallScreen = null;
  767 +
  768 + /**
  769 + * 是否小屏手机16:9-小屏手机一级沉浸式视频全屏显示,其他fragment设置底部padding为65dp
  770 + *
  771 + * @return true or false
  772 + */
  773 + public static boolean isSmallScreen() {
  774 + if (isSmallScreen != null) {
  775 + return isSmallScreen;
  776 + }
  777 + int screenHeight = ScreenUtils.getRealHeight();
  778 + int screenWidth = ScreenUtils.getRealWidth();
  779 + double screenRatio = ToolsUtil.divNum(screenHeight, screenWidth);
  780 + // 小屏手机16:9
  781 + return isSmallScreen = ToolsUtil.isEqual(screenRatio, 1.78d);
  782 + }
748 } 783 }
  1 +package com.wd.common.widget;
  2 +
  3 +import android.content.Context;
  4 +import android.content.res.TypedArray;
  5 +import android.graphics.Canvas;
  6 +import android.graphics.Color;
  7 +import android.graphics.Paint;
  8 +import android.os.Handler;
  9 +import android.os.Message;
  10 +import android.util.AttributeSet;
  11 +import android.util.Log;
  12 +import android.view.View;
  13 +
  14 +import androidx.annotation.Nullable;
  15 +
  16 +import com.wd.fastcoding.base.R;
  17 +
  18 +import java.util.regex.Matcher;
  19 +import java.util.regex.Pattern;
  20 +
  21 +public class DYVideoLoadingView extends View {
  22 + private static final String TAG = "DYVideoLoadingView";
  23 + private int mWidth, mHeight;
  24 + private int mDefaultWidth, mDefaultHeight;
  25 + private int mProgressWidth;
  26 + private int mMinProgressWidth;
  27 + private Paint mPaint;
  28 + private String mColor;
  29 + private Handler mHandler;
  30 + private int mTimePeriod = 1;
  31 +
  32 + public DYVideoLoadingView(Context context) {
  33 + this(context, null);
  34 + }
  35 +
  36 + public DYVideoLoadingView(Context context, @Nullable AttributeSet attrs) {
  37 + this(context, attrs, 0);
  38 + }
  39 +
  40 + public DYVideoLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  41 + super(context, attrs, defStyleAttr);
  42 +
  43 + //获取颜色值和最小宽高度,以及进度条最小宽度
  44 + TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DYVideoLoadingView);
  45 + String color = typedArray.getString(R.styleable.DYVideoLoadingView_amberprogressColor);
  46 + mDefaultWidth = (int) typedArray.getDimension(R.styleable.DYVideoLoadingView_amberminWidth, 600);
  47 + mDefaultHeight = (int) typedArray.getDimension(R.styleable.DYVideoLoadingView_amberminHeight, 5);
  48 + mMinProgressWidth = (int) typedArray.getDimension(R.styleable.DYVideoLoadingView_amberminProgressWidth, 100);
  49 + mProgressWidth = mMinProgressWidth;
  50 +
  51 + //根据正则表达式来判断颜色格式是否正确
  52 + String regularStr = "^#[A-Fa-f0-9]{6}";
  53 + Pattern compile = Pattern.compile(regularStr);
  54 + if (color == null) {
  55 + mColor = "#808080";
  56 + } else {
  57 + Matcher matcher = compile.matcher(color);
  58 + if (matcher.matches()) {//如果颜色格式正确
  59 + mColor = color;
  60 + } else {
  61 + //如果颜色格式不正确
  62 + throw new IllegalArgumentException("wrong color string type!");
  63 + }
  64 + }
  65 + typedArray.recycle();
  66 +
  67 +
  68 +
  69 + /* //设置view的默认最小宽度
  70 + mDefaultWidth=600;
  71 + //设置view的默认最小高度
  72 + mDefaultHeight=5;
  73 + //设置进度条的初始宽度,这个宽度不能大于view的最小宽度,否则进度条不能向两边延伸
  74 + mProgressWidth=100;
  75 + //设置默认初始颜色
  76 + mColor="#808080";*/
  77 +
  78 + mPaint = new Paint();
  79 + //设置虎逼模式为填充带边框
  80 + mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
  81 + //设置抗锯齿
  82 + mPaint.setAntiAlias(true);
  83 + }
  84 +
  85 + /**
  86 + * 设置重绘的周期
  87 + *
  88 + * @param timePeriod
  89 + */
  90 + public void setTimePeriod(int timePeriod) {
  91 + if (mTimePeriod > 0) {
  92 + this.mTimePeriod = timePeriod;
  93 + }
  94 + }
  95 +
  96 + @Override
  97 + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  98 + super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  99 + //通过widthMeasureSpec,heightMeasureSpec 来获取view的测量模式和宽高
  100 + int width = getValue(widthMeasureSpec, true);
  101 + int height = getValue(heightMeasureSpec, false);
  102 +
  103 + //此方法用来设置设置View的具体宽高
  104 + setMeasuredDimension(width, height);
  105 + }
  106 +
  107 + /**
  108 + * 获取view的宽高值
  109 + *
  110 + * @param measureSpec
  111 + * @param isWidth 是否是测量宽度
  112 + * @return
  113 + */
  114 + private int getValue(int measureSpec, boolean isWidth) {
  115 + //获取测量模式
  116 + int mode = MeasureSpec.getMode(measureSpec);
  117 + //获取测量的值
  118 + int size = MeasureSpec.getSize(measureSpec);
  119 + switch (mode) {
  120 + /**
  121 + * 如果父控件传递给的MeasureSpec的mode是MeasureSpec.UNSPECIFIED,就说明,父控件对自己没有任何限制,那么尺寸就选择自己需要的尺寸size
  122 +
  123 + 如果父控件传递给的MeasureSpec的mode是MeasureSpec.EXACTLY,就说明父控件有明确的要求,希望自己能用measureSpec中的尺寸,这时就推荐使用MeasureSpec.getSize(measureSpec)
  124 +
  125 + 如果父控件传递给的MeasureSpec的mode是MeasureSpec.AT_MOST,就说明父控件希望自己不要超出MeasureSpec.getSize(measureSpec),如果超出了,就选择MeasureSpec.getSize(measureSpec),否则用自己想要的尺寸就行了
  126 + */
  127 + case MeasureSpec.EXACTLY:
  128 + //子view的大小已经被限定死,我们只能使用其固定大小
  129 + return size;
  130 + case MeasureSpec.AT_MOST:
  131 + //父控件认为子view的大小不能超过size的值,那么我们就取size和默认值之间的最小值
  132 + return Math.min(isWidth ? mDefaultWidth : mDefaultHeight, size);
  133 + case MeasureSpec.UNSPECIFIED:
  134 + //父view不限定子view的大小,我们将其值设置为默认值
  135 + return isWidth ? mDefaultWidth : mDefaultHeight;
  136 + default:
  137 + return isWidth ? mDefaultWidth : mDefaultHeight;
  138 + }
  139 + }
  140 +
  141 + @Override
  142 + protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  143 + super.onSizeChanged(w, h, oldw, oldh);
  144 + mWidth = w;
  145 + mHeight = h;
  146 + if (mWidth < mProgressWidth) {
  147 + //如果宽度小于进度条的宽度
  148 + Log.d(TAG, "the progressWidth must less than mWidth");
  149 + }
  150 + mPaint.setStrokeWidth(mHeight);
  151 + }
  152 +
  153 + @Override
  154 + protected void onDraw(Canvas canvas) {
  155 + super.onDraw(canvas);
  156 + //首先判断进度条的宽度是否大于view宽度
  157 + if (mProgressWidth < mWidth) {
  158 + //如果不大于,将进度条宽度增加10
  159 + mProgressWidth += 25;//注意执行此步骤是mProgressWidth值有可能大于view宽度;
  160 + } else {
  161 + //如果进度条宽度大于view宽度将进度条宽度设置为初始宽度
  162 + mProgressWidth = mMinProgressWidth;
  163 + }
  164 + //计算颜色透明度
  165 + //mProgressWidth/mWidth 计算当前进度条宽度占总宽度的比例
  166 + //255*mProgressWidth/mWidth 计算当前比例下对应的透明度值
  167 + //由于是由不透明变成全透明,所以使用255减去其值
  168 + int currentColorValue = 255;
  169 + if (mWidth != 0){
  170 + currentColorValue = 255 - 255 * mProgressWidth / mWidth;
  171 + }
  172 + if (currentColorValue > 255) {
  173 + //由于mProgressWidth有可能大于view的宽度,要保证颜色值不能大于255
  174 + currentColorValue = 255;
  175 + }
  176 + if (currentColorValue < 30) {
  177 + //此处是为了限制让其不成为全透明,如果设置为全透明,在最后阶段进度宽度渐变观察不到
  178 + currentColorValue = 30;
  179 + }
  180 + //将透明度转换为16进制
  181 + String s = Integer.toHexString(currentColorValue);
  182 + //拼接颜色字符串并转化为颜色值
  183 + int color = Color.parseColor("#" + mColor.substring(1, mColor.length()));
  184 + //给画笔设置颜色
  185 + mPaint.setColor(color);
  186 + //使用canvas来画进度条(确实就是画一条线)
  187 + canvas.drawLine(mWidth / 2 - mProgressWidth / 2, mDefaultHeight / 2, mWidth / 2 + mProgressWidth / 2,
  188 + mDefaultHeight / 2, mPaint);
  189 + }
  190 +
  191 + public void startAnimation() {
  192 + mHandler = new Handler() {
  193 + @Override
  194 + public void handleMessage(Message msg) {
  195 + super.handleMessage(msg);
  196 + invalidate();
  197 + this.sendEmptyMessageDelayed(1, mTimePeriod);
  198 + }
  199 + };
  200 + mHandler.sendEmptyMessageDelayed(1, mTimePeriod);
  201 + }
  202 +
  203 + public void stopAnimation() {
  204 + if (mHandler != null) {
  205 + mHandler.removeMessages(1);
  206 + }
  207 + }
  208 +}
  1 +package com.wd.common.widget;
  2 +
  3 +import android.content.Context;
  4 +import android.content.res.TypedArray;
  5 +import android.util.AttributeSet;
  6 +import android.widget.ScrollView;
  7 +
  8 +import com.wd.fastcoding.base.R;
  9 +import com.wd.foundation.wdkit.utils.UiUtils;
  10 +
  11 +
  12 +/**
  13 + * 描述:最大滚动高度
  14 + *
  15 + * @author : lvjinhui
  16 + * @since: 2023/11/2
  17 + */
  18 +public class MaxHeightScrollView extends ScrollView {
  19 +
  20 + private int maxHeight;
  21 +
  22 + public MaxHeightScrollView(Context context) {
  23 + this(context, null);
  24 + }
  25 +
  26 + public MaxHeightScrollView(Context context, AttributeSet attrs) {
  27 + this(context, attrs, 0);
  28 + }
  29 +
  30 + public MaxHeightScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
  31 + super(context, attrs, defStyleAttr);
  32 +
  33 + TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaxHeightScrollView);
  34 + maxHeight = typedArray.getDimensionPixelSize(R.styleable.MaxHeightScrollView_maxScrollHeight,
  35 + UiUtils.dp2px(R.dimen.rmrb_dp330));
  36 + typedArray.recycle();
  37 + }
  38 +
  39 + public void setMaxHeight(int maxHeight){
  40 + this.maxHeight = maxHeight;
  41 + invalidate();
  42 + }
  43 +
  44 + @Override
  45 + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  46 + super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST));
  47 + }
  48 +}
  1 +/*
  2 + * Copyright (c) People Technologies Co., Ltd. 2019-2022. All rights reserved.
  3 + */
  4 +
  5 +package com.wd.common.widget;
  6 +
  7 +import android.animation.Animator;
  8 +import android.animation.AnimatorListenerAdapter;
  9 +import android.animation.AnimatorSet;
  10 +import android.animation.ObjectAnimator;
  11 +import android.animation.TimeInterpolator;
  12 +import android.content.Context;
  13 +import android.os.SystemClock;
  14 +import android.util.AttributeSet;
  15 +import android.view.MotionEvent;
  16 +import android.view.View;
  17 +import android.view.animation.LinearInterpolator;
  18 +import android.widget.ImageView;
  19 +import android.widget.RelativeLayout;
  20 +
  21 +
  22 +import com.wd.base.log.Logger;
  23 +import com.wd.common.listener.MyClickListener;
  24 +import com.wd.fastcoding.base.R;
  25 +
  26 +import java.security.SecureRandom;
  27 +
  28 +/**
  29 + * 描述:点赞动画view
  30 + *
  31 + * @author : lvjinhui
  32 + * @since: 2022/7/7
  33 + */
  34 +public class ThumbsUpView extends RelativeLayout {
  35 + /**
  36 + * 点击的时间间隔
  37 + */
  38 + private static long INTERVAL = 300;
  39 +
  40 + /**
  41 + * 记录上一次的点击时间
  42 + */
  43 + private long lastClickTime = 0;
  44 +
  45 + private final long value0_5 = 50L;
  46 +
  47 + private final long value1 = 100L;
  48 +
  49 + private final long value1_5 = 150L;
  50 +
  51 + private final int value1_5_int = 150;
  52 +
  53 + private final int value2 = 200;
  54 +
  55 + private final int value3 = 150;
  56 +
  57 + private final long value3L = 300L;
  58 +
  59 + private final long value4 = 400L;
  60 +
  61 + private final Float value6 = -600F;
  62 +
  63 + private final long value7 = 700L;
  64 +
  65 + private final long value8 = 800L;
  66 +
  67 + private Context mContext;
  68 +
  69 + /**
  70 + * 随机心形图片角度
  71 + */
  72 + private float[] num = {-30, -20, 0, 20, 30};
  73 +
  74 + private long[] mHits = new long[2];
  75 +
  76 + private MyClickListener.MyClickCallBack clickCallBack;
  77 +
  78 + private MyClickListener myClickListener;
  79 +
  80 + private int drawableId = R.mipmap.icon_bottom_liked;
  81 +
  82 + public ThumbsUpView(Context context) {
  83 + this(context, null);
  84 + }
  85 +
  86 + public ThumbsUpView(Context context, AttributeSet attrs) {
  87 + this(context, attrs, 0);
  88 + }
  89 +
  90 + public ThumbsUpView(Context context, AttributeSet attrs, int defStyleAttr) {
  91 + super(context, attrs, defStyleAttr);
  92 + this.mContext = context;
  93 + }
  94 +
  95 + public void setAnimalDrawableId(int drawableId) {
  96 + this.drawableId = drawableId;
  97 + }
  98 +
  99 + /**
  100 + * 监听点击事件
  101 + *
  102 + * @param event
  103 + * @return
  104 + */
  105 + @Override
  106 + public boolean dispatchTouchEvent(MotionEvent event) {
  107 +
  108 + switch (event.getAction()) {
  109 + case MotionEvent.ACTION_DOWN:
  110 + // 获取点击时间
  111 + long currTime = SystemClock.uptimeMillis();
  112 + // 判断点击之间的时间差
  113 + long interval = currTime - lastClickTime;
  114 + lastClickTime = currTime;
  115 + // 小于0.2秒,拦截事件,并做处理
  116 + if (interval < INTERVAL) {
  117 + setAnnouncement(event.getX(),event.getY());
  118 + }
  119 + break;
  120 + default:
  121 + break;
  122 + }
  123 + return super.dispatchTouchEvent(event);
  124 +
  125 + }
  126 +
  127 + @Override
  128 + public boolean onTouchEvent(MotionEvent event) {
  129 + if (myClickListener!=null){
  130 + myClickListener.onTouch(this,event);
  131 + }
  132 + return super.onTouchEvent(event);
  133 + }
  134 +
  135 + private ObjectAnimator scaleAni(View view, String propertyName, Float from, Float to, Long time, Long delay) {
  136 + ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, propertyName, from, to);
  137 + objectAnimator.setInterpolator(new LinearInterpolator());
  138 + objectAnimator.setStartDelay(delay);
  139 + objectAnimator.setDuration(time);
  140 + return objectAnimator;
  141 + }
  142 +
  143 + private ObjectAnimator translationX(View view, Float from, Float to, Long time, Long delayTime) {
  144 + ObjectAnimator ani = ObjectAnimator.ofFloat(view, "translationX", from, to);
  145 + ani.setInterpolator(new LinearInterpolator());
  146 + ani.setStartDelay(delayTime);
  147 + ani.setDuration(time);
  148 + return ani;
  149 + }
  150 +
  151 + private ObjectAnimator translationY(View view, Float from, Float to, Long time, Long delayTime) {
  152 + ObjectAnimator ani = ObjectAnimator.ofFloat(view, "translationY", from, to);
  153 + ani.setInterpolator(new LinearInterpolator());
  154 + ani.setStartDelay(delayTime);
  155 + ani.setDuration(time);
  156 + return ani;
  157 + }
  158 +
  159 + private ObjectAnimator alphaAni(View view, Float from, Float to, Long time, Long delayTime) {
  160 + ObjectAnimator ani = ObjectAnimator.ofFloat(view, "alpha", from, to);
  161 + ani.setInterpolator(new LinearInterpolator());
  162 + ani.setStartDelay(delayTime);
  163 + ani.setDuration(time);
  164 + return ani;
  165 + }
  166 +
  167 + private ObjectAnimator rotation(View view, Long time, Long delayTime, Float values) {
  168 + ObjectAnimator ani = ObjectAnimator.ofFloat(view, "rotation", values);
  169 + ani.setInterpolator(new TimeInterpolator() {
  170 + @Override
  171 + public float getInterpolation(float input) {
  172 + return 0;
  173 + }
  174 + });
  175 + ani.setStartDelay(delayTime);
  176 + ani.setDuration(time);
  177 + return ani;
  178 + }
  179 +
  180 + public void setOnClickListener(MyClickListener.MyClickCallBack onClickListener) {
  181 + this.clickCallBack = onClickListener;
  182 + myClickListener = new MyClickListener(clickCallBack);
  183 + }
  184 +
  185 + public MyClickListener.MyClickCallBack getOnClickListener() {
  186 + return clickCallBack;
  187 + }
  188 +
  189 + public void setAnnouncement(float x,float y){
  190 + Logger.t("ThumbsUpView").i("点击动画 ===> x y"+x +"/"+y);
  191 + if(drawableId == -1){
  192 + return;
  193 + }
  194 + final ImageView imageView = new ImageView(mContext);
  195 + // 设置展示的位置,需要在手指触摸的位置上方,即触摸点是心形的右下角的位置
  196 + LayoutParams params = new LayoutParams(value2, value2);
  197 + params.leftMargin = (int) x - value1_5_int;
  198 + params.topMargin = (int) y - value3;
  199 + // 设置图片资源
  200 + imageView.setImageDrawable(getResources().getDrawable(drawableId));
  201 + imageView.setLayoutParams(params);
  202 + // 把IV添加到父布局当中
  203 + addView(imageView);
  204 + // 设置控件的动画
  205 + AnimatorSet animatorSet = new AnimatorSet();
  206 + // 缩放动画,X轴2倍缩小至0 .9倍
  207 + animatorSet.play(scaleAni(imageView, "scaleX", 2f, 0.9f, value1, 0L))
  208 + // 缩放动画,Y轴2倍缩放至0.9倍
  209 + .with(scaleAni(imageView, "scaleY", 2f, 0.9f, value1, 0L))
  210 + // 旋转动画,随机旋转角
  211 + .with(rotation(imageView, 0L, 0L, num[new SecureRandom().nextInt(4)]))
  212 + // 渐变透明动画,透明度从0-1
  213 + .with(alphaAni(imageView, 0F, 1F, value1, 0L))
  214 + // 缩放动画,X轴0.9倍缩小至
  215 + .with(scaleAni(imageView, "scaleX", 0.9f, 1F, value0_5, value1_5))
  216 + // 缩放动画,Y轴0.9倍缩放至
  217 + .with(scaleAni(imageView, "scaleY", 0.9f, 1F, value0_5, value1_5))
  218 + // 位移动画,Y轴从0上移至600
  219 + .with(translationY(imageView, 0f, value6, value8, value4))
  220 + // 透明动画,从1-0
  221 + .with(alphaAni(imageView, 1F, 0F, value3L, value4))
  222 + // 缩放动画,X轴1至3倍
  223 + .with(scaleAni(imageView, "scaleX", 1F, 3F, value7, value4))
  224 + // 缩放动画,Y轴1至3倍
  225 + .with(scaleAni(imageView, "scaleY", 1F, 3F, value7, value4));
  226 + // 开始动画
  227 + animatorSet.start();
  228 + // 设置动画结束监听
  229 + animatorSet.addListener(new AnimatorListenerAdapter() {
  230 + @Override
  231 + public void onAnimationEnd(Animator animation) {
  232 + super.onAnimationEnd(animation);
  233 + // 当动画结束以后,需要把控件从父布局移除
  234 + removeViewInLayout(imageView);
  235 + }
  236 + });
  237 + }
  238 +
  239 +
  240 +}
  1 +package com.wd.common.widget;
  2 +
  3 +import android.content.Context;
  4 +import android.util.AttributeSet;
  5 +import android.view.View;
  6 +import android.widget.TextView;
  7 +
  8 +import androidx.annotation.NonNull;
  9 +import androidx.annotation.Nullable;
  10 +
  11 +import com.airbnb.lottie.LottieAnimationView;
  12 +import com.scwang.smart.refresh.layout.api.RefreshFooter;
  13 +import com.scwang.smart.refresh.layout.api.RefreshLayout;
  14 +import com.scwang.smart.refresh.layout.constant.RefreshState;
  15 +import com.scwang.smart.refresh.layout.constant.SpinnerStyle;
  16 +import com.scwang.smart.refresh.layout.simple.SimpleComponent;
  17 +import com.wd.fastcoding.base.R;
  18 +import com.wd.foundation.wdkit.utils.AnimUtil;
  19 +
  20 +/**
  21 + * 上推加载更多
  22 + */
  23 +public class VideoLoadMoreFooter extends SimpleComponent implements RefreshFooter {
  24 +
  25 + private LottieAnimationView animationView;
  26 + private TextView tvDesc;
  27 + private RefreshState newState;
  28 +
  29 + public VideoLoadMoreFooter(Context context) {
  30 + this(context, null);
  31 + }
  32 +
  33 + public VideoLoadMoreFooter(Context context, @Nullable AttributeSet attrs) {
  34 + this(context, attrs, 0);
  35 + }
  36 +
  37 + public VideoLoadMoreFooter(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  38 + super(context, attrs, defStyleAttr);
  39 + View view = View.inflate(context, R.layout.refresh_loading_more, this);
  40 + animationView = view.findViewById(R.id.animation_view);
  41 + tvDesc = view.findViewById(R.id.tv_desc);
  42 + }
  43 +
  44 + public void setDescTextColor(int colorId) {
  45 + if (tvDesc != null) {
  46 + tvDesc.setTextColor(colorId);
  47 + }
  48 + }
  49 +
  50 + /**
  51 + * 获取真实视图(必须返回,不能为null)一般就是返回当前自定义的view
  52 + */
  53 + @NonNull
  54 + @Override
  55 + public View getView() {
  56 + return this;
  57 + }
  58 +
  59 +
  60 + /**
  61 + * 获取变换方式(必须指定一个:平移、拉伸、固定、全屏),Translate指平移,大多数都是平移
  62 + */
  63 + @NonNull
  64 + @Override
  65 + public SpinnerStyle getSpinnerStyle() {
  66 + return SpinnerStyle.Translate;
  67 + }
  68 +
  69 +
  70 + /**
  71 + * 手指拖动下拉(会连续多次调用,用于实时控制动画关键帧)
  72 + *
  73 + * @param percent 下拉的百分比 值 = offset/headerHeight (0 - percent - (headerHeight+maxDragHeight) / headerHeight )
  74 + * @param offset 下拉的像素偏移量 0 - offset - (headerHeight+maxDragHeight)
  75 + * @param height Header的高度
  76 + * @param maxDragHeight 最大拖动高度
  77 + */
  78 + @Override
  79 + public void onMoving(boolean isDragging, float percent, int offset, int height, int maxDragHeight) {
  80 +// Log.e("下拉刷新", "onMoving-> percent:" + percent + " offset:" + " height:" + height + " ");
  81 + if (newState != RefreshState.Refreshing) {
  82 + animationView.setProgress(percent % 1);
  83 + }
  84 + }
  85 +
  86 + /**
  87 + * 一般可以理解为一下case中的三种状态,在达到相应状态时候开始改变
  88 + * 注意:这三种状态都是初始化的状态
  89 + */
  90 + @Override
  91 + public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
  92 + this.newState = newState;
  93 + // Log.e("上推刷新", "onStateChanged->newState:" + newState);
  94 +
  95 + switch (newState) {
  96 + case None:
  97 + animationView.pauseAnimation();
  98 + setVisibility(View.GONE);
  99 + break;
  100 + case PullUpToLoad:
  101 +// animationView.playAnimation();
  102 + tvDesc.setText(R.string.up_load_more);
  103 + setVisibility(View.VISIBLE);
  104 + AnimUtil.showLocalLottieEffects(animationView,"video_loading_more.json", true);
  105 + break;
  106 + default:
  107 + break;
  108 +
  109 + }
  110 + }
  111 +
  112 +
  113 + /**
  114 + * 开始动画(开始刷新或者开始加载动画)
  115 + *
  116 + * @param layout RefreshLayout
  117 + * @param height HeaderHeight or FooterHeight
  118 + * @param maxDragHeight 最大拖动高度
  119 + */
  120 + @Override
  121 + public void onStartAnimator(@NonNull RefreshLayout layout, int height, int maxDragHeight) {
  122 +// Log.e("下拉刷新", "onStartAnimator");
  123 + }
  124 +}
  1 +package com.wd.common.widget.alertdialog;
  2 +
  3 +import android.content.Context;
  4 +import android.content.DialogInterface;
  5 +import android.util.SparseArray;
  6 +import android.view.Gravity;
  7 +import android.view.View;
  8 +import android.view.ViewGroup;
  9 +import android.view.Window;
  10 +import android.view.WindowManager;
  11 +
  12 +/**
  13 + * Time:2022/11/01
  14 + * Author:ypf
  15 + * Description:对话框视图控制器
  16 + */
  17 +class AlertController {
  18 +
  19 + private final AlertDialog mDialog;
  20 +
  21 + private DialogViewHelper mViewHelper;
  22 +
  23 + public AlertController(AlertDialog dialog) {
  24 + this.mDialog = dialog;
  25 + }
  26 +
  27 + public void setViewHelper(DialogViewHelper viewHelper) {
  28 + this.mViewHelper = viewHelper;
  29 + }
  30 +
  31 + /**
  32 + * 设置文本
  33 + *
  34 + * @param viewId 控件id
  35 + * @param text 文本内容
  36 + */
  37 + public void setText(int viewId, CharSequence text) {
  38 + mViewHelper.setText(viewId, text);
  39 + }
  40 +
  41 + /**
  42 + * 获取控件视图
  43 + *
  44 + * @param viewId 控件id
  45 + */
  46 + public <T extends View> T getView(int viewId) {
  47 + return mViewHelper.getView(viewId);
  48 + }
  49 +
  50 + /**
  51 + * 设置点击事件
  52 + *
  53 + * @param viewId 控件id
  54 + * @param listener 控件点击监听
  55 + */
  56 + public void setOnClickListener(int viewId, IDialogInterface.IOnClickListener listener) {
  57 + mViewHelper.setOnClickListener(viewId, mDialog, listener);
  58 + }
  59 +
  60 + /**
  61 + * 获取Dialog
  62 + *
  63 + * @return AlertDialog对话框
  64 + */
  65 + public AlertDialog getDialog() {
  66 + return mDialog;
  67 + }
  68 +
  69 + /**
  70 + * 获取Dialog的Window
  71 + *
  72 + * @return Window窗口
  73 + */
  74 + public Window getWindow() {
  75 + return mDialog.getWindow();
  76 + }
  77 +
  78 + public static class AlertParams {
  79 + public Context mContext;
  80 + public int mThemeResId;
  81 + // 点击空白是否能够取消 默认点击阴影可以取消
  82 + public boolean mCancelable = true;
  83 + // dialog Cancel监听
  84 + public DialogInterface.OnCancelListener mOnCancelListener;
  85 + // dialog Dismiss监听
  86 + public DialogInterface.OnDismissListener mOnDismissListener;
  87 + // dialog Key监听
  88 + public DialogInterface.OnKeyListener mOnKeyListener;
  89 + // 布局layout id
  90 + public int mViewLayoutResId;
  91 + // 存放文本的修改
  92 + public SparseArray<CharSequence> mTextArray = new SparseArray<>();
  93 + // 存放点击事件
  94 + public SparseArray<IDialogInterface.IOnClickListener> mClickArray = new SparseArray<>();
  95 + // 宽度
  96 + public int mWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
  97 + // 高度
  98 + public int mHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
  99 + // 动画
  100 + public int mAnimations = 0;
  101 + // 位置
  102 + public int mGravity = Gravity.CENTER;
  103 +
  104 + public AlertParams(Context context, int themeResId) {
  105 + this.mContext = context;
  106 + this.mThemeResId = themeResId;
  107 + }
  108 +
  109 + /**
  110 + * 绑定和设置参数
  111 + *
  112 + * @param alertController 对话框控制器
  113 + */
  114 + public void apply(AlertController alertController) {
  115 + // 完善这个地方 设置参数
  116 +
  117 + // 1. 设置Dialog布局 DialogViewHelper
  118 + DialogViewHelper viewHelper = null;
  119 + if (mViewLayoutResId != 0) {
  120 + viewHelper = new DialogViewHelper(alertController.getWindow());
  121 + }
  122 +
  123 + if (viewHelper == null) {
  124 + throw new IllegalArgumentException("请设置布局setContentView()");
  125 + }
  126 +
  127 + // 给Dialog 设置布局
  128 + alertController.getDialog().setContentView(mViewLayoutResId);
  129 +
  130 + // 设置 Controller的辅助类
  131 + alertController.setViewHelper(viewHelper);
  132 +
  133 + // 2.设置文本
  134 + int textArraySize = mTextArray.size();
  135 + for (int i = 0; i < textArraySize; i++) {
  136 + alertController.setText(mTextArray.keyAt(i), mTextArray.valueAt(i));
  137 + }
  138 +
  139 + // 3.设置点击
  140 + int clickArraySize = mClickArray.size();
  141 + for (int i = 0; i < clickArraySize; i++) {
  142 + alertController.setOnClickListener(mClickArray.keyAt(i), mClickArray.valueAt(i));
  143 + }
  144 +
  145 + // 4.配置自定义的效果 全屏从底部弹出默认动画
  146 + Window window = alertController.getWindow();
  147 + // 设置位置
  148 + window.setGravity(mGravity);
  149 +
  150 + // 设置动画
  151 + if (mAnimations != 0) {
  152 + window.setWindowAnimations(mAnimations);
  153 + }
  154 +
  155 + // 设置宽高
  156 + WindowManager.LayoutParams params = window.getAttributes();
  157 + params.width = mWidth;
  158 + params.height = mHeight;
  159 + window.setAttributes(params);
  160 + }
  161 +
  162 + }
  163 +
  164 +}
  1 +package com.wd.common.widget.alertdialog;
  2 +
  3 +import android.app.Dialog;
  4 +import android.content.Context;
  5 +import android.view.Gravity;
  6 +import android.view.View;
  7 +import android.view.ViewGroup;
  8 +
  9 +import com.wd.fastcoding.base.R;
  10 +
  11 +
  12 +/**
  13 + * Time:2022/11/01
  14 + * Author:ypf
  15 + * Description:自定义万能Dialog
  16 + */
  17 +public class AlertDialog extends Dialog {
  18 +
  19 + private final AlertController mAlertController;
  20 +
  21 + public AlertDialog(Context context, int themeResId) {
  22 + super(context, themeResId);
  23 + mAlertController = new AlertController(this);
  24 + }
  25 +
  26 + /**
  27 + * 设置文本
  28 + *
  29 + * @param viewId 控件id
  30 + * @param text 文本内容
  31 + */
  32 + public void setText(int viewId, CharSequence text) {
  33 + mAlertController.setText(viewId, text);
  34 + }
  35 +
  36 + /**
  37 + * 获取控件视图
  38 + *
  39 + * @param viewId 控件id
  40 + */
  41 + public <T extends View> T getView(int viewId) {
  42 + return mAlertController.getView(viewId);
  43 + }
  44 +
  45 + /**
  46 + * 设置点击事件
  47 + *
  48 + * @param viewId 控件id
  49 + * @param listener 控件点击监听
  50 + */
  51 + public void setOnClickListener(int viewId, IDialogInterface.IOnClickListener listener) {
  52 + mAlertController.setOnClickListener(viewId, listener);
  53 + }
  54 +
  55 + public static class Builder {
  56 +
  57 + private final AlertController.AlertParams P;
  58 +
  59 + public Builder(Context context) {
  60 + this(context, R.style.CenterDialogStyle);
  61 + }
  62 +
  63 + public Builder(Context context, int themeResId) {
  64 + P = new AlertController.AlertParams(context, themeResId);
  65 + }
  66 +
  67 + // 设置布局内容的layoutId
  68 + public Builder setContentView(int layoutId) {
  69 + P.mViewLayoutResId = layoutId;
  70 + return this;
  71 + }
  72 +
  73 + // 设置文本
  74 + public Builder setText(int viewId, CharSequence text) {
  75 + P.mTextArray.put(viewId, text);
  76 + return this;
  77 + }
  78 +
  79 + // 设置点击事件
  80 + public Builder setOnClickListener(int view, IDialogInterface.IOnClickListener listener) {
  81 + P.mClickArray.put(view, listener);
  82 + return this;
  83 + }
  84 +
  85 + // 配置一些万能的参数
  86 + public Builder fullWidth() {
  87 + P.mWidth = ViewGroup.LayoutParams.MATCH_PARENT;
  88 + return this;
  89 + }
  90 +
  91 + /**
  92 + * 从底部弹出
  93 + *
  94 + * @param isAnimation 是否有动画
  95 + * @return Builder
  96 + */
  97 + public Builder fromBottom(boolean isAnimation) {
  98 + if (isAnimation) {
  99 + P.mAnimations = R.style.dialog_from_bottom_anim;
  100 + }
  101 + P.mGravity = Gravity.BOTTOM;
  102 + return this;
  103 + }
  104 +
  105 + /**
  106 + * 设置Dialog的宽高
  107 + *
  108 + * @param width 对话框宽
  109 + * @param height 对话框高
  110 + * @return Builder
  111 + */
  112 + public Builder setWidthAndHeight(int width, int height) {
  113 + P.mWidth = width;
  114 + P.mHeight = height;
  115 + return this;
  116 + }
  117 +
  118 + /**
  119 + * 添加默认动画
  120 + *
  121 + * @return Builder
  122 + */
  123 + public Builder addDefaultAnimation() {
  124 + P.mAnimations = R.style.dialog_scale_anim;
  125 + return this;
  126 + }
  127 +
  128 + /**
  129 + * 设置动画
  130 + *
  131 + * @param styleAnimation 动画
  132 + * @return Builder
  133 + */
  134 + public Builder setAnimations(int styleAnimation) {
  135 + P.mAnimations = styleAnimation;
  136 + return this;
  137 + }
  138 +
  139 + public Builder setCancelable(boolean cancelable) {
  140 + P.mCancelable = cancelable;
  141 + return this;
  142 + }
  143 +
  144 + public Builder setOnCancelListener(OnCancelListener onCancelListener) {
  145 + P.mOnCancelListener = onCancelListener;
  146 + return this;
  147 + }
  148 +
  149 + public Builder setOnDismissListener(OnDismissListener onDismissListener) {
  150 + P.mOnDismissListener = onDismissListener;
  151 + return this;
  152 + }
  153 +
  154 + public Builder setOnKeyListener(OnKeyListener onKeyListener) {
  155 + P.mOnKeyListener = onKeyListener;
  156 + return this;
  157 + }
  158 +
  159 + public AlertDialog create() {
  160 + // Context has already been wrapped with the appropriate theme.
  161 + final AlertDialog dialog = new AlertDialog(P.mContext, P.mThemeResId);
  162 + P.apply(dialog.mAlertController);
  163 + dialog.setCancelable(P.mCancelable);
  164 + if (P.mCancelable) {
  165 + dialog.setCanceledOnTouchOutside(true);
  166 + }
  167 + dialog.setOnCancelListener(P.mOnCancelListener);
  168 + dialog.setOnDismissListener(P.mOnDismissListener);
  169 + if (P.mOnKeyListener != null) {
  170 + dialog.setOnKeyListener(P.mOnKeyListener);
  171 + }
  172 + return dialog;
  173 + }
  174 +
  175 + public AlertDialog show() {
  176 + final AlertDialog dialog = create();
  177 + dialog.show();
  178 + return dialog;
  179 + }
  180 + }
  181 +
  182 +}
  1 +package com.wd.common.widget.alertdialog;
  2 +
  3 +import android.util.SparseArray;
  4 +import android.view.View;
  5 +import android.view.Window;
  6 +import android.widget.TextView;
  7 +
  8 +import java.lang.ref.WeakReference;
  9 +
  10 +/**
  11 + * Time:2022/11/02
  12 + * Author:ypf
  13 + * Description:对话框视图辅助处理类
  14 + */
  15 +class DialogViewHelper {
  16 +
  17 + //上下文
  18 + private WeakReference<Window> mWindow;
  19 + // 防止霸气侧漏
  20 + private final SparseArray<WeakReference<View>> mViews;
  21 +
  22 + public DialogViewHelper(Window window) {
  23 + mWindow = new WeakReference<>(window);
  24 + mViews = new SparseArray<>();
  25 + }
  26 +
  27 + /**
  28 + * 设置文本
  29 + *
  30 + * @param viewId 控件id
  31 + * @param text 文本内容
  32 + */
  33 + public void setText(int viewId, CharSequence text) {
  34 + // 每次都 findViewById 减少findViewById的次数
  35 + TextView tv = getView(viewId);
  36 + if (tv != null) {
  37 + tv.setText(text);
  38 + }
  39 + }
  40 +
  41 + public <T extends View> T getView(int viewId) {
  42 + WeakReference<View> viewReference = mViews.get(viewId);
  43 + // 侧漏的问题 到时候到这个系统优化的时候再去介绍
  44 + View view = null;
  45 + if (viewReference != null) {
  46 + view = viewReference.get();
  47 + }
  48 +
  49 + if (view == null) {
  50 + view = mWindow.get().findViewById(viewId);
  51 + if (view != null) {
  52 + mViews.put(viewId, new WeakReference<>(view));
  53 + }
  54 + }
  55 + return (T) view;
  56 + }
  57 +
  58 + /**
  59 + * 设置点击事件
  60 + *
  61 + * @param viewId 控件id
  62 + * @param listener 控件点击监听
  63 + */
  64 + public void setOnClickListener(int viewId, AlertDialog dialog, IDialogInterface.IOnClickListener listener) {
  65 + View view = getView(viewId);
  66 + if (view != null) {
  67 + view.setOnClickListener(v -> listener.onClick(dialog, v));
  68 + }
  69 + }
  70 +
  71 +}
  1 +package com.wd.common.widget.alertdialog;
  2 +
  3 +import android.view.View;
  4 +
  5 +/**
  6 + * Time:2022/12/1
  7 + * Author:ypf
  8 + * Description:对话框相关接口
  9 + */
  10 +public interface IDialogInterface {
  11 +
  12 + /**
  13 + * 对话框中控件点击事件回调
  14 + */
  15 + interface IOnClickListener {
  16 + void onClick(AlertDialog dialog, View view);
  17 + }
  18 +
  19 +}
  1 +
  2 +package com.wd.common.widget.expand;
  3 +
  4 +import android.content.Context;
  5 +import android.content.res.TypedArray;
  6 +import android.graphics.drawable.Drawable;
  7 +import android.os.Build;
  8 +import android.text.Layout;
  9 +import android.text.StaticLayout;
  10 +import android.text.TextPaint;
  11 +import android.text.TextUtils;
  12 +import android.util.AttributeSet;
  13 +import android.util.TypedValue;
  14 +import android.view.View;
  15 +import android.view.ViewGroup;
  16 +import android.view.ViewTreeObserver;
  17 +import android.widget.FrameLayout;
  18 +import android.widget.LinearLayout;
  19 +import android.widget.RelativeLayout;
  20 +import android.widget.TextView;
  21 +
  22 +import com.wd.fastcoding.base.R;
  23 +import com.wd.foundation.wdkit.utils.TextViewUtils;
  24 +import com.wd.foundation.wdkit.utils.UiUtils;
  25 +
  26 +
  27 +public class BoldExpandTextView extends RelativeLayout implements View.OnClickListener {
  28 + private static final String TAG = BoldExpandTextView.class.getSimpleName();
  29 +
  30 + private static final String ELLIPSIS_STRING = new String(new char[]{'\u2026'});
  31 +
  32 + private static final int STYLE_DEFAULT = 0;
  33 +
  34 + private static final int STYLE_ICON = 1;
  35 +
  36 + private static final int STYLE_TEXT = 2;
  37 +
  38 + private Context mContext;
  39 +
  40 + private View mRootView;
  41 +
  42 + private TextView mTvContent;
  43 +
  44 + private LinearLayout mLayoutExpandMore;
  45 +
  46 + private TextView mTvExpand;
  47 +
  48 + private int mMeasuredWidth;
  49 +
  50 + /**
  51 + * 辅助TextView,保证末尾图标和文字与内容文字居中显示
  52 + */
  53 + private TextView mTvExpandHelper;
  54 +
  55 + private int mExpandIconResId;
  56 +
  57 + private int mExpandIconTop;
  58 +
  59 + private int mCollapseIconResId;
  60 +
  61 + private Drawable mExpandIconDrawable;
  62 +
  63 + private Drawable mCollapseIconDrawable;
  64 +
  65 + private String mExpandMoreStr;
  66 +
  67 + private String mCollapseLessStr;
  68 +
  69 + private int mMaxLines = 2;
  70 +
  71 + private int mContentTextSize;
  72 +
  73 + private int mExpandTextSize;
  74 +
  75 + private View newlineV;
  76 +
  77 + /**
  78 + * 是否展开
  79 + */
  80 + private boolean mIsExpand = false;
  81 +
  82 + /**
  83 + * 原内容文本
  84 + */
  85 + private String mOriginContentStr;
  86 +
  87 + /**
  88 + * 缩略后展示的文本
  89 + */
  90 + private CharSequence mEllipsizeStr;
  91 +
  92 + /**
  93 + * 主文字颜色
  94 + */
  95 + private int mContentTextColor;
  96 +
  97 + /**
  98 + * 展开/收起文字颜色
  99 + */
  100 + private int mExpandTextColor;
  101 +
  102 + /**
  103 + * 样式,默认为图标+文字样式
  104 + */
  105 + private int mExpandStyle = STYLE_DEFAULT;
  106 +
  107 + /**
  108 + * 展开/收缩布局对应图标的宽度,默认布局是15dp
  109 + */
  110 + private int mExpandIconWidth = 15;
  111 +
  112 + /**
  113 + * 缩略文本展示时与展开/搜索布局的间距,默认是20px
  114 + */
  115 + private int mSpaceMargin = 20;
  116 +
  117 + /**
  118 + * 文本显示的lineSpacingExtra,对应于TextView的lineSpacingExtra属性
  119 + */
  120 + private float mLineSpacingExtra = 0.0f;
  121 +
  122 + /**
  123 + * 文本显示的lineSpacingMultiplier,对应于TextView的lineSpacingMultiplier属性
  124 + */
  125 + private float mLineSpacingMultiplier = 1.0f;
  126 +
  127 + private OnExpandStateChangeListener mOnExpandStateChangeListener;
  128 +
  129 + private OnClickListener mListener;
  130 +
  131 + private boolean isShrink;
  132 +
  133 + /**
  134 + * 文字是否左右对齐
  135 + */
  136 + private boolean isJustify;
  137 +
  138 + /**
  139 + * 最后一行是否换行
  140 + */
  141 + private boolean linefeed = false;
  142 +
  143 + /**
  144 + * 监听器
  145 + */
  146 + public interface OnExpandStateChangeListener {
  147 + /**
  148 + * 展开时回调
  149 + */
  150 + void onExpand();
  151 +
  152 + /**
  153 + * 收起时回调
  154 + */
  155 + void onCollapse();
  156 +
  157 + }
  158 +
  159 + /**
  160 + * 监听器
  161 + */
  162 + public interface OnClickListener {
  163 + /**
  164 + *
  165 + */
  166 + void onClick();
  167 +
  168 + }
  169 +
  170 + public BoldExpandTextView(Context context) {
  171 + this(context, null);
  172 + }
  173 +
  174 + public BoldExpandTextView(Context context, AttributeSet attrs) {
  175 + this(context, attrs, 0);
  176 + }
  177 +
  178 + public BoldExpandTextView(Context context, AttributeSet attrs, int defStyleAttr) {
  179 + super(context, attrs, defStyleAttr);
  180 + mContext = context;
  181 + initAttributeSet(context, attrs);
  182 + initView();
  183 + }
  184 +
  185 + /**
  186 + * 初始化自定义属性
  187 + *
  188 + * @param context
  189 + * @param attrs
  190 + */
  191 + private void initAttributeSet(Context context, AttributeSet attrs) {
  192 + TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ExpandTextView);
  193 + if (ta != null) {
  194 + mMaxLines = ta.getInt(R.styleable.ExpandTextView_maxLines, 2);
  195 + mExpandIconResId = ta.getResourceId(R.styleable.ExpandTextView_expandIconResId, 0);
  196 + mExpandIconTop = ta.getResourceId(R.styleable.ExpandTextView_expandIconTop, 1);
  197 + mCollapseIconResId = ta.getResourceId(R.styleable.ExpandTextView_collapseIconResId, 0);
  198 + mExpandMoreStr = ta.getString(R.styleable.ExpandTextView_expandMoreText);
  199 + mCollapseLessStr = ta.getString(R.styleable.ExpandTextView_collapseLessText);
  200 + mContentTextSize = ta.getDimensionPixelSize(R.styleable.ExpandTextView_contentTextSize, sp2px(context, 14));
  201 + mContentTextColor = ta.getColor(R.styleable.ExpandTextView_contentTextColor, 0);
  202 + mExpandTextSize = ta.getDimensionPixelSize(R.styleable.ExpandTextView_expandTextSize, sp2px(context, 14));
  203 + mExpandTextColor = ta.getColor(R.styleable.ExpandTextView_expandTextColor, 0);
  204 + mExpandStyle = ta.getInt(R.styleable.ExpandTextView_expandStyle, STYLE_DEFAULT);
  205 + mExpandIconWidth = ta.getDimensionPixelSize(R.styleable.ExpandTextView_expandIconWidth, dp2px(context, 15));
  206 + mSpaceMargin = ta.getDimensionPixelSize(R.styleable.ExpandTextView_spaceMargin, dp2px(context, 6));
  207 + mLineSpacingExtra = ta.getDimensionPixelSize(R.styleable.ExpandTextView_lineSpacingExtra, 0);
  208 + mLineSpacingMultiplier = ta.getFloat(R.styleable.ExpandTextView_lineSpacingMultiplier, 1.0f);
  209 + isShrink = ta.getBoolean(R.styleable.ExpandTextView_isShrink, true);
  210 + isJustify = ta.getBoolean(R.styleable.ExpandTextView_isJustify, false);
  211 +
  212 + ta.recycle();
  213 + }
  214 + if (mMaxLines < 1) {
  215 + mMaxLines = 1;
  216 + }
  217 + }
  218 +
  219 + /**
  220 + * 初始化View
  221 + */
  222 + private void initView() {
  223 + // 由于左右对齐的自定义控件XQJustifyTextView,下拉刷新会闪烁。所以暂时活动列表不使用左右对齐的控件
  224 + mRootView = inflate(mContext, isJustify ? R.layout.layout_expand_justify : R.layout.layout_expand_bold, this);
  225 + mTvContent = findViewById(R.id.expand_content_tv);
  226 + mLayoutExpandMore = findViewById(R.id.expand_ll);
  227 + mTvExpand = findViewById(R.id.expand_tv);
  228 + newlineV = findViewById(R.id.newlineV);
  229 + mTvExpandHelper = findViewById(R.id.expand_helper_tv);
  230 +
  231 + TextViewUtils.setText(mTvExpand, mExpandMoreStr);
  232 + mTvContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, mContentTextSize);
  233 + // 辅助TextView,与内容TextView大小相等,保证末尾图标和文字与内容文字居中显示
  234 + mTvExpandHelper.setTextSize(TypedValue.COMPLEX_UNIT_PX, mContentTextSize);
  235 + mTvExpand.setTextSize(TypedValue.COMPLEX_UNIT_PX, mExpandTextSize);
  236 + mTvContent.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
  237 + mTvExpandHelper.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
  238 + mTvExpand.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
  239 + // 默认设置展开图标
  240 + setExpandMoreIcon(mExpandIconResId);
  241 + setCollapseLessIcon(mCollapseIconResId);
  242 + setContentTextColor(mContentTextColor);
  243 + setExpandTextColor(mExpandTextColor);
  244 + switch (mExpandStyle) {
  245 + case STYLE_ICON:
  246 + mTvExpand.setVisibility(GONE);
  247 + break;
  248 + case STYLE_TEXT:
  249 + mTvExpand.setVisibility(VISIBLE);
  250 + break;
  251 + default:
  252 + mTvExpand.setVisibility(VISIBLE);
  253 + break;
  254 + }
  255 + }
  256 +
  257 + @Override
  258 + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  259 + super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  260 + // Log.d(TAG, "onMeasure,measureWidth = " + getMeasuredWidth());
  261 + if (mMeasuredWidth <= 0 && getMeasuredWidth() > 0) {
  262 + mMeasuredWidth = getMeasuredWidth();
  263 + measureEllipsizeText(mMeasuredWidth);
  264 + }
  265 + }
  266 +
  267 + /**
  268 + * 设置文本内容
  269 + *
  270 + * @param contentStr
  271 + */
  272 + public void setContent(String contentStr) {
  273 + setContent(contentStr, null, null);
  274 + }
  275 +
  276 + /**
  277 + * 设置文本内容
  278 + *
  279 + * @param contentStr
  280 + */
  281 + public void setContent(String contentStr, OnClickListener listener) {
  282 + setContent(contentStr, null, listener);
  283 + }
  284 +
  285 + /**
  286 + * 获取文本内容
  287 + */
  288 + public String getContent(){
  289 + return mOriginContentStr;
  290 + }
  291 +
  292 + /**
  293 + * 获取文本 TextView
  294 + */
  295 + public TextView getTvContent() {
  296 + return mTvContent;
  297 + }
  298 +
  299 + /**
  300 + * 设置文本内容
  301 + *
  302 + * @param contentStr
  303 + * @param onExpandStateChangeListener 状态回调监听器
  304 + */
  305 + public void setContent(String contentStr, final OnExpandStateChangeListener onExpandStateChangeListener,
  306 + OnClickListener listener) {
  307 + if (TextUtils.isEmpty(contentStr) || mRootView == null) {
  308 + return;
  309 + }
  310 + //接口中返回有零宽字符zwsp,替换掉防止截取位置不对
  311 + mOriginContentStr = contentStr.replaceAll("\u200B","").trim();
  312 + mOnExpandStateChangeListener = onExpandStateChangeListener;
  313 + mListener = listener;
  314 + // 此处需要先设置mTvContent的text属性,防止在列表中,由于没有获取到控件宽度mMeasuredWidth,先执行onMeasure方法测量时,导致文本只能显示一行的问题
  315 + // 提前设置好text,再执行onMeasure,则没有该问题
  316 + mTvContent.setMaxLines(mMaxLines);
  317 + TextViewUtils.setText(mTvContent, mOriginContentStr);
  318 + // 获取文字的宽度
  319 + if (mMeasuredWidth <= 0) {
  320 + getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
  321 + @Override
  322 + public void onGlobalLayout() {
  323 + // 用完后立即移除监听,防止多次回调的问题
  324 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  325 + getViewTreeObserver().removeOnGlobalLayoutListener(this);
  326 + } else {
  327 + getViewTreeObserver().removeGlobalOnLayoutListener(this);
  328 + }
  329 + mMeasuredWidth = getMeasuredWidth();
  330 + measureEllipsizeText(mMeasuredWidth);
  331 + }
  332 + });
  333 + } else {
  334 + measureEllipsizeText(mMeasuredWidth);
  335 + }
  336 + }
  337 +
  338 + /**
  339 + * 点击事件
  340 + */
  341 + public void setmListener(OnClickListener mListener) {
  342 + this.mListener = mListener;
  343 + }
  344 +
  345 + /**
  346 + * 处理文本分行
  347 + *
  348 + * @param lineWidth
  349 + */
  350 + private void measureEllipsizeText(int lineWidth) {
  351 + if (TextUtils.isEmpty(mOriginContentStr)) {
  352 + return;
  353 + }
  354 + handleMeasureEllipsizeText(lineWidth);
  355 + }
  356 +
  357 + /**
  358 + * 使用StaticLayout处理文本分行和布局
  359 + *
  360 + * @param lineWidth 文本(布局)宽度
  361 + */
  362 + private void handleMeasureEllipsizeText(int lineWidth) {
  363 + TextPaint textPaint = mTvContent.getPaint();
  364 + StaticLayout staticLayout = new StaticLayout(mOriginContentStr, textPaint, lineWidth,
  365 + Layout.Alignment.ALIGN_NORMAL, mLineSpacingMultiplier, mLineSpacingExtra, false);
  366 + int lineCount = staticLayout.getLineCount();
  367 + if (lineCount < mMaxLines) {
  368 + // 不足最大行数,直接设置文本
  369 + // 少于最小展示行数,不再展示更多相关布局
  370 + mEllipsizeStr = mOriginContentStr;
  371 + mLayoutExpandMore.setVisibility(View.GONE);
  372 + mTvContent.setMaxLines(Integer.MAX_VALUE);
  373 + TextViewUtils.setText(mTvContent, mOriginContentStr);
  374 + } else {
  375 + // 超出最大行数
  376 + mRootView.setOnClickListener(this);
  377 + mLayoutExpandMore.setVisibility(View.VISIBLE);
  378 + // Step1:第mMinLineNum行的处理
  379 + handleEllipsizeString(staticLayout, lineWidth);
  380 + // Step2:最后一行的处理
  381 + handleLastLine(staticLayout, lineWidth);
  382 + if (mIsExpand) {
  383 + expand();
  384 + } else {
  385 + // 默认收缩
  386 + collapse();
  387 + }
  388 + }
  389 + }
  390 +
  391 + /**
  392 + * 处理缩略的字符串
  393 + *
  394 + * @param staticLayout
  395 + * @param lineWidth
  396 + */
  397 + private void handleEllipsizeString(StaticLayout staticLayout, int lineWidth) {
  398 + if (staticLayout == null) {
  399 + return;
  400 + }
  401 + TextPaint textPaint = mTvContent.getPaint();
  402 + // 获取到第mMinLineNum行的起始和结束位置
  403 + int startPos = staticLayout.getLineStart(mMaxLines - 1);
  404 + int endPos = staticLayout.getLineEnd(mMaxLines - 1);
  405 + // 修正,防止取子串越界
  406 + if (startPos < 0) {
  407 + startPos = 0;
  408 + }
  409 + if (endPos > mOriginContentStr.length()) {
  410 + endPos = mOriginContentStr.length();
  411 + }
  412 + if (startPos > endPos) {
  413 + startPos = endPos;
  414 + }
  415 + String lineContent = mOriginContentStr.substring(startPos, endPos);
  416 + float textLength = 0f;
  417 + if (lineContent != null) {
  418 + textLength = textPaint.measureText(lineContent);
  419 + }
  420 +
  421 + String strEllipsizeMark = ELLIPSIS_STRING;
  422 + float strEllipsizeWidth = textPaint.measureText(strEllipsizeMark);
  423 + float expandTextViewWidth = getExpandTextViewReservedWidth();
  424 +
  425 + // 展开控件需要预留的长度,预留宽度:"..." + 展开布局与文本间距 +图标长度 + 展开文本长度
  426 + float reservedWidth = mSpaceMargin + strEllipsizeWidth + expandTextViewWidth;
  427 + int correctEndPos = endPos;
  428 + if (reservedWidth + textLength > lineWidth) {
  429 + // 空间不够,需要按比例截取最后一行的字符串,以确保展示的最后一行文本不会与可展开布局重叠
  430 + float exceedSpace = reservedWidth + textLength - lineWidth;
  431 + if (textLength != 0) {
  432 + double exceedCount = ((exceedSpace / textLength) * 1.0d * (endPos - startPos));
  433 + correctEndPos = endPos - (int)Math.ceil(exceedCount);
  434 + }
  435 + } else {
  436 + // 文字宽度+展开布局的宽度 < 一行最大展示宽度: 展开布局左边跟随文字
  437 + ViewGroup.LayoutParams lp = mLayoutExpandMore.getLayoutParams();
  438 + if (lp instanceof FrameLayout.LayoutParams) {
  439 + FrameLayout.LayoutParams expandLayoutLp = (FrameLayout.LayoutParams) lp;
  440 + expandLayoutLp.rightMargin = (int) (lineWidth - (textLength + textPaint.measureText(strEllipsizeMark) + expandTextViewWidth));
  441 + mLayoutExpandMore.setLayoutParams(expandLayoutLp);
  442 + }
  443 +// mLayoutExpandMore.setX(lineWidth - (mSpaceMargin + textPaint.measureText(strEllipsizeMark)));
  444 + }
  445 + // java.lang.StringIndexOutOfBoundsException: String index out of range: -5
  446 + try {
  447 + String ellipsizeStr = mOriginContentStr.substring(0, correctEndPos);
  448 + mEllipsizeStr = removeEndLineBreak(ellipsizeStr) + strEllipsizeMark;
  449 + }catch (Exception e){
  450 + // e.printStackTrace();
  451 + }
  452 + }
  453 +
  454 + /**
  455 + * 处理最后一行文本
  456 + *
  457 + * @param staticLayout
  458 + * @param lineWidth
  459 + */
  460 + private void handleLastLine(StaticLayout staticLayout, int lineWidth) {
  461 + if (staticLayout == null) {
  462 + return;
  463 + }
  464 + int lineCount = staticLayout.getLineCount();
  465 + if (lineCount < 1) {
  466 + return;
  467 + }
  468 + int startPos = staticLayout.getLineStart(lineCount - 1);
  469 + int endPos = staticLayout.getLineEnd(lineCount - 1);
  470 + // 修正,防止取子串越界
  471 + if (startPos < 0) {
  472 + startPos = 0;
  473 + }
  474 + if (endPos > mOriginContentStr.length()) {
  475 + endPos = mOriginContentStr.length();
  476 + }
  477 + if (startPos > endPos) {
  478 + startPos = endPos;
  479 + }
  480 + String lastLineContent = mOriginContentStr.substring(startPos, endPos);
  481 + float textLength = 0f;
  482 + TextPaint textPaint = mTvContent.getPaint();
  483 + if (lastLineContent != null) {
  484 + textLength = textPaint.measureText(lastLineContent);
  485 + }
  486 + float reservedWidth = getExpandTextViewReservedWidth();
  487 + if (textLength + reservedWidth > lineWidth) {
  488 + // 文字宽度+展开布局的宽度 > 一行最大展示宽度
  489 + // 换行展示“收起”按钮及文字
  490 + mOriginContentStr += "\n";
  491 + linefeed = true;
  492 + }
  493 + }
  494 +
  495 + /**
  496 + * 获取展开布局的展开收缩控件的预留宽度
  497 + *
  498 + * @return value = 图标长度 + 展开提示文本长度
  499 + */
  500 + private float getExpandTextViewReservedWidth() {
  501 + int iconWidth = 0;
  502 + if (mExpandStyle == STYLE_DEFAULT || mExpandStyle == STYLE_ICON) {
  503 + // ll布局中的内容,图标iv的宽是15dp,参考布局
  504 + iconWidth = mExpandIconWidth;
  505 + }
  506 + float textWidth = 0f;
  507 + if (mExpandStyle == STYLE_DEFAULT || mExpandStyle == STYLE_TEXT) {
  508 + textWidth = mTvExpand.getPaint().measureText(mExpandMoreStr);
  509 + }
  510 + if (mExpandIconDrawable != null) {
  511 + textWidth += mExpandIconDrawable.getBounds().right - mExpandIconDrawable.getBounds().left;
  512 + }
  513 + // 展开控件需要预留的长度
  514 + return iconWidth + textWidth;
  515 + }
  516 +
  517 + /**
  518 + * 清除行末换行符
  519 + *
  520 + * @param text
  521 + * @return
  522 + */
  523 + private String removeEndLineBreak(CharSequence text) {
  524 + if (text == null) {
  525 + return null;
  526 + }
  527 + String str = text.toString();
  528 + if (str.endsWith("\n")) {
  529 + str = str.substring(0, str.length() - 1);
  530 + }
  531 + return str;
  532 + }
  533 +
  534 + /**
  535 + * 设置内容文字颜色
  536 + */
  537 + public void setContentTextColor(int colorId) {
  538 + if (colorId != 0) {
  539 + mContentTextColor = colorId;
  540 + mTvContent.setTextColor(colorId);
  541 + }
  542 + }
  543 +
  544 + /**
  545 + * 设置更多/收起文字颜色
  546 + */
  547 + public void setExpandTextColor(int colorId) {
  548 + if (colorId != 0) {
  549 + mExpandTextColor = colorId;
  550 + mTvExpand.setTextColor(colorId);
  551 + }
  552 + }
  553 +
  554 + /**
  555 + * 设置展开更多图标
  556 + *
  557 + * @param resId
  558 + */
  559 + public void setExpandMoreIcon(int resId) {
  560 + if (resId != 0) {
  561 + mExpandIconResId = resId;
  562 + mExpandIconDrawable = getResources().getDrawable(resId, null);
  563 + // 设置了Drawable对象在Canvas上的绘制区域,左上角坐标为(0, 2),右下角坐标为(12, 14)
  564 + mExpandIconDrawable.setBounds(0, UiUtils.dp2px(mExpandIconTop), UiUtils.dp2px(14-mExpandIconTop), UiUtils.dp2px(14));
  565 + // 当前处于收缩状态时,立即更新图标
  566 + if (!mIsExpand) {
  567 + mTvExpand.setCompoundDrawables(null, null, mExpandIconDrawable, null);
  568 + mTvExpand.setCompoundDrawablePadding(UiUtils.dp2px(1));
  569 + // mIconExpand.setImageResource(resId);
  570 + }
  571 + }
  572 + }
  573 +
  574 + /**
  575 + * 设置收缩图标
  576 + *
  577 + * @param resId
  578 + */
  579 + public void setCollapseLessIcon(int resId) {
  580 + if (resId != 0) {
  581 + mCollapseIconResId = resId;
  582 + mCollapseIconDrawable = getResources().getDrawable(resId, null);
  583 + mCollapseIconDrawable.setBounds(0, 0, UiUtils.dp2px(6), UiUtils.dp2px(10));
  584 + // 当前处于展开状态时,立即更新图标
  585 + if (mIsExpand) {
  586 + mTvExpand.setCompoundDrawables(null, null, mCollapseIconDrawable, null);
  587 + // mTvExpand.setCompoundDrawablePadding(UiUtils.dp2px(4));
  588 + // mIconExpand.setImageResource(resId);
  589 + }
  590 + }
  591 + }
  592 +
  593 + /**
  594 + * 展开
  595 + */
  596 + public void expand() {
  597 + setIsExpand(true);
  598 + mTvContent.setMaxLines(Integer.MAX_VALUE);
  599 + TextViewUtils.setText(mTvContent, mOriginContentStr);
  600 + if (newlineV != null) {
  601 + if (linefeed) {
  602 + newlineV.setVisibility(INVISIBLE);
  603 + } else {
  604 + newlineV.setVisibility(GONE);
  605 + }
  606 + }
  607 + TextViewUtils.setText(mTvExpand, mCollapseLessStr);
  608 + if (mCollapseIconDrawable != null) {
  609 + mTvExpand.setCompoundDrawables(null, null, mCollapseIconDrawable, null);
  610 + // mIconExpand.setImageResource(mCollapseIconResId);
  611 + }
  612 + }
  613 +
  614 + /**
  615 + * 收起
  616 + */
  617 + public void collapse() {
  618 + setIsExpand(false);
  619 + if (newlineV != null) {
  620 + newlineV.setVisibility(GONE);
  621 + }
  622 + mTvContent.setMaxLines(Integer.MAX_VALUE);
  623 + TextViewUtils.setText(mTvContent, mEllipsizeStr);
  624 + TextViewUtils.setText(mTvExpand, mExpandMoreStr);
  625 + if (mExpandIconDrawable != null) {
  626 + mTvExpand.setCompoundDrawables(null, null, mExpandIconDrawable, null);
  627 + // mIconExpand.setImageResource(mExpandIconResId);
  628 + }
  629 + }
  630 +
  631 + public int getLineCount() {
  632 + return mTvContent == null ? 0 : mTvContent.getLineCount();
  633 + }
  634 +
  635 + public void setShrinkLines(int shrinkLines) {
  636 + mMaxLines = shrinkLines;
  637 + }
  638 +
  639 + public void setIsExpand(boolean isExpand) {
  640 + mIsExpand = isExpand;
  641 + }
  642 +
  643 + public boolean isExpand() {
  644 + return mIsExpand;
  645 + }
  646 +
  647 + public void setShrink(boolean isShrink){
  648 + this.isShrink = isShrink;
  649 + }
  650 +
  651 + /**
  652 + * 转换dp为px
  653 + *
  654 + * @param context
  655 + * @param dipValue
  656 + * @return
  657 + */
  658 + private int dp2px(Context context, float dipValue) {
  659 + final float scale = context.getResources().getDisplayMetrics().density;
  660 + return (int) (dipValue * scale + 0.5f);
  661 + }
  662 +
  663 + /**
  664 + * 转换sp为px
  665 + *
  666 + * @param context
  667 + * @param spValue
  668 + * @return
  669 + */
  670 + public int sp2px(Context context, float spValue) {
  671 + float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
  672 + return (int) (spValue * fontScale + 0.5f);
  673 + }
  674 +
  675 + @Override
  676 + public void onClick(View v) {
  677 + if (mListener != null) {
  678 + mListener.onClick();
  679 + }
  680 + if (isShrink) {
  681 + if (!mIsExpand) {
  682 + // 之前是收缩状态,点击后展开
  683 + expand();
  684 + if (mOnExpandStateChangeListener != null) {
  685 + mOnExpandStateChangeListener.onExpand();
  686 + }
  687 + } else {
  688 + // 之前是展开状态,点击后收缩
  689 + collapse();
  690 + if (mOnExpandStateChangeListener != null) {
  691 + mOnExpandStateChangeListener.onCollapse();
  692 + }
  693 + }
  694 + }
  695 + }
  696 +}
  1 +
  2 +package com.wd.common.widget.expand;
  3 +
  4 +import android.content.Context;
  5 +import android.content.res.TypedArray;
  6 +import android.graphics.drawable.Drawable;
  7 +import android.os.Build;
  8 +import android.text.Layout;
  9 +import android.text.StaticLayout;
  10 +import android.text.TextPaint;
  11 +import android.text.TextUtils;
  12 +import android.util.AttributeSet;
  13 +import android.util.TypedValue;
  14 +import android.view.View;
  15 +import android.view.ViewGroup;
  16 +import android.view.ViewTreeObserver;
  17 +import android.widget.FrameLayout;
  18 +import android.widget.LinearLayout;
  19 +import android.widget.RelativeLayout;
  20 +import android.widget.TextView;
  21 +
  22 +import com.wd.fastcoding.base.R;
  23 +import com.wd.foundation.wdkit.utils.TextViewUtils;
  24 +import com.wd.foundation.wdkit.utils.UiUtils;
  25 +
  26 +
  27 +public class ExpandTextView extends RelativeLayout implements View.OnClickListener {
  28 + private static final String TAG = ExpandTextView.class.getSimpleName();
  29 +
  30 + private static final String ELLIPSIS_STRING = new String(new char[]{'\u2026'});
  31 +
  32 + private static final int STYLE_DEFAULT = 0;
  33 +
  34 + private static final int STYLE_ICON = 1;
  35 +
  36 + private static final int STYLE_TEXT = 2;
  37 +
  38 + private Context mContext;
  39 +
  40 + private View mRootView;
  41 +
  42 + private TextView mTvContent;
  43 +
  44 + private LinearLayout mLayoutExpandMore;
  45 +
  46 + private TextView mTvExpand;
  47 +
  48 + private int mMeasuredWidth;
  49 +
  50 + /**
  51 + * 辅助TextView,保证末尾图标和文字与内容文字居中显示
  52 + */
  53 + private TextView mTvExpandHelper;
  54 +
  55 + private int mExpandIconResId;
  56 +
  57 + private int mExpandIconTop;
  58 +
  59 + private int mCollapseIconResId;
  60 +
  61 + private Drawable mExpandIconDrawable;
  62 +
  63 + private Drawable mCollapseIconDrawable;
  64 +
  65 + private String mExpandMoreStr;
  66 +
  67 + private String mCollapseLessStr;
  68 +
  69 + private int mMaxLines = 2;
  70 +
  71 + private int mContentTextSize;
  72 +
  73 + private int mExpandTextSize;
  74 +
  75 + private View newlineV;
  76 +
  77 + /**
  78 + * 是否展开
  79 + */
  80 + private boolean mIsExpand = false;
  81 +
  82 + /**
  83 + * 原内容文本
  84 + */
  85 + private String mOriginContentStr;
  86 +
  87 + /**
  88 + * 缩略后展示的文本
  89 + */
  90 + private CharSequence mEllipsizeStr;
  91 +
  92 + /**
  93 + * 主文字颜色
  94 + */
  95 + private int mContentTextColor;
  96 +
  97 + /**
  98 + * 展开/收起文字颜色
  99 + */
  100 + private int mExpandTextColor;
  101 +
  102 + /**
  103 + * 样式,默认为图标+文字样式
  104 + */
  105 + private int mExpandStyle = STYLE_DEFAULT;
  106 +
  107 + /**
  108 + * 展开/收缩布局对应图标的宽度,默认布局是15dp
  109 + */
  110 + private int mExpandIconWidth = 15;
  111 +
  112 + /**
  113 + * 缩略文本展示时与展开/搜索布局的间距,默认是20px
  114 + */
  115 + private int mSpaceMargin = 20;
  116 +
  117 + /**
  118 + * 文本显示的lineSpacingExtra,对应于TextView的lineSpacingExtra属性
  119 + */
  120 + private float mLineSpacingExtra = 0.0f;
  121 +
  122 + /**
  123 + * 文本显示的lineSpacingMultiplier,对应于TextView的lineSpacingMultiplier属性
  124 + */
  125 + private float mLineSpacingMultiplier = 1.0f;
  126 +
  127 + private OnExpandStateChangeListener mOnExpandStateChangeListener;
  128 +
  129 + private OnClickListener mListener;
  130 +
  131 + private boolean isShrink;
  132 +
  133 + /**
  134 + * 文字是否左右对齐
  135 + */
  136 + private boolean isJustify;
  137 +
  138 + /**
  139 + * 最后一行是否换行
  140 + */
  141 + private boolean linefeed = false;
  142 +
  143 + /**
  144 + * 监听器
  145 + */
  146 + public interface OnExpandStateChangeListener {
  147 + /**
  148 + * 展开时回调
  149 + */
  150 + void onExpand();
  151 +
  152 + /**
  153 + * 收起时回调
  154 + */
  155 + void onCollapse();
  156 +
  157 + }
  158 +
  159 + /**
  160 + * 监听器
  161 + */
  162 + public interface OnClickListener {
  163 + /**
  164 + *
  165 + */
  166 + void onClick();
  167 +
  168 + }
  169 +
  170 + public ExpandTextView(Context context) {
  171 + this(context, null);
  172 + }
  173 +
  174 + public ExpandTextView(Context context, AttributeSet attrs) {
  175 + this(context, attrs, 0);
  176 + }
  177 +
  178 + public ExpandTextView(Context context, AttributeSet attrs, int defStyleAttr) {
  179 + super(context, attrs, defStyleAttr);
  180 + mContext = context;
  181 + initAttributeSet(context, attrs);
  182 + initView();
  183 + }
  184 +
  185 + /**
  186 + * 初始化自定义属性
  187 + *
  188 + * @param context
  189 + * @param attrs
  190 + */
  191 + private void initAttributeSet(Context context, AttributeSet attrs) {
  192 + TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ExpandTextView);
  193 + if (ta != null) {
  194 + mMaxLines = ta.getInt(R.styleable.ExpandTextView_maxLines, 2);
  195 + mExpandIconResId = ta.getResourceId(R.styleable.ExpandTextView_expandIconResId, 0);
  196 + mExpandIconTop = ta.getResourceId(R.styleable.ExpandTextView_expandIconTop, 1);
  197 + mCollapseIconResId = ta.getResourceId(R.styleable.ExpandTextView_collapseIconResId, 0);
  198 + mExpandMoreStr = ta.getString(R.styleable.ExpandTextView_expandMoreText);
  199 + mCollapseLessStr = ta.getString(R.styleable.ExpandTextView_collapseLessText);
  200 + mContentTextSize = ta.getDimensionPixelSize(R.styleable.ExpandTextView_contentTextSize, sp2px(context, 14));
  201 + mContentTextColor = ta.getColor(R.styleable.ExpandTextView_contentTextColor, 0);
  202 + mExpandTextSize = ta.getDimensionPixelSize(R.styleable.ExpandTextView_expandTextSize, sp2px(context, 14));
  203 + mExpandTextColor = ta.getColor(R.styleable.ExpandTextView_expandTextColor, 0);
  204 + mExpandStyle = ta.getInt(R.styleable.ExpandTextView_expandStyle, STYLE_DEFAULT);
  205 + mExpandIconWidth = ta.getDimensionPixelSize(R.styleable.ExpandTextView_expandIconWidth, dp2px(context, 15));
  206 + mSpaceMargin = ta.getDimensionPixelSize(R.styleable.ExpandTextView_spaceMargin, dp2px(context, 6));
  207 + mLineSpacingExtra = ta.getDimensionPixelSize(R.styleable.ExpandTextView_lineSpacingExtra, 0);
  208 + mLineSpacingMultiplier = ta.getFloat(R.styleable.ExpandTextView_lineSpacingMultiplier, 1.0f);
  209 + isShrink = ta.getBoolean(R.styleable.ExpandTextView_isShrink, true);
  210 + isJustify = ta.getBoolean(R.styleable.ExpandTextView_isJustify, false);
  211 +
  212 + ta.recycle();
  213 + }
  214 + if (mMaxLines < 1) {
  215 + mMaxLines = 1;
  216 + }
  217 + }
  218 +
  219 + /**
  220 + * 初始化View
  221 + */
  222 + private void initView() {
  223 + // 由于左右对齐的自定义控件XQJustifyTextView,下拉刷新会闪烁。所以暂时活动列表不使用左右对齐的控件
  224 + mRootView = inflate(mContext, isJustify ? R.layout.layout_expand_justify : R.layout.layout_expand, this);
  225 + mTvContent = findViewById(R.id.expand_content_tv);
  226 + mLayoutExpandMore = findViewById(R.id.expand_ll);
  227 + mTvExpand = findViewById(R.id.expand_tv);
  228 + newlineV = findViewById(R.id.newlineV);
  229 + mTvExpandHelper = findViewById(R.id.expand_helper_tv);
  230 +
  231 + TextViewUtils.setText(mTvExpand, mExpandMoreStr);
  232 + mTvContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, mContentTextSize);
  233 + // 辅助TextView,与内容TextView大小相等,保证末尾图标和文字与内容文字居中显示
  234 + mTvExpandHelper.setTextSize(TypedValue.COMPLEX_UNIT_PX, mContentTextSize);
  235 + mTvExpand.setTextSize(TypedValue.COMPLEX_UNIT_PX, mExpandTextSize);
  236 + mTvContent.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
  237 + mTvExpandHelper.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
  238 + mTvExpand.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
  239 + // 默认设置展开图标
  240 + setExpandMoreIcon(mExpandIconResId);
  241 + setCollapseLessIcon(mCollapseIconResId);
  242 + setContentTextColor(mContentTextColor);
  243 + setExpandTextColor(mExpandTextColor);
  244 + switch (mExpandStyle) {
  245 + case STYLE_ICON:
  246 + mTvExpand.setVisibility(GONE);
  247 + break;
  248 + case STYLE_TEXT:
  249 + mTvExpand.setVisibility(VISIBLE);
  250 + break;
  251 + default:
  252 + mTvExpand.setVisibility(VISIBLE);
  253 + break;
  254 + }
  255 + }
  256 +
  257 + @Override
  258 + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  259 + super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  260 + // Log.d(TAG, "onMeasure,measureWidth = " + getMeasuredWidth());
  261 + if (mMeasuredWidth <= 0 && getMeasuredWidth() > 0) {
  262 + mMeasuredWidth = getMeasuredWidth();
  263 + measureEllipsizeText(mMeasuredWidth);
  264 + }
  265 + }
  266 +
  267 + /**
  268 + * 设置文本内容
  269 + *
  270 + * @param contentStr
  271 + */
  272 + public void setContent(String contentStr) {
  273 + setContent(contentStr, null, null);
  274 + }
  275 +
  276 + /**
  277 + * 设置文本内容
  278 + *
  279 + * @param contentStr
  280 + */
  281 + public void setContent(String contentStr, OnClickListener listener) {
  282 + setContent(contentStr, null, listener);
  283 + }
  284 +
  285 + /**
  286 + * 获取文本内容
  287 + */
  288 + public String getContent(){
  289 + return mOriginContentStr;
  290 + }
  291 +
  292 + /**
  293 + * 获取文本 TextView
  294 + */
  295 + public TextView getTvContent() {
  296 + return mTvContent;
  297 + }
  298 +
  299 + /**
  300 + * 设置文本内容
  301 + *
  302 + * @param contentStr
  303 + * @param onExpandStateChangeListener 状态回调监听器
  304 + */
  305 + public void setContent(String contentStr, final OnExpandStateChangeListener onExpandStateChangeListener,
  306 + OnClickListener listener) {
  307 + if (TextUtils.isEmpty(contentStr) || mRootView == null) {
  308 + return;
  309 + }
  310 + mOriginContentStr = contentStr;
  311 + mOnExpandStateChangeListener = onExpandStateChangeListener;
  312 + mListener = listener;
  313 + // 此处需要先设置mTvContent的text属性,防止在列表中,由于没有获取到控件宽度mMeasuredWidth,先执行onMeasure方法测量时,导致文本只能显示一行的问题
  314 + // 提前设置好text,再执行onMeasure,则没有该问题
  315 + mTvContent.setMaxLines(mMaxLines);
  316 + TextViewUtils.setText(mTvContent, mOriginContentStr);
  317 + // 获取文字的宽度
  318 + if (mMeasuredWidth <= 0) {
  319 + getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
  320 + @Override
  321 + public void onGlobalLayout() {
  322 + // 用完后立即移除监听,防止多次回调的问题
  323 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  324 + getViewTreeObserver().removeOnGlobalLayoutListener(this);
  325 + } else {
  326 + getViewTreeObserver().removeGlobalOnLayoutListener(this);
  327 + }
  328 + mMeasuredWidth = getMeasuredWidth();
  329 + measureEllipsizeText(mMeasuredWidth);
  330 + }
  331 + });
  332 + } else {
  333 + measureEllipsizeText(mMeasuredWidth);
  334 + }
  335 + }
  336 +
  337 + /**
  338 + * 点击事件
  339 + */
  340 + public void setmListener(OnClickListener mListener) {
  341 + this.mListener = mListener;
  342 + }
  343 +
  344 + /**
  345 + * 处理文本分行
  346 + *
  347 + * @param lineWidth
  348 + */
  349 + private void measureEllipsizeText(int lineWidth) {
  350 + if (TextUtils.isEmpty(mOriginContentStr)) {
  351 + return;
  352 + }
  353 + handleMeasureEllipsizeText(lineWidth);
  354 + }
  355 +
  356 + /**
  357 + * 使用StaticLayout处理文本分行和布局
  358 + *
  359 + * @param lineWidth 文本(布局)宽度
  360 + */
  361 + private void handleMeasureEllipsizeText(int lineWidth) {
  362 + TextPaint textPaint = mTvContent.getPaint();
  363 + StaticLayout staticLayout = new StaticLayout(mOriginContentStr, textPaint, lineWidth,
  364 + Layout.Alignment.ALIGN_NORMAL, mLineSpacingMultiplier, mLineSpacingExtra, false);
  365 + int lineCount = staticLayout.getLineCount();
  366 + if (lineCount <= mMaxLines) {
  367 + // 不足最大行数,直接设置文本
  368 + // 少于最小展示行数,不再展示更多相关布局
  369 + mEllipsizeStr = mOriginContentStr;
  370 + mLayoutExpandMore.setVisibility(View.GONE);
  371 + mTvContent.setMaxLines(Integer.MAX_VALUE);
  372 + TextViewUtils.setText(mTvContent, mOriginContentStr);
  373 + } else {
  374 + // 超出最大行数
  375 + mRootView.setOnClickListener(this);
  376 + mLayoutExpandMore.setVisibility(View.VISIBLE);
  377 + // Step1:第mMinLineNum行的处理
  378 + handleEllipsizeString(staticLayout, lineWidth);
  379 + // Step2:最后一行的处理
  380 + handleLastLine(staticLayout, lineWidth);
  381 + if (mIsExpand) {
  382 + expand();
  383 + } else {
  384 + // 默认收缩
  385 + collapse();
  386 + }
  387 + }
  388 + }
  389 +
  390 + /**
  391 + * 处理缩略的字符串
  392 + *
  393 + * @param staticLayout
  394 + * @param lineWidth
  395 + */
  396 + private void handleEllipsizeString(StaticLayout staticLayout, int lineWidth) {
  397 + if (staticLayout == null) {
  398 + return;
  399 + }
  400 + TextPaint textPaint = mTvContent.getPaint();
  401 + // 获取到第mMinLineNum行的起始和结束位置
  402 + int startPos = staticLayout.getLineStart(mMaxLines - 1);
  403 + int endPos = staticLayout.getLineEnd(mMaxLines - 1);
  404 + // 修正,防止取子串越界
  405 + if (startPos < 0) {
  406 + startPos = 0;
  407 + }
  408 + if (endPos > mOriginContentStr.length()) {
  409 + endPos = mOriginContentStr.length();
  410 + }
  411 + if (startPos > endPos) {
  412 + startPos = endPos;
  413 + }
  414 + String lineContent = mOriginContentStr.substring(startPos, endPos);
  415 + float textLength = 0f;
  416 + if (lineContent != null) {
  417 + textLength = textPaint.measureText(lineContent);
  418 + }
  419 +
  420 + String strEllipsizeMark = ELLIPSIS_STRING;
  421 + float strEllipsizeWidth = textPaint.measureText(strEllipsizeMark);
  422 + float expandTextViewWidth = getExpandTextViewReservedWidth();
  423 +
  424 + // 展开控件需要预留的长度,预留宽度:"..." + 展开布局与文本间距 +图标长度 + 展开文本长度
  425 + float reservedWidth = mSpaceMargin + strEllipsizeWidth + expandTextViewWidth;
  426 + int correctEndPos = endPos;
  427 + if (reservedWidth + textLength > lineWidth) {
  428 + // 空间不够,需要按比例截取最后一行的字符串,以确保展示的最后一行文本不会与可展开布局重叠
  429 + float exceedSpace = reservedWidth + textLength - lineWidth;
  430 + if (textLength != 0) {
  431 + double exceedCount = ((exceedSpace / textLength) * 1.0d * (endPos - startPos));
  432 + correctEndPos = endPos - (int)Math.ceil(exceedCount);
  433 + }
  434 + } else {
  435 + // 文字宽度+展开布局的宽度 < 一行最大展示宽度: 展开布局左边跟随文字
  436 + ViewGroup.LayoutParams lp = mLayoutExpandMore.getLayoutParams();
  437 + if (lp instanceof FrameLayout.LayoutParams) {
  438 + FrameLayout.LayoutParams expandLayoutLp = (FrameLayout.LayoutParams) lp;
  439 + expandLayoutLp.width = (int) (lineWidth - (textLength + mSpaceMargin + textPaint.measureText(strEllipsizeMark)));
  440 + mLayoutExpandMore.setLayoutParams(expandLayoutLp);
  441 + }
  442 +// mLayoutExpandMore.setX(lineWidth - (mSpaceMargin + textPaint.measureText(strEllipsizeMark)));
  443 + }
  444 + // java.lang.StringIndexOutOfBoundsException: String index out of range: -5
  445 + try {
  446 + String ellipsizeStr = mOriginContentStr.substring(0, correctEndPos);
  447 + mEllipsizeStr = removeEndLineBreak(ellipsizeStr) + strEllipsizeMark;
  448 + }catch (Exception e){
  449 + // e.printStackTrace();
  450 + }
  451 + }
  452 +
  453 + /**
  454 + * 处理最后一行文本
  455 + *
  456 + * @param staticLayout
  457 + * @param lineWidth
  458 + */
  459 + private void handleLastLine(StaticLayout staticLayout, int lineWidth) {
  460 + if (staticLayout == null) {
  461 + return;
  462 + }
  463 + int lineCount = staticLayout.getLineCount();
  464 + if (lineCount < 1) {
  465 + return;
  466 + }
  467 + int startPos = staticLayout.getLineStart(lineCount - 1);
  468 + int endPos = staticLayout.getLineEnd(lineCount - 1);
  469 + // 修正,防止取子串越界
  470 + if (startPos < 0) {
  471 + startPos = 0;
  472 + }
  473 + if (endPos > mOriginContentStr.length()) {
  474 + endPos = mOriginContentStr.length();
  475 + }
  476 + if (startPos > endPos) {
  477 + startPos = endPos;
  478 + }
  479 + String lastLineContent = mOriginContentStr.substring(startPos, endPos);
  480 + float textLength = 0f;
  481 + TextPaint textPaint = mTvContent.getPaint();
  482 + if (lastLineContent != null) {
  483 + textLength = textPaint.measureText(lastLineContent);
  484 + }
  485 + float reservedWidth = getExpandTextViewReservedWidth();
  486 + if (textLength + reservedWidth > lineWidth) {
  487 + // 文字宽度+展开布局的宽度 > 一行最大展示宽度
  488 + // 换行展示“收起”按钮及文字
  489 + mOriginContentStr += "\n";
  490 + linefeed = true;
  491 + }
  492 + }
  493 +
  494 + /**
  495 + * 获取展开布局的展开收缩控件的预留宽度
  496 + *
  497 + * @return value = 图标长度 + 展开提示文本长度
  498 + */
  499 + private float getExpandTextViewReservedWidth() {
  500 + int iconWidth = 0;
  501 + if (mExpandStyle == STYLE_DEFAULT || mExpandStyle == STYLE_ICON) {
  502 + // ll布局中的内容,图标iv的宽是15dp,参考布局
  503 + iconWidth = mExpandIconWidth;
  504 + }
  505 + float textWidth = 0f;
  506 + if (mExpandStyle == STYLE_DEFAULT || mExpandStyle == STYLE_TEXT) {
  507 + textWidth = mTvExpand.getPaint().measureText(mExpandMoreStr);
  508 + }
  509 + if (mExpandIconDrawable != null) {
  510 + textWidth += mExpandIconDrawable.getBounds().right - mExpandIconDrawable.getBounds().left;
  511 + }
  512 + // 展开控件需要预留的长度
  513 + return iconWidth + textWidth;
  514 + }
  515 +
  516 + /**
  517 + * 清除行末换行符
  518 + *
  519 + * @param text
  520 + * @return
  521 + */
  522 + private String removeEndLineBreak(CharSequence text) {
  523 + if (text == null) {
  524 + return null;
  525 + }
  526 + String str = text.toString();
  527 + if (str.endsWith("\n")) {
  528 + str = str.substring(0, str.length() - 1);
  529 + }
  530 + return str;
  531 + }
  532 +
  533 + /**
  534 + * 设置内容文字颜色
  535 + */
  536 + public void setContentTextColor(int colorId) {
  537 + if (colorId != 0) {
  538 + mContentTextColor = colorId;
  539 + mTvContent.setTextColor(colorId);
  540 + }
  541 + }
  542 +
  543 + /**
  544 + * 设置更多/收起文字颜色
  545 + */
  546 + public void setExpandTextColor(int colorId) {
  547 + if (colorId != 0) {
  548 + mExpandTextColor = colorId;
  549 + mTvExpand.setTextColor(colorId);
  550 + }
  551 + }
  552 +
  553 + /**
  554 + * 设置展开更多图标
  555 + *
  556 + * @param resId
  557 + */
  558 + public void setExpandMoreIcon(int resId) {
  559 + if (resId != 0) {
  560 + mExpandIconResId = resId;
  561 + mExpandIconDrawable = getResources().getDrawable(resId, null);
  562 + // 设置了Drawable对象在Canvas上的绘制区域,左上角坐标为(0, 2),右下角坐标为(12, 14)
  563 + mExpandIconDrawable.setBounds(0, UiUtils.dp2px(mExpandIconTop), UiUtils.dp2px(14-mExpandIconTop), UiUtils.dp2px(14));
  564 + // 当前处于收缩状态时,立即更新图标
  565 + if (!mIsExpand) {
  566 + mTvExpand.setCompoundDrawables(null, null, mExpandIconDrawable, null);
  567 + mTvExpand.setCompoundDrawablePadding(UiUtils.dp2px(1));
  568 + // mIconExpand.setImageResource(resId);
  569 + }
  570 + }
  571 + }
  572 +
  573 + /**
  574 + * 设置收缩图标
  575 + *
  576 + * @param resId
  577 + */
  578 + public void setCollapseLessIcon(int resId) {
  579 + if (resId != 0) {
  580 + mCollapseIconResId = resId;
  581 + mCollapseIconDrawable = getResources().getDrawable(resId, null);
  582 + mCollapseIconDrawable.setBounds(0, 0, UiUtils.dp2px(6), UiUtils.dp2px(10));
  583 + // 当前处于展开状态时,立即更新图标
  584 + if (mIsExpand) {
  585 + mTvExpand.setCompoundDrawables(null, null, mCollapseIconDrawable, null);
  586 + // mTvExpand.setCompoundDrawablePadding(UiUtils.dp2px(4));
  587 + // mIconExpand.setImageResource(resId);
  588 + }
  589 + }
  590 + }
  591 +
  592 + /**
  593 + * 展开
  594 + */
  595 + public void expand() {
  596 + setIsExpand(true);
  597 + mTvContent.setMaxLines(Integer.MAX_VALUE);
  598 + TextViewUtils.setText(mTvContent, mOriginContentStr);
  599 + if (newlineV != null) {
  600 + if (linefeed) {
  601 + newlineV.setVisibility(INVISIBLE);
  602 + } else {
  603 + newlineV.setVisibility(GONE);
  604 + }
  605 + }
  606 + TextViewUtils.setText(mTvExpand, mCollapseLessStr);
  607 + if (mCollapseIconDrawable != null) {
  608 + mTvExpand.setCompoundDrawables(null, null, mCollapseIconDrawable, null);
  609 + // mIconExpand.setImageResource(mCollapseIconResId);
  610 + }
  611 + }
  612 +
  613 + /**
  614 + * 收起
  615 + */
  616 + public void collapse() {
  617 + setIsExpand(false);
  618 + if (newlineV != null) {
  619 + newlineV.setVisibility(GONE);
  620 + }
  621 + mTvContent.setMaxLines(Integer.MAX_VALUE);
  622 + TextViewUtils.setText(mTvContent, mEllipsizeStr);
  623 + TextViewUtils.setText(mTvExpand, mExpandMoreStr);
  624 + if (mExpandIconDrawable != null) {
  625 + mTvExpand.setCompoundDrawables(null, null, mExpandIconDrawable, null);
  626 + // mIconExpand.setImageResource(mExpandIconResId);
  627 + }
  628 + }
  629 +
  630 + public int getLineCount() {
  631 + return mTvContent == null ? 0 : mTvContent.getLineCount();
  632 + }
  633 +
  634 + public void setShrinkLines(int shrinkLines) {
  635 + mMaxLines = shrinkLines;
  636 + }
  637 +
  638 + public void setIsExpand(boolean isExpand) {
  639 + mIsExpand = isExpand;
  640 + }
  641 +
  642 + public boolean isExpand() {
  643 + return mIsExpand;
  644 + }
  645 +
  646 + public void setShrink(boolean isShrink){
  647 + this.isShrink = isShrink;
  648 + }
  649 +
  650 + /**
  651 + * 转换dp为px
  652 + *
  653 + * @param context
  654 + * @param dipValue
  655 + * @return
  656 + */
  657 + private int dp2px(Context context, float dipValue) {
  658 + final float scale = context.getResources().getDisplayMetrics().density;
  659 + return (int) (dipValue * scale + 0.5f);
  660 + }
  661 +
  662 + /**
  663 + * 转换sp为px
  664 + *
  665 + * @param context
  666 + * @param spValue
  667 + * @return
  668 + */
  669 + public int sp2px(Context context, float spValue) {
  670 + float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
  671 + return (int) (spValue * fontScale + 0.5f);
  672 + }
  673 +
  674 + @Override
  675 + public void onClick(View v) {
  676 + if (mListener != null) {
  677 + mListener.onClick();
  678 + }
  679 + if (isShrink) {
  680 + if (!mIsExpand) {
  681 + // 之前是收缩状态,点击后展开
  682 + expand();
  683 + if (mOnExpandStateChangeListener != null) {
  684 + mOnExpandStateChangeListener.onExpand();
  685 + }
  686 + } else {
  687 + // 之前是展开状态,点击后收缩
  688 + collapse();
  689 + if (mOnExpandStateChangeListener != null) {
  690 + mOnExpandStateChangeListener.onCollapse();
  691 + }
  692 + }
  693 + }
  694 + }
  695 +}
  1 +
  2 +package com.wd.common.widget.expand;
  3 +
  4 +import android.content.Context;
  5 +import android.graphics.Canvas;
  6 +import android.text.StaticLayout;
  7 +import android.text.TextPaint;
  8 +import android.text.TextUtils;
  9 +import android.util.AttributeSet;
  10 +import android.util.Log;
  11 +import android.view.Gravity;
  12 +
  13 +import androidx.appcompat.widget.AppCompatTextView;
  14 +
  15 +import java.io.UnsupportedEncodingException;
  16 +import java.util.ArrayList;
  17 +import java.util.Arrays;
  18 +import java.util.List;
  19 +import java.util.Objects;
  20 +
  21 +/**
  22 + * 左右对齐textview
  23 + *
  24 + * @author libo
  25 + * @version [V1.0.0, 2022/10/10]
  26 + * @since V1.0.0
  27 + */
  28 +public class XQJustifyTextView extends AppCompatTextView {
  29 +
  30 + private static final String TAG = "XQJustifyTextView";
  31 +
  32 + /**
  33 + * 绘制文字的起始Y坐标
  34 + */
  35 + private float mLineY;
  36 +
  37 + /**
  38 + * 文字的宽度
  39 + */
  40 + private int mViewWidth;
  41 +
  42 + /**
  43 + * 段落间距
  44 + */
  45 +// private int paragraphSpacing = dipToPx(getContext(), 15);
  46 + private int paragraphSpacing = 0;
  47 +
  48 + /**
  49 + * 当前所有行数的集合
  50 + */
  51 + private ArrayList<List<List<String>>> mParagraphLineList;
  52 +
  53 + /**
  54 + * 当前所有的行数
  55 + */
  56 + private int mLineCount;
  57 +
  58 + /**
  59 + * 每一段单词的内容集合
  60 + */
  61 + private ArrayList<List<String>> mParagraphWordList;
  62 +
  63 + /**
  64 + * 空格字符
  65 + */
  66 + private static final String BLANK = " ";
  67 +
  68 + /**
  69 + * 英语单词元音字母
  70 + */
  71 + private String[] vowel = {"a", "e", "i", "o", "u"};
  72 +
  73 + /**
  74 + * 英语单词元音字母集合
  75 + */
  76 + private List<String> vowels = Arrays.asList(vowel);
  77 +
  78 + public XQJustifyTextView(Context context) {
  79 + this(context, null);
  80 + }
  81 +
  82 + public XQJustifyTextView(Context context, AttributeSet attrs) {
  83 + this(context, attrs, 0);
  84 + }
  85 +
  86 + public XQJustifyTextView(Context context, AttributeSet attrs, int defStyleAttr) {
  87 + super(context, attrs, defStyleAttr);
  88 + }
  89 +
  90 + @Override
  91 + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  92 + super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  93 + mParagraphLineList = null;
  94 + mParagraphWordList = null;
  95 + mLineY = 0;
  96 + mViewWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
  97 + getParagraphList();
  98 + if (mParagraphLineList == null || mParagraphWordList == null || mParagraphWordList.size() == 0) {
  99 + return;
  100 + }
  101 +
  102 + for (List<String> frontList : mParagraphWordList) {
  103 + mParagraphLineList.add(getLineList(frontList));
  104 + }
  105 + setMeasuredDimension(mViewWidth, (mParagraphLineList.size() - 1) * paragraphSpacing + mLineCount * getLineHeight());
  106 + }
  107 +
  108 + @Override
  109 + protected void onDraw(Canvas canvas) {
  110 +
  111 + TextPaint paint = getPaint();
  112 + paint.setColor(getCurrentTextColor());
  113 + paint.drawableState = getDrawableState();
  114 + mLineY = 0;
  115 + float textSize = getTextSize();
  116 + mLineY += textSize + getPaddingTop();
  117 +// Layout layout = getLayout();
  118 +// if (layout == null) {
  119 +// return;
  120 +// }
  121 + adjust(canvas, paint);
  122 + }
  123 +
  124 + /**
  125 + * @param frontList
  126 + * @return 计算每一段绘制的内容
  127 + */
  128 + private synchronized List<List<String>> getLineList(List<String> frontList) {
  129 + Log.i(TAG, "getLineList ");
  130 + StringBuilder sb = new StringBuilder();
  131 + List<List<String>> lineLists = new ArrayList<>();
  132 + List<String> lineList = new ArrayList<>();
  133 + float width = 0;
  134 + String temp = "";
  135 + String front = "";
  136 + for (int i = 0; i < frontList.size(); i++) {
  137 +
  138 + front = frontList.get(i);
  139 +
  140 + if (!TextUtils.isEmpty(temp)) {
  141 + sb.append(temp);
  142 + lineList.add(temp);
  143 + if (!isCN(temp)) {
  144 + sb.append(BLANK);
  145 + }
  146 + temp = "";
  147 + }
  148 +
  149 + if (isCN(front)) {
  150 + sb.append(front);
  151 + } else {
  152 + if ((i + 1) < frontList.size()) {
  153 + String nextFront = frontList.get(i + 1);
  154 + if (isCN(nextFront)) {
  155 + sb.append(front);
  156 + } else {
  157 + sb.append(front).append(BLANK);
  158 + }
  159 + } else {
  160 + sb.append(front);
  161 + }
  162 +
  163 + }
  164 +
  165 + lineList.add(front);
  166 + width = StaticLayout.getDesiredWidth(sb.toString(), getPaint());
  167 +
  168 + if (width > mViewWidth) {
  169 +
  170 + // 先判断最后一个单词是否是英文的,是的话则切割,否则的话就移除最后一个
  171 + int lastIndex = lineList.size() - 1;
  172 + String lastWord = lineList.get(lastIndex);
  173 +
  174 + String lastTemp = "";
  175 + lineList.remove(lastIndex);
  176 + if (isCN(lastWord)) {
  177 +
  178 + addLines(lineLists, lineList);
  179 + lastTemp = lastWord;
  180 + } else {
  181 +
  182 + // 否则的话则截取字符串
  183 + String substring = sb.substring(0, sb.length() - lastWord.length() - 1);
  184 + sb.delete(0, sb.toString().length());
  185 + sb.append(substring).append(BLANK);
  186 + String tempLastWord = "";
  187 +
  188 + int length = lastWord.length();
  189 +
  190 + if (length <= 3) {
  191 + addLines(lineLists, lineList);
  192 + lastTemp = lastWord;
  193 + } else {
  194 + int cutoffIndex = 0;
  195 + for (int j = 0; j < length; j++) {
  196 +
  197 + tempLastWord = String.valueOf(lastWord.charAt(j));
  198 + sb.append(tempLastWord);
  199 + if (vowels.contains(tempLastWord)) {
  200 + // 根据元音字母来进行截断
  201 + if (j + 1 < length) {
  202 + String nextTempLastWord = String.valueOf(lastWord.charAt(j + 1));
  203 + sb.append(nextTempLastWord);
  204 + width = StaticLayout.getDesiredWidth(sb.toString(), getPaint());
  205 + cutoffIndex = j;
  206 + if (width > mViewWidth) {
  207 + if (j > 2 && j <= length - 2) {
  208 + // 单词截断后,前面的字符小于2个时,则不进行截断
  209 + String lastFinalWord = lastWord.substring(0, cutoffIndex + 2) + "-";
  210 + lineList.add(lastFinalWord);
  211 + addLines(lineLists, lineList);
  212 + lastTemp = lastWord.substring(cutoffIndex + 2, length);
  213 +
  214 + } else {
  215 + addLines(lineLists, lineList);
  216 + lastTemp = lastWord;
  217 + }
  218 + break;
  219 + }
  220 + } else {
  221 + addLines(lineLists, lineList);
  222 + lastTemp = lastWord;
  223 + break;
  224 + }
  225 + }
  226 +
  227 + width = StaticLayout.getDesiredWidth(sb.toString(), getPaint());
  228 +
  229 + // 找不到元音,则走默认的逻辑
  230 + if (width > mViewWidth) {
  231 + if (j > 2 && j <= length - 2) {
  232 + // 单词截断后,前面的字符小于2个时,则不进行截断
  233 + String lastFinalWord = lastWord.substring(0, j) + "-";
  234 + lineList.add(lastFinalWord);
  235 + addLines(lineLists, lineList);
  236 + lastTemp = lastWord.substring(j, length);
  237 +
  238 + } else {
  239 + addLines(lineLists, lineList);
  240 + lastTemp = lastWord;
  241 + }
  242 + break;
  243 + }
  244 + }
  245 + }
  246 + }
  247 +
  248 + sb.delete(0, sb.toString().length());
  249 + temp = lastTemp;
  250 +
  251 + }
  252 +
  253 + if (lineList.size() > 0 && i == frontList.size() - 1) {
  254 + addLines(lineLists, lineList);
  255 + }
  256 + }
  257 +
  258 + if (!TextUtils.isEmpty(temp)) {
  259 + lineList.add(temp);
  260 + addLines(lineLists, lineList);
  261 + }
  262 +
  263 + mLineCount += lineLists.size();
  264 + return lineLists;
  265 + }
  266 +
  267 + /**
  268 + * 添加一行到单词内容
  269 + *
  270 + * @param lineLists 总单词集合
  271 + * @param lineList 当前要添加的集合
  272 + */
  273 + private void addLines(List<List<String>> lineLists, List<String> lineList) {
  274 + if (lineLists == null || lineList == null) {
  275 + return;
  276 + }
  277 +
  278 + List<String> tempLines = new ArrayList<>(lineList);
  279 + lineLists.add(tempLines);
  280 + lineList.clear();
  281 + }
  282 +
  283 + /**
  284 + * 获取段落
  285 + */
  286 + private void getParagraphList() {
  287 + String text = getText().toString().replaceAll(" ", "").replaceAll(" ", "").replaceAll("\\r", "").trim();
  288 + mLineCount = 0;
  289 + String[] items = text.split("\\n");
  290 + mParagraphLineList = new ArrayList<>();
  291 + mParagraphWordList = new ArrayList<>();
  292 + for (String item : items) {
  293 + if (item.length() != 0) {
  294 + mParagraphWordList.add(getWordList(item));
  295 + }
  296 + }
  297 + }
  298 +
  299 + /**
  300 + * 截取每一段内容的每一个单词
  301 + *
  302 + * @param text
  303 + * @return
  304 + */
  305 + private synchronized List<String> getWordList(String text) {
  306 + if (TextUtils.isEmpty(text)) {
  307 + return new ArrayList<>();
  308 + }
  309 + Log.i(TAG, "getWordList ");
  310 + List<String> frontList = new ArrayList<>();
  311 + StringBuilder str = new StringBuilder();
  312 + for (int i = 0; i < text.length(); i++) {
  313 + String charAt = String.valueOf(text.charAt(i));
  314 + if (!Objects.equals(charAt, BLANK)) {
  315 + if (checkIsSymbol(charAt)) {
  316 + boolean isEmptyStr = str.length() == 0;
  317 + str.append(charAt);
  318 + if (!isEmptyStr) {
  319 + // 中英文都需要将字符串添加到这里;
  320 + frontList.add(str.toString());
  321 + str.delete(0, str.length());
  322 + }
  323 + } else {
  324 + if (isCN(str.toString())) {
  325 + frontList.add(str.toString());
  326 + str.delete(0, str.length());
  327 + }
  328 + str.append(charAt);
  329 + }
  330 + } else {
  331 + if (!TextUtils.isEmpty(str.toString())) {
  332 + frontList.add(str.toString().replaceAll(BLANK, ""));
  333 + str.delete(0, str.length());
  334 + }
  335 + }
  336 + }
  337 +
  338 + if (str.length() != 0) {
  339 + frontList.add(str.toString());
  340 + str.delete(0, str.length());
  341 + }
  342 +
  343 + return frontList;
  344 + }
  345 +
  346 + /**
  347 + * 中英文排版效果
  348 + *
  349 + * @param canvas
  350 + */
  351 + private synchronized void adjust(Canvas canvas, TextPaint paint) {
  352 + if (mParagraphWordList == null) {
  353 + return;
  354 + }
  355 + int size = mParagraphWordList.size();
  356 +
  357 + for (int j = 0; j < size; j++) { // 遍历每一段
  358 + List<List<String>> lineList = mParagraphLineList.get(j);
  359 + for (int i = 0; i < lineList.size(); i++) { // 遍历每一段的每一行
  360 + List<String> lineWords = lineList.get(i);
  361 + if (i == lineList.size() - 1) {
  362 + drawScaledEndText(canvas, lineWords, paint);
  363 + } else {
  364 + drawScaledText(canvas, lineWords, paint);
  365 + }
  366 + mLineY += getLineHeight();
  367 + }
  368 + mLineY += paragraphSpacing;
  369 + }
  370 + }
  371 +
  372 + /**
  373 + * 绘制最后一行文字
  374 + *
  375 + * @param canvas
  376 + * @param lineWords
  377 + * @param paint
  378 + */
  379 + private void drawScaledEndText(Canvas canvas, List<String> lineWords, TextPaint paint) {
  380 + if (canvas == null || lineWords == null || paint == null) {
  381 + return;
  382 + }
  383 + StringBuilder sb = new StringBuilder();
  384 + for (String aSplit : lineWords) {
  385 + if (isCN(aSplit)) {
  386 + sb.append(aSplit);
  387 + } else {
  388 + sb.append(aSplit).append(BLANK);
  389 + }
  390 + }
  391 + /**
  392 + * 最后一行适配布局方向
  393 + * android:gravity=""
  394 + * android:textAlignment=""
  395 + * 默认不设置则为左边
  396 + * 如果同时设置gravity和textAlignment属性,则以textAlignment的属性为准
  397 + * 也就是说textAlignment的属性优先级大于gravity的属性
  398 + */
  399 + final int layoutDirection = getLayoutDirection();
  400 + final int absoluteGravity = Gravity.getAbsoluteGravity(getGravity(), layoutDirection);
  401 + int lastGravity = absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
  402 + int textAlignment = getTextAlignment();
  403 +
  404 + if (TEXT_ALIGNMENT_TEXT_START == textAlignment || TEXT_ALIGNMENT_VIEW_START == textAlignment
  405 + || Gravity.LEFT == lastGravity) {
  406 + canvas.drawText(sb.toString(), 0, mLineY, paint);
  407 + } else if (TEXT_ALIGNMENT_TEXT_END == textAlignment || TEXT_ALIGNMENT_VIEW_END == textAlignment
  408 + || Gravity.RIGHT == lastGravity) {
  409 + float width = StaticLayout.getDesiredWidth(sb.toString(), getPaint());
  410 + canvas.drawText(sb.toString(), mViewWidth - width, mLineY, paint);
  411 + } else {
  412 + float width = StaticLayout.getDesiredWidth(sb.toString(), getPaint());
  413 + canvas.drawText(sb.toString(), (mViewWidth - width) / 2, mLineY, paint);
  414 + }
  415 + }
  416 +
  417 + /**
  418 + * 绘制左右对齐效果
  419 + *
  420 + * @param canvas
  421 + * @param line
  422 + * @param paint
  423 + */
  424 + private void drawScaledText(Canvas canvas, List<String> line, TextPaint paint) {
  425 + if (canvas == null || line == null || paint == null) {
  426 + return;
  427 + }
  428 + StringBuilder sb = new StringBuilder();
  429 + for (String aSplit : line) {
  430 + sb.append(aSplit);
  431 + }
  432 +
  433 + float lineWidth = StaticLayout.getDesiredWidth(sb, getPaint());
  434 + float cw = 0;
  435 + float d = (mViewWidth - lineWidth) / (line.size() - 1);
  436 + for (String aSplit : line) {
  437 + canvas.drawText(aSplit, cw, mLineY, getPaint());
  438 + cw += StaticLayout.getDesiredWidth(aSplit + "", paint) + d;
  439 + }
  440 + }
  441 +
  442 + /**
  443 + * 功能:判断字符串是否有中文
  444 + *
  445 + * @param str 字符串
  446 + * @return 是否有中文
  447 + */
  448 + public boolean isCN(String str) {
  449 + try {
  450 + byte[] bytes = str.getBytes("UTF-8");
  451 + if (bytes.length == str.length()) {
  452 + return false;
  453 + } else {
  454 + return true;
  455 + }
  456 + } catch (UnsupportedEncodingException e) {
  457 + // TODO Auto-generated catch block
  458 + e.printStackTrace();
  459 + }
  460 + return false;
  461 + }
  462 +
  463 + public static int dipToPx(Context var0, float var1) {
  464 + float var2 = var0.getResources().getDisplayMetrics().density;
  465 + return (int) (var1 * var2 + 0.5F);
  466 + }
  467 +
  468 + /**
  469 + * 判断是否包含标点符号等内容
  470 + *
  471 + * @param s 字符串
  472 + * @return 是否含有标点符号
  473 + */
  474 + public boolean checkIsSymbol(String s) {
  475 + boolean b = false;
  476 +
  477 + String tmp = s;
  478 + tmp = tmp.replaceAll("\\p{P}", "");
  479 + if (s.length() != tmp.length()) {
  480 + b = true;
  481 + }
  482 +
  483 + return b;
  484 + }
  485 +}
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<shape xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <gradient
  4 + android:type="linear"
  5 + android:startColor="#80000000"
  6 + android:endColor="#00000000"
  7 + android:angle="90" />
  8 +</shape>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + android:id="@+id/clEmptyArea"
  6 + android:layout_width="match_parent"
  7 + android:layout_height="match_parent">
  8 +
  9 + <!-- 做背景用-->
  10 + <LinearLayout
  11 + android:id="@+id/llDetail"
  12 + android:layout_width="match_parent"
  13 + android:layout_height="0dp"
  14 + android:orientation="vertical"
  15 + app:layout_constraintBottom_toBottomOf="@+id/clContent"
  16 + app:layout_constraintTop_toTopOf="@+id/clContent">
  17 +
  18 + <!-- 从透明0到1的渐变 -->
  19 + <View
  20 + android:id="@+id/v1"
  21 + android:layout_width="match_parent"
  22 + android:layout_height="0dp"
  23 + android:layout_weight="7"
  24 + android:background="@drawable/shape_gradient_short_video_describe_dialog_bg"
  25 + app:layout_constraintBottom_toTopOf="@+id/v2"
  26 + app:layout_constraintTop_toTopOf="parent" />
  27 +
  28 + <!-- 透明度 1 -->
  29 + <View
  30 + android:id="@+id/v2"
  31 + android:layout_width="match_parent"
  32 + android:layout_height="0dp"
  33 + android:layout_weight="3"
  34 + android:background="@color/color_000000"
  35 + app:layout_constraintBottom_toBottomOf="parent"
  36 + app:layout_constraintTop_toBottomOf="@+id/v1"
  37 + app:layout_constraintTop_toTopOf="parent" />
  38 +
  39 + </LinearLayout>
  40 +
  41 + <!-- 查看详情的内容 -->
  42 + <androidx.constraintlayout.widget.ConstraintLayout
  43 + android:id="@+id/clContent"
  44 + android:layout_width="match_parent"
  45 + android:layout_height="wrap_content"
  46 + app:layout_constraintBottom_toBottomOf="parent">
  47 +
  48 + <!-- 作者-->
  49 + <TextView
  50 + android:id="@+id/tv_author"
  51 + android:layout_width="wrap_content"
  52 + android:layout_height="wrap_content"
  53 + android:layout_marginStart="@dimen/rmrb_dp16"
  54 + android:layout_marginTop="@dimen/rmrb_dp62"
  55 + android:clickable="true"
  56 + android:textColor="@color/res_color_common_C8_keep"
  57 + android:textSize="@dimen/rmrb_dp14"
  58 + android:textStyle="bold"
  59 + app:layout_constraintStart_toStartOf="parent"
  60 + app:layout_constraintTop_toTopOf="parent"
  61 + tools:text="\@每日经济新闻" />
  62 +
  63 + <com.wd.common.widget.MaxHeightScrollView
  64 + android:id="@+id/svContent"
  65 + android:layout_width="match_parent"
  66 + android:layout_height="wrap_content"
  67 + app:maxScrollHeight="@dimen/rmrb_dp210"
  68 + app:layout_constraintTop_toBottomOf="@+id/tv_author">
  69 +
  70 + <LinearLayout
  71 + android:id="@+id/llContent"
  72 + android:layout_width="match_parent"
  73 + android:layout_height="wrap_content"
  74 + android:orientation="vertical">
  75 +
  76 + <!-- 标题-->
  77 + <TextView
  78 + android:id="@+id/tv_title"
  79 + android:layout_width="match_parent"
  80 + android:layout_height="wrap_content"
  81 + android:clickable="true"
  82 + android:lineSpacingMultiplier="1.1"
  83 + android:layout_marginStart="@dimen/rmrb_dp16"
  84 + android:layout_marginTop="@dimen/rmrb_dp8"
  85 + android:layout_marginEnd="@dimen/rmrb_dp16"
  86 + android:textColor="@color/res_color_common_C8_keep"
  87 + android:textSize="@dimen/rmrb_dp16"
  88 + android:textStyle="bold"
  89 + tools:text="深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通深圳首条跨海通道单线盾构贯通" />
  90 +
  91 + <!-- 描述-->
  92 + <TextView
  93 + android:id="@+id/tv_description"
  94 + android:layout_width="match_parent"
  95 + android:layout_height="wrap_content"
  96 + android:clickable="true"
  97 + android:lineSpacingMultiplier="1.1"
  98 + android:layout_marginStart="@dimen/rmrb_dp16"
  99 + android:layout_marginTop="@dimen/rmrb_dp2"
  100 + android:layout_marginEnd="@dimen/rmrb_dp16"
  101 + android:textColor="@color/res_color_common_C8_keep"
  102 + android:textSize="@dimen/rmrb_dp14"
  103 + tools:text="当日,中铁隧道局承建的深圳首条跨海通道——妈湾跨海通道右线实现贯通。妈湾跨海通道工程线路全长8.05公里,是连接深圳南山区前海片区和宝安区的海底地下工程。此次贯通的妈湾跨海通道右线盾构全长2063米,是整条线路的控制性工程当日,中铁隧道局承建的深圳首条跨海通道——妈湾跨海通道右线实现贯通。妈湾跨海通道工程线路全长8.05公里,是连接深圳南山区前海片区和宝安区的海底地下工程。此次贯通的妈湾跨海通道右线盾构全长2063米,是整条线路的控制性工程" />
  104 +
  105 + <TextView
  106 + android:id="@+id/tv_time"
  107 + android:layout_width="wrap_content"
  108 + android:layout_height="wrap_content"
  109 + android:textSize="@dimen/rmrb_dp13"
  110 + android:textColor="@color/res_color_general_B3FFFFFF_keep"
  111 + android:layout_marginTop="@dimen/rmrb_dp8"
  112 + android:layout_marginStart="@dimen/rmrb_dp16"
  113 + android:visibility="gone"/>
  114 +
  115 + </LinearLayout>
  116 +
  117 + </com.wd.common.widget.MaxHeightScrollView>
  118 +
  119 + <!-- 关闭按钮-->
  120 + <ImageView
  121 + android:id="@+id/iv_close"
  122 + android:layout_width="@dimen/rmrb_dp24"
  123 + android:layout_height="@dimen/rmrb_dp24"
  124 + android:layout_marginTop="@dimen/rmrb_dp17"
  125 + android:layout_marginBottom="@dimen/rmrb_dp30"
  126 + android:src="@mipmap/ic_video_desc_close"
  127 + app:layout_constraintBottom_toBottomOf="parent"
  128 + app:layout_constraintLeft_toLeftOf="parent"
  129 + app:layout_constraintRight_toRightOf="parent"
  130 + app:layout_constraintTop_toBottomOf="@+id/svContent" />
  131 +
  132 + </androidx.constraintlayout.widget.ConstraintLayout>
  133 +
  134 +</androidx.constraintlayout.widget.ConstraintLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +
  3 +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + android:id="@+id/expand_root_fl"
  6 + android:layout_width="match_parent"
  7 + android:layout_height="wrap_content"
  8 + tools:background="@color/color_000000">
  9 +
  10 + <LinearLayout
  11 + android:id="@+id/expand_ll"
  12 + android:layout_width="wrap_content"
  13 + android:layout_height="wrap_content"
  14 + android:layout_gravity="bottom|right"
  15 + android:gravity="right"
  16 + android:layout_marginRight="@dimen/rmrb_dp2"
  17 + android:visibility="gone"
  18 + tools:visibility="visible"
  19 + android:orientation="horizontal">
  20 +
  21 + <TextView
  22 + android:id="@+id/expand_tv"
  23 + android:layout_width="wrap_content"
  24 + android:layout_height="wrap_content"
  25 + android:drawablePadding="@dimen/rmrb_dp6"
  26 + android:text="全部"
  27 + android:textColor="#ffffff"
  28 + android:textSize="@dimen/rmrb_dp14"
  29 + android:visibility="visible" />
  30 +
  31 + <TextView
  32 + android:id="@+id/expand_helper_tv"
  33 + android:layout_width="0.5dp"
  34 + android:layout_height="wrap_content"
  35 + android:text=""
  36 + android:textColor="#333333"
  37 + android:textSize="@dimen/rmrb_dp14"
  38 + tools:visibility="visible"
  39 + android:visibility="gone" />
  40 +
  41 + <ImageView
  42 + android:id="@+id/expand_iv"
  43 + android:layout_width="@dimen/rmrb_dp12"
  44 + android:layout_height="@dimen/rmrb_dp12"
  45 + android:layout_marginTop="@dimen/rmrb_dp4"
  46 + android:src="@mipmap/icon_more_arrow_white"
  47 + android:scaleType="fitXY"
  48 + android:visibility="gone"
  49 + tools:visibility="gone" />
  50 +
  51 + </LinearLayout>
  52 +
  53 + <TextView
  54 + android:id="@+id/expand_content_tv"
  55 + android:layout_width="match_parent"
  56 + android:layout_height="wrap_content"
  57 + android:text=""
  58 + android:textColor="#333333"
  59 + android:textSize="@dimen/rmrb_dp14" />
  60 +
  61 +</FrameLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +
  3 +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + xmlns:app="http://schemas.android.com/apk/res-auto"
  6 + android:id="@+id/expand_root_fl"
  7 + android:layout_width="match_parent"
  8 + android:layout_height="wrap_content"
  9 + tools:background="@color/color_000000">
  10 +
  11 + <LinearLayout
  12 + android:id="@+id/expand_ll"
  13 + android:layout_width="wrap_content"
  14 + android:layout_height="wrap_content"
  15 + android:layout_gravity="bottom|right"
  16 + android:gravity="right"
  17 + android:layout_marginRight="@dimen/rmrb_dp2"
  18 + android:visibility="gone"
  19 + tools:visibility="visible"
  20 + android:orientation="horizontal">
  21 +
  22 + <TextView
  23 + android:id="@+id/expand_tv"
  24 + android:layout_width="wrap_content"
  25 + android:layout_height="wrap_content"
  26 + android:drawablePadding="@dimen/rmrb_dp6"
  27 + android:textStyle=""
  28 + android:text="全部"
  29 + android:textColor="#ffffff"
  30 + android:textSize="@dimen/rmrb_dp14"
  31 + android:visibility="visible" />
  32 +
  33 + <TextView
  34 + android:id="@+id/expand_helper_tv"
  35 + android:layout_width="0.5dp"
  36 + android:layout_height="wrap_content"
  37 + android:text=""
  38 + android:textColor="#333333"
  39 + android:textSize="@dimen/rmrb_dp14"
  40 + tools:visibility="visible"
  41 + android:visibility="gone" />
  42 +
  43 + <ImageView
  44 + android:id="@+id/expand_iv"
  45 + android:layout_width="@dimen/rmrb_dp12"
  46 + android:layout_height="@dimen/rmrb_dp12"
  47 + android:layout_marginTop="@dimen/rmrb_dp4"
  48 + android:src="@mipmap/icon_more_arrow_white"
  49 + android:scaleType="fitXY"
  50 + android:visibility="gone"
  51 + tools:visibility="gone" />
  52 +
  53 + </LinearLayout>
  54 +
  55 + <com.wd.foundation.wdkit.view.customtextview.StrokeWidthTextView
  56 + android:id="@+id/expand_content_tv"
  57 + android:layout_width="match_parent"
  58 + android:layout_height="wrap_content"
  59 + app:text_stroke_width="1"
  60 + tools:text="标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题"
  61 + android:textColor="@color/white"
  62 + android:textSize="@dimen/rmrb_dp14" />
  63 +
  64 +</FrameLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +
  3 +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + android:id="@+id/expand_root_fl"
  6 + android:layout_width="match_parent"
  7 + android:layout_height="wrap_content">
  8 +
  9 + <LinearLayout
  10 + android:id="@+id/expand_ll"
  11 + android:layout_width="wrap_content"
  12 + android:layout_height="wrap_content"
  13 + android:layout_gravity="bottom|right"
  14 + android:gravity="right"
  15 + android:layout_marginRight="@dimen/rmrb_dp2"
  16 + android:orientation="horizontal"
  17 + tools:visibility="visible"
  18 + android:visibility="gone">
  19 +
  20 + <TextView
  21 + android:id="@+id/expand_tv"
  22 + android:layout_width="wrap_content"
  23 + android:layout_height="wrap_content"
  24 + tools:background="@color/color_000000"
  25 + android:text="全部"
  26 + android:paddingBottom="@dimen/rmrb_dp2"
  27 + android:textColor="#ffffff"
  28 + android:textSize="@dimen/rmrb_dp14"
  29 + android:visibility="visible" />
  30 +
  31 + <TextView
  32 + android:id="@+id/expand_helper_tv"
  33 + android:layout_width="0.5dp"
  34 + android:layout_height="wrap_content"
  35 + android:text=""
  36 + android:textColor="#333333"
  37 + android:textSize="@dimen/rmrb_dp14"
  38 + tools:visibility="visible"
  39 + android:visibility="gone" />
  40 +
  41 + <ImageView
  42 + android:id="@+id/expand_iv"
  43 + android:layout_width="@dimen/rmrb_dp12"
  44 + android:layout_height="@dimen/rmrb_dp22"
  45 + android:layout_marginLeft="@dimen/rmrb_dp6"
  46 + android:scaleType="fitXY"
  47 + android:visibility="gone" />
  48 + </LinearLayout>
  49 +
  50 + <com.wd.common.widget.expand.XQJustifyTextView
  51 + android:id="@+id/expand_content_tv"
  52 + android:layout_width="match_parent"
  53 + android:layout_height="wrap_content"
  54 + android:lineSpacingExtra="@dimen/rmrb_dp2"
  55 + android:text="【不是特效!25岁小伙空翻打卡25处郑州地标】5月22日,河南郑州。25岁跑酷爱好者贠禾嘉花了近3天时间,用后空翻的形式打卡郑州25个地标性建筑,用时1小时15分钟。"
  56 + android:textColor="#333333"
  57 + android:textSize="@dimen/rmrb_dp14" />
  58 +
  59 + <View
  60 + android:id="@+id/newlineV"
  61 + android:layout_width="wrap_content"
  62 + android:layout_height="@dimen/rmrb_dp14"
  63 + android:layout_below="@+id/expand_content_tv"
  64 + android:visibility="gone"></View>
  65 +
  66 +</FrameLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + android:id="@+id/llProgressTime"
  6 + android:layout_width="wrap_content"
  7 + android:layout_height="wrap_content"
  8 + android:orientation="horizontal"
  9 + tools:background="@color/color_000000">
  10 +
  11 + <TextView
  12 + android:id="@+id/tvPlayProgress"
  13 + android:layout_width="wrap_content"
  14 + android:layout_height="wrap_content"
  15 + android:textColor="@color/color_80FFFFFF"
  16 + android:textSize="@dimen/rmrb_dp24"
  17 + android:textStyle="bold" />
  18 +
  19 + <TextView
  20 + android:id="@+id/tvPlayProgressSlash"
  21 + android:layout_width="wrap_content"
  22 + android:layout_height="wrap_content"
  23 + android:layout_gravity="center_vertical"
  24 + android:layout_marginLeft="@dimen/rmrb_dp10"
  25 + android:layout_marginRight="@dimen/rmrb_dp10"
  26 + android:text="/"
  27 + android:textColor="@color/color_80FFFFFF"
  28 + android:textSize="@dimen/rmrb_dp12"
  29 + android:textStyle="bold" />
  30 +
  31 + <TextView
  32 + android:id="@+id/tvPlayTotalTime"
  33 + android:layout_width="wrap_content"
  34 + android:layout_height="wrap_content"
  35 + android:textColor="@color/color_80FFFFFF"
  36 + android:textSize="@dimen/rmrb_dp24"
  37 + android:textStyle="bold" />
  38 +
  39 +</LinearLayout>
  1 +<?xml version="1.0" encoding="utf-8"?><!-- 全局区域动画(全域动画)加载动画 refreshing_btm_loading.pag -->
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + android:layout_width="match_parent"
  5 + android:layout_height="wrap_content"
  6 + android:gravity="center"
  7 + android:orientation="horizontal"
  8 + android:paddingTop="@dimen/rmrb_dp24"
  9 + android:paddingBottom="@dimen/rmrb_dp24">
  10 +
  11 + <com.airbnb.lottie.LottieAnimationView
  12 + android:id="@+id/animation_view"
  13 + android:layout_width="@dimen/rmrb_dp12"
  14 + android:layout_height="@dimen/rmrb_dp12"
  15 + app:lottie_autoPlay="false"
  16 + app:lottie_loop="true" />
  17 +
  18 + <TextView
  19 + android:id="@+id/tv_desc"
  20 + android:layout_width="wrap_content"
  21 + android:layout_height="wrap_content"
  22 + android:layout_gravity="center_horizontal"
  23 + android:text="努力加载中"
  24 + android:layout_marginLeft="@dimen/rmrb_dp6"
  25 + android:textColor="@color/res_color_888888"
  26 + android:textSize="@dimen/rmrb_dp12" />
  27 +
  28 +</LinearLayout>
@@ -30,4 +30,6 @@ @@ -30,4 +30,6 @@
30 <color name="alivc_common_bg_cyan_grey">#515254</color> 30 <color name="alivc_common_bg_cyan_grey">#515254</color>
31 <color name="color_73666666">#73666666</color> 31 <color name="color_73666666">#73666666</color>
32 <color name="red_theme_bg">#FFCC2424</color> 32 <color name="red_theme_bg">#FFCC2424</color>
  33 +
  34 + <color name="main_activity_top_img_bg">#FF7800</color>
33 </resources> 35 </resources>
@@ -568,4 +568,47 @@ @@ -568,4 +568,47 @@
568 <enum name="serif" value="3" /> 568 <enum name="serif" value="3" />
569 </attr> 569 </attr>
570 </declare-styleable> 570 </declare-styleable>
  571 +
  572 + <!--可展开布局自定义属性-->
  573 + <declare-styleable name="ExpandTextView">
  574 + <!--文本最大缩略行数,对应于TextView的maxLines-->
  575 + <attr name="maxLines" format="integer" />
  576 + <!--展开时对应的图片-->
  577 + <attr name="expandIconResId" format="reference" />
  578 + <!--不展开时对应的图片-->
  579 + <attr name="collapseIconResId" format="reference" />
  580 + <!--展开图片距离顶部距离-->
  581 + <attr name="expandIconTop" format="integer" />
  582 + <!--展开时对应末尾提示的文字-->
  583 + <attr name="expandMoreText" format="string" />
  584 + <!--不展开时对应末尾提示的文字-->
  585 + <attr name="collapseLessText" format="string" />
  586 + <!--内容文字的颜色-->
  587 + <attr name="contentTextColor" format="reference|color" />
  588 + <!--更多或收起文字的颜色-->
  589 + <attr name="expandTextColor" format="reference|color" />
  590 + <!--文字大小-->
  591 + <attr name="contentTextSize" format="dimension" />
  592 + <!--更多/收起文字大小-->
  593 + <attr name="expandTextSize" format="dimension" />
  594 + <!--展开/收缩布局对应图标的宽度-->
  595 + <attr name="expandIconWidth" format="dimension" />
  596 + <!--缩略文本展示时与展开/收缩布局的间距-->
  597 + <attr name="spaceMargin" format="dimension" />
  598 + <!--文本显示的lineSpacingExtra,对应于TextView的lineSpacingExtra属性-->
  599 + <attr name="lineSpacingExtra" format="dimension" />
  600 + <!--文本显示的lineSpacingMultiplier,对应于TextView的lineSpacingMultiplier属性-->
  601 + <attr name="lineSpacingMultiplier" format="float" />
  602 + <!--展开样式-->
  603 + <attr name="expandStyle" format="integer">
  604 + <!--默认样式:图标+文字-->
  605 + <enum name="DEFAULT" value="0" />
  606 + <enum name="ICON" value="1" />
  607 + <enum name="TEXT" value="2" />
  608 + </attr>
  609 + <!--是否收缩-->
  610 + <attr name="isShrink" format="boolean" />
  611 + <!--是否左右对齐-->
  612 + <attr name="isJustify" format="boolean" />
  613 + </declare-styleable>
571 </resources> 614 </resources>
@@ -49,7 +49,10 @@ android { @@ -49,7 +49,10 @@ android {
49 49
50 dependencies { 50 dependencies {
51 51
  52 + implementation project(path: ':module_musicplayer')
  53 + implementation project(path: ':wdkitcore')
52 implementation project(path: ':wdlayout') 54 implementation project(path: ':wdlayout')
  55 + implementation project(path: ':base_comment')
53 annotationProcessor rootProject.ext.dependencies["arouter-compiler"] 56 annotationProcessor rootProject.ext.dependencies["arouter-compiler"]
54 implementation rootProject.ext.dependencies["TagTextView"] 57 implementation rootProject.ext.dependencies["TagTextView"]
55 // coreLibraryDesugaring rootProject.ext.dependencies["desugar_jdk_libs"] 58 // coreLibraryDesugaring rootProject.ext.dependencies["desugar_jdk_libs"]
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 - package="com.people.module_player"> 3 + package="com.wd.module_videoplayer">
4 4
5 <application> 5 <application>
  6 + <activity
  7 + android:name=".ui.ShortVideoActivity"
  8 + android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout|uiMode"
  9 + android:resizeableActivity="true"
  10 + android:supportsPictureInPicture="true"/>
6 </application> 11 </application>
7 12
8 </manifest> 13 </manifest>