diff --git a/TravelPost/.classpath b/TravelPost/.classpath
index 609aa00..765e3f7 100644
--- a/TravelPost/.classpath
+++ b/TravelPost/.classpath
@@ -3,5 +3,8 @@
+
+
+
diff --git a/TravelPost/.project b/TravelPost/.project
index ee1f480..09a8d0b 100644
--- a/TravelPost/.project
+++ b/TravelPost/.project
@@ -30,4 +30,11 @@
com.android.ide.eclipse.adt.AndroidNatureorg.eclipse.jdt.core.javanature
+
+
+ FacebookLib_src
+ 2
+ _android_FacebookLib_9c84f9bf/src
+
+
diff --git a/TravelPost/AndroidManifest.xml b/TravelPost/AndroidManifest.xml
index cdf2248..3a0da7e 100644
--- a/TravelPost/AndroidManifest.xml
+++ b/TravelPost/AndroidManifest.xml
@@ -31,6 +31,7 @@
+
@@ -42,4 +43,5 @@
+
\ No newline at end of file
diff --git a/TravelPost/default.properties b/TravelPost/default.properties
index 77f7ad7..9e9f836 100644
--- a/TravelPost/default.properties
+++ b/TravelPost/default.properties
@@ -9,3 +9,4 @@
# Project target.
target=Google Inc.:Google APIs:9
+android.library.reference.1=../FacebookLib/
diff --git a/TravelPost/gen/com/TwentyCodes/android/TravelPost/R.java b/TravelPost/gen/com/TwentyCodes/android/TravelPost/R.java
index 5ab2385..70840b7 100644
--- a/TravelPost/gen/com/TwentyCodes/android/TravelPost/R.java
+++ b/TravelPost/gen/com/TwentyCodes/android/TravelPost/R.java
@@ -11,13 +11,19 @@ public final class R {
public static final class attr {
}
public static final class drawable {
- public static final int icon=0x7f020000;
+ public static final int facebook_icon=0x7f020000;
+ public static final int icon=0x7f020001;
}
public static final class id {
+ public static final int authCode=0x7f060002;
+ public static final int authOkButton=0x7f060001;
+ public static final int authWebView=0x7f060003;
public static final int widgetbutton=0x7f060000;
}
public static final class layout {
- public static final int travelpostwidget=0x7f030000;
+ public static final int main=0x7f030000;
+ public static final int travelpostwidget=0x7f030001;
+ public static final int webauth=0x7f030002;
}
public static final class string {
public static final int app_name=0x7f050001;
diff --git a/TravelPost/gen/com/facebook/android/R.java b/TravelPost/gen/com/facebook/android/R.java
new file mode 100644
index 0000000..1f5e654
--- /dev/null
+++ b/TravelPost/gen/com/facebook/android/R.java
@@ -0,0 +1,36 @@
+/* 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 attr {
+ }
+ public static final class drawable {
+ public static final int facebook_icon=0x7f020000;
+ public static final int icon=0x7f020001;
+ }
+ public static final class id {
+ public static final int authCode=0x7f060002;
+ public static final int authOkButton=0x7f060001;
+ public static final int authWebView=0x7f060003;
+ public static final int widgetbutton=0x7f060000;
+ }
+ public static final class layout {
+ public static final int main=0x7f030000;
+ public static final int travelpostwidget=0x7f030001;
+ public static final int webauth=0x7f030002;
+ }
+ public static final class string {
+ public static final int app_name=0x7f050001;
+ public static final int hello=0x7f050000;
+ }
+ public static final class xml {
+ public static final int settings=0x7f040000;
+ public static final int travelpostwidgetinfo=0x7f040001;
+ }
+}
diff --git a/TravelPost/libs/jtwitter.jar b/TravelPost/libs/jtwitter.jar
new file mode 100644
index 0000000..7f35149
Binary files /dev/null and b/TravelPost/libs/jtwitter.jar differ
diff --git a/TravelPost/libs/signpost-core-1.2.1.1.jar b/TravelPost/libs/signpost-core-1.2.1.1.jar
new file mode 100644
index 0000000..59e7537
Binary files /dev/null and b/TravelPost/libs/signpost-core-1.2.1.1.jar differ
diff --git a/TravelPost/res/layout/webauth.xml b/TravelPost/res/layout/webauth.xml
new file mode 100644
index 0000000..017861b
--- /dev/null
+++ b/TravelPost/res/layout/webauth.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TravelPost/res/xml/settings.xml b/TravelPost/res/xml/settings.xml
index f32953d..3990646 100644
--- a/TravelPost/res/xml/settings.xml
+++ b/TravelPost/res/xml/settings.xml
@@ -1,6 +1,10 @@
+
+
diff --git a/TravelPost/src/com/TwentyCodes/android/TravelPost/LocationReceiver.java b/TravelPost/src/com/TwentyCodes/android/TravelPost/LocationReceiver.java
index f6ecc4b..e1088d2 100644
--- a/TravelPost/src/com/TwentyCodes/android/TravelPost/LocationReceiver.java
+++ b/TravelPost/src/com/TwentyCodes/android/TravelPost/LocationReceiver.java
@@ -9,6 +9,7 @@ package com.TwentyCodes.android.TravelPost;
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;
@@ -17,12 +18,13 @@ import android.os.PowerManager.WakeLock;
* The broadcast receiver that works with LocationService.java
* @author ricky barrette
*/
-public class LocationReceiver extends BroadcastReceiver {
+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
@@ -42,6 +44,10 @@ public class LocationReceiver extends BroadcastReceiver {
*/
private void onLocationUpdate(Location location) {
//TODO something with the location i.e. report location to social services like twitter, ect...
+ SharedPreferences shared_prefs = mContext.getSharedPreferences(TravelPost.SETTINGS, Context.MODE_PRIVATE);
+ TravelPost.tweet(shared_prefs.getString(TravelPost.TWITTER_AUTH_CODE, ""), "yellow_jk", location.toString());
+
+
removeWakeLock();
}
@@ -52,6 +58,7 @@ public class LocationReceiver extends BroadcastReceiver {
*/
@Override
public void onReceive(Context context, Intent intent) {
+ mContext = context;
acquireWakeLock(context);
if(intent.getParcelableExtra(LOCATION_PARCEL) != null){
Location location = intent.getParcelableExtra(LOCATION_PARCEL);
@@ -68,4 +75,4 @@ public class LocationReceiver extends BroadcastReceiver {
mWakeLock.release();
}
-}
+}
\ No newline at end of file
diff --git a/TravelPost/src/com/TwentyCodes/android/TravelPost/TravelPost.java b/TravelPost/src/com/TwentyCodes/android/TravelPost/TravelPost.java
index 3988959..0a847ab 100644
--- a/TravelPost/src/com/TwentyCodes/android/TravelPost/TravelPost.java
+++ b/TravelPost/src/com/TwentyCodes/android/TravelPost/TravelPost.java
@@ -6,7 +6,14 @@
*/
package com.TwentyCodes.android.TravelPost;
+import winterwell.jtwitter.OAuthSignpostClient;
+import winterwell.jtwitter.Twitter;
+import android.app.Activity;
+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;
/**
@@ -14,10 +21,16 @@ import android.preference.PreferenceActivity;
* 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 {
+public class TravelPost extends PreferenceActivity implements OnPreferenceClickListener {
private PostMortemReportExceptionHandler mExceptionReport = new PostMortemReportExceptionHandler(this);
- private static final String SETTINGS = "settings";
+ private static SharedPreferences shared_prefs;
+ public static final String SETTINGS = "settings";
+ private static final int TWITTER_AUTH_REQUEST_CODE = 0;
+ public static final String TWITTER_AUTH_CODE = "twitter";
+ private static final String TC_TEST_OAUTH_KEY = "SSO8Vpy2Ecmc3BjvtwoRw";
+ private static final String TC_TEST_OAUTH_SECRET = "aa6t6N0wlenvbWzU7fZbrhgzmEmUl5s7zGRbbKoU";
+
/**
* called when the activity is first created
@@ -34,9 +47,52 @@ public class TravelPost extends PreferenceActivity {
// set shared_prefs name
getPreferenceManager().setSharedPreferencesName(SETTINGS);
+ shared_prefs = getPreferenceManager().getSharedPreferences();
// load preferences xml
this.addPreferencesFromResource(R.xml.settings);
+
+ this.findPreference("twitter_sign_in").setOnPreferenceClickListener(this);
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ OAuthSignpostClient client = new OAuthSignpostClient(TC_TEST_OAUTH_KEY, TC_TEST_OAUTH_SECRET, "oob");
+ this.startActivityForResult(new Intent(this, WebAuth.class).putExtra(WebAuth.AUTH_URL, client.authorizeUrl().toString()), TWITTER_AUTH_REQUEST_CODE);
+ return false;
+ }
+
+ /**
+ * 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) {
+ if(resultCode == Activity.RESULT_OK)
+ switch(requestCode){
+ case TWITTER_AUTH_REQUEST_CODE:
+ shared_prefs.edit().putString(TWITTER_AUTH_CODE, data.getStringExtra(WebAuth.AUTH_CODE)).commit();
+
+ //FOR TESTING
+// OAuthSignpostClient client = new OAuthSignpostClient(TC_TEST_OAUTH_KEY, TC_TEST_OAUTH_SECRET, "oob");
+// client.setAuthorizationCode(data.getStringExtra(WebAuth.AUTH_CODE));
+// Twitter twitter = new Twitter("yellow_jk", client);
+// // Optional: store the authorisation token details
+// Object accessToken = client.getAccessToken();
+//
+// // use the API!
+// twitter.setStatus("test");
+ break;
+ }
+ }
+
+ public static void tweet(String authCode, String userName, String msg){
+ OAuthSignpostClient client = new OAuthSignpostClient(TC_TEST_OAUTH_KEY, TC_TEST_OAUTH_SECRET, "oob");
+ Twitter jtwit = new Twitter(userName, client);
+ client.setAuthorizationCode(authCode);
+ jtwit.setStatus(msg);
}
}
\ No newline at end of file
diff --git a/TravelPost/src/com/TwentyCodes/android/TravelPost/WebAuth.java b/TravelPost/src/com/TwentyCodes/android/TravelPost/WebAuth.java
new file mode 100644
index 0000000..8997609
--- /dev/null
+++ b/TravelPost/src/com/TwentyCodes/android/TravelPost/WebAuth.java
@@ -0,0 +1,56 @@
+/**
+ * WebAuth.java
+ * @date Jan 24, 2011
+ * @author ricky barrette
+ * @author Twenty Codes, LLC
+ */
+package com.TwentyCodes.android.TravelPost;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.webkit.WebView;
+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";
+ private EditText mAuthCode;
+
+ /**
+ * 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.webauth);
+ WebView webView = (WebView) findViewById(R.id.authWebView);
+ webView.loadUrl(this.getIntent().getStringExtra(AUTH_URL));
+ webView.requestFocus(View.FOCUS_DOWN);
+
+ findViewById(R.id.authOkButton).setOnClickListener(this);
+ mAuthCode = (EditText) findViewById(R.id.authCode);
+ }
+
+ /**
+ * called when the ok button is clicked
+ * (non-Javadoc)
+ * @see android.view.View.OnClickListener#onClick(android.view.View)
+ * @author ricky barrette
+ */
+ @Override
+ public void onClick(View v) {
+ this.setResult(RESULT_OK, new Intent().putExtra(AUTH_CODE, mAuthCode.getText().toString()));
+ this.finish();
+ }
+}
\ No newline at end of file