Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. class StatusBar extends Layer
  2. constructor: (options = {}) ->
  3. options.provider ?= "Blueprint"
  4. options.data ?= "wifi"
  5. options.tintColor ?= "black"
  6. options.backgroundColor ?= null
  7. options.signalStrength ?= 3
  8. options.batteryStrength ?= 100
  9. options.time ?= null
  10.  
  11. super options
  12.  
  13. @options = options
  14. @padding = 6
  15.  
  16. @setupFrame()
  17.  
  18. @provider = @getProvider()
  19. @signal = @getSignal(@options.signalStrength)
  20. @time = @getTime(@options.time)
  21. @battery = @getBattery(@options.batteryStrength)
  22.  
  23. if @options.data == "wifi" || @options.data == "WIFI"
  24. @wifi = @getWifi()
  25. @colorWifi(@wifi)
  26. else
  27. @data = @getData()
  28.  
  29. @colorSignal(@signal)
  30. @colorBattery(@battery)
  31.  
  32. setupFrame: ->
  33. this.z = 0
  34. this.width = Screen.width
  35. this.height = 20
  36. this.backgroundColor = @options.backgroundColor
  37. this.color = @options.tintColor
  38.  
  39. @define "background",
  40. get: -> this
  41. set: (value) ->
  42. this.backgroundColor = value
  43.  
  44. @define "tint",
  45. get: -> @options.tintColor
  46. set: (value) ->
  47. this.color = value
  48. @options.tintColor = value
  49. @colorSignal(@signal)
  50. @colorBattery(@battery)
  51.  
  52. if @options.data == "wifi" || @options.data == "WIFI"
  53. @colorWifi(@wifi)
  54.  
  55. getProvider: ->
  56. return provider = new TextLayer
  57. parent: this
  58. x: (@padding * 2) + 16.5
  59. y: 2.5
  60. text: @options.provider
  61. fontSize: 12
  62. letterSpacing: 0.2
  63. fontWeight: 500
  64. color: @options.tintColor
  65.  
  66. getWifi: ->
  67. layers = []
  68.  
  69. wifiMask = new Layer
  70. parent: this
  71. width: 10
  72. height: 10
  73. x: @provider.x + @provider.width + 6
  74. y: 3
  75. rotation: 45
  76. clip: true
  77. backgroundColor: ""
  78.  
  79. for i in [0..2]
  80. level = new Layer
  81. parent: wifiMask
  82. width: 6 + (i * 6)
  83. height: 6 + (i * 6)
  84. x: 7 - (i * 3)
  85. y: 7 - (i * 3)
  86. borderRadius: 3 * (i + 1)
  87. backgroundColor: ""
  88. borderWidth: 1.5
  89.  
  90. layers.push(level)
  91.  
  92. return layers
  93.  
  94. colorWifi: (layers) ->
  95. layers[0].borderColor = ""
  96. layers[0].backgroundColor = @options.tintColor
  97. layers[1].borderColor = @options.tintColor
  98. layers[2].borderColor = @options.tintColor
  99.  
  100. getSignal: (strength = 3) =>
  101. strength -= 1
  102. layers = []
  103. barHeight = 4
  104.  
  105. signalWrapper = new Layer
  106. parent: this
  107. height: 10
  108. width: 16.5
  109. x: 6
  110. y: Align.center
  111. backgroundColor: ""
  112.  
  113. for i in [0..3]
  114. layer = new Layer
  115. parent: signalWrapper
  116. width: 3
  117. height: barHeight
  118. y: Align.bottom
  119. x: (i * 4.5)
  120. borderRadius: 2
  121.  
  122. layers.push(layer)
  123.  
  124. barHeight += 2
  125.  
  126. if i > strength
  127. layers[i].opacity = 0.3
  128.  
  129. return layers
  130.  
  131. colorSignal: (layers) ->
  132. for bar in layers
  133. bar.backgroundColor = @options.tintColor
  134.  
  135. getTime : (time = null) ->
  136. return time = new TextLayer
  137. parent: this
  138. x: Align.center
  139. y: 2.5
  140. text: @printTime(time)
  141. fontSize: 12
  142. letterSpacing: 0.2
  143. fontWeight: 600
  144. color: @options.tintColor
  145.  
  146. printTime : (time) ->
  147. if time == null
  148. time = new Date()
  149. if time.getMinutes() < 10
  150. minutes = "0" + time.getMinutes()
  151. else
  152. minutes = time.getMinutes()
  153.  
  154. return time.getHours() + ":" + minutes
  155. else
  156. return time
  157.  
  158. getBattery : (chargePercent = 100) ->
  159. layers = []
  160. batteryChargeWidth = 0.2 * chargePercent
  161.  
  162. batteryWrapper = new Layer
  163. parent: this
  164. width: 26.5
  165. height: 11.5
  166. y: Align.center
  167. x: Screen.width - @padding - 24
  168. backgroundColor: ""
  169.  
  170. pin = new Layer
  171. parent: batteryWrapper
  172. height: 4
  173. width: 1.5
  174. y: 3.5
  175. x: batteryWrapper.width - 1.5
  176. opacity: 0.4
  177. style: { "borderRadius": "0 4px 4px 0" }
  178.  
  179. layers.push(pin)
  180.  
  181. outline = new Layer
  182. parent: batteryWrapper
  183. width: 24
  184. height: 11.5
  185. y: Align.center
  186. x: 0
  187. borderRadius: 2
  188. borderWidth: 1
  189. opacity: 0.4
  190. backgroundColor: ""
  191. style: { "borderRadius": "1px 0 0 1px" }
  192.  
  193. layers.push(outline)
  194.  
  195. charge = new Layer
  196. parent: batteryWrapper
  197. width: batteryChargeWidth
  198. height: 7.5
  199. y: Align.center
  200. x: 2
  201.  
  202. layers.push(charge)
  203.  
  204. if chargePercent == 100
  205. charge.borderRadius = 1
  206. else
  207. charge.style = { "borderRadius": "1px 0 0 1px" }
  208.  
  209. return layers
  210.  
  211. colorBattery : (layers) ->
  212. layers[0].backgroundColor = @options.tintColor
  213. layers[1].borderColor = @options.tintColor
  214.  
  215. if @options.batteryStrength <= 10
  216. layers[2].backgroundColor = "red"
  217. else
  218. layers[2].backgroundColor = @options.tintColor
  219.  
  220. getData : ->
  221. return data = new TextLayer
  222. parent: this
  223. x: @provider.x + @provider.width + 4
  224. y: 2.5
  225. text: @options.data
  226. fontSize: 12
  227. letterSpacing: 0.2
  228. fontWeight: 500
  229. color: @options.tintColor
  230.  
  231. exports.StatusBar = StatusBar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement