|
256 | 256 | (.touchAndHold (utils/target) (utils/uia-point offset) duration))
|
257 | 257 |
|
258 | 258 |
|
| 259 | +(def orientations |
| 260 | + {js/UIA_DEVICE_ORIENTATION_UNKNOWN :unknown |
| 261 | + js/UIA_DEVICE_ORIENTATION_PORTRAIT :portrait |
| 262 | + js/UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN :portrait-upside-down |
| 263 | + js/UIA_DEVICE_ORIENTATION_LANDSCAPELEFT :landscape-left |
| 264 | + js/UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT :landscape-right |
| 265 | + js/UIA_DEVICE_ORIENTATION_FACEUP :faceup |
| 266 | + js/UIA_DEVICE_ORIENTATION_FACEDOWN :facedown}) |
| 267 | + |
| 268 | +(def rotatable-orientations |
| 269 | + [js/UIA_DEVICE_ORIENTATION_PORTRAIT |
| 270 | + js/UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT ;portrait rotated clockwise |
| 271 | + js/UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN ;landscaperight rotated clockwise |
| 272 | + js/UIA_DEVICE_ORIENTATION_LANDSCAPELEFT]) ;... |
| 273 | + |
| 274 | +(def clockwise-orientations |
| 275 | + (partition 2 1 (cycle rotatable-orientations))) |
| 276 | + |
| 277 | +;;((:portrait :landscape-right) ;; clockwise of :portrait is :landscape-right |
| 278 | +;; (:landscape-right :portrait-upside-down) ;; .. |
| 279 | +;; (:portrait-upside-down :landscape-left)) |
| 280 | + |
| 281 | + |
| 282 | +(defn relative-orientation |
| 283 | + [orientation dir] |
| 284 | + (if (some #(= orientation %) rotatable-orientations) |
| 285 | + (let [dir (case dir |
| 286 | + :left :counter-clockwise |
| 287 | + :right :clockwise |
| 288 | + dir) |
| 289 | + orientations (if (= :clockwise dir) |
| 290 | + clockwise-orientations |
| 291 | + (map reverse clockwise-orientations))] |
| 292 | + (second (first (filter #(= orientation (first %)) orientations)))) |
| 293 | + (throw (new js/Error (str "Can't rotate orientation: " orientation))))) |
| 294 | + |
| 295 | +(defn orientation |
| 296 | + [] |
| 297 | + (get orientations (.deviceOrientation (utils/target)))) |
| 298 | + |
| 299 | +(defn rotate |
| 300 | + [dir] |
| 301 | + (.setDeviceOrientation (utils/target) |
| 302 | + (relative-orientation |
| 303 | + (.deviceOrientation (utils/target)) |
| 304 | + dir))) |
| 305 | + |
259 | 306 | ;;; Alerts ;;;
|
260 | 307 |
|
261 | 308 | (def ^:dynamic *alert-handlers*
|
|
0 commit comments