Android Phonegap Native Timepicker

So I’ve been working on a simple android app and I finally got audacious and started to move beyond the basics. I was able to get an app in the store with just my HTML/JS/CSS skills pretty easily which makes phonegap a big success.

Anyhow, now my latest fiasco was to try and use the native android timepicker and while I’ve still got a ways to go, I wanted to post my working code that I also put back on a discussion I had with myself on the google group.

FWIW here’s what I’ve got working.

A simple TimePicker class with a showTimePicker method.

public class TimePicker {
private DroidGap mGap;

public TimePicker(DroidGap gap)
{
mGap = gap;
}

public void showTimePicker(){
mGap.showDialog(HelloWorldPlugin.TIME_DIALOG_ID);
}
}

A custom TimePickerDialog.OnTimeSetListener which is initialized with
knowledge of DroidGap too…

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mGap.sendJavascript(” callback javascript goes here!”);
}

Initialize and add the createdialog stuff like the android dialog
tutorial.

TimePicker timepicker = new TimePicker(this, appView);
appView.addJavascriptInterface(timepicker, “TimePicker”);

Then in the javascript, once phonegap loads, you can refer to the
timepicker:

window.TimePicker.showTimePicker();

Hope that Saves Somebody else some time or inspires somebody to show
me the ways of the plugin framework.

 

As I get better at this stuff, I might end up understanding how to do it within the plugin architecture but for now that’s it.

Cheers.

Django RadioSelect | CheckboxSelectMultiple | SelectDateWidget Examples

In trying to use django built-in forms, I had the most trouble finding good examples of django radioselect, checkboxselectmultiple and selectdatewidget.

Here’s my attempt to help others looking into using Django RadioSelect, CheckboxSelectMultiple, or the SelectDateWidget.

Django RadioSelect Example


from django.forms.widgets import RadioSelect

RADIO_CHOICES = [['1','Radio 1'],['2','Radio 2']]

class SimpleForm(forms.Form):
radio = forms.ChoiceField( widget=RadioSelect(), choices=RADIO_CHOICES)

Django CheckboxSelectMultiple Example


from django.forms.widgets import CheckboxSelectMultiple

CHECKBOX_CHOICES = (('1','The first choice'),('2','The Second Choice'))

class SimpleForm(forms.Form):
checkboxes = forms.MultipleChoiceField( required=False, widget=CheckboxSelectMultiple(), choices=CHECKBOX_CHOICES)

Django SelectDateWidget Example


from django.forms.extras.widgets import SelectDateWidget

YEAR_CHOICES = ('2016','2015')
class SimpleForm(forms.Form):
date = forms.DateField(widget=SelectDateWidget(None,YEAR_CHOICES) )

Django Docs

Update 1/3/2016: The official documentation on these have improved but is still buried within a huge post. Here is the link to the latest stable docs: https://docs.djangoproject.com/en/stable/ref/forms/widgets/

I Love Django Forms

These are all excellent features and the more I use Django, the more I like it. Chalk up Forms as another part of django that blows away any other web framework I’ve worked with.

Mechanize vs. Scrape:

In the process of automating functional tests, I have ran across another python library, mechanize, that looks to be very promising. Perhaps, even more so than scrape.py?

http://wwwsearch.sourceforge.net/mechanize/
http://stockrt.github.com/p/emulating-a-browser-in-python-with-mechanize/

So far it seems that the mechanize platform is more powerful, as it is able to handle complex tasks like managing a gmail inbox( see http://libgmail.sourceforge.net/ ).

My take so far is that scrape.py offers some nice features for validating that a given page has the tags and elements I am looking for. I’m still new to both of these libraries so if anyone out there has experience with both and could help nudge me in the right direction, it would be much appreciated.

scrape.py for functional website testing

This solution is perfect for testing your website’s functional capabilities. Scrape.py supports sessions and cookies so hitting your authenticated resources is cake.

Here’s a quick sample i wrote to test things out:

from scrape import *
s.go(“http://www.google.com”)
s.follow(“Sign in”)
x = s.doc.first(‘form’)
params = x.get_params()
params[‘Email’]=’keithentzeroth’
params[‘Passwd’]=’xxxxxx’
s.submit(x,params)
s.go(“http://www.google.com”)
print s.doc

Try it out with your google account. To verify you’re logged in look for the Sign Out link or alternatively look for a GAUSR cookie in s.cookiejar.

Thanks to Ka-Ping himself for clearing up some of my confusion.

My plan is to use this to test the site as if there were no script/styles enabled. Then to layer on browser behavior ( AJAX etc…), I’ll look to Selenium or something of the kind.

Mac Screen Captures

It hasn’t been too long since I exclusively started using mac at home and work. I struggled at first to capture screenshots and I’m still catching on to some of the great little things Apple has thrown in here.

This morning’s enlightenment was around capturing screen shots, both full and partial, on my mac. I was reading a blogpost about apps to replace the Snapper add-on I used to use and the author dropped a subtle hint about shift+command+control+4.

With a little search engine power, I found a useful page from apple, http://www.apple.com/pro/tips/secretcapture.html.

Mac Screen Captures

Command+Shift+3 = Screenshot Saved To Desktop
Command+Shift+4 = CrossHairs For Snapping To Desktop
Shift+Command+Shift+3 ( or 4) = …. To Clipboard For Pasting to Photoshop/eMails etc…

How To Stop Unwanted Solicitation of your Browsing History

I’ve known for awhile that the css :visited property on elements can allow me or others to detect whether or not a certain link has been visited by the user on the other end of a browser.

What I didn’t realize is that the browsers have already done things to help us out. If you can forego the need for links you’ve already visited to change color or background, then the safest option is to turn off visited links. What The Internet Knows About You describes both the underlying issue and some of the possible preventative measures. My favorite…

Firefox 3.5 users will be happy to learn that their browser has a configuration option which disables visited links. To enable it, type in about:config in the address bar and set the layout.css.visited_links_enabled option to False.

I’d much rather remember which links i visit, than have to discard my browsing history and lose the awesome bar.

Appengine + Django 1.1

So i got past my previous post with a different cell phone number. Now I know getting an appengine account is a more difficult than most online accounts. It makes sense too given free website hosting is at stake.

Anyhow, after a short time i was able to get django 1.1 up and running on appengine. For a little clarity, this provides all the glory of django templates, urls.py, middleware, forms, settings. But because of the big table db implementation of appengine, the admin tool, auth, session, and anything else built-in and dependent on django models will not work.

I found some other blogs that were close, but none of the step by steps worked for me. I followed instructions found at goole python libraries – django.

Since i learn best from code, I checked a basic project into github that i’ll continue to update on git as i make updates.

Browse the code on git.

Django Web Framework

So i slammed my old XP machine with Ubuntu this weekend and set to go through the django tutorial.

I’d already had a little experience with django, but hadn’t gone through the basics as another team member had set up our project.

After going through the tutorial, http://docs.djangoproject.com/en/dev/intro/tutorial01, i am confident that the way django encompasses the business model in its use of models.py, maps urls in urls.py, and provides a free admin tool makes it the best “framework” for creating web sites quick and easy. Pair this framework with what is already known to be an easy language, python, and you’ve got a winner.

I’ve yet to use django/python on anything over a month project, so i can’t really comment on whether or not Cal Henderson’s, www.iamcal.com, statement that if you need to build a “serious” website than the advantages of using a framework like django will at some point come crashing down by the need to modify and adapt the framework for your specific usages.