更温和的交互:呼吸式闪动警示 view 背景

前天晚上做了个简单的小工具类,叫做 BreathingViewHelper,传入一个 view 和需要的背景颜色之后,它的背景就会呈呼吸式闪动,可以用来做警示一些必要的内容没有填写或选择。

其实实现方法很简单,就是开个线程隔 38毫秒调用一下 setBackgroundColor 而已,之所以是 38mm 是因为只要间隔小于50毫秒的刷新率,人的肉眼就会当成是连续的;这样可以避免过多刷新,也是比较友好。

关键就是一个类呼吸函数,首先想到正弦函数,但正弦函数用起来感觉有点呼吸急促,因为它的呼和吸是均衡的,之后 Google 了下,找到一个更加逼真的呼吸函数:

s1

s2

代码实现:

private static double getBreathingY(long time, int n, int t) {
    float k = 1.0f / 3;
    float pi = 3.1415f;
    float x = time / 1000.0f;
    t = (int) (t / 1000.0f);
    if (x >= ((n - 1) * t) && x < ((n - (1 - k)) * t)) {
        double i = pi / (k * t) * ((x - (0.5f * k * t)) - (n - 1) * t);
        return 0.5f * Math.sin(i) + 0.5f;
    } else if (x >= ((n - (1 - k)) * t) && x < n * t) {
        double j = pi / ((1 - k) * t) * ((x - (0.5f * (3 - k) * t)) - (n - 1) * t);
        double one = 0.5f * Math.sin(j) + 0.5f;
        return one * one;
    }
    return 0;
}

这里关键是要在一个周期之后传入一个新的 n,我的做法就是判断  if (diffTime > n * t) 然后使 n++;

其余没什么好说的啦,有兴趣可以直接看源码:

https://github.com/drakeet/BreathingViewHelper

效果如下(因为这个视频如果显示出来就会自动播放,为了给大家省流量,我只能将它放在文章最后了):

不过,得说一下,目前这个呼吸频率还调得不够好,有点儿温和,可能还不是非常契合做「警示」效果,所以我可能还得调一调呼吸的周期,或者开放出方法来让使用的时候做调整。

  1. Pingback: Payday loans

  2. Pingback: Skydiving NYC

  3. Pingback: What you can do with coconut oil

  4. Pingback: garcinia cambogia extract does it work

  5. Pingback: What is a 403b retirement plan

  6. Pingback: Double glazing window

  7. Pingback: pickleball paddles

  8. Pingback: hotels in burlington nc

  9. Pingback: commercial water slide

  10. Pingback: interserver coupon

  11. Pingback: interserver promo code

  12. Pingback: website

  13. Pingback: click here

  14. Pingback: read more

  15. Pingback: new website

  16. Pingback: useful reference

  17. Pingback: my company

  18. Pingback: a fantastic read

  19. Pingback: original site

  20. Pingback: why not try these out

  21. Pingback: look at this site

  22. Pingback: check these guys out

  23. Pingback: you can try this out

  24. Pingback: navigate to these guys

  25. Pingback: additional hints

  26. Pingback: hop over to this website

  27. Pingback: More Bonuses

  28. Pingback: Continued

  29. Pingback: Discover More

  30. Pingback: click resources

  31. Pingback: pop over to this website

  32. Pingback: content

  33. Pingback: see post

  34. Pingback: look here

  35. Pingback: read more

  36. Pingback: best info

  37. Pingback: new website

  38. Pingback: news

  39. Pingback: about

  40. Pingback: useful reference

  41. Pingback: imp source

  42. Pingback: a fantastic read

  43. Pingback: my response

  44. Pingback: i thought about this

  45. Pingback: check these guys out

  46. Pingback: view publisher site

  47. Pingback: why not find out more

  48. Pingback: their explanation

  49. Pingback: Visit Website

  50. Pingback: her latest blog

  51. Pingback: More Bonuses

  52. Pingback: check that

  53. Pingback: you could check here

  54. Pingback: you could try here

  55. Pingback: Learn More

  56. Pingback: Get the facts

  57. Pingback: official statement

  58. Pingback: important source

  59. Pingback: click here

  60. Pingback: read more

  61. Pingback: click here

  62. Pingback: click here

  63. Pingback: click here

  64. Pingback: read more

  65. Pingback: read more

  66. Pingback: read more

  67. Pingback: website

  68. Pingback: click here

  69. Pingback: read more

  70. Pingback: more news

  71. Pingback: i thought about this

  72. Pingback: official site

  73. Pingback: check these guys out

  74. Pingback: her latest blog

  75. Pingback: Clicking Here

  76. Pingback: More hints

  77. Pingback: best value

  78. Pingback: new source

  79. Pingback: best news

  80. Pingback: learn now

  81. Pingback: givehermakeup.com

  82. Pingback: click here

  83. Pingback: read more

  84. Pingback: important

  85. Pingback: find

  86. Pingback: figure out

  87. Pingback: continue reading

  88. Pingback: what to do

  89. Pingback: where to look

  90. Pingback: where to look

  91. Pingback: insight

  92. Pingback: quality article

  93. Pingback: Sperry boots for women

  94. Pingback: More about the author

  95. Pingback: useful reference

  96. Pingback: i thought about this

  97. Pingback: their explanation

  98. Pingback: Homepage

  99. Pingback: a fantastic read

  100. Pingback: find this

  101. Pingback: browse this site

  102. Pingback: my response

  103. Pingback: i thought about this

  104. Pingback: why not try these out

  105. Pingback: More hints

  106. Pingback: Get the facts

  107. Pingback: you could look here

  108. Pingback: explanation

  109. Pingback: discover this info here

  110. Pingback: mitogen diagnostics

  111. Pingback: read more

  112. Pingback: check my blog

  113. Pingback: More about the author

  114. Pingback: click site

  115. Pingback: my review here

  116. Pingback: useful reference

  117. Pingback: Get More Info

  118. Pingback: see here

  119. Pingback: how to get bigger boobs in a week

  120. Pingback: how to get bigger boobs

  121. Pingback: this website

  122. Pingback: great post to read

  123. Pingback: my company

  124. Pingback: imp source

  125. Pingback: click to read more

  126. Pingback: how to get bigger boobs

  127. Pingback: a fantastic read

  128. Pingback: find this

  129. Pingback: Bonuses

  130. Pingback: read this article

  131. Pingback: click here now

  132. Pingback: browse this site

  133. Pingback: check here

  134. Pingback: original site

  135. Pingback: my response

  136. Pingback: this page

  137. Pingback: navigate to this website

  138. Pingback: news

  139. Pingback: have a peek at these guys

  140. Pingback: have a peek at these guys

  141. Pingback: click here

  142. Pingback: click here

  143. Pingback: click here

  144. Pingback: click here

  145. Pingback: read more

  146. Pingback: read more

  147. Pingback: read more

  148. Pingback: what is new

  149. Pingback: what is new

  150. Pingback: what is new

  151. Pingback: what is new