首页 > 编程语言 >直播商城系统源码,自定义View实现方向控制控件,可拖拽中间圆

直播商城系统源码,自定义View实现方向控制控件,可拖拽中间圆

时间:2023-08-02 14:14:01浏览次数:42  
标签:控件 自定义 paintDirection int private halfHeight 源码 halfWidth path

直播商城系统源码,自定义View实现方向控制控件,可拖拽中间圆

 

public class DirectionView extends View implements View.OnTouchListener {
    private int width;
    private int height;
    private int halfWidth;
    private int halfHeight;
    private int smallCircleRadius;
 
    private int sideWidth = 4;//外层边框宽度
 
    private Paint paintCircleSide;
    private Paint paintCircleBg;
    private Paint paintCircleCenter;
    private Paint paintDirection;
 
    private int pressDirectionH = 0;
    private int pressDirectionV = 0;
 
    private int smallCircleCenterX = -1;
    private int smallCircleCenterY = -1;
    private int halfTouchWidth = 65;
 
    private BlurMaskFilter blurMaskFilter;
    private Path path = new Path();
 
    public DirectionView(Context context) {
        super(context);
        init(context);
    }
 
    public DirectionView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }
 
    public DirectionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }
 
    private void init(Context context)
    {
        paintCircleSide = createPaintWithCommon(sideWidth, "#66ffffff", Paint.Style.STROKE);
        paintCircleBg = createPaintWithCommon(2, "#662a3845", Paint.Style.FILL);
        paintCircleCenter = createPaintWithCommon(2, "#ffffff", Paint.Style.FILL);
        paintDirection = createPaintWithCommon(6, "#ffffff", Paint.Style.STROKE);
 
        blurMaskFilter = new BlurMaskFilter(20, BlurMaskFilter.Blur.SOLID);
 
        this.setOnTouchListener(this);
    }
 
    private Paint createPaintWithCommon(int strokeWidth, String color, Paint.Style style)
    {
        Paint paint = new Paint();
        paint.setStrokeWidth(strokeWidth);
        paint.setColor(Color.parseColor(color));
        paint.setStyle(style);
        paint.setAntiAlias(true);
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStrokeCap(Paint.Cap.ROUND);
        return paint;
    }
 
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
 
        canvas.drawCircle(halfWidth, halfHeight, halfWidth - sideWidth / 2, paintCircleBg);
        canvas.drawCircle(halfWidth, halfHeight, halfWidth - sideWidth, paintCircleSide);
 
        if(this.smallCircleCenterY != -1)
        {
//            paintCircleCenter.setMaskFilter(blurMaskFilter);
            canvas.drawCircle(smallCircleCenterX, smallCircleCenterY, smallCircleRadius, paintCircleCenter);
        }
        else
        {
//            paintCircleCenter.setMaskFilter(null);
            canvas.drawCircle(halfWidth, halfHeight, smallCircleRadius, paintCircleCenter);
        }
 
        int offsetSize = 25;
        int offsetPosition = 20;
 
        //上
        if(pressDirectionV == PtzAction.Direction.Up)
            paintDirection.setColor(Color.parseColor("#0000ff"));
        else
            paintDirection.setColor(Color.parseColor("#ffffff"));
 
        path.reset();
        path.moveTo(halfWidth - offsetSize, halfHeight / 2 - offsetPosition);
        path.lineTo(halfWidth, halfHeight / 2 - offsetSize - offsetPosition);
        path.lineTo(halfWidth + offsetSize, halfHeight / 2 - offsetPosition);
        canvas.drawPath(path, paintDirection);
 
        //右
        if(pressDirectionH == PtzAction.Direction.Right)
            paintDirection.setColor(Color.parseColor("#0000ff"));
        else
            paintDirection.setColor(Color.parseColor("#ffffff"));
 
        path.reset();
        path.moveTo(halfWidth + halfWidth / 2 + offsetPosition, halfHeight - offsetSize);
        path.lineTo(halfWidth + halfWidth / 2 + offsetPosition + offsetSize, halfHeight);
        path.lineTo(halfWidth + halfWidth / 2 + offsetPosition, halfHeight + offsetSize);
        canvas.drawPath(path, paintDirection);
 
        //下
        if(pressDirectionV == PtzAction.Direction.Down)
            paintDirection.setColor(Color.parseColor("#0000ff"));
        else
            paintDirection.setColor(Color.parseColor("#ffffff"));
 
        path.reset();
        path.moveTo(halfWidth - offsetSize, halfHeight + halfHeight / 2 + offsetPosition);
        path.lineTo(halfWidth, halfHeight + halfHeight / 2 + offsetSize + offsetPosition);
        path.lineTo(halfWidth + offsetSize, halfHeight + halfHeight / 2 + offsetPosition);
        canvas.drawPath(path, paintDirection);
 
        //左
        if(pressDirectionH == PtzAction.Direction.Left)
            paintDirection.setColor(Color.parseColor("#0000ff"));
        else
            paintDirection.setColor(Color.parseColor("#ffffff"));
 
        path.reset();
        path.moveTo(halfWidth / 2 - offsetPosition, halfHeight - offsetSize);
        path.lineTo(halfWidth / 2 - offsetPosition - offsetSize, halfHeight);
        path.lineTo(halfWidth / 2 - offsetPosition, halfHeight + offsetSize);
        canvas.drawPath(path, paintDirection);
    }

 

 以上就是直播商城系统源码,自定义View实现方向控制控件,可拖拽中间圆, 更多内容欢迎关注之后的文章

 

标签:控件,自定义,paintDirection,int,private,halfHeight,源码,halfWidth,path
From: https://www.cnblogs.com/yunbaomengnan/p/17600512.html

相关文章

  • 视频直播源码,android:textColor设置无效
    视频直播源码,android:textColor设置无效title_color.xml <?xmlversion="1.0"encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android">  <itemandroid:color="@color/txt_blue"/>......
  • 借助Aspose.Slides 控件,快速在线将 PNG 转换为 PPT
    Aspose.Slides 是一款PowerPoint管理API,用于读取,编写,操作和转换PowerPoint幻灯片的独立API,可将PowerPoint转换为PDF,PDF/A,XPS,TIFF,HTML,ODP和其他PowerPoint格式。AsposeAPI支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。PowerPoin......
  • 盘点一对一源码iOS系统维持平台稳定功能(一):弹性扩缩容
    在移动互联网快速发展的时代,直播成为了一个火爆的行业,并成功进入到Android、iOS、鸿蒙系统中,人们只需具备网络与能下载直播平台的设备便可使用到一对一直播源码平台,所以几乎全世界的人们都成为了平台的用户,这就使得一对一直播源码平台的用户人数的庞大,但毕竟一对一直播源码平台是一......
  • PHP客服系统聊天页面-thinkphp加载页面源码解释
    PHPworkerman客服系统加载聊天页面的代码逻辑流程,可以进行参考。如果想要二开修改的,可以根据这个流程来修改。thinkphp的router部分Route::get('kefu/:u/:f?','index/index/chat');查看控制器加载页面逻辑application/index/controller/Index.phppublicfunctionchat函......
  • scrapy源码分析:redis分布式爬虫队列中,priority值越大,优先级越高
    scrapy源码分析:redis分布式爬虫队列中,priority值越大,优先级越高一、背景scrapy爬虫项目中,遇到scrapy的priority属性,搞不懂priority的值越大优先级越高,还是值越小优先级越高#通过priority修改优先级returnscrapy.Request(url=request.url,dont_filter=True,callback=spider......
  • 盘点一对一直播源码iOS系统维持平台稳定功能(一):弹性扩缩容
    在移动互联网快速发展的时代,直播成为了一个火爆的行业,并成功进入到Android、iOS、鸿蒙系统中,人们只需具备网络与能下载直播平台的设备便可使用到一对一直播源码平台,所以几乎全世界的人们都成为了平台的用户,这就使得一对一直播源码平台的用户人数的庞大,但毕竟一对一直播源码平台是......
  • 流程引擎表单:可自定义和多场景应用,快速助力提质增效!
    当前,在办公职场中,传统表单制作暴露出越来越多的漏洞,已经无法满足日益增长的业务需求。采用什么样的平台和软件可以提高效率?低代码技术平台是深得客户喜爱的一种快速框架平台,其中的流程引擎表单是其主要功能之一,可以助力提升办公协作效率,满足广大用户流程化办公的心愿。随着社会发......
  • react源码解析手写ReactDom.js和React
    前言大家好我是歌谣今天给大家带来react源码部分的实现创建项目首先npxcreate-react-appxxx降为17"dependencies":{"@testing-library/jest-dom":"^5.11.4","@testing-library/react":"^11.1.0","@testing-library/user-event&......
  • vue--day50--todolist案例自定义事件修改footer 和header 修改
    1.MyHeader.vue<template><divclass="todo-header"><!--v-model:="title"是实时绑定的--><inputtype="text"placeholder="请输入你的任务名称,回车键确认"v-model="title"@keyup.enter="add"/>......
  • 若依--自定义loadUserByUsername参数入参
    若依--自定义loadUserByUsername参数入参前言在使用若依的Security的登录认证时,默认只能使用用户名去查询sysUser,当我需要额外的参数去查询用户数据时,只能将用户名和额外参数组成json或者特定字符拼接,然后在UserDetailsServiceImpl的loadUserByUsername方法自定义查询数据。但是......