Ejemplo n.º 1
0
 private void setFriendPickerListeners(final FriendPickerFragment fragment) {
   fragment.setOnDoneButtonClickedListener(
       new FriendPickerFragment.OnDoneButtonClickedListener() {
         public void onDoneButtonClicked(PickerFragment<?> pickerFragment) {
           onFriendPickerDone(fragment);
         }
       });
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pickers);

    Bundle args = getIntent().getExtras();
    FragmentManager manager = getSupportFragmentManager();
    Fragment fragmentToShow = null;
    Uri intentUri = getIntent().getData();

    if (FRIEND_PICKER.equals(intentUri)) {
      if (savedInstanceState == null) {
        friendPickerFragment = new FriendPickerFragment(args);
      } else {
        friendPickerFragment =
            (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);
        ;
      }

      friendPickerFragment.setOnErrorListener(
          new PickerFragment.OnErrorListener() {
            @Override
            public void onError(FacebookException error) {
              PickerActivity.this.onError(error);
            }
          });
      friendPickerFragment.setOnDoneButtonClickedListener(
          new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked() {
              finishActivity();
            }
          });
      fragmentToShow = friendPickerFragment;

    } else if (PLACE_PICKER.equals(intentUri)) {
      if (savedInstanceState == null) {
        placePickerFragment = new PlacePickerFragment(args);
      } else {
        placePickerFragment = (PlacePickerFragment) manager.findFragmentById(R.id.picker_fragment);
      }
      placePickerFragment.setOnSelectionChangedListener(
          new PickerFragment.OnSelectionChangedListener() {
            @Override
            public void onSelectionChanged() {
              finishActivity(); // call finish since you can only pick one place
            }
          });
      placePickerFragment.setOnErrorListener(
          new PickerFragment.OnErrorListener() {
            @Override
            public void onError(FacebookException error) {
              PickerActivity.this.onError(error);
            }
          });
      placePickerFragment.setOnDoneButtonClickedListener(
          new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked() {
              finishActivity();
            }
          });
      fragmentToShow = placePickerFragment;
    } else {
      // Nothing to do, finish
      setResult(RESULT_CANCELED);
      finish();
      return;
    }

    manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit();
  }