created FacebookActivity.java and facebookactivity.xml. this activity is designed to assist with context issues during facebook authorization for the initial authorization.
also modified TravelPostMain.java to fire an intent for this activity. currently works. facebook authorized. saves the settings. only issue is you get a black screen aftwords. if you hit back all is good. TODO: log the onComplete method in facebookactivity to see what is happening. twitter authorization. finish widget and posting to sites.
This commit is contained in:
@@ -1,19 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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" />
|
||||
<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:name=".TravelPostMain"
|
||||
android:label="@string/app_name">
|
||||
<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.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<action
|
||||
android:name="android.intent.action.MAIN" />
|
||||
<category
|
||||
android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".SocialSites.FacebookActivity">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.READ_LOGS"></uses-permission>
|
||||
|
||||
9
TravelPost/ChangeLog.txt
Normal file
9
TravelPost/ChangeLog.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
created FacebookActivity.java and facebookactivity.xml. this activity is designed to assist with context issues during facebook authorization for the initial authorization.
|
||||
also modified TravelPostMain.java to fire an intent for this activity.
|
||||
|
||||
currently works. facebook authorized. saves the settings. only issue is you get a black screen aftwords. if you hit back all is good.
|
||||
|
||||
TODO:
|
||||
log the onComplete method in facebookactivity to see what is happening.
|
||||
twitter authorization.
|
||||
finish widget and posting to sites.
|
||||
@@ -33,7 +33,8 @@ public final class R {
|
||||
public static final int text=0x7f070001;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int powered_by_skyhook=0x7f030000;
|
||||
public static final int facebookactivity=0x7f030000;
|
||||
public static final int powered_by_skyhook=0x7f030001;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int about=0x7f050005;
|
||||
|
||||
@@ -33,7 +33,8 @@ public final class R {
|
||||
public static final int text=0x7f070001;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int powered_by_skyhook=0x7f030000;
|
||||
public static final int facebookactivity=0x7f030000;
|
||||
public static final int powered_by_skyhook=0x7f030001;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int about=0x7f050005;
|
||||
|
||||
@@ -33,7 +33,8 @@ public final class R {
|
||||
public static final int text=0x7f070001;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int powered_by_skyhook=0x7f030000;
|
||||
public static final int facebookactivity=0x7f030000;
|
||||
public static final int powered_by_skyhook=0x7f030001;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int about=0x7f050005;
|
||||
|
||||
@@ -33,7 +33,8 @@ public final class R {
|
||||
public static final int text=0x7f070001;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int powered_by_skyhook=0x7f030000;
|
||||
public static final int facebookactivity=0x7f030000;
|
||||
public static final int powered_by_skyhook=0x7f030001;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int about=0x7f050005;
|
||||
|
||||
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>
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.TwentyCodes.android.TravelPost.SocialSites;
|
||||
|
||||
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;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
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;
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setContentView(R.layout.facebookactivity);
|
||||
|
||||
mSettingsPrefs = this.getSharedPreferences(SETTINGS, 0);
|
||||
mFacebookPrefs = this.getSharedPreferences(FACEBOOK, 0);
|
||||
|
||||
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 void onComplete() {
|
||||
mFb = null;
|
||||
mFacebookPrefs = null;
|
||||
mSettingsPrefs = null;
|
||||
this.finishActivity(RESULT_OK);
|
||||
}
|
||||
|
||||
public void 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 fa = new FacebookActivity();
|
||||
fa.onComplete();
|
||||
}
|
||||
|
||||
public void onFacebookError(FacebookError error) {
|
||||
FacebookEvents.onLoginError(error.getMessage());
|
||||
if (Debug.LOGGING)
|
||||
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
|
||||
}
|
||||
|
||||
public void onError(DialogError error) {
|
||||
FacebookEvents.onLoginError(error.getMessage());
|
||||
if (Debug.LOGGING)
|
||||
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
|
||||
}
|
||||
|
||||
public void onCancel() {
|
||||
FacebookEvents.onLoginError("Action Canceled");
|
||||
if (Debug.LOGGING)
|
||||
Log.e(TAG, "LoginDialogListener.login cancelled");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,9 @@
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
|
||||
import com.TwentyCodes.android.TravelPost.Debug.Debug;
|
||||
import com.TwentyCodes.android.TravelPost.SocialSites.Facebook;
|
||||
import com.TwentyCodes.android.TravelPost.SocialSites.FacebookEvents;
|
||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||
import com.facebook.android.DialogError;
|
||||
import com.facebook.android.FacebookError;
|
||||
import com.facebook.android.Facebook.DialogListener;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
@@ -19,7 +11,9 @@ 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.exception.ExceptionHandler;
|
||||
|
||||
public class TravelPostMain extends PreferenceActivity implements OnPreferenceClickListener {
|
||||
|
||||
@@ -30,9 +24,7 @@ public class TravelPostMain extends PreferenceActivity implements OnPreferenceCl
|
||||
private static final String TAG = "TravelPostMain";
|
||||
|
||||
private static PreferenceCategory mSocialSites;
|
||||
private static SharedPreferences mPrefs;
|
||||
private static SharedPreferences mFacebookPrefs;
|
||||
private static Facebook mFb;
|
||||
private static Context mAppCtx;
|
||||
|
||||
|
||||
@@ -60,8 +52,7 @@ public class TravelPostMain extends PreferenceActivity implements OnPreferenceCl
|
||||
this.getPreferenceManager().setSharedPreferencesName(SETTINGS);
|
||||
this.addPreferencesFromResource(R.xml.travelpostmain);
|
||||
|
||||
mFb = new Facebook(this); //it seems dialogs crash when handed an application context. need to use this
|
||||
mPrefs = this.getSharedPreferences(SETTINGS, 0);
|
||||
this.getSharedPreferences(SETTINGS, 0);
|
||||
mFacebookPrefs = this.getSharedPreferences(FACEBOOK, 0);
|
||||
mSocialSites = (PreferenceCategory) this.findPreference("socialsites");
|
||||
this.findPreference("add_social_site").setOnPreferenceClickListener(this);
|
||||
@@ -125,11 +116,8 @@ public class TravelPostMain extends PreferenceActivity implements OnPreferenceCl
|
||||
Log.i(TAG, "addSocialSite.site" + site);
|
||||
|
||||
if (site.equals(FACEBOOK)) {
|
||||
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());
|
||||
}
|
||||
Intent intent = new Intent(this, com.TwentyCodes.android.TravelPost.SocialSites.FacebookActivity.class);
|
||||
this.startActivityForResult(intent, 0);
|
||||
} else if (site.equals(TWITTER)) {
|
||||
|
||||
}
|
||||
@@ -139,7 +127,7 @@ public class TravelPostMain extends PreferenceActivity implements OnPreferenceCl
|
||||
public void onStart() {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "onStart()");
|
||||
initPreferences();
|
||||
this.initPreferences();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@@ -196,53 +184,12 @@ public class TravelPostMain extends PreferenceActivity implements OnPreferenceCl
|
||||
*/
|
||||
|
||||
protected void createPreference(int id) {
|
||||
if (Debug.LOGGING)
|
||||
Log.i(TAG, "createPreference: " + id);
|
||||
Preference pref = new Preference(mAppCtx);
|
||||
pref.setTitle(mAppCtx.getString(id));
|
||||
pref.setKey(mAppCtx.getString(id));
|
||||
mSocialSites.addPreference(pref);
|
||||
pref.setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
|
||||
SharedPreferences prefs = TravelPostMain.mPrefs;
|
||||
SharedPreferences fbPrefs = TravelPostMain.mFacebookPrefs;
|
||||
if (TravelPostMain.mFb.isSessionValid()) {
|
||||
fbPrefs.edit().putBoolean(TravelPostMain.AUTHORIZED, true).commit();
|
||||
int auths = prefs.getInt(TravelPostMain.AUTHORIZED, 0);
|
||||
prefs.edit().putInt(TravelPostMain.AUTHORIZED, auths + 1).commit();
|
||||
}
|
||||
TravelPostMain tp = new TravelPostMain();
|
||||
tp.initPreferences();
|
||||
}
|
||||
|
||||
public void onFacebookError(FacebookError error) {
|
||||
FacebookEvents.onLoginError(error.getMessage());
|
||||
if (Debug.LOGGING)
|
||||
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
|
||||
}
|
||||
|
||||
public void onError(DialogError error) {
|
||||
FacebookEvents.onLoginError(error.getMessage());
|
||||
if (Debug.LOGGING)
|
||||
Log.e(TAG, "LoginDialogListener.error: " + error.getMessage());
|
||||
}
|
||||
|
||||
public void onCancel() {
|
||||
FacebookEvents.onLoginError("Action Canceled");
|
||||
if (Debug.LOGGING)
|
||||
Log.e(TAG, "LoginDialogListener.login cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user