initial commit of TravelPost rework.

TODO:
Need to finish Facebook and Twitter integration. To avoid context issues in facebook possible perform authorization in its own activity.
Need to handle the widget and posting.
This commit is contained in:
warren powers
2011-07-02 15:00:30 +00:00
parent d9520f1302
commit 2dee86b00e
26 changed files with 1441 additions and 0 deletions

16
TravelPost/.classpath Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="/LocationLib/lib/wpsapi.jar">
<attributes>
<attribute name="javadoc_location" value="http://tcdevsvn1/ShyHookdocumentation"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/warren/Development/workspace/TravelPost/libs/twitter4j-core-2.1.11.jar"/>
<classpathentry kind="src" path="FacebookLib_src"/>
<classpathentry kind="src" path="ExceptionHandlerLib_src"/>
<classpathentry kind="src" path="LocationLib_src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

50
TravelPost/.project Normal file
View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>TravelPost</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>ExceptionHandlerLib_src</name>
<type>2</type>
<locationURI>_android_ExceptionHandlerLib_7d68b46a/src</locationURI>
</link>
<link>
<name>FacebookLib_src</name>
<type>2</type>
<locationURI>_android_FacebookLib_9c84f9bf/src</locationURI>
</link>
<link>
<name>LocationLib_src</name>
<type>2</type>
<locationURI>_android_LocationLib_84551a70/src</locationURI>
</link>
</linkedResources>
</projectDescription>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TwentyCodes.android.TravelPost"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TravelPostMain"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.READ_LOGS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>

View File

@@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=Google Inc.:Google APIs:12
android.library.reference.3=../LocationLib
android.library.reference.1=../ExceptionHandlerLib
android.library.reference.2=../FacebookLib

View File

@@ -0,0 +1,88 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.TwentyCodes.android.SkyHook;
public final class R {
public static final class array {
public static final int accuracy_entries=0x7f060000;
public static final int accuracy_values=0x7f060001;
}
public static final class attr {
}
public static final class drawable {
public static final int compass=0x7f020000;
public static final int facebook_icon=0x7f020001;
public static final int icon=0x7f020002;
public static final int logoidea3=0x7f020003;
public static final int needle=0x7f020004;
public static final int skyhook_logo=0x7f020005;
public static final int skyhook_logo_alpha=0x7f020006;
public static final int skyhook_logo_alpha_small=0x7f020007;
public static final int tc_logo_complete=0x7f020008;
public static final int user=0x7f020009;
}
public static final class id {
public static final int skyhook_img=0x7f070000;
public static final int socialsites=0x7f070003;
public static final int tc_img=0x7f070002;
public static final int text=0x7f070001;
}
public static final class layout {
public static final int powered_by_skyhook=0x7f030000;
}
public static final class string {
public static final int about=0x7f050005;
public static final int about_info=0x7f050006;
public static final int about_verify=0x7f050007;
public static final int accuracy=0x7f050008;
public static final int accuracy_info=0x7f050009;
public static final int add_social_site=0x7f05000a;
public static final int app_name=0x7f050000;
public static final int cancel_service=0x7f05000b;
public static final int check_in_at=0x7f05000c;
public static final int clear=0x7f05000d;
public static final int crash=0x7f050003;
public static final int disable_facebook_checkin=0x7f05000e;
public static final int enable_facebook_checkin=0x7f05000f;
public static final int facebook=0x7f050010;
public static final int facebook_already_authorized=0x7f050011;
public static final int facebook_authorization_failure=0x7f050012;
public static final int facebook_options=0x7f050013;
public static final int facebook_session_not_valid=0x7f050014;
public static final int fb_signin=0x7f050015;
public static final int gathering=0x7f05001c;
public static final int gps_fix=0x7f050001;
public static final int loading=0x7f050016;
public static final int location_settings=0x7f050017;
public static final int poor_data_connection=0x7f05001e;
public static final int post_hint=0x7f050018;
public static final int post_lenght=0x7f050019;
public static final int post_settings=0x7f05001d;
public static final int post_to_long=0x7f05001a;
public static final int posting=0x7f05001b;
public static final int remove_facebook=0x7f05001f;
public static final int remove_facebook_confirmation=0x7f050020;
public static final int remove_site_title=0x7f050021;
public static final int remove_twitter=0x7f050022;
public static final int save_a_post=0x7f050023;
public static final int social_site=0x7f050024;
public static final int sorry=0x7f050004;
public static final int sorry_theres_trouble=0x7f050002;
public static final int twitter=0x7f050025;
public static final int twitter_already_authorized=0x7f050026;
public static final int twitter_authorization_failure=0x7f050027;
public static final int twitter_exception=0x7f050028;
public static final int twitter_signin=0x7f050029;
public static final int update=0x7f05002a;
public static final int verify_message=0x7f05002b;
public static final int verify_post=0x7f05002c;
}
public static final class xml {
public static final int travelpostmain=0x7f040000;
}
}

View File

@@ -0,0 +1,88 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.TwentyCodes.android.TravelPost;
public final class R {
public static final class array {
public static final int accuracy_entries=0x7f060000;
public static final int accuracy_values=0x7f060001;
}
public static final class attr {
}
public static final class drawable {
public static final int compass=0x7f020000;
public static final int facebook_icon=0x7f020001;
public static final int icon=0x7f020002;
public static final int logoidea3=0x7f020003;
public static final int needle=0x7f020004;
public static final int skyhook_logo=0x7f020005;
public static final int skyhook_logo_alpha=0x7f020006;
public static final int skyhook_logo_alpha_small=0x7f020007;
public static final int tc_logo_complete=0x7f020008;
public static final int user=0x7f020009;
}
public static final class id {
public static final int skyhook_img=0x7f070000;
public static final int socialsites=0x7f070003;
public static final int tc_img=0x7f070002;
public static final int text=0x7f070001;
}
public static final class layout {
public static final int powered_by_skyhook=0x7f030000;
}
public static final class string {
public static final int about=0x7f050005;
public static final int about_info=0x7f050006;
public static final int about_verify=0x7f050007;
public static final int accuracy=0x7f050008;
public static final int accuracy_info=0x7f050009;
public static final int add_social_site=0x7f05000a;
public static final int app_name=0x7f050000;
public static final int cancel_service=0x7f05000b;
public static final int check_in_at=0x7f05000c;
public static final int clear=0x7f05000d;
public static final int crash=0x7f050003;
public static final int disable_facebook_checkin=0x7f05000e;
public static final int enable_facebook_checkin=0x7f05000f;
public static final int facebook=0x7f050010;
public static final int facebook_already_authorized=0x7f050011;
public static final int facebook_authorization_failure=0x7f050012;
public static final int facebook_options=0x7f050013;
public static final int facebook_session_not_valid=0x7f050014;
public static final int fb_signin=0x7f050015;
public static final int gathering=0x7f05001c;
public static final int gps_fix=0x7f050001;
public static final int loading=0x7f050016;
public static final int location_settings=0x7f050017;
public static final int poor_data_connection=0x7f05001e;
public static final int post_hint=0x7f050018;
public static final int post_lenght=0x7f050019;
public static final int post_settings=0x7f05001d;
public static final int post_to_long=0x7f05001a;
public static final int posting=0x7f05001b;
public static final int remove_facebook=0x7f05001f;
public static final int remove_facebook_confirmation=0x7f050020;
public static final int remove_site_title=0x7f050021;
public static final int remove_twitter=0x7f050022;
public static final int save_a_post=0x7f050023;
public static final int social_site=0x7f050024;
public static final int sorry=0x7f050004;
public static final int sorry_theres_trouble=0x7f050002;
public static final int twitter=0x7f050025;
public static final int twitter_already_authorized=0x7f050026;
public static final int twitter_authorization_failure=0x7f050027;
public static final int twitter_exception=0x7f050028;
public static final int twitter_signin=0x7f050029;
public static final int update=0x7f05002a;
public static final int verify_message=0x7f05002b;
public static final int verify_post=0x7f05002c;
}
public static final class xml {
public static final int travelpostmain=0x7f040000;
}
}

View File

@@ -0,0 +1,88 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.TwentyCodes.android.exception;
public final class R {
public static final class array {
public static final int accuracy_entries=0x7f060000;
public static final int accuracy_values=0x7f060001;
}
public static final class attr {
}
public static final class drawable {
public static final int compass=0x7f020000;
public static final int facebook_icon=0x7f020001;
public static final int icon=0x7f020002;
public static final int logoidea3=0x7f020003;
public static final int needle=0x7f020004;
public static final int skyhook_logo=0x7f020005;
public static final int skyhook_logo_alpha=0x7f020006;
public static final int skyhook_logo_alpha_small=0x7f020007;
public static final int tc_logo_complete=0x7f020008;
public static final int user=0x7f020009;
}
public static final class id {
public static final int skyhook_img=0x7f070000;
public static final int socialsites=0x7f070003;
public static final int tc_img=0x7f070002;
public static final int text=0x7f070001;
}
public static final class layout {
public static final int powered_by_skyhook=0x7f030000;
}
public static final class string {
public static final int about=0x7f050005;
public static final int about_info=0x7f050006;
public static final int about_verify=0x7f050007;
public static final int accuracy=0x7f050008;
public static final int accuracy_info=0x7f050009;
public static final int add_social_site=0x7f05000a;
public static final int app_name=0x7f050000;
public static final int cancel_service=0x7f05000b;
public static final int check_in_at=0x7f05000c;
public static final int clear=0x7f05000d;
public static final int crash=0x7f050003;
public static final int disable_facebook_checkin=0x7f05000e;
public static final int enable_facebook_checkin=0x7f05000f;
public static final int facebook=0x7f050010;
public static final int facebook_already_authorized=0x7f050011;
public static final int facebook_authorization_failure=0x7f050012;
public static final int facebook_options=0x7f050013;
public static final int facebook_session_not_valid=0x7f050014;
public static final int fb_signin=0x7f050015;
public static final int gathering=0x7f05001c;
public static final int gps_fix=0x7f050001;
public static final int loading=0x7f050016;
public static final int location_settings=0x7f050017;
public static final int poor_data_connection=0x7f05001e;
public static final int post_hint=0x7f050018;
public static final int post_lenght=0x7f050019;
public static final int post_settings=0x7f05001d;
public static final int post_to_long=0x7f05001a;
public static final int posting=0x7f05001b;
public static final int remove_facebook=0x7f05001f;
public static final int remove_facebook_confirmation=0x7f050020;
public static final int remove_site_title=0x7f050021;
public static final int remove_twitter=0x7f050022;
public static final int save_a_post=0x7f050023;
public static final int social_site=0x7f050024;
public static final int sorry=0x7f050004;
public static final int sorry_theres_trouble=0x7f050002;
public static final int twitter=0x7f050025;
public static final int twitter_already_authorized=0x7f050026;
public static final int twitter_authorization_failure=0x7f050027;
public static final int twitter_exception=0x7f050028;
public static final int twitter_signin=0x7f050029;
public static final int update=0x7f05002a;
public static final int verify_message=0x7f05002b;
public static final int verify_post=0x7f05002c;
}
public static final class xml {
public static final int travelpostmain=0x7f040000;
}
}

View File

@@ -0,0 +1,88 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.facebook.android;
public final class R {
public static final class array {
public static final int accuracy_entries=0x7f060000;
public static final int accuracy_values=0x7f060001;
}
public static final class attr {
}
public static final class drawable {
public static final int compass=0x7f020000;
public static final int facebook_icon=0x7f020001;
public static final int icon=0x7f020002;
public static final int logoidea3=0x7f020003;
public static final int needle=0x7f020004;
public static final int skyhook_logo=0x7f020005;
public static final int skyhook_logo_alpha=0x7f020006;
public static final int skyhook_logo_alpha_small=0x7f020007;
public static final int tc_logo_complete=0x7f020008;
public static final int user=0x7f020009;
}
public static final class id {
public static final int skyhook_img=0x7f070000;
public static final int socialsites=0x7f070003;
public static final int tc_img=0x7f070002;
public static final int text=0x7f070001;
}
public static final class layout {
public static final int powered_by_skyhook=0x7f030000;
}
public static final class string {
public static final int about=0x7f050005;
public static final int about_info=0x7f050006;
public static final int about_verify=0x7f050007;
public static final int accuracy=0x7f050008;
public static final int accuracy_info=0x7f050009;
public static final int add_social_site=0x7f05000a;
public static final int app_name=0x7f050000;
public static final int cancel_service=0x7f05000b;
public static final int check_in_at=0x7f05000c;
public static final int clear=0x7f05000d;
public static final int crash=0x7f050003;
public static final int disable_facebook_checkin=0x7f05000e;
public static final int enable_facebook_checkin=0x7f05000f;
public static final int facebook=0x7f050010;
public static final int facebook_already_authorized=0x7f050011;
public static final int facebook_authorization_failure=0x7f050012;
public static final int facebook_options=0x7f050013;
public static final int facebook_session_not_valid=0x7f050014;
public static final int fb_signin=0x7f050015;
public static final int gathering=0x7f05001c;
public static final int gps_fix=0x7f050001;
public static final int loading=0x7f050016;
public static final int location_settings=0x7f050017;
public static final int poor_data_connection=0x7f05001e;
public static final int post_hint=0x7f050018;
public static final int post_lenght=0x7f050019;
public static final int post_settings=0x7f05001d;
public static final int post_to_long=0x7f05001a;
public static final int posting=0x7f05001b;
public static final int remove_facebook=0x7f05001f;
public static final int remove_facebook_confirmation=0x7f050020;
public static final int remove_site_title=0x7f050021;
public static final int remove_twitter=0x7f050022;
public static final int save_a_post=0x7f050023;
public static final int social_site=0x7f050024;
public static final int sorry=0x7f050004;
public static final int sorry_theres_trouble=0x7f050002;
public static final int twitter=0x7f050025;
public static final int twitter_already_authorized=0x7f050026;
public static final int twitter_authorization_failure=0x7f050027;
public static final int twitter_exception=0x7f050028;
public static final int twitter_signin=0x7f050029;
public static final int update=0x7f05002a;
public static final int verify_message=0x7f05002b;
public static final int verify_post=0x7f05002c;
}
public static final class xml {
public static final int travelpostmain=0x7f040000;
}
}

Binary file not shown.

36
TravelPost/proguard.cfg Normal file
View File

@@ -0,0 +1,36 @@
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="accuracy_entries">
<item>High (8 meters)</item>
<item>Medium (20 meters)</item>
<item>Low (50 meters)</item>
</string-array>
<string-array name="accuracy_values">
<item>8</item>
<item>20</item>
<item>50</item>
</string-array>
</resources>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="about">About</string>
<string name="about_info">Travel Post will post your location to several different social sites like Facebook! Simply add the widget to your homescreen and press the widget. If you have any questions or comments feel free to email us at TwentyCodes@gmail.com.</string>
<string name="about_verify">Please review your post</string>
<string name="accuracy">Accuracy</string>
<string name="accuracy_info">Higher accuracy equals longer wait.</string>
<string name="add_social_site">Add A Social Site</string>
<string name="app_name">Travel Post</string>
<string name="cancel_service">Do you want to cancel your post?</string>
<string name="check_in_at">Check in at:</string>
<string name="clear">Clear</string>
<string name="disable_facebook_checkin">Post to Facebook Wall</string>
<string name="enable_facebook_checkin">Post to Facebook Check In</string>
<string name="facebook">Facebook</string>
<string name="facebook_already_authorized">Facebook is already authorized.</string>
<string name="facebook_authorization_failure">Unable to authorize Facebook account. Please try again.</string>
<string name="facebook_options">Facebook Options</string>
<string name="facebook_session_not_valid">Your Facebook session is no longer valid. Please log in to Facebook again.</string>
<string name="fb_signin">Facebook Sign In</string>
<string name="loading">Loading...</string>
<string name="location_settings">Location Settings</string>
<string name="post_hint">Whats up?</string>
<string name="post_lenght">Post Lenght: </string>
<string name="post_to_long">Please Reduce your post to 140 chars</string>
<string name="posting">Posting...</string>
<string name="gathering">Gathering location...</string>
<string name="post_settings">Post Settings</string>
<string name="poor_data_connection">We are having issues connecting to the internet. Please try again later.</string>
<string name="remove_facebook">Remove Facebook</string>
<string name="remove_facebook_confirmation">Are you sure you want to remove Facebook? You will not be able to post messages to Facebook anymore.</string>
<string name="remove_site_title">Remove Social Site</string>
<string name="remove_twitter">Are you sure you want to remove Twitter? You will not be able to post messages to Twitter anymore.</string>
<string name="save_a_post">Save a Post</string>
<string name="social_site">Social Sites</string>
<string name="twitter">Twitter</string>
<string name="twitter_already_authorized">Twitter is already authorized.</string>
<string name="twitter_authorization_failure">Unable to authorize Twitter account. Please try again.</string>
<string name="twitter_exception">We could not connect to Twitter. Please check your connection and try again.</string>
<string name="twitter_signin">Twitter Sign In</string>
<string name="update">Update</string>
<string name="verify_message">Verify the message before posting.</string>
<string name="verify_post">Verify Post</string>
</resources>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/app_name">
<PreferenceCategory
android:id="@+id/socialsites"
android:title="@string/social_site"
android:key="socialsites">
<Preference
android:title="@string/add_social_site"
android:key="add_social_site" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/location_settings">
<ListPreference
android:title="@string/accuracy"
android:summary="@string/accuracy_info"
android:entries="@array/accuracy_entries"
android:entryValues="@array/accuracy_values"
android:key="accuracy"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/about">
<com.TwentyCodes.android.TravelPost.UI.AboutView
android:title="@string/about_info"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -0,0 +1,15 @@
package com.TwentyCodes.android.TravelPost.Debug;
/**
* This class is used to hold debug values used throughout the application.
*/
public class Debug {
/**
* This variable if true will enable android logging.
*/
public static final boolean LOGGING = true;
}

View File

@@ -0,0 +1,254 @@
package com.TwentyCodes.android.TravelPost.SocialSites;
import java.io.IOException;
import org.json.JSONException;
import org.json.JSONObject;
import com.TwentyCodes.android.TravelPost.Debug.Debug;
import com.TwentyCodes.android.TravelPost.SocialSites.FacebookEvents.AuthListener;
import com.TwentyCodes.android.TravelPost.SocialSites.FacebookEvents.LogoutListener;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.Facebook.DialogListener;
import android.app.Dialog;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
public class Facebook {
private static final String[] PERMISSIONS = new String[] {"publish_stream", "publish_checkins"};
/* Permissions that are prompted to the user for authorization */
private static final String APP_ID = "197267276952565";
/* This is the api key for the facebook application. See /FacebookLib/APIS.txt */
private static final String TAG = "Facebook";
private final com.facebook.android.Facebook mFb = new com.facebook.android.Facebook(APP_ID);
private final AsyncFacebookRunner mAsync = new AsyncFacebookRunner(mFb);
private Context mCtx;
private Handler mHandler;
/**
* @param loginDialogListener - specify your own listener
*/
public void authorize(DialogListener loginDialogListener) {
if (Debug.LOGGING)
Log.i(TAG, "authorize()");
if (!this.mFb.isSessionValid()) {
Log.i(TAG, "authorize().seesion is not valid");
this.mFb.authorize(this.mCtx, PERMISSIONS, loginDialogListener);
}
}
/**
* Users Facebooks check in server to post to the users wall.
* @param text to post to wall
* @param Location object representing the users current location
* @param placeId found using places search this.placeSearch(Location)
* @throws SessionNotValidException - if the facebook session is not valid
* @return String JSON object response of post
*/
public String checkIn(String post, Location location, String placeId) throws FacebookSessionNotValidException, JSONException, IOException {
if (this.mFb.isSessionValid()) {
Bundle parameters = new Bundle();
parameters.putString("place", placeId);
parameters.putString("message", post);
parameters.putString("coordinates", new JSONObject().put("latitude", location.getLatitude()).put("longitude", location.getLongitude()).toString());
return this.mFb.request("me/checkins", parameters, "POST");
} else {
if (this.mFb.getAccessToken() == null && Debug.LOGGING) {
Log.i(TAG, "postToWall.access token is null");
}
throw new FacebookSessionNotValidException("This session is not valid");
}
}
public Facebook(final Context context) {
this.mCtx = context;
this.mHandler = new Handler();
FacebookSessionStore.restore(this.mFb, this.mCtx);
FacebookEvents.addAuthListener(new FacebookAuthListener());
FacebookEvents.addLogoutListener(new FacebookLogoutListener());
}
/**
* @return true if the session is valid
*/
public boolean isSessionValid() {
return this.mFb.isSessionValid();
}
/**
* This method started the Facebook logout process
*/
public void logout() {
if (this.mFb.isSessionValid()) {
FacebookEvents.onLogoutBegin();
this.mAsync.logout(this.mCtx, new LogoutRequestListener());
}
}
/**
* Searches facebook for places that the provided location could be
* @param location to perform the search
* @param radius to search in meters. recommended radius is 1000
* @return A String of a JASONObject of places
* @throws SessionNotValidException if session is not valid
*/
public String placeSearch(Location location, long radius) throws FacebookSessionNotValidException, IOException {
if (this.mFb.isSessionValid()) {
Bundle parameters = new Bundle();
parameters.putString("type", "place");
parameters.putString("center", location.getLatitude()+","+location.getLongitude());
parameters.putString("distance", Long.toString(radius));
return this.mFb.request("search", parameters, "GET");
} else {
if (this.mFb.getAccessToken() == null && Debug.LOGGING) {
Log.i(TAG, "postToWall.access token is null");
}
throw new FacebookSessionNotValidException("This session is not valid");
}
}
/**
* Allows the user to post to their wall and input their own message
* This method displays a dialog asking for input
* @author warren
*/
public void postToWallDialog() {
this.mFb.dialog(this.mCtx, "feed", new FacebookDialogListener());
}
/**
* This method posts a message to the users wall
* @author warren
* @param msg - message to post
*/
public void postToWall(String msg) throws FacebookSessionNotValidException, IOException {
if (Debug.LOGGING)
Log.d(TAG, "postToWall()");
if (mFb.isSessionValid()) {
Bundle parameters = new Bundle();
parameters.putString("message", msg);
String response = mFb.request("me/feed", parameters, "POST");
if (Debug.LOGGING)
Log.d(TAG, "received response: " + response);
if ((response == null || response.equals("") || response.equals("false")) && Debug.LOGGING) {
Log.v("Error", "Blank response");
throw new IOException("No response from post request");
}
} else {
if (mFb.getAccessToken() == null && Debug.LOGGING) {
Log.i(TAG, "postToWall.access token is null");
}
throw new FacebookSessionNotValidException("This session is not valid");
}
}
/**
* Handles facebook authorization callbacks.
* @author warren
*
*/
private class FacebookAuthListener implements AuthListener {
@Override
public void onAuthSucceed() {
FacebookSessionStore.save(mFb, mCtx);
if (Debug.LOGGING)
Log.i(TAG, "FacebookAuthListener.onAuthSucceed()");
}
@Override
public void onAuthFail(String error) {
if (Debug.LOGGING)
Log.i(TAG, "FacebookAuthListener.anAuthFail");
}
}
/**
* Handles facebook logout callbacks
* @author warren
*
*/
private class FacebookLogoutListener implements LogoutListener {
@Override
public void onLogoutBegin() {
if (Debug.LOGGING)
Log.i(TAG, "FacebookLogoutListener.logout being");
}
@Override
public void onLogoutFinish() {
FacebookSessionStore.clear(mCtx);
if (Debug.LOGGING)
Log.i(TAG, "FacebookLogoutListener.logout succeeded");
}
}
/**
* Listens for requests to log out.
* @author warren
*
*/
private class LogoutRequestListener extends FacebookBaseRequestListener {
public void onComplete(String response, final Object state) {
// callback should be run in the original thread,
// not the background thread
mHandler.post(new Runnable() {
public void run() {
FacebookEvents.onLogoutFinish();
}
});
}
}
/**
* Listens for dialogs to post text to wall
* @author warren
*
*/
public class FacebookDialogListener extends FacebookBaseDialogListener {
public void onComplete(Bundle values, Dialog dialog) {
final String postId = values.getString("post_id");
if (postId != null) {
if (Debug.LOGGING)
Log.d(TAG, "Dialog Success. post_id=" + postId);
mAsync.request(postId, new WallPostRequestListener());
} else {
if (Debug.LOGGING)
Log.d(TAG, "No wall post made");
}
}
}
/**
* Listens for posts to the wall
* @author warren
*
*/
public class WallPostRequestListener extends FacebookBaseRequestListener {
public void onComplete(final String response, final Object state) {
if (Debug.LOGGING)
Log.i(TAG, "WallPostRequestListener.post successful");
}
}
}

View File

@@ -0,0 +1,19 @@
package com.TwentyCodes.android.TravelPost.SocialSites;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
public abstract class FacebookBaseDialogListener implements DialogListener {
public void onFacebookError(FacebookError e) {
e.printStackTrace();
}
public void onError(DialogError e) {
e.printStackTrace();
}
public void onCancel() {
}
}

View File

@@ -0,0 +1,38 @@
package com.TwentyCodes.android.TravelPost.SocialSites;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import android.util.Log;
import com.TwentyCodes.android.TravelPost.Debug.Debug;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.FacebookError;
public abstract class FacebookBaseRequestListener implements RequestListener {
public void onFacebookError(FacebookError e, final Object state) {
if (Debug.LOGGING)
Log.e("Facebook", e.getMessage());
e.printStackTrace();
}
public void onFileNotFoundException(FileNotFoundException e, final Object state) {
if (Debug.LOGGING)
Log.e("Facebook", e.getMessage());
e.printStackTrace();
}
public void onIOException(IOException e, final Object state) {
if (Debug.LOGGING)
Log.e("Facebook", e.getMessage());
e.printStackTrace();
}
public void onMalformedURLException(MalformedURLException e, final Object state) {
if (Debug.LOGGING)
Log.e("Facebook", e.getMessage());
e.printStackTrace();
}
}

View File

@@ -0,0 +1,144 @@
/*
* Copyright 2010 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.TwentyCodes.android.TravelPost.SocialSites;
import java.util.LinkedList;
public class FacebookEvents {
private static LinkedList<AuthListener> mAuthListeners = new LinkedList<AuthListener>();
private static LinkedList<LogoutListener> mLogoutListeners = new LinkedList<LogoutListener>();
/**
* Associate the given listener with this Facebook object. The listener's
* callback interface will be invoked when authentication events occur.
*
* @param listener
* The callback object for notifying the application when auth
* events happen.
*/
public static void addAuthListener(AuthListener listener) {
mAuthListeners.add(listener);
}
/**
* Remove the given listener from the list of those that will be notified
* when authentication events occur.
*
* @param listener
* The callback object for notifying the application when auth
* events happen.
*/
public static void removeAuthListener(AuthListener listener) {
mAuthListeners.remove(listener);
}
/**
* Associate the given listener with this Facebook object. The listener's
* callback interface will be invoked when logout occurs.
*
* @param listener
* The callback object for notifying the application when log out
* starts and finishes.
*/
public static void addLogoutListener(LogoutListener listener) {
mLogoutListeners.add(listener);
}
/**
* Remove the given listener from the list of those that will be notified
* when logout occurs.
*
* @param listener
* The callback object for notifying the application when log out
* starts and finishes.
*/
public static void removeLogoutListener(LogoutListener listener) {
mLogoutListeners.remove(listener);
}
public static void onLoginSuccess() {
for (AuthListener listener : mAuthListeners) {
listener.onAuthSucceed();
}
}
public static void onLoginError(String error) {
for (AuthListener listener : mAuthListeners) {
listener.onAuthFail(error);
}
}
public static void onLogoutBegin() {
for (LogoutListener l : mLogoutListeners) {
l.onLogoutBegin();
}
}
public static void onLogoutFinish() {
for (LogoutListener l : mLogoutListeners) {
l.onLogoutFinish();
}
}
/**
* Callback interface for authorization events.
*
*/
public static interface AuthListener {
/**
* Called when a auth flow completes successfully and a valid OAuth
* Token was received.
*
* Executed by the thread that initiated the authentication.
*
* API requests can now be made.
*/
public void onAuthSucceed();
/**
* Called when a login completes unsuccessfully with an error.
*
* Executed by the thread that initiated the authentication.
*/
public void onAuthFail(String error);
}
/**
* Callback interface for logout events.
*
*/
public static interface LogoutListener {
/**
* Called when logout begins, before session is invalidated.
* Last chance to make an API call.
*
* Executed by the thread that initiated the logout.
*/
public void onLogoutBegin();
/**
* Called when the session information has been cleared.
* UI should be updated to reflect logged-out state.
*
* Executed by the thread that initiated the logout.
*/
public void onLogoutFinish();
}
}

View File

@@ -0,0 +1,16 @@
package com.TwentyCodes.android.TravelPost.SocialSites;
import android.accounts.AccountsException;
public class FacebookSessionNotValidException extends AccountsException {
/**
* Generated serial UID
*/
private static final long serialVersionUID = -6783174641458701144L;
public FacebookSessionNotValidException(String message) {
new AccountsException(message);
}
}

View File

@@ -0,0 +1,38 @@
package com.TwentyCodes.android.TravelPost.SocialSites;
import com.TwentyCodes.android.TravelPost.Debug.Debug;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
public class FacebookSessionStore {
private static final String TOKEN = "access_token";
private static final String EXPIRES = "expires_in";
private static final String KEY = "facebook-session";
private static final String TAG = "FacebookSessionStore";
public static boolean save(com.facebook.android.Facebook session, Context context) {
Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.putString(TOKEN, session.getAccessToken());
editor.putLong(EXPIRES, session.getAccessExpires());
return editor.commit();
}
public static boolean restore(com.facebook.android.Facebook session, Context context) {
if (context == null && Debug.LOGGING)
Log.i(TAG, "restore().context is null");
SharedPreferences savedSession = context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
session.setAccessToken(savedSession.getString(TOKEN, null));
session.setAccessExpires(savedSession.getLong(EXPIRES, 0));
return session.isSessionValid();
}
public static void clear(Context context) {
Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.clear();
editor.commit();
}
}

View File

@@ -0,0 +1,17 @@
package com.TwentyCodes.android.TravelPost.SocialSites;
import android.content.Context;
public class Twitter {
private Context mCtx;
public Twitter (Context ctx) {
this.mCtx = ctx;
}
public void authorize() {
}
}

View File

@@ -0,0 +1,248 @@
package com.TwentyCodes.android.TravelPost;
import com.TwentyCodes.android.TravelPost.Debug.Debug;
import com.TwentyCodes.android.TravelPost.SocialSites.Facebook;
import com.TwentyCodes.android.TravelPost.SocialSites.FacebookEvents;
import com.TwentyCodes.android.exception.ExceptionHandler;
import com.facebook.android.DialogError;
import com.facebook.android.FacebookError;
import com.facebook.android.Facebook.DialogListener;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.util.Log;
import android.widget.Toast;
public class TravelPostMain extends PreferenceActivity implements OnPreferenceClickListener {
private static final String SETTINGS = "settings"; //Shared Prefs name
private static final String AUTHORIZED = "authorized"; //key for shared prefs showing how many social sites are added
private static final String FACEBOOK = "Facebook"; //the facebook shared pref
private static final String TWITTER = "Twitter"; //the twitter shared pref
private static final String TAG = "TravelPostMain";
private static PreferenceCategory mSocialSites;
private static SharedPreferences mPrefs;
private static SharedPreferences mFacebookPrefs;
private static Facebook mFb;
private static Context mAppCtx;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Debug.LOGGING)
Log.i(TAG, "onCreate()");
/* Sets default uncaught exception handler */
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
mAppCtx = this.getApplicationContext();
this.initActivity();
}
/**
* This method initializes the xml layout and all variables needed for that layout
*/
private void initActivity() {
if (Debug.LOGGING)
Log.i(TAG, "initActivity()");
this.getPreferenceManager().setSharedPreferencesName(SETTINGS);
this.addPreferencesFromResource(R.xml.travelpostmain);
mFb = new Facebook(this); //it seems dialogs crash when handed an application context. need to use this
mPrefs = this.getSharedPreferences(SETTINGS, 0);
mFacebookPrefs = this.getSharedPreferences(FACEBOOK, 0);
mSocialSites = (PreferenceCategory) this.findPreference("socialsites");
this.findPreference("add_social_site").setOnPreferenceClickListener(this);
}
/**
* Places the preferences for the social sites
*/
protected void initPreferences() {
String[] socialSites = new String[] {FACEBOOK, TWITTER};
/* We only need to create social site preferences if non have been authorized */
if (this.getSharedPreferences(SETTINGS, 0).getInt(AUTHORIZED, 0) > 0) {
/* This for loop searches for available social sites an adds the preference */
for (String site : socialSites) {
/*
* The nested if block below does two things for each social site.
* 1. The outer if block and the else if block first checks which site we are looking at and wether it is authorized
* 2. The inner if blocks check to see if the preference for the corresponding site does not exist.
* If both prove true it creates the preference
*/
if (site.equals(FACEBOOK) && mFacebookPrefs.getBoolean(AUTHORIZED, false)) {
if (mSocialSites.findPreference(mAppCtx.getString(R.string.facebook)) == null) {
createPreference(R.string.facebook);
}
} else if (site.equals(TWITTER) && mAppCtx.getSharedPreferences(TWITTER, 0).getBoolean(AUTHORIZED, false)) {
if (mSocialSites.findPreference(mAppCtx.getString(R.string.twitter)) == null) {
createPreference(R.string.twitter);
}
}
}
}
}
/**
* Will display a prompt asking for what social site to add. Will be called when the add a social site is clicked.
* @author warren
*/
private void displaySocialSitesDialog() {
final CharSequence[] sites = {this.getString(R.string.facebook), this.getString(R.string.twitter)};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(this.getText(R.string.add_social_site));
builder.setItems(sites, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
addSocialSite(sites[item]);
}
});
AlertDialog alert = builder.create();
alert.show();
}
/**
* Adds the site and creates a preference
* @author warren
* @param site
*/
private void addSocialSite(CharSequence site) {
if (Debug.LOGGING)
Log.i(TAG, "addSocialSite.site" + site);
if (site.equals(FACEBOOK)) {
if (this.getSharedPreferences(FACEBOOK, 0).getBoolean(AUTHORIZED, false)) {
Toast.makeText(this, this.getString(R.string.facebook_already_authorized), Toast.LENGTH_LONG);
} else {
mFb.authorize(new LoginDialogListener());
}
} else if (site.equals(TWITTER)) {
}
}
@Override
public void onStart() {
if (Debug.LOGGING)
Log.i(TAG, "onStart()");
initPreferences();
super.onStart();
}
@Override
public void onDestroy() {
if (Debug.LOGGING)
Log.i(TAG, "onDestroy()");
super.onDestroy();
}
@Override
public void onRestart() {
if (Debug.LOGGING)
Log.i(TAG, "onRestart()");
super.onRestart();
}
@Override
public void onPause() {
if (Debug.LOGGING)
Log.i(TAG, "onPause()");
super.onPause();
}
@Override
public void onStop() {
if (Debug.LOGGING)
Log.i(TAG, "onStop()");
super.onStop();
}
@Override
public void onResume() {
if (Debug.LOGGING)
Log.i(TAG, "onResume()");
super.onResume();
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (Debug.LOGGING)
Log.i(TAG, "onPreferenceClick()");
if (preference.getKey().equals("add_social_site")) {
this.displaySocialSitesDialog();
return true;
}
return false;
}
/**
* This method creates a preferences with the given ID under the socialsites preference category.
* It also assigned the onclicklistener
* @param id - auto generated id of title of preference. (ex: R.string.facebook)
*/
protected void createPreference(int id) {
Preference pref = new Preference(mAppCtx);
pref.setTitle(mAppCtx.getString(id));
pref.setKey(mAppCtx.getString(id));
mSocialSites.addPreference(pref);
pref.setOnPreferenceClickListener(this);
}
/**
* Handles facebook login callbacks
* @author warren
*
*/
protected final class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values, Dialog dialog) {
FacebookEvents.onLoginSuccess();
if (Debug.LOGGING)
Log.i(TAG, "LoginDialogListener.onComplete.login success");
SharedPreferences prefs = TravelPostMain.mPrefs;
SharedPreferences fbPrefs = TravelPostMain.mFacebookPrefs;
if (TravelPostMain.mFb.isSessionValid()) {
fbPrefs.edit().putBoolean(TravelPostMain.AUTHORIZED, true).commit();
int auths = prefs.getInt(TravelPostMain.AUTHORIZED, 0);
prefs.edit().putInt(TravelPostMain.AUTHORIZED, auths + 1).commit();
}
TravelPostMain tp = new TravelPostMain();
tp.initPreferences();
}
public void onFacebookError(FacebookError error) {
FacebookEvents.onLoginError(error.getMessage());
if (Debug.LOGGING)
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
}
public void onError(DialogError error) {
FacebookEvents.onLoginError(error.getMessage());
if (Debug.LOGGING)
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
}
public void onCancel() {
FacebookEvents.onLoginError("Action Canceled");
if (Debug.LOGGING)
Log.e(TAG, "LoginDialogListener.login cancelled");
}
}
}

View File

@@ -0,0 +1,70 @@
package com.TwentyCodes.android.TravelPost.UI;
import android.content.Context;
import android.graphics.Typeface;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public class AboutView extends Preference {
public AboutView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public AboutView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AboutView(Context context) {
super(context);
}
/**
* creates a linear layout the contains only a textview.
* (non-Javadoc)
* @see android.preference.Preference#onCreateView(android.view.ViewGroup)
* @param parent
* @return
* @author ricky barrette
*/
@Override
protected View onCreateView(ViewGroup parent){
/*
* create a vertical linear layout that width and height that wraps content
*/
LinearLayout layout = new LinearLayout(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
layout.setPadding(15, 5, 10, 5);
layout.setOrientation(LinearLayout.VERTICAL);
layout.removeAllViews();
/*
* create a textview that will be used to display the title provided in xml
* and add it to the lay out
*/
TextView title = new TextView(getContext());
title.setText(this.getTitle());
title.setTextSize(16);
title.setTypeface(Typeface.SANS_SERIF);
title.setGravity(Gravity.LEFT);
title.setLayoutParams(params);
/*
* add the title and the time picker views to the layout
*/
layout.addView(title);
layout.setId(android.R.id.widget_frame);
return layout;
}
}