Java Code Examples for android.app.FragmentManager

The following examples show how to use android.app.FragmentManager. These examples are extracted from open source projects. 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
@Override
public boolean dispatchKeyEvent(final KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_BACK:
                FragmentManager fm = getFragmentManager();
                int cnt = fm.getBackStackEntryCount();
                if (cnt <= 1) {
                    finish();
                    return false;
                } else {
                    currentPage--;
                }
                break;
            default:
                break;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 2
private void submit(String spell) {
    String input = mEt_Spelling.getText().toString().trim();
    if (input.length() == 0) {
        Toast.makeText(mContext, "Please enter the spelling",
                Toast.LENGTH_SHORT).show();

    } else {
        mAlert.dismiss();

        String answered = mEt_Spelling.getText().toString().trim();
        db.markAnswered(Integer.parseInt(spell), answered);

        Bundle arguments = new Bundle();
        arguments.putString(Intent.EXTRA_TEXT, String.valueOf(spell));

        Fragment frag = ResponseFragment.newInstance();
        frag.setArguments(arguments);

        getActivity().getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        getActivity().getSupportFragmentManager().beginTransaction().replace(((ViewGroup) getView().getParent()).getId(), frag).addToBackStack(null).commit();

    }
}
 
Example 3
Source Project: cwac-pager   Source File: ArrayPagerAdapter.java    License: Apache License 2.0 6 votes vote down vote up
public ArrayPagerAdapter(FragmentManager fragmentManager,
                         List<PageDescriptor> descriptors,
                         RetentionStrategy retentionStrategy) {
  this.fm=fragmentManager;
  this.entries=new ArrayList<PageEntry>();

  for (PageDescriptor desc : descriptors) {
    validatePageDescriptor(desc);

    entries.add(new PageEntry(desc));
  }

  this.retentionStrategy=retentionStrategy;

  if (this.retentionStrategy == null) {
    this.retentionStrategy=KEEP;
  }
}
 
Example 4
Source Project: maps-app-android   Source File: MapsAppActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Opens the content browser that shows the user's maps.
 */
private void showContentBrowser() {
	FragmentManager fragmentManager = getFragmentManager();
	Fragment browseFragment = fragmentManager.findFragmentByTag(ContentBrowserFragment.TAG);
	if (browseFragment == null) {
		browseFragment = new ContentBrowserFragment();
	}

	if (!browseFragment.isVisible()) {
		FragmentTransaction transaction = fragmentManager.beginTransaction();
		transaction.add(R.id.maps_app_activity_content_frame, browseFragment, ContentBrowserFragment.TAG);
		transaction.addToBackStack(null);
		transaction.commit();

		invalidateOptionsMenu(); // reload the options menu
	}

	mDrawerLayout.closeDrawers();
}
 
Example 5
Source Project: debugkit   Source File: DevTool.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Build the tool and show it.
 *
 * @return this to allow chaining.
 */
public Builder build() {
    if (devToolsEnabled) {
        if (mFunctions != null && mFunctions.size() > 0)
            fragment.setFunctionList(mFunctions);

        if (mTextSize != null)
            fragment.setConsoleTextSize(mTextSize);

        fragment.displayAt(startX, starty);

        try {
            FragmentManager fragmentManager = activity.getFragmentManager();
            fragmentManager.beginTransaction()
                    .add(android.R.id.content, fragment)
                    .commit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        fragment.setTheme(mTheme);
    }
    return this;
}
 
Example 6
Source Project: ShoppingList   Source File: ShoppingListFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void onError(ResponseHelper error) {
//        if(error.getType() == CONSTS.APP_ERROR_IO) {
//            getList();
//            return;
//        }

        resetRefreshing();
        ErrorFragment errFR;
        Bundle args = new Bundle();
        args.putString("error_code", error.getContent());
        errFR = new ErrorFragment();
        errFR.setArguments(args);
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fragment_container, errFR);
        transaction.addToBackStack(null);
        transaction.commitAllowingStateLoss();
    }
 
Example 7
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setupActionBar();

	setContentView(R.layout.directory_chooser_activity);

	final String newDirName = getIntent().getStringExtra(EXTRA_NEW_DIR_NAME);
	final String initialDir = getIntent().getStringExtra(EXTRA_INITIAL_DIRECTORY);

	if (newDirName == null) {
		throw new IllegalArgumentException(
				"You must provide EXTRA_NEW_DIR_NAME when starting the DirectoryChooserActivity.");
	}

	if (savedInstanceState == null) {
		final FragmentManager fragmentManager = getFragmentManager();
		final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(newDirName, initialDir);
		fragmentManager.beginTransaction()
				.add(R.id.main, fragment)
				.commit();
	}
}
 
Example 8
Source Project: WearViewStub   Source File: ElementGridPagerAdapter.java    License: Apache License 2.0 6 votes vote down vote up
public ElementGridPagerAdapter(List<Element> elements, FragmentManager fm) {
    super(fm);

    this.mRows = new ArrayList<>();
    this.mElement = elements;

    //Construit le tableau des éléménts à afficher
    for (Element element : elements) {
        mRows.add(new Row(
                        //pour l'instant nous ne mettrons qu'un élément par ligne
                        createElementFragment(),
                        CardFragment.create(element.getTitre(), element.getTexte()),
                        createActionFragment(),
                        createActionFragment()
                )
        );
    }
}
 
Example 9
Source Project: moviedb-android   Source File: TVDetailsTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Adds the fragment to a new blank activity, thereby fully
 * initializing its view.
 */
@Before
public void setUp() {
    tvDetailsFragment = new TVDetails();
    activity = Robolectric.buildActivity(MainActivity.class).create().get();
    FragmentManager manager = activity.getFragmentManager();
    Bundle bundle = new Bundle();
    bundle.putInt("id", 1);
    tvDetailsFragment.setArguments(bundle);
    manager.beginTransaction().add(tvDetailsFragment, FRAGMENT_TAG).commit();

    tvDetailsFragmentView = tvDetailsFragment.getView();
    moreIcon = (CircledImageView) tvDetailsFragmentView.findViewById(R.id.moreIcon);
    homeIcon = (CircledImageView) tvDetailsFragmentView.findViewById(R.id.homeIcon);
    galleryIcon = (CircledImageView) tvDetailsFragmentView.findViewById(R.id.galleryIcon);
}
 
Example 10
Source Project: moviedb-android   Source File: GenresList.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 */
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
                        long id) {
    if (movieList.getCurrentList().equals("genre/" + genresList.get(position).getId() + "/movies"))
        movieList.setBackState(1);
    else {
        movieList.setCurrentList("genre/" + genresList.get(position).getId() + "/movies");
        movieList.setBackState(0);
    }
    movieList.setTitle(genresList.get(position).getName());
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle args = new Bundle();
    args.putString("currentList", "genresList");
    movieList.setArguments(args);
    transaction.replace(R.id.frame_container, movieList);
    // add the current transaction to the back stack:
    transaction.addToBackStack("genresList");
    transaction.commit();
    backState = 1;
}
 
Example 11
private void selectItem(int position) {
	// update the main content by replacing fragments
	Fragment fragment = new AnimalFragment();
	Bundle args = new Bundle();
	args.putInt(AnimalFragment.ARG_ANIMAL_NUMBER, position);
	fragment.setArguments(args);

	FragmentManager fragmentManager = getFragmentManager();
	fragmentManager.beginTransaction()
			.replace(R.id.content_frame, fragment).commit();

	// update selected item and title, then close the drawer
	mDrawerList.setItemChecked(position, true);
	setTitle(mAnimalTitles[position]);
	mDrawerLayout.closeDrawer(mDrawerList);
}
 
Example 12
Source Project: yandex-money-sdk-android   Source File: PaymentActivity.java    License: MIT License 6 votes vote down vote up
private void replaceFragment(@Nullable Fragment fragment, boolean clearBackStack) {
    if (fragment == null || isStateSaved) {
        return;
    }

    Fragment currentFragment = getCurrentFragment();
    FragmentManager manager = getFragmentManager();
    if (clearBackStack) {
        manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

    @SuppressLint("CommitTransaction")
    FragmentTransaction transaction = manager.beginTransaction()
            .replace(R.id.ym_container, fragment);
    if (!clearBackStack && currentFragment != null) {
        transaction.addToBackStack(fragment.getTag());
    }
    transaction.commit();
    hideKeyboard();
}
 
Example 13
Source Project: cordova-plugin-camera-preview   Source File: CameraPreview.java    License: MIT License 6 votes vote down vote up
private boolean stopCamera(CallbackContext callbackContext) {
  if(webViewParent != null) {
    cordova.getActivity().runOnUiThread(new Runnable() {
      @Override
      public void run() {
        ((ViewGroup)webView.getView()).bringToFront();
        webViewParent = null;
      }
    });
  }

  if(this.hasView(callbackContext) == false){
    return true;
  }

  FragmentManager fragmentManager = cordova.getActivity().getFragmentManager();
  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  fragmentTransaction.remove(fragment);
  fragmentTransaction.commit();
  fragment = null;

  callbackContext.success();
  return true;
}
 
Example 14
Source Project: HtmlDialog   Source File: HtmlDialog.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * The sole constructor for {@code HtmlDialog}.
 *
 * @param fm  The {@code FragmentManager} from the calling activity that is used
 *            internally to show the {@code DialogFragment}.
 */
public HtmlDialog(FragmentManager fm)
{
    // See if there are any DialogFragments from the FragmentManager
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(HtmlDialogFragment.TAG_HTML_DIALOG_FRAGMENT);

    // Remove if found
    if (prev != null)
    {
        ft.remove(prev);
        ft.commit();
    }

    mFragmentManager = fm;
}
 
Example 15
Source Project: Ouroboros   Source File: ThreadActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void doPositiveClickInternal(String threadNo, String boardName) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    //clear dialog fragments
    fragmentManager.popBackStack("threadDialog", FragmentManager.POP_BACK_STACK_INCLUSIVE);
    if (!threadNo.equals("0")){
        threadDepth = threadDepth + 1;
        threadFragment = new ThreadFragment().newInstance(threadNo, boardName);
        fragmentTransaction.replace(R.id.placeholder_card, threadFragment)
                .addToBackStack("threadDepth" + String.valueOf(threadDepth))
                .commit();
    } else {
        Intent intent = new Intent(this, CatalogActivity.class);
        intent.putExtra(Util.INTENT_BOARD_NAME, boardName);
        startActivity(intent);

    }

}
 
Example 16
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final AbstractBrowserActivity activity = (AbstractBrowserActivity) getActivity();
    final FragmentManager fm = getFragmentManager();

    switch (item.getItemId()) {
        case R.id.folderinfo:
            final DialogFragment dirInfo = new DirectoryInfoDialog();
            dirInfo.show(fm, AbstractBrowserActivity.TAG_DIALOG);
            return true;
        case R.id.search:
            Intent sintent = new Intent(activity, SearchActivity.class);
            startActivity(sintent);
            return true;
        case R.id.paste:
            final PasteTaskExecutor ptc = new PasteTaskExecutor(activity, mCurrentPath);
            ptc.start();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 17
Source Project: FireFiles   Source File: ServerFragment.java    License: Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, RootInfo root) {
    final ServerFragment fragment = new ServerFragment();
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_ROOT, root);
    fragment.setArguments(args);
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 18
private boolean popFragment() {
    FragmentManager fm = getFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStack();
        return true;
    }
    return false;
}
 
Example 19
Source Project: webrtc_android   Source File: Permissions.java    License: MIT License 5 votes vote down vote up
@RequiresApi(M)
public static void request2(Activity activity, String permission, Consumer<Integer> callback) {
    final FragmentManager fm = activity.getFragmentManager();
    if (!has(activity, permission)) {
        fm.beginTransaction().add(new PermissionRequestFragment(new String[]{permission}, callback), null).commitAllowingStateLoss();
    } else {
        callback.accept(PERMISSION_GRANTED);
    }
}
 
Example 20
@Override
    public void onHotwordDetected() {
        FragmentManager fm = activity.getFragmentManager();
        mVoiceMenu = VoiceMenuDialogFragment.getInstance(fm,mHotword,null,mPhrases);
        mVoiceMenu.show(fm, VoiceMenuDialogFragment.FRAGMENT_TAG);
//        mVoiceDetection.changePhrases(mPhrases);

        mListener.onHotwordDetected();
    }
 
Example 21
Source Project: FireFiles   Source File: StandaloneActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();
    final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
    final MenuItem search = menu.findItem(R.id.menu_search);
    final MenuItem sort = menu.findItem(R.id.menu_sort);
    final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    sort.setVisible(cwd != null);
    grid.setVisible(mState.derivedMode != State.MODE_GRID);
    list.setVisible(mState.derivedMode != State.MODE_LIST);
    if (mState.currentSearch != null) {
        // Search uses backend ranking; no sorting
        sort.setVisible(false);
        search.expandActionView();
        mSearchView.setIconified(false);
        mSearchView.clearFocus();
        mSearchView.setQuery(mState.currentSearch, false);
    } else {
        mIgnoreNextClose = true;
        mSearchView.setIconified(true);
        mSearchView.clearFocus();
        mIgnoreNextCollapse = true;
        search.collapseActionView();
    }
    // Only sort by size when visible
    sortSize.setVisible(mState.showSize);
    search.setVisible(true);
    createDir.setVisible(true);
    return true;
}
 
Example 22
Source Project: Snake   Source File: FragmentManagerHelper.java    License: Apache License 2.0 5 votes vote down vote up
public androidx.fragment.app.Fragment getLastAndroidXFragment(androidx.fragment.app.FragmentManager fragmentManager) {
    if (null == fragmentManager) return null;

    int backStackCount = fragmentManager.getBackStackEntryCount();
    if (backStackCount <= 0) return null;

    androidx.fragment.app.FragmentManager.BackStackEntry backStackEntry = fragmentManager.getBackStackEntryAt(backStackCount - 1);
    String fragmentTag = backStackEntry.getName();
    return fragmentManager.findFragmentByTag(fragmentTag);
}
 
Example 23
Source Project: AvoidOnResult   Source File: AvoidOnResult.java    License: Apache License 2.0 5 votes vote down vote up
private AvoidOnResultFragment getAvoidOnResultFragment(Activity activity) {
    AvoidOnResultFragment avoidOnResultFragment = findAvoidOnResultFragment(activity);
    if (avoidOnResultFragment == null) {
        avoidOnResultFragment = new AvoidOnResultFragment();
        FragmentManager fragmentManager = activity.getFragmentManager();
        fragmentManager
                .beginTransaction()
                .add(avoidOnResultFragment, TAG)
                .commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
    return avoidOnResultFragment;
}
 
Example 24
Source Project: FireFiles   Source File: ServerFragment.java    License: Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, RootInfo root) {
    final ServerFragment fragment = new ServerFragment();
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_ROOT, root);
    fragment.setArguments(args);
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 25
Source Project: RateMyApp   Source File: ShowDialogAction.java    License: MIT License 5 votes vote down vote up
@Override
public void execute(Context context, FragmentManager fragmentManager){
    try {
        AbstractDialogFragment dialogFragment = fragmentDialogClass.newInstance();
        dialogFragment.setActualListener(actualListener);
        dialogFragment.show(fragmentManager, tag);
    } catch (Exception e) { }
}
 
Example 26
public static ConversationFragment get(Activity activity) {
    FragmentManager fragmentManager = activity.getFragmentManager();
    Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
    if (fragment != null && fragment instanceof ConversationFragment) {
        return (ConversationFragment) fragment;
    } else {
        fragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
        return fragment != null && fragment instanceof ConversationFragment ? (ConversationFragment) fragment : null;
    }
}
 
Example 27
Source Project: chromium-webview-samples   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
            .commit();
}
 
Example 28
Source Project: deagle   Source File: Permissions.java    License: Apache License 2.0 5 votes vote down vote up
/** @param callback will be called if request is not canceled, with either {@link PackageManager#PERMISSION_GRANTED} or {@link PackageManager#PERMISSION_DENIED} */
@RequiresApi(M) public static void request(final Activity activity, final String permission, final Consumer<Integer> callback) {
	final FragmentManager fm = activity.getFragmentManager();
	if (! has(activity, permission))
		fm.beginTransaction().add(new PermissionRequestFragment(permission, callback), null).commitAllowingStateLoss();
	else callback.accept(PackageManager.PERMISSION_GRANTED);
}
 
Example 29
Source Project: writeily-pro   Source File: MainActivity.java    License: MIT License 5 votes vote down vote up
private void showFolderNameDialog() {
    FragmentManager fragManager = getFragmentManager();

    Bundle args = new Bundle();
    args.putString(Constants.CURRENT_DIRECTORY_DIALOG_KEY, notesFragment.getCurrentDir().getAbsolutePath());

    CreateFolderDialog createFolderDialog = new CreateFolderDialog();
    createFolderDialog.setArguments(args);
    createFolderDialog.show(fragManager, Constants.CREATE_FOLDER_DIALOG_TAG);
}
 
Example 30
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    DocumentScannerApplication.getInstance().trackScreenView("Settings");
    FragmentManager fm=getFragmentManager();
    FragmentTransaction ft=fm.beginTransaction();

    sf=new SettingsFragment();
    ft.replace(android.R.id.content, sf);
    ft.commit();
}