Android Open Source - Kodesearch Main Fragment






From Project

Back to project page Kodesearch.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project Kodesearch 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.kodesearch.external;
/*w w w  . jav  a  2  s  .com*/
import com.facebook.FacebookException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.widget.WebDialog;
import com.facebook.widget.WebDialog.OnCompleteListener;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.widget.Toast;

public class MainFragment extends Fragment {
  private static final String TAG = "MainFragment";
  private UiLifecycleHelper uiHelper;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);
  }

  @Override
  public void onResume() {
    super.onResume();
    uiHelper.onResume();
  }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
  }

  @Override
  public void onPause() {
    super.onPause();
    uiHelper.onPause();
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
  }

  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
  }
  

  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(getActivity(),
        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(getActivity(),
                    "Posted story, id: " + postId,
                    Toast.LENGTH_SHORT).show();
              } else {
                // User clicked the Cancel button
                Toast.makeText(
                    getActivity().getApplicationContext(),
                    "Publish cancelled", Toast.LENGTH_SHORT)
                    .show();
              }
            } else if (error instanceof FacebookOperationCanceledException) {
              // User clicked the "x" button
              Toast.makeText(
                  getActivity().getApplicationContext(),
                  "Publish cancelled", Toast.LENGTH_SHORT)
                  .show();
            } else {
              // Generic, ex: network error
              Toast.makeText(
                  getActivity().getApplicationContext(),
                  "Error posting story", Toast.LENGTH_SHORT)
                  .show();
            }
          }

          public void onComplete1(Bundle values,
              FacebookException error) {
            // TODO Auto-generated method stub
            
          }

        }).build();
    feedDialog.show();
  }

  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 Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state,
        Exception exception) {
      onSessionStateChange(session, state, exception);
    }
  };
}




Java Source Code List

com.kodesearch.ListResults.java
com.kodesearch.MainActivity.java
com.kodesearch.NewsFragment.java
com.kodesearch.SearchFragment.java
com.kodesearch.ServiceHandler.java
com.kodesearch.ViewResult.java
com.kodesearch.external.AlertDialogManager.java
com.kodesearch.external.CleanHtml.java
com.kodesearch.external.ConnectionDetector.java
com.kodesearch.external.FragmentNavigationDrawer.java
com.kodesearch.external.MainFragment.java
com.kodesearch.external.NavDrawerItem.java
com.kodesearch.external.NavDrawerListAdapter.java
com.kodesearch.external.RobotoButton.java
com.kodesearch.external.RobotoTextView.java
com.kodesearch.external.RobotoTypefaceManager.java
com.kodesearch.external.ShareWithTwitter.java