Search in sources :

Example 1 with PickerFragment

use of com.example.scrumptious.picker.PickerFragment in project facebook-android-sdk by facebook.

the class PickerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pickers);
    Bundle args = getIntent().getExtras();
    FragmentManager manager = getFragmentManager();
    Fragment fragmentToShow = null;
    Uri intentUri = getIntent().getData();
    if (FRIEND_PICKER.equals(intentUri)) {
        if (savedInstanceState == null) {
            friendPickerFragment = new FriendPickerFragment();
            friendPickerFragment.setSettingsFromBundle(args);
            friendPickerFragment.setFriendPickerType(FriendPickerFragment.FriendPickerType.TAGGABLE_FRIENDS);
        } else {
            friendPickerFragment = (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);
            ;
        }
        friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {

            @Override
            public void onError(PickerFragment fragment, FacebookException error) {
                PickerActivity.this.onError(error);
            }
        });
        friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {

            @Override
            public void onDoneButtonClicked(PickerFragment fragment) {
                finishActivity();
            }
        });
        fragmentToShow = friendPickerFragment;
    } else if (PLACE_PICKER.equals(intentUri)) {
        if (savedInstanceState == null) {
            placePickerFragment = new PlacePickerFragment();
            placePickerFragment.setSettingsFromBundle(args);
        } else {
            placePickerFragment = (PlacePickerFragment) manager.findFragmentById(R.id.picker_fragment);
        }
        placePickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {

            @Override
            public void onSelectionChanged(PickerFragment fragment) {
                // call finish since you can only pick one place
                finishActivity();
            }
        });
        placePickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {

            @Override
            public void onError(PickerFragment fragment, FacebookException error) {
                PickerActivity.this.onError(error);
            }
        });
        placePickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {

            @Override
            public void onDoneButtonClicked(PickerFragment fragment) {
                finishActivity();
            }
        });
        fragmentToShow = placePickerFragment;
    } else {
        // Nothing to do, finish
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit();
}
Also used : PlacePickerFragment(com.example.scrumptious.picker.PlacePickerFragment) Bundle(android.os.Bundle) Fragment(android.app.Fragment) PlacePickerFragment(com.example.scrumptious.picker.PlacePickerFragment) PickerFragment(com.example.scrumptious.picker.PickerFragment) FriendPickerFragment(com.example.scrumptious.picker.FriendPickerFragment) Uri(android.net.Uri) FragmentManager(android.app.FragmentManager) FacebookException(com.facebook.FacebookException) PlacePickerFragment(com.example.scrumptious.picker.PlacePickerFragment) PickerFragment(com.example.scrumptious.picker.PickerFragment) FriendPickerFragment(com.example.scrumptious.picker.FriendPickerFragment) FriendPickerFragment(com.example.scrumptious.picker.FriendPickerFragment)

Aggregations

Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 FriendPickerFragment (com.example.scrumptious.picker.FriendPickerFragment)1 PickerFragment (com.example.scrumptious.picker.PickerFragment)1 PlacePickerFragment (com.example.scrumptious.picker.PlacePickerFragment)1 FacebookException (com.facebook.FacebookException)1