123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package com.ys.bdtp.cad.test
- import android.graphics.Bitmap
- import android.graphics.Canvas
- import android.graphics.Color
- import android.graphics.Matrix
- import android.graphics.Paint
- import android.graphics.RectF
- import android.util.Log
- import com.ys.bdtp.graph.SGraphyItem
- import com.ys.bdtp.graph.SMotionEvent
- import com.ys.bdtp.graph.enums.SGraphyItemFlag
- import java.util.*
- /**
- * 设备
- * @author Andy
- */
- class GraphyFmItem(parent: SGraphyItem? = null) : SGraphyItem(parent) {
- // 画笔
- private var pen = Paint()
- var flag:Boolean = false
- var isClick:Boolean = false
- /** 当前设备 */
- var isCurrent:Boolean=false
- private lateinit var bitmapdianbiao:Bitmap
- private lateinit var bitmapequipment:Bitmap
- private lateinit var decodeResource:Bitmap
- private var bitheight = 0
- private var bitwidth = 0
- /** png图数据 */
- private var pngWidth = 16
- private var pngHeight = 16
- /** png定位点的坐标 */
- private val pngLocatX = 8
- private val pngLocatY = 14
- /** 原始宽 */
- private var originalWidth = 0
- /** 原始高 */
- private var originalHeight = 0
- private var rate = 1f
- var color = Color.BLACK
- /**
- * 默认构造函数
- */
- init {
- // hide()
- isClick=true
- isCurrent=false
- pen.color = color
- pen.strokeWidth = 5f
- pen.isAntiAlias=false
- /** item获取焦点ItemIsFocusable,移动ItemIsMovable */
- flags= EnumSet.of(SGraphyItemFlag.ItemIsFocusable)
- } // init
- /**
- * Item对象边界区域
- */
- override fun boundingRect(): RectF {
- return RectF(0f,0f,600f,300f)
- } // Function boundingRect()
- /**
- * @param canvas 画布对象
- */
- override fun onDraw(canvas: Canvas) {
- try {
- canvas.drawRect(0f,0f,600f,300f,pen)
- invalidate()
- } catch (e: Exception) {
- e.printStackTrace()
- }
- return
- } // Function paint()
- /**
- * 点击
- */
- override fun onSingleTapUp(e: SMotionEvent): Boolean {
- Log.e("被点击1","**************************************")
- return true
- }
- /**
- *
- * @param bm 传入的bitmap
- * @param newWidth 指定的图片宽
- * @param newHeight 指定的图片高
- * @return newbm 返回 bitmap类型
- */
- private fun setImgSize(bm: Bitmap?, newWidth: Int, newHeight: Int): Bitmap {
- // 获得图片的宽高.
- val width = bm!!.width
- val height = bm.height
- // 计算缩放比例.
- val scaleWidth = newWidth.toFloat() / width
- val scaleHeight = newHeight.toFloat() / height
- // 取得想要缩放的matrix参数.
- val matrix = Matrix()
- matrix.postScale(scaleWidth, scaleHeight)
- // bm.config = Bitmap.Config.RGB_565
- // 得到新的图片.
- return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true)
- }
- } // Class GraphyWallItem
|