Android Open Source - QBShare-Android Async Linked In Runner






From Project

Back to project page QBShare-Android.

License

The source code is released under:

Copyright (c) 2011 QBurst, http://qburst.com/ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redi...

If you think the Android project QBShare-Android 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

/*
 * Copyright 2010 Facebook, Inc.//from  w w  w. j  a va2s. c  om
 *
 * 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 com.qburst.android.linkedin;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;

import android.content.Context;

/**
 * A sample implementation of asynchronous API requests.  This class provides
 * the ability to execute API methods and have the call return immediately, 
 * without blocking the calling thread.  This is necessary when accessing the 
 * API in the UI thread, for instance.  The request response is returned to 
 * the caller via a callback interface, which the developer must implement.
 * 
 * This sample implementation simply spawns a new thread for each request,
 * and makes the API call immediately.  This may work in many applications,
 * but more sophisticated users may re-implement this behavior using a thread
 * pool, a network thread, a request queue, or other mechanism.  Advanced
 * functionality could be built, such as rate-limiting of requests, as per
 * a specific application's needs.
 * 
 * @see RequestListener
 *        The callback interface.
 * 
 * @author ssoneff@facebook.com
 *
 */
public class AsyncLinkedInRunner {

  LinkedIn tw;

  public AsyncLinkedInRunner(LinkedIn tw) {
    this.tw = tw;
  }

  /**
   * Invalidate the current user session by removing the access token in
   * memory, clearing the browser cookies, and calling auth.expireSession
   * through the API. The application will be notified when logout is
   * complete via the callback interface.  
   * 
   * Note that this method is asynchronous and the callback will be invoked 
   * in a background thread; operations that affect the UI will need to be 
   * posted to the UI thread or an appropriate handler.
   * 
   * @param context
   *            The Android context in which the logout should be called: it
   *            should be the same context in which the login occurred in
   *            order to clear any stored cookies
   * @param listener
   *            Callback interface to notify the application when the request
   *            has completed.
   */
  public void logout(final Context context, final RequestListener listener) {
    new Thread() {
      @Override public void run() {
        try {
          String response = tw.logout(context);
          if (response.length() == 0 || response.equals("false")){
            listener.onTwitterError(new LinkedInError(
            "auth.expireSession failed"));
            return;
          }
          listener.onComplete(response);
        } catch (FileNotFoundException e) {
          listener.onFileNotFoundException(e);
        } catch (MalformedURLException e) {
          listener.onMalformedURLException(e);
        } catch (IOException e) {
          listener.onIOException(e);
        }
      }
    }.start();
  }

  public static interface RequestListener {
    public void onComplete(String response);
    public void onIOException(IOException e);
    public void onFileNotFoundException(FileNotFoundException e);
    public void onMalformedURLException(MalformedURLException e);
    public void onTwitterError(LinkedInError e);

  }

}




Java Source Code List

com.qburst.android.facebook.AsyncFacebookRunner.java
com.qburst.android.facebook.BaseDialogListener.java
com.qburst.android.facebook.BaseRequestListener.java
com.qburst.android.facebook.DialogError.java
com.qburst.android.facebook.FacebookError.java
com.qburst.android.facebook.Facebook.java
com.qburst.android.facebook.FbDialog.java
com.qburst.android.facebook.SessionEvents.java
com.qburst.android.facebook.SessionStore.java
com.qburst.android.facebook.Util.java
com.qburst.android.interfaces.share.QBShareListener.java
com.qburst.android.interfaces.share.QBShareManager.java
com.qburst.android.interfaces.share.QBShare.java
com.qburst.android.linkedin.AsyncLinkedInRunner.java
com.qburst.android.linkedin.DialogError.java
com.qburst.android.linkedin.LinkedInConstants.java
com.qburst.android.linkedin.LinkedInError.java
com.qburst.android.linkedin.LinkedIn.java
com.qburst.android.linkedin.LnDialog.java
com.qburst.android.linkedin.Util.java
com.qburst.android.twitter.AsyncTwitterRunner.java
com.qburst.android.twitter.DialogError.java
com.qburst.android.twitter.TwDialog.java
com.qburst.android.twitter.TwitterConstants.java
com.qburst.android.twitter.TwitterError.java
com.qburst.android.twitter.Twitter.java
com.qburst.android.twitter.Util.java
com.qburst.config.QBShareConstants.java
com.qburst.share.activities.QBShareActivity.java
com.qburst.share.activities.QBShareFacebook.java
com.qburst.share.activities.QBShareTwitter.java
com.qburst.share.activities.QMShareLinkedIn.java
com.qmcommerce.android.utils.QBImageLoaderListener.java
com.qmcommerce.android.utils.QBImageLoader.java