Hi, I'm Brett and I make stuff

31 Mar

Date Picker in Android – Month 0?

So I’m working on a new Android app and was having a small problem with the Date Picker widget. My datepicker.getMonth() kept returning incorrectly. What was the problem? The month is zero-based.

http://developer.android.com/reference/android/widget/DatePicker.html#getMonth()

“year — The initial year.
monthOfYear — The initial month starting from zero.
dayOfMonth — The initial day of the month.”

So for my application, I have to call getMonth()+1 every time. I thought this was odd, but I found a comment on Stack Overflow that pointed out that if you had an array of months, you’d want the array value to match up with the month. Interesting

http://stackoverflow.com/questions/4467816/datepicker-shows-wrong-value-of-month

0 Comments

05 Oct

Android Python Timelapse

So It’s been a little while since I messed around with android scripting, but I just finished a fun script that someone may find useful. I created a small timelapse script that allows the user to choose the interval and the folder where it will save the pictures (on the sdcard).

Choose the interval to take pictures, in minutes. Default choices are 1, 5, 10, 30, 60 minute intervals, or choose custom and enter your own value

Choose the folder in which to save the pictures

Let it do its thing!

You can grab the file here: timelapse.py or copy and paste the code below:

import android, time, os

droid = android.Android()

def titleAlert():
  title = 'Android Python Timelapse'
  message = 'Welcome to Android Python Timelapse.  In the following dialogs, you will be asked to choose your interval and the location where you would like your pictures saved.  Enjoy! Questions or comments? Please send to Support@SubmergedSpaceman.com'
  droid.dialogCreateAlert(title, message)
  droid.dialogSetPositiveButtonText('Continue')
  droid.dialogShow()
  response = droid.dialogGetResponse().result
  return response['which'] == 'positive'  

def chooseInterval():
  title = 'Please choose your picture interval in minutes.  To use a different value, choose Custom'
  droid.dialogCreateAlert(title)
  droid.dialogSetItems(['1', '5', '10','30','60','Custom'])
  droid.dialogShow()
  response = droid.dialogGetResponse().result['item']

  if response == 0:
    timer = 1
  elif response == 1:  
    timer = 5
  elif response == 2:  
    timer = 10
  elif response == 3:  
    timer = 30
  elif response == 4:  
    timer = 60
  elif response == 5:  
    timer = droid.dialogGetInput("please enter your interval in minutes").result
    timer = float(timer)
  print "interval is: "+str(timer) +" minutes"
  return timer

def chooseFolder():
  title = 'Please choose where you would like to store your pictures'
  captureTime = time.strftime("%Y-%m-%d--%H-%M-%S", time.localtime())
  droid.dialogCreateAlert(title)
  droid.dialogSetItems(['/sdcard/YYYY-MM-DD', '/sdcard/timelapse', 'Custom'])
  droid.dialogShow()
  response = droid.dialogGetResponse().result['item']

  if response == 0:
    folderStr = captureTime
  elif response == 1:  
    folderStr = "timelapse"
  elif response == 2:  
    folderStr = droid.dialogGetInput("please enter the name of the folder you would like to create:   /sdcard/").result
 
  print "folder set to: /sdcard/"+folderStr
  return folderStr

def takePics(picfolder="timelapse", lapse=30):
  loopvar = 'true'

  while loopvar == 'true':
    captureTime = time.strftime("%Y-%m-%d--%H-%M-%S", time.localtime())
    captureLocation = '/sdcard/'+picFolder+"/"+str(captureTime)+'.jpg'
    print "picture taken: "+captureLocation
    droid.cameraCapturePicture(captureLocation,True)
    interval = lapse * 60
    time.sleep(interval)

titleAlert()
lapse = chooseInterval()
picFolder = chooseFolder()
os.system("mkdir /sdcard/"+picFolder)
takePics(picFolder,lapse)

And here is the video I made after letting the script run for about 4 days. There was some sort of opening ceremony happening by our apartment, but we were out of town for the weekend. Glad I got it all on film! (It’s pretty slow going at the start, skip to about 1:40 where things start to get going)

check out my other SL4A script:
http://www.submergedspaceman.com/blog/2010/02/16/android-scripting-environment-is-incredible-part-i/

And my new cell stand in the shop!
http://www.submergedspaceman.com/blog/2010/09/25/universal-cellphone-stand/
(you can get it from Ponoko or Etsy from that link as well)

2Comments

25 Sep

Universal Cellphone Stand

stand with phone
Hello! I’ve just added a new page on my site; the shop! My first product is one I recently created using the great laser cutting website Ponoko.com. It’s a stand for phones. I thought about it a while ago and decided to try out the Ponoko service. everything worked great! Check it out here at Ponoko.com or on Etsy.com here You can purchase it right at my shop or either of those websites (they all use paypal, so it’s the same to me) Go get one!

3Comments

17 Aug

GeekDad-Ponoko-Sparkfun Competition

bart DisplayHey Everyone! I’m a finalist in a competition on Wired’s GeekDad! The contest was to make something that could be laser printed at Ponoko (I highly recommend their service, by the way) and uses electronics from Sparkfun (also awesome). My entry is for a BART Display to show when the next trains are coming.

Check it out here and vote for me! GeekDad contest

0 Comments

03 Jun

30 Days of Creativity – Day3

Ok, the last post was from yesterday’s project. Today’s tiny project was to make the wallpaper into one for my Droid. I’ve never made one before. The first mistake was making it 480×854 pixel resolution, since that’s the size of the display. For Android phones, the wallpaper scrolls horizontally, so the actual dimensions needed to make a wallpaper for the Droid is 960×854. Got it! Screenshot of the wallpaper in action:
screen shot

Here’s the file if anyone wants it:
source file

1Comment

03 Jun

30 Days of Creativity – Day2

So I ran across the site http://30daysofcreativity.com/ just one day late! Basically, its a challenge to be creative everyday in the month of June. Unfortunately, this is also the same month we are moving! So I’ll be creative, but in small ways. To start things off, I’ve created a background for inspiration:

30daysofcreativity background

its 1920×1080 and please use it if you’d like! Let me know if you want a different size or color.

go CREATE!

0 Comments

05 Apr

Creating the Dashboard Part I: Concept

This is part one of my series of posts describing the Nokia N900 Contest I entered in the spring of 2010.
Read More

2Comments

27 Mar

PUSH N900 competition winners

Read More

5Comments

18 Mar

PUSH N900 Competition

Links and info about our participation in the Nokia PUSH N900 Competition
Read More

0 Comments

16 Feb

Android Scripting Environment is Incredible: part I

what_to-say

Update As Edward Pain pointed out, the latest version of ASE (soon to be SL4A) changed the TTS and the way that dictionaries are called. I’ve updated this script to take these into account. Thanks Ed!

So I’ve been loving having the DROID around.  I don’t even mind carrying a phone in each pocket because it’s totally worth it.  My most recent obsession is the Android Scripting Environment (ASE)

Basically, it allows you to write code in high-level languages like python, bash, perl, etc, right on the device.  This is when a physical keyboard is really handy.  So I downloaded the app and started messing around with the included python scripts.  I’ve never coded anything in python before, but I have programmed in a bunch of other languages, so it really wasn’t hard at all.  By far the coolest pre-installed script was the Text-To-Speech (TTS) example.  I’m not sure what it is about making computers/devices say funny stuff that makes me laugh so much, but its really fun.

I soon noticed as I was cracking myself up over making the DROID say things like “Then I put my hands up, they’re playing my song” that I’d really like the option to repeat what it just said.  So I decided to code it.  Please be gentle on me; I do not profess to be an expert coder, I just hack stuff together till it works.  Any suggestions would be appreciated.

First thing I did was take the original code and wrap it in a while loop.  This will repeat the phrase as many times as I like, as long as the condition remains true:


"""Speak user generated text."""

__author__ = ' Brett Peterson <brettjpeterson@gmail.com>'

import android

droid = android.Android()

message = droid.getInput('TTS', 'What would you like to say?').result
droid.ttsSpeak(message)

repeat = droid.getInput('repeat', 'Repeat? Y/N').result
while repeat == "y":
  droid.ttsSpeak(message)
  repeat = droid.getInput('repeat', 'Repeat? Y/N').result

Read More

4Comments