Recent Posts

Using SocialCam without all the Facebook Mess

Don't you hate it when a website forces you to use Facebook for everything? SocialCam is yet another example. Using the bookmarklet below, you don't have to use Facebook anymore!

SocialCam Freedom - drag me into your bookmark toolbar and click when on Facebook or SocialCam

What do I do?

Simply click it once when on your Facebook news feed and all links will now work without needing the SocialCam app!

Simply click it when on a SocialCam webpage to view any videos in the sidebar without needing to log in!

Yes Pandora, I'm still Listening

Are you tired of having Pandora stop and wait for you to click "I'm still Listening" button? Well, drag the button below into your bookmarks, and when you start Pandora, click on it. Then, you'll never see that button again!

I'm Still Listening - drag me into your bookmark toolbar and click when viewing Pandora

How's it Work?

When Pandora revamped their interface a while back, they moved to an HTML based display. With that, it allows Javascript to interact with the controls. This script simply checks once a second if the button is there. If it is, it clicks on it. That's it!

Technical details: Pandora includes jQuery for use, so this bookmarklet uses that. The button is selectable because it has the CSS classes still_listening, button, and btn_bg. I find anything that has all three of those buttons and click on it! Pretty simple.

Starting Activity from Sleeping Device

Permissions Required

In order to wake up the device, you need to request the WAKE_LOCK permission. To do that, add this XML snippet into your AndroidManifest.xml.

<uses-permission android:name="android.permission.WAKE_LOCK" />

Waking up the Activity Using a Wake Lock

NOTE: I'm modifying the code found in Android - Creating an Alarm with AlarmManager.

Add this to your AlarmReceiverActivity:

private PowerManager.WakeLock wl;
...
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
        wl.acquire();
       ...
       ... //The rest of the onCreate() is still the same (for now)
}

protected void onStop() {
    super.onStop();
    wl.release();
}

So, what we're doing here is requesting a WAKE_LOCK from the operating system. This lock is a lock on CPU and must be released. That's why (in this case), I release the lock in the onStop for the activity. Feel free to move it to somewhere else, but you must be sure it gets released.

Android - Creating an Alarm with AlarmManager

There isn't a lot of good write-ups on how to use the AlarmManager, so here is an example that launches an Activity using the AlarmManager.

What's the AlarmManager used for?

The AlarmManager is used to schedule events or services at either a set time or a set interval. It's Android's "version" of the cron. In this case, we're going to set an alarm for five seconds after the app is launched.

What we're going to build

In order to use build this simple app, we're going to create only two classes. One will be for the Main Activity, and one will be for the Activity we want to launch with the Alarm. We will also have two simple layouts for each of the activities.

Creating input fields that only accept integers - jQuery

Wouldn't it be nice to force only certain characters into a text field? How about for a field asking for age? You would only want integers. Same with height, weight, or even a phone number. Well, here's a quick snippet that'll do just that!


$(document).ready(function() {
$("#inputField").keypress(function(event) {
return /\d/.test(String.fromCharCode(event.keyCode));
});
});

So, what's happening here? Well, it adds a keypress event to the input field with id "inputField" (feel free to change to whatever you need). Whenever a key is pressed, this function is fired. If the function returns false, the key pressed is not added to the input field. If it returns true, it is added.

The function is given an Event object, and the keyCode value is a numeric value. The String.fromCharCode converts that to the actual character that the user inputted. It is then tested if that character was an integer, using a regular expression test. If it is not an integer, false is returned, and the character is not added to the field! Pretty simple, huh?