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:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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