Skip to content

Instantly share code, notes, and snippets.

@blackmann
Created May 24, 2014 10:38
Show Gist options
  • Save blackmann/8c033c6243561f1cb84e to your computer and use it in GitHub Desktop.
Save blackmann/8c033c6243561f1cb84e to your computer and use it in GitHub Desktop.
A simple log-in app in python4android
#some simple login app
from android import Android
import time
import random
a = Android()
p=0
a.dialogCreateHorizontalProgress("Loading App")
a.dialogShow()
while p <= 100:
prog_bar= random.randrange(1,11)
a.dialogSetCurrentProgress(p)
time.sleep(0.2)
p+=prog_bar
print "Done loading!"
a.dialogDismiss()
print '-'*17
a.dialogCreateAlert("Lex", "Please Sign in")
a.dialogShow()
time.sleep(1.8)
a.dialogDismiss()
#sub challenge
data = {"lexis":"12345","degreat":"andex"}
tries = 3
while tries >= 0:
if tries == 0:
print "--Bye bye--"
break
a.dialogCreateInput("Enter username","username")
a.dialogSetPositiveButtonText("OK")
a.dialogShow()
user=a.dialogGetResponse().result
username = user["value"]
a.dialogCreatePassword()
a.dialogSetPositiveButtonText("OK")
a.dialogShow()
passw = a.dialogGetResponse().result
password = passw["value"]
if data.has_key(username):
if password == data[username]:
a.dialogCreateAlert("Logged")
a.dialogShow()
time.sleep(2)
a.dialogDismiss()
tries = -1
print "--Login success--"
else:
a.dialogueCreateAlert("Sorry! Try Again")
a.dialogShow()
time.sleep(2)
a.dialogDismiss()
tries-=1
else:
a.dialogCreateAlert("Sorry! Try Again")
a.dialogShow()
time.sleep(2)
a.dialogDismiss()
tries -= 1
#main challenge -- the media player
#quit
@blackmann
Copy link
Author

This program requires you to install sl4a(scripting layer for android) and py4a(python for android) on your android mobile. The users dictionary can be modified to read login credentials from a txt file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment