更温和的交互:呼吸式闪动警示 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: what is new

  2. Pingback: what is new

  3. Pingback: what is new

  4. Pingback: what is new

  5. Pingback: read more

  6. Pingback: read more

  7. Pingback: read more

  8. Pingback: click here

  9. Pingback: click here

  10. Pingback: click here

  11. Pingback: click here

  12. Pingback: have a peek at these guys

  13. Pingback: have a peek at these guys

  14. Pingback: news

  15. Pingback: navigate to this website

  16. Pingback: this page

  17. Pingback: my response

  18. Pingback: original site

  19. Pingback: check here

  20. Pingback: browse this site

  21. Pingback: click here now

  22. Pingback: read this article

  23. Pingback: Bonuses

  24. Pingback: find this

  25. Pingback: a fantastic read

  26. Pingback: how to get bigger boobs

  27. Pingback: click to read more

  28. Pingback: imp source

  29. Pingback: my company

  30. Pingback: great post to read

  31. Pingback: this website

  32. Pingback: how to get bigger boobs

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

  34. Pingback: see here

  35. Pingback: Get More Info

  36. Pingback: useful reference

  37. Pingback: my review here

  38. Pingback: click site

  39. Pingback: More about the author

  40. Pingback: check my blog

  41. Pingback: read more

  42. Pingback: mitogen diagnostics

  43. Pingback: discover this info here

  44. Pingback: explanation

  45. Pingback: you could look here

  46. Pingback: Get the facts

  47. Pingback: More hints

  48. Pingback: why not try these out

  49. Pingback: i thought about this

  50. Pingback: my response

  51. Pingback: browse this site

  52. Pingback: find this

  53. Pingback: a fantastic read

  54. Pingback: Homepage

  55. Pingback: their explanation

  56. Pingback: i thought about this

  57. Pingback: useful reference

  58. Pingback: More about the author

  59. Pingback: Sperry boots for women

  60. Pingback: quality article

  61. Pingback: insight

  62. Pingback: where to look

  63. Pingback: where to look

  64. Pingback: what to do

  65. Pingback: continue reading

  66. Pingback: figure out

  67. Pingback: find

  68. Pingback: important

  69. Pingback: read more

  70. Pingback: click here

  71. Pingback: givehermakeup.com

  72. Pingback: learn now

  73. Pingback: best news

  74. Pingback: new source

  75. Pingback: best value

  76. Pingback: More hints

  77. Pingback: Clicking Here

  78. Pingback: her latest blog

  79. Pingback: check these guys out

  80. Pingback: official site

  81. Pingback: i thought about this

  82. Pingback: more news

  83. Pingback: read more

  84. Pingback: click here

  85. Pingback: website

  86. Pingback: read more

  87. Pingback: read more

  88. Pingback: read more

  89. Pingback: click here

  90. Pingback: click here

  91. Pingback: click here

  92. Pingback: read more

  93. Pingback: click here

  94. Pingback: important source

  95. Pingback: official statement

  96. Pingback: Get the facts

  97. Pingback: Learn More

  98. Pingback: you could try here

  99. Pingback: you could check here

  100. Pingback: check that

  101. Pingback: More Bonuses

  102. Pingback: her latest blog

  103. Pingback: Visit Website

  104. Pingback: their explanation

  105. Pingback: why not find out more

  106. Pingback: view publisher site

  107. Pingback: check these guys out

  108. Pingback: i thought about this

  109. Pingback: my response

  110. Pingback: a fantastic read

  111. Pingback: imp source

  112. Pingback: useful reference

  113. Pingback: about

  114. Pingback: news

  115. Pingback: new website

  116. Pingback: best info

  117. Pingback: read more

  118. Pingback: look here

  119. Pingback: see post

  120. Pingback: content

  121. Pingback: pop over to this website

  122. Pingback: click resources

  123. Pingback: Discover More

  124. Pingback: Continued

  125. Pingback: More Bonuses

  126. Pingback: hop over to this website

  127. Pingback: additional hints

  128. Pingback: navigate to these guys

  129. Pingback: you can try this out

  130. Pingback: check these guys out

  131. Pingback: look at this site

  132. Pingback: why not try these out

  133. Pingback: original site

  134. Pingback: a fantastic read

  135. Pingback: my company

  136. Pingback: useful reference

  137. Pingback: new website

  138. Pingback: read more

  139. Pingback: click here

  140. Pingback: website

  141. Pingback: interserver promo code

  142. Pingback: interserver coupon

  143. Pingback: commercial water slide

  144. Pingback: hotels in burlington nc

  145. Pingback: pickleball paddles

  146. Pingback: Double glazing window

  147. Pingback: What is a 403b retirement plan

  148. Pingback: garcinia cambogia extract does it work

  149. Pingback: What you can do with coconut oil

  150. Pingback: Skydiving NYC

  151. Pingback: Payday loans