Guest User

Untitled

a guest
Jul 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. class SectionFragment : Fragment() {
  2.  
  3.  
  4. override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
  5. savedInstanceState: Bundle?): View? {
  6. val view = inflater!!.inflate(R.layout.fragment_section, container, false)
  7. val bundle = arguments
  8. val myLayout = view.findViewById(R.id.mylayout) as RelativeLayout
  9. val id = bundle.getInt("ID")
  10.  
  11. val displayMetrics = DisplayMetrics()
  12. activity.windowManager.defaultDisplay.getMetrics(displayMetrics)
  13. val phoneHeight = displayMetrics.heightPixels
  14. val phoneWidth = displayMetrics.widthPixels
  15.  
  16. doAsync {
  17.  
  18. val tables = SqlHelper.fetchAll(Table::class.java, "SectionID = " + id.toLong())
  19.  
  20. uiThread {
  21.  
  22. tables!!.forEach {
  23.  
  24. val tableShape = SqlHelper.fetch(TableShape::class.java, "ID = " + it.TableShapeID)
  25. val imageViewTable = ImageView(context)
  26. val imageFile = SqlHelper.fetch(File::class.java, "ID = " + tableShape!!.ImageFileID)
  27.  
  28. imageViewTable.adjustViewBounds = true
  29. imageViewTable.setBackgroundFromLocalServer(imageFile!!.Source!!)
  30.  
  31. val params = RelativeLayout.LayoutParams(
  32. (tableShape.Width * it.SizeMultiplier*phoneWidth/855).toInt(),
  33. RelativeLayout.LayoutParams.WRAP_CONTENT)//boyut
  34.  
  35. params.leftMargin = (it.PosX*phoneWidth/855).toInt() //x
  36. params.topMargin = (it.PosY*phoneHeight/638-(100*phoneHeight/638)).toInt() //y
  37.  
  38. imageViewTable.rotation = it.Angle
  39. myLayout.addView(imageViewTable, params)
  40.  
  41. val table = it
  42.  
  43. imageViewTable.setOnClickListener({
  44.  
  45. Toast.makeText(context, "" + table.ID + "\n" +
  46. table.Name + "\n" +
  47. table.Capacity + "\n" +
  48.  
  49. table.Angle + "\n" +
  50. table.PosX + "\n" +
  51. table.PosY + "\n" +
  52. table.SizeMultiplier + "\n" +
  53. table.TableShapeID,
  54.  
  55. Toast.LENGTH_SHORT).show()
  56. })
  57. }
  58. }
  59.  
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. return view
  71. }
  72.  
  73.  
  74. }
Add Comment
Please, Sign In to add comment