Java Code Examples for android.support.v7.app.AppCompatActivity#getSupportFragmentManager()

The following examples show how to use android.support.v7.app.AppCompatActivity#getSupportFragmentManager() . 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: BelvedereUi.java    From belvedere with Apache License 2.0 6 votes vote down vote up
/**
 * Install the ImageStream to an {@link AppCompatActivity}
 *
 * @param activity the activity that will show the ImageStream
 * @return an {@link ImageStream}
 */
public static ImageStream install(@NonNull AppCompatActivity activity) {
    final FragmentManager supportFragmentManager = activity.getSupportFragmentManager();
    final Fragment fragment = supportFragmentManager.findFragmentByTag(FRAGMENT_TAG_POPUP);

    final ImageStream popupBackend;
    if(fragment instanceof ImageStream) {
        popupBackend = (ImageStream) fragment;
    } else {
        popupBackend = new ImageStream();
        supportFragmentManager
                .beginTransaction()
                .add(popupBackend, FRAGMENT_TAG_POPUP)
                .commitNow();
    }

    popupBackend.setKeyboardHelper(KeyboardHelper.inject(activity));
    return popupBackend;
}
 
Example 2
Source File: DialogHelper.java    From HeartbeatFixerForGCM with Apache License 2.0 6 votes vote down vote up
private static void showDialog(@NonNull AppCompatActivity activity,
                               @NonNull DialogFragment fragment,
                               @NonNull String tag) {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        throw new RuntimeException("Should be called on the main thread");
    }

    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(tag);
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    fragment.show(ft, tag);
}
 
Example 3
Source File: TimerViewHolder.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
public TimerViewHolder(ViewGroup parent, OnListItemInteractionListener<Timer> listener,
                       AsyncTimersTableUpdateHandler asyncTimersTableUpdateHandler) {
    super(parent, R.layout.item_timer, listener);
    Log.d(TAG, "New TimerViewHolder");
    mAsyncTimersTableUpdateHandler = asyncTimersTableUpdateHandler;
    mStartIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_start_24dp);
    mPauseIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_pause_24dp);

    // TODO: This is bad! Use a Controller/Presenter instead...
    // or simply pass in an instance of FragmentManager to the ctor.
    AppCompatActivity act = (AppCompatActivity) getContext();
    mAddLabelDialogController = new AddLabelDialogController(
            act.getSupportFragmentManager(),
            new AddLabelDialog.OnLabelSetListener() {
                @Override
                public void onLabelSet(String label) {
                    mController.updateLabel(label);
                }
            });

    // The item layout is inflated in the super ctor, so we can safely reference our views.
    mPopupMenu = new PopupMenu(getContext(), mMenuButton);
    mPopupMenu.inflate(R.menu.menu_timer_viewholder);
    mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_delete:
                    mController.deleteTimer();
                    return true;
            }
            return false;
        }
    });
}
 
Example 4
Source File: MeunIView.java    From MeiZiNews with MIT License 5 votes vote down vote up
private void initViewPager(AppCompatActivity appCompatActivity) {
    baseFragmentPagerAdapter = new BaseFragmentPagerAdapter<>(
            appCompatActivity.getSupportFragmentManager(),
            fragments,
            titles
    );
    viewpager.setAdapter(baseFragmentPagerAdapter);
}
 
Example 5
Source File: Helpers.java    From Muzesto with GNU General Public License v3.0 5 votes vote down vote up
public static void showAbout(AppCompatActivity activity) {
    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_about");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    new AboutDialog().show(ft, "dialog_about");
}
 
Example 6
Source File: ChangeLogDialogFragment.java    From openwebnet-android with MIT License 5 votes vote down vote up
public static void show(AppCompatActivity activity) {
    DialogFragment dialogFragment = new ChangeLogDialogFragment();
    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(TAG_FRAGMENT);
    if (prev != null) {
        ft.remove(prev);
    }
    dialogFragment.show(ft, TAG_FRAGMENT);
}
 
Example 7
Source File: BaseLoginShare.java    From LoginSharePay with Apache License 2.0 5 votes vote down vote up
private void removeFragment(AppCompatActivity activity) {
    ProxyFragment proxyFragment = findFragment(activity);
    boolean isNewInstance = proxyFragment == null;
    if (!isNewInstance) {
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.remove(proxyFragment).commitAllowingStateLoss();
    }
}
 
Example 8
Source File: FragmentHelper.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void replace(AppCompatActivity activity,
                            Fragment fragment,
                            @IdRes int containerId,
                            boolean backStack) {
    if (activity.isFinishing()) return;
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    setCustomAnimations(transaction);
    if (backStack) transaction.addToBackStack(null);
    transaction.replace(containerId, fragment).commit();
}
 
Example 9
Source File: FragmentHelper.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void replace(AppCompatActivity activity,
                           Fragment fragment,
                           @IdRes int containerId,
                           String tag) {
    if (activity.isFinishing()) return;
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    setCustomAnimations(transaction);
    transaction.replace(containerId, fragment, tag).commit();
}
 
Example 10
Source File: ThemedRingtonePreference.java    From ClockPlus with GNU General Public License v3.0 4 votes vote down vote up
private RingtonePickerDialogController newController() {
    // TODO: BAD!
    AppCompatActivity a = (AppCompatActivity) getContext();
    return new RingtonePickerDialogController(a.getSupportFragmentManager(), this);
}
 
Example 11
Source File: SearchableListFragment.java    From SteamGifts with MIT License 4 votes vote down vote up
protected void startSearch(String query) {
    Log.d(TAG, "Starting Search for " + query);

    AppCompatActivity activity = ((AppCompatActivity) getActivity());
    FragmentManager fragmentManager = activity.getSupportFragmentManager();

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.fragment_container, newSearchingInstance(query), CommonActivity.FRAGMENT_TAG);
    transaction.addToBackStack(TAG);
    transaction.commit();
}
 
Example 12
Source File: ActivityModule.java    From android-mvp-architecture with Apache License 2.0 4 votes vote down vote up
@Provides
FeedPagerAdapter provideFeedPagerAdapter(AppCompatActivity activity) {
    return new FeedPagerAdapter(activity.getSupportFragmentManager());
}
 
Example 13
Source File: ViewPagerAdapter.java    From android-periodic-table with GNU General Public License v3.0 4 votes vote down vote up
public ViewPagerAdapter(AppCompatActivity activity) {
    super(activity.getSupportFragmentManager());

    mContext = activity;
}
 
Example 14
Source File: ExoPlayerVideoModule.java    From v9porn with MIT License 4 votes vote down vote up
@Provides
static FragmentManager providesSupportFragmentManager(AppCompatActivity mAppCompatActivity) {
    return mAppCompatActivity.getSupportFragmentManager();
}
 
Example 15
Source File: MaterialTwoStepsLogin.java    From unipiazza-android-twostepslogin with Apache License 2.0 4 votes vote down vote up
public void setActivity(AppCompatActivity activity) {
    fm = activity.getSupportFragmentManager();
    fm.beginTransaction().replace(R.id.fragmentView, firstStepFragment)
            .commit();
}
 
Example 16
Source File: TabManager.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public TabManager(AppCompatActivity activity, TabListener listener) {
    fragmentManager = activity.getSupportFragmentManager();
    tabListener = listener;
    updateFragmentList();
}
 
Example 17
Source File: JiaoZiVideoPlayerModule.java    From v9porn with MIT License 4 votes vote down vote up
@Provides
static FragmentManager providesSupportFragmentManager(AppCompatActivity mAppCompatActivity) {
    return mAppCompatActivity.getSupportFragmentManager();
}
 
Example 18
Source File: FragmentStackManager.java    From Anecdote with Apache License 2.0 4 votes vote down vote up
/**
 * Change tu current displayed fragment by a new one.
 *
 * @param frag            the new fragment to display
 * @param saveInBackstack if we want the fragment to be in backstack
 * @param animate         if we want a nice animation or not
 * @param sharedView      the shared view for the transition
 * @param sharedName      the shared name of the transition
 */
public void changeFragment(
                            AppCompatActivity activity,
                            Fragment frag,
                            boolean saveInBackstack,
                            boolean animate,
                            @Nullable View sharedView,
                            @Nullable String sharedName) {
    String log = "changeFragment: ";
    String backStateName = ((Object) frag).getClass().getName();

    if (frag instanceof AnecdoteFragment) {
        backStateName += frag.getArguments().getString(AnecdoteFragment.ARGS_WEBSITE_PAGE_SLUG);
    }

    try {
        android.support.v4.app.FragmentManager manager = activity.getSupportFragmentManager();
        boolean fragmentPopped = manager.popBackStackImmediate(backStateName, 0);

        if (!fragmentPopped && manager.findFragmentByTag(backStateName) == null) { //fragment not in back stack, create it.
            FragmentTransaction transaction = manager.beginTransaction();

            if (animate) {
                log += " animate";
                transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right);
            }
            if (sharedView != null && !TextUtils.isEmpty(sharedName)) {
                ViewCompat.setTransitionName(sharedView, sharedName);
                transaction.addSharedElement(sharedView, sharedName);
            }

            transaction.replace(R.id.fragment_container, frag, backStateName);

            if (saveInBackstack) {
                log += " addToBackTack(" + backStateName + ")";
                transaction.addToBackStack(backStateName);
            } else {
                log += " NO addToBackTack(" + backStateName + ")";
            }

            transaction.commit();

            // If some snackbar is display, hide it
            if (mSnackbar != null && mSnackbar.isShownOrQueued()) {
                mSnackbar.dismiss();
            }

        } else if (!fragmentPopped && manager.findFragmentByTag(backStateName) != null) {
            log += " fragment not popped but finded: " + backStateName;
        } else {
            log += " nothing to do : " + backStateName + " fragmentPopped: " + fragmentPopped;
            // custom effect if fragment is already instanciated
        }
        Log.d(TAG, log);
    } catch (IllegalStateException exception) {
        Log.w(TAG, "Unable to commit fragment, could be activity as been killed in background. " + exception.toString());
    }
}
 
Example 19
Source File: BaseAlarmViewHolder.java    From ClockPlus with GNU General Public License v3.0 4 votes vote down vote up
public BaseAlarmViewHolder(ViewGroup parent, @LayoutRes int layoutRes,
                               OnListItemInteractionListener<Alarm> listener,
                               AlarmController controller) {
        super(parent, layoutRes, listener);
        mAlarmController = controller;
        // Because of VH binding, setting drawable resources on views would be bad for performance.
        // Instead, we create and cache the Drawables once.
        mDismissNowDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_dismiss_alarm_24dp);
        mCancelSnoozeDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_cancel_snooze);

        // TODO: This is bad! Use a Controller/Presenter instead...
        // or simply pass in an instance of FragmentManager to the ctor.
        AppCompatActivity act = (AppCompatActivity) getContext();
        mFragmentManager = act.getSupportFragmentManager();
        mAddLabelDialogController = new AddLabelDialogController(mFragmentManager,
            new AddLabelDialog.OnLabelSetListener() {
                @Override
                public void onLabelSet(String label) {
                    final Alarm oldAlarm = getAlarm();
                    Alarm newAlarm = oldAlarm.toBuilder()
                            .label(label)
                            .build();
                    oldAlarm.copyMutableFieldsTo(newAlarm);
                    persistUpdatedAlarm(newAlarm, false);
                }
            }
        );
        mTimePickerDialogController = new TimePickerDialogController(mFragmentManager, getContext(),
            new OnTimeSetListener() {
                @Override
                public void onTimeSet(ViewGroup viewGroup, int hourOfDay, int minute) {
                    final Alarm oldAlarm = getAlarm();
                    // I don't think we need this; scheduling a new alarm that is considered
                    // equal to a previous alarm will overwrite the previous alarm.
//                        mAlarmController.cancelAlarm(oldAlarm, false);
                    Alarm newAlarm = oldAlarm.toBuilder()
                            .hour(hourOfDay)
                            .minutes(minute)
                            .build();
                    oldAlarm.copyMutableFieldsTo(newAlarm);
                    // -------------------------------------------
                    // TOneverDO: precede copyMutableFieldsTo()
                    newAlarm.setEnabled(true); // Always enabled, esp. if oldAlarm is not enabled
                    // ----------------------------------------------
                    persistUpdatedAlarm(newAlarm, true);
                }
            }
        );
    }
 
Example 20
Source File: FragmentAdapter.java    From SteamGifts with MIT License 4 votes vote down vote up
public FragmentAdapter(AppCompatActivity activity, ViewPager viewPager, Fragment... fragments) {
    super(activity.getSupportFragmentManager());
    this.activity = activity;
    this.viewPager = viewPager;
    this.fragments.addAll(Arrays.asList(fragments));
}