Example usage for android.support.v4.app FragmentActivity getSupportFragmentManager

List of usage examples for android.support.v4.app FragmentActivity getSupportFragmentManager

Introduction

In this page you can find the example usage for android.support.v4.app FragmentActivity getSupportFragmentManager.

Prototype

public FragmentManager getSupportFragmentManager() 

Source Link

Document

Return the FragmentManager for interacting with fragments associated with this activity.

Usage

From source file:com.app.blockydemo.ui.fragment.FormulaEditorFragment.java

public static void showFragment(View view, Brick brick, Formula formula) {

    FragmentActivity activity = null;
    activity = (FragmentActivity) view.getContext();

    FormulaEditorFragment formulaEditorFragment = (FormulaEditorFragment) activity.getSupportFragmentManager()
            .findFragmentByTag(FORMULA_EDITOR_FRAGMENT_TAG);

    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction fragTransaction = fragmentManager.beginTransaction();

    if (formulaEditorFragment == null) {
        formulaEditorFragment = new FormulaEditorFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(BRICK_BUNDLE_ARGUMENT, brick);
        bundle.putSerializable(FORMULA_BUNDLE_ARGUMENT, formula);
        formulaEditorFragment.setArguments(bundle);

        fragTransaction.add(R.id.script_fragment_container, formulaEditorFragment, FORMULA_EDITOR_FRAGMENT_TAG);
        fragTransaction.hide(fragmentManager.findFragmentByTag(ScriptFragment.TAG));
        fragTransaction.show(formulaEditorFragment);
        BottomBar.hideBottomBar(activity);
    } else if (formulaEditorFragment.isHidden()) {
        formulaEditorFragment.updateBrickViewAndFormula(brick, formula);
        fragTransaction.hide(fragmentManager.findFragmentByTag(ScriptFragment.TAG));
        fragTransaction.show(formulaEditorFragment);
        BottomBar.hideBottomBar(activity);
    } else {/*from  w w  w.  ja  v a2s  .  c o m*/
        formulaEditorFragment.setInputFormula(formula, SET_FORMULA_ON_SWITCH_EDIT_TEXT);
    }
    fragTransaction.commit();
}

From source file:ca.rmen.android.networkmonitor.app.dialog.DialogFragmentFactory.java

/**
 * Show a visible dialog fragment with the given title and message, and an ok and cancel button. If the given activity implements
 *         {@link DialogButtonListener}, the actionId and extras parameter will be provided in
 *         the {@link DialogButtonListener#onOkClicked(int, Bundle)} callback on the activity, when the user clicks on the ok button.
 *///from   ww w . ja va 2  s .co m
public static void showConfirmDialog(FragmentActivity activity, String title, String message, int actionId,
        Bundle extras) {
    Log.v(TAG, "showConfirmDialog: title = " + title + ", message = " + message + ", actionId = " + actionId
            + ", extras = " + extras);
    ConfirmDialogFragment result = new ConfirmDialogFragment();
    Bundle arguments = new Bundle(4);
    arguments.putString(EXTRA_TITLE, title);
    arguments.putString(EXTRA_MESSAGE, message);
    arguments.putInt(EXTRA_ACTION_ID, actionId);
    if (extras != null)
        arguments.putBundle(EXTRA_EXTRAS, extras);
    result.setArguments(arguments);
    result.show(activity.getSupportFragmentManager(), ConfirmDialogFragment.class.getSimpleName());
}

From source file:ca.rmen.android.networkmonitor.app.dialog.DialogFragmentFactory.java

/**
 * Show a visible dialog fragment with the given title and list of items. If the given activity implements {@link DialogItemListener}, the
 *         actionId, list of items, and item selected by the user, will be provided in the
 *         {@link DialogItemListener#onItemSelected(int, CharSequence[], int)} callback on the activity, when the user selects an item.
 * @param selectedItem if greater than zero, then the given item at that index will be pre-selected in the list.
 *//* www.ja va 2 s  .c  om*/
public static void showChoiceDialog(FragmentActivity activity, String title, CharSequence[] items,
        int selectedItem, int actionId) {
    Log.v(TAG, "showChoiceDialog: title = " + title + ", actionId = " + actionId + ", items ="
            + Arrays.toString(items) + ", selectedItem = " + selectedItem);
    ChoiceDialogFragment result = new ChoiceDialogFragment();
    Bundle arguments = new Bundle(5);
    arguments.putString(EXTRA_TITLE, title);
    arguments.putInt(EXTRA_ACTION_ID, actionId);
    arguments.putCharSequenceArray(EXTRA_CHOICES, items);
    arguments.putInt(EXTRA_SELECTED_ITEM, selectedItem);
    result.setArguments(arguments);
    result.show(activity.getSupportFragmentManager(), ChoiceDialogFragment.class.getSimpleName());
}

From source file:ca.rmen.android.scrumchatter.dialog.DialogFragmentFactory.java

/**
 * Show a visible dialog fragment with the given title and list of items. If the given activity implements {@link DialogItemListener}, the
 *         actionId, list of items, and item selected by the user, will be provided in the
 *         {@link DialogItemListener#onItemSelected(int, CharSequence[], int)} callback on the activity, when the user selects an item.
 * @param selectedItem if greater than zero, then the given item at that index will be pre-selected in the list.
 *//*ww  w  . j a v  a 2  s. c  o m*/
public static void showChoiceDialog(FragmentActivity activity, String title, CharSequence[] items,
        int selectedItem, @SuppressWarnings("SameParameterValue") int actionId) {
    Log.v(TAG, "showChoiceDialog: title = " + title + ", actionId = " + actionId + ", items ="
            + Arrays.toString(items) + ", selectedItem = " + selectedItem);
    ChoiceDialogFragment result = new ChoiceDialogFragment();
    Bundle arguments = new Bundle(5);
    arguments.putString(EXTRA_TITLE, title);
    arguments.putInt(EXTRA_ACTION_ID, actionId);
    arguments.putCharSequenceArray(EXTRA_CHOICES, items);
    arguments.putInt(EXTRA_SELECTED_ITEM, selectedItem);
    result.setArguments(arguments);
    result.show(activity.getSupportFragmentManager(), ChoiceDialogFragment.class.getSimpleName());
}

From source file:org.adaway.helper.ImportExportHelper.java

/**
 * Opens file manager to open file and return it in onActivityResult in Activity
 *
 * @param activity/*from  www.j a v a 2s  . c  o m*/
 */
public static void openFileStream(final FragmentActivity activity) {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("text/plain");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {
        activity.startActivityForResult(intent, REQUEST_CODE_IMPORT);
    } catch (ActivityNotFoundException e) {
        ActivityNotFoundDialogFragment notFoundDialog = ActivityNotFoundDialogFragment.newInstance(
                R.string.no_file_manager_title, R.string.no_file_manager,
                "market://details?id=org.openintents.filemanager", "OI File Manager");

        notFoundDialog.show(activity.getSupportFragmentManager(), "notFoundDialog");
    }
}

From source file:com.scvngr.levelup.core.test.TestThreadingUtils.java

/**
 * Adds a fragment in a transaction synchronized in the main thread (tagged with the fragment's
 * class name)./*from ww w. j  a v a 2s . c o m*/
 *
 * @param instrumentation the test {@link Instrumentation}.
 * @param activity the {@link FragmentActivity} to add it to.
 * @param fragment Fragment to add.
 * @param inView adds the fragment to the view hierarchy if true.
 * @param tag the Fragment's tag (null tag will fail fast).
 */
public static void addFragmentInMainSync(@NonNull final Instrumentation instrumentation,
        @NonNull final FragmentActivity activity, @NonNull final Fragment fragment, final boolean inView,
        final String tag) {
    if (null == tag) {
        throw new AssertionError("Cannot add fragment with null tag");
    }

    runOnMainSync(instrumentation, activity, new Runnable() {
        @Override
        public void run() {
            if (!inView) {
                activity.getSupportFragmentManager().beginTransaction().add(fragment, tag).commit();
            } else {
                activity.getSupportFragmentManager().beginTransaction()
                        .add(R.id.levelup_activity_content, fragment, tag).commit();
            }

            activity.getSupportFragmentManager().executePendingTransactions();
        }
    });
}

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static Fragment getFocusedFragment(FragmentActivity activity) {
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus == null) {
        return null;
    }/*from   w  w  w . java 2 s  .c om*/
    ViewParent currentFocusParent = currentFocus.getParent();
    if (currentFocusParent == null) {
        return null;
    }
    List<Fragment> fragments = activity.getSupportFragmentManager().getFragments();
    for (Fragment f : fragments) {
        if (f == null) {
            continue;
        }
        ViewParent v = currentFocusParent;
        View fragmentView = f.getView();
        while (v != null) {
            if (v == fragmentView) {
                return f;
            }
            v = v.getParent();
        }
    }

    return null;
}

From source file:com.monmonja.library.utils.PlayServiceUtils.java

public static void rateAppDialog(FragmentActivity activity, int passByThenAlertCount, String alertTitle,
        String alertBody, String marketUri) {
    SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(activity.getApplicationContext());
    int rateAppBy = sharedPreferences.getInt(PREF_RATE_APP, 1);
    boolean rateAppByEnable = sharedPreferences.getBoolean(PREF_RATE_APP_ENABLE, true);

    if (rateAppByEnable) {
        if (rateAppBy % passByThenAlertCount == 0) {
            RateAppDialogFragment fragment = new RateAppDialogFragment();
            fragment.mAlertTitle = alertTitle;
            fragment.mAlertBody = alertBody;
            fragment.mMarketUri = marketUri;
            fragment.show(activity.getSupportFragmentManager(), RateAppDialogFragment.TAG);
        } else {/*from w ww  . j  av  a 2s  . c om*/
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putInt(PREF_RATE_APP, ++rateAppBy);
            editor.apply();
        }
    }

    SharedPreferences.Editor editor = sharedPreferences.edit();
    //        editor.putBoolean(PREF_RATE_APP_ENABLE, true); // debug mode
    editor.apply();
}

From source file:com.zapp.library.merchant.util.PBBAAppUtils.java

/**
 * Show the Pay by Bank app Error Popup. It closes any other Pay by Bank App popup currently open.
 *
 * @param activity     The activity to use.
 * @param errorCode    The error code to display (optional). The error code is appended to the error message in round brackets (e.g. if errorCode is "A12.3" then the
 *                     message displayed will be "Network error (A12.3)")
 * @param errorTitle   The error title to display (optional).
 * @param errorMessage The error message to display.
 * @param callback     The callback listener for the popup. The popup keeps {@link java.lang.ref.WeakReference} to the callback.
 * @see PBBAPopupCallback// w  ww  .j  a  v  a2s  . c  o  m
 * @see #showPBBAPopup(FragmentActivity, String, String, PBBAPopupCallback)
 * @see #dismissPBBAPopup(FragmentActivity)
 * @see #setPBBAPopupCallback(FragmentActivity, PBBAPopupCallback)
 */
@SuppressWarnings("ElementOnlyUsedFromTestCode")
public static void showPBBAErrorPopup(@NonNull final FragmentActivity activity, @Nullable String errorCode,
        @Nullable String errorTitle, @NonNull final String errorMessage,
        @NonNull final PBBAPopupCallback callback) {

    verifyActivity(activity);

    if (TextUtils.isEmpty(errorMessage)) {
        throw new IllegalArgumentException("errorMessage is required");
    }
    //noinspection ConstantConditions
    if (callback == null) {
        throw new IllegalArgumentException("callback == null");
    }

    final FragmentManager fragmentManager = activity.getSupportFragmentManager();

    final PBBAPopup fragment = (PBBAPopup) fragmentManager.findFragmentByTag(PBBAPopup.TAG);

    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    if (fragment != null) {
        transaction.remove(fragment);
    }
    final PBBAPopupErrorFragment newFragment = PBBAPopupErrorFragment.newInstance(errorCode, errorTitle,
            errorMessage);
    newFragment.setCallback(callback);

    transaction.add(newFragment, PBBAPopup.TAG).commit();
}

From source file:com.fastbootmobile.encore.utils.Utils.java

public static void showCurrentSongOverflow(final Context context, final View parent, final Song song,
        final boolean showArtist) {
    PopupMenu popupMenu = new PopupMenu(context, parent);
    popupMenu.inflate(R.menu.queue_overflow);
    if (song.getAlbum() == null) {
        Log.d(TAG, "No album information, removing album options");

        // This song has no album information, hide the entries
        Menu menu = popupMenu.getMenu();
        menu.removeItem(R.id.menu_add_album_to_queue);
        menu.removeItem(R.id.menu_open_album);
    }/*  w w w .ja v a  2  s  .  com*/

    if (!showArtist) {
        Menu menu = popupMenu.getMenu();
        menu.removeItem(R.id.menu_open_artist);
    }

    popupMenu.show();

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            final ProviderAggregator aggregator = ProviderAggregator.getDefault();

            switch (menuItem.getItemId()) {
            case R.id.menu_open_album:
                final Resources res = context.getResources();
                Intent intent = AlbumActivity.craftIntent(context,
                        ((BitmapDrawable) res.getDrawable(R.drawable.album_placeholder)).getBitmap(),
                        song.getAlbum(), song.getProvider(),
                        res.getColor(R.color.default_album_art_background));
                context.startActivity(intent);
                break;

            case R.id.menu_open_artist:
                intent = ArtistActivity.craftIntent(context, null, song.getArtist(), song.getProvider(),
                        context.getResources().getColor(R.color.default_album_art_background));
                context.startActivity(intent);
                break;

            case R.id.menu_add_album_to_queue:
                PlaybackProxy.queueAlbum(aggregator.retrieveAlbum(song.getAlbum(), song.getProvider()), false);
                Toast.makeText(context, R.string.toast_album_added_to_queue, Toast.LENGTH_SHORT).show();
                break;

            case R.id.menu_add_to_playlist:
                PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(song);
                if (context instanceof FragmentActivity) {
                    FragmentActivity act = (FragmentActivity) context;
                    fragment.show(act.getSupportFragmentManager(), song.getRef());
                } else {
                    throw new IllegalArgumentException("Context must be an instance of FragmentActivity");
                }
                break;

            default:
                return false;
            }
            return true;
        }
    });
}