public static TaskSpan getAudioSpan(Context context, int type, String json, String time, int progress) {
View spanView = View.inflate(context, R.layout.bbs_audio_bar_tag, null);
LinearLayout llBg = (LinearLayout) spanView.findViewById(R.id.ll_bg);
ImageView icPlay = (ImageView) spanView.findViewById(R.id.iv_play);
ImageView icStop = (ImageView) spanView.findViewById(R.id.iv_stop);
TextView tvTime = (TextView) spanView.findViewById(R.id.tv_time);
ProgressBar proBar = (ProgressBar) spanView.findViewById(R.id.progress_bar);
switch (type) {
case AUDIO_PLAY_NONE:
try {
final String[] split = json.split(BBSConstants.SPLIT_TAG);
JSONObject obj = new JSONObject(split[1]);
final JSONObject data = obj.optJSONObject(Constants.RETURN_DATA);
int duration = data.optInt(BBSConstants.LONG_DATA_DURATION);
tvTime.setText(DateUtil.getDurationTime(duration / 1000, false));
proBar.setProgress(0);
icPlay.setVisibility(View.VISIBLE);
icStop.setVisibility(View.GONE);
llBg.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.grey_bg_50dp_corner_no_border));
} catch (JSONException e) {
e.printStackTrace();
}
break;
case AUDIO_PLAY_ING:
proBar.setProgress(progress);
icPlay.setVisibility(View.GONE);
icStop.setVisibility(View.VISIBLE);
llBg.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.blue_bg_50dp_corner_no_border));
tvTime.setText(time);
break;
}
BitmapDrawable drawable = (BitmapDrawable) ViewUtil.convertViewToDrawable(spanView);
drawable.setTargetDensity(MyApplication.getInstance().getResources().getDisplayMetrics());
final float scale = 1.0f / 6.0f;
final int width = DeviceUtil.getScreenWidth((Activity) context) - DeviceUtil.dip2px(context, LENGTH);
float height = (float) width * scale;
drawable.setBounds(0, 0, width, (int) height);
return new TaskSpan(drawable, type, json);
}
package com.gnet.uc.activity.appcenter;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import android.widget.TextView;
/**
* 集结号富文本Span的点击事件
*
* @author lei.han
* @time 2017/6/20 下午11:02
*/
public class TaskMovementMethod extends LinkMovementMethod {
public boolean onTouchEvent(TextView widget, Spannable buffer,
MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
float xLeft = layout.getPrimaryHorizontal(off);
if (xLeft < x) {
off += 1;
} else {
off -= 1;
}
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
TaskSpan[] spans = buffer.getSpans(off, off, TaskSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer,
buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
}
return true;
} else if (spans.length != 0) {
if (action == MotionEvent.ACTION_UP) {
spans[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer,
buffer.getSpanStart(spans[0]),
buffer.getSpanEnd(spans[0]));
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return false;
}
}
editText.setMovementMethod(new TaskMovementMethod());
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有