first commit
This commit is contained in:
commit
417e54da96
5696 changed files with 900003 additions and 0 deletions
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
title=Compass
|
||||
author=Nik Klever
|
||||
orientation=portrait
|
25
kivy_venv/share/kivy-examples/android/compass/compass.kv
Normal file
25
kivy_venv/share/kivy-examples/android/compass/compass.kv
Normal file
|
@ -0,0 +1,25 @@
|
|||
#:kivy 1.7.0
|
||||
|
||||
FloatLayout:
|
||||
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .98, .98, .98
|
||||
Rectangle:
|
||||
size: self.size
|
||||
|
||||
Image:
|
||||
source: 'rose.png'
|
||||
|
||||
Image:
|
||||
source: 'needle.png'
|
||||
|
||||
canvas.before:
|
||||
PushMatrix
|
||||
Rotate:
|
||||
angle: app.needle_angle
|
||||
axis: 0, 0, 1
|
||||
origin: self.center
|
||||
|
||||
canvas.after:
|
||||
PopMatrix
|
77
kivy_venv/share/kivy-examples/android/compass/main.py
Normal file
77
kivy_venv/share/kivy-examples/android/compass/main.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
'''
|
||||
Compass example
|
||||
===============
|
||||
|
||||
This example is a demonstration of Hardware class usage.
|
||||
But it has severals drawbacks, like using only the magnetic sensor, and
|
||||
extrapolating values to get the orientation. The compass is absolutely not
|
||||
accurate.
|
||||
|
||||
The right way would be to get the accelerometer + magnetic, and computer
|
||||
everything according to the phone orientation. This is not the purpose of this
|
||||
example right now.
|
||||
|
||||
You can compile it with::
|
||||
|
||||
./build.py --package org.test.compass --name compass \
|
||||
--private ~/code/kivy/examples/android/compass \
|
||||
--window --version 1.0 debug installd
|
||||
'''
|
||||
|
||||
|
||||
import kivy
|
||||
kivy.require('1.7.0')
|
||||
|
||||
from jnius import autoclass
|
||||
from math import floor
|
||||
from kivy.app import App
|
||||
from kivy.properties import NumericProperty
|
||||
from kivy.clock import Clock
|
||||
from kivy.vector import Vector
|
||||
from kivy.animation import Animation
|
||||
|
||||
Hardware = autoclass('org.renpy.android.Hardware')
|
||||
|
||||
|
||||
class CompassApp(App):
|
||||
|
||||
needle_angle = NumericProperty(0)
|
||||
|
||||
def build(self):
|
||||
self._anim = None
|
||||
Hardware.magneticFieldSensorEnable(True)
|
||||
Clock.schedule_interval(self.update_compass, 1 / 10.)
|
||||
|
||||
def update_compass(self, *args):
|
||||
# read the magnetic sensor from the Hardware class
|
||||
(x, y, z) = Hardware.magneticFieldSensorReading()
|
||||
|
||||
# calculate the angle
|
||||
needle_angle = Vector(x, y).angle((0, 1)) + 90.
|
||||
|
||||
# fix animation transition around the unit circle
|
||||
if (self.needle_angle % 360) - needle_angle > 180:
|
||||
needle_angle += 360
|
||||
elif (self.needle_angle % 360) - needle_angle < -180:
|
||||
needle_angle -= 360
|
||||
# add the number of revolutions to the result
|
||||
needle_angle += 360 * floor(self.needle_angle / 360.)
|
||||
|
||||
# animate the needle
|
||||
if self._anim:
|
||||
self._anim.stop(self)
|
||||
self._anim = Animation(needle_angle=needle_angle, d=.2, t='out_quad')
|
||||
self._anim.start(self)
|
||||
|
||||
def on_pause(self):
|
||||
# when you are going on pause, don't forget to stop the sensor
|
||||
Hardware.magneticFieldSensorEnable(False)
|
||||
return True
|
||||
|
||||
def on_resume(self):
|
||||
# reactivate the sensor when you are back to the app
|
||||
Hardware.magneticFieldSensorEnable(True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
CompassApp().run()
|
BIN
kivy_venv/share/kivy-examples/android/compass/needle.png
Normal file
BIN
kivy_venv/share/kivy-examples/android/compass/needle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
BIN
kivy_venv/share/kivy-examples/android/compass/rose.png
Normal file
BIN
kivy_venv/share/kivy-examples/android/compass/rose.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
title=TakePicture
|
||||
author=Mathieu Virbel
|
||||
orientation=portrait
|
80
kivy_venv/share/kivy-examples/android/takepicture/main.py
Normal file
80
kivy_venv/share/kivy-examples/android/takepicture/main.py
Normal file
|
@ -0,0 +1,80 @@
|
|||
'''
|
||||
Take picture
|
||||
============
|
||||
|
||||
.. author:: Mathieu Virbel <mat@kivy.org>
|
||||
|
||||
Little example to demonstrate how to start an Intent, and get the result.
|
||||
When you use the Android.startActivityForResult(), the result will be
|
||||
dispatched into onActivityResult. You can catch the event with the
|
||||
android.activity API from python-for-android project.
|
||||
|
||||
If you want to compile it, don't forget to add the CAMERA permission::
|
||||
|
||||
./build.py --name 'TakePicture' --package org.test.takepicture \
|
||||
--permission CAMERA --version 1 \
|
||||
--private ~/code/kivy/examples/android/takepicture \
|
||||
debug installd
|
||||
|
||||
'''
|
||||
|
||||
__version__ = '0.1'
|
||||
|
||||
from kivy.app import App
|
||||
from os.path import exists
|
||||
from jnius import autoclass, cast
|
||||
from android import activity, mActivity
|
||||
from functools import partial
|
||||
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')
|
||||
MediaStore = autoclass('android.provider.MediaStore')
|
||||
Uri = autoclass('android.net.Uri')
|
||||
Environment = autoclass('android.os.Environment')
|
||||
|
||||
|
||||
class Picture(Scatter):
|
||||
source = StringProperty(None)
|
||||
|
||||
|
||||
class TakePictureApp(App):
|
||||
def build(self):
|
||||
self.index = 0
|
||||
activity.bind(on_activity_result=self.on_activity_result)
|
||||
|
||||
def get_filename(self):
|
||||
while True:
|
||||
self.index += 1
|
||||
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)
|
||||
self.last_fn = self.get_filename()
|
||||
self.uri = Uri.parse('file://' + self.last_fn)
|
||||
self.uri = cast('android.os.Parcelable', self.uri)
|
||||
intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
|
||||
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()
|
BIN
kivy_venv/share/kivy-examples/android/takepicture/shadow32.png
Normal file
BIN
kivy_venv/share/kivy-examples/android/takepicture/shadow32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
|
@ -0,0 +1,40 @@
|
|||
#:kivy 1.0
|
||||
#:import win kivy.core.window
|
||||
|
||||
Widget:
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .85, .87, .88
|
||||
Rectangle:
|
||||
size: self.size
|
||||
|
||||
Button:
|
||||
text: 'Take a picture'
|
||||
width: self.texture_size[0] + dp(40)
|
||||
height: '48dp'
|
||||
on_release: app.take_picture()
|
||||
|
||||
<Picture>:
|
||||
on_size: self.center = win.Window.center
|
||||
size: image.size
|
||||
size_hint: None, None
|
||||
|
||||
Image:
|
||||
id: image
|
||||
source: root.source
|
||||
|
||||
# create initial image to be 400 pixels width
|
||||
size: 400, 400
|
||||
|
||||
# add shadow background
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: 1, 1, 1, 1
|
||||
BorderImage:
|
||||
source: 'shadow32.png'
|
||||
border: (36, 36, 36, 36)
|
||||
size:(self.width + 72, self.height + 72)
|
||||
pos: (-36, -36)
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue