Example usage for android.app FragmentManager findFragmentByTag

List of usage examples for android.app FragmentManager findFragmentByTag

Introduction

In this page you can find the example usage for android.app FragmentManager findFragmentByTag.

Prototype

public abstract Fragment findFragmentByTag(String tag);

Source Link

Document

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

Usage

From source file:systems.byteswap.publicstream.MainActivity.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    FragmentManager fm = getFragmentManager();
    dataFragment = (MainFragment) fm.findFragmentByTag("data");
    if (dataFragment == null) {
        createWithoutFragment();//from  w  w  w.j  a v a  2  s.c o m
    } else {
        restoreFromFragment();
    }
}

From source file:systems.byteswap.publicstream.MainActivity.java

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

    setContentView(R.layout.activity_main);

    store = new StorageProvider(this);

    // find the retained fragment on activity restarts
    FragmentManager fm = getFragmentManager();
    dataFragment = (MainFragment) fm.findFragmentByTag("data");
    // create the fragment and data the first time
    // or load existing data...
    if (dataFragment == null) {
        //create everything necessary new
        createWithoutFragment();/*  ww w  . j a v  a2 s .co  m*/
        //commit our fragment (containing data) to the FragmentManager
        fm.beginTransaction().add(dataFragment, "data").commit();
    } else {
        //Existing fragment -> restore everything from there
        restoreFromFragment();
    }

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    IntentFilter filter = new IntentFilter();
    filter.setPriority(Integer.MAX_VALUE);
    filter.addAction(MediaService.ACTION_PLAY_PAUSE);
    registerReceiver(mReceiver, filter);
    registerV21();

    /**
    Set up the ViewPager with the sections adapter.
    The {@link ViewPager} that will host the section contents.
    */
    ViewPager mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setPageTransformer(true, new CubeOutTransformer());

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    addGUIListener();
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

/**
 * Retrieve the {@link DetailViewFragment} that is associated with this
 * activity./*from  ww w  .j a  va 2  s. co m*/
 * 
 * @return the fragment, or null if it is not present
 */
DetailViewFragment findDetailViewFragment() {
    FragmentManager fragmentManager = this.getFragmentManager();
    DetailViewFragment result = (DetailViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.DETAIL_FRAGMENT);
    return result;
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

/**
 * Find a {@link MapListViewFragment} that is associated with this activity.
 * If not present, returns null./*from w  w w  . java 2  s.  c  o m*/
 * 
 * @return
 */
MapListViewFragment findMapListViewFragment() {
    FragmentManager fragmentManager = this.getFragmentManager();
    MapListViewFragment result = (MapListViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.MAP_LIST);
    return result;
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

/**
 * Hide every fragment except that specified by fragmentToKeepVisible.
 * /*w  w w  . ja  v a2  s.c  o m*/
 * @param fragmentToKeepVisible
 * @param fragmentTransaction
 *            the transaction on which the calls to hide the fragments is to
 *            be performed
 */
private void hideAllOtherViewFragments(ViewFragmentType fragmentToKeepVisible,
        FragmentTransaction fragmentTransaction) {
    FragmentManager fragmentManager = this.getFragmentManager();
    // First acquire all the possible fragments.
    Fragment spreadsheet = fragmentManager.findFragmentByTag(Constants.FragmentTags.SPREADSHEET);
    Fragment list = fragmentManager.findFragmentByTag(Constants.FragmentTags.LIST);
    Fragment graphManager = fragmentManager.findFragmentByTag(Constants.FragmentTags.GRAPH_MANAGER);
    Fragment mapList = fragmentManager.findFragmentByTag(Constants.FragmentTags.MAP_LIST);
    Fragment mapInner = fragmentManager.findFragmentByTag(Constants.FragmentTags.MAP_INNER_MAP);
    Fragment detailFragment = fragmentManager.findFragmentByTag(Constants.FragmentTags.DETAIL_FRAGMENT);
    Fragment graphViewFragment = fragmentManager.findFragmentByTag(Constants.FragmentTags.GRAPH_VIEW);
    if (fragmentToKeepVisible != ViewFragmentType.SPREADSHEET && spreadsheet != null) {
        fragmentTransaction.hide(spreadsheet);
    }
    if (fragmentToKeepVisible != ViewFragmentType.LIST && list != null) {
        fragmentTransaction.hide(list);
    }

    if (fragmentToKeepVisible != ViewFragmentType.DETAIL && detailFragment != null) {
        fragmentTransaction.hide(detailFragment);
    }

    if (fragmentToKeepVisible != ViewFragmentType.MAP) {
        if (mapList != null) {
            fragmentTransaction.hide(mapList);
        }
        if (mapInner != null) {
            fragmentTransaction.hide(mapInner);
        }
    }
}

From source file:com.android.calendar.AllInOneActivity.java

@Override
public void handleEvent(EventInfo event) {
    long displayTime = -1;
    if (event.eventType == EventType.GO_TO) {
        if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
            mBackToPreviousView = true;//from   w  ww. j a v  a2  s  .  c  o  m
        } else if (event.viewType != mController.getPreviousViewType() && event.viewType != ViewType.EDIT) {
            // Clear the flag is change to a different view type
            mBackToPreviousView = false;
        }

        setMainPane(null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
        if (mSearchView != null) {
            mSearchView.clearFocus();
        }
        if (mShowCalendarControls) {
            int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? mControlsAnimateWidth
                    : mControlsAnimateHeight;
            boolean noControlsView = event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA;
            if (mControlsMenu != null) {
                mControlsMenu.setVisible(!noControlsView);
                mControlsMenu.setEnabled(!noControlsView);
            }
            if (noControlsView || mHideControls) {
                // hide minimonth and calendar frag
                mShowSideViews = false;
                if (!mHideControls) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", 0,
                            animationSize);
                    slideAnimation.addListener(mSlideAnimationDoneListener);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                } else {
                    mMiniMonth.setVisibility(View.GONE);
                    mCalendarsList.setVisibility(View.GONE);
                    mMiniMonthContainer.setVisibility(View.GONE);
                }
            } else {
                // show minimonth and calendar frag
                mShowSideViews = true;
                mMiniMonth.setVisibility(View.VISIBLE);
                mCalendarsList.setVisibility(View.VISIBLE);
                mMiniMonthContainer.setVisibility(View.VISIBLE);
                if (!mHideControls && (mController.getPreviousViewType() == ViewType.MONTH
                        || mController.getPreviousViewType() == ViewType.AGENDA)) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
                            animationSize, 0);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                }
            }
        }
        displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true)
                : event.startTime.toMillis(true);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(displayTime);
        }
    } else if (event.eventType == EventType.VIEW_EVENT) {

        // If in Agenda view and "show_event_details_with_agenda" is "true",
        // do not create the event info fragment here, it will be created by the Agenda
        // fragment

        if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
            if (event.startTime != null && event.endTime != null) {
                // Event is all day , adjust the goto time to local time
                if (event.isAllDay()) {
                    Utils.convertAlldayUtcToLocal(event.startTime, event.startTime.toMillis(false), mTimeZone);
                    Utils.convertAlldayUtcToLocal(event.endTime, event.endTime.toMillis(false), mTimeZone);
                }
                mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime, event.selectedTime,
                        event.id, ViewType.AGENDA, CalendarController.EXTRA_GOTO_TIME, null, null);
            } else if (event.selectedTime != null) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, event.id,
                        ViewType.AGENDA);
            }
        } else {
            // TODO Fix the temp hack below: && mCurrentView !=
            // ViewType.AGENDA
            if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, -1,
                        ViewType.CURRENT);
            }
            int response = event.getResponse();
            if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda)
                    || ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK)
                            || mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)) {
                // start event info as activity
                Intent intent = new Intent(Intent.ACTION_VIEW);
                Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
                intent.setData(eventUri);
                intent.setClass(this, EventInfoActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
                intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
                intent.putExtra(ATTENDEE_STATUS, response);
                startActivity(intent);
            } else {
                // start event info as a dialog
                EventInfoFragment fragment = new EventInfoFragment(this, event.id,
                        event.startTime.toMillis(false), event.endTime.toMillis(false), response, true,
                        EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */);
                fragment.setDialogParams(event.x, event.y, mActionBar.getHeight());
                FragmentManager fm = getFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                // if we have an old popup replace it
                Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
                if (fOld != null && fOld.isAdded()) {
                    ft.remove(fOld);
                }
                ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
                ft.commit();
            }
        }
        displayTime = event.startTime.toMillis(true);
    } else if (event.eventType == EventType.UPDATE_TITLE) {
        setTitleInActionBar(event);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(mController.getTime());
        }
    }
    updateSecondaryTitleFields(displayTime);
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

public void showListFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.LIST);
    this.updateChildViewVisibility(ViewFragmentType.LIST);
    // Try to use a passed file name. If one doesn't exist, try to use the
    // default./* ww  w  .  j  av  a 2 s . c  om*/
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    if (fileName == null) {
        SQLiteDatabase db = null;
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getListViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.LIST, fragmentTransaction);
    ListViewFragment listViewFragment = (ListViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.LIST);
    if (listViewFragment == null || createNew) {
        if (listViewFragment == null) {
            WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] existing list fragment not found");
        } else {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] removing old list fragment");
            fragmentTransaction.remove(listViewFragment);
        }
        listViewFragment = this.createListViewFragment(fileName);
        fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, listViewFragment,
                Constants.FragmentTags.LIST);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] existing list fragment found");
        fragmentTransaction.show(listViewFragment);
    }
    fragmentTransaction.commit();
}

From source file:com.esri.android.mapsapp.MapFragment.java

/**
 * Opens the map represented by the specified portal item or if null, opens
 * a default map./*from w ww  .  j a va2 s .  c om*/
 */
public void showMap(String portalItemId, String basemapPortalItemId) {

    // remove existing MapFragment explicitly, simply replacing it can cause
    // the app to freeze when switching basemaps
    FragmentTransaction transaction;
    FragmentManager fragmentManager = getFragmentManager();
    Fragment currentMapFragment = fragmentManager.findFragmentByTag(MapFragment.TAG);
    if (currentMapFragment != null) {
        transaction = fragmentManager.beginTransaction();
        transaction.remove(currentMapFragment);
        transaction.commit();
    }

    MapFragment mapFragment = MapFragment.newInstance(portalItemId, basemapPortalItemId);

    transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.maps_app_activity_content_frame, mapFragment, MapFragment.TAG);
    transaction.addToBackStack(null);
    transaction.commit();

    getActivity().invalidateOptionsMenu(); // reload the options menu
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

public void showMapFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.MAP);
    this.updateChildViewVisibility(ViewFragmentType.MAP);
    // Set the list view file name.
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    if (fileName == null) {
        SQLiteDatabase db = null;/*from   ww  w  .j ava 2 s  .com*/
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getMapListViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.MAP, fragmentTransaction);
    MapListViewFragment mapListViewFragment = (MapListViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.MAP_LIST);
    TableMapInnerFragment innerMapFragment = (TableMapInnerFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.MAP_INNER_MAP);
    if (mapListViewFragment == null || (fileName != null && !fileName.equals(mapListViewFragment.getFileName()))
            || createNew) {
        if (mapListViewFragment != null) {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old map list fragment");
            fragmentTransaction.remove(mapListViewFragment);
        }
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new map list fragment");
        mapListViewFragment = this.createMapListViewFragment(fileName);
        fragmentTransaction.add(R.id.map_view_list, mapListViewFragment, Constants.FragmentTags.MAP_LIST);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing map list fragment found");
        fragmentTransaction.show(mapListViewFragment);
    }
    if (innerMapFragment == null || createNew) {
        if (innerMapFragment != null) {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old inner map fragment");
            fragmentTransaction.remove(innerMapFragment);
        }
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new inner map fragment");
        innerMapFragment = this.createInnerMapFragment();
        fragmentTransaction.add(R.id.map_view_inner_map, innerMapFragment,
                Constants.FragmentTags.MAP_INNER_MAP);
        innerMapFragment.listener = this;
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing inner map fragment found");
        innerMapFragment.listener = this;
        fragmentTransaction.show(innerMapFragment);
    }
    fragmentTransaction.commit();
}