Skip to content payday loans gallup new mexico
Jun 29 15

Preventing Elements from Being Included in GSON Produced JSON in Java

by Mike Chenault

There are two ways to handle these situations.

If you never want a vairable to be included in the JSON created by GSON then you can use the transient keyword:

private transient String variableName;

If you need to dynamically include and remove the element then just set the value of the variable to null.  A problem that many novice developers may run into is errors when attempting to set primitive types to null.  Primitive types in Java such as int or boolean cannot be set to null and will therefore always be included in the JSON created by GSON.  To get around this, for any elements you don’t want included, instead of using a primative use the primitive’s wrapper class.

Primitive type Wrapper class Constructor Arguments
byte Byte byte or String
short Short short or String
int Integer int or String
long Long long or String
float Float float, double or String
double Double double or String
char Character char
boolean Boolean boolean or String
*Table taken from Wikipedia here

Wrappers can be set to null so you can choose to include or exclude these elements from the JSON.

Mar 25 13

PHP Get variables in Javascript

by Mike Chenault

You can get the PHP get variables from javascript using the following function:

            function $_GET(variable) {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == variable) {
                        return unescape(pair[1]);
                    }
                }
                return false;
            }

This will grab variables in the url such as http://coutblog.com?getVariable=value

Mar 4 13

How to fix error while loading shared libraries: libassuan.so.0 when installing GNUPG

by Mike Chenault

I was trying to install GNU Privacy Gaurd and ran into this error on the make.

gnupg ../../g10/gpg2: error while loading shared libraries: libassuan.so.0: cannot open shared object file: No such file or directory

I was able to fix this by running the following command:

ldconfig -v

This may not work for everyone but I thought I would put this out there in case someone else runs into this issue.

Feb 20 13

How to safely unregister Android ContentObserver

by Mike Chenault

To save system resources ContentObservers need to be safely unregistered when no longer in use.  The best way to do this is the following.

try {
	getContentResolver().unregisterContentObserver(myContentObserver);
} catch (IllegalStateException ise) {
	// Do Nothing.  Observer has already been unregistered.
}

As of Android 4.1.2, there is no method to check whether the observer is registered or not.  Therefore we use the try-catch method to catch situations where the observer has already been unregistered.  This sub-routine will typically be included in the onDestroy() of an activity but can be called anywhere you need it.

Jan 30 13

Create Dojo Dialog in HTML

by Mike Chenault

You can create a dojo dialog in html code and using the javascript set when the dialog is shown as following.

 

First declare your dialog:

<div class=”dijitHidden”>
<div data-dojo-type=”dijit.Dialog” data-dojo-props=”title:’Dialog Title'” id=”dialogId”>
<div>
<p><b>This div holds the body of the dialog</b></p>
</div>

<button onclick=”dijit.byId(‘dialogId’).hide();”>Ok</button>
</div>
</div>

To show this dialog use the javascript code as such:

dijit.byId(‘contactAdminToCompleteSettingsDialog’).show();

Jan 30 12

Querying for Presence in Android

by Mike Chenault

Presence is saved in the Android database for each user.  There is a presence table which stores multiple presences and statuses for each user from each presence source, such as skype, jabber, and gTalk.  The presence is derived from some enumeration which would typically include states such as “availible,” “away,” and “do not disturb”.  The status is the message that the user can enter when setting their status, such as if one sets themselves to away on gTalk they might want to include the following message, “Out to lunch be right back.” Typically we only want the most recent of any presence provider.  Therefore we can query for the presence and the status associated with this user.  NOTE: The following code is for Android 3.0 and beyond.  For 2.x and below, use a managed cursor instead of the cursor loader.

presenceUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, Uri.encode(lookupKey));

String[] presenseProjection = {
Contacts.CONTACT_PRESENCE,
     Contacts.CONTACT_STATUS
};

cursorLoader = new CursorLoader(
     context,
     presenceUri,
     presenseProjection,
     null,
     null,
     null);

Cursor presenceCursor = cursorLoader.loadInBackground();

if(presenceCursor.moveToFirst()) {
     int presence = presenceCursor.getInt(presenceCursor.getColumnIndex(Contacts.CONTACT_PRESENCE));
     String status = presenceCursor.getString(presenceCursor.getColumnIndex(Contacts.CONTACT_STATUS));
}
presenceCursor.close();

If we want to react to a new presence we can register a ContentObserver on the database.  We should register on the database table instead of the cursor.  If we register on the cursor then the cursor must stay open and that takes up valuable resources and will potentially slow down your application.

ContentObserver statusObserver = new ContentObserver(new Handler()) {
			@Override
			public void onChange(boolean selfChange) {
				presenceCursor = cursorLoader.loadInBackground();
				// Do what you want with the cursor
			}
		};

		context.getContentResolver().registerContentObserver (presenceUri, true, statusObserver); 
Oct 13 11

Fragment Sample Code

by Mike Chenault

Tonight I will be giving a talk on Fragments at the Android Developers Meetup in Dallas.  Here is the sample code for the application I am demoing.  The zip includes the slides I will be speaking on.

FragmentSampleForMeetup

Thank you to all that attended.

Oct 12 11

Hide and show Fragments using a FragmentTransaction

by Mike Chenault

Fragment is a child of Object and not View so one cannot call:

fragment.setVisibility(View.INVISIBLE);

Instead we can use a FragmentTransaction to hide or show a fragment.

From the holder activity or a fragment:

FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.hide(myFrag);
ft.commit();

Note that multiple fragments can be hidden or shown before the commit by making multiple calls to ft.hide(…) or ft.show(…).

This flow will work with all the FragmentTransaction actions; add, remove, show, hide, attach, and detach.

http://developer.android.com/reference/android/app/FragmentTransaction.html

Sep 20 11

./adb: No such file or directory

by Mike Chenault

./adb: No such file or directory

This problem shows up on Ubuntu for some users. Most users can fix this by installing the ia32-libs package.

sudo apt-get install ia32-libx

Aug 16 10

Create links to Android Marketplace: Android

by Mike Chenault

See the bottom of this link to see how to link to the Android Marketplace.

Click here