Compare commits
10 Commits
50f2ffd7a5
...
9c8a0c8696
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c8a0c8696 | ||
|
|
1245960577 | ||
|
|
a2ebf10a3b | ||
|
|
13aec96feb | ||
|
|
d2fa3a0cc6 | ||
|
|
2dee86b00e | ||
|
|
d9520f1302 | ||
|
|
0e8bf9a40e | ||
| 3c1415e059 | |||
| 44e32e4a14 |
@@ -3,13 +3,8 @@
|
||||
<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="libs/twitter4j-core-2.1.11.jar"/>
|
||||
<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="ExceptionHandlerLib_src"/>
|
||||
<classpathentry kind="src" path="FacebookLib_src"/>
|
||||
<classpathentry kind="src" path="LocationLib_src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated by Code Pro -->
|
||||
<entry-points
|
||||
version="1">
|
||||
<explicit-entry-points/>
|
||||
<include-main
|
||||
enabled="true"/>
|
||||
<include-tests
|
||||
enabled="false"/>
|
||||
<include-xml
|
||||
enabled="true"/>
|
||||
</entry-points>
|
||||
@@ -31,15 +31,15 @@
|
||||
<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>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#Sun Jul 17 17:40:10 EDT 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
|
||||
@@ -1,47 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.TwentyCodes.android.TravelPost" android:versionName="0.0.0" android:versionCode="5" android:installLocation="internalOnly">
|
||||
<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:label="@string/app_name"
|
||||
android:configChanges="orientation" android:name="TravelPost">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
|
||||
|
||||
<receiver android:name="LocationReceiver" android:exported="true"
|
||||
android:enabled="true" android:process=":locationreceiver">
|
||||
<intent-filter>
|
||||
<action android:name="TwentyCodes.TravelPost.intent.action.LocationUpdate" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:label="@string/app_name" android:name="TravelPostWidget">
|
||||
<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.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action
|
||||
android:name="android.intent.action.MAIN" />
|
||||
<category
|
||||
android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/travelpostwidgetinfo"/>
|
||||
</receiver>
|
||||
|
||||
<service android:process=":TravelPostLocationService" android:enabled="true" android:exported="true" android:name="com.TwentyCodes.android.location.LocationService"></service>
|
||||
<activity android:name="WebAuth" android:configChanges="orientation"></activity>
|
||||
<activity android:name="PostActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"></activity>
|
||||
</application>
|
||||
|
||||
<uses-sdk android:minSdkVersion="7" />
|
||||
|
||||
<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>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".SocialSites.FacebookActivity"/>
|
||||
<activity
|
||||
android:name=".SocialSites.TwitterWebAuth"/>
|
||||
</application>
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.READ_LOGS"/>
|
||||
<uses-permission
|
||||
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission
|
||||
android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission
|
||||
android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
|
||||
<uses-permission
|
||||
android:name="android.permission.ACCESS_MOCK_LOCATION"/>
|
||||
<uses-permission
|
||||
android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission
|
||||
android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
@@ -1,10 +1,6 @@
|
||||
changed postToWall() to postWall() in FacebookAuth.java.
|
||||
added handling of onclicks for each social site.
|
||||
also handled removal of sites.
|
||||
|
||||
created method postToWall(). this method should post without user interaction
|
||||
also removed locationlib. There are too many issues with skyhook. Since this project does not use skyhook I will handle location internally.
|
||||
|
||||
in FacebookAuth.java i splite the init() method into two. authorize() and logout().
|
||||
|
||||
created postToWallDialog() in FacebookAuth.java to display a dialog when posting to wall.
|
||||
|
||||
t seems the facebook sdk is not saving an access token when trying to make a direct facebook graph request.
|
||||
it does save the access token when calling a dialog but prompts for credentials. i believe the authorization process is failing. not sure why. still researching.
|
||||
had to make a small modification to Add Social Site preference. For some reason the key value changed. works now.
|
||||
@@ -8,8 +8,6 @@
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=Google Inc.:Google APIs:9
|
||||
proguard.config=proguard.cfg
|
||||
android.library.reference.1=../FacebookLib/
|
||||
|
||||
android.library.reference.2=../LocationLib
|
||||
target=Google Inc.:Google APIs:12
|
||||
android.library.reference.1=../ExceptionHandlerLib
|
||||
android.library.reference.2=../FacebookLib
|
||||
|
||||
@@ -8,55 +8,76 @@
|
||||
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 facebook_icon=0x7f020000;
|
||||
public static final int icon=0x7f020001;
|
||||
public static final int logoidea3=0x7f020002;
|
||||
public static final int sign_post_icon=0x7f020003;
|
||||
public static final int sign_post_icon_mod=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 int widget=0x7f02000a;
|
||||
public static final int notification=0x7f020002;
|
||||
public static final int widget=0x7f020003;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int authCode=0x7f060007;
|
||||
public static final int authOkButton=0x7f060006;
|
||||
public static final int authWebView=0x7f060008;
|
||||
public static final int post=0x7f060001;
|
||||
public static final int postOkButton=0x7f060000;
|
||||
public static final int skyhook_img=0x7f060002;
|
||||
public static final int tc_img=0x7f060004;
|
||||
public static final int text=0x7f060003;
|
||||
public static final int widgetbutton=0x7f060005;
|
||||
public static final int authCode=0x7f070001;
|
||||
public static final int authOkButton=0x7f070000;
|
||||
public static final int authWebView=0x7f070002;
|
||||
public static final int socialsites=0x7f070003;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int main=0x7f030000;
|
||||
public static final int post=0x7f030001;
|
||||
public static final int powered_by_skyhook=0x7f030002;
|
||||
public static final int travelpostwidget=0x7f030003;
|
||||
public static final int webauth=0x7f030004;
|
||||
public static final int facebookactivity=0x7f030000;
|
||||
public static final int twitterwebauth=0x7f030001;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int about=0x7f050007;
|
||||
public static final int app_name=0x7f050000;
|
||||
public static final int fb_signin=0x7f050005;
|
||||
public static final int gps_fix=0x7f050001;
|
||||
public static final int hello=0x7f050003;
|
||||
public static final int location_settings=0x7f050006;
|
||||
public static final int post_hint=0x7f05000b;
|
||||
public static final int post_settings=0x7f050008;
|
||||
public static final int save_a_post=0x7f050009;
|
||||
public static final int services=0x7f05000a;
|
||||
public static final int sorry_theres_trouble=0x7f050002;
|
||||
public static final int twitter_signin=0x7f050004;
|
||||
public static final int about=0x7f050002;
|
||||
public static final int about_info=0x7f050003;
|
||||
public static final int about_verify=0x7f050004;
|
||||
public static final int accuracy=0x7f050005;
|
||||
public static final int accuracy_info=0x7f050006;
|
||||
public static final int add_social_site=0x7f050007;
|
||||
public static final int app_name=0x7f050008;
|
||||
public static final int cancel_service=0x7f050009;
|
||||
public static final int check_in_at=0x7f05000a;
|
||||
public static final int clear=0x7f05000b;
|
||||
public static final int crash=0x7f050000;
|
||||
public static final int disable_facebook_checkin=0x7f05000c;
|
||||
public static final int enable_facebook_checkin=0x7f05000d;
|
||||
public static final int facebook=0x7f05000e;
|
||||
public static final int facebook_already_authorized=0x7f05000f;
|
||||
public static final int facebook_authorization_failure=0x7f050010;
|
||||
public static final int facebook_options=0x7f050011;
|
||||
public static final int facebook_session_not_valid=0x7f050012;
|
||||
public static final int fb_signin=0x7f050013;
|
||||
public static final int gathering=0x7f05001a;
|
||||
public static final int loading=0x7f050014;
|
||||
public static final int location_settings=0x7f050015;
|
||||
public static final int poor_data_connection=0x7f05001c;
|
||||
public static final int post_hint=0x7f050016;
|
||||
public static final int post_lenght=0x7f050017;
|
||||
public static final int post_settings=0x7f05001b;
|
||||
public static final int post_to_long=0x7f050018;
|
||||
public static final int posting=0x7f050019;
|
||||
public static final int remove_facebook=0x7f05001d;
|
||||
public static final int remove_facebook_confirmation=0x7f05001e;
|
||||
public static final int remove_site_title=0x7f05001f;
|
||||
public static final int remove_twitter=0x7f050020;
|
||||
public static final int remove_twitter_confirmation=0x7f050021;
|
||||
public static final int save_a_post=0x7f050022;
|
||||
public static final int social_site=0x7f050023;
|
||||
public static final int sorry=0x7f050001;
|
||||
public static final int twitter=0x7f050024;
|
||||
public static final int twitter_already_authorized=0x7f050025;
|
||||
public static final int twitter_authorization_failure=0x7f050026;
|
||||
public static final int twitter_exception=0x7f050027;
|
||||
public static final int twitter_options=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 settings=0x7f040000;
|
||||
public static final int travelpostwidgetinfo=0x7f040001;
|
||||
public static final int travelpostmain=0x7f040000;
|
||||
}
|
||||
}
|
||||
|
||||
83
TravelPost/gen/com/TwentyCodes/android/exception/R.java
Normal file
83
TravelPost/gen/com/TwentyCodes/android/exception/R.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/* 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 facebook_icon=0x7f020000;
|
||||
public static final int icon=0x7f020001;
|
||||
public static final int notification=0x7f020002;
|
||||
public static final int widget=0x7f020003;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int authCode=0x7f070001;
|
||||
public static final int authOkButton=0x7f070000;
|
||||
public static final int authWebView=0x7f070002;
|
||||
public static final int socialsites=0x7f070003;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int facebookactivity=0x7f030000;
|
||||
public static final int twitterwebauth=0x7f030001;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int about=0x7f050002;
|
||||
public static final int about_info=0x7f050003;
|
||||
public static final int about_verify=0x7f050004;
|
||||
public static final int accuracy=0x7f050005;
|
||||
public static final int accuracy_info=0x7f050006;
|
||||
public static final int add_social_site=0x7f050007;
|
||||
public static final int app_name=0x7f050008;
|
||||
public static final int cancel_service=0x7f050009;
|
||||
public static final int check_in_at=0x7f05000a;
|
||||
public static final int clear=0x7f05000b;
|
||||
public static final int crash=0x7f050000;
|
||||
public static final int disable_facebook_checkin=0x7f05000c;
|
||||
public static final int enable_facebook_checkin=0x7f05000d;
|
||||
public static final int facebook=0x7f05000e;
|
||||
public static final int facebook_already_authorized=0x7f05000f;
|
||||
public static final int facebook_authorization_failure=0x7f050010;
|
||||
public static final int facebook_options=0x7f050011;
|
||||
public static final int facebook_session_not_valid=0x7f050012;
|
||||
public static final int fb_signin=0x7f050013;
|
||||
public static final int gathering=0x7f05001a;
|
||||
public static final int loading=0x7f050014;
|
||||
public static final int location_settings=0x7f050015;
|
||||
public static final int poor_data_connection=0x7f05001c;
|
||||
public static final int post_hint=0x7f050016;
|
||||
public static final int post_lenght=0x7f050017;
|
||||
public static final int post_settings=0x7f05001b;
|
||||
public static final int post_to_long=0x7f050018;
|
||||
public static final int posting=0x7f050019;
|
||||
public static final int remove_facebook=0x7f05001d;
|
||||
public static final int remove_facebook_confirmation=0x7f05001e;
|
||||
public static final int remove_site_title=0x7f05001f;
|
||||
public static final int remove_twitter=0x7f050020;
|
||||
public static final int remove_twitter_confirmation=0x7f050021;
|
||||
public static final int save_a_post=0x7f050022;
|
||||
public static final int social_site=0x7f050023;
|
||||
public static final int sorry=0x7f050001;
|
||||
public static final int twitter=0x7f050024;
|
||||
public static final int twitter_already_authorized=0x7f050025;
|
||||
public static final int twitter_authorization_failure=0x7f050026;
|
||||
public static final int twitter_exception=0x7f050027;
|
||||
public static final int twitter_options=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;
|
||||
}
|
||||
}
|
||||
83
TravelPost/gen/com/facebook/android/R.java
Normal file
83
TravelPost/gen/com/facebook/android/R.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/* 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 facebook_icon=0x7f020000;
|
||||
public static final int icon=0x7f020001;
|
||||
public static final int notification=0x7f020002;
|
||||
public static final int widget=0x7f020003;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int authCode=0x7f070001;
|
||||
public static final int authOkButton=0x7f070000;
|
||||
public static final int authWebView=0x7f070002;
|
||||
public static final int socialsites=0x7f070003;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int facebookactivity=0x7f030000;
|
||||
public static final int twitterwebauth=0x7f030001;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int about=0x7f050002;
|
||||
public static final int about_info=0x7f050003;
|
||||
public static final int about_verify=0x7f050004;
|
||||
public static final int accuracy=0x7f050005;
|
||||
public static final int accuracy_info=0x7f050006;
|
||||
public static final int add_social_site=0x7f050007;
|
||||
public static final int app_name=0x7f050008;
|
||||
public static final int cancel_service=0x7f050009;
|
||||
public static final int check_in_at=0x7f05000a;
|
||||
public static final int clear=0x7f05000b;
|
||||
public static final int crash=0x7f050000;
|
||||
public static final int disable_facebook_checkin=0x7f05000c;
|
||||
public static final int enable_facebook_checkin=0x7f05000d;
|
||||
public static final int facebook=0x7f05000e;
|
||||
public static final int facebook_already_authorized=0x7f05000f;
|
||||
public static final int facebook_authorization_failure=0x7f050010;
|
||||
public static final int facebook_options=0x7f050011;
|
||||
public static final int facebook_session_not_valid=0x7f050012;
|
||||
public static final int fb_signin=0x7f050013;
|
||||
public static final int gathering=0x7f05001a;
|
||||
public static final int loading=0x7f050014;
|
||||
public static final int location_settings=0x7f050015;
|
||||
public static final int poor_data_connection=0x7f05001c;
|
||||
public static final int post_hint=0x7f050016;
|
||||
public static final int post_lenght=0x7f050017;
|
||||
public static final int post_settings=0x7f05001b;
|
||||
public static final int post_to_long=0x7f050018;
|
||||
public static final int posting=0x7f050019;
|
||||
public static final int remove_facebook=0x7f05001d;
|
||||
public static final int remove_facebook_confirmation=0x7f05001e;
|
||||
public static final int remove_site_title=0x7f05001f;
|
||||
public static final int remove_twitter=0x7f050020;
|
||||
public static final int remove_twitter_confirmation=0x7f050021;
|
||||
public static final int save_a_post=0x7f050022;
|
||||
public static final int social_site=0x7f050023;
|
||||
public static final int sorry=0x7f050001;
|
||||
public static final int twitter=0x7f050024;
|
||||
public static final int twitter_already_authorized=0x7f050025;
|
||||
public static final int twitter_authorization_failure=0x7f050026;
|
||||
public static final int twitter_exception=0x7f050027;
|
||||
public static final int twitter_options=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;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
-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 * {
|
||||
|
||||
BIN
TravelPost/res/drawable-hdpi/notification.png
Normal file
BIN
TravelPost/res/drawable-hdpi/notification.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
TravelPost/res/drawable-ldpi/notification.png
Normal file
BIN
TravelPost/res/drawable-ldpi/notification.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 618 B |
BIN
TravelPost/res/drawable-mdpi/notification.png
Normal file
BIN
TravelPost/res/drawable-mdpi/notification.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 764 B |
Binary file not shown.
|
Before Width: | Height: | Size: 5.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.5 KiB |
8
TravelPost/res/layout/facebookactivity.xml
Normal file
8
TravelPost/res/layout/facebookactivity.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:alpha="0">
|
||||
</LinearLayout>
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||
|
||||
<RelativeLayout android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#FFFFFF">
|
||||
|
||||
<Button android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@android:string/ok"
|
||||
android:id="@+id/postOkButton"
|
||||
android:layout_alignBottom="@+id/post"
|
||||
android:layout_alignTop="@id/post"
|
||||
android:layout_alignParentRight="true"></Button>
|
||||
|
||||
<EditText android:layout_toLeftOf="@id/postOkButton"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/post_hint"
|
||||
android:id="@id/post">
|
||||
</EditText>
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<ImageButton
|
||||
android:id="@+id/widgetbutton"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:background="@drawable/widget"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent">
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
@@ -8,7 +10,7 @@
|
||||
android:text="Ok"
|
||||
android:id="@+id/authOkButton"
|
||||
android:layout_alignBottom="@+id/authCode"
|
||||
android:layout_alignParentRight="true"></Button>
|
||||
android:layout_alignParentRight="true"/>
|
||||
|
||||
<EditText
|
||||
android:layout_toLeftOf="@id/authOkButton"
|
||||
@@ -16,15 +18,14 @@
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Auth Code"
|
||||
android:id="@+id/authCode">
|
||||
</EditText>
|
||||
android:id="@+id/authCode"
|
||||
android:inputType="number"/>
|
||||
|
||||
<WebView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_above="@id/authCode"
|
||||
android:id="@+id/authWebView"
|
||||
android:layout_alignParentTop="true">
|
||||
</WebView>
|
||||
android:layout_alignParentTop="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
13
TravelPost/res/values/arrays.xml
Normal file
13
TravelPost/res/values/arrays.xml
Normal 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>
|
||||
@@ -1,13 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="hello">Hello World!</string>
|
||||
<string name="app_name">Travel Post</string>
|
||||
<string name="twitter_signin">Twitter Sign In</string>
|
||||
<string name="fb_signin">Facebook Sign In</string>
|
||||
<string name="location_settings">Location Settings</string>
|
||||
<string name="about">About</string>
|
||||
<string name="post_settings">Post Settings</string>
|
||||
<string name="save_a_post">Save a post</string>
|
||||
<string name="services">Social Services</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 characters</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">Remove Twitter</string>
|
||||
<string name="remove_twitter_confirmation">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 or check your Twitter settings.</string>
|
||||
<string name="twitter_exception">We could not connect to Twitter. Please check your connection and try again.</string>
|
||||
<string name="twitter_options">Twitter Options</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>
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/app_name">
|
||||
<PreferenceCategory android:title="@string/post_settings">
|
||||
<CheckBoxPreference android:title="@string/save_a_post" android:key="save_a_post"></CheckBoxPreference>
|
||||
<EditTextPreference android:key="saved_post" android:title="Post" android:dependency="save_a_post"></EditTextPreference>
|
||||
</PreferenceCategory><PreferenceCategory
|
||||
android:title="@string/services">
|
||||
<Preference
|
||||
android:title="@string/twitter_signin"
|
||||
android:key="twitter_sign_in"/>
|
||||
<Preference
|
||||
android:title="@string/fb_signin"
|
||||
android:key="facebook_sign_in"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/location_settings">
|
||||
|
||||
</PreferenceCategory><PreferenceCategory android:title="@string/about">
|
||||
<com.TwentyCodes.android.TravelPost.TextViewPreference android:title="@string/hello"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
31
TravelPost/res/xml/travelpostmain.xml
Normal file
31
TravelPost/res/xml/travelpostmain.xml
Normal 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="@string/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>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="146dip"
|
||||
android:minHeight="72dip"
|
||||
android:updatePeriodMillis="10000"
|
||||
android:initialLayout="@layout/travelpostwidget"/>
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.TwentyCodes.android.Facebook;
|
||||
|
||||
import com.facebook.android.DialogError;
|
||||
import com.facebook.android.Facebook.DialogListener;
|
||||
import com.facebook.android.FacebookError;
|
||||
|
||||
/**
|
||||
* Skeleton base class for RequestListeners, providing default error
|
||||
* handling. Applications should handle these error conditions.
|
||||
*
|
||||
*/
|
||||
public abstract class BaseDialogListener implements DialogListener {
|
||||
|
||||
public void onFacebookError(FacebookError e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void onError(DialogError e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void onCancel() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.TwentyCodes.android.Facebook;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.facebook.android.AsyncFacebookRunner.RequestListener;
|
||||
import com.facebook.android.FacebookError;
|
||||
|
||||
/**
|
||||
* Skeleton base class for RequestListeners, providing default error
|
||||
* handling. Applications should handle these error conditions.
|
||||
*
|
||||
*/
|
||||
public abstract class BaseRequestListener implements RequestListener {
|
||||
|
||||
public void onFacebookError(FacebookError e, final Object state) {
|
||||
Log.e("Facebook", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void onFileNotFoundException(FileNotFoundException e,
|
||||
final Object state) {
|
||||
Log.e("Facebook", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void onIOException(IOException e, final Object state) {
|
||||
Log.e("Facebook", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void onMalformedURLException(MalformedURLException e,
|
||||
final Object state) {
|
||||
Log.e("Facebook", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,263 +0,0 @@
|
||||
package com.TwentyCodes.android.Facebook;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import com.TwentyCodes.android.Facebook.SessionEvents.AuthListener;
|
||||
import com.TwentyCodes.android.Facebook.SessionEvents.LogoutListener;
|
||||
import com.facebook.android.AsyncFacebookRunner;
|
||||
import com.facebook.android.DialogError;
|
||||
import com.facebook.android.Facebook;
|
||||
import com.facebook.android.Facebook.DialogListener;
|
||||
import com.facebook.android.FacebookError;
|
||||
|
||||
/**
|
||||
* This class handles SSO for facebook.
|
||||
* @author warren
|
||||
*
|
||||
*/
|
||||
|
||||
public class FacebookAuth {
|
||||
|
||||
private static final String[] PERMISSIONS = new String[] {"publish_stream"};
|
||||
/* 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 = "FacebookAuth";
|
||||
private Facebook mFb;
|
||||
private AsyncFacebookRunner mAsyncRunner;
|
||||
private Context mCtx;
|
||||
private Activity mActivity;
|
||||
private Handler mHandler;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param Context - context to work in
|
||||
* @param Activity - current displayed activity
|
||||
*/
|
||||
|
||||
public FacebookAuth(Context context, Activity activity) {
|
||||
mCtx = context;
|
||||
mActivity = activity;
|
||||
mHandler = new Handler();
|
||||
mFb = new Facebook(APP_ID);
|
||||
mAsyncRunner = new AsyncFacebookRunner(mFb);
|
||||
SessionStore.restore(mFb, mCtx);
|
||||
SessionEvents.addAuthListener(new FacebookAuthListener());
|
||||
SessionEvents.addLogoutListener(new FacebookLogoutListener());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes the authorization process.
|
||||
*/
|
||||
|
||||
public void init() {
|
||||
Log.i(TAG, "init()");
|
||||
if (mFb.isSessionValid()) {
|
||||
/*
|
||||
*These lines log out you out of facebook. For now commented out.
|
||||
*/
|
||||
// SessionEvents.onLogoutBegin();
|
||||
// mAsyncRunner.logout(mCtx, new LogoutRequestListener());
|
||||
} else {
|
||||
mFb.authorize(mActivity, PERMISSIONS, new LoginDialogListener());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method authorizes the facebook account
|
||||
* @author warren
|
||||
*/
|
||||
|
||||
public void authorize() throws NullPointerException {
|
||||
if (!mFb.isSessionValid()) {
|
||||
mFb.authorize(mActivity, PERMISSIONS, new LoginDialogListener());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method starts the logout process
|
||||
* @author warren
|
||||
*/
|
||||
|
||||
public void logout() {
|
||||
if (mFb.isSessionValid()) {
|
||||
SessionEvents.onLogoutBegin();
|
||||
mAsyncRunner.logout(mCtx, new LogoutRequestListener());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method posts a message to the users wall
|
||||
* @author warren
|
||||
* @param msg - message to post
|
||||
*/
|
||||
|
||||
public void postToWall(String msg) throws SessionNotValidException {
|
||||
Log.d(TAG, "Testing graph API wall post");
|
||||
if (mFb.isSessionValid()) {
|
||||
try {
|
||||
String response = mFb.request("me");
|
||||
Bundle parameters = new Bundle();
|
||||
parameters.putString("message", msg);
|
||||
parameters.putString("description", "test test test");
|
||||
response = mFb.request("me/feed", parameters, "POST");
|
||||
Log.d(TAG, "got response: " + response);
|
||||
if (response == null || response.equals("") || response.equals("false")) {
|
||||
Log.v("Error", "Blank response");
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (mFb.getAccessToken() == null) {
|
||||
Log.i(TAG, "postToWall.access token is null");
|
||||
}
|
||||
throw new SessionNotValidException("This session is not valid");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the user to post to their wall and input their own message
|
||||
* @author warren
|
||||
*/
|
||||
|
||||
public void postToWallDialog() {
|
||||
mFb.dialog(mCtx, "feed", new FacebookDialogListener());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles facebook authorization callbacks.
|
||||
* @author warren
|
||||
*
|
||||
*/
|
||||
|
||||
private class FacebookAuthListener implements AuthListener {
|
||||
|
||||
@Override
|
||||
public void onAuthSucceed() {
|
||||
SessionStore.save(mFb, mCtx);
|
||||
Log.i(TAG, "FacebookAuthListener.onAuthSucceed()");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthFail(String error) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles facebook logout callbacks
|
||||
* @author warren
|
||||
*
|
||||
*/
|
||||
|
||||
private class FacebookLogoutListener implements LogoutListener {
|
||||
|
||||
@Override
|
||||
public void onLogoutBegin() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogoutFinish() {
|
||||
SessionStore.clear(mCtx);
|
||||
Log.i(TAG, "FacebookLogoutListener.logout succeeded");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles facebook login callbacks
|
||||
* @author warren
|
||||
*
|
||||
*/
|
||||
|
||||
private final class LoginDialogListener implements DialogListener {
|
||||
public void onComplete(Bundle values) {
|
||||
SessionEvents.onLoginSuccess();
|
||||
Log.i(TAG, "LoginDialogListener.onComplete.login success");
|
||||
}
|
||||
|
||||
public void onFacebookError(FacebookError error) {
|
||||
SessionEvents.onLoginError(error.getMessage());
|
||||
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
|
||||
}
|
||||
|
||||
public void onError(DialogError error) {
|
||||
SessionEvents.onLoginError(error.getMessage());
|
||||
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
|
||||
}
|
||||
|
||||
public void onCancel() {
|
||||
SessionEvents.onLoginError("Action Canceled");
|
||||
Log.e(TAG, "LoginDialogListener.login cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for requests to log out.
|
||||
* @author warren
|
||||
*
|
||||
*/
|
||||
|
||||
private class LogoutRequestListener extends BaseRequestListener {
|
||||
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() {
|
||||
SessionEvents.onLogoutFinish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for dialogs to post text to wall
|
||||
* @author warren
|
||||
*
|
||||
*/
|
||||
|
||||
public class FacebookDialogListener extends BaseDialogListener {
|
||||
|
||||
public void onComplete(Bundle values) {
|
||||
final String postId = values.getString("post_id");
|
||||
if (postId != null) {
|
||||
Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);
|
||||
mAsyncRunner.request(postId, new WallPostRequestListener());
|
||||
} else {
|
||||
Log.d("Facebook-Example", "No wall post made");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for posts to the wall
|
||||
* @author warren
|
||||
*
|
||||
*/
|
||||
|
||||
public class WallPostRequestListener extends BaseRequestListener {
|
||||
|
||||
public void onComplete(final String response, final Object state) {
|
||||
Log.i(TAG, "WallPostRequestListener.post successful");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the session is valid
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public boolean isSessionValid() {
|
||||
return mFb.isSessionValid();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.TwentyCodes.android.Facebook;
|
||||
|
||||
import android.accounts.AccountsException;
|
||||
|
||||
public class SessionNotValidException extends AccountsException {
|
||||
|
||||
/**
|
||||
* generated id
|
||||
*/
|
||||
private static final long serialVersionUID = 624797017013181185L;
|
||||
|
||||
public SessionNotValidException(String message) {
|
||||
new AccountsException(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.Facebook;
|
||||
|
||||
import com.facebook.android.Facebook;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
|
||||
public class SessionStore {
|
||||
|
||||
private static final String TOKEN = "access_token";
|
||||
private static final String EXPIRES = "expires_in";
|
||||
private static final String KEY = "facebook-session";
|
||||
|
||||
public static boolean save(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(Facebook session, Context context) {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
/**
|
||||
* LocationReceiver.java
|
||||
* @date Jan 21, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
|
||||
import com.TwentyCodes.android.Facebook.FacebookAuth;
|
||||
import com.TwentyCodes.android.Facebook.SessionNotValidException;
|
||||
import com.TwentyCodes.android.location.ReverseGeocoder;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* The broadcast receiver that works with LocationService.java
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class LocationReceiver extends BroadcastReceiver{
|
||||
|
||||
public static final String ACTION_UPDATE = "TwentyCodes.TravelPost.intent.action.LocationUpdate";
|
||||
public static final String LOCATION_PARCEL = "location_parcel";
|
||||
private static final String TAG = "LocationReceiver";
|
||||
private WakeLock mWakeLock;
|
||||
private Context mContext;
|
||||
|
||||
/**
|
||||
* acquires a wakelock to prevent the device's cpu from sleeping
|
||||
* @param context
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void acquireWakeLock(Context context) {
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
||||
mWakeLock.acquire();
|
||||
}
|
||||
|
||||
/**
|
||||
* called when this receiver receives a location update
|
||||
* @param location
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void onLocationUpdate(Location location) {
|
||||
/*
|
||||
* the following is used to load prefs from shared_prefs
|
||||
*/
|
||||
SharedPreferences settings = mContext.getSharedPreferences(TravelPost.SETTINGS, 0);
|
||||
|
||||
//check to see if save a post is enabled, if not use the post the user provide
|
||||
if(settings.getBoolean(TravelPost.SAVE_A_POST, false))
|
||||
postToSocialServices(settings.getString(TravelPost.SAVED_POST, null), location);
|
||||
else {
|
||||
postToSocialServices(settings.getString(TravelPost.USERS_POST, null), location);
|
||||
settings.edit().remove(TravelPost.USERS_POST).commit();
|
||||
}
|
||||
|
||||
removeWakeLock();
|
||||
}
|
||||
|
||||
/**
|
||||
* a convince method to post to social networks
|
||||
* @param string
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void postToSocialServices(String post, Location location) {
|
||||
Log.d(TravelPost.TAG, "Posting: "+ post);
|
||||
|
||||
//generate the post
|
||||
String thePost = ReverseGeocoder.getAddressFromLocation(location) +" : "+ post;
|
||||
|
||||
// TODO check post size, is it greater than 140 chars?
|
||||
|
||||
// TODO Add more social services
|
||||
|
||||
//post to twitter
|
||||
try {
|
||||
Log.d(TravelPost.TAG, TwitterServices.tweet(mContext, thePost).toString());
|
||||
} catch (TwitterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//if there is a facebook authization, then post!
|
||||
if (mContext.getSharedPreferences("facebook-session", 0).getString("access_token", null) != null) {
|
||||
//post to facebook
|
||||
FacebookAuth fbAuth = new FacebookAuth(mContext, new Activity());
|
||||
fbAuth.authorize();
|
||||
try {
|
||||
fbAuth.postToWall(thePost);
|
||||
} catch (SessionNotValidException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there is a location update from the location service.
|
||||
* @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mContext = context;
|
||||
acquireWakeLock(context);
|
||||
if(intent.getParcelableExtra(LOCATION_PARCEL) != null){
|
||||
Location location = intent.getParcelableExtra(LOCATION_PARCEL);
|
||||
onLocationUpdate(location);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* removes the wake lock if there is one held
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void removeWakeLock() {
|
||||
if(mWakeLock.isHeld())
|
||||
mWakeLock.release();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
* PostActivity.java
|
||||
* @date Feb 5, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
|
||||
import com.TwentyCodes.android.location.LocationService;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* This is going to be the activity that is displayed when the travel post widget is clicked.
|
||||
* This genreal feel of this activity is going to be similar to the google search widget activity
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class PostActivity extends Activity implements OnClickListener {
|
||||
|
||||
private EditText mPostEditText;
|
||||
|
||||
/**
|
||||
* called when the activity is first created
|
||||
* (non-Javadoc)
|
||||
* @see android.app.Activity#onCreate(android.os.Bundle)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setContentView(R.layout.post);
|
||||
findViewById(R.id.postOkButton).setOnClickListener(this);
|
||||
mPostEditText = (EditText) findViewById(R.id.post);
|
||||
}
|
||||
|
||||
/**
|
||||
* called when the ok button is pressed
|
||||
* (non-Javadoc)
|
||||
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//store post information to shared_prefs
|
||||
this.getSharedPreferences(TravelPost.SETTINGS, 0).edit().putString(TravelPost.USERS_POST, mPostEditText.getText().toString()).commit();
|
||||
//start the service
|
||||
this.startService(LocationService.getStartServiceIntent(this, LocationReceiver.ACTION_UPDATE));
|
||||
//exit the activity
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
/**
|
||||
* @author Twenty Codes
|
||||
* @author ricky barrette
|
||||
*/
|
||||
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Build;
|
||||
|
||||
/**
|
||||
* The Twenty Codes, LLC Exception handler.<br/>
|
||||
* This exception handler will generate an email with the stacktrace, cause, device & eviroment, and complete logcat <br/> <br/>
|
||||
* to use create a field variable, and add the following lines to your onCreate()
|
||||
* <code> mExceptionReport.run();
|
||||
Thread.setDefaultUncaughtExceptionHandler(mExceptionReport); </code> <br/> <br/>
|
||||
* Don't forget the manifest tag <code>android.permission.READ_LOGS</code>
|
||||
* @author ricky barette
|
||||
*/
|
||||
public class PostMortemReportExceptionHandler implements UncaughtExceptionHandler, Runnable {
|
||||
public static final String ExceptionReportFilename = "postmortem.trace";
|
||||
|
||||
private static final String MSG_SUBJECT_TAG = "Exception Report"; //"app title + this tag" = email subject
|
||||
private static final String MSG_SENDTO = "twentycodes@gmail.com"; //email will be sent to this account
|
||||
//the following may be something you wish to consider localizing
|
||||
private static final String MSG_BODY = "Just click send to help make this application better. "+
|
||||
"No personal information is being sent (you can check by reading the rest of the email).";
|
||||
|
||||
private Thread.UncaughtExceptionHandler mDefaultUEH;
|
||||
private Activity mApp = null;
|
||||
|
||||
public PostMortemReportExceptionHandler(Activity aApp) {
|
||||
mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
|
||||
mApp = aApp;
|
||||
}
|
||||
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
submit(e);
|
||||
//do not forget to pass this exception through up the chain
|
||||
mDefaultUEH.uncaughtException(t,e);
|
||||
}
|
||||
|
||||
public String getDebugReport(Throwable aException) {
|
||||
|
||||
// NumberFormat theFormatter = new DecimalFormat("#0.");
|
||||
//stack trace
|
||||
StackTraceElement[] theStackTrace = aException.getStackTrace();
|
||||
|
||||
StringBuffer report = new StringBuffer();
|
||||
|
||||
report.append("--------- Application ---------\n\n");
|
||||
|
||||
report.append(mApp.getPackageName()+" generated the following exception:\n\n");
|
||||
|
||||
report.append(aException.toString() + "\n\n");
|
||||
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
report.append("--------- Stack trace ---------\n\n");
|
||||
for (int i = 0; i < theStackTrace.length; i++) {
|
||||
report.append(" " + theStackTrace[i].toString() + "\n");
|
||||
}
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
//app environment
|
||||
PackageManager pm = mApp.getPackageManager();
|
||||
PackageInfo pi;
|
||||
try {
|
||||
pi = pm.getPackageInfo(mApp.getPackageName(), 0);
|
||||
} catch (NameNotFoundException eNnf) {
|
||||
//doubt this will ever run since we want info about our own package
|
||||
pi = new PackageInfo();
|
||||
pi.versionName = "unknown";
|
||||
pi.versionCode = 69;
|
||||
}
|
||||
|
||||
Date theDate = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss_zzz");
|
||||
report.append("-------- Environment --------\n");
|
||||
report.append("Time\t="+sdf.format(theDate)+"\n");
|
||||
report.append("Device\t="+Build.FINGERPRINT+"\n");
|
||||
try {
|
||||
Field theMfrField = Build.class.getField("MANUFACTURER");
|
||||
report.append("Make\t="+theMfrField.get(null)+"\n");
|
||||
} catch (SecurityException e) {
|
||||
} catch (NoSuchFieldException e) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
report.append("Device: " + Build.DEVICE + "\n");
|
||||
report.append("Brand: " + Build.BRAND + "\n");
|
||||
report.append("Model: "+Build.MODEL+"\n");
|
||||
report.append("Product: "+Build.PRODUCT+"\n");
|
||||
report.append("App:\t "+mApp.getPackageName()+", version "+pi.versionName+" (build "+pi.versionCode+")\n");
|
||||
report.append("Locale: "+mApp.getResources().getConfiguration().locale.getDisplayName()+"\n");
|
||||
report.append("-----------------------------\n\n");
|
||||
|
||||
report.append("--------- Firmware ---------\n\n");
|
||||
report.append("SDK: " + Build.VERSION.SDK + "\n");
|
||||
report.append("Release: " + Build.VERSION.RELEASE + "\n");
|
||||
report.append("Incremental: " + Build.VERSION.INCREMENTAL + "\n");
|
||||
report.append("Build Id: " + Build.ID + "\n");
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
// If the exception was thrown in a background thread inside
|
||||
// AsyncTask, then the actual exception can be found with getCause
|
||||
report.append("--------- Cause ---------\n\n");
|
||||
Throwable cause = aException.getCause();
|
||||
if (cause != null) {
|
||||
report.append(cause.toString() + "\n\n");
|
||||
theStackTrace = cause.getStackTrace();
|
||||
for (int i = 0; i < theStackTrace.length; i++) {
|
||||
report.append(" " + theStackTrace[i].toString() + "\n");
|
||||
}
|
||||
}
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
report.append("--------- Complete Logcat ---------\n\n");
|
||||
report.append(getLog().toString());
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
report.append("END REPORT");
|
||||
|
||||
return report.toString();
|
||||
}
|
||||
|
||||
protected void saveDebugReport(String aReport) {
|
||||
//save report to file
|
||||
try {
|
||||
FileOutputStream theFile = mApp.openFileOutput(ExceptionReportFilename, Context.MODE_PRIVATE);
|
||||
theFile.write(aReport.getBytes());
|
||||
theFile.close();
|
||||
} catch(IOException ioe) {
|
||||
//error during error report needs to be ignored, do not wish to start infinite loop
|
||||
}
|
||||
}
|
||||
|
||||
public void sendDebugReportToAuthor() {
|
||||
String theLine = "";
|
||||
StringBuffer theTrace = new StringBuffer();
|
||||
try {
|
||||
BufferedReader theReader = new BufferedReader(
|
||||
new InputStreamReader(mApp.openFileInput(ExceptionReportFilename)));
|
||||
while ((theLine = theReader.readLine())!=null) {
|
||||
theTrace.append(theLine+"\n");
|
||||
}
|
||||
if (sendDebugReportToAuthor(theTrace.toString())) {
|
||||
mApp.deleteFile(ExceptionReportFilename);
|
||||
}
|
||||
} catch (FileNotFoundException eFnf) {
|
||||
// nothing to do
|
||||
} catch(IOException eIo) {
|
||||
// not going to report
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean sendDebugReportToAuthor(String aReport) {
|
||||
if (aReport!=null) {
|
||||
Intent theIntent = new Intent(Intent.ACTION_SEND);
|
||||
String theSubject = mApp.getTitle()+" "+MSG_SUBJECT_TAG;
|
||||
String theBody = "\n"+MSG_BODY+"\n\n"+aReport+"\n\n";
|
||||
theIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {MSG_SENDTO});
|
||||
theIntent.putExtra(Intent.EXTRA_TEXT, theBody);
|
||||
theIntent.putExtra(Intent.EXTRA_SUBJECT, theSubject);
|
||||
theIntent.setType("message/rfc822");
|
||||
Boolean hasSendRecipients = (mApp.getPackageManager().queryIntentActivities(theIntent,0).size()>0);
|
||||
if (hasSendRecipients) {
|
||||
mApp.startActivity(theIntent);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
sendDebugReportToAuthor();
|
||||
}
|
||||
|
||||
public void submit(Throwable e) {
|
||||
String theErrReport = getDebugReport(e);
|
||||
saveDebugReport(theErrReport);
|
||||
//try to send file contents via email (need to do so via the UI thread)
|
||||
mApp.runOnUiThread(this);
|
||||
}
|
||||
|
||||
protected StringBuilder getLog(){
|
||||
final StringBuilder log = new StringBuilder();
|
||||
try{
|
||||
Process process = Runtime.getRuntime().exec("logcat -d");
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null){
|
||||
log.append(line);
|
||||
log.append("\n");
|
||||
}
|
||||
}
|
||||
catch (IOException e){
|
||||
}
|
||||
return log;
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.TwentyCodes.android.TravelPost.SocialSites;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.TwentyCodes.android.TravelPost.R;
|
||||
import com.TwentyCodes.android.TravelPost.Debug.Debug;
|
||||
import com.facebook.android.DialogError;
|
||||
import com.facebook.android.Facebook.DialogListener;
|
||||
import com.facebook.android.FacebookError;
|
||||
|
||||
public class FacebookActivity extends Activity {
|
||||
|
||||
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 TAG = "FacebookActivity";
|
||||
private static final String SETTINGS = "settings"; //Shared Prefs name
|
||||
private static SharedPreferences mSettingsPrefs;
|
||||
private static SharedPreferences mFacebookPrefs;
|
||||
private static Facebook mFb;
|
||||
private static Activity mFa;
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setContentView(R.layout.facebookactivity);
|
||||
|
||||
mSettingsPrefs = this.getSharedPreferences(SETTINGS, 0);
|
||||
mFacebookPrefs = this.getSharedPreferences(FACEBOOK, 0);
|
||||
mFa = this;
|
||||
|
||||
mFb = new Facebook(this); //NOTE: facebook auth creates a dialog with this context. If you pass the application context the dialog will crash #fixitgoogle
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
public static void onComplete() {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "onComplete()");
|
||||
mFa.finish();
|
||||
}
|
||||
|
||||
@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 onStart() {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "onStart()");
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestart() {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "onRestart()");
|
||||
super.onRestart();
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "onDestroy()");
|
||||
mFb = null;
|
||||
mFacebookPrefs = null;
|
||||
mSettingsPrefs = null;
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
|
||||
String authorized = FacebookActivity.AUTHORIZED;
|
||||
SharedPreferences prefs = FacebookActivity.mSettingsPrefs;
|
||||
SharedPreferences fbPrefs = FacebookActivity.mFacebookPrefs;
|
||||
|
||||
if (FacebookActivity.mFb.isSessionValid()) {
|
||||
fbPrefs.edit().putBoolean(authorized, true).commit();
|
||||
int auths = prefs.getInt(authorized, 0);
|
||||
prefs.edit().putInt(authorized, auths + 1).commit();
|
||||
}
|
||||
FacebookActivity.onComplete();
|
||||
}
|
||||
|
||||
public void onFacebookError(FacebookError error) {
|
||||
FacebookEvents.onLoginError(error.getMessage());
|
||||
if (Debug.LOGGING)
|
||||
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
|
||||
Toast.makeText(mFa.getApplicationContext(), "Facebook authorization failed. Error: " + error.getMessage(), Toast.LENGTH_LONG).show();
|
||||
FacebookActivity.onComplete();
|
||||
}
|
||||
|
||||
public void onError(DialogError error) {
|
||||
FacebookEvents.onLoginError(error.getMessage());
|
||||
if (Debug.LOGGING)
|
||||
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
|
||||
Toast.makeText(mFa.getApplicationContext(), "Facebook authorization failed. Error: " + error.getMessage(), Toast.LENGTH_LONG).show();
|
||||
FacebookActivity.onComplete();
|
||||
}
|
||||
|
||||
public void onCancel() {
|
||||
FacebookEvents.onLoginError("Action Canceled");
|
||||
if (Debug.LOGGING)
|
||||
Log.e(TAG, "LoginDialogListener.login cancelled");
|
||||
FacebookActivity.onComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -14,16 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.TwentyCodes.android.Facebook;
|
||||
package com.TwentyCodes.android.TravelPost.SocialSites;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class SessionEvents {
|
||||
public class FacebookEvents {
|
||||
|
||||
private static LinkedList<AuthListener> mAuthListeners =
|
||||
new LinkedList<AuthListener>();
|
||||
private static LinkedList<LogoutListener> mLogoutListeners =
|
||||
new LinkedList<LogoutListener>();
|
||||
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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
/**
|
||||
* TwitterServices.java
|
||||
* @date Jan 30, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
package com.TwentyCodes.android.TravelPost.SocialSites;
|
||||
|
||||
import com.TwentyCodes.android.TravelPost.Debug.Debug;
|
||||
|
||||
import twitter4j.Status;
|
||||
import twitter4j.Twitter;
|
||||
@@ -30,10 +26,18 @@ public class TwitterServices {
|
||||
// private static final String TC_TEST_OAUTH_SECRET = "Sf8nUTImllxET4SYriQ6e4YOLK4i8UUmO3x0tcPqhU";
|
||||
private static final String TRAVEL_PORT_OAUTH_KEY = "NkSaLHkkpwMYnXryEKEA";
|
||||
private static final String TRAVEL_PORT_OAUTH_SECRET = "imbqMfZs1nFxxMCtsRLrS3xWm1VOi5uZ3IuOv9iYk";
|
||||
private static final String TAG = "Twitter";
|
||||
private static final String TWITTER = "Twitter";
|
||||
private Twitter twitter;
|
||||
private static SharedPreferences shared_prefs;
|
||||
private RequestToken requestToken;
|
||||
|
||||
public TwitterServices (Context ctx) {
|
||||
shared_prefs = ctx.getSharedPreferences(TWITTER, 0);
|
||||
twitter = new TwitterFactory().getInstance();
|
||||
twitter.setOAuthConsumer(TRAVEL_PORT_OAUTH_KEY, TRAVEL_PORT_OAUTH_SECRET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts a tweet to twitter. <p>
|
||||
* You need to authorize your application first
|
||||
@@ -43,8 +47,9 @@ public class TwitterServices {
|
||||
* @return Status
|
||||
*/
|
||||
public static Status tweet(Context context, String msg) throws TwitterException{
|
||||
shared_prefs = context.getSharedPreferences(TravelPost.SETTINGS, 0);
|
||||
Log.d(TravelPost.TAG, "Tweeting: "+ msg);
|
||||
shared_prefs = context.getSharedPreferences(TWITTER, 0);
|
||||
if (Debug.LOGGING)
|
||||
Log.d(TAG, "Tweeting: "+ msg);
|
||||
ConfigurationBuilder cb = new ConfigurationBuilder();
|
||||
cb.setDebugEnabled(true);
|
||||
cb.setOAuthConsumerKey(TRAVEL_PORT_OAUTH_KEY);
|
||||
@@ -56,17 +61,6 @@ public class TwitterServices {
|
||||
return twitter.updateStatus(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new TwitterServices. <p>
|
||||
* Initialization of this object is only needed for authorization, posting can be done statically once the users tokens are stored.
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public TwitterServices(Context context) {
|
||||
shared_prefs = context.getSharedPreferences(TravelPost.SETTINGS, 0);
|
||||
twitter = new TwitterFactory().getInstance();
|
||||
twitter.setOAuthConsumer(TRAVEL_PORT_OAUTH_KEY, TRAVEL_PORT_OAUTH_SECRET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Authorization URL
|
||||
* @throws TwitterException
|
||||
@@ -86,11 +80,13 @@ public class TwitterServices {
|
||||
*/
|
||||
public boolean saveAuthorizationTokens(String authorizationCode) throws TwitterException{
|
||||
AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, authorizationCode);
|
||||
Log.v(TravelPost.TAG,"saving twitter tokens");
|
||||
if (Debug.LOGGING)
|
||||
Log.v(TAG,"saving twitter tokens");
|
||||
Editor e = shared_prefs.edit();
|
||||
e.putString(TWITTER_AUTH_TOKEN, accessToken.getToken()).commit();
|
||||
e.putString(TWITTER_AUTH_SECRET, accessToken.getTokenSecret()).commit();
|
||||
return e.commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
/**
|
||||
* WebAuth.java
|
||||
* @date Jan 24, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
package com.TwentyCodes.android.TravelPost.SocialSites;
|
||||
|
||||
import com.TwentyCodes.android.TravelPost.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
@@ -18,10 +14,9 @@ import android.widget.EditText;
|
||||
* a simple activity that will be started to display the social client auth code for a result (user entered auth code).
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class WebAuth extends Activity implements OnClickListener {
|
||||
|
||||
public static final String AUTH_URL = "auth_url";
|
||||
public static final String AUTH_CODE = "auth_code";
|
||||
public class TwitterWebAuth extends Activity implements OnClickListener {
|
||||
private static final String AUTH_URL = "auth_url";
|
||||
private static final String AUTH_CODE = "auth_code";
|
||||
private EditText mAuthCode;
|
||||
|
||||
/**
|
||||
@@ -33,7 +28,7 @@ public class WebAuth extends Activity implements OnClickListener {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setContentView(R.layout.webauth);
|
||||
this.setContentView(R.layout.twitterwebauth);
|
||||
WebView webView = (WebView) findViewById(R.id.authWebView);
|
||||
webView.loadUrl(this.getIntent().getStringExtra(AUTH_URL));
|
||||
webView.requestFocus(View.FOCUS_DOWN);
|
||||
@@ -53,4 +48,5 @@ public class WebAuth extends Activity implements OnClickListener {
|
||||
setResult(RESULT_OK, new Intent().putExtra(AUTH_CODE, mAuthCode.getText().toString()));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
/**
|
||||
* TravelPost.java
|
||||
* @date Jan 21, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.TwentyCodes.android.Facebook.FacebookAuth;
|
||||
import com.TwentyCodes.android.location.LocationService;
|
||||
|
||||
/**
|
||||
* Main activity for the Travel Post widget.
|
||||
* This activity will be used to gather and store the users settings for the widget using shared_prefs
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class TravelPost extends PreferenceActivity implements OnPreferenceClickListener {
|
||||
|
||||
private PostMortemReportExceptionHandler mExceptionReport = new PostMortemReportExceptionHandler(this);
|
||||
private TwitterServices mTwitterServices = null;
|
||||
public static final String SETTINGS = "settings";
|
||||
private static final int TWITTER_AUTH_REQUEST_CODE = 0;
|
||||
public static final String TAG = "TravelPost";
|
||||
public static final String SAVED_POST = "saved_post";
|
||||
public static final String SAVE_A_POST = "save_a_post";
|
||||
public static final String USERS_POST = "users_post";
|
||||
private FacebookAuth mFbAuth;
|
||||
|
||||
/**
|
||||
* called when the web auth activity returns its result
|
||||
* (non-Javadoc)
|
||||
* @see android.preference.PreferenceActivity#onActivityResult(int, int, android.content.Intent)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Log.v(TAG, "onActivityResult()");
|
||||
Log.d(TAG, "Request code:"+ requestCode);
|
||||
String authCode = null;
|
||||
if(data != null){
|
||||
authCode = data.getStringExtra(WebAuth.AUTH_CODE);
|
||||
if (authCode != null) {
|
||||
Log.d(TAG, authCode);
|
||||
} else {
|
||||
Log.d(TAG, "onActivityForResult.authCode is null");
|
||||
}
|
||||
} else
|
||||
Log.e(TAG, "WebAuth result was null!!!");
|
||||
|
||||
if(resultCode == Activity.RESULT_OK)
|
||||
switch(requestCode){
|
||||
case TWITTER_AUTH_REQUEST_CODE:
|
||||
try {
|
||||
mTwitterServices.saveAuthorizationTokens(authCode);
|
||||
} catch (TwitterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called when the activity is first created
|
||||
* (non-Javadoc)
|
||||
* @see android.preference.PreferenceActivity#onCreate(android.os.Bundle)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.v(TAG, "onCreate()");
|
||||
|
||||
//set this preference activity to use the settings file we choose.
|
||||
this.getPreferenceManager().setSharedPreferencesName(SETTINGS);
|
||||
|
||||
//start the exception handler
|
||||
mExceptionReport.run();
|
||||
Thread.setDefaultUncaughtExceptionHandler(mExceptionReport);
|
||||
|
||||
// load preferences xml
|
||||
this.addPreferencesFromResource(R.xml.settings);
|
||||
|
||||
this.findPreference("twitter_sign_in").setOnPreferenceClickListener(this);
|
||||
this.findPreference("facebook_sign_in").setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy(){
|
||||
Log.v(TAG, "onDestroy()");
|
||||
updateWidget();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
||||
if (preference.getKey().equals("twitter_sign_in")) {
|
||||
mTwitterServices = new TwitterServices(this);
|
||||
try {
|
||||
this.startActivityForResult(new Intent(this, WebAuth.class).putExtra(WebAuth.AUTH_URL, mTwitterServices.getAuthorizationURL()), TWITTER_AUTH_REQUEST_CODE);
|
||||
} catch (TwitterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (preference.getKey().equals("facebook_sign_in")) {
|
||||
mFbAuth = new FacebookAuth(this, this);
|
||||
mFbAuth.authorize();
|
||||
// try {
|
||||
// mFbAuth.postToWall("Another test");
|
||||
// } catch (SessionNotValidException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the widget
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void updateWidget(){
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
|
||||
ComponentName thisWidget = new ComponentName(this, TravelPostWidget.class);
|
||||
PendingIntent pendingIntent;
|
||||
|
||||
/*
|
||||
* if the save a post option is enabled then go start the service,
|
||||
* else get the users input
|
||||
*/
|
||||
if( this.getSharedPreferences(SETTINGS, 0).getBoolean(TravelPost.SAVE_A_POST, false)){
|
||||
//Create a pending intent to start the location service
|
||||
pendingIntent = PendingIntent.getService(this, 0, LocationService.getStartServiceIntent(this, LocationReceiver.ACTION_UPDATE), 0);
|
||||
} else {
|
||||
//create a pending intent to start the post activity
|
||||
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, PostActivity.class), 0);
|
||||
}
|
||||
|
||||
// Get the layout for the App Widget and attach an on-click listener to the button
|
||||
RemoteViews views = new RemoteViews(this.getPackageName(), R.layout.travelpostwidget);
|
||||
views.setOnClickPendingIntent(R.id.widgetbutton, pendingIntent);
|
||||
|
||||
//send the update to the widget
|
||||
appWidgetManager.updateAppWidget(thisWidget, views);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,395 @@
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
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;
|
||||
|
||||
import com.TwentyCodes.android.TravelPost.Debug.Debug;
|
||||
import com.TwentyCodes.android.TravelPost.SocialSites.TwitterServices;
|
||||
import com.TwentyCodes.android.TravelPost.SocialSites.TwitterWebAuth;
|
||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||
|
||||
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 final String AUTH_URL = "auth_url";
|
||||
private static final String AUTH_CODE = "auth_code";
|
||||
|
||||
private static PreferenceCategory mSocialSites;
|
||||
private static SharedPreferences mFacebookPrefs;
|
||||
private TwitterServices mTwitterServices;
|
||||
|
||||
|
||||
/** 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));
|
||||
|
||||
this.initActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "onActivityResult()");
|
||||
|
||||
SharedPreferences prefs = this.getSharedPreferences(SETTINGS, 0);
|
||||
if (intent != null) { /* This if block is required. If the user hits back while Twitter is being authorized the intent returned is null */
|
||||
String authCode = intent.getStringExtra(AUTH_CODE);
|
||||
boolean authSaved = true;
|
||||
if(resultCode == Activity.RESULT_OK) {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "onActivityResult.RESULT_OK");
|
||||
if (requestCode == 0) {
|
||||
try {
|
||||
mTwitterServices.saveAuthorizationTokens(authCode);
|
||||
} catch (TwitterException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, this.getString(R.string.twitter_authorization_failure), Toast.LENGTH_LONG).show();
|
||||
authSaved = false;
|
||||
}
|
||||
}
|
||||
getSharedPreferences(TWITTER, 0).edit().putBoolean(AUTHORIZED, authSaved).commit();
|
||||
if (authSaved) {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "onActivityResult.authSaved is true");
|
||||
|
||||
int auths = prefs.getInt(AUTHORIZED, 0);
|
||||
prefs.edit().putInt(AUTHORIZED, auths + 1).commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.initPreferences();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
mFacebookPrefs = this.getSharedPreferences(FACEBOOK, 0);
|
||||
mSocialSites = (PreferenceCategory) this.findPreference("socialsites");
|
||||
this.findPreference(this.getString(R.string.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(this.getString(R.string.facebook)) == null) {
|
||||
createPreference(R.string.facebook);
|
||||
}
|
||||
} else if (site.equals(TWITTER) && this.getSharedPreferences(TWITTER, 0).getBoolean(AUTHORIZED, false)) {
|
||||
if (mSocialSites.findPreference(this.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 (!mFacebookPrefs.getBoolean(AUTHORIZED, false)) {
|
||||
Intent intent = new Intent(this.getApplicationContext(), com.TwentyCodes.android.TravelPost.SocialSites.FacebookActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
this.startActivityForResult(intent, 1010);
|
||||
} else {
|
||||
Toast.makeText(this, this.getString(R.string.facebook_already_authorized), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else if (site.equals(TWITTER)) {
|
||||
if (!this.getSharedPreferences(TWITTER, 0).getBoolean(AUTHORIZED, false)) {
|
||||
mTwitterServices = new TwitterServices(this);
|
||||
final ProgressDialog progress = ProgressDialog.show(this, "", this.getText(R.string.loading), true, true);
|
||||
//Connect to twitter in a new thread to prevent ANRs
|
||||
new Thread( new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
android.os.Looper.prepare();
|
||||
try {
|
||||
String url = mTwitterServices.getAuthorizationURL();
|
||||
progress.dismiss();
|
||||
TravelPostMain.this.startActivityForResult(new Intent(TravelPostMain.this, TwitterWebAuth.class).putExtra(TravelPostMain.AUTH_URL, url), 0);
|
||||
} catch (TwitterException e) {
|
||||
e.printStackTrace();
|
||||
/* This can be thrown due to invalid authorization to Twitter (bad password or auth code??) */
|
||||
progress.dismiss();
|
||||
Toast.makeText(TravelPostMain.this, TravelPostMain.this.getString(R.string.twitter_exception), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
} else {
|
||||
Toast.makeText(this, this.getString(R.string.twitter_already_authorized), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "onStart()");
|
||||
this.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(this.getString(R.string.add_social_site))) {
|
||||
this.displaySocialSitesDialog();
|
||||
return true;
|
||||
} else if (preference.getKey().equals(this.getString(R.string.facebook))) {
|
||||
this.facebookDialog();
|
||||
return true;
|
||||
} else if (preference.getKey().equals(this.getString(R.string.twitter))) {
|
||||
this.twitterDialog();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dialog displayed when the facebook selection is picked. allows the user to post to wall/checkin, and remove facebook
|
||||
*/
|
||||
|
||||
private void facebookDialog() {
|
||||
final SharedPreferences prefs = mFacebookPrefs;
|
||||
CharSequence[] options;
|
||||
if (prefs.getBoolean("checkin", true)) {
|
||||
options = new CharSequence[] {this.getString(R.string.disable_facebook_checkin), this.getString(R.string.remove_facebook)};
|
||||
} else {
|
||||
options = new CharSequence[] {this.getString(R.string.enable_facebook_checkin), this.getString(R.string.remove_facebook)};
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(this.getString(R.string.facebook_options));
|
||||
builder.setItems(options, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0:
|
||||
if (prefs.getBoolean("checkin", true)) {
|
||||
prefs.edit().putBoolean("checkin", false).commit();
|
||||
} else {
|
||||
prefs.edit().putBoolean("checkin", true).commit();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
removeSiteDialog(R.string.remove_facebook_confirmation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method prompts the user for confirmation of removal of social site
|
||||
* @param id - the id used to confirm removal of site. ex: R.string.remove_twitter_confirmaiton
|
||||
*/
|
||||
|
||||
private void removeSiteDialog(final int id) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(this.getString(R.string.remove_site_title));
|
||||
builder.setMessage(this.getString(id));
|
||||
builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
switch (id) {
|
||||
case (R.string.remove_twitter_confirmation):
|
||||
removeSite(R.string.twitter);
|
||||
break;
|
||||
case (R.string.remove_facebook_confirmation):
|
||||
removeSite(R.string.facebook);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method removes the shared prefs and preference for the given social site.
|
||||
* @param id - R id given to preference when site was created
|
||||
*/
|
||||
|
||||
private void removeSite(int id) {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "removeSite.site: " + this.getString(id));
|
||||
SharedPreferences prefSettings = this.getSharedPreferences(SETTINGS, 0);
|
||||
int auth = 0;
|
||||
switch (id) {
|
||||
case R.string.facebook:
|
||||
auth = prefSettings.getInt(AUTHORIZED, 1);
|
||||
prefSettings.edit().putInt(AUTHORIZED, auth - 1).commit();
|
||||
mFacebookPrefs.edit().clear().commit();
|
||||
this.getSharedPreferences("facebook-session", 0).edit().clear().commit();
|
||||
this.deleteDatabase("webviewCache.db");
|
||||
this.deleteDatabase("webview.db");
|
||||
break;
|
||||
case R.string.twitter:
|
||||
auth = prefSettings.getInt(AUTHORIZED, 1);
|
||||
prefSettings.edit().putInt(AUTHORIZED, auth - 1).commit();
|
||||
this.getSharedPreferences(TWITTER, 0).edit().clear().commit();
|
||||
break;
|
||||
}
|
||||
this.removePreference(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dialog displayed when the twitter selection is picked. allows the user to remove the feature
|
||||
*/
|
||||
|
||||
private void twitterDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(this.getString(R.string.twitter_options));
|
||||
builder.setItems(new CharSequence[] {this.getString(R.string.remove_twitter)}, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
removeSiteDialog(R.string.remove_twitter_confirmation);
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* removes a given preference from the social sites preference category
|
||||
* @param id of the preference
|
||||
*/
|
||||
|
||||
private void removePreference(int id) {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "removePreference: " + this.getString(id));
|
||||
mSocialSites.removePreference(findPreference(this.getString(id)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
||||
private void createPreference(int id) {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "createPreference: " + this.getString(id));
|
||||
Preference pref = new Preference(this);
|
||||
pref.setTitle(this.getString(id));
|
||||
pref.setKey(this.getString(id));
|
||||
mSocialSites.addPreference(pref);
|
||||
pref.setOnPreferenceClickListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/**
|
||||
* TravelPostWidget.java
|
||||
* @date Jan, 15, 2011
|
||||
* @author warren powers
|
||||
*/
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.TwentyCodes.android.location.LocationService;
|
||||
|
||||
/**
|
||||
* This class will display the widget on the android screen and handle user interaction
|
||||
* @author warren
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class TravelPostWidget extends AppWidgetProvider {
|
||||
|
||||
/**
|
||||
* Set to true when the application is being debugged.
|
||||
*/
|
||||
private static final boolean DEBUG = true;
|
||||
public final String TAG = "TravelPostWidget";
|
||||
|
||||
/**
|
||||
* Called in response to the ACTION_APPWIDGET_UPDATE broadcast when this AppWidget provider is being asked to provide RemoteViews for a set of AppWidgets.
|
||||
* Override this method to implement your own AppWidget functionality.
|
||||
* @see android.appwidget.AppWidgetProvider#onUpdate(android.content.Context, android.appwidget.AppWidgetManager, int[])
|
||||
* @param context
|
||||
* @param appWidgetManager
|
||||
* @param appWidgetIds
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
if(DEBUG)
|
||||
Log.v(TAG, "onUpdate()");
|
||||
final int N = appWidgetIds.length;
|
||||
|
||||
/*
|
||||
* the following is used to load widget prefs from shared_prefs
|
||||
*/
|
||||
SharedPreferences settings = context.getSharedPreferences(TravelPost.SETTINGS, 0);
|
||||
|
||||
// Perform this loop procedure for each App Widget that belongs to this provider
|
||||
for (int i=0; i<N; i++) {
|
||||
int appWidgetId = appWidgetIds[i];
|
||||
|
||||
PendingIntent pendingIntent;
|
||||
|
||||
/*
|
||||
* if the save a post option is enabled then go start the service,
|
||||
* else get the users input
|
||||
*/
|
||||
if( settings.getBoolean(TravelPost.SAVE_A_POST, false)){
|
||||
//Create a pending intent to start the location service
|
||||
pendingIntent = PendingIntent.getService(context, 0, LocationService.getStartServiceIntent(context, LocationReceiver.ACTION_UPDATE), 0);
|
||||
} else {
|
||||
//create a pending intent to start the post activity
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, PostActivity.class), 0);
|
||||
}
|
||||
|
||||
// Get the layout for the App Widget and attach an on-click listener to the button
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.travelpostwidget);
|
||||
views.setOnClickPendingIntent(R.id.widgetbutton, pendingIntent);
|
||||
|
||||
// Tell the AppWidgetManager to perform an update on the current App Widget
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
}
|
||||
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements onReceive(Context, Intent) to dispatch calls to the various other methods on AppWidgetProvider.
|
||||
* (non-Javadoc)
|
||||
* @see android.appwidget.AppWidgetProvider#onReceive(android.content.Context, android.content.Intent)
|
||||
* @param context
|
||||
* @param intent received
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if(DEBUG)
|
||||
Log.v(TAG, "onReceive");
|
||||
// v1.5 fix that doesn't call onDelete Action
|
||||
final String action = intent.getAction();
|
||||
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
|
||||
final int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
this.onDeleted(context, new int[] { appWidgetId });
|
||||
}
|
||||
} else {
|
||||
super.onReceive(context, intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in response to the ACTION_APPWIDGET_DELETED broadcast when one or more AppWidget instances have been deleted.
|
||||
* Override this method to implement your own AppWidget functionality.
|
||||
* (non-Javadoc)
|
||||
* @see android.appwidget.AppWidgetProvider#onDeleted(android.content.Context, int[])
|
||||
* @param context
|
||||
* @param appWidgetIds
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onDeleted(Context context, int[] appWidgetIds) {
|
||||
if(DEBUG)
|
||||
Log.v(TAG, "onDelete()");
|
||||
super.onDeleted(context, appWidgetIds);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
/**
|
||||
* @author Twenty Codes
|
||||
* @author ricky barrette
|
||||
*/
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
package com.TwentyCodes.android.TravelPost.UI;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
@@ -14,41 +10,21 @@ import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* this class will be a simple TextView to be used in a preference activity. you set the text using the set title tag
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class TextViewPreference extends Preference {
|
||||
public class AboutView extends Preference {
|
||||
|
||||
/**
|
||||
* creates a preference that is nothing but a text view
|
||||
* @param context
|
||||
*/
|
||||
public TextViewPreference(Context context) {
|
||||
super(context);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a preference that is nothing but a text view
|
||||
* @param context
|
||||
* @param attrs
|
||||
*/
|
||||
public TextViewPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a preference that is nothing but a text view
|
||||
* @param context
|
||||
* @param attrs
|
||||
* @param defStyle
|
||||
*/
|
||||
public TextViewPreference(Context context, AttributeSet attrs, int defStyle) {
|
||||
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)
|
||||
@@ -76,7 +52,7 @@ public class TextViewPreference extends Preference {
|
||||
* and add it to the lay out
|
||||
*/
|
||||
TextView title = new TextView(getContext());
|
||||
title.setText(getTitle());
|
||||
title.setText(this.getTitle());
|
||||
title.setTextSize(16);
|
||||
title.setTypeface(Typeface.SANS_SERIF);
|
||||
title.setGravity(Gravity.LEFT);
|
||||
@@ -90,4 +66,5 @@ public class TextViewPreference extends Preference {
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user