Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
9.7 kB
4
Indexable
Never
private fun coordinateData(jArrayimage: JSONArray?, result: Bitmap) {

//        canvas= Canvas(result)
        try {
            for (j in 0 until jArrayimage!!.length()) {
                val jObjectimg = jArrayimage.getJSONObject(j)
                imageSessions = ArrayList()
                coords = jObjectimg.getString("coords")
                user_id = jObjectimg.getString("user_id")
                headig = jObjectimg.getString("Heading")
                stand_number = jObjectimg.getString("stand_number")
                exid = jObjectimg.getString("exid")
                firstname = jObjectimg.getString("Firstname")
                lastname = jObjectimg.getString("Lastname")
                email = jObjectimg.getString("Email")
                isSession = jObjectimg.getString("is_session")
                company_logo = jObjectimg.getString("company_logo")

                var is_favorites="0"
                if(jObjectimg.has("is_favorites"))
                {
                    is_favorites=jObjectimg.getString("is_favorites")
                }

                val jArraySession = jObjectimg.getJSONArray("session")
                for (s in 0 until jArraySession.length()) {
                    val jObjectSession = jArraySession.getJSONObject(s)
                    str_sId = jObjectSession.getString("sid")
                    str_sHeading = jObjectSession.getString("session_heading")
                    str_sSDate = jObjectSession.getString("Start_date")
                    str_sTime = jObjectSession.getString("Start_time")
                    imageSessions!!.add(
                            MapImageSession(
                                    str_sId!!,
                                    str_sHeading!!,
                                    str_sSDate!!,
                                    str_sTime!!
                            )
                    )
                }
                img_MappingArray!!.add(
                        ImageMappingDetail(
                                coords!!,
                                user_id!!,
                                headig!!,
                                stand_number!!,
                                exid!!,
                                firstname!!,
                                lastname!!,
                                email!!,
                                GlobalData.getImageUrl(sessionManager) + company_logo,
                                isSession,
                                imageSessions!!
                        )
                )
                val split_coords = coords?.split(",".toRegex())?.toTypedArray()
                top = split_coords?.get(0)
                left = split_coords?.get(1)
                right = split_coords?.get(2)
                bottom = split_coords?.get(3)
                val rect = Rect(top!!.toInt(), left!!.toInt(), right!!.toInt(), bottom!!.toInt())
                rectangles.add(MapCoordinatesDetails(rect, headig!!))

                if(GlobalData.IS_FROM_EXHIBITORS)
                {
                    val canvas1 = Canvas(result)
                    val paint1 = Paint()

                    if (!SessionManager.Map_coords.equals("", ignoreCase = true)) {
                        var ci_top = ""
                        var ci_left = ""
                        var ci_right = ""
                        var ci_bottom = ""
                        val split_coords1 =
                                SessionManager.Map_coords!!.split(",".toRegex()).toTypedArray()
                        ci_top = split_coords1[0]
                        ci_left = split_coords1[1]
                        ci_right = split_coords1[2]
                        ci_bottom = split_coords1[3]
                        if (rectangles[j].rect.contains(
                                        ci_top.toInt(),
                                        ci_left.toInt(),
                                        ci_right.toInt(),
                                        ci_bottom.toInt()
                                )
                        ) {
                            val pointF = PointF(rect.centerX().toFloat(), rect.centerY().toFloat())
                            binding!!.detailImage.setScaleAndCenter(1.5f, pointF)
                            val options = BitmapFactory.Options()
                            options.inScaled = true
                            options.inDither = true
                            options.inPreferredConfig = Bitmap.Config.ARGB_8888


                            val bm=BitmapFactory.decodeResource(
                                    context!!.resources,
                                    R.drawable.orangepinn,
                                    options
                            )

                            val resizedBitmap = scaleDown(bm, 70f, true)
                            canvas1!!.drawBitmap(
                                    resizedBitmap,
                                    (rect.centerX() - 30).toFloat(),
                                    (rect.centerY() - 60).toFloat(),
                                    paint1
                            )




                        }
                        mat = binding!!.detailImage.matrix
                    }

                }
                else
                {
                    val canvas1 = Canvas(result)
                    val paint1 = Paint()
                    if (!SessionManager.Map_coords.equals("", ignoreCase = true)) {
                        var ci_top = ""
                        var ci_left = ""
                        var ci_right = ""
                        var ci_bottom = ""
                        val split_coords1 =
                                SessionManager.Map_coords!!.split(",".toRegex()).toTypedArray()
                        ci_top = split_coords1[0]
                        ci_left = split_coords1[1]
                        ci_right = split_coords1[2]
                        ci_bottom = split_coords1[3]
                        if (rectangles[j].rect.contains(
                                        ci_top.toInt(),
                                        ci_left.toInt(),
                                        ci_right.toInt(),
                                        ci_bottom.toInt()
                                )
                        ) {
                            val pointF = PointF(rect.centerX().toFloat(), rect.centerY().toFloat())
                            binding!!.detailImage.setScaleAndCenter(1.5f, pointF)
                            val options = BitmapFactory.Options()
                            options.inScaled = true
                            options.inDither = true
                            options.inPreferredConfig = Bitmap.Config.ARGB_8888

                            if(is_favorites.equals("1"))
                            {
                                val bm2 = BitmapFactory.decodeResource(
                                        context!!.resources,
                                        R.drawable.yellostar,
                                        options
                                )

                                val resizedBitmap = scaleDown(bm2, 70f, true)
                                canvas1!!.drawBitmap(
                                        resizedBitmap,
                                        (rect.centerX() - 30).toFloat(),
                                        (rect.centerY() - 60).toFloat(),
                                        paint1
                                )
                            } else {
                                val bm = BitmapFactory.decodeResource(
                                    context!!.resources,
                                    R.drawable.orangepinn,
                                    options
                                )

                                val resizedBitmap = scaleDown(bm, 70f, true)
                                canvas1!!.drawBitmap(
                                    resizedBitmap,
                                    (rect.centerX() - 30).toFloat(),
                                    (rect.centerY() - 60).toFloat(),
                                    paint1
                                )
                            }



                        }
                        mat = binding!!.detailImage.matrix
                    }else{
                        val pointF = PointF(rect.centerX().toFloat(), rect.centerY().toFloat())
//                        binding!!.detailImage.setScaleAndCenter(1.5f, pointF)
                        val options = BitmapFactory.Options()
                        options.inScaled = true
                        options.inDither = true
                        options.inPreferredConfig = Bitmap.Config.ARGB_8888
                        if(is_favorites.equals("1"))
                        {
                            val bm2 = BitmapFactory.decodeResource(
                                context!!.resources,
                                R.drawable.yellostar,
                                options
                            )

                            val resizedBitmap = scaleDown(bm2, 70f, true)
                            canvas1!!.drawBitmap(
                                resizedBitmap,
                                (rect.centerX() - 30).toFloat(),
                                (rect.centerY() - 60).toFloat(),
                                paint1
                            )
                        }
                    }

                }


            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

        GlobalData.IS_FROM_EXHIBITORS=false
    }
Leave a Comment