@@ -196,10 +196,8 @@ class FloatMonitor(private val mContext: Context) {
196196
197197 private var activityManager: ActivityManager ? = null
198198 private var myHandler = Handler (Looper .getMainLooper())
199- private var batteryUnit = BatteryUtils ()
200199 private val info = ActivityManager .MemoryInfo ()
201200
202- private var sum = - 1
203201 private var totalMem = 0
204202 private var availMem = 0
205203 private var coreCount = - 1 ;
@@ -213,6 +211,13 @@ class FloatMonitor(private val mContext: Context) {
213211 private val boldStyleSpan = StyleSpan (Typeface .BOLD )
214212 private val whiteSpan = ForegroundColorSpan (Color .WHITE )
215213
214+ private fun whiteBoldSpan (text : String ): SpannableString {
215+ return SpannableString (text).apply {
216+ setSpan(whiteSpan, 0 , text.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
217+ setSpan(boldStyleSpan, 0 , text.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
218+ }
219+ }
220+
216221 private fun updateInfo () {
217222 if (coreCount < 1 ) {
218223 coreCount = CpuFrequencyUtil .getCoreCount()
@@ -265,33 +270,22 @@ class FloatMonitor(private val mContext: Context) {
265270 availMem = (info.availMem / 1024 / 1024f ).toInt()
266271 val ramInfoText = " #RAM " + ((totalMem - availMem) * 100 / totalMem).toString() + " %"
267272
268- otherInfoBuilder.append(SpannableString (ramInfoText).apply {
269- setSpan(whiteSpan, 0 , ramInfoText.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
270- setSpan(boldStyleSpan, 0 , ramInfoText.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
271- })
273+ otherInfoBuilder.append(whiteBoldSpan(ramInfoText))
272274 otherInfoBuilder.append(" \n " )
273275
274276 if (gpuMemoryUsage != null ) {
275- gpuMemoryUsage = " #GMEM " + gpuMemoryUsage
276- otherInfoBuilder.append(SpannableString (gpuMemoryUsage).apply {
277- setSpan(whiteSpan, 0 , gpuMemoryUsage.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
278- setSpan(boldStyleSpan, 0 , gpuMemoryUsage.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
279- })
277+ otherInfoBuilder.append(whiteBoldSpan(" #GMEM " + gpuMemoryUsage))
280278 otherInfoBuilder.append(" \n " )
281279 }
282280
283- var clusterIndex = 0
284- for (cluster in clusters) {
281+ for ((clusterIndex, cluster) in clusters.withIndex()) {
285282 if (clusterIndex != 0 ) {
286283 otherInfoBuilder.append(" \n " )
287284 }
288- if (cluster.size > 0 ) {
285+ if (cluster.isNotEmpty() ) {
289286 try {
290287 val title = " #" + cluster[0 ] + " ~" + cluster[cluster.size - 1 ] + " " + subFreqStr(clustersFreq.get(clusterIndex)) + " Mhz" ;
291- otherInfoBuilder.append(SpannableString (title).apply {
292- setSpan(whiteSpan, 0 , title.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
293- setSpan(boldStyleSpan, 0 , title.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
294- })
288+ otherInfoBuilder.append(whiteBoldSpan(title))
295289
296290 val otherInfos = StringBuilder (" " )
297291 for (core in cluster) {
@@ -310,28 +304,21 @@ class FloatMonitor(private val mContext: Context) {
310304 } catch (ex: Exception ) {
311305 }
312306 }
313- clusterIndex++
314307 }
315308
316309 fpsUtils.currentFps?.run {
317310 otherInfoBuilder.append(" \n " )
318311
319312 val fpsInfo = " #FPS $this "
320- otherInfoBuilder.append(SpannableString (fpsInfo).apply {
321- setSpan(whiteSpan, 0 , fpsInfo.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
322- setSpan(boldStyleSpan, 0 , fpsInfo.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
323- })
313+ otherInfoBuilder.append(SpannableString (fpsInfo))
324314 }
325315
326316 batteryCurrentNowMa?.run {
327317 if (this > - 20000 && this < 20000 ) {
328318 otherInfoBuilder.append(" \n " )
329319
330320 val batteryInfo = " #BAT " + (if (this > 0 ) (" +" + this ) else this ) + " mA"
331- otherInfoBuilder.append(SpannableString (batteryInfo).apply {
332- setSpan(whiteSpan, 0 , batteryInfo.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
333- setSpan(boldStyleSpan, 0 , batteryInfo.length, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
334- })
321+ otherInfoBuilder.append(SpannableString (batteryInfo))
335322 }
336323 }
337324 }
0 commit comments