Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some examples of python code for android - needs refactoring
- Loading branch information
0 parents
commit 648c4de
Showing
10 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
++++++++++++++++++++++++++++++++++++++++++++++++ | ||
pyandroid - some examples of python code for android | ||
++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
this are some sample code used to ilustrate python usage in android, shown during my talk. Needs A LOT of refectoring. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/> | ||
<title>Sorteio</title> | ||
<script type="text/javascript" language="javascript" charset="utf-8"> | ||
var droid = new Android(); | ||
var raffle = function() { | ||
droid.eventPost("raffle", document.getElementById("limit").value); | ||
}; | ||
</script> | ||
<style> | ||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
text-align: center; | ||
} | ||
|
||
h1 { | ||
font-size: 300%; | ||
text-shadow: 4px 4px 4px #888; | ||
margin: 20px 0; | ||
} | ||
|
||
label { | ||
display: block; | ||
} | ||
|
||
input[type="text"] { | ||
border-radius: 0.2em; | ||
font-size: 40px; | ||
margin: 10px 0 0 0; | ||
padding: 4px; | ||
text-align: center; | ||
width: 200px; | ||
} | ||
|
||
input[type="button"] { | ||
border: 1px solid #006B93; | ||
border-radius: 0.3em; | ||
color: #FFFFFF; | ||
height: 40px; | ||
font-size: 20px; | ||
font-weight: bold; | ||
background: #237ECD; | ||
width: 200px; | ||
} | ||
|
||
input[type="button"]:active { | ||
background-color: #FFFFFF; | ||
color: #006B93; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Sorteio</h1> | ||
<p><label for="limit">Número de inscritos</label> <input type="text" name="inscritos" value="200" id="limit"/></p> | ||
<p><input type="button" value="Sortear" onclick="raffle();" /></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import android | ||
from time import sleep | ||
|
||
droid = android.Android() | ||
|
||
def get_contacts: | ||
contactos = droid.queryContent('content://com.android.contacts/data/phones',\ | ||
['display_name','data1'],None,None,None).result | ||
|
||
#Se crean la lista nombres y telefonos | ||
nombres = [] | ||
telefonos = [] | ||
|
||
#Se agrega la informacion de los contactos a las listas. | ||
for i in range(len(contacts)): | ||
nombres.append(contacts[i][u'display_name']) | ||
telefonos.append(contacts[i][u'data1']) | ||
|
||
#Se despliega la lista de contactos | ||
droid.dialogCreateAlert("Contactos") | ||
droid.dialogSetItems(nombres) | ||
droid.dialogShow() | ||
|
||
#Se captura el resultado de la seleccion simple | ||
respuesta = droid.dialogGetResponse().result | ||
|
||
#Se muestra la informacion del contacto seleccionado | ||
droid.makeToast('El contacto seleccionado es: %s, su numero es: %s' | ||
%(nombres[respuesta['item']],telefonos[respuesta['item']])) | ||
sleep(5) | ||
droid.makeToast("Realizando la llamada") | ||
sleep(2) | ||
|
||
#Se realiza la llamada al contacto seleccioando. | ||
droid.phoneCallNumber("%s" %telefonos[respuesta['item']]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import android | ||
|
||
droid = android.Android() | ||
name = droid.dialogGetInput("Hello!", "What is your name?") | ||
droid.makeToast("Hello %s! Grat to see you in PyConAr" % name.result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import android | ||
from time import sleep | ||
|
||
droid = android.Android() | ||
droid.startLocating() | ||
sleep(15) | ||
latitud = droid.readLocation().result["network"]["latitude"] | ||
longitud = droid.readLocation().result["network"]["longitude"] | ||
droid.stopLocating() | ||
|
||
droid.webViewShow("http://maps.google.com/maps?q=%s,%s" % (latitud, longitud)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import android | ||
|
||
droid = android.Android() | ||
droid.cameraCapturePicture('/sdcard/pyconar.jpg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import android | ||
from time import sleep | ||
|
||
droid = android.Android() | ||
droid.startLocating() | ||
sleep(15) | ||
latitud = droid.readLocation().result["network"]["latitude"] | ||
longitud = droid.readLocation().result["network"]["longitude"] | ||
droid.stopLocating() | ||
|
||
#telefono = "1167916111" | ||
telefono = "1165272786" | ||
#telefono = droid.dialogGetInput(" GPS to SMS", "Phone number:") | ||
mensaje = "Estoy en http://maps.google.com/maps?q=%s,%s" % (latitud, longitud) | ||
droid.smsSend(telefono,mensaje) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import android | ||
from time import sleep | ||
|
||
droid = android.Android() | ||
droid.startLocating() | ||
sleep(15) | ||
latitud = droid.readLocation().result["network"]["latitude"] | ||
longitud = droid.readLocation().result["network"]["longitude"] | ||
droid.stopLocating() | ||
|
||
droid.webViewShow("http://maps.google.com/maps?q=%s,%s" % (latitud, longitud)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
import android | ||
import random | ||
|
||
class Raffler(object): | ||
|
||
def __init__(self, min, max): | ||
self.min = min | ||
self.max = max | ||
|
||
def raffle(self): | ||
return random.randint(self.min, self.max) | ||
|
||
def notify_raffled_number(droid, number): | ||
droid.dialogCreateAlert("Sorteio", "O número sorteado foi: %d!" % number) | ||
droid.dialogSetPositiveButtonText("Ok") | ||
droid.dialogShow() | ||
|
||
if __name__ == '__main__': | ||
droid = android.Android() | ||
droid.webViewShow('file:///sdcard/sl4a/scripts/html/home.html') | ||
while True: | ||
result = droid.eventWaitFor('raffle').result | ||
maximum = int(result['data']) | ||
number = Raffler(1, maximum).raffle() | ||
notify_raffled_number(droid, number) |