diff --git a/.metadata/.lock b/.metadata/.lock new file mode 100644 index 0000000..e69de29 diff --git a/.metadata/.plugins/org.eclipse.cdt.core/proj.android.1392888541642.pdom b/.metadata/.plugins/org.eclipse.cdt.core/proj.android.1392888541642.pdom new file mode 100644 index 0000000..9a9a71b Binary files /dev/null and b/.metadata/.plugins/org.eclipse.cdt.core/proj.android.1392888541642.pdom differ diff --git a/.metadata/.plugins/org.eclipse.cdt.make.core/specs.c b/.metadata/.plugins/org.eclipse.cdt.make.core/specs.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.cdt.make.core/specs.c @@ -0,0 +1 @@ + diff --git a/.metadata/.plugins/org.eclipse.cdt.make.core/specs.cpp b/.metadata/.plugins/org.eclipse.cdt.make.core/specs.cpp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.cdt.make.core/specs.cpp @@ -0,0 +1 @@ + diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/14/50ae9f3abd9d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/14/50ae9f3abd9d00131dfa83034257a068 new file mode 100644 index 0000000..38e0abb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/14/50ae9f3abd9d00131dfa83034257a068 @@ -0,0 +1,151 @@ +package org.cocos.fbtutorial; + +import java.util.Arrays; +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import com.facebook.Request; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; + +public class FacebookConnectPlugin { + private static final String TAG = "FacebookPlugin"; + private static FacebookConnectPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private static int callIndex; + public FacebookConnectPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public static void login(int cbIndex, String scope) { + callIndex = cbIndex; + instance.login_(); + } + + public void login_() { + + Session session = Session.getActiveSession(); + if (!session.isOpened() && !session.isClosed()) { + session.openForRead(new Session.OpenRequest(activity) + .setPermissions(Arrays.asList("basic_info")).setCallback( + statusCallback)); + } else { + Session.openActiveSession(activity, true, statusCallback); + } + } + public static void logout(int cbIndex) { + instance.logout_(); + callIndex = cbIndex; + } + + public void logout_() { + Session session = Session.getActiveSession(); + if (!session.isClosed()) { + session.closeAndClearTokenInformation(); + } + } + public static String getStatus(int cbIndex) { + + callIndex = cbIndex; + + return instance.getStatus_(); + } + + public String getStatus_() { + + Session session = Session.getActiveSession(); + + if (session.getState().equals(SessionState.CREATED)) + { + return "CREATED"; + } + else if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) + { + return "CREATED_TOKEN_LOADED"; + } + else if (session.getState().equals(SessionState.OPENING)) + { + return "OPENING"; + } + else if (session.getState().equals(SessionState.OPENED)) + { + return "OPENED"; + } + else if (session.getState().equals(SessionState.OPENED_TOKEN_UPDATED)) + { + return "OPENED_TOKEN_UPDATED"; + } + else if (session.getState().equals(SessionState.CLOSED_LOGIN_FAILED)) + { + return "CLOSED_LOGIN_FAILED"; + } + else if (session.getState().equals(SessionState.CLOSED)) + { + return "CLOSED"; + } + + return ""; + } + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + public static native void nativeCallback(int cbIndex, String params); + private class SessionStatusCallback implements Session.StatusCallback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + + nativeCallback(callIndex,""); + } + + } + + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/20/d0ab3d79319d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/20/d0ab3d79319d00131dbff94f19ed6e11 new file mode 100644 index 0000000..d17cce9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/20/d0ab3d79319d00131dbff94f19ed6e11 @@ -0,0 +1,250 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + byte[] buffer = new byte[1024]; + byte[] data = null; + //Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + //R.drawable.icon); + AssetManager am = activity.getAssets(); + try { + InputStream is = am.open("CloseSelected.png"); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + int i; + while((i=is.read(buffer))!=-1){ + os.write(buffer, 0, buffer.length); + } + data = os.toByteArray(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + /* + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + + data = baos.toByteArray(); + */ + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/21/d033baa0329d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/21/d033baa0329d00131dbff94f19ed6e11 new file mode 100644 index 0000000..0659137 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/21/d033baa0329d00131dbff94f19ed6e11 @@ -0,0 +1,261 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + + /* + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + R.drawable.icon); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + */ + + byte[] buffer = new byte[1024]; + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + int i; + while((i=is.read(buffer))!=-1) + { + os.write(buffer, 0, buffer.length); + } + + data = os.toByteArray(); + Log.i("10000",data.toString()); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2b/b0ea939e2d9d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/2b/b0ea939e2d9d00131dbff94f19ed6e11 new file mode 100644 index 0000000..7bdd207 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2b/b0ea939e2d9d00131dbff94f19ed6e11 @@ -0,0 +1,216 @@ +package org.cocos.fbtutorial; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.WebDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + params.putString("picture", + "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/90ef0815b79d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/90ef0815b79d00131dfa83034257a068 new file mode 100644 index 0000000..407e6e7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/40/90ef0815b79d00131dfa83034257a068 @@ -0,0 +1,246 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + params.putString("method", "photos.upload"); + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + /* + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/60b4fadb289d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/46/60b4fadb289d00131dbff94f19ed6e11 new file mode 100644 index 0000000..d1ba149 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/46/60b4fadb289d00131dbff94f19ed6e11 @@ -0,0 +1,216 @@ +package org.cocos.fbtutorial; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.WebDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + params.putString("picture", + "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4b/00f5a0f9ba9d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/4b/00f5a0f9ba9d00131dfa83034257a068 new file mode 100644 index 0000000..2a1872c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4b/00f5a0f9ba9d00131dfa83034257a068 @@ -0,0 +1,269 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public String name = null; + public String caption = null; + public String description = null; + public String link = null; + public String picture = null; + + + + public FacebookPostPlugin(Activity activity) + { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler() + { + @Override + public void handleMessage(Message msg) + { + super.handleMessage(msg); + switch(msg.what) + { + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + + params.putString("name", name); + params.putString("caption",caption); + params.putString("description",description); + params.putString("link",link); + params.putString("picture",picture); + + /* + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); +*/ + + /* + params.putString("method", "photos.upload"); + + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/30eda258b99d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/53/30eda258b99d00131dfa83034257a068 new file mode 100644 index 0000000..83e9be8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/53/30eda258b99d00131dfa83034257a068 @@ -0,0 +1,249 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + /* + params.putString("method", "photos.upload"); + + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/58/d0ff4d7a309d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/58/d0ff4d7a309d00131dbff94f19ed6e11 new file mode 100644 index 0000000..efbf1da --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/58/d0ff4d7a309d00131dbff94f19ed6e11 @@ -0,0 +1,245 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + params.putString("picture", + "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + byte[] data = null; + + //Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + //R.drawable.icon); + AssetManager am = activity.getAssets(); + try { + InputStream is = am.open("CloseSelected.png"); + is.read(data); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + /* + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + + data = baos.toByteArray(); + */ + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/f0b08986bc9d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/f0b08986bc9d00131dfa83034257a068 new file mode 100644 index 0000000..c865f21 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/f0b08986bc9d00131dfa83034257a068 @@ -0,0 +1,284 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + private String name = null; + private String caption = null; + private String description = null; + private String link = null; + private String picture = null; + + + + public FacebookPostPlugin(Activity activity) + { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler() + { + @Override + public void handleMessage(Message msg) + { + super.handleMessage(msg); + switch(msg.what) + { + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex,String aName,String aCaption,String aDescription,String aLink,String aPicture) + { + name = aName; + caption = aCaption; + description = aDescription; + link = aLink; + picture = aPicture; + + + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + + + Log.i("name", name); + Log.i("caption",caption); + Log.i("description",description); + Log.i("link",link); + Log.i("picture",picture); + + params.putString("name", name); + params.putString("caption",caption); + params.putString("description",description); + params.putString("link",link); + params.putString("picture",picture); + + /* + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); +*/ + + /* + params.putString("method", "photos.upload"); + + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/60/f02e404b329d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/60/f02e404b329d00131dbff94f19ed6e11 new file mode 100644 index 0000000..aad5601 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/60/f02e404b329d00131dbff94f19ed6e11 @@ -0,0 +1,252 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + byte[] buffer = new byte[1024]; + byte[] data = null; + //Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + //R.drawable.icon); + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + int i; + while((i=is.read(buffer))!=-1) + { + os.write(buffer, 0, buffer.length); + } + data = os.toByteArray(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + /* + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + + data = baos.toByteArray(); + */ + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/61/3059f6ac059d00131668ef7d7149c7c2 b/.metadata/.plugins/org.eclipse.core.resources/.history/61/3059f6ac059d00131668ef7d7149c7c2 new file mode 100755 index 0000000..a061f30 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/61/3059f6ac059d00131668ef7d7149c7c2 @@ -0,0 +1,132 @@ +/** + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cocos.fbtutorial; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.text.TextUtils; +import android.util.Log; +import android.widget.Toast; +import com.facebook.FacebookException; +import com.facebook.model.GraphUser; +import com.facebook.widget.FriendPickerFragment; +import com.facebook.widget.PickerFragment; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +// This class provides an example of an Activity that uses FriendPickerFragment to display a list of +// the user's friends. It takes a programmatic approach to creating the FriendPickerFragment with the +// desired parameters -- see PickPlaceActivity in the PlacePickerSample project for an example of an +// Activity creating a fragment (in this case a PlacePickerFragment) via XML layout rather than +// programmatically. +public class PickFriendsActivity extends FragmentActivity { + FriendPickerFragment friendPickerFragment; + + // A helper to simplify life for callers who want to populate a Bundle with the necessary + // parameters. A more sophisticated Activity might define its own set of parameters; our needs + // are simple, so we just populate what we want to pass to the FriendPickerFragment. + public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar) { + intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY, userId); + intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect); + intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, showTitleBar); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.pick_friends_activity); + + FragmentManager fm = getSupportFragmentManager(); + + if (savedInstanceState == null) { + // First time through, we create our fragment programmatically. + final Bundle args = getIntent().getExtras(); + friendPickerFragment = new FriendPickerFragment(args); + fm.beginTransaction() + .add(R.id.friend_picker_fragment, friendPickerFragment) + .commit(); + } else { + // Subsequent times, our fragment is recreated by the framework and already has saved and + // restored its state, so we don't need to specify args again. (In fact, this might be + // incorrect if the fragment was modified programmatically since it was created.) + friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment); + } + + friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { + @Override + public void onError(PickerFragment fragment, FacebookException error) { + PickFriendsActivity.this.onError(error); + } + }); + + friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { + @Override + public void onDoneButtonClicked(PickerFragment fragment) { + // We just store our selection in the Application for other activities to look at. + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + application.setSelectedUsers(friendPickerFragment.getSelection()); + Collection selection = application.getSelectedUsers(); + String results = ""; + if (selection != null && selection.size() > 0) + { + ArrayList names = new ArrayList(); + for (GraphUser user : selection) + { + Log.i("100", "111111111="+user.getName()); + names.add(user.getName()); + } + results = TextUtils.join(", ", names); + FacebookConnectPlugin.nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + else + { + results = ""; + FacebookConnectPlugin.nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + + setResult(RESULT_OK, null); + finish(); + } + }); + } + private void onError(Exception error) { + String text = getString(R.string.exception, error.getMessage()); + Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); + toast.show(); + } + + @Override + protected void onStart() { + super.onStart(); + try { + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + List selectedUsers = application.getSelectedUsers(); + if (selectedUsers != null && !selectedUsers.isEmpty()) { + friendPickerFragment.setSelection(selectedUsers); + } + // Load data, unless a query has already taken place. + friendPickerFragment.loadData(false); + } catch (Exception ex) { + ex.printStackTrace(); + onError(ex); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/67/6010377dbc9d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/67/6010377dbc9d00131dfa83034257a068 new file mode 100644 index 0000000..48adc0a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/67/6010377dbc9d00131dfa83034257a068 @@ -0,0 +1,276 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public String name = null; + public String caption = null; + public String description = null; + public String link = null; + public String picture = null; + + + + public FacebookPostPlugin(Activity activity) + { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler() + { + @Override + public void handleMessage(Message msg) + { + super.handleMessage(msg); + switch(msg.what) + { + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + + + Log.i("name", name); + Log.i("caption",caption); + Log.i("description",description); + Log.i("link",link); + Log.i("picture",picture); + + params.putString("name", name); + params.putString("caption",caption); + params.putString("description",description); + params.putString("link",link); + params.putString("picture",picture); + + /* + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); +*/ + + /* + params.putString("method", "photos.upload"); + + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/b04c7a71039d00131668ef7d7149c7c2 b/.metadata/.plugins/org.eclipse.core.resources/.history/6a/b04c7a71039d00131668ef7d7149c7c2 new file mode 100755 index 0000000..cfa1e35 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6a/b04c7a71039d00131668ef7d7149c7c2 @@ -0,0 +1,131 @@ +/** + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cocos.fbtutorial; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.text.TextUtils; +import android.widget.Toast; +import com.facebook.FacebookException; +import com.facebook.model.GraphUser; +import com.facebook.widget.FriendPickerFragment; +import com.facebook.widget.PickerFragment; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +// This class provides an example of an Activity that uses FriendPickerFragment to display a list of +// the user's friends. It takes a programmatic approach to creating the FriendPickerFragment with the +// desired parameters -- see PickPlaceActivity in the PlacePickerSample project for an example of an +// Activity creating a fragment (in this case a PlacePickerFragment) via XML layout rather than +// programmatically. +public class PickFriendsActivity extends FragmentActivity { + FriendPickerFragment friendPickerFragment; + + // A helper to simplify life for callers who want to populate a Bundle with the necessary + // parameters. A more sophisticated Activity might define its own set of parameters; our needs + // are simple, so we just populate what we want to pass to the FriendPickerFragment. + public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar) { + intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY, userId); + intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect); + intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, showTitleBar); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.pick_friends_activity); + + FragmentManager fm = getSupportFragmentManager(); + + if (savedInstanceState == null) { + // First time through, we create our fragment programmatically. + final Bundle args = getIntent().getExtras(); + friendPickerFragment = new FriendPickerFragment(args); + fm.beginTransaction() + .add(R.id.friend_picker_fragment, friendPickerFragment) + .commit(); + } else { + // Subsequent times, our fragment is recreated by the framework and already has saved and + // restored its state, so we don't need to specify args again. (In fact, this might be + // incorrect if the fragment was modified programmatically since it was created.) + friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment); + } + + friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { + @Override + public void onError(PickerFragment fragment, FacebookException error) { + PickFriendsActivity.this.onError(error); + } + }); + + friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { + @Override + public void onDoneButtonClicked(PickerFragment fragment) { + // We just store our selection in the Application for other activities to look at. + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + application.setSelectedUsers(friendPickerFragment.getSelection()); + Collection selection = application.getSelectedUsers(); + String results = ""; + if (selection != null && selection.size() > 0) + { + ArrayList names = new ArrayList(); + for (GraphUser user : selection) + { + names.add(user.getName()); + } + results = TextUtils.join(", ", names); + nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + else + { + results = ""; + nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + + setResult(RESULT_OK, null); + finish(); + } + }); + } + private static native void nativeCallback(int cbIndex, String params); + private void onError(Exception error) { + String text = getString(R.string.exception, error.getMessage()); + Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); + toast.show(); + } + + @Override + protected void onStart() { + super.onStart(); + try { + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + List selectedUsers = application.getSelectedUsers(); + if (selectedUsers != null && !selectedUsers.isEmpty()) { + friendPickerFragment.setSelection(selectedUsers); + } + // Load data, unless a query has already taken place. + friendPickerFragment.loadData(false); + } catch (Exception ex) { + ex.printStackTrace(); + onError(ex); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/30168bd6be9a001313bfddf6b926a522 b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/30168bd6be9a001313bfddf6b926a522 new file mode 100644 index 0000000..545d589 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/30168bd6be9a001313bfddf6b926a522 @@ -0,0 +1,5 @@ + + + FacebookTutorial + 1537694433122352 + diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/10fbe60ad89a001318b8acb451017248 b/.metadata/.plugins/org.eclipse.core.resources/.history/6d/10fbe60ad89a001318b8acb451017248 new file mode 100644 index 0000000..a436b57 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6d/10fbe60ad89a001318b8acb451017248 @@ -0,0 +1,151 @@ +package org.cocos.fbtutorial; + +import java.util.Arrays; +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import com.facebook.Request; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; + +public class FacebookConnectPlugin { + private static final String TAG = "FacebookPlugin"; + private static FacebookConnectPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private static int callIndex; + public FacebookConnectPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public static void login(int cbIndex, String scope) { + instance.login_(); + callIndex = cbIndex; + } + + public void login_() { + + Session session = Session.getActiveSession(); + if (!session.isOpened() && !session.isClosed()) { + session.openForRead(new Session.OpenRequest(activity) + .setPermissions(Arrays.asList("basic_info")).setCallback( + statusCallback)); + } else { + Session.openActiveSession(activity, true, statusCallback); + } + } + public static void logout(int cbIndex) { + instance.logout_(); + callIndex = cbIndex; + } + + public void logout_() { + Session session = Session.getActiveSession(); + if (!session.isClosed()) { + session.closeAndClearTokenInformation(); + } + } + public static String getStatus(int cbIndex) { + + callIndex = cbIndex; + + return instance.getStatus_(); + } + + public String getStatus_() { + + Session session = Session.getActiveSession(); + + if (session.getState().equals(SessionState.CREATED)) + { + return "CREATED"; + } + else if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) + { + return "CREATED_TOKEN_LOADED"; + } + else if (session.getState().equals(SessionState.OPENING)) + { + return "OPENING"; + } + else if (session.getState().equals(SessionState.OPENED)) + { + return "OPENED"; + } + else if (session.getState().equals(SessionState.OPENED_TOKEN_UPDATED)) + { + return "OPENED_TOKEN_UPDATED"; + } + else if (session.getState().equals(SessionState.CLOSED_LOGIN_FAILED)) + { + return "CLOSED_LOGIN_FAILED"; + } + else if (session.getState().equals(SessionState.CLOSED)) + { + return "CLOSED"; + } + + return ""; + } + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + private static native void nativeCallback(int cbIndex, String params); + private class SessionStatusCallback implements Session.StatusCallback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + + nativeCallback(callIndex,""); + } + + } + + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/d009b9fabc9d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/d009b9fabc9d00131dfa83034257a068 new file mode 100644 index 0000000..77e6805 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/d009b9fabc9d00131dfa83034257a068 @@ -0,0 +1,284 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + static public String name = null; + static public String caption = null; + static public String description = null; + static public String link = null; + static public String picture = null; + + + + public FacebookPostPlugin(Activity activity) + { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler() + { + @Override + public void handleMessage(Message msg) + { + super.handleMessage(msg); + switch(msg.what) + { + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex,String aName,String aCaption,String aDescription,String aLink,String aPicture) + { + name = aName; + caption = aCaption; + description = aDescription; + link = aLink; + picture = aPicture; + + + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + + + Log.i("name", name); + Log.i("caption",caption); + Log.i("description",description); + Log.i("link",link); + Log.i("picture",picture); + + params.putString("name", name); + params.putString("caption",caption); + params.putString("description",description); + params.putString("link",link); + params.putString("picture",picture); + + /* + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); +*/ + + /* + params.putString("method", "photos.upload"); + + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/86/80958383bf9d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/86/80958383bf9d00131dfa83034257a068 new file mode 100644 index 0000000..657b9b4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/86/80958383bf9d00131dfa83034257a068 @@ -0,0 +1,283 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + static public String name = null; + static public String caption = null; + static public String description = null; + static public String link = null; + static public String picture = null; + + + + public FacebookPostPlugin(Activity activity) + { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler() + { + @Override + public void handleMessage(Message msg) + { + super.handleMessage(msg); + switch(msg.what) + { + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex,String aName,String aCaption,String aDescription,String aLink,String aPicture) + { + name = aName; + caption = aCaption; + description = aDescription; + link = aLink; + picture = aPicture; + + + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + + Log.i("name", name); + Log.i("caption",caption); + Log.i("description",description); + Log.i("link",link); + Log.i("picture",picture); + + params.putString("name", name); + params.putString("caption",caption); + params.putString("description",description); + params.putString("link",link); + params.putString("picture",picture); + + /* + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); +*/ + + /* + params.putString("method", "photos.upload"); + + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/80f49b2a389d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/80f49b2a389d00131dbff94f19ed6e11 new file mode 100644 index 0000000..677a8f1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/80f49b2a389d00131dbff94f19ed6e11 @@ -0,0 +1,256 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + + /* + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + R.drawable.icon); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + */ + + //byte[] buffer = new byte[1024]; + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/40ba5719d89a001318b8acb451017248 b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/40ba5719d89a001318b8acb451017248 new file mode 100644 index 0000000..6cb7170 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/40ba5719d89a001318b8acb451017248 @@ -0,0 +1,118 @@ +package org.cocos.fbtutorial; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; + +public class FacebookPickFriendPlugin { + private static final int PICK_FRIENDS_ACTIVITY = 1; + private static final String TAG = "FacebookPlugin"; + private static FacebookPickFriendPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + boolean pickFriendsWhenSessionOpened; + + public static void pickFriend(int cbIndex) { + instance.pickFriend_(); + } + + public FacebookPickFriendPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + } + + public void pickFriend_() { + if (ensureOpenSession()) { + Intent intent = new Intent(activity, PickFriendsActivity.class); + // Note: The following line is optional, as multi-select behavior is + // the default for + // FriendPickerFragment. It is here to demonstrate how parameters + // could be passed to the + // friend picker if single-select functionality was desired, or if a + // different user ID was + // desired (for instance, to see friends of a friend). + PickFriendsActivity.populateParameters(intent, null, true, true); + activity.startActivityForResult(intent, PICK_FRIENDS_ACTIVITY); + } else { + pickFriendsWhenSessionOpened = true; + } + } + + private boolean ensureOpenSession() { + if (Session.getActiveSession() == null + || !Session.getActiveSession().isOpened()) { + Session.openActiveSession(activity, true, statusCallback); + return false; + } + return true; + } + + private class SessionStatusCallback implements Session.StatusCallback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + if (pickFriendsWhenSessionOpened && state.isOpened()) { + pickFriendsWhenSessionOpened = false; + pickFriend_(); + } + } + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + /* + * ------------------------- + * + * @Override public void onActivityResult(int requestCode, int resultCode, + * Intent data) { switch (requestCode) { case PICK_FRIENDS_ACTIVITY: + * displaySelectedFriends(resultCode); break; default: + * Session.getActiveSession().onActivityResult(this, requestCode, + * resultCode, data); break; } } -------------------------------- + */ +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/207baa57039d00131668ef7d7149c7c2 b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/207baa57039d00131668ef7d7149c7c2 new file mode 100644 index 0000000..5f06a0b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/207baa57039d00131668ef7d7149c7c2 @@ -0,0 +1,151 @@ +package org.cocos.fbtutorial; + +import java.util.Arrays; +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import com.facebook.Request; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; + +public class FacebookConnectPlugin { + private static final String TAG = "FacebookPlugin"; + private static FacebookConnectPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private static int callIndex; + public FacebookConnectPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public static void login(int cbIndex, String scope) { + callIndex = cbIndex; + instance.login_(); + } + + public void login_() { + + Session session = Session.getActiveSession(); + if (!session.isOpened() && !session.isClosed()) { + session.openForRead(new Session.OpenRequest(activity) + .setPermissions(Arrays.asList("basic_info")).setCallback( + statusCallback)); + } else { + Session.openActiveSession(activity, true, statusCallback); + } + } + public static void logout(int cbIndex) { + instance.logout_(); + callIndex = cbIndex; + } + + public void logout_() { + Session session = Session.getActiveSession(); + if (!session.isClosed()) { + session.closeAndClearTokenInformation(); + } + } + public static String getStatus(int cbIndex) { + + callIndex = cbIndex; + + return instance.getStatus_(); + } + + public String getStatus_() { + + Session session = Session.getActiveSession(); + + if (session.getState().equals(SessionState.CREATED)) + { + return "CREATED"; + } + else if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) + { + return "CREATED_TOKEN_LOADED"; + } + else if (session.getState().equals(SessionState.OPENING)) + { + return "OPENING"; + } + else if (session.getState().equals(SessionState.OPENED)) + { + return "OPENED"; + } + else if (session.getState().equals(SessionState.OPENED_TOKEN_UPDATED)) + { + return "OPENED_TOKEN_UPDATED"; + } + else if (session.getState().equals(SessionState.CLOSED_LOGIN_FAILED)) + { + return "CLOSED_LOGIN_FAILED"; + } + else if (session.getState().equals(SessionState.CLOSED)) + { + return "CLOSED"; + } + + return ""; + } + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + private static native void nativeCallback(int cbIndex, String params); + private class SessionStatusCallback implements Session.StatusCallback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + + nativeCallback(callIndex,""); + } + + } + + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/a0716a72ca9d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/a0716a72ca9d00131dfa83034257a068 new file mode 100644 index 0000000..bd9104b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/a0716a72ca9d00131dfa83034257a068 @@ -0,0 +1,282 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + static public String name = null; + static public String caption = null; + static public String description = null; + static public String link = null; + static public String picture = null; + + + + public FacebookPostPlugin(Activity activity) + { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler() + { + @Override + public void handleMessage(Message msg) + { + super.handleMessage(msg); + switch(msg.what) + { + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex,String aName,String aCaption,String aDescription,String aLink,String aPicture) + { + name = aName; + caption = aCaption; + description = aDescription; + link = aLink; + picture = aPicture; + + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + + Log.i("name", name); + Log.i("caption",caption); + Log.i("description",description); + Log.i("link",link); + Log.i("picture",picture); + + params.putString("name", name); + params.putString("caption",caption); + params.putString("description",description); + params.putString("link",link); + params.putString("picture",picture); + + /* + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); +*/ + + /* + params.putString("method", "photos.upload"); + + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/af/d0050157319d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/af/d0050157319d00131dbff94f19ed6e11 new file mode 100644 index 0000000..f312121 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/af/d0050157319d00131dbff94f19ed6e11 @@ -0,0 +1,245 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + byte[] data = null; + + //Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + //R.drawable.icon); + AssetManager am = activity.getAssets(); + try { + InputStream is = am.open("CloseSelected.png"); + is.read(data); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + /* + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + + data = baos.toByteArray(); + */ + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/a006b7fd039d00131668ef7d7149c7c2 b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/a006b7fd039d00131668ef7d7149c7c2 new file mode 100755 index 0000000..e7fd1f2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/a006b7fd039d00131668ef7d7149c7c2 @@ -0,0 +1,130 @@ +/** + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cocos.fbtutorial; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.text.TextUtils; +import android.widget.Toast; +import com.facebook.FacebookException; +import com.facebook.model.GraphUser; +import com.facebook.widget.FriendPickerFragment; +import com.facebook.widget.PickerFragment; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +// This class provides an example of an Activity that uses FriendPickerFragment to display a list of +// the user's friends. It takes a programmatic approach to creating the FriendPickerFragment with the +// desired parameters -- see PickPlaceActivity in the PlacePickerSample project for an example of an +// Activity creating a fragment (in this case a PlacePickerFragment) via XML layout rather than +// programmatically. +public class PickFriendsActivity extends FragmentActivity { + FriendPickerFragment friendPickerFragment; + + // A helper to simplify life for callers who want to populate a Bundle with the necessary + // parameters. A more sophisticated Activity might define its own set of parameters; our needs + // are simple, so we just populate what we want to pass to the FriendPickerFragment. + public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar) { + intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY, userId); + intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect); + intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, showTitleBar); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.pick_friends_activity); + + FragmentManager fm = getSupportFragmentManager(); + + if (savedInstanceState == null) { + // First time through, we create our fragment programmatically. + final Bundle args = getIntent().getExtras(); + friendPickerFragment = new FriendPickerFragment(args); + fm.beginTransaction() + .add(R.id.friend_picker_fragment, friendPickerFragment) + .commit(); + } else { + // Subsequent times, our fragment is recreated by the framework and already has saved and + // restored its state, so we don't need to specify args again. (In fact, this might be + // incorrect if the fragment was modified programmatically since it was created.) + friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment); + } + + friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { + @Override + public void onError(PickerFragment fragment, FacebookException error) { + PickFriendsActivity.this.onError(error); + } + }); + + friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { + @Override + public void onDoneButtonClicked(PickerFragment fragment) { + // We just store our selection in the Application for other activities to look at. + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + application.setSelectedUsers(friendPickerFragment.getSelection()); + Collection selection = application.getSelectedUsers(); + String results = ""; + if (selection != null && selection.size() > 0) + { + ArrayList names = new ArrayList(); + for (GraphUser user : selection) + { + names.add(user.getName()); + } + results = TextUtils.join(", ", names); + FacebookConnectPlugin.nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + else + { + results = ""; + FacebookConnectPlugin.nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + + setResult(RESULT_OK, null); + finish(); + } + }); + } + private void onError(Exception error) { + String text = getString(R.string.exception, error.getMessage()); + Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); + toast.show(); + } + + @Override + protected void onStart() { + super.onStart(); + try { + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + List selectedUsers = application.getSelectedUsers(); + if (selectedUsers != null && !selectedUsers.isEmpty()) { + friendPickerFragment.setSelection(selectedUsers); + } + // Load data, unless a query has already taken place. + friendPickerFragment.loadData(false); + } catch (Exception ex) { + ex.printStackTrace(); + onError(ex); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b2/909d0948d89a001318b8acb451017248 b/.metadata/.plugins/org.eclipse.core.resources/.history/b2/909d0948d89a001318b8acb451017248 new file mode 100755 index 0000000..eafeafe --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b2/909d0948d89a001318b8acb451017248 @@ -0,0 +1,129 @@ +/** + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cocos.fbtutorial; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.text.TextUtils; +import android.widget.Toast; +import com.facebook.FacebookException; +import com.facebook.model.GraphUser; +import com.facebook.widget.FriendPickerFragment; +import com.facebook.widget.PickerFragment; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +// This class provides an example of an Activity that uses FriendPickerFragment to display a list of +// the user's friends. It takes a programmatic approach to creating the FriendPickerFragment with the +// desired parameters -- see PickPlaceActivity in the PlacePickerSample project for an example of an +// Activity creating a fragment (in this case a PlacePickerFragment) via XML layout rather than +// programmatically. +public class PickFriendsActivity extends FragmentActivity { + FriendPickerFragment friendPickerFragment; + + // A helper to simplify life for callers who want to populate a Bundle with the necessary + // parameters. A more sophisticated Activity might define its own set of parameters; our needs + // are simple, so we just populate what we want to pass to the FriendPickerFragment. + public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar) { + intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY, userId); + intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect); + intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, showTitleBar); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.pick_friends_activity); + + FragmentManager fm = getSupportFragmentManager(); + + if (savedInstanceState == null) { + // First time through, we create our fragment programmatically. + final Bundle args = getIntent().getExtras(); + friendPickerFragment = new FriendPickerFragment(args); + fm.beginTransaction() + .add(R.id.friend_picker_fragment, friendPickerFragment) + .commit(); + } else { + // Subsequent times, our fragment is recreated by the framework and already has saved and + // restored its state, so we don't need to specify args again. (In fact, this might be + // incorrect if the fragment was modified programmatically since it was created.) + friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment); + } + + friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { + @Override + public void onError(PickerFragment fragment, FacebookException error) { + PickFriendsActivity.this.onError(error); + } + }); + + friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { + @Override + public void onDoneButtonClicked(PickerFragment fragment) { + // We just store our selection in the Application for other activities to look at. + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + application.setSelectedUsers(friendPickerFragment.getSelection()); + Collection selection = application.getSelectedUsers(); + String results = ""; + if (selection != null && selection.size() > 0) + { + ArrayList names = new ArrayList(); + for (GraphUser user : selection) + { + names.add(user.getName()); + } + results = TextUtils.join(", ", names); + } + else + { + results = ""; + } + + setResult(RESULT_OK, null); + finish(); + } + }); + } + + private void onError(Exception error) { + String text = getString(R.string.exception, error.getMessage()); + Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); + toast.show(); + } + + @Override + protected void onStart() { + super.onStart(); + try { + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + List selectedUsers = application.getSelectedUsers(); + if (selectedUsers != null && !selectedUsers.isEmpty()) { + friendPickerFragment.setSelection(selectedUsers); + } + // Load data, unless a query has already taken place. + friendPickerFragment.loadData(false); + } catch (Exception ex) { + ex.printStackTrace(); + onError(ex); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/609d2143399d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/609d2143399d00131dbff94f19ed6e11 new file mode 100644 index 0000000..5aca4ce --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/609d2143399d00131dbff94f19ed6e11 @@ -0,0 +1,259 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + /* + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + */ + params.putString("method", "photos.upload"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + + /* + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + R.drawable.icon); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + */ + + //byte[] buffer = new byte[1024]; + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/40ad394f3e9d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/40ad394f3e9d00131dbff94f19ed6e11 new file mode 100644 index 0000000..ae34ee3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/40ad394f3e9d00131dbff94f19ed6e11 @@ -0,0 +1,260 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + /* + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + */ + params.putString("method", "photos.upload"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + + /* + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + R.drawable.icon); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + */ + + //byte[] buffer = new byte[1024]; + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/b0e274ec299d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/b0e274ec299d00131dbff94f19ed6e11 new file mode 100644 index 0000000..d23cd6b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/b0e274ec299d00131dbff94f19ed6e11 @@ -0,0 +1,217 @@ +package org.cocos.fbtutorial; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.WebDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + params.putString("picture", + "http://img0.bdstatic.com/img/image/7700eb30f2442a7d933c636082daf4bd11372f001d5.jpg"); + //"//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/e0c5f385359d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/e0c5f385359d00131dbff94f19ed6e11 new file mode 100644 index 0000000..e06fcc1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/e0c5f385359d00131dbff94f19ed6e11 @@ -0,0 +1,261 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + + /* + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + R.drawable.icon); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + */ + + byte[] buffer = new byte[1024]; + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + int i; + while((i=is.read(buffer))!=-1) + { + os.write(buffer, 0, buffer.length); + } + + data = os.toByteArray(); + Log.i("10000",""+data.length); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0e8e965369d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0e8e965369d00131dbff94f19ed6e11 new file mode 100644 index 0000000..b4ea847 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0e8e965369d00131dbff94f19ed6e11 @@ -0,0 +1,262 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + + /* + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + R.drawable.icon); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + */ + + byte[] buffer = new byte[1024]; + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + int i; + while((i=is.read(buffer))!=-1) + { + os.write(buffer, 0, buffer.length); + } + + data = os.toByteArray(); + Log.i("10000",""+data.length); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d3/a045498d2f9d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/d3/a045498d2f9d00131dbff94f19ed6e11 new file mode 100644 index 0000000..e031fd1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d3/a045498d2f9d00131dbff94f19ed6e11 @@ -0,0 +1,232 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.WebDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + params.putString("picture", + "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(getResources(), + R.drawable.ic_launcher); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/de/806ad7b0329d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/de/806ad7b0329d00131dbff94f19ed6e11 new file mode 100644 index 0000000..d67a656 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/de/806ad7b0329d00131dbff94f19ed6e11 @@ -0,0 +1,261 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + + /* + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + R.drawable.icon); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + */ + + byte[] buffer = new byte[1024]; + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + int i; + while((i=is.read(buffer))!=-1) + { + os.write(buffer, 0, buffer.length); + } + + data = os.toByteArray(); + Log.i("10000",data.length); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/d06adec4bc9d00131dfa83034257a068 b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/d06adec4bc9d00131dfa83034257a068 new file mode 100644 index 0000000..aca48d5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/d06adec4bc9d00131dfa83034257a068 @@ -0,0 +1,284 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public String name = null; + public String caption = null; + public String description = null; + public String link = null; + public String picture = null; + + + + public FacebookPostPlugin(Activity activity) + { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler() + { + @Override + public void handleMessage(Message msg) + { + super.handleMessage(msg); + switch(msg.what) + { + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex,String aName,String aCaption,String aDescription,String aLink,String aPicture) + { + name = aName; + caption = aCaption; + description = aDescription; + link = aLink; + picture = aPicture; + + + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + + + Log.i("name", name); + Log.i("caption",caption); + Log.i("description",description); + Log.i("link",link); + Log.i("picture",picture); + + params.putString("name", name); + params.putString("caption",caption); + params.putString("description",description); + params.putString("link",link); + params.putString("picture",picture); + + /* + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); +*/ + + /* + params.putString("method", "photos.upload"); + + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e7/d0273064329d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/e7/d0273064329d00131dbff94f19ed6e11 new file mode 100644 index 0000000..8cda514 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e7/d0273064329d00131dbff94f19ed6e11 @@ -0,0 +1,260 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + //params.putString("picture", + // "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + + /* + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + R.drawable.icon); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + */ + + byte[] buffer = new byte[1024]; + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + int i; + while((i=is.read(buffer))!=-1) + { + os.write(buffer, 0, buffer.length); + } + + data = os.toByteArray(); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/70477daad79a001318b8acb451017248 b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/70477daad79a001318b8acb451017248 new file mode 100755 index 0000000..41b21b9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/70477daad79a001318b8acb451017248 @@ -0,0 +1,111 @@ +/** + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cocos.fbtutorial; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.widget.Toast; +import com.facebook.FacebookException; +import com.facebook.model.GraphUser; +import com.facebook.widget.FriendPickerFragment; +import com.facebook.widget.PickerFragment; + +import java.util.List; + +// This class provides an example of an Activity that uses FriendPickerFragment to display a list of +// the user's friends. It takes a programmatic approach to creating the FriendPickerFragment with the +// desired parameters -- see PickPlaceActivity in the PlacePickerSample project for an example of an +// Activity creating a fragment (in this case a PlacePickerFragment) via XML layout rather than +// programmatically. +public class PickFriendsActivity extends FragmentActivity { + FriendPickerFragment friendPickerFragment; + + // A helper to simplify life for callers who want to populate a Bundle with the necessary + // parameters. A more sophisticated Activity might define its own set of parameters; our needs + // are simple, so we just populate what we want to pass to the FriendPickerFragment. + public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar) { + intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY, userId); + intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect); + intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, showTitleBar); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.pick_friends_activity); + + FragmentManager fm = getSupportFragmentManager(); + + if (savedInstanceState == null) { + // First time through, we create our fragment programmatically. + final Bundle args = getIntent().getExtras(); + friendPickerFragment = new FriendPickerFragment(args); + fm.beginTransaction() + .add(R.id.friend_picker_fragment, friendPickerFragment) + .commit(); + } else { + // Subsequent times, our fragment is recreated by the framework and already has saved and + // restored its state, so we don't need to specify args again. (In fact, this might be + // incorrect if the fragment was modified programmatically since it was created.) + friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment); + } + + friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { + @Override + public void onError(PickerFragment fragment, FacebookException error) { + PickFriendsActivity.this.onError(error); + } + }); + + friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { + @Override + public void onDoneButtonClicked(PickerFragment fragment) { + // We just store our selection in the Application for other activities to look at. + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + application.setSelectedUsers(friendPickerFragment.getSelection()); + + setResult(RESULT_OK, null); + finish(); + } + }); + } + + private void onError(Exception error) { + String text = getString(R.string.exception, error.getMessage()); + Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); + toast.show(); + } + + @Override + protected void onStart() { + super.onStart(); + try { + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + List selectedUsers = application.getSelectedUsers(); + if (selectedUsers != null && !selectedUsers.isEmpty()) { + friendPickerFragment.setSelection(selectedUsers); + } + // Load data, unless a query has already taken place. + friendPickerFragment.loadData(false); + } catch (Exception ex) { + ex.printStackTrace(); + onError(ex); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/c0b09c67309d00131dbff94f19ed6e11 b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/c0b09c67309d00131dbff94f19ed6e11 new file mode 100644 index 0000000..e214ba7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/c0b09c67309d00131dbff94f19ed6e11 @@ -0,0 +1,232 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookPostPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch(msg.what){ + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + params.putString("picture", + "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + + + byte[] data = null; + + Bitmap bi = BitmapFactory.decodeResource(activity.getResources(), + R.drawable.icon); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + + + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f6/c07b6c81039d00131668ef7d7149c7c2 b/.metadata/.plugins/org.eclipse.core.resources/.history/f6/c07b6c81039d00131668ef7d7149c7c2 new file mode 100755 index 0000000..487c8ef --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f6/c07b6c81039d00131668ef7d7149c7c2 @@ -0,0 +1,131 @@ +/** + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cocos.fbtutorial; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.text.TextUtils; +import android.widget.Toast; +import com.facebook.FacebookException; +import com.facebook.model.GraphUser; +import com.facebook.widget.FriendPickerFragment; +import com.facebook.widget.PickerFragment; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +// This class provides an example of an Activity that uses FriendPickerFragment to display a list of +// the user's friends. It takes a programmatic approach to creating the FriendPickerFragment with the +// desired parameters -- see PickPlaceActivity in the PlacePickerSample project for an example of an +// Activity creating a fragment (in this case a PlacePickerFragment) via XML layout rather than +// programmatically. +public class PickFriendsActivity extends FragmentActivity { + FriendPickerFragment friendPickerFragment; + + // A helper to simplify life for callers who want to populate a Bundle with the necessary + // parameters. A more sophisticated Activity might define its own set of parameters; our needs + // are simple, so we just populate what we want to pass to the FriendPickerFragment. + public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar) { + intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY, userId); + intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect); + intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, showTitleBar); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.pick_friends_activity); + + FragmentManager fm = getSupportFragmentManager(); + + if (savedInstanceState == null) { + // First time through, we create our fragment programmatically. + final Bundle args = getIntent().getExtras(); + friendPickerFragment = new FriendPickerFragment(args); + fm.beginTransaction() + .add(R.id.friend_picker_fragment, friendPickerFragment) + .commit(); + } else { + // Subsequent times, our fragment is recreated by the framework and already has saved and + // restored its state, so we don't need to specify args again. (In fact, this might be + // incorrect if the fragment was modified programmatically since it was created.) + friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment); + } + + friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { + @Override + public void onError(PickerFragment fragment, FacebookException error) { + PickFriendsActivity.this.onError(error); + } + }); + + friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { + @Override + public void onDoneButtonClicked(PickerFragment fragment) { + // We just store our selection in the Application for other activities to look at. + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + application.setSelectedUsers(friendPickerFragment.getSelection()); + Collection selection = application.getSelectedUsers(); + String results = ""; + if (selection != null && selection.size() > 0) + { + ArrayList names = new ArrayList(); + for (GraphUser user : selection) + { + names.add(user.getName()); + } + results = TextUtils.join(", ", names); + FacebookConnectPlugin.nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + else + { + results = ""; + FacebookConnectPlugin.nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + + setResult(RESULT_OK, null); + finish(); + } + }); + } + // private static native void nativeCallback(int cbIndex, String params); + private void onError(Exception error) { + String text = getString(R.string.exception, error.getMessage()); + Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); + toast.show(); + } + + @Override + protected void onStart() { + super.onStart(); + try { + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + List selectedUsers = application.getSelectedUsers(); + if (selectedUsers != null && !selectedUsers.isEmpty()) { + friendPickerFragment.setSelection(selectedUsers); + } + // Load data, unless a query has already taken place. + friendPickerFragment.loadData(false); + } catch (Exception ex) { + ex.printStackTrace(); + onError(ex); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/40/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/40/properties.index new file mode 100644 index 0000000..cb1ecb6 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/40/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/47/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/47/properties.index new file mode 100644 index 0000000..e946bff Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/47/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/62/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/62/properties.index new file mode 100644 index 0000000..4d388ee Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/62/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/65/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/65/properties.index new file mode 100644 index 0000000..1a3596a Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/65/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/78/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/78/properties.index new file mode 100644 index 0000000..d26e027 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/78/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/c4/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/c4/properties.index new file mode 100644 index 0000000..fb3b0b0 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/c4/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/c7/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/c7/properties.index new file mode 100644 index 0000000..8bd68a0 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/c7/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..ddcc100 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/de/properties.index new file mode 100644 index 0000000..085345a Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/fe/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/fe/properties.index new file mode 100644 index 0000000..a376dc3 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/a0/fe/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/properties.index new file mode 100644 index 0000000..7292ef9 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.location new file mode 100644 index 0000000..42aa36b Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.markers b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.markers new file mode 100644 index 0000000..8b68b05 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.markers differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.markers.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.syncinfo.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..2aedd35 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FacebookSDK/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..2154f2e Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.indexes/a0/de/properties.index new file mode 100644 index 0000000..8a27727 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.indexes/properties.index new file mode 100644 index 0000000..9dc203a Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.location new file mode 100644 index 0000000..a1e26cf Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/1.tree b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/1.tree new file mode 100644 index 0000000..d9c697b Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/1.tree differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..aad5301 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/FriendPickerSample/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..a6d116c Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.indexes/a0/de/properties.index new file mode 100644 index 0000000..8a27727 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.indexes/properties.index new file mode 100644 index 0000000..31985ad Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.location new file mode 100644 index 0000000..21bd7f0 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/3.tree b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/3.tree new file mode 100644 index 0000000..ab58399 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/3.tree differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..3b43376 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/GraphApiSample/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..a6d116c Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.indexes/a0/de/properties.index new file mode 100644 index 0000000..8a27727 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.indexes/properties.index new file mode 100644 index 0000000..6256f7b Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.location new file mode 100644 index 0000000..75860ed Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/1.tree b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/1.tree new file mode 100644 index 0000000..a40c5db Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/1.tree differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..447a95f Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/HelloFacebookSample/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..3c6b965 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.indexes/a0/de/properties.index new file mode 100644 index 0000000..8a27727 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.indexes/properties.index new file mode 100644 index 0000000..4b3766d Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.location new file mode 100644 index 0000000..747a7bb Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/1.tree b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/1.tree new file mode 100644 index 0000000..c1fe20a Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/1.tree differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..6b26f20 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/PlacePickerSample/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..9823cda Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.indexes/a0/de/properties.index new file mode 100644 index 0000000..8a27727 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.indexes/properties.index new file mode 100644 index 0000000..2b2959f Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.location new file mode 100644 index 0000000..5662f34 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/1.tree b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/1.tree new file mode 100644 index 0000000..538e01d Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/1.tree differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..fa4a50e Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/ProfilePictureSample/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/a0/62/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/a0/62/properties.index new file mode 100644 index 0000000..fe0c81d Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/a0/62/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..955e273 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/a0/de/properties.index new file mode 100644 index 0000000..ecd02af Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/properties.index new file mode 100644 index 0000000..0d8f81a Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.location new file mode 100644 index 0000000..85398d5 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.markers.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.syncinfo.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..a32be66 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RPSSample/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/a0/62/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/a0/62/properties.index new file mode 100644 index 0000000..7d3cba3 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/a0/62/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..ad4e038 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/a0/de/properties.index new file mode 100644 index 0000000..8a27727 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/properties.index new file mode 100644 index 0000000..889ff53 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.location new file mode 100644 index 0000000..bfbad5f Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.markers.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.syncinfo.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..e9d83d3 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/Scrumptious/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..bd1ffa4 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.indexes/a0/de/properties.index new file mode 100644 index 0000000..8a27727 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.indexes/properties.index new file mode 100644 index 0000000..5fde90d Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.location new file mode 100644 index 0000000..43fedbc Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.markers.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.syncinfo.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..f8015bf Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SessionLoginSample/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/a0/5f/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/a0/5f/properties.index new file mode 100644 index 0000000..b40e632 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/a0/5f/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..c62628e Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/a0/de/properties.index new file mode 100644 index 0000000..8a27727 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/properties.index new file mode 100644 index 0000000..e2c6ea6 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.location new file mode 100644 index 0000000..e6a2452 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.markers.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.syncinfo.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..7d13ce1 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/SwitchUserSample/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.indexes/properties.index new file mode 100644 index 0000000..b92276b Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.location b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.location new file mode 100644 index 0000000..a475113 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.location differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.markers b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.markers new file mode 100644 index 0000000..6f8c8d0 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.markers differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.markers.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.syncinfo.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..5fccf00 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/libcocos2dx/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/a0/d6/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/a0/d6/properties.index new file mode 100644 index 0000000..0cb344c Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/a0/d6/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/a0/de/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/a0/de/history.index new file mode 100644 index 0000000..5f1dd9f Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/a0/de/history.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/a0/de/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/a0/de/properties.index new file mode 100644 index 0000000..fe043c1 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/a0/de/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/e4/e4/9b/1a/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/e4/e4/9b/1a/history.index new file mode 100644 index 0000000..289f9dc Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/e4/e4/9b/1a/history.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/properties.index new file mode 100644 index 0000000..508b60d Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.markers b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.markers new file mode 100644 index 0000000..d95a299 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.markers differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.markers.snap new file mode 100644 index 0000000..ef71524 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.syncinfo.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/org.eclipse.jdt.core/state.dat b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/org.eclipse.jdt.core/state.dat new file mode 100644 index 0000000..e2d78da Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.projects/proj.android/org.eclipse.jdt.core/state.dat differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version b/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version new file mode 100644 index 0000000..25cb955 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index b/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index new file mode 100644 index 0000000..0a695a3 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version b/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version new file mode 100644 index 0000000..6b2aaa7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap new file mode 100644 index 0000000..91d6c54 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/6.tree b/.metadata/.plugins/org.eclipse.core.resources/.root/6.tree new file mode 100644 index 0000000..b8b040b Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.root/6.tree differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources b/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources new file mode 100644 index 0000000..8d7dc35 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.snap b/.metadata/.plugins/org.eclipse.core.resources/.snap new file mode 100644 index 0000000..4d20378 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.android.ide.eclipse.adt.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.android.ide.eclipse.adt.prefs new file mode 100644 index 0000000..860a062 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.android.ide.eclipse.adt.prefs @@ -0,0 +1,4 @@ +com.android.ide.eclipse.adt.fixLegacyEditors=1 +com.android.ide.eclipse.adt.sdk=/Users/liuyuye/Desktop/adt-bundle-mac-x86_64-20131030/sdk +com.android.ide.eclipse.adt.xmlEditor=true +eclipse.preferences.version=1 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.android.ide.eclipse.ddms.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.android.ide.eclipse.ddms.prefs new file mode 100644 index 0000000..964381e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.android.ide.eclipse.ddms.prefs @@ -0,0 +1,11 @@ +ddms.logcat.auotmonitor.level=error +ddms.logcat.automonitor.userprompt=true +eclipse.preferences.version=1 +logcat.view.colsize.Application=154 +logcat.view.colsize.Level=18 +logcat.view.colsize.PID=46 +logcat.view.colsize.TID=46 +logcat.view.colsize.Tag=101 +logcat.view.colsize.Text=545 +logcat.view.colsize.Time=140 +logcat.view.filters.list=name\: 'data', tag\: '10000', text\: '', pid\: '', app\: '', level\: 'verbose', diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.core.prj-proj.android.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.core.prj-proj.android.prefs new file mode 100644 index 0000000..9c00dc4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.core.prj-proj.android.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +indexer/preferenceScope=0 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.debug.core.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.debug.core.prefs new file mode 100644 index 0000000..b8c9267 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.debug.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.debug.core.cDebug.default_source_containers=\n\n\n\n\n\n\n\n diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.managedbuilder.core.prefs new file mode 100644 index 0000000..51c6d49 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.managedbuilder.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +properties/MyProject.null.190811507/0.756827735=\#\n\#Tue Feb 25 10\:11\:33 CST 2014\norg.eclipse.cdt.build.core.prefbase.toolchain.294545719\=\\\#\\n\\\#Tue Feb 25 10\\\:11\\\:33 CST 2014\\nrebuildState\\\=false\\n\norg.eclipse.cdt.build.core.settings.holder.2035290044\=\\\#\\n\\\#Tue Feb 25 10\\\:11\\\:33 CST 2014\\nrebuildState\\\=false\\n\n0.756827735\=\\\#\\n\\\#Tue Feb 25 10\\\:11\\\:33 CST 2014\\nrcState\\\=0\\nrebuildState\\\=false\\n\norg.eclipse.cdt.build.core.settings.holder.libs.1844369373\=\\\#\\n\\\#Tue Feb 25 10\\\:11\\\:33 CST 2014\\nrebuildState\\\=false\\n\norg.eclipse.cdt.build.core.settings.holder.731367497\=\\\#\\n\\\#Tue Feb 25 10\\\:11\\\:33 CST 2014\\nrebuildState\\\=false\\n\norg.eclipse.cdt.build.core.settings.holder.991472034\=\\\#\\n\\\#Tue Feb 25 10\\\:11\\\:33 CST 2014\\nrebuildState\\\=false\\n\n diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.ui.prefs new file mode 100644 index 0000000..5e2da66 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.ui.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +spelling_locale_initialized=true +useAnnotationsPrefPage=true +useQuickDiffPrefPage=true diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..dffc6b5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +version=1 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.debug.core.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.debug.core.prefs new file mode 100644 index 0000000..a5f7da5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.debug.core.prefs @@ -0,0 +1,4 @@ +//org.eclipse.debug.core.PREFERRED_DELEGATES/org.eclipse.cdt.launch.applicationLaunchType=org.eclipse.cdt.dsf.gdb.launch.localCLaunch,debug;org.eclipse.cdt.cdi.launch.localCLaunch,run +//org.eclipse.debug.core.PREFERRED_DELEGATES/org.eclipse.cdt.launch.attachLaunchType=org.eclipse.cdt.dsf.gdb.launch.attachCLaunch,debug +//org.eclipse.debug.core.PREFERRED_DELEGATES/org.eclipse.cdt.launch.postmortemLaunchType=org.eclipse.cdt.dsf.gdb.launch.coreCLaunch,debug +eclipse.preferences.version=1 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.debug.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.debug.ui.prefs new file mode 100644 index 0000000..acd9485 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.debug.ui.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.debug.ui.PREF_LAUNCH_PERSPECTIVES=\n\n +preferredDetailPanes=DefaultDetailPane\:DefaultDetailPane| +preferredTargets=default\:default|org.eclipse.cdt.debug.ui.toggleCBreakpointTarget\:org.eclipse.cdt.debug.ui.toggleCBreakpointTarget| diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..aa0353e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.classpathVariable.JRE_LIB=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar +org.eclipse.jdt.core.classpathVariable.JRE_SRC= +org.eclipse.jdt.core.classpathVariable.JRE_SRCROOT= +org.eclipse.jdt.core.codeComplete.visibilityCheck=enabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.debug.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.debug.ui.prefs new file mode 100644 index 0000000..536506b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.debug.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.debug.ui.VariableView.org.eclipse.jdt.debug.ui.show_null_entries=true diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.launching.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.launching.prefs new file mode 100644 index 0000000..eaf9a76 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.launching.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.launching.PREF_VM_XML=\n\n\n\n\n\n diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..9c4d431 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,19 @@ +content_assist_lru_history= +content_assist_number_of_computers=12 +content_assist_proposals_background=255,255,255 +content_assist_proposals_foreground=0,0,0 +eclipse.preferences.version=1 +fontPropagated=true +org.eclipse.jdt.ui.editor.tab.width= +org.eclipse.jdt.ui.formatterprofiles.version=12 +org.eclipse.jdt.ui.javadoclocations.migrated=true +org.eclipse.jdt.ui.text.code_templates_migrated=true +org.eclipse.jdt.ui.text.custom_code_templates= +org.eclipse.jdt.ui.text.custom_templates= +org.eclipse.jdt.ui.text.templates_migrated=true +org.eclipse.jface.textfont=1|Monaco|11.0|0|COCOA|1|; +proposalOrderMigrated=true +spelling_locale_initialized=true +tabWidthPropagated=true +useAnnotationsPrefPage=true +useQuickDiffPrefPage=true diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.ui.prefs new file mode 100644 index 0000000..56cd496 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.team.ui.first_time=false diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.editors.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.editors.prefs new file mode 100644 index 0000000..61f3bb8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.editors.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +overviewRuler_migration=migrated_3.1 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs new file mode 100644 index 0000000..6923f38 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs @@ -0,0 +1,5 @@ +PROBLEMS_FILTERS_MIGRATE=true +eclipse.preferences.version=1 +platformState=1390448080384 +quickStart=false +tipsAndTricks=true diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs new file mode 100644 index 0000000..08076f2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +showIntro=false diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.sse.core.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.sse.core.prefs new file mode 100644 index 0000000..858f3a5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.sse.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +task-tag-projects-already-scanned=FacebookSDK,libcocos2dx,proj.android,FriendPickerSample,GraphApiSample,HelloFacebookSample,PlacePickerSample,ProfilePictureSample,RPSSample,Scrumptious,SessionLoginSample,SwitchUserSample diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.sse.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.sse.ui.prefs new file mode 100644 index 0000000..4fd0cd3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.sse.ui.prefs @@ -0,0 +1,4 @@ +content_assist_number_of_computers=2 +eclipse.preferences.version=1 +useAnnotationsPrefPage=true +useQuickDiffPrefPage=true diff --git a/.metadata/.plugins/org.eclipse.debug.core/.launches/GraphApiSample.launch b/.metadata/.plugins/org.eclipse.debug.core/.launches/GraphApiSample.launch new file mode 100644 index 0000000..2392486 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.debug.core/.launches/GraphApiSample.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.debug.core/.launches/proj.android (1).launch b/.metadata/.plugins/org.eclipse.debug.core/.launches/proj.android (1).launch new file mode 100644 index 0000000..719992a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.debug.core/.launches/proj.android (1).launch @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.debug.core/.launches/proj.android.launch b/.metadata/.plugins/org.eclipse.debug.core/.launches/proj.android.launch new file mode 100644 index 0000000..5e45761 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.debug.core/.launches/proj.android.launch @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.debug.ui/dialog_settings.xml b/.metadata/.plugins/org.eclipse.debug.ui/dialog_settings.xml new file mode 100644 index 0000000..4c3ca5a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.debug.ui/dialog_settings.xml @@ -0,0 +1,11 @@ + +
+
+ + + + + + +
+
diff --git a/.metadata/.plugins/org.eclipse.debug.ui/launchConfigurationHistory.xml b/.metadata/.plugins/org.eclipse.debug.ui/launchConfigurationHistory.xml new file mode 100644 index 0000000..c2fcf17 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.debug.ui/launchConfigurationHistory.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi new file mode 100644 index 0000000..f8a4f0a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi @@ -0,0 +1,2441 @@ + + + activeSchemeId:org.eclipse.ui.defaultAcceleratorConfiguration + + topLevel + + + + + persp.actionSet:org.eclipse.ui.cheatsheets.actionSet + persp.actionSet:org.eclipse.search.searchActionSet + persp.actionSet:org.eclipse.ui.edit.text.actionSet.annotationNavigation + persp.actionSet:org.eclipse.ui.edit.text.actionSet.navigation + persp.actionSet:org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo + persp.actionSet:org.eclipse.ui.externaltools.ExternalToolsSet + persp.actionSet:org.eclipse.ui.actionSet.keyBindings + persp.actionSet:org.eclipse.ui.actionSet.openFiles + persp.actionSet:org.eclipse.debug.ui.launchActionSet + persp.actionSet:org.eclipse.jdt.ui.JavaActionSet + persp.actionSet:org.eclipse.jdt.ui.JavaElementCreationActionSet + persp.actionSet:org.eclipse.ui.NavigateActionSet + persp.viewSC:org.eclipse.jdt.ui.PackageExplorer + persp.viewSC:org.eclipse.jdt.ui.TypeHierarchy + persp.viewSC:org.eclipse.jdt.ui.SourceView + persp.viewSC:org.eclipse.jdt.ui.JavadocView + persp.viewSC:org.eclipse.search.ui.views.SearchView + persp.viewSC:org.eclipse.ui.console.ConsoleView + persp.viewSC:org.eclipse.ui.views.ContentOutline + persp.viewSC:org.eclipse.ui.views.ProblemView + persp.viewSC:org.eclipse.ui.views.ResourceNavigator + persp.viewSC:org.eclipse.ui.views.TaskList + persp.viewSC:org.eclipse.ui.views.ProgressView + persp.viewSC:org.eclipse.ui.navigator.ProjectExplorer + persp.viewSC:org.eclipse.ui.texteditor.TemplatesView + persp.viewSC:org.eclipse.pde.runtime.LogView + persp.newWizSC:org.eclipse.jdt.ui.wizards.JavaProjectWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewPackageCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewClassCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewEnumCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewAnnotationCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewSourceFolderCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewSnippetFileCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewJavaWorkingSetWizard + persp.newWizSC:org.eclipse.ui.wizards.new.folder + persp.newWizSC:org.eclipse.ui.wizards.new.file + persp.newWizSC:org.eclipse.ui.editors.wizards.UntitledTextFileWizard + persp.perspSC:org.eclipse.jdt.ui.JavaBrowsingPerspective + persp.perspSC:org.eclipse.debug.ui.DebugPerspective + persp.newWizSC:com.android.ide.eclipse.adt.project.NewProjectWizard + persp.newWizSC:com.android.ide.eclipse.editors.wizards.NewXmlFileWizard + persp.actionSet:adt.actionSet.wizards + persp.actionSet:adt.actionSet.avdManager + persp.actionSet:adt.actionSet.lint + persp.actionSet:adt.actionSet.refactorings + persp.perspSC:com.android.ide.eclipse.ddms.Perspective + persp.perspSC:com.android.ide.eclipse.hierarchyviewer.PixelPerfectPespective + persp.perspSC:com.android.ide.eclipse.hierarchyviewer.TreeViewPerspective + persp.viewSC:org.eclipse.ant.ui.views.AntView + persp.showIn:org.eclipse.egit.ui.RepositoriesView + persp.actionSet:org.eclipse.debug.ui.breakpointActionSet + persp.actionSet:org.eclipse.jdt.debug.ui.JDTDebugActionSet + persp.newWizSC:org.eclipse.jdt.junit.wizards.NewTestCaseCreationWizard + persp.actionSet:org.eclipse.jdt.junit.JUnitActionSet + persp.showIn:org.eclipse.jdt.ui.PackageExplorer + persp.showIn:org.eclipse.team.ui.GenericHistoryView + persp.showIn:org.eclipse.ui.views.ResourceNavigator + persp.showIn:org.eclipse.ui.navigator.ProjectExplorer + + + + newtablook + org.eclipse.e4.primaryNavigationStack + + + + + + + + newtablook + + + + + + + + newtablook + org.eclipse.e4.secondaryNavigationStack + + + + + + + newtablook + org.eclipse.e4.secondaryDataStack + + + + + + + + + + + + + + + persp.actionSet:org.eclipse.ui.cheatsheets.actionSet + persp.actionSet:org.eclipse.search.searchActionSet + persp.actionSet:org.eclipse.ui.edit.text.actionSet.annotationNavigation + persp.actionSet:org.eclipse.ui.edit.text.actionSet.navigation + persp.actionSet:org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo + persp.actionSet:org.eclipse.ui.externaltools.ExternalToolsSet + persp.actionSet:org.eclipse.ui.actionSet.keyBindings + persp.actionSet:org.eclipse.ui.actionSet.openFiles + persp.actionSet:org.eclipse.debug.ui.launchActionSet + persp.actionSet:org.eclipse.debug.ui.debugActionSet + persp.viewSC:org.eclipse.debug.ui.DebugView + persp.viewSC:org.eclipse.debug.ui.VariableView + persp.viewSC:org.eclipse.debug.ui.BreakpointView + persp.viewSC:org.eclipse.debug.ui.ExpressionView + persp.viewSC:org.eclipse.ui.views.ContentOutline + persp.viewSC:org.eclipse.ui.console.ConsoleView + persp.viewSC:org.eclipse.ui.views.TaskList + persp.viewSC:com.android.ide.eclipse.ddms.views.LogCatView + persp.viewSC:com.android.ide.eclipse.ddms.views.DeviceView + persp.perspSC:com.android.ide.eclipse.ddms.Perspective + persp.viewSC:org.eclipse.ant.ui.views.AntView + persp.viewSC:org.eclipse.cdt.debug.ui.SignalsView + persp.viewSC:org.eclipse.debug.ui.RegisterView + persp.viewSC:org.eclipse.debug.ui.ModuleView + persp.viewSC:org.eclipse.debug.ui.MemoryView + persp.viewSC:org.eclipse.ui.views.ProblemView + persp.viewSC:org.eclipse.cdt.debug.ui.executablesView + persp.actionSet:org.eclipse.cdt.debug.ui.debugActionSet + persp.viewSC:org.eclipse.cdt.dsf.gdb.ui.tracecontrol.view + persp.viewSC:org.eclipse.cdt.dsf.debug.ui.disassembly.view + persp.perspSC:org.eclipse.cdt.ui.CPerspective + persp.actionSet:org.eclipse.ui.NavigateActionSet + persp.actionSet:org.eclipse.debug.ui.breakpointActionSet + persp.viewSC:org.eclipse.pde.runtime.LogView + persp.showIn:org.eclipse.egit.ui.RepositoriesView + persp.actionSet:org.eclipse.jdt.debug.ui.JDTDebugActionSet + persp.viewSC:org.eclipse.jdt.debug.ui.DisplayView + persp.perspSC:org.eclipse.jdt.ui.JavaPerspective + persp.perspSC:org.eclipse.jdt.ui.JavaBrowsingPerspective + persp.actionSet:org.eclipse.jdt.ui.JavaActionSet + persp.showIn:org.eclipse.jdt.ui.PackageExplorer + persp.perspSC:org.eclipse.wst.xml.ui.perspective + + + + + newtablook + org.eclipse.e4.primaryNavigationStack + + + + + + + newtablook + + + + + + + + + + + + newtablook + org.eclipse.e4.secondaryNavigationStack + + + + + + + + + + newtablook + + + + newtablook + org.eclipse.e4.secondaryDataStack + + + + + + + + + + + + + + + + + + + + + View + categoryTag:Help + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:Help + + + + newtablook + org.eclipse.e4.primaryDataStack + EditorStack + + + Editor + org.eclipse.jdt.ui.CompilationUnitEditor + removeOnHide + activeOnClose + + + + + + View + categoryTag:Java + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:Java + + + View + categoryTag:General + + + View + categoryTag:General + + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:General + + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:General + + + View + categoryTag:Ant + + + View + categoryTag:Git + + + View + categoryTag:Java + + + + View + categoryTag:Android + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:Debug + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:Debug + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:Debug + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:General + + + + toolbarSeparator + + + + Draggable + + + + + + + + + + + + + + + + toolbarSeparator + + + + Draggable + + + + + + Draggable + + + + + Draggable + + + + + Draggable + + + + + Draggable + + + + + + + Draggable + + + + + + + Draggable + + + + + + Draggable + + + + + + + + + toolbarSeparator + + + + Draggable + + + + + + + + + + + + toolbarSeparator + + + + toolbarSeparator + + + + Draggable + + + + + stretch + + + glue + + + + glue + + + Draggable + + + + + stretch + + + + Draggable + + + + + TrimStack + + + + + + + + + + + + + + + + + + + + platform:cocoa + + + locale:zh + + + + + + + + + platform:cocoa + + + + + + + + + + + + + + platform:cocoa + + + locale:zh + + + platform:cocoa + + + platform:cocoa + + + + + + + + + + + + + + + + + + + + platform:cocoa + + + + + + + + + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + + + + + + + + + + + + + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + platform:cocoa + + + + locale:zh + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + platform:cocoa + + + + platform:cocoa + + + platform:cocoa + + + + platform:cocoa + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + + + + + + platform:cocoa + + + + + + + + + + platform:cocoa + + + + + platform:cocoa + + + + + + + + + + + + + + + + + + + + + + + locale:zh + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + + platform:cocoa + + + + + + + + + + + + + + + + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + + + platform:cocoa + + + + platform:cocoa + + + + + platform:cocoa + + + + platform:cocoa + + + + platform:cocoa + + + + + platform:cocoa + + + platform:cocoa + + + + + + + + + + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + platform:cocoa + + + platform:cocoa + + + + + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + platform:cocoa + + + + + + + + + + platform:cocoa + + + + + + platform:cocoa + + + + + + + platform:cocoa + + + + + platform:cocoa + + + platform:cocoa + + + + + + platform:cocoa + + + + + platform:cocoa + + + + + + + + + + + + + + + + + + platform:cocoa + + + + + + + + + + + + + + + platform:cocoa + + + + + + platform:cocoa + + + + + + + + + + + + + + + + + + + + + + + + + platform:cocoa + + + platform:cocoa + + + + + + + + + + + + + + + + platform:cocoa + + + platform:cocoa + + + + + platform:cocoa + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Editor + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Tracer for OpenGL ES + + + View + categoryTag:Tracer for OpenGL ES + + + View + categoryTag:Tracer for OpenGL ES + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Android + + + View + categoryTag:Ant + + + View + categoryTag:&C/C++ + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Make + + + View + categoryTag:&C/C++ + + + View + categoryTag:&C/C++ + + + View + categoryTag:&C/C++ + + + View + categoryTag:&C/C++ + + + View + categoryTag:&C/C++ + + + View + categoryTag:General + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Git + + + View + categoryTag:Git + + + View + categoryTag:Git + + + View + categoryTag:Git + + + View + categoryTag:General + + + View + categoryTag:Help + + + View + categoryTag:Debug + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:Java Browsing + + + View + categoryTag:Java Browsing + + + View + categoryTag:Java Browsing + + + View + categoryTag:Java Browsing + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:Team + + + View + categoryTag:Team + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:Help + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:XML + + + View + categoryTag:XML + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.jdt.core/1361584401.index b/.metadata/.plugins/org.eclipse.jdt.core/1361584401.index new file mode 100644 index 0000000..03683d3 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/1361584401.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/1423205185.index b/.metadata/.plugins/org.eclipse.jdt.core/1423205185.index new file mode 100644 index 0000000..8f8b131 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/1423205185.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/17206113.index b/.metadata/.plugins/org.eclipse.jdt.core/17206113.index new file mode 100644 index 0000000..5f5ee4e Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/17206113.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/2165888622.index b/.metadata/.plugins/org.eclipse.jdt.core/2165888622.index new file mode 100644 index 0000000..16b22f8 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/2165888622.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/2190866907.index b/.metadata/.plugins/org.eclipse.jdt.core/2190866907.index new file mode 100644 index 0000000..5fea1c1 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/2190866907.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/2213088605.index b/.metadata/.plugins/org.eclipse.jdt.core/2213088605.index new file mode 100644 index 0000000..e3011bc Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/2213088605.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/2741727132.index b/.metadata/.plugins/org.eclipse.jdt.core/2741727132.index new file mode 100644 index 0000000..12e1998 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/2741727132.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/3290624007.index b/.metadata/.plugins/org.eclipse.jdt.core/3290624007.index new file mode 100644 index 0000000..eb25788 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/3290624007.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/334757748.index b/.metadata/.plugins/org.eclipse.jdt.core/334757748.index new file mode 100644 index 0000000..7429bea Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/334757748.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/3848462231.index b/.metadata/.plugins/org.eclipse.jdt.core/3848462231.index new file mode 100644 index 0000000..2b2380c Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/3848462231.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/4209013441.index b/.metadata/.plugins/org.eclipse.jdt.core/4209013441.index new file mode 100644 index 0000000..3189987 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/4209013441.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/474682028.index b/.metadata/.plugins/org.eclipse.jdt.core/474682028.index new file mode 100644 index 0000000..ccca5a4 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/474682028.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/517444550.index b/.metadata/.plugins/org.eclipse.jdt.core/517444550.index new file mode 100644 index 0000000..8f8b131 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/517444550.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/703662753.index b/.metadata/.plugins/org.eclipse.jdt.core/703662753.index new file mode 100644 index 0000000..9659455 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/703662753.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps b/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps new file mode 100644 index 0000000..63e7928 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/invalidArchivesCache b/.metadata/.plugins/org.eclipse.jdt.core/invalidArchivesCache new file mode 100644 index 0000000..593f470 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/invalidArchivesCache differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/javaLikeNames.txt b/.metadata/.plugins/org.eclipse.jdt.core/javaLikeNames.txt new file mode 100644 index 0000000..8586397 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.core/javaLikeNames.txt @@ -0,0 +1 @@ +java \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache b/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache new file mode 100644 index 0000000..4c78d0b Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt b/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt new file mode 100644 index 0000000..c415f1a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt @@ -0,0 +1,13 @@ +INDEX VERSION 1.126+/Users/liuyuye/Desktop/FacebookDemo/projects/FacebookTutorial/.metadata/.plugins/org.eclipse.jdt.core +2213088605.index +4209013441.index +17206113.index +474682028.index +2741727132.index +3290624007.index +2165888622.index +2190866907.index +3848462231.index +1361584401.index +1423205185.index +334757748.index diff --git a/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat b/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat new file mode 100644 index 0000000..54b2a3e Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat differ diff --git a/.metadata/.plugins/org.eclipse.jdt.launching/.install.xml b/.metadata/.plugins/org.eclipse.jdt.launching/.install.xml new file mode 100644 index 0000000..d0c0943 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.launching/.install.xml @@ -0,0 +1,4 @@ + + + + diff --git a/.metadata/.plugins/org.eclipse.jdt.launching/libraryInfos.xml b/.metadata/.plugins/org.eclipse.jdt.launching/libraryInfos.xml new file mode 100644 index 0000000..d549c44 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.launching/libraryInfos.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml b/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml new file mode 100644 index 0000000..a4ee3cb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml @@ -0,0 +1,2 @@ + + diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml new file mode 100644 index 0000000..ca6a6ca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml b/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml new file mode 100644 index 0000000..4c0b4d3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml @@ -0,0 +1,16 @@ + +
+
+ + + + + +
+
+
+
+
+
+
+
diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/8/refactorings.history b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/8/refactorings.history new file mode 100644 index 0000000..608d496 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/8/refactorings.history @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/8/refactorings.index b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/8/refactorings.index new file mode 100644 index 0000000..f41fbe5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/8/refactorings.index @@ -0,0 +1,2 @@ +1392881629032 Delete resource 'FacebookSDK' +1392888522073 Delete resource 'proj.android' diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/9/refactorings.history b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/9/refactorings.history new file mode 100644 index 0000000..48c8803 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/9/refactorings.history @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/9/refactorings.index b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/9/refactorings.index new file mode 100644 index 0000000..93f9f42 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2014/2/9/refactorings.index @@ -0,0 +1 @@ +1393228985013 Delete resource 'FriendPickerSample' diff --git a/.metadata/.plugins/org.eclipse.ltk.ui.refactoring/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ltk.ui.refactoring/dialog_settings.xml new file mode 100644 index 0000000..27eb404 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.ui.refactoring/dialog_settings.xml @@ -0,0 +1,7 @@ + +
+
+ + +
+
diff --git a/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml new file mode 100644 index 0000000..0dcaf23 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml @@ -0,0 +1,14 @@ + +
+
+ + +
+
+ + + + + +
+
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench.texteditor/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.workbench.texteditor/dialog_settings.xml new file mode 100644 index 0000000..a55e5ce --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ui.workbench.texteditor/dialog_settings.xml @@ -0,0 +1,31 @@ + +
+
+ + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
+
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml new file mode 100644 index 0000000..9d666b1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml @@ -0,0 +1,21 @@ + +
+
+ + + + + + + + + + +
+
+ + + + +
+
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml new file mode 100644 index 0000000..d538cb2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.wst.sse.ui/dialog_settings.xml b/.metadata/.plugins/org.eclipse.wst.sse.ui/dialog_settings.xml new file mode 100644 index 0000000..63fae25 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.wst.sse.ui/dialog_settings.xml @@ -0,0 +1,5 @@ + +
+
+
+
diff --git a/.metadata/version.ini b/.metadata/version.ini new file mode 100644 index 0000000..c51ff74 --- /dev/null +++ b/.metadata/version.ini @@ -0,0 +1 @@ +org.eclipse.core.runtime=1 \ No newline at end of file diff --git a/Classes/.DS_Store b/Classes/.DS_Store index 3044b7e..2ac4aa5 100644 Binary files a/Classes/.DS_Store and b/Classes/.DS_Store differ diff --git a/Classes/FacebookInterface.cpp b/Classes/FacebookInterface.cpp index 9e8db22..c5b075d 100755 --- a/Classes/FacebookInterface.cpp +++ b/Classes/FacebookInterface.cpp @@ -4,39 +4,18 @@ #include "platform/android/jni/JniHelper.h" #include #include - -/* -#include "ScriptingCore.h" - -const char* FBJavaClassName = "org/cocos2dx/facebookjsb/FacebookConnectPlugin"; - -extern jsval anonEvaluate(JSContext *cx, JSObject *thisObj, const char* string); -JSObject *fbObject = NULL; -*/ - +const char* FBJavaFriendClassName = "org/cocos/fbtutorial/FacebookPickFriendPlugin"; +const char* FBJavaLoginClassName = "org/cocos/fbtutorial/FacebookConnectPlugin"; +const char* FBJavaPostClassName = "org/cocos/fbtutorial/FacebookPostPlugin"; +const char* FBJavaSendRequestsClassName = "org/cocos/fbtutorial/FacebookSendRequestsPlugin"; const char* FBJavaClassName = "org/cocos/fbtutorial/FacebookConnectPlugin"; -extern "C"{ - /*void Java_org_cocos_fbtutorial_FacebookTutorial_nativeCallback(JNIEnv* env, jobject thiz, jint cbIndex,jstring params) - { - - //ScriptingCore* sc = ScriptingCore::getInstance(); - //JSContext *cx = sc->getGlobalContext(); - - //if (fbObject == NULL) - // fbObject = JSVAL_TO_OBJECT(anonEvaluate(cx, sc->getGlobalObject(), "(function () { return FB; })()")); - // - //jsval res; - - if (params != NULL) +extern "C" +{ + void Java_org_cocos_fbtutorial_FacebookConnectPlugin_nativeCallback(JNIEnv* env, jobject thiz, jint cbIndex,jstring params) + { + + if (params != NULL) { - //jsval argv[2]; - //argv[0] = INT_TO_JSVAL(cbIndex); - - //std::string tstr = JniHelper::jstring2string(params); - //argv[1] = std_string_to_jsval(cx,tstr); - - //JS_CallFunctionName(cx, fbObject, "callback", 2, argv, &res); - const char* str; str = env->GetStringUTFChars(params, 0); std::string tstr(str); @@ -44,119 +23,114 @@ extern "C"{ } else { - //jsval argv[1]; - //argv[0] = INT_TO_JSVAL(cbIndex); - - //JS_CallFunctionName(cx, fbObject, "callback", 1, argv, &res); std::string tstr = ""; HelloWorld::CallFunctionName(cbIndex,tstr); } - }*/ + } }; - -void FacebookInterface::callbackJs(int cbIndex, const char* params){ - -} - void FacebookInterface::login(int cbIndex,const char* scope){ cocos2d::JniMethodInfo t; if (cocos2d::JniHelper::getStaticMethodInfo(t - , FBJavaClassName - , "login" - , "(ILjava/lang/String;)V")) + , FBJavaLoginClassName + , "login" + , "(ILjava/lang/String;)V")) { if (scope) { jstring jeventId = t.env->NewStringUTF(scope); t.env->CallStaticVoidMethod(t.classID, t.methodID, cbIndex,jeventId); t.env->DeleteLocalRef(jeventId); - } + } else { t.env->CallStaticVoidMethod(t.classID, t.methodID, cbIndex,NULL); - } + } t.env->DeleteLocalRef(t.classID); - } + } } void FacebookInterface::logout(int cbIndex){ - /* - JniMethodInfo t; - if (JniHelper::getStaticMethodInfo(t - , FBJavaClassName - , "logout" - , "(I)V")) + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t + , FBJavaClassName + , "logout" + , "(I)V")) { t.env->CallStaticVoidMethod(t.classID, t.methodID, cbIndex); t.env->DeleteLocalRef(t.classID); - } - */ + } } -void FacebookInterface::getLoginStatus(int cbIndex){ +const char* FacebookInterface::getStatus(int cbIndex){ cocos2d::JniMethodInfo t; if (cocos2d::JniHelper::getStaticMethodInfo(t - , FBJavaClassName - , "getLoginStatus" - , "(I)V")) + , FBJavaClassName + , "getStatus" + , "(I)Ljava/lang/String;")) + { + jstring ret = (jstring)(t.env->CallStaticObjectMethod(t.classID, t.methodID,cbIndex)); + t.env->DeleteLocalRef(t.classID); + const char* aStr = " "; + aStr = t.env->GetStringUTFChars(ret, false); + return aStr; + } +} + +void FacebookInterface::pickFriend(int cbIndex){ + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t + , FBJavaFriendClassName + , "pickFriend" + , "(I)V")) { t.env->CallStaticVoidMethod(t.classID, t.methodID, cbIndex); t.env->DeleteLocalRef(t.classID); - } - + } } -std::string FacebookInterface::api(const char* graphPath,const char* method,const char* params,int cbIndex){ - std::string errorRet; - /* - JniMethodInfo t; - - - if (JniHelper::getStaticMethodInfo(t - , FBJavaClassName - , "api" - , "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;")) +void FacebookInterface::postStatus(int cbIndex,const char* name,const char* caption,const char* description,const char* link,const char* picture){ + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t + , FBJavaPostClassName + , "postStatus" + , "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) { - jstring jgraphPath = t.env->NewStringUTF(graphPath); - jstring jmethod = NULL; - if(method) - jmethod = t.env->NewStringUTF(method); - jstring jparams = NULL; - if(params) - jparams = t.env->NewStringUTF(params); + CCLOG("ajhsdkjahdkjahkjsdhakjsdhajksd"); + if (name && caption && description && link && picture) + { + jstring nameId = t.env->NewStringUTF(name); + jstring captionId = t.env->NewStringUTF(name); + jstring descriptionId = t.env->NewStringUTF(name); + jstring linkId = t.env->NewStringUTF(name); + jstring pictureId = t.env->NewStringUTF(name); + + t.env->CallStaticVoidMethod(t.classID, t.methodID, cbIndex,nameId,captionId,descriptionId,linkId,pictureId); + t.env->DeleteLocalRef(nameId); + t.env->DeleteLocalRef(captionId); + t.env->DeleteLocalRef(descriptionId); + t.env->DeleteLocalRef(linkId); + t.env->DeleteLocalRef(pictureId); + } + else + { + t.env->CallStaticVoidMethod(t.classID, t.methodID, cbIndex,NULL); + } - jstring ret = (jstring)(t.env->CallStaticObjectMethod(t.classID, t.methodID, jgraphPath,jmethod,jparams,cbIndex)); - t.env->DeleteLocalRef(jgraphPath); - if(method) - t.env->DeleteLocalRef(jmethod); - if(params) - t.env->DeleteLocalRef(jparams); t.env->DeleteLocalRef(t.classID); - - if (ret != NULL) - errorRet = JniHelper::jstring2string(ret); - } - */ - - return errorRet; + } } -void FacebookInterface::ui(const char* params,int cbIndex){ - +void FacebookInterface::sendRequests(int cbIndex){ cocos2d::JniMethodInfo t; if (cocos2d::JniHelper::getStaticMethodInfo(t - , FBJavaClassName - , "ui" - , "(Ljava/lang/String;I)V")) + , FBJavaSendRequestsClassName + , "sendRequests" + , "(I)V")) { - jstring jparams = t.env->NewStringUTF(params); - t.env->CallStaticVoidMethod(t.classID, t.methodID, jparams,cbIndex); - t.env->DeleteLocalRef(jparams); + t.env->CallStaticVoidMethod(t.classID, t.methodID, cbIndex); t.env->DeleteLocalRef(t.classID); - } - + } } - #endif diff --git a/Classes/FacebookInterface.h b/Classes/FacebookInterface.h index 0d01687..dfcc7d6 100755 --- a/Classes/FacebookInterface.h +++ b/Classes/FacebookInterface.h @@ -6,14 +6,14 @@ class FacebookInterface { public: - static void login(int cbIndex,const char* scope); - static void logout(int cbIndex); - static void getLoginStatus(int cbIndex); - static std::string api(const char* graphPath,const char* method,const char* params,int cbIndex); - static void ui(const char* params,int cbIndex); - //for callback static void callbackJs(int cbIndex, const char* params); + + static void login(int cbIndex,const char* scope); + static void logout(int cbIndex); + static const char* getStatus(int cbIndex); + static void pickFriend(int cbIndex); + static void postStatus(int cbIndex,const char* name,const char* caption,const char* description,const char* link,const char* picture); + static void sendRequests(int cbIndex); }; - -#endif //__INTERFACE_FACEBOOK_H_ \ No newline at end of file +#endif //__INTERFACE_FACEBOOK_H_ diff --git a/Classes/HelloWorldScene.cpp b/Classes/HelloWorldScene.cpp index c24ac07..3895bce 100644 --- a/Classes/HelloWorldScene.cpp +++ b/Classes/HelloWorldScene.cpp @@ -11,6 +11,7 @@ using namespace std; bool HelloWorld::isCallBack = false; int HelloWorld::pressedButtonNum = -1; +string HelloWorld::friendListStr = ""; CCScene* HelloWorld::scene() { @@ -31,10 +32,11 @@ bool HelloWorld::init() CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); - statusLabel = CCLabelTTF::create("LogIn", "Arial", 100); + statusLabel = CCLabelTTF::create("LogIn", "Arial", 100, + CCSizeMake(100*5, 0), kCCTextAlignmentCenter,kCCVerticalTextAlignmentTop); statusLabel->setColor(ccBLUE); statusLabel->setPosition(ccp(origin.x + statusLabel->getContentSize().width/2, - origin.y + visibleSize.height - statusLabel->getContentSize().height)); + origin.y + visibleSize.height/2)); this->addChild(statusLabel, 1); @@ -48,7 +50,9 @@ bool HelloWorld::init() menuVect.push_back("login"); menuVect.push_back("logout"); menuVect.push_back("getStatus"); - + menuVect.push_back("post"); + menuVect.push_back("pickFriend"); + menuVect.push_back("sendRequests"); for (int i = 0; isetString(FacebookInterface::getStatus(1)); + } + break; + case 3: + FacebookInterface::postStatus(3, + "Facebook SDK for Android", + "Build great social apps and get more installs.", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.", + "https://developers.facebook.com/android", + "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); + break; + case 4: + FacebookInterface::pickFriend(4); + break; + case 5: + FacebookInterface::sendRequests(5); + break; + default: break; } @@ -94,9 +117,21 @@ void HelloWorld::menuCloseCallback(CCObject* pSender) void HelloWorld::CallFunctionName(int cbIndex,string tstr) { - isCallBack = true; HelloWorld::pressedButtonNum = cbIndex; - // CCLOG("%s",tstr.c_str()); + switch (HelloWorld::pressedButtonNum) + { + case 3: + break; + case 4: + HelloWorld::friendListStr = tstr; + CCLOG("HelloWorld::friendListStr=%s",HelloWorld::friendListStr.c_str()); + break; + case 5: + break; + default: + break; + } + isCallBack = true; } void HelloWorld::FacebookCallback(float dt) { @@ -106,13 +141,37 @@ void HelloWorld::FacebookCallback(float dt) } switch (HelloWorld::pressedButtonNum) { + isCallBack = false; // add Facebook3 case 0: { statusLabel->setString("logout"); } - break; + break; + case 1: + { + statusLabel->setString("login"); + } + break; + case 2: + { + statusLabel->setString(FacebookInterface::getStatus(1)); + } + break; + case 3: + { + } + //FacebookInterface::postStatus(3); + break; + case 4: + { + statusLabel->setString(HelloWorld::friendListStr.c_str()); + } + break; + case 5: + //FacebookInterface::sendRequests(5); + break; default: break; } diff --git a/Classes/HelloWorldScene.h b/Classes/HelloWorldScene.h index 031676b..ec2efa5 100644 --- a/Classes/HelloWorldScene.h +++ b/Classes/HelloWorldScene.h @@ -18,6 +18,8 @@ class HelloWorld : public cocos2d::CCLayer static int pressedButtonNum; + static std::string friendListStr; + // a selector callback void menuCloseCallback(CCObject* pSender); diff --git a/proj.android/AndroidManifest.xml b/proj.android/AndroidManifest.xml index bb55f64..9568c7a 100644 --- a/proj.android/AndroidManifest.xml +++ b/proj.android/AndroidManifest.xml @@ -8,7 +8,8 @@ + android:icon="@drawable/icon" + android:name="org.cocos.fbtutorial.FriendPickerApplication"> + + android:icon="@drawable/icon" + android:name="org.cocos.fbtutorial.FriendPickerApplication"> + + + + + + + diff --git a/proj.android/res/values/strings.xml b/proj.android/res/values/strings.xml index 545d589..3a9aaf1 100644 --- a/proj.android/res/values/strings.xml +++ b/proj.android/res/values/strings.xml @@ -2,4 +2,5 @@ FacebookTutorial 1537694433122352 - + Exception: %1$s + \ No newline at end of file diff --git a/proj.android/src/org/cocos/fbtutorial/FacebookConnectPlugin.java b/proj.android/src/org/cocos/fbtutorial/FacebookConnectPlugin.java index f936e79..9c1ba5d 100644 --- a/proj.android/src/org/cocos/fbtutorial/FacebookConnectPlugin.java +++ b/proj.android/src/org/cocos/fbtutorial/FacebookConnectPlugin.java @@ -1,23 +1,23 @@ package org.cocos.fbtutorial; import java.util.Arrays; - -import com.facebook.Session; -import com.facebook.SessionState; -import com.facebook.UiLifecycleHelper; - import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; +import com.facebook.Request; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; + public class FacebookConnectPlugin { private static final String TAG = "FacebookPlugin"; private static FacebookConnectPlugin instance; private UiLifecycleHelper uiHelper; private Session.StatusCallback statusCallback = new SessionStatusCallback(); private Activity activity; - + private static int callIndex; public FacebookConnectPlugin(Activity activity) { this.activity = activity; instance = this; @@ -29,20 +29,24 @@ public void onCreate(Bundle savedInstanceState) { } public static void login(int cbIndex, String scope) { + callIndex = cbIndex; instance.login_(); } - + public void login_() { + Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { - session.openForRead(new Session.OpenRequest(activity).setPermissions( - Arrays.asList("basic_info")).setCallback(statusCallback)); + session.openForRead(new Session.OpenRequest(activity) + .setPermissions(Arrays.asList("basic_info")).setCallback( + statusCallback)); } else { Session.openActiveSession(activity, true, statusCallback); } } - public static void logout(int cbIndex, String scope) { + public static void logout(int cbIndex) { instance.logout_(); + callIndex = cbIndex; } public void logout_() { @@ -51,17 +55,47 @@ public void logout_() { session.closeAndClearTokenInformation(); } } - public static void getStatus(int cbIndex, String scope) { - instance.getStatus_(); + public static String getStatus(int cbIndex) { + + callIndex = cbIndex; + + return instance.getStatus_(); } - public void getStatus_() { - /* - Session session = Session.getActiveSession(); - if (!session.isClosed()) { - session.closeAndClearTokenInformation(); - } - */ + public String getStatus_() { + + Session session = Session.getActiveSession(); + + if (session.getState().equals(SessionState.CREATED)) + { + return "CREATED"; + } + else if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) + { + return "CREATED_TOKEN_LOADED"; + } + else if (session.getState().equals(SessionState.OPENING)) + { + return "OPENING"; + } + else if (session.getState().equals(SessionState.OPENED)) + { + return "OPENED"; + } + else if (session.getState().equals(SessionState.OPENED_TOKEN_UPDATED)) + { + return "OPENED_TOKEN_UPDATED"; + } + else if (session.getState().equals(SessionState.CLOSED_LOGIN_FAILED)) + { + return "CLOSED_LOGIN_FAILED"; + } + else if (session.getState().equals(SessionState.CLOSED)) + { + return "CLOSED"; + } + + return ""; } public void onResume() { // For scenarios where the main activity is launched and user @@ -71,9 +105,6 @@ public void onResume() { if (session != null && (session.isOpened() || session.isClosed())) { onSessionStateChange(session, session.getState(), null); } - if(uiHelper == null){ - Log.i(TAG, "ddd"); - } uiHelper.onResume(); } @@ -93,6 +124,8 @@ public void onDestory() { uiHelper.onDestroy(); } + + private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { @@ -101,13 +134,15 @@ private void onSessionStateChange(Session session, SessionState state, Log.i(TAG, "Logged out..."); } } - + public static native void nativeCallback(int cbIndex, String params); private class SessionStatusCallback implements Session.StatusCallback { @Override public void call(Session session, SessionState state, Exception exception) { // Respond to session state changes, ex: updating the view onSessionStateChange(session, state, exception); + + nativeCallback(callIndex,""); } - } + } } diff --git a/proj.android/src/org/cocos/fbtutorial/FacebookPickFriendPlugin.java b/proj.android/src/org/cocos/fbtutorial/FacebookPickFriendPlugin.java new file mode 100644 index 0000000..3dff709 --- /dev/null +++ b/proj.android/src/org/cocos/fbtutorial/FacebookPickFriendPlugin.java @@ -0,0 +1,120 @@ +package org.cocos.fbtutorial; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; + +public class FacebookPickFriendPlugin { + private static final int PICK_FRIENDS_ACTIVITY = 1; + private static final String TAG = "FacebookPlugin"; + private static FacebookPickFriendPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + boolean pickFriendsWhenSessionOpened; + public static int callIndex; + + public static void pickFriend(int cbIndex) { + callIndex = cbIndex; + instance.pickFriend_(); + } + + public FacebookPickFriendPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + } + + public void pickFriend_() { + if (ensureOpenSession()) { + Intent intent = new Intent(activity, PickFriendsActivity.class); + // Note: The following line is optional, as multi-select behavior is + // the default for + // FriendPickerFragment. It is here to demonstrate how parameters + // could be passed to the + // friend picker if single-select functionality was desired, or if a + // different user ID was + // desired (for instance, to see friends of a friend). + PickFriendsActivity.populateParameters(intent, null, true, true); + activity.startActivityForResult(intent, PICK_FRIENDS_ACTIVITY); + } else { + pickFriendsWhenSessionOpened = true; + } + } + + private boolean ensureOpenSession() { + if (Session.getActiveSession() == null + || !Session.getActiveSession().isOpened()) { + Session.openActiveSession(activity, true, statusCallback); + return false; + } + return true; + } + + private class SessionStatusCallback implements Session.StatusCallback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + if (pickFriendsWhenSessionOpened && state.isOpened()) { + pickFriendsWhenSessionOpened = false; + pickFriend_(); + } + } + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + /* + * ------------------------- + * + * @Override public void onActivityResult(int requestCode, int resultCode, + * Intent data) { switch (requestCode) { case PICK_FRIENDS_ACTIVITY: + * displaySelectedFriends(resultCode); break; default: + * Session.getActiveSession().onActivityResult(this, requestCode, + * resultCode, data); break; } } -------------------------------- + */ +} diff --git a/proj.android/src/org/cocos/fbtutorial/FacebookPostPlugin.java b/proj.android/src/org/cocos/fbtutorial/FacebookPostPlugin.java new file mode 100644 index 0000000..6e381cd --- /dev/null +++ b/proj.android/src/org/cocos/fbtutorial/FacebookPostPlugin.java @@ -0,0 +1,280 @@ +package org.cocos.fbtutorial; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.android.AsyncFacebookRunner; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookPostPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookPostPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + static public String name = null; + static public String caption = null; + static public String description = null; + static public String link = null; + static public String picture = null; + + public FacebookPostPlugin(Activity activity) + { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler() + { + @Override + public void handleMessage(Message msg) + { + super.handleMessage(msg); + switch(msg.what) + { + case 1: + postStatus_(); + break; + default: + break; + } + } + }; + } + + public static void postStatus(int cbIndex,String aName,String aCaption,String aDescription,String aLink,String aPicture) + { + name = aName; + caption = aCaption; + description = aDescription; + link = aLink; + picture = aPicture; + + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + //instance.postStatus_(); + } + + public void postStatus_() { + + if (FacebookDialog.canPresentShareDialog( + activity.getApplicationContext(), + FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { + Log.i(TAG, "canPresent"); + // Publish the post using the Share Dialog + FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder( + activity) + .setLink("https://developers.facebook.com/android").build(); + uiHelper.trackPendingDialogCall(shareDialog.present()); + + } else { + // Fallback. For example, publish the post using the Feed Dialog + Log.i(TAG, "webdialog"); + publishFeedDialog(); + } + + } + + private void publishFeedDialog() { + Bundle params = new Bundle(); + + Log.i("name", name); + Log.i("caption",caption); + Log.i("description",description); + Log.i("link",link); + Log.i("picture",picture); + + params.putString("name", name); + params.putString("caption",caption); + params.putString("description",description); + params.putString("link",link); + params.putString("picture",picture); + + /* + params.putString("name", "Facebook SDK for Android"); + params.putString("caption", + "Build great social apps and get more installs."); + + params.putString( + "description", + "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); + params.putString("link", "https://developers.facebook.com/android"); + + + params.putString("picture", "//https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); +*/ + + /* + params.putString("method", "photos.upload"); + + byte[] data = null; + + AssetManager am = activity.getAssets(); + try + { + InputStream is = am.open("CloseSelected.png"); + Bitmap bi=BitmapFactory.decodeStream(is); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); + data = baos.toByteArray(); + params.putByteArray("picture", data); + Log.i("10000","innnnnnnn"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + + WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, + Session.getActiveSession(), params)).setOnCompleteListener( + new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error == null) { + // When the story is posted, echo the success + // and the post Id. + final String postId = values.getString("post_id"); + if (postId != null) { + Toast.makeText(activity, + "Posted story, id: " + postId, + Toast.LENGTH_SHORT).show(); + } else { + // User clicked the Cancel button + Toast.makeText( + activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } + } else if (error instanceof FacebookOperationCanceledException) { + // User clicked the "x" button + Toast.makeText(activity.getApplicationContext(), + "Publish cancelled", Toast.LENGTH_SHORT) + .show(); + } else { + // Generic, ex: network error + Toast.makeText(activity.getApplicationContext(), + "Error posting story", Toast.LENGTH_SHORT) + .show(); + } + } + + }).build(); + feedDialog.show(); + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/proj.android/src/org/cocos/fbtutorial/FacebookSendRequestsPlugin.java b/proj.android/src/org/cocos/fbtutorial/FacebookSendRequestsPlugin.java new file mode 100644 index 0000000..e22a5e1 --- /dev/null +++ b/proj.android/src/org/cocos/fbtutorial/FacebookSendRequestsPlugin.java @@ -0,0 +1,187 @@ +package org.cocos.fbtutorial; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; +import android.widget.Toast; + +import com.facebook.FacebookException; +import com.facebook.FacebookOperationCanceledException; +import com.facebook.Session; +import com.facebook.SessionState; +import com.facebook.UiLifecycleHelper; +import com.facebook.widget.FacebookDialog; +import com.facebook.widget.FacebookDialog.PendingCall; +import com.facebook.widget.WebDialog; +import com.facebook.widget.WebDialog.OnCompleteListener; + +public class FacebookSendRequestsPlugin { + private static final String TAG = "FacebookPostPlugin"; + private static FacebookSendRequestsPlugin instance; + private UiLifecycleHelper uiHelper; + private Session.StatusCallback statusCallback = new SessionStatusCallback(); + private Activity activity; + private Handler handler; + + public FacebookSendRequestsPlugin(Activity activity) { + this.activity = activity; + instance = this; + uiHelper = new UiLifecycleHelper(activity, statusCallback); + handler = new Handler() { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch (msg.what) { + case 1: + sendRequests_(); + break; + default: + break; + } + } + }; + } + + public static void sendRequests(int cbIndex) { + Message message = Message.obtain(); + message.what = 1; + instance.handler.sendMessage(message); + } + + public void sendRequests_() { + + Bundle params = new Bundle(); + params.putString("message", "Learn how to make your Android apps social"); + + WebDialog requestsDialog = ( + new WebDialog.RequestsDialogBuilder(activity, + Session.getActiveSession(), + params)) + .setOnCompleteListener(new OnCompleteListener() { + + @Override + public void onComplete(Bundle values, + FacebookException error) { + if (error != null) { + if (error instanceof FacebookOperationCanceledException) { + Toast.makeText(activity.getApplicationContext(), + "Request cancelled", + Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(activity.getApplicationContext(), + "Network Error", + Toast.LENGTH_SHORT).show(); + } + } else { + final String requestId = values.getString("request"); + if (requestId != null) { + Toast.makeText(activity.getApplicationContext(), + "Request sent", + Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(activity.getApplicationContext(), + "Request cancelled", + Toast.LENGTH_SHORT).show(); + } + } + } + + }) + .build(); + requestsDialog.show(); + + } + + private class SessionStatusCallback implements Session.StatusCallback, + FacebookDialog.Callback { + @Override + public void call(Session session, SessionState state, + Exception exception) { + // Respond to session state changes, ex: updating the view + onSessionStateChange(session, state, exception); + } + + @Override + public void onComplete(PendingCall pendingCall, Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onComplete"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + } + + @Override + public void onError(PendingCall pendingCall, Exception error, + Bundle data) { + // TODO Auto-generated method stub + Log.i(TAG, "ShareDialog onError"); + boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data); + String completionGesture = FacebookDialog + .getNativeDialogCompletionGesture(data); + String postId = FacebookDialog.getNativeDialogPostId(data); + Log.i(TAG, "didCancel:" + didCancel + "completionGesture:" + + completionGesture + "postId:" + postId); + + } + } + + private void onSessionStateChange(Session session, SessionState state, + Exception exception) { + if (state.isOpened()) { + Log.i(TAG, "Logged in..."); + } else if (state.isClosed()) { + Log.i(TAG, "Logged out..."); + } + } + + public void onCreate(Bundle savedInstanceState) { + uiHelper.onCreate(savedInstanceState); + } + + public void onResume() { + // For scenarios where the main activity is launched and user + // session is not null, the session state change notification + // may not be triggered. Trigger it if it's open/closed. + Session session = Session.getActiveSession(); + if (session != null && (session.isOpened() || session.isClosed())) { + onSessionStateChange(session, session.getState(), null); + } + uiHelper.onResume(); + } + + public void onPause() { + uiHelper.onPause(); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); + } + + public void onSaveInstanceState(Bundle outState) { + uiHelper.onSaveInstanceState(outState); + } + + public void onDestory() { + uiHelper.onDestroy(); + } + + private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { + @Override + public void onError(FacebookDialog.PendingCall pendingCall, + Exception error, Bundle data) { + Log.d("HelloFacebook", String.format("Error: %s", error.toString())); + } + + @Override + public void onComplete(FacebookDialog.PendingCall pendingCall, + Bundle data) { + Log.d("HelloFacebook", "Success!"); + } + }; +} diff --git a/proj.android/src/org/cocos/fbtutorial/FacebookTutorial.java b/proj.android/src/org/cocos/fbtutorial/FacebookTutorial.java index 2b31b5f..6b56e7b 100644 --- a/proj.android/src/org/cocos/fbtutorial/FacebookTutorial.java +++ b/proj.android/src/org/cocos/fbtutorial/FacebookTutorial.java @@ -31,12 +31,22 @@ of this software and associated documentation files (the "Software"), to deal public class FacebookTutorial extends Cocos2dxActivity { - protected FacebookConnectPlugin facebookVan = null; + protected FacebookConnectPlugin facebookLoginPlugin = null; + protected FacebookPickFriendPlugin facebooFriendPlugin = null; + protected FacebookPostPlugin facebookPostPlugin = null; + protected FacebookSendRequestsPlugin facebookSendRequestsPlugin = null; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - facebookVan = new FacebookConnectPlugin(this); - facebookVan.onCreate(savedInstanceState); + facebookLoginPlugin = new FacebookConnectPlugin(this); + facebooFriendPlugin = new FacebookPickFriendPlugin(this); + facebookPostPlugin = new FacebookPostPlugin(this); + facebookSendRequestsPlugin = new FacebookSendRequestsPlugin(this); + facebookLoginPlugin.onCreate(savedInstanceState); + facebooFriendPlugin.onCreate(savedInstanceState); + facebookPostPlugin.onCreate(savedInstanceState); + facebookSendRequestsPlugin.onCreate(savedInstanceState); + } public Cocos2dxGLSurfaceView onCreateView() { @@ -54,31 +64,46 @@ public Cocos2dxGLSurfaceView onCreateView() { @Override public void onResume() { super.onResume(); - facebookVan.onResume(); + facebookLoginPlugin.onResume(); + facebooFriendPlugin.onResume(); + facebookPostPlugin.onResume(); + facebookSendRequestsPlugin.onResume(); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - facebookVan.onActivityResult(requestCode, resultCode, data); + facebookLoginPlugin.onActivityResult(requestCode, resultCode, data); + facebooFriendPlugin.onActivityResult(requestCode, resultCode, data); + facebookPostPlugin.onActivityResult(requestCode, resultCode, data); + facebookSendRequestsPlugin.onActivityResult(requestCode, resultCode, data); } @Override public void onPause() { super.onPause(); - facebookVan.onPause(); + facebookLoginPlugin.onPause(); + facebooFriendPlugin.onPause(); + facebookPostPlugin.onPause(); + facebookSendRequestsPlugin.onPause(); } @Override public void onDestroy() { super.onDestroy(); - facebookVan.onDestory(); + facebookLoginPlugin.onDestory(); + facebooFriendPlugin.onDestory(); + facebookPostPlugin.onDestory(); + facebookSendRequestsPlugin.onDestory(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - facebookVan.onSaveInstanceState(outState); + facebookLoginPlugin.onSaveInstanceState(outState); + facebooFriendPlugin.onSaveInstanceState(outState); + facebookPostPlugin.onSaveInstanceState(outState); + facebookSendRequestsPlugin.onSaveInstanceState(outState); } } diff --git a/proj.android/src/org/cocos/fbtutorial/FriendPickerApplication.java b/proj.android/src/org/cocos/fbtutorial/FriendPickerApplication.java new file mode 100755 index 0000000..58206b7 --- /dev/null +++ b/proj.android/src/org/cocos/fbtutorial/FriendPickerApplication.java @@ -0,0 +1,36 @@ +/** + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cocos.fbtutorial; + +import android.app.Application; +import com.facebook.model.GraphUser; + +import java.util.List; + +// We use a custom Application class to store our minimal state data (which users have been selected). +// A real-world application will likely require a more robust data model. +public class FriendPickerApplication extends Application { + private List selectedUsers; + + public List getSelectedUsers() { + return selectedUsers; + } + + public void setSelectedUsers(List selectedUsers) { + this.selectedUsers = selectedUsers; + } +} diff --git a/proj.android/src/org/cocos/fbtutorial/PickFriendsActivity.java b/proj.android/src/org/cocos/fbtutorial/PickFriendsActivity.java new file mode 100755 index 0000000..7e9eac6 --- /dev/null +++ b/proj.android/src/org/cocos/fbtutorial/PickFriendsActivity.java @@ -0,0 +1,131 @@ +/** + * Copyright 2010-present Facebook. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cocos.fbtutorial; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.text.TextUtils; +import android.util.Log; +import android.widget.Toast; +import com.facebook.FacebookException; +import com.facebook.model.GraphUser; +import com.facebook.widget.FriendPickerFragment; +import com.facebook.widget.PickerFragment; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +// This class provides an example of an Activity that uses FriendPickerFragment to display a list of +// the user's friends. It takes a programmatic approach to creating the FriendPickerFragment with the +// desired parameters -- see PickPlaceActivity in the PlacePickerSample project for an example of an +// Activity creating a fragment (in this case a PlacePickerFragment) via XML layout rather than +// programmatically. +public class PickFriendsActivity extends FragmentActivity { + FriendPickerFragment friendPickerFragment; + + // A helper to simplify life for callers who want to populate a Bundle with the necessary + // parameters. A more sophisticated Activity might define its own set of parameters; our needs + // are simple, so we just populate what we want to pass to the FriendPickerFragment. + public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar) { + intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY, userId); + intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect); + intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, showTitleBar); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.pick_friends_activity); + + FragmentManager fm = getSupportFragmentManager(); + + if (savedInstanceState == null) { + // First time through, we create our fragment programmatically. + final Bundle args = getIntent().getExtras(); + friendPickerFragment = new FriendPickerFragment(args); + fm.beginTransaction() + .add(R.id.friend_picker_fragment, friendPickerFragment) + .commit(); + } else { + // Subsequent times, our fragment is recreated by the framework and already has saved and + // restored its state, so we don't need to specify args again. (In fact, this might be + // incorrect if the fragment was modified programmatically since it was created.) + friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment); + } + + friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { + @Override + public void onError(PickerFragment fragment, FacebookException error) { + PickFriendsActivity.this.onError(error); + } + }); + + friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { + @Override + public void onDoneButtonClicked(PickerFragment fragment) { + // We just store our selection in the Application for other activities to look at. + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + application.setSelectedUsers(friendPickerFragment.getSelection()); + Collection selection = application.getSelectedUsers(); + String results = ""; + if (selection != null && selection.size() > 0) + { + ArrayList names = new ArrayList(); + for (GraphUser user : selection) + { + names.add(user.getName()); + } + results = TextUtils.join(", ", names); + FacebookConnectPlugin.nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + else + { + results = ""; + FacebookConnectPlugin.nativeCallback(FacebookPickFriendPlugin.callIndex,results); + } + + setResult(RESULT_OK, null); + finish(); + } + }); + } + private void onError(Exception error) { + String text = getString(R.string.exception, error.getMessage()); + Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); + toast.show(); + } + + @Override + protected void onStart() { + super.onStart(); + try { + FriendPickerApplication application = (FriendPickerApplication) getApplication(); + List selectedUsers = application.getSelectedUsers(); + if (selectedUsers != null && !selectedUsers.isEmpty()) { + friendPickerFragment.setSelection(selectedUsers); + } + // Load data, unless a query has already taken place. + friendPickerFragment.loadData(false); + } catch (Exception ex) { + ex.printStackTrace(); + onError(ex); + } + } +} diff --git a/proj.ios/FacebookTutorial.xcodeproj/project.xcworkspace/xcuserdata/liuyuye.xcuserdatad/UserInterfaceState.xcuserstate b/proj.ios/FacebookTutorial.xcodeproj/project.xcworkspace/xcuserdata/liuyuye.xcuserdatad/UserInterfaceState.xcuserstate index 9bb45b6..389cb6b 100644 Binary files a/proj.ios/FacebookTutorial.xcodeproj/project.xcworkspace/xcuserdata/liuyuye.xcuserdatad/UserInterfaceState.xcuserstate and b/proj.ios/FacebookTutorial.xcodeproj/project.xcworkspace/xcuserdata/liuyuye.xcuserdatad/UserInterfaceState.xcuserstate differ