renamed Twitter.java to TwitterServices.java and copied code from original TwitterServices.java (why change what works?)
added thread needed to start twitter authorization to TravelPostMain.java. Created TwitterWebAuth.java and twitterwebauth.xml modified some strings to better explain failure points. tested and working for authorization.
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
android:versionCode="1"
|
android:versionCode="1"
|
||||||
android:versionName="1.0">
|
android:versionName="1.0">
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="7"/>
|
<uses-sdk
|
||||||
|
android:minSdkVersion="7"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:icon="@drawable/icon"
|
android:icon="@drawable/icon"
|
||||||
@@ -22,15 +23,23 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".SocialSites.FacebookActivity">
|
android:name=".SocialSites.FacebookActivity"/>
|
||||||
</activity>
|
<activity
|
||||||
|
android:name=".SocialSites.TwitterWebAuth"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.READ_LOGS"></uses-permission>
|
<uses-permission
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
|
android:name="android.permission.READ_LOGS"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
|
<uses-permission
|
||||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
|
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
|
<uses-permission
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
|
android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
<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>
|
</manifest>
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
added logs to FacebookActivity.onComplete()
|
renamed Twitter.java to TwitterServices.java and copied code from original TwitterServices.java (why change what works?)
|
||||||
|
added thread needed to start twitter authorization to TravelPostMain.java. Created TwitterWebAuth.java and twitterwebauth.xml
|
||||||
|
modified some strings to better explain failure points.
|
||||||
|
|
||||||
onComplete() is being called but still the activity is not finishing. When you hit back it works as expected.
|
tested and working for authorization.
|
||||||
I've tried adding flags to the calling intent, intializing all lifecycle methods and even arranging the order things are called.
|
|
||||||
|
|
||||||
I have tried these intent flags so far:
|
|
||||||
FLAG_ACTIVITY_NO_HISTORY
|
|
||||||
FLAG_ACTIVITY_NEW_TASK
|
|
||||||
FLAG_ACTIVITY_CLEAR_TASK
|
|
||||||
@@ -29,14 +29,18 @@ public final class R {
|
|||||||
public static final int widget=0x7f02000b;
|
public static final int widget=0x7f02000b;
|
||||||
}
|
}
|
||||||
public static final class id {
|
public static final class id {
|
||||||
|
public static final int authCode=0x7f070004;
|
||||||
|
public static final int authOkButton=0x7f070003;
|
||||||
|
public static final int authWebView=0x7f070005;
|
||||||
public static final int skyhook_img=0x7f070000;
|
public static final int skyhook_img=0x7f070000;
|
||||||
public static final int socialsites=0x7f070003;
|
public static final int socialsites=0x7f070006;
|
||||||
public static final int tc_img=0x7f070002;
|
public static final int tc_img=0x7f070002;
|
||||||
public static final int text=0x7f070001;
|
public static final int text=0x7f070001;
|
||||||
}
|
}
|
||||||
public static final class layout {
|
public static final class layout {
|
||||||
public static final int facebookactivity=0x7f030000;
|
public static final int facebookactivity=0x7f030000;
|
||||||
public static final int powered_by_skyhook=0x7f030001;
|
public static final int powered_by_skyhook=0x7f030001;
|
||||||
|
public static final int twitterwebauth=0x7f030002;
|
||||||
}
|
}
|
||||||
public static final class string {
|
public static final class string {
|
||||||
public static final int about=0x7f050005;
|
public static final int about=0x7f050005;
|
||||||
|
|||||||
@@ -29,14 +29,18 @@ public final class R {
|
|||||||
public static final int widget=0x7f02000b;
|
public static final int widget=0x7f02000b;
|
||||||
}
|
}
|
||||||
public static final class id {
|
public static final class id {
|
||||||
|
public static final int authCode=0x7f070004;
|
||||||
|
public static final int authOkButton=0x7f070003;
|
||||||
|
public static final int authWebView=0x7f070005;
|
||||||
public static final int skyhook_img=0x7f070000;
|
public static final int skyhook_img=0x7f070000;
|
||||||
public static final int socialsites=0x7f070003;
|
public static final int socialsites=0x7f070006;
|
||||||
public static final int tc_img=0x7f070002;
|
public static final int tc_img=0x7f070002;
|
||||||
public static final int text=0x7f070001;
|
public static final int text=0x7f070001;
|
||||||
}
|
}
|
||||||
public static final class layout {
|
public static final class layout {
|
||||||
public static final int facebookactivity=0x7f030000;
|
public static final int facebookactivity=0x7f030000;
|
||||||
public static final int powered_by_skyhook=0x7f030001;
|
public static final int powered_by_skyhook=0x7f030001;
|
||||||
|
public static final int twitterwebauth=0x7f030002;
|
||||||
}
|
}
|
||||||
public static final class string {
|
public static final class string {
|
||||||
public static final int about=0x7f050005;
|
public static final int about=0x7f050005;
|
||||||
|
|||||||
@@ -29,14 +29,18 @@ public final class R {
|
|||||||
public static final int widget=0x7f02000b;
|
public static final int widget=0x7f02000b;
|
||||||
}
|
}
|
||||||
public static final class id {
|
public static final class id {
|
||||||
|
public static final int authCode=0x7f070004;
|
||||||
|
public static final int authOkButton=0x7f070003;
|
||||||
|
public static final int authWebView=0x7f070005;
|
||||||
public static final int skyhook_img=0x7f070000;
|
public static final int skyhook_img=0x7f070000;
|
||||||
public static final int socialsites=0x7f070003;
|
public static final int socialsites=0x7f070006;
|
||||||
public static final int tc_img=0x7f070002;
|
public static final int tc_img=0x7f070002;
|
||||||
public static final int text=0x7f070001;
|
public static final int text=0x7f070001;
|
||||||
}
|
}
|
||||||
public static final class layout {
|
public static final class layout {
|
||||||
public static final int facebookactivity=0x7f030000;
|
public static final int facebookactivity=0x7f030000;
|
||||||
public static final int powered_by_skyhook=0x7f030001;
|
public static final int powered_by_skyhook=0x7f030001;
|
||||||
|
public static final int twitterwebauth=0x7f030002;
|
||||||
}
|
}
|
||||||
public static final class string {
|
public static final class string {
|
||||||
public static final int about=0x7f050005;
|
public static final int about=0x7f050005;
|
||||||
|
|||||||
@@ -29,14 +29,18 @@ public final class R {
|
|||||||
public static final int widget=0x7f02000b;
|
public static final int widget=0x7f02000b;
|
||||||
}
|
}
|
||||||
public static final class id {
|
public static final class id {
|
||||||
|
public static final int authCode=0x7f070004;
|
||||||
|
public static final int authOkButton=0x7f070003;
|
||||||
|
public static final int authWebView=0x7f070005;
|
||||||
public static final int skyhook_img=0x7f070000;
|
public static final int skyhook_img=0x7f070000;
|
||||||
public static final int socialsites=0x7f070003;
|
public static final int socialsites=0x7f070006;
|
||||||
public static final int tc_img=0x7f070002;
|
public static final int tc_img=0x7f070002;
|
||||||
public static final int text=0x7f070001;
|
public static final int text=0x7f070001;
|
||||||
}
|
}
|
||||||
public static final class layout {
|
public static final class layout {
|
||||||
public static final int facebookactivity=0x7f030000;
|
public static final int facebookactivity=0x7f030000;
|
||||||
public static final int powered_by_skyhook=0x7f030001;
|
public static final int powered_by_skyhook=0x7f030001;
|
||||||
|
public static final int twitterwebauth=0x7f030002;
|
||||||
}
|
}
|
||||||
public static final class string {
|
public static final class string {
|
||||||
public static final int about=0x7f050005;
|
public static final int about=0x7f050005;
|
||||||
|
|||||||
31
TravelPost/res/layout/twitterwebauth.xml
Normal file
31
TravelPost/res/layout/twitterwebauth.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?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"/>
|
||||||
|
|
||||||
|
<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"
|
||||||
|
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"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<string name="social_site">Social Sites</string>
|
<string name="social_site">Social Sites</string>
|
||||||
<string name="twitter">Twitter</string>
|
<string name="twitter">Twitter</string>
|
||||||
<string name="twitter_already_authorized">Twitter is already authorized.</string>
|
<string name="twitter_already_authorized">Twitter is already authorized.</string>
|
||||||
<string name="twitter_authorization_failure">Unable to authorize Twitter account. Please try again.</string>
|
<string name="twitter_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_exception">We could not connect to Twitter. Please check your connection and try again.</string>
|
||||||
<string name="twitter_signin">Twitter Sign In</string>
|
<string name="twitter_signin">Twitter Sign In</string>
|
||||||
<string name="update">Update</string>
|
<string name="update">Update</string>
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.TwentyCodes.android.TravelPost.SocialSites;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
public class Twitter {
|
|
||||||
|
|
||||||
private Context mCtx;
|
|
||||||
|
|
||||||
public Twitter (Context ctx) {
|
|
||||||
this.mCtx = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void authorize() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package com.TwentyCodes.android.TravelPost.SocialSites;
|
||||||
|
|
||||||
|
import com.TwentyCodes.android.TravelPost.Debug.Debug;
|
||||||
|
|
||||||
|
import twitter4j.Status;
|
||||||
|
import twitter4j.Twitter;
|
||||||
|
import twitter4j.TwitterException;
|
||||||
|
import twitter4j.TwitterFactory;
|
||||||
|
import twitter4j.conf.ConfigurationBuilder;
|
||||||
|
import twitter4j.http.AccessToken;
|
||||||
|
import twitter4j.http.RequestToken;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SharedPreferences.Editor;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convince class for working with the twitter4j API
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public class TwitterServices {
|
||||||
|
|
||||||
|
public static final String TWITTER_AUTH_TOKEN = "twitter_token";
|
||||||
|
public static final String TWITTER_AUTH_SECRET = "twitter_secret";
|
||||||
|
// private static final String TC_TEST_OAUTH_KEY = "CFYYGtuYjEHmwycZIhYS3Q";
|
||||||
|
// 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
|
||||||
|
* @param msg
|
||||||
|
* @throws TwitterException
|
||||||
|
* @author ricky barrette
|
||||||
|
* @return Status
|
||||||
|
*/
|
||||||
|
public static Status tweet(Context context, String msg) throws TwitterException{
|
||||||
|
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);
|
||||||
|
cb.setOAuthConsumerSecret(TRAVEL_PORT_OAUTH_SECRET);
|
||||||
|
cb.setOAuthAccessToken(shared_prefs.getString(TWITTER_AUTH_TOKEN, ""));
|
||||||
|
cb.setOAuthAccessTokenSecret(shared_prefs.getString(TWITTER_AUTH_SECRET, ""));
|
||||||
|
TwitterFactory tf = new TwitterFactory(cb.build());
|
||||||
|
Twitter twitter = tf.getInstance();
|
||||||
|
return twitter.updateStatus(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Authorization URL
|
||||||
|
* @throws TwitterException
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public String getAuthorizationURL() throws TwitterException{
|
||||||
|
requestToken = twitter.getOAuthRequestToken();
|
||||||
|
return requestToken.getAuthorizationURL();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the authorization tokens for future use
|
||||||
|
* @param authorizationCode
|
||||||
|
* @return true if save was successful
|
||||||
|
* @throws TwitterException
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public boolean saveAuthorizationTokens(String authorizationCode) throws TwitterException{
|
||||||
|
AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, authorizationCode);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.TwentyCodes.android.TravelPost.SocialSites;
|
||||||
|
|
||||||
|
import com.TwentyCodes.android.TravelPost.R;
|
||||||
|
|
||||||
|
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 TwitterWebAuth extends Activity implements OnClickListener {
|
||||||
|
private static final String AUTH_URL = "auth_url";
|
||||||
|
private 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.twitterwebauth);
|
||||||
|
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) {
|
||||||
|
setResult(RESULT_OK, new Intent().putExtra(AUTH_CODE, mAuthCode.getText().toString()));
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.TwentyCodes.android.TravelPost;
|
package com.TwentyCodes.android.TravelPost;
|
||||||
|
|
||||||
|
import twitter4j.TwitterException;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@@ -10,8 +13,11 @@ import android.preference.Preference.OnPreferenceClickListener;
|
|||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.TwentyCodes.android.TravelPost.Debug.Debug;
|
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;
|
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||||
|
|
||||||
public class TravelPostMain extends PreferenceActivity implements OnPreferenceClickListener {
|
public class TravelPostMain extends PreferenceActivity implements OnPreferenceClickListener {
|
||||||
@@ -21,9 +27,12 @@ public class TravelPostMain extends PreferenceActivity implements OnPreferenceCl
|
|||||||
private static final String FACEBOOK = "Facebook"; //the facebook shared pref
|
private static final String FACEBOOK = "Facebook"; //the facebook shared pref
|
||||||
private static final String TWITTER = "Twitter"; //the twitter shared pref
|
private static final String TWITTER = "Twitter"; //the twitter shared pref
|
||||||
private static final String TAG = "TravelPostMain";
|
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 PreferenceCategory mSocialSites;
|
||||||
private static SharedPreferences mFacebookPrefs;
|
private static SharedPreferences mFacebookPrefs;
|
||||||
|
private TwitterServices mTwitterServices;
|
||||||
|
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@@ -43,6 +52,34 @@ public class TravelPostMain extends PreferenceActivity implements OnPreferenceCl
|
|||||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
if (Debug.LOGGING)
|
if (Debug.LOGGING)
|
||||||
Log.i(TAG, "onActivityResult()");
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,11 +155,37 @@ public class TravelPostMain extends PreferenceActivity implements OnPreferenceCl
|
|||||||
Log.i(TAG, "addSocialSite.site" + site);
|
Log.i(TAG, "addSocialSite.site" + site);
|
||||||
|
|
||||||
if (site.equals(FACEBOOK)) {
|
if (site.equals(FACEBOOK)) {
|
||||||
Intent intent = new Intent(this.getApplicationContext(), com.TwentyCodes.android.TravelPost.SocialSites.FacebookActivity.class);
|
if (!mFacebookPrefs.getBoolean(AUTHORIZED, false)) {
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
Intent intent = new Intent(this.getApplicationContext(), com.TwentyCodes.android.TravelPost.SocialSites.FacebookActivity.class);
|
||||||
this.startActivityForResult(intent, 1010);
|
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)) {
|
} 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user