Android Open Source - rsmonitor-heartrate Facebook Functions






From Project

Back to project page rsmonitor-heartrate.

License

The source code is released under:

GNU General Public License

If you think the Android project rsmonitor-heartrate listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.facebook.android;
//from w  w w .  j a v a2s.c  o  m
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URLEncoder;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;

import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.renaultsport.heartrate.R;




public class FacebookFunctions
{
  private static class LoginDialogListener implements Facebook.DialogListener
  {
    @Override
    public void onComplete (Bundle values)
    {
      SessionStore.save (FacebookFunctions.mFacebook, FacebookFunctions.mContext);
      SessionEvents.onLoginSuccess ();
    }

    @Override
    public void onFacebookError (FacebookError error) { SessionEvents.onLoginError (error.getMessage ()); }

    @Override
    public void onError (DialogError error) { SessionEvents.onLoginError (error.getMessage ()); }

    @Override
    public void onCancel () { SessionEvents.onLoginError ("Action canceled"); }
  }




  private static final String RENAULT_SPORT_URL      = "http://www.renault-sport.com/fr/";
  private static final String FACEBOOK_APP_ID        = "192073384232319";
  private static final String FACEBOOK_APP_NAME      = "R.S. Monitor de Renault Sport";
  private static final String FACEBOOK_APP_LOGO_URL    = "http://www.renault-sport.com/snippets/media/logo.jpg";
  private static final String GP_GET_REQUEST        = "GET";
  private static final String GP_POST_REQUEST        = "POST";
  private static final String GP_ACCESS_TOKEN        = "access_token";
  private static final String GP_METHOD          = "method";
  private static final String GP_PAGE_ID          = "page_id";
  private static final String GP_PAGES_ADD_FAN      = "pages.addFan";
  private static final String GP_PHOTOS_UPLOAD      = "photos.upload";
  private static final String GP_LINK            = "link";
  private static final String GP_NAME            = "name";
  private static final String GP_PICTURE          = "picture";
  private static final String GP_DESCRIPTION        = "description";
  private static final String GP_CONTENT_TYPE        = "contentType";
  private static final String GP_VIDEO_3GPP        = "video/3gpp";
  private static final String GP_LIKES_URI        = "/likes";
  private static final String GP_ME_URI          = "me";
  private static final String GP_ME_FEED_URI        = "me/feed";
  private static final String PACKAGE_NAME        = "com.facebook.katana";
  private static final String PUBLISH_PERMISSION      = "publish_stream";
  private static final String BIRTHDAY_PERMISSION      = "user_birthday";
  private static final String EMAIL_PERMISSION      = "email";

  private static String[]        PERMISSIONS  = null;
  private static int          mFacebookRequestCode  = 0;
  private static AsyncFacebookRunner  mAsyncFacebookRunner  = null;
  private static Context        mContext        = null;
  private static Facebook        mFacebook        = new Facebook (FACEBOOK_APP_ID);




  static
  {
    String [] permissions = null;

    mAsyncFacebookRunner = new AsyncFacebookRunner (mFacebook);

    permissions = new String [3];
    permissions [0] = PUBLISH_PERMISSION;
    permissions [1] = BIRTHDAY_PERMISSION;
    permissions [2] = EMAIL_PERMISSION;

    PERMISSIONS = permissions;
  }




  public static void initialize (Context context) { mContext = context; }

  public static void handleLoginResult (int resultCode, Intent intent) { mFacebook.authorizeCallback (mFacebookRequestCode, resultCode, intent); }

  public static boolean isConnected () { return ((mContext != null) && (SessionStore.restore (mFacebook, mContext))); }

  public static boolean isInstalled (Context context)
  {
    boolean result = false;

    try { context.getPackageManager ().getPackageInfo (PACKAGE_NAME, 0); result = true; }
    catch (PackageManager.NameNotFoundException exception) { }

    return result;
  }

  public static void like (String graphPath, RequestListener requestListener)
  {
    Bundle bundle = null;
    
    bundle = new Bundle ();
    mAsyncFacebookRunner.request (graphPath + GP_LIKES_URI, bundle, GP_POST_REQUEST, requestListener, null);
  }

  public static void login (Activity activity, int requestCode)
  {
    if (mContext != null)
    {
      mFacebookRequestCode = requestCode;
      mFacebook.authorize (activity, PERMISSIONS, -1, new LoginDialogListener ());
    }
  }

  public static void me (RequestListener requestListener)
  {
    Bundle bundle = null;
    
    bundle = new Bundle ();
    bundle.putString (GP_ACCESS_TOKEN, URLEncoder.encode (mFacebook.getAccessToken ()));

    mAsyncFacebookRunner.request (GP_ME_URI, bundle, GP_GET_REQUEST, requestListener, null);
  }

  public static void pagesLikes (String pageId, RequestListener requestListener)
  {
    Bundle bundle = null;
    
    bundle = new Bundle ();
    bundle.putString (GP_PAGE_ID,  pageId);
    bundle.putString (GP_METHOD,  GP_PAGES_ADD_FAN);

    mAsyncFacebookRunner.request (null, bundle, GP_POST_REQUEST, requestListener, null);
  }

  public static void publishCommentOnWall (String description, RequestListener requestListener)
  {
    Bundle bundle = null;
    
    bundle = new Bundle ();
    bundle.putString (GP_LINK,      RENAULT_SPORT_URL);
    bundle.putString (GP_NAME,      FACEBOOK_APP_NAME);
    bundle.putString (GP_PICTURE,    FACEBOOK_APP_LOGO_URL);
    bundle.putString (GP_DESCRIPTION,  description);

    mAsyncFacebookRunner.request (GP_ME_FEED_URI, bundle, GP_POST_REQUEST, requestListener, null);
  }

  public static void publishCommentOnWall (String description, RequestListener requestListener, Bitmap snapshot)
  {
    float          fWidth      = 0;
    float          fHeight      = 0;
    Bundle          bundle      = null;
    Bitmap          bitmap      = null;
    Paint          paint      = null;
    Canvas          canvas      = null;
    ByteArrayOutputStream  outputStream  = null;
    Bitmap.CompressFormat  compressFormat  = null;
    byte []          arrayOfByte    = null;


    bundle = new Bundle ();
    if (description.length () > 0)
    {
      description = mContext.getResources ().getString (R.string.performed_with) + description;

      bitmap = Bitmap.createBitmap (snapshot.getWidth (), 20 + snapshot.getHeight (), Bitmap.Config.ARGB_8888);
  
      paint = new Paint();
      paint.setTextSize  (16.0F);
      paint.setAntiAlias  (true);
  
      canvas = new Canvas (bitmap);
      canvas.drawBitmap (bitmap, 0.0F, 0.0F, paint);
  
      paint.setColor (0xffffffff);
      paint.setColor (0xff000000);
      canvas.drawRect (0.0F, -10 + snapshot.getHeight (), snapshot.getWidth (), 20 + snapshot.getHeight (), paint);
  
      fWidth  = 10 * snapshot.getWidth () / 100;
      fHeight  = 8 + snapshot.getHeight ();
  
      canvas.drawText (description, fWidth, fHeight, paint);
      snapshot = bitmap;
    }

    outputStream  = new ByteArrayOutputStream ();
    compressFormat  = Bitmap.CompressFormat.JPEG;
    snapshot.compress (compressFormat, 100, outputStream);
    arrayOfByte = outputStream.toByteArray ();

    bundle.putString  (GP_NAME,      FACEBOOK_APP_NAME);
    bundle.putString  (GP_DESCRIPTION,  description);
    bundle.putString  (GP_METHOD,      GP_PHOTOS_UPLOAD);
    bundle.putByteArray  (GP_PICTURE,    arrayOfByte);

    mAsyncFacebookRunner.request (null, bundle, GP_POST_REQUEST, requestListener, null);
  }

  public static void publishCommentOnWall (String description, RequestListener requestListener, String filePath, String name)
  {
    int        index    = 0;
    Bundle      bundle    = null;
    File      file    = null;
    FileInputStream  inputStream  = null;
    byte []      arrayOfByte  = null;


    bundle = new Bundle ();

    file = new File (filePath);
    try
    {
      inputStream = new FileInputStream (file);
      if (inputStream != null)
      {
        arrayOfByte = new byte [(int) file.length ()];

        index = 0;
        while (index < arrayOfByte.length)
        {
          try { index += inputStream.read (arrayOfByte, index, arrayOfByte.length - index); }
          catch (IOException exception) { }
        }

        bundle.putString  (GP_NAME,      name);
        bundle.putString  (GP_DESCRIPTION,  description);
        bundle.putString  (GP_CONTENT_TYPE,  GP_VIDEO_3GPP);
        bundle.putByteArray  ("video.3gp",    arrayOfByte);

        mAsyncFacebookRunner.request("me/videos", bundle, "POST", requestListener, null);
      }
    }
    catch (FileNotFoundException exception) { }
  }
}




Java Source Code List

com.facebook.android.AsyncFacebookRunner.java
com.facebook.android.BaseDialogListener.java
com.facebook.android.BaseRequestListener.java
com.facebook.android.DialogError.java
com.facebook.android.FQLQuery.java
com.facebook.android.FacebookError.java
com.facebook.android.FacebookFunctions.java
com.facebook.android.Facebook.java
com.facebook.android.FbDialog.java
com.facebook.android.FieldsConnectionsDialog.java
com.facebook.android.FriendsGetProfilePics.java
com.facebook.android.FriendsList.java
com.facebook.android.GraphExplorer.java
com.facebook.android.IntentUriHandler.java
com.facebook.android.LoginButton.java
com.facebook.android.PermissionsDialog.java
com.facebook.android.Places.java
com.facebook.android.SessionEvents.java
com.facebook.android.SessionStore.java
com.facebook.android.TokenRefreshDialog.java
com.facebook.android.UpdateStatusResultDialog.java
com.facebook.android.UploadPhotoResultDialog.java
com.facebook.android.Util.java
com.facebook.android.Utility.java
com.googlecode.android.widgets.DateSlider.AlternativeDateSlider.java
com.googlecode.android.widgets.DateSlider.CustomDateSlider.java
com.googlecode.android.widgets.DateSlider.DateSlider.java
com.googlecode.android.widgets.DateSlider.DateTimeSlider.java
com.googlecode.android.widgets.DateSlider.DefaultDateSlider.java
com.googlecode.android.widgets.DateSlider.MonthYearDateSlider.java
com.googlecode.android.widgets.DateSlider.ScrollLayout.java
com.googlecode.android.widgets.DateSlider.TimeSlider.java
com.googlecode.android.widgets.DateSlider.TimeView.java
com.renaultsport.heartrate.ActivityMain.java
com.renaultsport.heartrate.ActivityRecord.java
com.renaultsport.heartrate.ActivitySplash.java
com.renaultsport.heartrate.ActivityUpload.java
com.renaultsport.heartrate.ActivityVideoReader.java
com.renaultsport.heartrate.ActivityWarning.java
com.renaultsport.heartrate.MainApplication.java
com.renaultsport.heartrate.utils.CaptureCamera.java
com.renaultsport.heartrate.utils.ClientThread.java
com.renaultsport.heartrate.utils.Constants.java
com.renaultsport.heartrate.utils.RunEncoder.java
team.stride.tabs.TabGroupActivity.java