index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (() => {
  2. class Gallery {
  3. contents = [];
  4. constructor(path) {
  5. this.path = path;
  6. this.current = 0;
  7. this.view = null;
  8. }
  9. getSelfPath() {
  10. const pkg = hmApp.packageInfo();
  11. const idn = pkg.appId.toString(16).padStart(8, "0").toUpperCase();
  12. return "/storage/js_" + pkg.type + "s/" + idn;
  13. }
  14. start() {
  15. const absPath = this.getSelfPath() + "/assets/" + this.path;
  16. const [filenames, e] = hmFS.readdir(absPath);
  17. console.log(filenames);
  18. this.contents = filenames;
  19. if (this.contents.length < 1) {
  20. return;
  21. }
  22. // Inage view
  23. this.view = hmUI.createWidget(hmUI.widget.IMG, {
  24. x: 0,
  25. y: 0,
  26. w: 192,
  27. h: 490,
  28. src: this.path + "/" + this.contents[0],
  29. });
  30. // Switch handlers
  31. hmUI
  32. .createWidget(hmUI.widget.IMG, {
  33. x: 0,
  34. y: 64,
  35. w: 192,
  36. h: (490 - 64) / 2,
  37. src: "",
  38. })
  39. .addEventListener(hmUI.event.CLICK_UP, () => {
  40. this.switch(-1);
  41. });
  42. hmUI
  43. .createWidget(hmUI.widget.IMG, {
  44. x: 0,
  45. y: 64 + (490 - 64) / 2,
  46. w: 192,
  47. h: (490 - 64) / 2,
  48. src: "",
  49. })
  50. .addEventListener(hmUI.event.CLICK_UP, () => {
  51. this.switch(1);
  52. });
  53. }
  54. switch(delta) {
  55. const val = this.current + delta;
  56. if (!this.contents[val]) return;
  57. this.view.setProperty(hmUI.prop.MORE, {
  58. src: this.path + "/" + this.contents[val],
  59. });
  60. this.current = val;
  61. console.log(this.path + "/" + this.contents[val]);
  62. }
  63. }
  64. let __$$app$$__ = __$$hmAppManager$$__.currentApp;
  65. let __$$module$$__ = __$$app$$__.current;
  66. __$$module$$__.module = DeviceRuntimeCore.Page({
  67. onInit() {
  68. const gal = new Gallery("images");
  69. gal.start();
  70. }
  71. });
  72. })();