登录  | 立即注册

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

查看: 1369|回复: 0

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

[复制链接]

444

主题

509

帖子

2051

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2051

荣誉管理论坛元老

发表于 2021-7-1 08:33:17 来自手机 | 显示全部楼层 |阅读模式 来自:
  1. --Copyright© Ayaka_Ago. All Rights Reserved.
    4 r6 _/ G- G) d3 v2 B4 ^% n1 @) J
  2. require"import"
    9 Z( b$ |  q+ k. {
  3. import"android.hardware.SensorEventListener"$ Q5 R* ?7 x  S+ W) ~0 X
  4. import"android.hardware.SensorManager", A, I: q5 X9 t6 u2 W
  5. import"android.hardware.Sensor"
    ( g  p% S* n8 ^1 H5 r% n5 u) G8 I0 B
  6. --setOrientation(0)# D4 @6 ?8 p, A0 L
  7. h=activity.getHeight()--! }. X! E  {  \
  8. w=activity.getWidth()# i( T, D; b& R
  9. import "android.graphics.ColorFilter"
    3 X  b& O- K) d8 |
  10. import "android.hardware.camera2.CameraManager"  h8 {! \- |5 J3 V3 V% F
  11. import "android.widget.PageView"# i2 o/ j3 ?: F" e2 y& Z3 \
  12. import "android.hardware.SensorEventListener"* J7 c2 t" m/ n. [% K4 B
  13. import "android.hardware.Sensor"0 a' X% v! O1 a  m" _
  14. import "android.widget.FrameLayout". v) c& h$ n$ g
  15. import "android.content.Context"- f$ ?0 s) s) F% B' s9 L. L, q# ]
  16. import "android.widget.ImageView"* f% S( F( J% J9 k* z* e4 G
  17. import "android.hardware.SensorManager"8 V3 g. }' Z4 y0 Q* h' f! D
  18. import "android.widget.TextView"2 x$ M/ W* |0 R* @. E
  19. import "android.widget.LinearLayout"
    6 g! p9 L, A+ U1 M
  20. import "android.widget.CircleImageView"' `  E! `( J: M% H* t) D: b- u
  21. import "com.nirenr.Color"8 q+ n8 x+ w' V
  22. import "android.graphics.Color"
    & |1 b+ X; X6 d* ^- v' W2 a0 B& C
  23. import "android.text.Html"& Y1 R# q) S/ Z7 ~* B2 k0 ^
  24. import "android.graphics.drawable.GradientDrawable"' z( x- d( v  |' E6 B
  25. activity.setTheme(android.R.style.Theme_DeviceDefault_Light)--设置md主题1 s) B' G- b% v. I) K3 X+ s
  26. local CameraManager=this.getSystemService(Context.CAMERA_SERVICE)--相机
      |6 G/ v# G& C2 ]3 X% \; E8 k
  27. local sensorManager=this.getSystemService(Context.SENSOR_SERVICE)--传感器
    ; |: c' }* S: Z" F% s3 j& u' _
  28. local OrientationSensor=sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION)--方向
    # V' t( D) a- |( k
  29. local curp=09 R! T& P5 H, x) W  z

  30. 9 \( y/ Y" k, F: W7 U- \
  31. local function rim(radiu,da,db,c,inside)" x+ _$ s9 n. t* n
  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)
    " x  ?6 I7 k+ _8 c
  33. end' L2 P% y* D! v# N- G
  34. / b* @+ E6 Q8 p7 l" F5 F( k! F
  35. aa={  }; _& j5 }( g  w$ g* M$ r- a
  36.   FrameLayout,
    0 f, u3 v' h) G6 q$ S7 X$ {# _+ L
  37.   {6 B# U0 _6 x3 Z5 h
  38.     PageView,
    0 _2 A1 @+ p0 ?" F
  39.     OverScrollMode=2,+ j( o: S% h: {9 n( i2 ^
  40.     layout_width="fill",# R, B8 e0 [  b. e
  41.     layout_height="fill",
    # E8 l5 M2 o  \; ~4 ?. C
  42.     onPageChangeListener={
    " @6 n% T+ T: C/ `  R
  43.       onPageSelected=function (p)
    3 A' p' A$ X' V6 y. r
  44.         curp=p/ L3 p& j* d6 `
  45.         if p==0 then2 \* B+ y4 i( p+ f
  46.           compass_title.setText("指南针")1 H- U6 i6 Z( f5 ~6 o/ z! F' s
  47.           compass_indicator.getChildAt(0).setColorFilter(Color.DKGRAY)8 _! _  F9 W, j9 b4 ^
  48.           compass_indicator.getChildAt(1).setColorFilter(Color.LTGRAY)
    # K+ [' I1 S( M* o
  49.          else
    5 W4 T- u9 T& N
  50.           compass_title.setText("水平仪")- C" P5 m0 L# @0 k" B  ?$ I( F
  51.           compass_indicator.getChildAt(0).setColorFilter(Color.LTGRAY)
    ) Y, N9 |$ k4 R2 T
  52.           compass_indicator.getChildAt(1).setColorFilter(Color.DKGRAY)7 F: {. W2 d8 a4 L
  53.         end9 b" ]' C* @  k) e2 q+ I# Y) C
  54.       end},
      y* e, ~' n3 q% _. m% O
  55.     id="pgs",# T; E9 Z  v) M
  56.     pages={; M2 z1 j! L8 {- Q; `5 g7 n
  57.       {
    " n  X7 {9 @$ `4 I/ Z# F' @' P- I* I
  58.         LinearLayout,
    / T% E" N' k( N, s7 q0 E) T/ k7 G
  59.         orientation="vertical",  S7 Q# Q; J( \7 D8 |- h7 V
  60.         gravity="center",# J  V: n( ~& `- g! F+ o9 @  r
  61.         layout_width="fill",
    & s) ?3 F: F7 V* p  n! C
  62.         {- ?0 u2 X4 J; q& k; N
  63.           FrameLayout,
    $ @; w/ Y6 ?4 _
  64.           layout_width="250dp",
    : m! S3 I6 A/ _
  65.           layout_height="250dp",
    / C& c7 V5 ~/ r& L$ a; ]
  66.           layout_gravity="center",2 e1 A' X7 r1 v
  67.           id="compass_circle",! M# F+ u# J( ~3 y) i5 n+ R
  68.           {) X8 N% y) z: ?8 J1 n/ y: a
  69.             FrameLayout,
    ( |; ^8 J' }" D2 ~! B$ ^
  70.             backgroundDrawable=rim(w,w*0.008,w*0.016),
    2 w5 H. o7 _( d1 i% L' [- z2 y
  71.             layout_width="fill",# C) L' c' P. Q. o. T4 k8 r
  72.             layout_height="fill",
    7 R) ?+ X( p% P1 o9 g+ W. P5 ]3 v1 U
  73.           },2 j& K) u& p! v! M: b7 ^
  74.           {6 r" Y& T  a: D+ y
  75.             TextView,
    9 q4 F# v: G  }, I) C
  76.             layout_gravity="top|center",
    # F# v1 o: X* j3 }
  77.             / K8 q) D5 p# w4 e8 U2 b
  78.             id="compass_north",0 Z8 d, V( w# _7 c
  79.             textSize="20dp",6 R9 |! L2 z0 x( q
  80.             gravity="center",
    ; c1 {; L1 f/ J: q
  81.             layout_marginTop="16dp",
    0 e. T  w: u  d
  82.             text="N",
    , v7 e. [1 r1 P! I- A8 J
  83.           },
    , j( T8 d2 L! J- y6 o8 R
  84.           {
    1 @0 l8 \5 t: L2 c8 D( ?5 j' V
  85.             TextView,
    9 ]* K) m4 g# v% X! e
  86.             id="compass_west",
    ) _- o9 y8 Y3 x
  87.             
    . O5 j& V9 x# w9 m' y/ s8 ]# y" p
  88.             textSize="20dp",
    - \9 h; X7 O6 b7 d+ Q: ?% m
  89.             layout_marginLeft="16dp",
    ' N5 R0 v+ O  V: N! p, o1 w
  90.             layout_gravity="center|left",
    ! s4 ]( t  J( {6 e
  91.             text="W",
    # @  P  c7 n# e3 Y/ W! |
  92.           },
    8 W6 C& h+ Q& Z9 \7 H1 H
  93.           {
    * r* p! T1 S/ S' X
  94.             ImageView,
    8 A/ p3 H' C  L, _$ @
  95.             src="icon.png",9 Y' \" e! Y( `7 {
  96.             layout_height="42dp",* j" T# v2 x/ |# v) F( z9 ]
  97.             layout_gravity="center",
    + K* g% u6 K+ U6 ?. s
  98.             layout_width="42dp",7 J8 d8 F  r5 E' {" s) x
  99.             rotation=90,0 A3 c! F8 T( z! h6 f
  100.             ColorFilter=强调色,
    1 _9 h- z; j0 R# H0 r
  101.           },
    $ F. u1 R. c; P$ }
  102.           {
    # @( r! b5 Q5 V2 Q0 M  q
  103.             TextView,
    4 |- l* m& p1 j4 o& S: w% q+ _
  104.             id="compass_east",& X# B* k  Q# h% C4 h( `  l+ c- [
  105.             layout_marginRight="16dp",# R; d# ^( M* h' S5 }
  106.             textColor=文字色,% J" `! t: A% B* p
  107.             textSize="20dp",
    % E) ^( j2 j. t
  108.             layout_gravity="center|right",
    ( y2 b  n! y% M+ I4 j, h( F
  109.             text="E",
    % ?8 }8 d& @$ W; S% Q& r' k
  110.           },% n% P( i5 Y# S2 p$ Y
  111.           {9 d) ^5 a+ j) z
  112.             TextView,& |% W+ [& N1 ]
  113.             layout_gravity="bottom|center",
    3 ~% M& M  ?' a) t% Q9 r; X+ D
  114.             textColor=文字色,
    9 F; f( a4 b! R" h! y( f( O
  115.             id="compass_south",
    ; N4 h: _9 `3 N  f. T5 u* t
  116.             textSize="20dp",
    " P3 V. q3 k& K0 B
  117.             layout_marginBottom="16dp",
    " Q- m6 N8 r. s2 P
  118.             text="S",
    4 |+ R! K+ C6 l, [, s
  119.           },2 C& k) E/ Q1 g) I' G
  120.         },6 u) b  e2 S- z' T  ?# K
  121.         {
    7 L+ |3 ^6 b3 r$ a% X0 ^% t" M3 T
  122.           TextView,
      k5 w0 }) k/ M6 z# C
  123.           id="current_dir",
    . a+ w* ~! D- J
  124.           layout_width="fill",
    9 A) W- Y' Q/ E8 c, N$ j$ X
  125.           , A+ Y! c8 J% w3 K( z; S
  126.           textSize="25dp",
    ; f# g; {+ E5 O1 R$ E
  127.           text="北",& R9 `) {) K. {4 q
  128.           layout_marginTop="56dp",9 c. ]% e  y! D  Q8 w6 E4 J
  129.           gravity="center",
    " d; U% ~7 l! {5 R+ N! D
  130.         },* L& `1 Y( m! F6 N
  131.         {
    ' u; m# M9 F* c4 h  G
  132.           TextView,
    , a. H" x6 C! m0 S
  133.           id="compass_degree",
    , G8 K5 p3 t' w, D5 k
  134.           text="0",
    , j* P0 Z. L' A4 V. @' Y0 l+ o
  135.           ! G$ W% {( z$ O+ {
  136.           textSize="25dp",
    ) ]7 r6 d4 T3 Q& V: L
  137.           layout_marginTop="12dp",
    + U7 q/ b" d; ?. d7 _
  138.           gravity="center",
    . w  t$ U8 s/ Q4 v. z; r$ {
  139.           layout_width="fill",
    $ S! R( L: I. F' h
  140.         },3 ]. l, y7 J. u! w5 _& D  Q; c
  141.       },
    % ]8 \0 g6 D7 v) W- n* O3 i& e
  142.       {1 U  K4 N5 k- E8 b
  143.         FrameLayout,
    1 [, F. y& J- q3 _! u
  144.         layout_width="fill",/ S; q2 E8 J: J3 T
  145.         layout_height="fill",
    ' \# C6 u, B* T% r: K8 p  C8 H
  146.         {
    9 ?7 Z( Y7 q% R: S  M( t) @) s
  147.           FrameLayout,7 E6 b- `1 m5 V. e# x; a
  148.           backgroundDrawable=rim(w,h,0,文字色),5 H- w6 {3 g0 J& m0 V1 W
  149.           layout_width="148dp",( w# n9 I- {) h; `$ S
  150.           layout_gravity="center",
    % L4 f# j3 e% I
  151.           id="compass_balanceline",+ k3 D  [# j# a
  152.           layout_height="148dp",
    * l  k" d- b4 u& l3 F
  153.         },( j( t1 s6 p* v' ^. y
  154.         {5 y- u" F" R2 M! \# W" K, K
  155.           FrameLayout,
      k$ D3 P# h5 R8 x  i0 j8 N7 P
  156.           -- foreground=rim(w,h,0,图标色,图标色),! L; U( f( Q/ X/ T7 S0 u
  157.           layout_width="148dp",
    4 d6 l; p) r) S" v$ z7 w$ X9 g
  158.           layout_gravity="center"," P/ I6 W: P1 f, l
  159.           id="compass_balance",
    ! |2 Y4 b1 `/ s! }( o- J9 O
  160.           layout_height="148dp",
    ( G) @0 L' s' R2 y6 ?; J
  161.         },
    3 A9 ^+ S- `8 p* Q
  162.         {, L. C2 F- @" |7 L
  163.           LinearLayout,
    4 H' Q( F5 [, P) b. w% d3 \5 m% }
  164.           layout_width="fill",7 W# o9 ?- U' e- {
  165.           layout_marginBottom="64dp",
    / N0 ?4 x) T) X. ~/ e3 B5 o
  166.           layout_gravity="bottom",! L" D% h# ~9 D4 k, r
  167.           {
    / N8 V, \4 X$ Z% y# |: c5 v( k
  168.             LinearLayout,3 m6 J2 q. L3 L
  169.             layout_weight=1,
    1 |6 ?$ ^) t1 t% Q
  170.             gravity="center",
    ) \; f  v7 ?# V- L: W% ~. H4 Y
  171.             orientation="vertical",0 ^& Z( F: n( ^
  172.             {
    " z$ ?& k( L' a* H- u" `% a
  173.               TextView,
    0 X8 M8 \& j# }$ j
  174.               id="balance_x",. B( \1 Z6 M. G' Z
  175.               text="0",- k+ c! v; P- T
  176.               textSize="16dp",) E' `+ h* T! t* r
  177.               textColor=文字色,
    % t0 K1 \7 I4 H+ ~. k9 X7 e
  178.             },
    9 i( z2 v; ?) k& P( A3 U0 g# G
  179.             {
    1 M0 P2 z( D" ^- x/ z% q6 w3 U  D' |
  180.               TextView,# P, T! j  Z2 \0 _( a1 W
  181.               text="X",8 p. g1 `/ |  Y$ ]
  182.               textSize="14dp",
    5 s2 l5 S/ c& W4 p0 T* h- z
  183.               textColor=次要文字色,. A! g5 U! B8 |" q" m
  184.             },: E( l& l0 n* L( G+ _5 o
  185.           },
    . f5 z; M# F2 F* B% j
  186.           {
    : Y7 q6 i& k0 l
  187.             LinearLayout,
    1 P& A* V2 A; q/ z
  188.             layout_weight=1,/ R" e  w! l5 B
  189.             gravity="center",
    + f2 r4 o8 Y% Y: W# X, u9 F/ m$ ]4 y) W
  190.             orientation="vertical",0 o9 x. ?! c) v5 K! ~6 Y8 H8 a
  191.             {2 h" E" z( q& {$ _4 u  X5 @3 p
  192.               TextView,
    7 E/ _4 ^& w/ c6 q5 p; i- ^( ?$ @
  193.               id="balance_y",; I1 h; {* M2 c& [, l
  194.               text="0",8 y% |9 `* X7 I
  195.               textSize="16dp",9 n4 {9 @3 o( v& Z. X" v; @* D  g- a
  196.               textColor=文字色,
    % }7 N7 M# n( N. U
  197.             },# P6 i  X6 l) k3 K
  198.             {& r& x3 I% O0 `4 b
  199.               TextView,
      R# T8 x, L& Y1 L% M6 b
  200.               text="Y",
    . V- b2 A$ }, j
  201.               textSize="14dp",) O; t* \3 M# Z% E# v$ S
  202.               textColor=次要文字色,) z% F6 ~- {' s! q! N. M
  203.             },
    # P5 F. N7 R$ V
  204.           },4 Y7 L; Q( D9 |$ h3 m
  205.         },
    4 f: I  v1 S) Y- Y- D; R
  206.       },3 _" {7 I, d: ]' `) ]" P
  207.     },--pages
    * k0 s; \5 B; y; @+ ]# l. e: R
  208.   },--pageview2 {8 B& I5 E, r9 r% t
  209.   {
    ' W2 `' P+ S5 ?6 y3 c5 L2 ^0 Y, \
  210.     LinearLayout,
    . W3 a" Q" i6 [6 ]0 j" ~& t
  211.     layout_width="fill",
    , c1 Y1 ]6 t/ ^3 R
  212.     layout_gravity="bottom",, B6 E& d; Z  O0 V" l# O1 r( V
  213.     gravity="center",
    . ]5 f) ^" x5 ?5 v7 n4 S0 b* `# e
  214.     layout_marginBottom="24dp",9 a1 J3 }2 @5 ]* q  r& f
  215.     id="compass_indicator",6 }" v2 r3 ~( y, p) G, M
  216.     {% l) `. F2 m( @0 N7 I7 l, j" r
  217.       CircleImageView,) F- L) ?/ |; A
  218.       src="drawable/dot.png",
    1 ^. c, `: a7 r. Q$ {) Z* L
  219.       layout_width="6dp",, i8 q2 A5 t8 P
  220.       --colorFilter=Color.DKGRAY,
    , b; A" \6 `. s0 c
  221.       layout_height="6dp",1 j) h! I4 G8 a) A5 \
  222.       layout_marginRight="4dp",
    6 S5 D. P( D. C3 {, k
  223.     },$ {2 O  A, U( e) }% U* I( F2 f
  224.     {# D5 x- b7 @5 c6 l* F, t
  225.       CircleImageView,* c& B! A  {+ f6 u9 w# i+ q* D7 P
  226.       src="drawable/dot.png",
    ! }' f7 y. c' N' Y! }  S1 I+ v
  227.       --colorFilter=Color.GRAY,
    0 a9 e+ F+ _: w2 ?$ u5 L
  228.       layout_width="6dp",
    $ L2 H5 c2 o( m+ W" L7 u8 |
  229.       layout_height="6dp",
    4 ]# u# F# ^8 ^/ y
  230.     },
    4 ~7 V# _1 C4 U. `' D8 u) P$ {% g
  231.   },$ w5 A; U/ G4 X+ k
  232.   {# Y8 L7 b! S) Y$ Z8 `1 c
  233.     LinearLayout,; ~/ P& |; ?9 N' B2 `2 Q3 y5 `: Q
  234.     layout_height="52dp",
    0 R2 H8 Y" ~, I8 @
  235.     {$ v+ v$ S  c, y+ Y" p
  236.       TextView,
    ) O3 j" y+ b% t" J3 a
  237.       textSize="18dp",
    9 G+ a$ N& C0 `; f
  238.       textColor=图标色,
    ( ?$ g. y4 i' N# }( t  K* {
  239.       text="指南针",; ~1 w# ^. u; P; W& H1 M
  240.       layout_height="fill",
    * P8 k, \9 r9 s5 p& o
  241.       paddingLeft="16dp",
    ; V- F8 j0 R( N0 ~6 r0 ~( r
  242.       paddingRight="8dp",. t' Z6 ^+ s) [! `6 E6 [( I1 ~7 f* p2 G
  243.       id="compass_title",7 g9 c# B$ b4 H% S, B6 l, U/ @
  244.       gravity="center|left",
    - U4 q0 o3 l) ~( B) y
  245.     },5 H' |* K( h' S+ [: h
  246.     {--标题旁边的问号& h% V5 h5 Y0 s% u
  247.       ImageView,) v* I! H( U) ]8 [
  248.       layout_width="52dp",
    8 N& R3 y; U) D+ P* C
  249.       layout_height="fill",
    - P7 ^! A2 S: n6 u" d9 d) B+ x
  250.       padding="16dp",3 T3 I0 I6 T5 z$ Q
  251.       onClick=function()) i8 j" {: a$ J% V4 m" T, T& i
  252.         a.fun.dia("指南针与水平仪",Html.fromHtml("\t\t校准指南针:<br><br>\t\t· 绕 8 字转动手机<br>\t\t· 远离磁场干扰"),"我知道了")
    ( X& Q/ T+ O5 I* A
  253.       end,+ l( Z/ \' e( p4 t/ |4 @; A9 d% X
  254.       --foreground=波纹(),: s: O* R; P4 d, ]7 X5 `
  255.       src="drawable/help_circle.png",
    + P* h, r% K7 U0 I2 k, z, t
  256.       id="compass_question",$ v# P" s' B; G4 b; Z
  257.       colorFilter=图标色,
    6 L% h1 g( w' \2 U/ a6 m
  258.       --visibility=8,
    " t3 d+ F4 I5 J1 |8 w- a: D9 \$ L
  259.     },( e* b/ u4 F- J( y" n, i
  260.   },8 F- X2 N& c+ L. \' n5 K
  261. }
    3 O8 D  x+ C8 r+ I: X% y6 h
  262. activity.setContentView(loadlayout(aa))4 P* Y& Z8 `, b2 g4 a& U" ~

  263. , q7 X% _. ~* K# b1 m
  264. if OrientationSensor then--有这个传感器; m( T( o* E+ f8 J
  265. 3 |3 A* l- B; _0 r
  266.   function onResume()
    ! k) E6 A* y/ q/ K) ~
  267.     if not listener then
    6 w  ], f' ~) x/ e
  268.       listener=SensorEventListener({
    1 x3 L" B% a8 i( A: Q# J
  269.         onSensorChanged=function(e)( t0 h* b+ @6 T) u0 L4 c% U
  270.           infoChnaged=true
    , G" k. P; F( ~1 l! e* s
  271.           local z=e.values[0]
    / P" w0 n1 X: y8 k0 p+ v
  272.           local y=e.values[1]
    6 B; T& y3 O2 D
  273.           local x=e.values[2]% D0 B: Q1 P9 J% t4 [# r
  274.           if z>330 or z<45 then
    3 a5 _# x$ v) h& ]0 T; W# A: d7 e, E
  275.             current_dir.setText("北")
    : t4 X0 j5 i4 n  R6 L7 I* b. g' z
  276.            elseif z>315 then0 P( i) v! R- `2 e0 G% A8 t. Q. |
  277.             current_dir.setText("西北")2 |% f* u6 V2 z( Z: O
  278.            elseif z>255 then
    - I. ?( ]/ [" Y% r0 l  u1 `) i
  279.             current_dir.setText("西")4 w5 ?5 K9 u$ b& W) x' f) N* Y
  280.            elseif z>220 then
    ) j; G: @, _( L
  281.             current_dir.setText("西南")
    , S' ^- Y0 I9 T; q
  282.            elseif z>165 then6 ?8 J3 Z) N  Z8 e9 N( u
  283.             current_dir.setText("南"), R/ R7 E8 x+ m" @7 h
  284.            elseif z>125 then
    0 M" s) F/ k9 t1 l
  285.             current_dir.setText("东南")9 {/ a" |/ E. U5 s8 M, r: I
  286.            elseif z>75 then
    & O) O9 r% N+ u0 v, m4 F
  287.             current_dir.setText("东"); m1 {: l; t; R* C; J4 n
  288.            elseif z>=45 then4 c4 ]) R3 x1 ]8 F! q# s2 l
  289.             current_dir.setText("东北"), K9 O0 c/ y" F
  290.           end  E4 c! n  q# h4 s( R
  291.           compass_circle.setRotation(360-z)
    : b/ W; H( R0 q9 X
  292.           compass_south.setRotation(z)
    ( A% M9 `3 F2 [. `6 c
  293.           compass_west.setRotation(z)9 ~" {' u4 M4 @/ Z
  294.           compass_east.setRotation(z)  N9 E/ A' T8 _1 H7 r/ L: g
  295.           compass_north.setRotation(z)
    3 y5 A6 r. y4 {" q3 I
  296.           compass_degree.setText(" "..tointeger(z).."°")! O# ^( Z. I0 o+ g: j0 a
  297.           compass_balance.setTranslationX(x*3.5); n( X# b5 [  M. O, V7 n
  298.           compass_balance.setTranslationY(y*3.5)
    5 L+ l- Q  T* i1 v3 M4 P1 p6 p
  299.           balance_x.setText(""..tointeger(x))
    , ~5 z, e4 ?2 s
  300.           balance_y.setText(""..tointeger(y)). W: }& d4 Y  k2 h4 Y& W$ d
  301.         end})
    ) b2 x9 I5 r3 I- t2 F6 u3 Z" v& f
  302.       sensorManager.registerListener(listener,OrientationSensor,SensorManager.SENSOR_DELAY_FASTEST)
    $ x! Q  x# B! }$ R& v
  303.     end( b) a% @. K4 k; F1 y
  304.   end9 F/ X5 ~& @2 t

  305. - m+ j0 B# `: |0 }( J
  306.   function onPause()
    + R8 l0 ^5 n; Q5 R/ ~4 a. I6 m
  307.     if listener then
    3 A0 f9 g( l5 p' W
  308.       sensorManager.unregisterListener(listener)
    & s1 A3 O9 X& T! n( N1 Z, J8 l
  309.       listener=nil
    8 z* d% s: l3 l6 ^% _% I+ z* t) S4 k
  310.     end
      r2 d# p; A% y5 i# ?8 p
  311.   end& o/ [) }: a5 K2 B' `

  312. 0 m. q5 g7 k2 t3 M3 ?
  313.   function onDestroy()
    3 x8 ]/ B, p4 \8 A- l0 B
  314.     if listener then) ^3 Z+ v$ n' C6 Z2 g& T9 u
  315.       sensorManager.unregisterListener(listener)* ]/ b4 S- U# l/ G; W% F
  316.       listener=nil
    7 c4 h8 t$ s, X( d! I# v" ~
  317.     end- c" \. M$ ?/ R7 |
  318.   end
    # L& E3 Y- Z  R

  319. 2 j" h. F  j. v- A" M$ `: H, Y8 ]
  320.   task(1000,function(): ^8 I/ I) T# K# J; v: n+ \
  321.     if not infoChnaged then1 @) `2 c, C9 C9 b
  322.       onResume()" ]) A% s3 |# t$ a! N! |
  323.     end2 A: u. ]. N4 C
  324.   end)
    ' G( q1 s. b* `* a5 M# G

  325. * b* I  B# t* d/ ^' ]0 q
  326.   function onKeyDown(k)
    8 l4 P! a% _, G6 Q/ t! d6 w
  327.     if k==4 and curp~=0 then
    ; J4 H3 a8 K- ^7 ^5 T, S- @8 |
  328.       pgs.showPage(0)& f2 l6 i6 w( V
  329.       return true4 o5 u/ J& Z% }: s( j
  330.     end
    2 u5 |4 H6 \% F% r$ A
  331.   end! K5 Q5 B+ k, e2 f/ K* e% E

  332. , A1 a" v; m3 q
  333. else--没这个传感器: M1 t" H9 `* b9 `, L* E1 o9 N; U
  334.   print("您的设备不支持此功能")
    + E- \7 c0 C6 ]( v; z$ a( w
  335.   this.finish()6 i1 O6 l1 X% a5 j) O. n/ _+ D9 o# O
  336. end
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-4-25 08:58 , Processed in 0.052945 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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