created webauth.xml to be used with displaying the web auth site, and allowing the user to input their auth code
i created WebAuth.java to be used to display the social client auth site, and get the users auth code started intergration of twitter
This commit is contained in:
@@ -3,5 +3,8 @@
|
|||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="src" path="gen"/>
|
<classpathentry kind="src" path="gen"/>
|
||||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
|
<classpathentry kind="src" path="FacebookLib_src"/>
|
||||||
|
<classpathentry kind="lib" path="libs/jtwitter.jar"/>
|
||||||
|
<classpathentry kind="lib" path="libs/signpost-core-1.2.1.1.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -30,4 +30,11 @@
|
|||||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
|
<linkedResources>
|
||||||
|
<link>
|
||||||
|
<name>FacebookLib_src</name>
|
||||||
|
<type>2</type>
|
||||||
|
<locationURI>_android_FacebookLib_9c84f9bf/src</locationURI>
|
||||||
|
</link>
|
||||||
|
</linkedResources>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<service android:process=":TravelPostLocationService" android:enabled="true" android:name="LocationService" android:exported="true"></service>
|
<service android:process=":TravelPostLocationService" android:enabled="true" android:name="LocationService" android:exported="true"></service>
|
||||||
|
<activity android:name="WebAuth"></activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="7" />
|
<uses-sdk android:minSdkVersion="7" />
|
||||||
@@ -42,4 +43,5 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></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.WAKE_LOCK"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -9,3 +9,4 @@
|
|||||||
|
|
||||||
# Project target.
|
# Project target.
|
||||||
target=Google Inc.:Google APIs:9
|
target=Google Inc.:Google APIs:9
|
||||||
|
android.library.reference.1=../FacebookLib/
|
||||||
|
|||||||
@@ -11,13 +11,19 @@ public final class R {
|
|||||||
public static final class attr {
|
public static final class attr {
|
||||||
}
|
}
|
||||||
public static final class drawable {
|
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 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 int widgetbutton=0x7f060000;
|
||||||
}
|
}
|
||||||
public static final class layout {
|
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 class string {
|
||||||
public static final int app_name=0x7f050001;
|
public static final int app_name=0x7f050001;
|
||||||
|
|||||||
36
TravelPost/gen/com/facebook/android/R.java
Normal file
36
TravelPost/gen/com/facebook/android/R.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
TravelPost/libs/jtwitter.jar
Normal file
BIN
TravelPost/libs/jtwitter.jar
Normal file
Binary file not shown.
BIN
TravelPost/libs/signpost-core-1.2.1.1.jar
Normal file
BIN
TravelPost/libs/signpost-core-1.2.1.1.jar
Normal file
Binary file not shown.
30
TravelPost/res/layout/webauth.xml
Normal file
30
TravelPost/res/layout/webauth.xml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Ok"
|
||||||
|
android:id="@+id/authOkButton"
|
||||||
|
android:layout_alignBottom="@+id/authCode"
|
||||||
|
android:layout_alignParentRight="true"></Button>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_toLeftOf="@id/authOkButton"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Auth Code"
|
||||||
|
android:id="@+id/authCode">
|
||||||
|
</EditText>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -2,6 +2,10 @@
|
|||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="Travel Post">
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="Travel Post">
|
||||||
<PreferenceCategory android:title="Services">
|
<PreferenceCategory android:title="Services">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:title="Twitter Sign In"
|
||||||
|
android:key="twitter_sign_in"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package com.TwentyCodes.android.TravelPost;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
@@ -17,12 +18,13 @@ import android.os.PowerManager.WakeLock;
|
|||||||
* The broadcast receiver that works with LocationService.java
|
* The broadcast receiver that works with LocationService.java
|
||||||
* @author ricky barrette
|
* @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 ACTION_UPDATE = "TwentyCodes.TravelPost.intent.action.LocationUpdate";
|
||||||
public static final String LOCATION_PARCEL = "location_parcel";
|
public static final String LOCATION_PARCEL = "location_parcel";
|
||||||
private static final String TAG = "LocationReceiver";
|
private static final String TAG = "LocationReceiver";
|
||||||
private WakeLock mWakeLock;
|
private WakeLock mWakeLock;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acquires a wakelock to prevent the device's cpu from sleeping
|
* 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) {
|
private void onLocationUpdate(Location location) {
|
||||||
//TODO something with the location i.e. report location to social services like twitter, ect...
|
//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();
|
removeWakeLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +58,7 @@ public class LocationReceiver extends BroadcastReceiver {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
mContext = context;
|
||||||
acquireWakeLock(context);
|
acquireWakeLock(context);
|
||||||
if(intent.getParcelableExtra(LOCATION_PARCEL) != null){
|
if(intent.getParcelableExtra(LOCATION_PARCEL) != null){
|
||||||
Location location = intent.getParcelableExtra(LOCATION_PARCEL);
|
Location location = intent.getParcelableExtra(LOCATION_PARCEL);
|
||||||
|
|||||||
@@ -6,7 +6,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.TravelPost;
|
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.os.Bundle;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceActivity;
|
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
|
* This activity will be used to gather and store the users settings for the widget using shared_prefs
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class TravelPost extends PreferenceActivity {
|
public class TravelPost extends PreferenceActivity implements OnPreferenceClickListener {
|
||||||
|
|
||||||
private PostMortemReportExceptionHandler mExceptionReport = new PostMortemReportExceptionHandler(this);
|
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
|
* called when the activity is first created
|
||||||
@@ -34,9 +47,52 @@ public class TravelPost extends PreferenceActivity {
|
|||||||
|
|
||||||
// set shared_prefs name
|
// set shared_prefs name
|
||||||
getPreferenceManager().setSharedPreferencesName(SETTINGS);
|
getPreferenceManager().setSharedPreferencesName(SETTINGS);
|
||||||
|
shared_prefs = getPreferenceManager().getSharedPreferences();
|
||||||
|
|
||||||
// load preferences xml
|
// load preferences xml
|
||||||
this.addPreferencesFromResource(R.xml.settings);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user