|
- require "import"
4 W/ F4 B. w+ d- r0 \ - import "android.app.*"
5 b6 q y- S% e S5 U - import "android.os.*"
K& Y& P+ T# E/ d - import "android.widget.*") ^9 c& N3 l8 Y
- import "android.view.*"
) J. G$ ^8 {. s4 c - & ^: H$ k {6 x/ I9 G. z3 ~
- --activity.setTitle('AndroLua+')
8 z& f1 E7 n8 W5 y - layout={
6 T% n4 k. _" ~: {0 z/ s' v% } - LinearLayout;( k4 O$ @, K) X/ |1 W
- orientation="vertical";
5 l$ E$ t# y" J4 `) H - layout_height="fill";
: Z ]0 K7 o9 U9 J9 f - id="bg";+ [6 O" f4 c* ~: E3 [* s1 m" y$ F; N
- gravity="center";
+ L; h% k/ q) Y" g$ D - layout_width="fill";
: `+ x$ b" n& Y' b2 ]" C. m$ o - { o/ D( `/ r# g1 m5 M- M
- Button;
# Q8 I# v! D z8 [4 L7 I8 O0 H - text="调用相机拍照";
) T! d3 k7 L9 d, [$ b( G( `; f - id="btn1";* d9 O& f5 Z" `6 I8 g( y
- };
5 c7 U+ H% T" p" s; n# I/ |# F - {! P( k6 p% e0 S: B" x
- ImageView;' D0 C: f% |1 F; g4 L
- id="img";) ^0 I; {' g7 p/ D" T
- };( _! E! m m" m( f
- {
6 k* N8 u- v. W - Button;+ o- c0 x* k, _. V0 A# W5 C9 t4 H
- text="设置为桌面壁纸";
8 z0 ^3 C' U' V j4 u/ ~2 b - id="btn2";) ]( ]9 x8 t! v+ u& O& z7 O
- };
# x$ j* r: J+ Y8 e3 Z - };' G. A) P# r. l; }+ ^6 }
- activity.setTheme(android.R.style.Theme_DeviceDefault_Light)--设置md主题" f7 ]4 z" X' v
. N6 F6 {( s% w* S0 N7 f- activity.setContentView(loadlayout(layout)), C" S! }5 \5 E; |; \5 |. _
& H+ `; i3 h* F+ a9 r- --导入包) i8 s- x( \" Q$ `! w4 h
- import "android.content.res.*"
3 H2 X; M3 f6 M - import "android.content.*"
9 v" r0 h2 j1 D' Z+ e' }8 b/ ^ - import "android.provider.*"* I, F) ]) m' J- q; d- i6 R
- import "android.graphics.*"+ ]# P# K; l/ D4 D: l1 q8 v
- 6 x9 V: V+ l. s+ j0 R9 ~' M
- --获取桌面壁纸' J7 Q" {" `9 k9 f% N
- zmimg=activity.getWallpaper()# R( u2 i0 a( K# d# w
- bg.setBackgroundDrawable(zmimg);( c, c# r6 s4 ]# O6 b) |
& Q" @6 ^, z q% d `/ W9 z6 O5 U
P: Z& H% u& e2 w- btn2.setVisibility(View.GONE);
# J8 |" s1 u6 Q% G v0 g - btn1.onClick=function()
; o! M; B1 `) D. v1 y# }- ^ - --//跳转到android自带的照相机+ t" R- v( E) w' q/ r
- intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE);
' K+ c5 c8 ]- a! _! p - photoUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
% A. O5 E$ P, b# t+ ` - activity.startActivityForResult(intent, 1);
+ R% Z) w5 d6 y& m% U - end" J/ u g* w, T" b4 m
- $ G( q6 E" |8 g3 O
- --//监听拍照完成后的处理1 G, J& T: g0 K" y* B4 \
- function onActivityResult(requestCode, resultCode, data): S* t# C }. h/ P# T( L: K3 T
- --super.onActivityResult(requestCode, resultCode, data);
3 a3 m& C/ b. M5 X - if resultCode==activity.RESULT_OK then) |- Z8 }) }& _
- --获取相机返回的数据,并转换为Bitmap图片格式
$ F) ]5 Q* g0 c3 t | - bundle = data.getExtras();+ W; p# ]$ s9 @
- bitmap = bundle.get("data");
9 F* |; F) m" o, [ - --设置的图片也可以输入路径
8 h( D7 `- z7 O6 ]/ z: L2 k - img.setImageBitmap(bitmap)" T* E* a. ` |9 G+ a
- btn2.setVisibility(View.VISIBLE);
( O6 @7 ^$ g0 Y - end
8 ^0 c) M+ ~% i& W8 A - end
3 H% [7 d$ T d
0 J4 Y3 H6 V/ C. ]( l+ B! {
) ^5 W6 z/ O$ d' q( w/ f: h, E" R
" m' K9 t" q# y U: H- function setBgImg()' J, K- l: o( m ?" \. w
- resour=activity.getBaseContext().getResources();1 a# Q( X* t7 @& L" S/ p
- --//设置桌面背景
; P& Q# f* x% B8 _0 \ - activity.setWallpaper(bitmap);
/ W' x9 k% D: C7 P- w - end
R8 v$ S/ k; D9 R' g& l; x
4 ~7 M! L* S5 H! Z6 d- btn2.onClick=function()3 \! q, U2 F/ P
- if pcall(setBgImg) then7 k9 L* q3 d; }+ [9 Q
- print("设置成功")
" e# i X. r* Z8 T- W" V9 S - else, w% `( S6 o \. G+ K {/ y8 U
- print("设置失败")$ W2 h/ h) A$ L2 D& R0 r, B: S
- end0 x7 c k& y1 W
- end2 n9 L" P2 c+ d# H7 p) ^& |
8 Y2 A3 J! `: p, Y) |% ]1 W% G3 J4 v- 7 L4 ^+ E/ f# P% `+ m1 d6 Z
- , B+ C% p! Q$ O( _4 s" G# N( P5 N5 P
- i$ R# {# t8 t% g. B# A, ^
复制代码 |
|