James Baca

Views and Animation Tips

by James Baca on Apr.12, 2012, under Android

I was working on some animations today and had a few problems. The first was an interesting scenario where I needed to get the height of an item that wasn’t going to be displayed when the screen first loaded. The problem was that any time I called the getHeight method I always got zero returned to me. After some hunting on the Stack Overflow I came across this post. Sure enough the accepted answer worked. I was able to get the height as soon as layout was called. I then removed the listener and and set the view to gone.

The second problem I ran into was the animation wasn’t very smooth. A simple call to setDrawingCacheEnabled( true ); on the animated view helped. There was one strange thing though. After the view was done animating it would jump around it bit. Very not cool! After some more researching I found that you need to clear the animation from the view when the animation is over. You can do this by setting an animation listener. The animation listener has three method that get called. The two that I have found most useful are onStartAnimation and onEndAnimation.

Leave a Comment : more...

JS.LA Thumbnails from Videos using JS and HTML5

by James Baca on Apr.07, 2012, under Uncategorized

I was giving a lightning talk at the last JS.LA meetup. I was going to demo how to take a screen shot from a very clip. Unfortunately there was no audio so I didn’t get to show the Very Mary Kate presentation clip. The presentation was going specifically cover how to get a thumbnail from a video in html5 using javascript. The slides and demo/source code are available here. Make sure to check out my previous post about security exceptions when trying to take a screen shot.

Leave a Comment :, more...

SECURITY_ERR; DOM Exception 18

by James Baca on Apr.04, 2012, under Uncategorized

I was working with HTML5 and Javascript when I started getting this error from calling toDataURL on a canvas object. Turns out that browsers aren’t supposed to let you convert a movie to an image if the movie is considered dirty[source]. Movies are considered origin-dirty if they are coming from another server. For example this is origin-dirty:
<video>
<source src="http://someotheraddress.com/video.mp4" type="video/mp4">
</video>

This is origin-clean:
<video>
<source src="blog.jamesbaca.net/video.mp4" type="video/mp4">
</video>

Leave a Comment :, more...

ViewServer

by James Baca on Mar.25, 2012, under Android

So the other day I was working on a project. I looked at the xml and thought that it could use some refactoring. I went to use the hierarchyviewer in the android sdk. Unfortunately the tool wasn’t working with my phone. Turns out that it doesn’t work with production phones! You need root for it to work. Fortunately there is a project that allows even productions phones to work without needing root. It can be found here. I like hierarchyviewer’s easy to use interface. Each view is a node in the view. Each node has three circle indicators for Measure, Layout, and Draw methods in a view. The circles are colored green, yellow, and red to indicate speed. If you think a layout is slow you can at a high level go look for the red nodes. The red nodes give you a hint that their container View may be the culprit. After refactoring I was able to make my view load about 25% faster.

Leave a Comment : more...

Force dialog to take up full screen width

by James Baca on Dec.14, 2011, under Android

So I ran into a problem with getting dialogs to take up the full screen. The resource view I was using already specified fill_parent for the width. Fortunately I was able to find this. The problem is that by default dialog set’s it’s width to wrap_content. This was frustrating because on my thunderbolt it was not exhibiting this behavior. The solution I found that works is as follows:
// skip over the creation of dialog
Dialog lDialog = ...
WindowManager.LayoutParams lWindowParams = new WindowManager.LayoutParams();
lWindowParams.copyFrom(getDialog().getWindow().getAttributes());
lWindowParams.width = WindowManager.LayoutParams.FILL_PARENT; // this is where the magic happens
lWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
lDialog.show();// I was told to call show first I am not sure if this it to cause layout to happen so that we can override width?
lDialog.getWindow().setAttributes(lWindowParams);

Leave a Comment :, , , , more...

Copying Intent Data

by James Baca on Nov.23, 2011, under Android, Uncategorized

There is some confusion from an earlier tutorial I wrote about using urban airships push notifications. On one of the steps I have a function call to copyIntentData. This is a method I wrote. I glossed over it because I was focusing on urban airship configuration and felt that this topic fell outside the scope of tutorial. I have had a few questions posted about what this function entails. This function is very similar to code found on urbanairship’s documentation for logging data found in the intent. Here is the code enjoy!

	/**
	 * Method copies the intent extras from the received intent to the intent
	 * that will be dispatched.
	 *
	 * @param aReceived
	 * @param aDispatch
	 */
	private void copyIntentData(Intent aReceived, Intent aDispatch) {
		Set lKeys = aReceived.getExtras().keySet();
		List lIgnoredKeys = (List) Arrays.asList(
				"collapse_key",// c2dm collapse key
				"from",// c2dm sender
				PushManager.EXTRA_NOTIFICATION_ID,// int id of generated
													// notification
													// (ACTION_PUSH_RECEIVED
													// only)
				PushManager.EXTRA_PUSH_ID);// internal UA push id

		for (String lKey : lKeys) {

			// we don't need to copy all of the details
			if (lIgnoredKeys.contains(lKey)) {
				continue;
			}

			// the actual copy part
			aDispatch.putExtra(lKey, aReceived.getStringExtra(lKey));
		}
	}
Leave a Comment :, more...

Custom Button States

by James Baca on Oct.01, 2011, under Android

I wanted to make a ImageButton to appear differently depending on a variable. The ImageButton would behave more like a checkbox. I know that there are other options such as subclassing the CheckBox or ToggleButton. This was more of a curiosity.

My use case was I had a loop button that I wanted to display a different image when it was active.
Image of Inactive Button StateIImage of Active Button State
(continue reading…)

Leave a Comment :, , more...

Hide filter popup

by James Baca on Sep.14, 2011, under Android

Filtering a ListView is easy. However, there is popup text that comes with it:

I couldn’t find reference to getting rid of this popup text. I had to do some exploring to come up with the following:

The code for that is:
Filter lFilter = mDataAdapter.getFilter();
lFilter.filter("Item to filter for");

Also to clear the filter:
Filter lFilter = mDataAdapter.getFilter();
lFilter.filter("");

Unfiltered ListView:

Standard Filtered ListView:

No Text Filtered ListView:

Leave a Comment : more...

Up, up, and away with Urban Airship

by James Baca on Aug.23, 2011, under Android

Airship illustration by Alan Gutierrez

© Alan Gutierrez

Update

I have gotten a lot of feedback from this post. I am a freelance Android developer. If you get stuck or simply don’t want the headache of configuring push notifications. I can be hired.

Forward

This tutorial is for using Urban Airship’s Android push notifications service. They offer two different methods for enabling push notifications. One via their in house helium service, and the other using Google’s Cloud to Device Messaging(C2DM) framework. This tutorial will focus on the Cloud to Device Messaging.
(continue reading…)

9 Comments :, , , more...

Sample Code For Sending an Android Push Notification from PHP via Urban Airship

by James Baca on Aug.23, 2011, under Android

Update:
Sorry there is some confusion about what variables need to be changed in order for this script to work.
The only values that need to be changed are:

  • $dictionary['apids'] = array(…)
  • $username
  • $password

Obtaining an apid is explained on step 9 of this page. The $username is the application key from the details page for the urban airship apps page. The password is the Application Master Secret from the same page. See below for details.

Screenshot showing where to find $username and $password values

Where to find the $username and $password values


(continue reading…)

7 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

 

May 2012
M T W T F S S
« Apr    
 123456
78910111213
14151617181920
21222324252627
28293031