Android Open Source - Fruity-Bang Selection Fragment






From Project

Back to project page Fruity-Bang.

License

The source code is released under:

MIT License

If you think the Android project Fruity-Bang 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 vn.edu.rmit.fruitybang;
//  w w w .j a  v  a  2 s . co  m
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.facebook.FacebookException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.Session;
import com.facebook.widget.WebDialog;
import com.facebook.widget.WebDialog.OnCompleteListener;

public class SelectionFragment extends Fragment {
  private Button publishButton;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.selection, container, false);

    publishButton = (Button) view.findViewById(R.id.publishButton);
    publishButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if (getActivity() instanceof MainActivity) {
          MainActivity main = (MainActivity) getActivity();
          publishFeedDialog(main.getScore());
        } else {
          publishFeedDialog(1);
        }
      }
    });
    return view;
  }

  private void publishFeedDialog(long score) {
    Bundle params = new Bundle();
    params.putString("picture", "https://raw.github.com/damhonglinh/fruitybang/master/ic_launcher.png");
    params.putString("name", getString(R.string.title));
    params.putString("caption", getString(R.string.caption));
    params.putString("description", getString(R.string.description) + " - "
        + score + getString(R.string.description1));
    params.putString("link", getString(R.string.websiteUrl));

    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(),
                    getString(R.string.shareSuccessfully),
                    Toast.LENGTH_SHORT).show();
              } else {
                // User clicked the Cancel button
                Toast.makeText(getActivity(),
                    getString(R.string.shareCancelled),
                    Toast.LENGTH_SHORT).show();
              }
            } else if (error instanceof FacebookOperationCanceledException) {
              // User clicked the "x" button
              Toast.makeText(
                  getActivity().getApplicationContext(),
                  getString(R.string.shareCancelled),
                  Toast.LENGTH_SHORT).show();
            } else {
              // Generic, ex: network error
              Toast.makeText(
                  getActivity().getApplicationContext(),
                  getString(R.string.shareFail),
                  Toast.LENGTH_SHORT).show();
            }
          }
        }).build();
    feedDialog.show();
  }
}




Java Source Code List

GameController.BushGhost.java
GameController.CharGhost.java
GameController.SaGhost.java
GameController.WormGhost.java
Game.GameConstant.java
Game.Game.java
Game.Home.java
Game.MapGenerator.java
GameModel.Bush.java
GameModel.Coin.java
GameModel.CuteModel.java
GameModel.Explosion.java
GameModel.Fruit.java
GameModel.Rock.java
GameModel.Ruby.java
GameModel.Sa.java
GameModel.Win.java
GameModel.Worm.java
Game.Scene.java
Game.Store.java
Model.Account.java
vn.edu.rmit.fruitybang.GameActivity.java
vn.edu.rmit.fruitybang.LoadingAsyncTask.java
vn.edu.rmit.fruitybang.MainActivity.java
vn.edu.rmit.fruitybang.SelectionFragment.java
vn.edu.rmit.fruitybang.SplashFragment.java