Notepad: inserting timestamp and data read from QR Code

961 views
Skip to first unread message

Isaac Potoczny-Jones

unread,
Apr 27, 2009, 10:43:28 PM4/27/09
to openi...@googlegroups.com
Greetings,

I've added a couple of features to OI Notepad that I wanted some
feedback on. I can commit these to svn if desired.

The first is a timestamp insertion. While editing a note, the user can
get a menu item "Insert timestamp" which inserts the give date & time at
the current point. I know that I would find this extremely useful; I
take a lot of notes in meetings using OI Notepad, and I usually want the
top line to read, "Meeting with joe about foo april 27, 2009".

The second feature is somewhat similar in that it inserts text at a
given point, but it does so by calling out to zxing. zxing is a QR Code
reader & generator. For those who don't know, QR codes are two
dimensional barcodes which encode a certain amount of data, including
plain text. With this feature, a user can scan a QR code, and the
scanned text will be inserted into the note at the given point. This
can be used to give someone a copy of a note, share bookmarks, contact
data, or to pass notes in class, for instance :)

I haven't added a "share note" feature, although that isn't hard. It
should probably be part of the "send" function?

I'm not positive about how good my "insert at point" function is. It
adds a string to the given point, but does so by adding it to the
database. I wanted to just add it to mText, but that didn't get updated
when returning from the QR code intent. Check out my function and let
me know how it looks.

If these features are of interest, I can commit my code and you can hack
at it directly :)

peace,

isaac

private void insertAtPoint (String textToInsert) {

String originalText = mText.getText().toString();
int insertPos = mText.getSelectionStart();
ContentValues values = new ContentValues();
StringBuffer sb = new StringBuffer(originalText);
sb.insert(insertPos, textToInsert);

// This stuff is only done when working with a full-fledged note.
if (!mNoteOnly) {
// Bump the modification time to now.
values.put(Notes.MODIFIED_DATE, System.currentTimeMillis());

String title = ExtractTitle.extractTitle(originalText);
values.put(Notes.TITLE, title);
}

// Write our text back into the provider.
String newNote = sb.toString();
values.put(Notes.NOTE, newNote);

// Commit all of our changes to persistent storage. When the
update completes
// the content provider will notify the cursor of the change,
which will
// cause the UI to be updated.
getContentResolver().update(mUri, values, null, null);
//ijones: notification doesn't seem to trigger for some reason :(
mText.setTextKeepState(newNote);
}


Peli

unread,
Apr 28, 2009, 7:29:30 AM4/28/09
to OpenIntents
Hi Isaac,

Great idea! Thanks for your contribution! Actually, your functions
sound like perfect candidates for "extensions".

This would mean a bit more coding effort now, but it could prevent
feature creep ( http://en.wikipedia.org/wiki/Creeping_featurism ) in
the long run. People simply install those extensions they really want
and need.

What is required:
* An extension, similar to the recent "Delete All" extension (
http://groups.google.com/group/openintents/browse_frm/thread/f69697a95e3d923
) which is a menu extension to the current note.
* A new intent should be created in OI Notepad. The intent should be
something like ACTION_INSERT_AT_CURRENT_POSITION (*).
* The extension is launched, and can return an EXTRA_TEXT with
whatever should be inserted, e.g. time stamp or QR code.
* OI Notepad in onActiviyResult reads the EXTRA_TEXT for that action,
and inserts the text.

This would pave the way for many more similar extensions, where
something can be inserted at the current position, e.g. contact
details (pick from contacts), song title (pick from media store),
bookmarks, etc...

(*) Wait: Maybe it is better to have arbitrary actions (like
ACTION_GET_QR_CODE or ACTION_GET_CURRENT_TIMESTAMP), but with special
category CATEGORY_INSERT_AT_CURRENT_POSITION. OI Notepad would know by
this category, that an EXTRA_TEXT is to be expected that should be
inserted at the current position.

The actions could be used in other applications as well (e.g. shopping
list).

Peli

On Apr 28, 4:43 am, Isaac Potoczny-Jones <isaac.jo...@gmail.com>
wrote:

Peli

unread,
Apr 28, 2009, 7:48:10 AM4/28/09
to OpenIntents
Hm, the category could be called:
CATEGORY_ALTERNATIVE_SELECTION

and this would mean an alternative action that can be performed on the
current selection (or cursor position if nothing is selected).

This would enable extensions, where one selects some text, this text
is passed to the extension, modified, and returned, and replaced.

E.g.
* ACTION_CHANGE_CASE: Change selection from "hello" to "HELLO" or the
other way.
* ACTION_THESAURUS: Open online thesaurus based on current selection,
and replace result upon return.
* ACTION_SEARCH: Online search based on selection. Does not modify
anything.

This could apply to any EditText, in fact, and in a sense, CUT, COPY,
and PASTE could be seen as being nice examples of what could be
implemented using the CATEGORY_ALTERNATIVE_SELECTION.

I'm sure there are many other use cases possible with this. I'd say,
it would be worth the effort :-)

Peli

On Apr 28, 1:29 pm, Peli <peli0...@googlemail.com> wrote:
> Hi Isaac,
>
> Great idea! Thanks for your contribution! Actually, your functions
> sound like perfect candidates for "extensions".
>
> This would mean a bit more coding effort now, but it could prevent
> feature creep (http://en.wikipedia.org/wiki/Creeping_featurism) in
> the long run. People simply install those extensions they really want
> and need.
>
> What is required:
> * An extension, similar to the recent "Delete All" extension (http://groups.google.com/group/openintents/browse_frm/thread/f69697a9...

Peli

unread,
Apr 28, 2009, 7:56:25 AM4/28/09
to OpenIntents
Probably even better:
CATEGORY_TEXT_SELECTION_ALTERNATIVE
to differentiate it better from
CATEGORY_SELECTED_ALTERNATIVE
which applies to selected items of a list.

Peli

Isaac Potoczny-Jones

unread,
Apr 29, 2009, 12:30:39 AM4/29/09
to openi...@googlegroups.com
Hi Peli & others,

I see this will take some more work to implement :) I don't know how
soon I can get to doing so, I will definitely try it out; I love
extensions systems.

I just added "share barcode", which allows you to display the text in
the current note as a barcode and someone with OI Notepad (or another qr
code reader) can then scan it in.

If you want to check out the notepad application with scan & display
barcode functionality, it's here:

http://syntaxpolice.org/tmp/NotePad.apk

Of course, you'll need two phones or a phone and an emulator to try it.

peace,

isaac

Friedger (OpenIntents)

unread,
Apr 29, 2009, 3:23:17 AM4/29/09
to openi...@googlegroups.com
Issac,

What have you used to create the bar code? I have done a small app
that does a similar thing. I used barbecue (net.sourceforge.barbecue).
The idea was to store all the customer cards on the phone (to get more
space in the wallet). However, the scanners of supermarket don't like
the reflection on the screen :-(

Friedger

2009/4/29 Isaac Potoczny-Jones <isaac...@gmail.com>:

Isaac Potoczny-Jones

unread,
Apr 29, 2009, 9:21:06 AM4/29/09
to openi...@googlegroups.com
Friedger (OpenIntents) wrote:
> Issac,
>
> What have you used to create the bar code? I have done a small app
> that does a similar thing. I used barbecue (net.sourceforge.barbecue).
> The idea was to store all the customer cards on the phone (to get more
> space in the wallet). However, the scanners of supermarket don't like
> the reflection on the screen :-(

It uses zxing, an open source qr code generator. Called "Barcode
Scanner" in the market. (Does it all via intents.)

peace,

isaac

Isaac Potoczny-Jones

unread,
May 3, 2009, 12:56:26 AM5/3/09
to openi...@googlegroups.com
I still haven't gotten around to implementing this as an extension, but
I did write up a description of this functionality in a little blog entry:

http://animate-innovations.com/?q=content/integrating-qr-codes-android-app-zxing

peace,

isaac

Peli

unread,
May 4, 2009, 4:39:06 AM5/4/09
to OpenIntents
Hi Isaac,

Thanks for the inspiring write-up. I quickly implemented the necessary
enhancement in OI Notepad so that arbitrary extensions can be easily
created independently.

For demonstration, the extension OI Insert date inserts the current
date:
http://code.google.com/p/openintents/source/browse/#svn/trunk/extensions/InsertDate

I've written another extension in literally 10 minutes: OI ROT13
simply encrypts the selected text:
http://code.google.com/p/openintents/source/browse/#svn/trunk/extensions/ROT13

All one needs to do to have a new extension appear is to add the
following intent filter to the Manifest:
<activity android:name=".ROT13Activity"
android:label="@string/rot13"
android:theme="@android:style/
Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="org.openintents.action.ROT13" />
<category
android:name="org.openintents.category.TEXT_SELECTION_ALTERNATIVE" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

The android:theme is used so that the blank activity does not flash
black, but stays silent.
The category TEXT_SELECTION_ALTERNATIVE says that this activity
handles text selections (and thus can be found and included by OI
Notepad).
I had to add the mimeType "text/plain", otherwise the intent filtering
did not work.

The selected text is passed in EXTRA_TEXT.
For extensions that need to know about the context of the selection,
also EXTRA_TEXT_BEFORE_SELECTION and EXTRA_TEXT_AFTER_SELECTION are
passed as well.

In this case, these additional extras are used to select all, if
EXTRA_TEXT is empty (i.e. the user had not selected anything).

With this in place, it should be easy to implement the QR Code to work
on the current selection (or all text if nothing is selected), just
like ROT13.

In fact, it should be so simple that it could almost be included in
the ZXing library itself as an additional intent that the library can
handle :-)

There are many more ideas for extensions that immediately come to my
mind:
* OI Reverse (reverse the letters)
* OI Case (show dialog "to UPPER", "to lower", ...)
* OI Calculate (calculate simple things, like "1+1")
* ...

This really opens so many possibilities in a simple way :-) Thanks
Isaac, for your initial suggestion :-)

Peli

On 3 Mai, 06:56, Isaac Potoczny-Jones <isaac.jo...@gmail.com> wrote:
> I still haven't gotten around to implementing this as an extension, but
> I did write up a description of this functionality in a little blog entry:
>
> http://animate-innovations.com/?q=content/integrating-qr-codes-androi...
>
> peace,
>
>    isaac
Reply all
Reply to author
Forward
0 new messages