Example usage for android.support.v4.app FragmentManager findFragmentById

List of usage examples for android.support.v4.app FragmentManager findFragmentById

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager findFragmentById.

Prototype

public abstract Fragment findFragmentById(int id);

Source Link

Document

Finds a fragment that was identified by the given id either when inflated from XML or as the container ID when added in a transaction.

Usage

From source file:edu.mit.mobile.android.livingpostcards.CardEditActivity.java

@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);

    mSherlock.setContentView(R.layout.activity_card_edit);
    final ActionBar ab = mSherlock.getActionBar();
    ab.setDisplayHomeAsUpEnabled(true);/*from  w w w.  j a va 2  s  .  c  o  m*/

    mTitle = (EditText) findViewById(R.id.title);
    mDescription = (EditText) findViewById(R.id.description);

    final View addFrame = findViewById(R.id.add_frame);

    addFrame.setOnClickListener(this);

    mCard = getIntent().getData();
    final String action = getIntent().getAction();

    final FragmentManager fm = getSupportFragmentManager();

    if (Intent.ACTION_EDIT.equals(action) || Intent.ACTION_DELETE.equals(action)) {
        final FragmentTransaction ft = fm.beginTransaction();
        final Fragment f = fm.findFragmentById(R.id.card_edit_fragment);
        if (f != null) {
            mCardViewFragment = (CardMediaEditFragment) f;
        } else {
            mCardViewFragment = CardMediaEditFragment.newInstance(Card.MEDIA.getUri(mCard));
            ft.replace(R.id.card_edit_fragment, mCardViewFragment);
        }

        // if the dialog has been automatically restored by the system, hook it in.
        final SetCollabDescDialogFragment collab = (SetCollabDescDialogFragment) fm
                .findFragmentByTag(TAG_DIALOG_COLLABORATIVE);
        if (collab != null) {
            collab.setOnMarkCollaborativeListener(mOnMarkCollabListener);
        }

        mUserUri = Authenticator.getUserUri(this, Authenticator.ACCOUNT_TYPE);

        getSupportLoaderManager().initLoader(0, null, this);

        // if this isn't null, it was saved automatically for us. So hook it back in.
        final DeleteDialogFragment deleteDialog = (DeleteDialogFragment) fm
                .findFragmentByTag(TAG_DELETE_DIALOG);
        if (deleteDialog != null) {
            deleteDialog.registerOnDeleteListener(this);

        } else if (Intent.ACTION_DELETE.equals(action)) {
            onDeletePostcard();
        }

        ft.commit();
    }
}

From source file:net.vivekiyer.GAL.CorporateAddressBook.java

@TargetApi(11)
private void displaySearchResult(HashMultimap<String, Contact> contacts, String searchTerm) {

    this.mContacts = contacts;
    this.latestSearchTerm = searchTerm;

    final FragmentManager fragmentManager = getSupportFragmentManager();

    CorporateAddressBookFragment list = (CorporateAddressBookFragment) fragmentManager
            .findFragmentById(R.id.main_fragment);
    if (list == null) {
        Debug.Log("List fragment missing from main activity, discarding search result"); //$NON-NLS-1$
        return;//w w  w . ja  v  a 2 s.c  o  m
    }
    list.displayResult(mContacts, latestSearchTerm);

    resetAndHideDetails(fragmentManager);
    if (!Utility.isPreHoneycomb() && (searchView != null))
        searchView.setQuery("", false); //$NON-NLS-1$
    list.getView().requestFocus();
}

From source file:com.esri.android.ecologicalmarineunitexplorer.MainActivity.java

/**
 * Attach display logic to bottom sheet behavior.
 *//* w w  w. j  a v  a2  s  . co m*/
private void setUpBottomSheetFragment() {
    final FragmentManager fm = getSupportFragmentManager();
    BottomSheetFragment mBottomSheetFragment = (BottomSheetFragment) fm
            .findFragmentById(R.id.bottom_sheet_view);

    if (mBottomSheetFragment == null) {
        mBottomSheetFragment = BottomSheetFragment.newInstance();
        ActivityUtils.addFragmentToActivity(fm, mBottomSheetFragment, R.id.bottom_sheet_view,
                getString(R.string.fragment_summary));
        mBottomSheetPresenter = new BottomSheetPresenter(mBottomSheetFragment);
    }

    mBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet_view));
    if (mBottomSheetBehavior != null) {
        mBottomSheetBehavior.setHideable(true);
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

        mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull final View bottomSheet, final int newState) {
                invalidateOptionsMenu();

                if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
                    showBottomSheetContent();
                    mFab.setVisibility(View.VISIBLE);
                    final LinearLayout layout = (LinearLayout) findViewById(R.id.horizontalLinearLayout);
                    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    layoutParams.setMargins(0, 0, 0, 0);
                    layout.setLayoutParams(layoutParams);
                    layout.requestLayout();

                }
                if (newState == BottomSheetBehavior.STATE_EXPANDED) {

                    final LinearLayout layout = (LinearLayout) findViewById(R.id.horizontalLinearLayout);
                    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    final int toolbarSize = findViewById(R.id.toolbar).getHeight();
                    layoutParams.setMargins(0, toolbarSize, 0, 0);
                    layout.setLayoutParams(layoutParams);
                    layout.requestLayout();
                }
                if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                    final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.chartContainer);
                    if (fragment == null) {
                        mFab.setVisibility(View.VISIBLE);
                    } else {
                        mFab.setVisibility(View.INVISIBLE);
                    }
                }
            }

            @Override
            public void onSlide(@NonNull final View bottomSheet, final float slideOffset) {

                final float scaleFactor = 1 - slideOffset;
                if (mFab != null) {
                    if (scaleFactor <= 1) {
                        mFab.setVisibility(View.VISIBLE);
                        mFab.animate().scaleX(1 - slideOffset).scaleY(1 - slideOffset).setDuration(0).start();
                    }
                    if (slideOffset == 1.00f) {
                        mFab.setVisibility(View.INVISIBLE);
                    }
                }
            }
        });
    }
}

From source file:com.example.david.wheretogo_test1.PickerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pickers);//from  ww w .j a  va2 s  . c  om

    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);
            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(args);
        } else {
            placePickerFragment = (PlacePickerFragment) manager.findFragmentById(R.id.picker_fragment);
        }
        placePickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {
            @Override
            public void onSelectionChanged(PickerFragment<?> fragment) {
                finishActivity(); // call finish since you can only pick one place
            }
        });
        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();
}

From source file:it.gulch.linuxday.android.activities.TrackScheduleActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.track_schedule);

    Bundle extras = getIntent().getExtras();
    day = (Day) extras.getSerializable(EXTRA_DAY);
    track = (Track) extras.getSerializable(EXTRA_TRACK);

    ActionBar bar = getSupportActionBar();
    bar.setDisplayHomeAsUpEnabled(true);
    bar.setTitle(track.toString());//from   w w w  .java  2  s . c  om
    bar.setSubtitle(day.toString());

    isTabletLandscape = getResources().getBoolean(R.bool.tablet_landscape);

    TrackScheduleListFragment trackScheduleListFragment;
    FragmentManager fm = getSupportFragmentManager();
    if (savedInstanceState == null) {
        long fromEventId = extras.getLong(EXTRA_FROM_EVENT_ID, -1L);
        if (fromEventId != -1L) {
            trackScheduleListFragment = TrackScheduleListFragment.newInstance(day, track, fromEventId);
        } else {
            trackScheduleListFragment = TrackScheduleListFragment.newInstance(day, track);
        }

        fm.beginTransaction().add(R.id.schedule, trackScheduleListFragment).commit();
    } else {
        trackScheduleListFragment = (TrackScheduleListFragment) fm.findFragmentById(R.id.schedule);

        // Remove the room image DialogFragment when switching from dual pane to single pane mode
        if (!isTabletLandscape) {
            Fragment roomImageDialogFragment = fm.findFragmentByTag(RoomImageDialogFragment.TAG);
            if (roomImageDialogFragment != null) {
                fm.beginTransaction().remove(roomImageDialogFragment).commit();
            }
        }
    }
    trackScheduleListFragment.setSelectionEnabled(isTabletLandscape);

    if (isTabletLandscape) {
        // Enable Android Beam
        NfcUtils.setAppDataPushMessageCallbackIfAvailable(this, this);
    }
}

From source file:com.esri.android.ecologicalmarineunitexplorer.MainActivity.java

/**
 * Show the view with the water column profiles
 * @param point - Point representing clicked geo location
 *///from www.j a  v a 2s  .c o m
private void showWaterColumnProfile(final Point point) {
    // Remove water column, summary, text and button
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    // hideMapView();

    setUpWaterProfileToolbar();

    final FrameLayout layout = (FrameLayout) findViewById(R.id.chartContainer);
    if (layout != null) {
        layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        layout.requestLayout();
    }

    final WaterProfileFragment waterProfileFragment = WaterProfileFragment.newInstance();
    new WaterProfilePresenter(point, waterProfileFragment, mDataManager);

    // Add the chart view to the column container
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    final Fragment f = fm.findFragmentById(R.id.chartContainer);
    if (f == null) {
        transaction.addToBackStack(getString(R.string.fragment_detail_chart));
    }
    transaction.replace(R.id.chartContainer, waterProfileFragment);
    transaction.commit();

    // Hide the FAB
    mFab.setVisibility(View.INVISIBLE);

    mInMapState = false;
}

From source file:com.esri.android.ecologicalmarineunitexplorer.MainActivity.java

/**
 * Show the candlestick charts for a specific EMU layer
 * @param emuName - int representing an EMU layer name
 *///from   ww  w. j a va 2 s  .com
private void showSummaryDetail(final int emuName) {
    // Hide the bottom sheet containing the summary view
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

    // Expand the layout for the charts
    final FrameLayout layout = (FrameLayout) findViewById(R.id.chartContainer);
    if (layout != null) {
        layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        layout.requestLayout();
    }

    if (mSummaryChartFragment == null) {
        mSummaryChartFragment = SummaryChartFragment.newInstance();
        mSummaryChartPresenter = new SummaryChartPresenter(emuName, mSummaryChartFragment, mDataManager);
    } else {
        mSummaryChartPresenter.setEmuName(emuName);
    }

    // Add the chart view to the column container
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    final Fragment f = fm.findFragmentById(R.id.chartContainer);
    if (f == null) {
        transaction.addToBackStack(getString(R.string.fragment_detail_chart));
    }
    transaction.replace(R.id.chartContainer, mSummaryChartFragment);
    transaction.commit();

    // Hide the FAB
    mFab.setVisibility(View.INVISIBLE);
    mInMapState = false;

    setUpChartSummaryToolbar(emuName);
}

From source file:net.vivekiyer.GAL.CorporateAddressBook.java

@Override
public void onContactSelected(Contact contact) {
    // Create a parcel with the associated contact object
    // This parcel is used to send data to the activity

    this.selectedContact = contact;

    final FragmentManager fragmentManager = getSupportFragmentManager();

    CorporateContactRecordFragment details = (CorporateContactRecordFragment) fragmentManager
            .findFragmentById(R.id.contact_fragment);

    if (details == null || !details.isInLayout()) {
        final Bundle b = new Bundle();
        b.putParcelable("net.vivekiyer.GAL", selectedContact); //$NON-NLS-1$

        // Launch the activity
        final Intent myIntent = new Intent();
        myIntent.setClassName("net.vivekiyer.GAL", //$NON-NLS-1$
                "net.vivekiyer.GAL.CorporateContactRecord"); //$NON-NLS-1$

        myIntent.putExtras(b);/*from   ww w  .  ja  va  2  s  . c o m*/
        startActivity(myIntent);
    } else {
        CorporateAddressBookFragment list = (CorporateAddressBookFragment) fragmentManager
                .findFragmentById(R.id.main_fragment);
        list.setViewBackground(true);

        details.setContact(selectedContact);

        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        //ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        // Below does not work since it resizes the result fragment before anim starts,
        // making it look rather weird. Better off w/o anims, unfortunately.
        //ft.setCustomAnimations(R.anim.slide_in, R.anim.slide_out);
        ft.show(details);
        ft.commit();
    }
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.tablet.SessionsSandboxMultiPaneActivity.java

private void showFullUI(boolean fullUI) {
    mFullUI = fullUI;//from   ww  w.  j  av  a 2 s  .c  o m
    final ActionBar actionBar = getSupportActionBar();
    final FragmentManager fm = getSupportFragmentManager();

    if (fullUI) {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setListNavigationCallbacks(mActionBarSpinnerAdapter, this);
        fm.beginTransaction().show(fm.findFragmentById(R.id.fragment_tracks_dropdown)).commit();
    } else {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        actionBar.setDisplayShowTitleEnabled(true);

        fm.beginTransaction().hide(fm.findFragmentById(R.id.fragment_tracks_dropdown)).commit();
    }
}

From source file:com.nicolatesser.geofencedemo.LocationActivity.java

private void init() {
    // Initialize map
    if (mMap == null) {
        FragmentManager myFragmentManager = getSupportFragmentManager();
        SupportMapFragment myMapFragment = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.map);
        mMap = myMapFragment.getMap();// w w w  .  j  a v a 2  s  .  co  m
    }

    // Initialize Location Client
    mLocationStatus = (TextView) findViewById(R.id.location_status);

    if (mLocationClient == null) {
        mLocationClient = new LocationClient(this, mLocationCallback, mLocationCallback);
        Log.v(LocationActivity.TAG, "Location Client connect");
        if (!(mLocationClient.isConnected() || mLocationClient.isConnecting())) {
            mLocationClient.connect();
        }
    }

    // Initialize Action Recognition
    if (mActivityRecognitionClient == null) {
        mActivityRecognitionClient = new ActivityRecognitionClient(this, mActivityRecognitionCallback,
                mActivityRecognitionCallback);
    }
    mSwitch = (Switch) findViewById(R.id.swtich);
    stopActivityDetection(mSwitch);
    mSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                startActivityDetection(buttonView);
            } else {
                stopActivityDetection(buttonView);
            }
        }
    });
    if (mActivityRecognitionIntentReceiver == null) {
        mActivityRecognitionIntentReceiver = new ActivityRecognitionIntentReceiver();
        registerReceiver(mActivityRecognitionIntentReceiver,
                new IntentFilter(LocationActivity.ACTION_ACTIVITY_RECOGNITION));
    }

    // Initialize Geo Fencing
    mGeoFenceStatus = (TextView) findViewById(R.id.geo_fence_status);

    if (mGeoFences == null) {
        mGeoFences = new HashMap<String, Circle>();

        // add Seitenbau Gmbh;
        addGeoFence("SEITENBAU", new LatLng(47.670417, 9.155700));
        //addGeoFence("HOME", new LatLng(47.672872, 9.170997));
        addGeoFence("WASSERTURM", new LatLng(47.67029, 9.154609));

    }

    if (mTriggeringFences == null) {
        mTriggeringFences = new HashMap<String, Circle>();
    }

    // Setup map to allow adding Geo Fences
    mMap.getUiSettings().setAllGesturesEnabled(true);
    mMap.setOnMapLongClickListener(mGeoFenceCallback);

}