Merge pull request #2360 from jchome/patch-1

Propose of update to be runnable on Samsung S4
This commit is contained in:
Akshay Arora 2014-08-03 01:01:44 +05:30
commit 0a8176a14c
1 changed files with 11 additions and 3 deletions

View File

@ -29,11 +29,13 @@ from kivy.clock import Clock
from kivy.uix.scatter import Scatter
from kivy.properties import StringProperty
from PIL import Image
Intent = autoclass('android.content.Intent')
PythonActivity = autoclass('org.renpy.android.PythonActivity')
MediaStore = autoclass('android.provider.MediaStore')
Uri = autoclass('android.net.Uri')
Environment = autoclass('android.os.Environment')
class Picture(Scatter):
@ -46,11 +48,13 @@ class TakePictureApp(App):
activity.bind(on_activity_result=self.on_activity_result)
def get_filename(self):
#print( Environment.getExternalStorageDirectory().getPath() )
while True:
self.index += 1
fn = '/sdcard/takepicture{}.png'.format(self.index)
fn = Environment.getExternalStorageDirectory().getPath()+'/takepicture{}.jpg'.format(self.index)
if not exists(fn):
return fn
def take_picture(self):
intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
@ -59,16 +63,20 @@ class TakePictureApp(App):
self.uri = cast('android.os.Parcelable', self.uri)
intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
PythonActivity.mActivity.startActivityForResult(intent, 0x123)
def on_activity_result(self, requestCode, resultCode, intent):
if requestCode == 0x123:
Clock.schedule_once(partial(self.add_picture, self.last_fn), 0)
def add_picture(self, fn, *args):
im = Image.open(fn)
width, height = im.size
im.thumbnail( (width/4,height/4) , Image.ANTIALIAS)
im.save(fn,quality=95)
self.root.add_widget(Picture(source=fn, center=self.root.center))
def on_pause(self):
return True
TakePictureApp().run()