Android Open Source - videoMerge Facebook Event Observer






From Project

Back to project page videoMerge.

License

The source code is released under:

Apache License

If you think the Android project videoMerge 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.dragonplayer.merge;
/*www  .  j  a  v a 2 s .co m*/
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

import android.app.Activity;
import android.widget.Toast;

import com.nostra13.socialsharing.common.AuthListener;
import com.nostra13.socialsharing.common.LogoutListener;
import com.nostra13.socialsharing.common.PostListener;
import com.nostra13.socialsharing.facebook.FacebookEvents;
import com.dragonplayer.merge.R;

/**
 * Observes Facebook events (authentication, publishing, logging out) and shows appropriate {@link Toast toasts}. Use
 * {@link #registerListeners()} to start observe events and {@link #unregisterListeners()} to stop observing.<br />
 * <b>Good practice:</b> Call {@link #registerListeners()} at {@link Activity#onStart()} method and necessarily call
 * {@link #unregisterListeners()} at {@link Activity#onStop()} method
 * 
 * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
 */
public class FacebookEventObserver {

  private Reference<Activity> context;

  private FacebookEventObserver() {
    context = new WeakReference<Activity>(null);
  }

  public static FacebookEventObserver newInstance() {
    return new FacebookEventObserver();
  }

  private AuthListener authListener = new AuthListener() {
    @Override
    public void onAuthSucceed() {
//      showToastOnUIThread(R.string.toast_facebook_auth_success);
    }

    @Override
    public void onAuthFail(String error) {
//      showToastOnUIThread(R.string.toast_facebook_auth_fail);
    }
  };

  private PostListener postListener = new PostListener() {
    @Override
    public void onPostPublishingFailed() {
//      showToastOnUIThread(R.string.facebook_post_publishing_failed);
    }

    @Override
    public void onPostPublished() {
//      showToastOnUIThread(R.string.facebook_post_published);
    }
  };

  private LogoutListener logoutListener = new LogoutListener() {
    @Override
    public void onLogoutComplete() {
//      showToastOnUIThread(R.string.facebook_logged_out);
    }
  };

  private void showToastOnUIThread(final int textRes) {
    final Activity curActivity = context.get();
    if (curActivity != null) {
      curActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
//          Toast.makeText(curActivity, textRes, Toast.LENGTH_SHORT).show();
        }
      });
    }
  }

  /** Should be call at {@link Activity#onStart()} */
  public void registerListeners(Activity context) {
    this.context = new WeakReference<Activity>(context);

    FacebookEvents.addAuthListener(authListener);
    FacebookEvents.addPostListener(postListener);
    FacebookEvents.addLogoutListener(logoutListener);
  }

  /** Should be call at {@link Activity#onStop()} */
  public void unregisterListeners() {
    context.clear();

    FacebookEvents.removeAuthListener(authListener);
    FacebookEvents.removePostListener(postListener);
    FacebookEvents.removeLogoutListener(logoutListener);
  }
}




Java Source Code List

com.dragonplayer.merge.FBLikeActivity.java
com.dragonplayer.merge.FacebookActivity.java
com.dragonplayer.merge.FacebookEventObserver.java
com.dragonplayer.merge.LoadingDialog.java
com.dragonplayer.merge.MainActivity.java
com.dragonplayer.merge.SplashActivity.java
com.dragonplayer.merge.TextInputActivity.java
com.dragonplayer.merge.adapter.FrameListAdapter.java
com.dragonplayer.merge.adapter.FrameSubListAdapter.java
com.dragonplayer.merge.adapter.MediaListAdapter.java
com.dragonplayer.merge.adapter.ProjectListAdapter.java
com.dragonplayer.merge.adapter.ProjectSubListAdapter.java
com.dragonplayer.merge.fragment.AboutFragment.java
com.dragonplayer.merge.fragment.AddAudioFragment.java
com.dragonplayer.merge.fragment.BaseFragment.java
com.dragonplayer.merge.fragment.FinishFragment.java
com.dragonplayer.merge.fragment.FrameFragment.java
com.dragonplayer.merge.fragment.FrameListFragment.java
com.dragonplayer.merge.fragment.GiftFragment.java
com.dragonplayer.merge.fragment.GridFragment.java
com.dragonplayer.merge.fragment.HomeFragment.java
com.dragonplayer.merge.fragment.LockConfirmFragment.java
com.dragonplayer.merge.fragment.LockFragment.java
com.dragonplayer.merge.fragment.UploadConfirmFragment.java
com.dragonplayer.merge.fragment.UploadFragment.java
com.dragonplayer.merge.fragment.UploadInfoFragment.java
com.dragonplayer.merge.fragment.UploadSelectMediaFragment.java
com.dragonplayer.merge.fragment.WorkFragment.java
com.dragonplayer.merge.frames.FrameInfo.java
com.dragonplayer.merge.frames.FramePart.java
com.dragonplayer.merge.frames.FrameView.java
com.dragonplayer.merge.frames.Frame.java
com.dragonplayer.merge.frames.FramesLayout.java
com.dragonplayer.merge.frames.Frames.java
com.dragonplayer.merge.frames.HorizontalListView.java
com.dragonplayer.merge.frames.ProjectFiles.java
com.dragonplayer.merge.frames.timeout.java
com.dragonplayer.merge.utils.AppConnectivity.java
com.dragonplayer.merge.utils.BannerData.java
com.dragonplayer.merge.utils.BitmapManager.java
com.dragonplayer.merge.utils.BitmapUtil.java
com.dragonplayer.merge.utils.Constants.java
com.dragonplayer.merge.utils.DlgWindow1.java
com.dragonplayer.merge.utils.DlgWindow2.java
com.dragonplayer.merge.utils.DlgWindow4.java
com.dragonplayer.merge.utils.DlgWindow5.java
com.dragonplayer.merge.utils.DlgWindow6.java
com.dragonplayer.merge.utils.DlgWindow7.java
com.dragonplayer.merge.utils.DlgWindow8.java
com.dragonplayer.merge.utils.FileMover.java
com.dragonplayer.merge.utils.Flag.java
com.dragonplayer.merge.utils.MLog.java
com.dragonplayer.merge.utils.SingleMediaScanner.java
com.dragonplayer.merge.utils.Utils.java
com.dragonplayer.merge.utils.WeTouch_network_interface.java
com.dragonplayer.merge.utils.WeTouch_uploadImage.java
com.dragonplayer.merge.utils.WebService.java