demo.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. let SCRIPT_CONF = require('./common/ScriptConf.js')
  2. /**
  3. * 作者: 大柒
  4. * 日期: 20190307
  5. *
  6. */
  7. var window = floaty.rawWindow(
  8. <frame id="xx1" h="800px" w="150px" >
  9. <img id="cd_1" layout_gravity="bottom|center" w="100px" h="100px" src="file://./start.png" rotation="-90" />
  10. <img id="cd_2" layout_gravity="bottom|center" w="100px" h="100px" src="file://./resume.png" rotation="-90" />
  11. <img id="cd_3" layout_gravity="bottom|center" w="100px" h="100px" src="file://./back.png" rotation="-90" />
  12. </frame>
  13. );
  14. var window1 = floaty.window(
  15. <frame h="150px" w="150px" >
  16. <img id="jia" layout_gravity="bottom|left" w="150px" h="150px" src="file://./test.png" />
  17. </frame>
  18. );
  19. //cd1值 菜单的默认加载位置 b,d,e 跟随C值 这个自己摸索
  20. //jiaodu值 加载图标的旋转开始角度
  21. //sleep0值 动画时间 0为无延迟 数值越小 加载越快 反之则慢
  22. //date0_sj值 按下手指不移动时等待多少毫秒关闭悬浮窗
  23. //move0值 手指移动的距离小于该值 则判断为 未移动
  24. //date1_sj 值 手指触摸时间小于该值 则判断为点击
  25. var cd1 = 180;
  26. var jiaodu = 0;
  27. var sleep0=1;
  28. var date0_sj=1000;
  29. var move0=60;
  30. var date1_sj=200;
  31. var y2 = false, y1 = true;
  32. let cd2 = cd1, cd3 = cd1
  33. let windowWidth
  34. let windowHeight
  35. let window1Width
  36. let window1Height
  37. let lockStart = false
  38. ui.post(function () {
  39. windowWidth = window.getWidth();
  40. windowHeight = window.getHeight();
  41. window1Width = window1.getWidth();
  42. window1Height = window1.getHeight();
  43. }, 1000);
  44. window.cd_1.setPivotY(cd1)
  45. window.cd_1.setPivotX(cd1)
  46. window.cd_2.setPivotY(cd2)
  47. window.cd_2.setPivotX(cd2)
  48. window.cd_3.setPivotY(cd3)
  49. window.cd_3.setPivotX(cd3)
  50. window.setTouchable(false);
  51. //两个悬浮窗Y值差值
  52. var Y_cz=725
  53. //两个悬浮窗初始位置
  54. window.setPosition(50, device.height - (400+Y_cz))
  55. // window.setPosition(device.width - 200, device.height - (400+Y_cz))
  56. window1.setPosition(50, device.height - 400)
  57. function jz() {
  58. threads.start(function () {
  59. if (y1) {
  60. y1 = false
  61. if (y2) {
  62. y2 = false
  63. for (let i = 0; i < 100; i++) {
  64. if (i % 2) { window1.jia.setRotation(jiaodu += 1) }
  65. window.cd_1.setPivotY(cd1 += 4)
  66. window.cd_1.setPivotX(cd1)
  67. window.cd_2.setPivotY(cd2 += 3)
  68. window.cd_2.setPivotX(cd2)
  69. window.cd_3.setPivotY(cd3 += 2)
  70. window.cd_3.setPivotX(cd3)
  71. sleep(sleep0)
  72. }
  73. } else {
  74. for (let i = 100; i > 0; i--) {
  75. if (i % 2) { window1.jia.setRotation(jiaodu -= 1) }
  76. window.cd_1.setPivotY(cd1 -= 4)
  77. window.cd_1.setPivotX(cd1)
  78. window.cd_2.setPivotY(cd2 -= 3)
  79. window.cd_2.setPivotX(cd2)
  80. window.cd_3.setPivotY(cd3 -= 2)
  81. window.cd_3.setPivotX(cd3)
  82. sleep(sleep0)
  83. }
  84. y2 = true;
  85. }
  86. y1 = true
  87. }
  88. })
  89. }
  90. window.cd_1.on("click", () => {
  91. if (y2) {
  92. if(!lockStart){
  93. if(SCRIPT_CONF){
  94. lockStart = true
  95. let obj = SCRIPT_CONF.script
  96. let obj1 = SCRIPT_CONF.conf
  97. let obj2 = SCRIPT_CONF.module
  98. let obj3 = "const ENV_CONF = " + JSON.stringify(obj1) + ";\r\n" ;
  99. obj3 += obj
  100. engines.execScript(obj2,obj3)
  101. lockStart = false
  102. }
  103. }else{
  104. toastLog("脚本已经在运行")
  105. }
  106. jz();
  107. window.setTouchable(false);
  108. }
  109. })
  110. window.cd_2.on("click", () => {
  111. if (y2) {
  112. engines.stopAll()
  113. jz();
  114. window.setTouchable(false);
  115. }
  116. })
  117. window.cd_3.on("click", () => {
  118. if (y2) {
  119. toastLog("系统")
  120. jz();
  121. window.setTouchable(false);
  122. }
  123. })
  124. var fn = () => { }
  125. var id = setInterval(
  126. fn, 3000
  127. )
  128. //记录按键被按下时的触摸坐标
  129. var x = 0,
  130. y = 0;
  131. //记录按键被按下时的悬浮窗位置
  132. var windowX, windowY;
  133. //记录按键被按下的时间以便判断长按等动作
  134. var downTime;yd=false;
  135. window1.jia.setOnTouchListener(function (view, event) {
  136. switch (event.getAction()) {
  137. case event.ACTION_DOWN:
  138. x = event.getRawX();
  139. y = event.getRawY();
  140. windowX = window.getX();
  141. windowY = window.getY();
  142. windowX1 = window1.getX();
  143. windowY1 = window1.getY();
  144. downTime = new Date().getTime();
  145. return true;
  146. case event.ACTION_MOVE:
  147. if(!yd){//如果移动的距离大于h值 则判断为移动 yd为真
  148. if (Math.abs(event.getRawY() - y) >move0 || Math.abs(event.getRawX() - x) > move0) {yd=true}
  149. //如果按下的时间超过g值并且yd值为假判断为长按,退出脚本
  150. if (new Date().getTime() - downTime > date0_sj) {
  151. log(new Date().getTime() - downTime);
  152. exit();
  153. //关闭悬浮窗
  154. //window.close()
  155. //window1.close()
  156. }
  157. }else{//移动手指时调整两个悬浮窗位置
  158. windowHeight = window1Height
  159. windowWidth = window1Width
  160. let xAxisMovingDistance = event.getRawX() - x;
  161. let yAxisMovingDistance = event.getRawY() - y;
  162. if (windowX + xAxisMovingDistance < 0) {
  163. if (windowY + yAxisMovingDistance < 0) {
  164. window.setPosition(10,
  165. windowY + (event.getRawY() - y));
  166. window1.setPosition(10,
  167. windowY + ((event.getRawY() - y)+Y_cz));
  168. console.log("触发了8")
  169. } else if (windowY + windowHeight + yAxisMovingDistance > device.height) {
  170. window.setPosition(10,
  171. device.height - windowHeight);
  172. window1.setPosition(10,
  173. device.height - windowHeight+Y_cz);
  174. console.log("触发了7")
  175. // window.setPosition(0, );
  176. } else {
  177. console.log("触发了6")
  178. window.setPosition(10,
  179. windowY + yAxisMovingDistance);
  180. window1.setPosition(10,
  181. windowY + yAxisMovingDistance+Y_cz);
  182. // window.setPosition(0, windowY + yAxisMovingDistance);
  183. }
  184. } else if (windowX + xAxisMovingDistance > device.width - windowWidth) {
  185. if (windowY + yAxisMovingDistance < 0) {
  186. console.log("触发了5")
  187. window.setPosition(device.width - windowWidth,
  188. windowY + yAxisMovingDistance);
  189. window1.setPosition(device.width - windowWidth,
  190. windowY + yAxisMovingDistance+Y_cz);
  191. } else if (windowY + windowHeight + yAxisMovingDistance > device.height) {
  192. console.log("触发了4")
  193. window.setPosition(device.width - windowWidth,
  194. device.height - window1Height);
  195. window1.setPosition(device.width - windowWidth,
  196. device.height - windowHeight+Y_cz);
  197. // window.setPosition(device.width - windowWidth, device.height - windowHeight);
  198. } else {
  199. console.log("触发了3")
  200. window.setPosition(device.width - windowWidth,
  201. windowY + yAxisMovingDistance);
  202. window1.setPosition(device.width - windowWidth,
  203. windowY + yAxisMovingDistance+Y_cz);
  204. // window.setPosition(device.width - windowWidth, windowY + yAxisMovingDistance);
  205. }
  206. } else {
  207. if (windowY + yAxisMovingDistance < 0) {
  208. console.log("触发了1")
  209. window.setPosition(windowX + xAxisMovingDistance,
  210. 0);
  211. window1.setPosition(windowX + xAxisMovingDistance,
  212. 0 +Y_cz);
  213. // window.setPosition(device.width - windowWidth, windowY + yAxisMovingDistance);
  214. // window.setPosition(windowX + xAxisMovingDistance, 0);
  215. } else if (windowY1 + windowHeight + yAxisMovingDistance + 50> device.height) {
  216. console.log("触发了2")
  217. window.setPosition(windowX + xAxisMovingDistance,
  218. device.height - windowHeight - Y_cz);
  219. window1.setPosition(windowX + xAxisMovingDistance,
  220. device.height - windowHeight - 50);
  221. // window.setPosition(windowX + xAxisMovingDistance, device.height - windowHeight);
  222. } else {
  223. window.setPosition(windowX + xAxisMovingDistance,
  224. windowY + yAxisMovingDistance);
  225. window1.setPosition(windowX + xAxisMovingDistance,
  226. windowY + yAxisMovingDistance +Y_cz);
  227. // window.setPosition(windowX + xAxisMovingDistance, windowY + yAxisMovingDistance);
  228. }
  229. }
  230. }
  231. return true;
  232. case event.ACTION_UP:
  233. //触摸时间小于 200毫秒 则判断为 点击
  234. if (new Date().getTime() - downTime < date1_sj) {
  235. jz();
  236. //根据Y2值 设置悬浮窗是否可以触摸
  237. if(y2){
  238. window.setTouchable(false);
  239. }else{
  240. window.setTouchable(true);
  241. }
  242. }
  243. yd=false
  244. return true;
  245. }
  246. return true;
  247. });
  248. var floatyObj = {}
  249. floatyObj.show = function(){
  250. var Y_cz=725
  251. //两个悬浮窗初始位置
  252. window.setPosition(50, device.height - (400+Y_cz))
  253. // window.setPosition(device.width - 200, device.height - (400+Y_cz))
  254. window1.setPosition(50, device.height - 400)
  255. }
  256. floatyObj.hide = function(){
  257. window.setPosition(-3000, device.height - (400+Y_cz))
  258. // window.setPosition(device.width - 200, device.height - (400+Y_cz))
  259. window1.setPosition(-3000, device.height - 400)
  260. }
  261. module.exports = floatyObj;