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

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

Introduction

In this page you can find the example usage for android.support.v4.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:com.grayfox.android.app.fragment.ExploreFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    FragmentManager fragmentManager = getChildFragmentManager();
    SupportMapFragment fragment = (SupportMapFragment) fragmentManager.findFragmentByTag(MAP_FRAGMENT_TAG);
    if (fragment == null) {
        fragment = SupportMapFragment.newInstance();
        fragmentManager.beginTransaction().replace(R.id.map_container, fragment, MAP_FRAGMENT_TAG).commit();
    }/*from   w w w. j  ava 2  s.com*/
    myLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onRequestLocationUpdates();
        }
    });
    googleApiClient = new GoogleApiClient.Builder(getActivity()).addApi(LocationServices.API)
            .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    fragment.getMapAsync(this);
}

From source file:com.bitants.wally.fragments.SearchFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    FragmentManager fragmentManager = getFragmentManager();
    if (fragmentManager.findFragmentByTag(ColorPickerDialogFragment.TAG) != null) {
        ColorPickerDialogFragment colorPickerDialogFragment = (ColorPickerDialogFragment) fragmentManager
                .findFragmentByTag(ColorPickerDialogFragment.TAG);
        colorPickerDialogFragment/* w  ww .  ja  v  a  2s . c  o  m*/
                .setOnDialogButtonClickedListener(getColorPickerOnDialogButtonClickedListener());
        /*
        If the color picker dialog is open when a user rotates their device, the listener for the buttons
        would still be attached to the old fragment, hence not updating the content in the new one.
        This solution solves the problem by reattaching the listener to the new fragment.
         */
    }
}

From source file:com.espiandev.redux.cast.mediarouterplus.MediaRouteButtonPlus.java

/**
 * Show the route chooser or controller dialog.
 * <p>//from   ww w  .  ja v  a2 s.co m
 * If the default route is selected or if the currently selected route does
 * not match the {@link #getRouteSelector selector}, then shows the route chooser dialog.
 * Otherwise, shows the route controller dialog to offer the user
 * a choice to disconnect from the route or perform other control actions
 * such as setting the route's volume.
 * </p><p>
 * The application can customize the dialogs by calling {@link #setDialogFactory}
 * to provide a customized dialog factory.
 * </p>
 *
 * @return True if the dialog was actually shown.
 *
 * @throws IllegalStateException if the activity is not a subclass of
 * {@link android.support.v4.app.FragmentActivity}.
 */
public boolean showDialog() {
    if (!mAttachedToWindow) {
        return false;
    }

    final FragmentManager fm = getFragmentManager();
    if (fm == null) {
        throw new IllegalStateException("The activity must be a subclass of FragmentActivity");
    }

    MediaRouter.RouteInfo route = mRouter.getSelectedRoute();
    if (route.isDefault() || !route.matchesSelector(mSelector)) {
        if (fm.findFragmentByTag(CHOOSER_FRAGMENT_TAG) != null) {
            Log.w(TAG, "showDialog(): Route chooser dialog already showing!");
            return false;
        }
        MediaRouteChooserDialogFragment f = mDialogFactory.onCreateChooserDialogFragment();
        f.setRouteSelector(mSelector);
        f.show(fm, CHOOSER_FRAGMENT_TAG);
    } else {
        if (fm.findFragmentByTag(CONTROLLER_FRAGMENT_TAG) != null) {
            Log.w(TAG, "showDialog(): Route controller dialog already showing!");
            return false;
        }
        MediaRouteControllerDialogFragment f = mDialogFactory.onCreateControllerDialogFragment();
        f.show(fm, CONTROLLER_FRAGMENT_TAG);
    }
    return true;
}

From source file:com.jaspersoft.android.jaspermobile.dialog.RateAppDialog.java

public void show(Context context, FragmentManager fm) {
    DefaultPrefHelper prefHelper = DefaultPrefHelper_.getInstance_(context);
    if (!prefHelper.isRateDialogEnabled())
        return;//from ww  w  .  ja va2  s . com

    prefHelper.increaseNonRateLaunchCount();

    long lastAppLaunchTime = prefHelper.getLastRateTime();
    long currentTime = new Date().getTime();
    if (lastAppLaunchTime == 0) {
        prefHelper.setLastRateTime(currentTime);
        return;
    }

    long appLaunchCount = prefHelper.getNonRateLaunchCount();
    if (appLaunchCount != LAUNCHES_UNTIL_SHOW || currentTime <= lastAppLaunchTime + PASSED_TIME_UNTIL_SHOW)
        return;

    prefHelper.setLastRateTime(currentTime);

    RateAppDialog dialogFragment = (RateAppDialog) fm.findFragmentByTag(TAG);
    if (dialogFragment == null) {
        dialogFragment = RateAppDialog_.builder().build();
        dialogFragment.show(fm, TAG);
    }
}

From source file:com.chatwingsdk.activities.CommunicationActivity.java

protected void setupMode(CommunicationModeManager newMode, CommunicationMessagesFragment newFragment) {
    /*/*from w w w.  jav a  2s  .  c o  m*/
     * Update fragments
     */
    String fragmentTag = getString(R.string.tag_communication_messages);
    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment oldFragment = fragmentManager.findFragmentByTag(fragmentTag);
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (oldFragment != null) {
        fragmentTransaction.remove(oldFragment);
    }
    fragmentTransaction.add(R.id.fragment_container, newFragment, fragmentTag);
    fragmentTransaction.commit();

    /*
     * Deactivate old mode and activate the new one
     */
    if (mCurrentCommunicationMode != null) {
        mCurrentCommunicationMode.deactivate();
    }
    mCurrentCommunicationMode = newMode;
    mCurrentCommunicationMode.activate();

    /*
     * Setup drawer layout
     */
    // Set custom shadows that overlay the main content when a drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
    mDrawerToggle = mCurrentCommunicationMode.getDrawerToggleListener();
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    // Don't allow the drawer layout to catch back button and close itself
    // on back key is pressed. This activity will handle it.
    mDrawerLayout.setFocusableInTouchMode(false);

    invalidateOptionsMenu();
}

From source file:com.androzic.MainActivity.java

@Override
public void onRouteDetails(Route route) {
    FragmentManager fm = getSupportFragmentManager();
    RouteDetails routeDetails = (RouteDetails) fm.findFragmentByTag("route_details");
    if (routeDetails == null)
        routeDetails = (RouteDetails) Fragment.instantiate(this, RouteDetails.class.getName());
    routeDetails.setRoute(route);/*from   w  ww . ja v  a2 s  .c  o  m*/
    addFragment(routeDetails, "route_details");
}

From source file:com.androzic.MainActivity.java

@Override
public void onTrackDetails(Track track) {
    FragmentManager fm = getSupportFragmentManager();
    TrackDetails trackDetails = (TrackDetails) fm.findFragmentByTag("track_details");
    if (trackDetails == null)
        trackDetails = new TrackDetails();
    trackDetails.setTrack(track);/*from   w  w w .  j a v a2s.c  om*/
    addFragment(trackDetails, "track_details");
}

From source file:android.support.v7.app.MediaRouteButton.java

/**
 * Show the route chooser or controller dialog.
 * <p>//from  w  w w. ja v a 2s.co  m
 * If the default route is selected or if the currently selected route does
 * not match the {@link #getRouteSelector selector}, then shows the route chooser dialog.
 * Otherwise, shows the route controller dialog to offer the user
 * a choice to disconnect from the route or perform other control actions
 * such as setting the route's volume.
 * </p><p>
 * The application can customize the dialogs by calling {@link #setDialogFactory}
 * to provide a customized dialog factory.
 * </p>
 *
 * @return True if the dialog was actually shown.
 *
 * @throws IllegalStateException if the activity is not a subclass of
 * {@link FragmentActivity}.
 */
public boolean showDialog() {
    if (!mAttachedToWindow) {
        return false;
    }

    final FragmentManager fm = getFragmentManager();
    if (fm == null) {
        throw new IllegalStateException("The activity must be a subclass of FragmentActivity");
    }

    MediaRouter.RouteInfo route = mRouter.getSelectedRoute();
    if (route.isDefaultOrBluetooth() || !route.matchesSelector(mSelector)) {
        if (fm.findFragmentByTag(CHOOSER_FRAGMENT_TAG) != null) {
            Log.w(TAG, "showDialog(): Route chooser dialog already showing!");
            return false;
        }
        MediaRouteChooserDialogFragment f = mDialogFactory.onCreateChooserDialogFragment();
        f.setRouteSelector(mSelector);
        f.show(fm, CHOOSER_FRAGMENT_TAG);
    } else {
        if (fm.findFragmentByTag(CONTROLLER_FRAGMENT_TAG) != null) {
            Log.w(TAG, "showDialog(): Route controller dialog already showing!");
            return false;
        }
        MediaRouteControllerDialogFragment f = mDialogFactory.onCreateControllerDialogFragment();
        f.show(fm, CONTROLLER_FRAGMENT_TAG);
    }
    return true;
}

From source file:com.androzic.MainActivity.java

@Override
public void onWaypointShow(Waypoint waypoint) {
    Location loc = application.getLocationAsLocation();
    FragmentManager fm = getSupportFragmentManager();
    WaypointInfo waypointInfo = (WaypointInfo) fm.findFragmentByTag("waypoint_info");
    if (waypointInfo == null)
        waypointInfo = new WaypointInfo();
    waypointInfo.setWaypoint(waypoint);//from   w ww. j a v a2s.  c  om
    Bundle args = new Bundle();
    args.putDouble("lat", loc.getLatitude());
    args.putDouble("lon", loc.getLongitude());
    waypointInfo.setArguments(args);
    waypointInfo.show(fm, "waypoint_info");
}

From source file:com.androzic.MainActivity.java

@Override
public void onRouteEdit(Route route) {
    FragmentManager fm = getSupportFragmentManager();
    RouteProperties routeProperties = (RouteProperties) fm.findFragmentByTag("route_properties");
    if (routeProperties == null)
        routeProperties = (RouteProperties) Fragment.instantiate(this, RouteProperties.class.getName());
    routeProperties.setRoute(route);// w w w  .  ja  v a 2  s  .  c o m
    addFragment(routeProperties, "route_properties");
}