请选择 进入手机版 | 继续访问电脑版

登录  | 立即注册

游客您好!登录后享受更多精彩

查看: 1364|回复: 0

[lua教程] 【lua教程】指南针

[复制链接]

444

主题

509

帖子

2051

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2051

荣誉管理论坛元老

发表于 2021-7-1 08:33:17 来自手机 | 显示全部楼层 |阅读模式 来自:
  1. --Copyright© Ayaka_Ago. All Rights Reserved.- O- M& q& P8 D0 N( M
  2. require"import"
    , a. \7 }9 H3 z- [
  3. import"android.hardware.SensorEventListener"$ u" O5 E, \( D, f# ^
  4. import"android.hardware.SensorManager"  d/ S+ z' Z0 E, A: {
  5. import"android.hardware.Sensor"
    7 \  ^' S' @- e- ^
  6. --setOrientation(0)( a2 {6 ]& W# X! ^/ N
  7. h=activity.getHeight()--
    ( h4 P, G" x+ y( d* z* X
  8. w=activity.getWidth()
    9 [* K& A$ x: L& k
  9. import "android.graphics.ColorFilter"/ `  v- W8 \. H& P# \! n
  10. import "android.hardware.camera2.CameraManager"  i! N( o8 D' s& R6 }' M
  11. import "android.widget.PageView"; T. {5 s0 S9 B2 ?8 Q3 |% [9 Q
  12. import "android.hardware.SensorEventListener"2 U; U) C: e) ]" P! z0 m
  13. import "android.hardware.Sensor"6 m  C& |3 @# s- Z& _
  14. import "android.widget.FrameLayout"
    , o& f% O% {4 n+ Y! B3 v: Z
  15. import "android.content.Context"
    ) a" g. K- S: B; ^0 X6 U
  16. import "android.widget.ImageView"7 M, n. W" P( X, Z1 b0 k6 ?
  17. import "android.hardware.SensorManager"/ n" G  n3 t) T$ ]# A
  18. import "android.widget.TextView"8 C/ D7 f; y* O# a7 b# }' W- A8 p
  19. import "android.widget.LinearLayout"
    ' u" H$ B7 p; M# v* q8 I
  20. import "android.widget.CircleImageView"9 L- M# P2 L8 V2 u& L
  21. import "com.nirenr.Color"1 ^# ]: x) e  m: E$ c6 m7 g
  22. import "android.graphics.Color"# d5 n# P+ u) P) `
  23. import "android.text.Html"5 r  j, |0 w3 a, R8 n: O; N9 K' H
  24. import "android.graphics.drawable.GradientDrawable"
    ; M! n: n# m% U% i: S
  25. activity.setTheme(android.R.style.Theme_DeviceDefault_Light)--设置md主题$ K0 G0 O; F2 k, Z+ U
  26. local CameraManager=this.getSystemService(Context.CAMERA_SERVICE)--相机% o, i# u7 E! e* `5 u# @
  27. local sensorManager=this.getSystemService(Context.SENSOR_SERVICE)--传感器
    * g7 ]) g5 F3 \* V
  28. local OrientationSensor=sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION)--方向
    ' }! s# }$ a8 H" k' O
  29. local curp=0- g/ B. k: C( z" S; F

  30. 0 S& b! g) Z( J: E' ~
  31. local function rim(radiu,da,db,c,inside)
    9 ~- _3 q/ d( ^1 o, `( N' ]; X
  32.   return GradientDrawable().setShape(GradientDrawable.RECTANGLE).setStroke(10,c or 文字色,da,db).setColor(inside or 0).setCornerRadii({radiu,radiu,radiu,radiu,radiu,radiu,radiu,radiu}).setGradientType(1)5 R; L$ }: R0 W! H+ S2 \
  33. end% u! T, n7 b# n- D- \/ x
  34. * @( h* R8 s9 L! U  ^$ q
  35. aa={- Q; k+ |' i( |2 H$ w# W) Q  N
  36.   FrameLayout,6 V$ m2 J( I. N# m5 i
  37.   {- q, N- |% z# E1 T
  38.     PageView,
    2 \* }2 C4 Z/ C, Q
  39.     OverScrollMode=2,6 F6 R+ o( R+ m4 u
  40.     layout_width="fill",8 ^3 m7 k4 |$ e" Q% t' g  F1 M
  41.     layout_height="fill",
    . B" H2 w9 G3 J# i# N' z
  42.     onPageChangeListener={
    " L5 t8 B* w* g2 a
  43.       onPageSelected=function (p)# y: C2 K4 [0 J4 \7 `
  44.         curp=p+ Y6 m" e/ V8 l7 V
  45.         if p==0 then( r: j. G6 X1 K3 A
  46.           compass_title.setText("指南针")
    5 Z; B. C1 c$ W& Y3 t
  47.           compass_indicator.getChildAt(0).setColorFilter(Color.DKGRAY); J6 r* N/ e9 t7 T" T% T  @! w6 }
  48.           compass_indicator.getChildAt(1).setColorFilter(Color.LTGRAY), b$ }' I: }* z- v& H
  49.          else
    7 \% L; ~) o* \) y
  50.           compass_title.setText("水平仪")5 y) W, Q. d$ t4 g
  51.           compass_indicator.getChildAt(0).setColorFilter(Color.LTGRAY)2 s9 T' B0 u$ C2 n# r% q: [' [& S3 h2 e% P9 [
  52.           compass_indicator.getChildAt(1).setColorFilter(Color.DKGRAY)
    " N7 E  j$ N  f+ [
  53.         end, s9 f- P) P8 B) N4 p: e/ @
  54.       end},7 A) A) A' k+ K( T2 e
  55.     id="pgs",
    9 R4 ]$ \9 o4 P- J
  56.     pages={) ]* L& Q* }- W+ G8 h7 A
  57.       {
    $ c* |: {9 M/ {' ^
  58.         LinearLayout,# o, |5 Y* T8 _
  59.         orientation="vertical",
    4 v# W! ^0 ?2 ?- O7 b; y! d
  60.         gravity="center",; I# g0 q! g8 J# B* Q1 x
  61.         layout_width="fill",7 Y# T8 T7 t7 H/ s. _1 B" }1 `
  62.         {
    & T1 x+ N. r4 T; O  e* y
  63.           FrameLayout,
    3 N% ~* }5 L) d9 r0 k- e
  64.           layout_width="250dp",
    $ Z* l; o- O. p' x+ y4 s3 s5 S
  65.           layout_height="250dp",' R  p. p  I% d: ]* d
  66.           layout_gravity="center",
    # ], B4 C0 p/ u: M
  67.           id="compass_circle",
    ' h' u8 K0 R; `, `8 @) N
  68.           {
    ( o6 k. H9 M) s1 M. A/ ~
  69.             FrameLayout,4 M$ K9 u% s1 y" y5 v7 ^% R& \
  70.             backgroundDrawable=rim(w,w*0.008,w*0.016),
    3 {& K+ R0 m/ L# Y9 x  B5 T
  71.             layout_width="fill",9 b. l( {; E/ F# b! \$ K
  72.             layout_height="fill",& o# O9 A; G1 _8 ^; X4 }
  73.           },
    / Q  E) Q0 `1 ~: s
  74.           {5 m; v& j: m& w; H
  75.             TextView,
    ) ~$ R: i" ]& N3 h1 X" ?: D
  76.             layout_gravity="top|center",
    . R, U5 x0 i: V) @: R
  77.             * j5 H* h) P9 L+ e( w3 W" U$ i
  78.             id="compass_north",
    , O9 u2 f# w% b7 Y2 T& O/ @) r$ |; E
  79.             textSize="20dp",, y/ J4 q% J( Z* h! Z
  80.             gravity="center",2 p, ~% f7 j; d
  81.             layout_marginTop="16dp",* _, V9 X, t; f4 j' a: D. [
  82.             text="N",  {% N$ T! |1 M
  83.           },  ~3 l8 e' K; M! i
  84.           {
    ' e+ f* q! B1 j+ X; M& R5 i
  85.             TextView,% M4 T9 O2 l, z( Z* L* e+ |
  86.             id="compass_west",
    ' u6 j8 m8 u. x, s7 k; D1 r
  87.             4 |2 a6 d" L# [8 k
  88.             textSize="20dp",* C) _7 A/ d0 L# ?/ b, B
  89.             layout_marginLeft="16dp",# e. Y: o' ^& e3 R: t7 v4 `0 e
  90.             layout_gravity="center|left",: \7 q" b3 M! _% j+ ?9 j, r
  91.             text="W",
    0 k0 ^7 A+ C5 \: ]4 q
  92.           },) [, e; T6 ^7 N5 w+ `/ n! j" d$ M* b
  93.           {! ^$ O1 C3 d$ ~8 U" V# P  h
  94.             ImageView,
    ! ~8 f8 y: v) s  q5 b
  95.             src="icon.png",7 j! a6 q" [8 b  z6 F7 k, m* L
  96.             layout_height="42dp",# R. b8 w- P+ J' ?
  97.             layout_gravity="center",
    1 L1 z. ?# n: ~2 R; S* U
  98.             layout_width="42dp",
    ' L2 x& Y+ U6 |4 q$ X  u5 Y& K
  99.             rotation=90,
    2 M% j! z. n% g  J
  100.             ColorFilter=强调色,% e" ?# V! {, W3 w0 r; a. }8 T" |
  101.           },4 @9 L3 s6 ?( k: l% U
  102.           {
    + }) [: M% N' ]& v8 [. h# u' N/ d9 b
  103.             TextView,! |3 `7 F% @: G$ I0 f3 x
  104.             id="compass_east",
    8 E. C( l, b; e. A" I. Q3 [' P
  105.             layout_marginRight="16dp",
    1 a( G6 ?8 p6 A6 d8 E- O$ d
  106.             textColor=文字色,
    : L" B) j1 A0 |* [- @1 t0 x
  107.             textSize="20dp",
    5 m/ A/ J! d- @
  108.             layout_gravity="center|right",/ `4 f# v& u4 K2 o7 T7 s
  109.             text="E",) n) R9 L& L+ ]- x' W' F  [
  110.           },
    ; Y- t6 g5 L2 ]# l
  111.           {
      @/ p0 X0 B, z7 R: E0 v. [& C1 T
  112.             TextView,6 s1 u  l/ H* p+ o  ^; a! N6 r+ [$ A
  113.             layout_gravity="bottom|center",
      @: v8 m' ]2 t: v7 p# m6 M
  114.             textColor=文字色,/ \* _/ V, L9 x* r* P4 Z
  115.             id="compass_south",
    ; J. f; `& e/ K$ e9 _% U, H
  116.             textSize="20dp",( {2 J* v* y% g( A2 `
  117.             layout_marginBottom="16dp",
    % S2 I& o% O6 w: F) |4 w
  118.             text="S",
    : C! J  Q+ ]) }" ]8 D
  119.           },
    % |% j* t! Q: Z
  120.         },5 ~( j, R5 y% I7 `3 d) E1 M% p9 Q
  121.         {+ f& z2 Y2 V3 Y3 y5 h
  122.           TextView,
    ) N; E8 ]5 w9 Q4 b# _2 _
  123.           id="current_dir",2 G: W1 M0 ^! T! m+ k
  124.           layout_width="fill",- x% J) ]6 j( A: A
  125.           3 O7 m; t2 N! m$ k, l' N; m: M- `
  126.           textSize="25dp",. f2 J' ~9 i( d7 I( j
  127.           text="北",; s3 V3 v: |% L
  128.           layout_marginTop="56dp",0 o/ ^9 T+ ^4 l
  129.           gravity="center",
    " O, ^1 v9 G( b; P. K& g8 h
  130.         },( Y" g: J+ h6 h5 t5 T* q* z
  131.         {
    3 K6 S4 M  ^  S, y
  132.           TextView,* M+ S9 f2 ^7 g2 ^6 r6 e
  133.           id="compass_degree",
    % F; r/ F9 _% d
  134.           text="0",9 N5 ?. g( O/ k1 x* ?2 s$ \2 I% m* o9 v
  135.          
    6 h3 i& p" }/ y
  136.           textSize="25dp",: e0 _- p8 `0 O- C; ?
  137.           layout_marginTop="12dp",$ {' x; x3 ~" s. l5 O& _8 ~
  138.           gravity="center",/ I9 M1 L# r1 U( x2 R! O7 Q
  139.           layout_width="fill",
    $ w$ ^( m& C2 `
  140.         },' j, f* _3 P# E3 J6 b
  141.       },
    5 \- V0 i* B: K3 P
  142.       {
    # Z" O5 D& s6 X/ c
  143.         FrameLayout,8 j4 ?& N4 _( k* r
  144.         layout_width="fill",3 C% s% m" f& p# D
  145.         layout_height="fill",  ?. P( E* j; R: y) j' O
  146.         {
    4 k0 F4 |/ ^/ v7 @2 \( k
  147.           FrameLayout,- _6 t: z* Z' R; G! C9 w  T
  148.           backgroundDrawable=rim(w,h,0,文字色),
    $ K7 P. w3 F7 s$ G
  149.           layout_width="148dp",
    ( B! l: a2 O. G! X# ]
  150.           layout_gravity="center",
    / D3 v4 D! B, i3 q8 @% z; S! P7 Q
  151.           id="compass_balanceline",% |3 i% G+ k: I
  152.           layout_height="148dp",
    1 Y/ Q# Z* F& _* j* F( V4 z
  153.         },
    6 H) E9 }4 j6 `0 A
  154.         {. n* b" V( m8 w% P3 x
  155.           FrameLayout,
    - c: y5 n" e& f; q. Y  p
  156.           -- foreground=rim(w,h,0,图标色,图标色),4 I1 Y4 a" m* {5 ^0 e
  157.           layout_width="148dp",
    2 Z& N; M7 z' @8 {4 U, q( ]& T
  158.           layout_gravity="center",
    , r- U1 M1 u; P) D/ U8 \
  159.           id="compass_balance",. J! h9 h/ O5 g3 a' K* J% q. _+ L0 L
  160.           layout_height="148dp",0 p' q/ ?) n4 P# g! t2 t* k
  161.         },+ t+ A# r+ z) J% Q
  162.         {+ U, J, I- P. N. T1 t
  163.           LinearLayout,
    0 M2 O2 t4 r; X) W# m, ]
  164.           layout_width="fill",
    4 K* U% F! f( ~# G$ `( m2 l2 W
  165.           layout_marginBottom="64dp",
    1 R4 o0 x" s8 Q. c
  166.           layout_gravity="bottom",6 v5 p+ U0 V% Z' l' b& R1 k
  167.           {# s- W; u9 w. S- g8 Z! {# w5 z
  168.             LinearLayout,
    $ ], v$ V+ E' t
  169.             layout_weight=1,  c: ?. ]5 P# H
  170.             gravity="center",
    ) n( f  Y8 R- R& P  m% x
  171.             orientation="vertical",& M" y' y( ~8 Z. K" |
  172.             {
    . }0 Q. W: e4 v8 p- c  Z! g
  173.               TextView,  Q' `, w8 M- _7 x
  174.               id="balance_x",, f- b9 N& V; {3 t
  175.               text="0",0 c( ?; m4 }" L7 q3 x6 \
  176.               textSize="16dp",
    - a9 k) k3 J9 A2 l
  177.               textColor=文字色,
    ! h/ D- n& n& l& M5 V
  178.             },( Q! G. ^/ N) Q1 l3 _5 \7 A
  179.             {
    # }3 R6 i" n" b3 u( d* h2 k
  180.               TextView,
    2 g' G! }: d6 Z7 y
  181.               text="X",
    % k" v( p. j6 c8 T1 o" }/ C) s3 ^
  182.               textSize="14dp",
    % i8 F. g: c9 w
  183.               textColor=次要文字色,
    ( O# A/ d9 p3 I: }3 D  K1 O
  184.             },
    8 {# T* u, d, h" j8 [! C/ ?4 y
  185.           },
    4 I' }8 d6 N* `$ H6 L2 V. V
  186.           {
    # W% ~  e0 k* @7 M9 Y# V
  187.             LinearLayout,
    8 f  L3 h' h. ]* j) m
  188.             layout_weight=1,: `6 r- G/ w: f& q
  189.             gravity="center",$ f! {: `* z& C% S4 T
  190.             orientation="vertical",: r9 C7 x" l6 i$ T5 v1 A& ?
  191.             {; K6 t/ \, Y3 e, ?+ F! E, I
  192.               TextView,$ k0 ?+ U! L/ ^- e6 G
  193.               id="balance_y",
    . C1 f5 w8 g, X6 E& E
  194.               text="0",3 _. Z0 p; V$ P) l; v: s9 [. c
  195.               textSize="16dp",  l; `- r# v7 l  I  S0 K) O
  196.               textColor=文字色,
    ; H( Q: X; Z' a; u
  197.             },& X3 e) O) G- {' j
  198.             {
    * m' m* O3 w6 u# M
  199.               TextView,$ I, F/ ^0 W' c) b* i0 W
  200.               text="Y",/ s- e' y* w( f  l: }+ M/ V
  201.               textSize="14dp",
    & q( T6 h2 q, K, U$ f& q: z9 t# @1 ]
  202.               textColor=次要文字色,% |$ G9 D8 I4 k1 }* N+ ~2 K
  203.             },. [0 l4 r) Z- \  ?% y4 a
  204.           },. Q% U- _& ~6 {" {* X+ S+ R: b+ h- p
  205.         },
    & [+ c; M" t  H. v* d
  206.       },
    ; X4 x4 s1 ?+ P7 L/ d
  207.     },--pages  O+ E: a4 W6 E' R: m; z) H
  208.   },--pageview
    , Z1 ?+ J1 o3 D( a
  209.   {
    3 \5 D0 a8 U% x+ h5 D
  210.     LinearLayout,
    ! [* B/ A: [: j1 s- q! E0 o1 k$ k' u
  211.     layout_width="fill"," Z  V. B" ]0 K6 o% A  B% x! d% l! l
  212.     layout_gravity="bottom",
    / _, l  L' n% A
  213.     gravity="center",$ s3 L8 J& ~# {+ y2 y+ W
  214.     layout_marginBottom="24dp",5 N' P$ d* a# H; v' ^
  215.     id="compass_indicator",9 ?" s* J2 n& r7 B, K; P9 W7 Z
  216.     {
    # X& B" l/ `' v7 Z' j2 [* n0 }
  217.       CircleImageView,! Z: p: j1 w3 ?
  218.       src="drawable/dot.png",' {/ }* Y$ F4 c9 S% V1 G" d
  219.       layout_width="6dp",$ M/ s4 S8 F- U: \' W7 v
  220.       --colorFilter=Color.DKGRAY,5 [! A0 p: g& X( N- q2 }
  221.       layout_height="6dp",
    % @, u+ E: T- _& y7 i$ f
  222.       layout_marginRight="4dp",
    3 U8 l7 M1 h1 f1 T; P' R
  223.     },0 V; y6 Z; J6 J6 Z- |
  224.     {
    9 i+ C; F$ @5 G
  225.       CircleImageView,
    : k4 c& ?0 X" ^' ^7 W
  226.       src="drawable/dot.png",$ B; _. Z5 o. V* I1 c7 H
  227.       --colorFilter=Color.GRAY,
    ) ^  u: [4 b0 B( R
  228.       layout_width="6dp",/ s; Y0 V' W) t
  229.       layout_height="6dp",# h. s( c6 E# _4 s: q
  230.     },3 u( A5 U4 L* S  \* |1 X& r
  231.   },1 h. v% y2 R4 q* \4 l5 n
  232.   {
    . A0 e3 l# Q  k
  233.     LinearLayout,
    ( ?1 t( S2 }* u' E% R/ q
  234.     layout_height="52dp",2 P. k' G3 \1 h3 \% R8 F$ N
  235.     {( C" |2 r, V0 B7 H3 L1 }4 l
  236.       TextView,
    - K5 z7 b% u( u; F5 n: X: R
  237.       textSize="18dp",& I' K+ e4 I% B8 l( @" T3 o8 G
  238.       textColor=图标色,$ b4 B7 J* K% s/ N; j/ ~1 y; j2 G
  239.       text="指南针",  \$ F  H# i) C" T' h( r. V
  240.       layout_height="fill",& t% A( z$ i% o; u8 T: g7 P. q
  241.       paddingLeft="16dp",
    1 c/ O) R) h* `6 `1 f
  242.       paddingRight="8dp",
    % k: d( F* j% }0 c$ x* O
  243.       id="compass_title",+ S% V8 r7 W, }: [* a9 b' Z; L
  244.       gravity="center|left",
    7 I) @, b" p) k/ X7 H# w/ m* h* W
  245.     },$ P9 p, ^( F' a8 V
  246.     {--标题旁边的问号. T( G( T9 t; j0 N* w  n/ k/ C
  247.       ImageView,
    . i0 \" U6 b# m
  248.       layout_width="52dp",
    ' `7 D" H+ x% s; n% v8 T  P
  249.       layout_height="fill",+ M. @" \( t/ H% |- ~3 P6 I
  250.       padding="16dp",
    # J" z9 y0 n0 c8 w1 f1 e' v
  251.       onClick=function()! B! u+ [$ w* t
  252.         a.fun.dia("指南针与水平仪",Html.fromHtml("\t\t校准指南针:<br><br>\t\t· 绕 8 字转动手机<br>\t\t· 远离磁场干扰"),"我知道了")
    ( B. |6 t0 t- |( O/ ]
  253.       end,+ U6 J  R6 [! r- [
  254.       --foreground=波纹(),
    + Z! ]& {8 `8 r  V2 S
  255.       src="drawable/help_circle.png"," A6 T/ z) H2 Z$ X8 i, e* G
  256.       id="compass_question",
    3 J7 C5 r) ^( B5 c9 o
  257.       colorFilter=图标色," p) H% |, k+ ~9 ^
  258.       --visibility=8," t7 [3 \9 F! q) `
  259.     }," M* u7 h6 \. ~
  260.   },3 q: d1 u3 r9 M. S, ?
  261. }/ A: l6 N+ o  O, Y8 }
  262. activity.setContentView(loadlayout(aa))( F! l  q8 b4 k4 y( W+ X
  263. 7 d- w- @$ }0 o; Q
  264. if OrientationSensor then--有这个传感器
    0 e" w8 g1 P) V

  265. 5 \6 ^! |! Q& h* j7 _. v
  266.   function onResume()/ R! s+ u- Y# R- D/ h
  267.     if not listener then
    : G" m3 m) p: Z, E  M
  268.       listener=SensorEventListener({: E  m; h+ l* G5 o( i- U' P' I
  269.         onSensorChanged=function(e)
    4 E( G- G3 _$ [% i' D9 A9 l% s
  270.           infoChnaged=true" T+ Z! ]* P  Z9 g' s
  271.           local z=e.values[0]; J& r' K" I. z# b. A( F
  272.           local y=e.values[1]
    " n. ]1 d/ G3 ]  ^
  273.           local x=e.values[2]
    * C) k" T7 d) m7 Y- x( |1 K7 I0 |
  274.           if z>330 or z<45 then
    3 A* W( P: p) _* t1 Z: J  @( p
  275.             current_dir.setText("北")
    , [/ X# U: @4 x
  276.            elseif z>315 then
    . W7 Y0 ~6 X" `$ \
  277.             current_dir.setText("西北")
    # `8 O0 ]. X0 C5 J
  278.            elseif z>255 then! N9 [; y: M, q+ n6 ?  D0 h
  279.             current_dir.setText("西")$ e% u5 m; b$ Y1 T
  280.            elseif z>220 then
    ! \8 n: j. ~3 |6 v
  281.             current_dir.setText("西南")
    / `" e# @# \/ E5 t. v
  282.            elseif z>165 then
    6 T/ I- Y2 P0 |
  283.             current_dir.setText("南")
      D( j. r7 G' g" @' H
  284.            elseif z>125 then
    ) t7 }) H( E& o7 ~
  285.             current_dir.setText("东南")% ^9 n) q0 A6 f) z+ J! l# k) F4 p
  286.            elseif z>75 then8 G, j- l- L* r  y- M$ u7 W$ d
  287.             current_dir.setText("东"); T9 n( |0 t8 b7 y% }* R4 r1 x
  288.            elseif z>=45 then
    4 O- }+ n. G  j% Q8 [8 u
  289.             current_dir.setText("东北"), w5 @" Z& c6 g' i9 P8 n# U% \
  290.           end
    / l9 `2 O6 n: U* O) O. K& @6 C
  291.           compass_circle.setRotation(360-z)
    ! \! @  x8 H/ [6 K% _. Q
  292.           compass_south.setRotation(z): b  t- ~: a- Q
  293.           compass_west.setRotation(z)0 S7 p4 u7 z$ ?/ v" _( N
  294.           compass_east.setRotation(z)
    7 P  ~1 l' w6 p5 E
  295.           compass_north.setRotation(z)' B$ N" _$ ?. P- r7 k% t8 m/ u1 Q
  296.           compass_degree.setText(" "..tointeger(z).."°")# L1 I9 E% L! h# V0 ]2 _" A, ^4 A
  297.           compass_balance.setTranslationX(x*3.5)
    + Z2 J4 L; u5 ]. l" W- G# D; D' Z" B
  298.           compass_balance.setTranslationY(y*3.5)
    7 C* k1 |) |; {$ {1 F: F
  299.           balance_x.setText(""..tointeger(x))/ H4 z# @0 I6 r- W( P
  300.           balance_y.setText(""..tointeger(y))
    4 P: w( \! ~1 ^5 [+ w8 R
  301.         end})
    1 u6 U. y- n1 D1 D1 q+ y. Q
  302.       sensorManager.registerListener(listener,OrientationSensor,SensorManager.SENSOR_DELAY_FASTEST). Q, z: N  v2 d/ o1 q
  303.     end& W; k8 F7 ~2 j7 d5 `
  304.   end8 }" b& A- j4 _, i( O2 ?
  305. ! |8 I6 v) h) W5 J5 X
  306.   function onPause()
    7 L  ?4 I8 ~3 W
  307.     if listener then7 y, Q; `8 s4 d+ l
  308.       sensorManager.unregisterListener(listener)6 Z/ U0 Z% `4 I% w; ^
  309.       listener=nil4 P6 p. }; F1 r7 n+ b+ [
  310.     end
    * G- }6 a* [: u3 D2 p6 R
  311.   end
    0 W" X# |& I0 b% v/ {

  312. ' ]; w  A5 q2 [# |3 `
  313.   function onDestroy()( `7 J% f8 ]! [1 y+ {0 c% o
  314.     if listener then
    4 z4 O; ^: E6 t, @+ U) }: B8 n' l
  315.       sensorManager.unregisterListener(listener)* ~/ Y- h9 v, y2 H# `4 Z
  316.       listener=nil; C9 V* Q9 w7 u$ S$ `
  317.     end
    " T6 p. f+ J) m7 k' J" _3 `& U
  318.   end
    ; }6 R" D, F: }. d0 J2 L2 f% }( o6 d

  319. 6 s4 x  I/ U9 g1 B1 G
  320.   task(1000,function()# d6 W' d* E3 P4 E; ]2 Q6 M( z
  321.     if not infoChnaged then
    * d& H( T' H, u+ S
  322.       onResume()
    . n9 u- u' C3 P  P
  323.     end: ^' c/ W7 y" J, N
  324.   end)
    5 o. A  q, |/ s4 f
  325. + d6 G5 {/ x. E. A$ a  g- O5 c6 k' `, g
  326.   function onKeyDown(k)
    : v( m7 q8 n/ W$ L1 l  ]$ j8 |
  327.     if k==4 and curp~=0 then
    1 G8 |& ?8 L1 n3 L
  328.       pgs.showPage(0)
    ( s- l  A9 d: j- Y2 a
  329.       return true
    " M$ w! n, I- l4 ]
  330.     end
    8 a2 W, k3 c0 b  ^$ U9 D3 O7 U$ B
  331.   end2 G) D6 O: Z  d8 }# T8 s/ N

  332. ) z- X- }$ ?; A5 D, {
  333. else--没这个传感器8 \9 e$ k* B& L9 `: m8 w: i
  334.   print("您的设备不支持此功能")
    $ r2 h& F/ {$ v/ t4 @2 F( n* q
  335.   this.finish()
    # C; \8 k4 P  n
  336. end
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|星空社区 |网站地图

GMT+8, 2024-4-16 19:47 , Processed in 0.056466 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表