python for android : 显示图片
来源:互联网 发布:个人软件定制 编辑:程序博客网 时间:2024/05/01 03:52
参考: https://code.google.com/p/android-scripting/wiki/FullScreenUI
这是一个简单的图片查看小程序 ,只有基本功能: back 选图片 next ,还有一个没能实现的功能:横屏显示。
imageview.py
# -*- coding: utf-8 -*-import androidimport os,sys,timereload(sys)sys.setdefaultencoding('utf-8')droid = android.Android()base_dir = '/mnt/sdcard/DCIM/'if not os.path.isdir(base_dir): print base_dir,'is not dir' sys.exit(4)def show_dir(path=base_dir): """Shows the contents of a directory in a list view.""" nodes = sorted(os.listdir(path)) # Make a way to go up a level. if path != base_dir: nodes.insert(0, '..') droid.dialogCreateAlert(os.path.basename(path).title()) droid.dialogSetItems(nodes) droid.dialogShow() # Get the selected file or directory. result = droid.dialogGetResponse().result droid.dialogDismiss() if 'item' not in result: return target = nodes[result['item']] target_path = os.path.join(path, target) if target == '..': target_path = os.path.dirname(path) if os.path.isdir(target_path): return show_dir(target_path) elif os.path.splitext(target)[1].lower() in ('.jpg','.png'): return target_path # inform the user. else: droid.makeToast('Only .jpg .png files are currently supported!') returntarget_path = Nonetarget = ''path =''alist =[]def init(): global target_path, target,path,nodes target_path = show_dir() path = os.path.dirname(target_path) alist = imagelist(path) show_image() returndef show_image(): global target_path, target,path if target_path is None: return if os.path.exists(target_path): target = os.path.basename(target_path) img = 'file://' + target_path droid.fullSetProperty("imageView","src",img) else: droid.makeToast('Error: %s not exists',path) returndef imagelist(path): global alist nodes = sorted(os.listdir(path)) alist =[] for f in nodes: if os.path.splitext(f)[1].lower() in ('.jpg','.png'): alist.append(f) returndef back(): global target_path,target, alist j = None for i in range(0,len(alist)): if alist[i]==target: j=i break if j is None: return if j >0: target = alist[j-1] target_path = os.path.join(path, target) show_image() else: droid.makeToast('this is begin image') returndef next(): global target_path,target, alist j = None len1 = len(alist) for i in range(0,len1): if alist[i]==target: j=i break if j is None: return if j < len1-1: target = alist[j+1] target_path = os.path.join(path, target) show_image() else: droid.makeToast('this is end image') returndef sensor(): droid.startSensingTimed(1, 250) s4 = droid.sensorsReadAccelerometer().result x,y,z =s4 if x<1.0 and y>3.0 : droid.makeToast('portrait 纵向 ') if x>3.0 and y<1.0 : droid.makeToast('landscape 横向 ') if x<1.0 and y<1.0 : droid.makeToast('horizontal 水平') returndef eventloop(): while True: event=droid.eventWait().result if event["name"]=="click": id=event["data"]["id"] if id=="image": init() if id=="next": next() if id=="back": back() if id=="sensor": sensor() if id=="Exit": return elif event["name"]=="screen": if event["data"]=="destroy": returnlayout = """<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/background" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ff000000"> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/Exit" android:layout_width="60dp" android:layout_height="wrap_content" android:text="退出" /> <Button android:id="@+id/back" android:layout_width="60dp" android:layout_height="wrap_content" android:text="《" /> <Button android:id="@+id/image" android:layout_width="60dp" android:layout_height="wrap_content" android:text="图片" /> <Button android:id="@+id/next" android:layout_width="60dp" android:layout_height="wrap_content" android:text="》" /> <Button android:id="@+id/sensor" android:layout_width="60dp" android:layout_height="wrap_content" android:text="目" /> </LinearLayout> <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:adjustViewBounds="true" /></LinearLayout>"""droid.fullShow(layout)eventloop()droid.fullDismiss()
0 0
- python for android : 显示图片
- python for android : geocode 显示地图
- OpenCV for Python [1].图片读入、显示、保存
- OpenCV for Python [2]使用Matplotlib显示图片
- osg for android 学习之十五:显示图片
- python显示图片
- Python中显示图片
- python显示图片
- python PNG图片显示
- openCV for python 学习(一):环境搭建与图片显示
- mono for android 图片
- Android显示在线图片
- Android ListView显示图片
- android 显示gif图片
- Android显示在线图片
- Android 网络图片显示
- Android 显示图片
- android 图片缩略图显示
- 设置nginx让baidu,google等爬虫抓取不同语言的页面
- 云存储-Google的云存储技术细节 GFS
- linux 下 ifcfg-eth0 配置
- Clojure专题:文件处理
- 《java编程思想系列之7》 内部类
- python for android : 显示图片
- Linux中ifcfg-eth0配置参数说明
- 射线与平面的相交检测(Ray-Plane intersection test)
- 第一周工作心情
- bzoj1041题解
- Android内核详解之Low memory killer
- Java关于String十个问题
- (转)在endnote中制作GB/T7714《文后参考文献著录规则》的输出格式
- *bzoj1083题解