Wednesday, February 29, 2012

Free Pluralsight Training TODAY Only

Check out their blog post for more information. I love Pluralsight!

Tuesday, February 21, 2012

Thank You, Microsoft!

Microsoft was nice enough to give me App Hub 12-month membership for free. Now I can finally test and deploy the Windows Phone app. Thank you MS!


Sunday, February 19, 2012

Android Hackbook and Facebook SDK

Hackbook is great for learning Facebook SDK and Android development.


Hackbook Place Check-in


final Intent myIntent = new Intent(getApplicationContext(), Places.class);

new AlertDialog.Builder(this)
.setTitle(R.string.get_location)
.setMessage(R.string.get_default_or_new_location)
.setPositiveButton(R.string.current_location_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
myIntent.putExtra("LOCATION", "current");
startActivity(myIntent);
}
})
.setNegativeButton(R.string.times_square_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
myIntent.putExtra("LOCATION", "times_square");
startActivity(myIntent);
}

}).show();


Hackbook Upload Photo

import android.provider.MediaStore;

final static int PICK_EXISTING_PHOTO_RESULT_CODE = 1;

dialog = ProgressDialog.show(Hackbook.this, "",
getString(R.string.please_wait), true, true);
new AlertDialog.Builder(this)
.setTitle(R.string.gallery_remote_title)
.setMessage(R.string.gallery_remote_msg)
.setPositiveButton(R.string.gallery_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_PICK,
(MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
startActivityForResult(intent,
PICK_EXISTING_PHOTO_RESULT_CODE);
}

})
.setNegativeButton(R.string.remote_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
/*
* Source tag: upload_photo_tag
*/  
Bundle params = new Bundle();
params.putString("url",
"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
params.putString("caption",
"FbAPIs Sample App photo upload");
Utility.mAsyncRunner.request("me/photos", params,
"POST", new PhotoUploadListener(), null);
}

}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface d) {
dialog.dismiss();
}
}).show();
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
/*
* if this is the activity result from authorization flow, do a call
* back to authorizeCallback Source Tag: login_tag
*/

case AUTHORIZE_ACTIVITY_RESULT_CODE: {
Utility.mFacebook.authorizeCallback(requestCode, resultCode, data);
break;
}

/*
* if this is the result for a photo picker from the gallery, upload
* the image after scaling it. You can use the Utility.scaleImage()
* function for scaling
*/

case PICK_EXISTING_PHOTO_RESULT_CODE: {
if (resultCode == Activity.RESULT_OK) {
Uri photoUri = data.getData();
if (photoUri != null) {
Bundle params = new Bundle();
try {
params.putByteArray("photo",
Utility.scaleImage(getApplicationContext(), photoUri));
} catch (IOException e) {
e.printStackTrace();
}
params.putString("caption", "FbAPIs Sample App photo upload");
Utility.mAsyncRunner.request("me/photos", params, "POST",
new PhotoUploadListener(), null);
} else {
Toast.makeText(getApplicationContext(),
"Error selecting image from the gallery.", Toast.LENGTH_SHORT)
.show();
}
} else {
Toast.makeText(getApplicationContext(), "No image selected for upload.",
Toast.LENGTH_SHORT).show();
}
break;
}

//}
}



public class PhotoUploadListener extends BaseRequestListener {

        @Override
        public void onComplete(final String response, final Object state) {
            dialog.dismiss();
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    new UploadPhotoResultDialog(Hackbook.this, "Upload Photo executed", response)
                            .show();
                }
            });
        }

        public void onFacebookError(FacebookError error) {
            dialog.dismiss();
            Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(),
                    Toast.LENGTH_LONG).show();
        }
    }

Hackbook Get Friends Graph API


dialog = ProgressDialog.show(Hackbook.this, "",
getString(R.string.please_wait), true, true);
new AlertDialog.Builder(this)
.setTitle(R.string.Graph_FQL_title)
.setMessage(R.string.Graph_FQL_msg)
.setPositiveButton(R.string.graph_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
graph_or_fql = "graph";
Bundle params = new Bundle();
params.putString("fields", "name, picture, location");
Utility.mAsyncRunner.request("me/friends", params,
new FriendsRequestListener());
}

})
.setNegativeButton(R.string.fql_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
graph_or_fql = "fql";
String query = "select name, current_location, uid, pic_square from user where uid in (select uid2 from friend where uid1=me()) order by name";
Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query", query);
Utility.mAsyncRunner.request(null, params,
new FriendsRequestListener());
}

}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface d) {
dialog.dismiss();
}
}).show();


public class FriendsRequestListener extends BaseRequestListener {

        @Override
        public void onComplete(final String response, final Object state) {
            dialog.dismiss();
            Intent myIntent = new Intent(getApplicationContext(), FriendsList.class);
            myIntent.putExtra("API_RESPONSE", response);
            myIntent.putExtra("METHOD", graph_or_fql);
            startActivity(myIntent);
        }

        public void onFacebookError(FacebookError error) {
            dialog.dismiss();
            Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(),
                    Toast.LENGTH_SHORT).show();
        }
    }

Hackbook Update Status


Bundle params = new Bundle();
params.putString("caption", getString(R.string.app_name));
params.putString("description", getString(R.string.app_desc));
params.putString("picture", Utility.HACK_ICON_URL);
params.putString("name", getString(R.string.app_action));

Utility.mFacebook.dialog(Hackbook.this, "feed", params, new UpdateStatusListener());
String access_token = Utility.mFacebook.getAccessToken();
System.out.println(access_token);


public class UpdateStatusListener extends BaseDialogListener {
        @Override
        public void onComplete(Bundle values) {
            final String postId = values.getString("post_id");
            if (postId != null) {
                new UpdateStatusResultDialog(Hackbook.this, "Update Status executed", values)
                        .show();
            } else {
                Toast toast = Toast.makeText(getApplicationContext(), "No wall post made",
                        Toast.LENGTH_SHORT);
                toast.show();
            }
        }

        @Override
        public void onFacebookError(FacebookError error) {
            Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(),
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel() {
            Toast toast = Toast.makeText(getApplicationContext(), "Update status cancelled",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    }

Hackbook App Requests


import android.os.Bundle;
import android.widget.Toast;

Bundle params = new Bundle();
params.putString("message", getString(R.string.request_message));
Utility.mFacebook.dialog(Hackbook.this, "apprequests", params, new AppRequestsListener());

public class AppRequestsListener extends BaseDialogListener {
        @Override
        public void onComplete(Bundle values) {
            Toast toast = Toast.makeText(getApplicationContext(), "App request sent",
                    Toast.LENGTH_SHORT);
            toast.show();
        }

        @Override
        public void onFacebookError(FacebookError error) {
            Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(),
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel() {
            Toast toast = Toast.makeText(getApplicationContext(), "App request cancelled",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    }

Thursday, February 16, 2012

Android NotePad App Modified

Added Context Menu Item 'Edit Date'

Added Options Menu Item 'Edit Date'


Added 'Edit Date' Activity as a Dialog

Facebook Open Graph

  1. Check out Facebook API Explorer: https://developers.facebook.com/tools/explorer
  2. Make sure 'Access Token' field is filled out by clicking 'Get Access Token'
  3. 3) In the box next to 'GET' paste the following text '333474563361578/events'. 
  4. Click 'Submit'
  5. The following JSON data is returned. It contains 2 events that are currently listed on this page https://www.facebook.com/pages/Mason-Events/333474563361578?sk=events
{
"data": [
{
"name": "Films Committee Meeting",
"start_time": "2012-02-27T20:30:00",
"end_time": "2012-02-27T23:30:00",
"location": "George Mason University",
"id": "170763413035583"
},
{
"name": "Special Events Committee Meetings",
"start_time": "2012-02-27T19:30:00",
"end_time": "2012-02-27T20:30:00",
"location": "George Mason University",
"id": "253568778055608"
}
],
"paging": {
"previous": "https://graph.facebook.com/333474563361578/events?format=json&limit=5000&since=1330374600&__paging_token=170763413035583&__previous=1",
"next": "https://graph.facebook.com/333474563361578/events?format=json&limit=5000&until=1330371000&__paging_token=253568778055608"
}
}

    6.  You can click on the id link to get more specific information about each event.
{
"id": "170763413035583",
"owner": {
"name": "Mason Events",
"category": "Community",
"id": "333474563361578"
},
"name": "Films Committee Meeting",
"description": "Where: PB Office\n\nWant to plan special film events on campus and help pick what is showing the JC cinema on the weekends? Come on out to the committee meetings!!!!",
"start_time": "2012-02-27T20:30:00",
"end_time": "2012-02-27T23:30:00",
"location": "George Mason University",
"venue": {
"latitude": 38.830211976257,
"longitude": -77.308175843647,
"id": "5625209996"
},
"privacy": "OPEN",
"updated_time": "2012-02-17T02:35:40+0000",
"type": "event"
}