Java Code Examples for android.app.FragmentManager#findFragmentByTag()

The following examples show how to use android.app.FragmentManager#findFragmentByTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UartActivity.java    From Bluefruit_LE_Connect_Android with MIT License 6 votes vote down vote up
private void restoreRetainedDataFragment() {
    // find the retained fragment
    FragmentManager fm = getFragmentManager();
    mRetainedDataFragment = (DataFragment) fm.findFragmentByTag(TAG);

    if (mRetainedDataFragment == null) {
        // Create
        mRetainedDataFragment = new DataFragment();
        fm.beginTransaction().add(mRetainedDataFragment, TAG).commit();

        mDataBuffer = new ArrayList<>();
        mTextSpanBuffer = new SpannableStringBuilder();
    } else {
        // Restore status
        mShowDataInHexFormat = mRetainedDataFragment.mShowDataInHexFormat;
        mTextSpanBuffer = mRetainedDataFragment.mTextSpanBuffer;
        mDataBuffer = mRetainedDataFragment.mDataBuffer;
        mSentBytes = mRetainedDataFragment.mSentBytes;
        mReceivedBytes = mRetainedDataFragment.mReceivedBytes;
    }
}
 
Example 2
Source File: ExtStorageWritePermisisonCheckFragment.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
public static Completable getObservable(RxActivity activity)
{
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (
            ContextCompat.checkSelfPermission(
                    activity,
                    Manifest.permission.READ_EXTERNAL_STORAGE
            ) == PackageManager.PERMISSION_GRANTED
            && ContextCompat.checkSelfPermission(
                    activity,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE
            ) == PackageManager.PERMISSION_GRANTED)
    )
        return Completable.complete();

    FragmentManager fm = activity.getFragmentManager();
    ExtStorageWritePermisisonCheckFragment f = (ExtStorageWritePermisisonCheckFragment) fm.findFragmentByTag(TAG);
    if(f == null)
    {
        f = new ExtStorageWritePermisisonCheckFragment();
        activity.getFragmentManager().beginTransaction().add(f, TAG).commit();
    }
    return f._extStoragePermissionCheckSubject;
}
 
Example 3
Source File: ActivityPermissionHelper.java    From easypermissions with Apache License 2.0 6 votes vote down vote up
@Override
public void showRequestPermissionRationale(@NonNull String rationale,
                                           @NonNull String positiveButton,
                                           @NonNull String negativeButton,
                                           @StyleRes int theme,
                                           int requestCode,
                                           @NonNull String... perms) {
    FragmentManager fm = getHost().getFragmentManager();

    // Check if fragment is already showing
    Fragment fragment = fm.findFragmentByTag(RationaleDialogFragment.TAG);
    if (fragment instanceof RationaleDialogFragment) {
        Log.d(TAG, "Found existing fragment, not showing rationale.");
        return;
    }

    RationaleDialogFragment
            .newInstance(positiveButton, negativeButton, rationale, theme, requestCode, perms)
            .showAllowingStateLoss(fm, RationaleDialogFragment.TAG);
}
 
Example 4
Source File: RTProxyImpl.java    From Android-RTEditor with Apache License 2.0 5 votes vote down vote up
@Override
/* @inheritDoc */
public void openDialogFragment(String fragmentTag, DialogFragment fragment) {
    Activity activity = getActivity();
    if (activity != null) {
        FragmentManager fragmentMgr = activity.getFragmentManager();
        FragmentTransaction ft = fragmentMgr.beginTransaction();
        DialogFragment oldFragment = (DialogFragment) fragmentMgr
                .findFragmentByTag(fragmentTag);
        if (oldFragment == null) {
            fragment.show(ft, fragmentTag);
        }
    }
}
 
Example 5
Source File: FakeSignatureGlobalWarningDialog.java    From haystack with GNU General Public License v3.0 5 votes vote down vote up
static void show(Fragment fragment) {
    FragmentManager manager = fragment.getActivity().getFragmentManager();
    if (manager.findFragmentByTag(TAG) == null) {
        FakeSignatureGlobalWarningDialog dialog = new FakeSignatureGlobalWarningDialog();
        dialog.setTargetFragment(fragment, /* requestCode: */ 0);
        dialog.show(manager, TAG);
    }
}
 
Example 6
Source File: FragmentReplacementActivity.java    From HelloActivityAndFragment with Apache License 2.0 5 votes vote down vote up
private void removeFragmentB() {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(FragmentB.TAG);
    if (null != fragment) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.remove(fragment).commit();
    }
    //remove() only goes down to onDestroyView(), not onDestroy() and onDetach()
    //if addToBackStack(), back button will goes down to onDetach()
}
 
Example 7
Source File: FakeSignatureGlobalWarningDialog.java    From haystack with GNU General Public License v3.0 5 votes vote down vote up
static void show(Fragment fragment) {
    FragmentManager manager = fragment.getActivity().getFragmentManager();
    if (manager.findFragmentByTag(TAG) == null) {
        FakeSignatureGlobalWarningDialog dialog = new FakeSignatureGlobalWarningDialog();
        dialog.setTargetFragment(fragment, /* requestCode: */ 0);
        dialog.show(manager, TAG);
    }
}
 
Example 8
Source File: Controller.java    From NewbieGuide with Apache License 2.0 5 votes vote down vote up
private void addListenerFragment() {
    //fragment监听销毁界面关闭引导层
    if (fragment != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        compatibleFragment(fragment);
        FragmentManager fm = fragment.getChildFragmentManager();
        ListenerFragment listenerFragment = (ListenerFragment) fm.findFragmentByTag(LISTENER_FRAGMENT);
        if (listenerFragment == null) {
            listenerFragment = new ListenerFragment();
            fm.beginTransaction().add(listenerFragment, LISTENER_FRAGMENT).commitAllowingStateLoss();
        }
        listenerFragment.setFragmentLifecycle(new FragmentLifecycleAdapter() {
            @Override
            public void onDestroyView() {
                LogUtil.i("ListenerFragment.onDestroyView");
                remove();
            }
        });
    }

    if (v4Fragment != null && v4Fragment.isAdded()) {
        android.support.v4.app.FragmentManager v4Fm = v4Fragment.getChildFragmentManager();
        V4ListenerFragment v4ListenerFragment = (V4ListenerFragment) v4Fm.findFragmentByTag(LISTENER_FRAGMENT);
        if (v4ListenerFragment == null) {
            v4ListenerFragment = new V4ListenerFragment();
            v4Fm.beginTransaction().add(v4ListenerFragment, LISTENER_FRAGMENT).commitAllowingStateLoss();
        }
        v4ListenerFragment.setFragmentLifecycle(new FragmentLifecycleAdapter() {
            @Override
            public void onDestroyView() {
                LogUtil.i("v4ListenerFragment.onDestroyView");
                remove();
            }
        });
    }
}
 
Example 9
Source File: WhatIsMaterialActivity.java    From MaterialDesignSupport with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FragmentManager fm = getFragmentManager();
    whatIsMaterialFragment = (WhatIsMaterialFragment) fm.findFragmentByTag(WhatIsMaterialFragment.TAG);

    if (whatIsMaterialFragment == null) {
        whatIsMaterialFragment = WhatIsMaterialFragment.newInstance();
        addFragment(whatIsMaterialFragment, WhatIsMaterialFragment.TAG);
    }
}
 
Example 10
Source File: VideoCastControllerActivity.java    From UTubeTV with The Unlicense 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.cast_activity);
  loadAndSetupViews();
  mVolumeIncrement = CastUtils.getFloatFromPreference(this, VideoCastManager.PREFS_KEY_VOLUME_INCREMENT);
  try {
    mCastManager = VideoCastManager.getInstance(this);
  } catch (CastException e) {
    // logged already
  }

  setupActionBar();
  Bundle extras = getIntent().getExtras();
  if (null == extras) {
    finish();
    return;
  }

  FragmentManager fm = getFragmentManager();
  VideoCastControllerFragment mediaAuthFragment = (VideoCastControllerFragment) fm.findFragmentByTag("task");

  // if fragment is null, it means this is the first time, so create it
  if (mediaAuthFragment == null) {
    mediaAuthFragment = VideoCastControllerFragment.newInstance(extras);
    fm.beginTransaction().add(mediaAuthFragment, "task").commit();
    mListener = mediaAuthFragment;
    setOnVideoCastControllerChangedListener(mListener);
  } else {
    mListener = mediaAuthFragment;
    mListener.onConfigurationChanged();
  }
}
 
Example 11
Source File: PinchImageView.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the retainFragment - search it by the index. If not found, create a new one.
 *
 * @param fm The fragment manager handling this fragment.
 * @param index The index of the view (required in case of multiple PinchImageViews to be retained).
 * @return the retainFragment.
 */
@NonNull
public static RetainFragment findOrCreateRetainFragment(@NonNull final FragmentManager fm, final int index) {
	RetainFragment fragment = (RetainFragment) fm.findFragmentByTag(TAG + index);
	if (fragment == null) {
		fragment = new RetainFragment();
		fm.beginTransaction().add(fragment, TAG + index).commit();
	}
	return fragment;
}
 
Example 12
Source File: SyncCustomizationFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
private void closeDialogIfOpen(String tag) {
    FragmentManager manager = getFragmentManager();
    if (manager == null) {
        // Do nothing if the manager doesn't exist yet; see http://crbug.com/480544.
        return;
    }
    DialogFragment df = (DialogFragment) manager.findFragmentByTag(tag);
    if (df != null) {
        df.dismiss();
    }
}
 
Example 13
Source File: BaseFragmentUtil.java    From android-commons with Apache License 2.0 5 votes vote down vote up
public static void showDialogFragment(final DialogFragment dialog,
                                      final String tag, final FragmentManager fragmentManager) {
  final FragmentTransaction ft = fragmentManager.beginTransaction();
  final Fragment prev = fragmentManager.findFragmentByTag(tag);
  if (prev != null) {
    ft.remove(prev);
  }
  ft.add(dialog, tag);
  ft.commitAllowingStateLoss();
}
 
Example 14
Source File: OverlayPinchImageView.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the retainFragment - search it by the index. If not found, create a new one.
 *
 * @param fm    The fragment manager handling this fragment.
 * @param index The index of the view (required in case of multiple PinchImageViews to be retained).
 * @return the retainFragment.
 */
@NonNull
public static RetainFragment findOrCreateRetainFragment(@NonNull final FragmentManager fm, final int index) {
	RetainFragment fragment = (RetainFragment) fm.findFragmentByTag(TAG + index);
	if (fragment == null) {
		fragment = new RetainFragment();
		try {
			fm.beginTransaction().add(fragment, TAG + index).commit();
		}
		catch (IllegalStateException e) {
			TrackingUtil.sendException("opv1", e);
		}
	}
	return fragment;
}
 
Example 15
Source File: FilePropertiesFragment.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
private void cancelCalcTask()
{
	FragmentManager fm = getFragmentManager();
	if(fm == null)
		return;
	TaskFragment tf = (TaskFragment) fm.findFragmentByTag(CalcPropertiesTaskFragment.TAG);
	if(tf!=null)
		tf.cancel();
}
 
Example 16
Source File: FileListViewFragmentBase.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
private void openLocation(Location locToOpen)
{
    FragmentManager fm = getFragmentManager();
    String openerTag = LocationOpenerBaseFragment.getOpenerTag(locToOpen);
    if(fm.findFragmentByTag(openerTag)==null)
    {
        LocationOpenerBaseFragment opener = LocationOpenerBaseFragment.getDefaultOpenerForLocation(locToOpen);
        Bundle openerArgs = new Bundle();
        LocationsManager.storePathsInBundle(openerArgs, locToOpen, null);
        openerArgs.putString(LocationOpenerBaseFragment.PARAM_RECEIVER_FRAGMENT_TAG, getTag());
        opener.setArguments(openerArgs);
        fm.beginTransaction().add(opener, openerTag).commit();
    }
}
 
Example 17
Source File: HiddenSettingsActivity.java    From United4 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Switches to the passed fragment
 * If the currently shown fragment has the same type as the argument, does nothing. Otherwise,
 * removes the current fragment and makes a new fragment of the passed in type and shows it
 * @param type the fragment to switch to
 * @param arguments arguments to give to the fragment
 */
private void swapScreens(FragmentType type, @Nullable Bundle arguments) {
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    // if we already have a fragment and that fragment is not the fragment we want to show, remove it
    // otherwise, it is the fragment we want to show, so we're done, just return and abort the transaction
    if (manager.findFragmentByTag("fragment") != null) {
        if (((HiddenSettingsFragment) manager.findFragmentByTag("fragment")).getType() != type) {
            transaction.remove(manager.findFragmentByTag("fragment"));
        } else {
            return;
        }
    }
    // Make a new fragment
    Fragment newFragment = null;
    switch (type) {
        case SETTINGS_LIST:
            newFragment = new SettingsListFragment();
            break;
        case JANITOR_LOGIN:
            newFragment = new JanitorLoginFragment();
            break;
        case THREAD_WATCHER:
            newFragment = new ThreadWatcherFragment();
            break;
        case AWOO_ENDPOINT:
            newFragment = new AwooEndpointFragment();
            break;
        case DEBUG_SETTINGS_LIST:
            newFragment = new DebugSettingsListFragment();
            break;
        case COLOR_LIST:
            newFragment = new ColorListFragment();
            break;
        case PROPERTY_EDITOR:
            newFragment = new PropertyEditorFragment();
            break;
        case PROPERTY_EDITOR_NEW:
            newFragment = new NewPropertyFragment();
            break;
        case PROPERTIES_LIST:
            newFragment = new PropertiesListFragment();
            break;
        case HIDDEN_LIST:
            newFragment = new HiddenThreadListFragment();
            break;
        case NOTIFICATION_SETTINGS:
            newFragment = new NotificationSettingsFragment();
            break;
        case COLOR_PICKER:
            newFragment = new ColorPickerFragment();
            break;
    }
    newFragment.setArguments(arguments);
    // Put the fragment in our layout
    //transaction.add(newFragment, "fragment");
    transaction.replace(R.id.userscript_activity_main_fragment, newFragment, "fragment");
    transaction.addToBackStack("fragment"); // TODO is this needed?
    transaction.commit();
}
 
Example 18
Source File: HomeFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static HomeFragment get(FragmentManager fm) {
    return (HomeFragment) fm.findFragmentByTag(TAG);
}
 
Example 19
Source File: PickFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static PickFragment get(FragmentManager fm) {
    return (PickFragment) fm.findFragmentByTag(TAG);
}
 
Example 20
Source File: RssfeedActivity.java    From codeexamples-android with Eclipse Public License 1.0 3 votes vote down vote up
private void showDetailFragment(int containerId, String rssItemUrl, boolean addToBackStack) {
	
	// find detail fragment first
	FragmentManager fm = getFragmentManager();
	RssfeedDetailFragment detailFragment =
			(RssfeedDetailFragment) fm.findFragmentByTag(TAG_DETAIL);

	if (detailFragment == null) {
		// create new detail fragment
		detailFragment = RssfeedDetailFragment.instantiate(rssItemUrl);
		
		// add fragment to the layout
		addDetailFragment(detailFragment, containerId, addToBackStack, fm);
		
	} else if (detailFragment.getId() != containerId) {
			
		// remove fragment from old container
		fm.beginTransaction().remove(detailFragment).commit();
		fm.executePendingTransactions();
		
		// add fragment to the new container
		addDetailFragment(detailFragment, containerId, addToBackStack, fm);
		
	} // else, fragment is already at the right place
	
	detailFragment.setUrl(rssItemUrl);
	
}