android.support.v4.app.FragmentManager Java Examples

The following examples show how to use android.support.v4.app.FragmentManager. 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: RecyclerActivity.java    From AndroidSamples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_recycler);

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = new RecyFragment();
        fm.beginTransaction()
                .add(R.id.fragment_container, fragment)
                .commit();
    }

}
 
Example #2
Source File: AuthorisedArea_1.java    From owasp-workshop-android-pentest with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_authorised_area_1, container, false);

    ClickMe = (Button) rootView.findViewById(R.id.button);
    ClickMe.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
        mEdit = (EditText) getView().findViewById(R.id.editText_password);
        if(auth(sha1Hash(mEdit.getText().toString()))) {
            FragmentManager fm = getFragmentManager();
            AuthorisedArea_2 f = new AuthorisedArea_2();
            fm.beginTransaction().replace(R.id.main_content,f).commit();
        }
        }
    });
    return rootView;
}
 
Example #3
Source File: FavoritePagerAdapter.java    From Pasta-Music with Apache License 2.0 6 votes vote down vote up
public FavoritePagerAdapter(Activity activity, FragmentManager manager) {
    super(manager);
    this.activity = activity;
    pasta = (Pasta) activity.getApplicationContext();

    Bundle args = new Bundle();
    args.putBoolean("favorite", true);

    playlistFragment = new OmniFragment();
    playlistFragment.setArguments(args);

    albumFragment = new OmniFragment();
    albumFragment.setArguments(args);

    trackFragment = new OmniFragment();
    trackFragment.setArguments(args);

    artistFragment = new OmniFragment();
    artistFragment.setArguments(args);

    load();
}
 
Example #4
Source File: AuthorListFragment.java    From IslamicLibraryAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    if (item.getItemId() == R.id.action_rearrange) {

        if (mCurrentLayoutManagerType == GRID_LAYOUT_MANAGER) {
            setRecyclerViewLayoutManager(LINEAR_LAYOUT_MANAGER);
            item.setIcon(R.drawable.ic_view_stream_black_24dp);
        } else {//if mCurrentLayoutManagerType == LINEAR_LAYOUT_MANAGER
            setRecyclerViewLayoutManager(GRID_LAYOUT_MANAGER);
            item.setIcon(R.drawable.ic_view_module_black_24dp);
        }

        return true;
    } else if (item.getItemId() == R.id.action_sort) {
        SortListDialogFragment sortListDialogFragment = SortListDialogFragment.newInstance(R.array.author_list_sorting, mCurrentSortIndex);
        //see this answer http://stackoverflow.com/a/37794319/3061221
        FragmentManager fm = getChildFragmentManager();
        sortListDialogFragment.show(fm, "fragment_sort");
        return true;

    } else return super.onOptionsItemSelected(item);
}
 
Example #5
Source File: ArrayPagerAdapter.java    From cwac-pager with 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 #6
Source File: FragmentNavigationDrawer.java    From example with Apache License 2.0 6 votes vote down vote up
/**
 * Swaps fragments in the main content view
 */
public void selectDrawerItem(int position) {
    // Create a new fragment and specify the planet to show based on
    // position
    FragmentNavItem navItem = drawerNavItems.get(position);
    Fragment fragment = null;
    try {
        fragment = navItem.getFragmentClass().newInstance();
        Bundle args = navItem.getFragmentArgs();
        if (args != null) {
            fragment.setArguments(args);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Insert the fragment by replacing any existing fragment
    FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(drawerContainerRes, fragment).commit();

    // Highlight the selected item, update the title, and close the drawer
    lvDrawer.setItemChecked(position, true);
    setTitle(navItem.getTitle());
    closeDrawer(lvDrawer);
}
 
Example #7
Source File: ColumnListActivity.java    From likequanmintv with Apache License 2.0 6 votes vote down vote up
private void initView() {
    title=(TextView)findViewById(R.id.title);
    ivBack =(ImageView)findViewById(R.id.imgBack);
    ivBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    content=(FrameLayout)findViewById(R.id.content);

    ItemColumn itemColumn= (ItemColumn) getIntent().getSerializableExtra("itemColumn");
    title.setText(""+itemColumn.name);
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ts = fm.beginTransaction();
    Bundle bundle=new Bundle();
    String mUrl="json/categories/"+itemColumn.slug+"/list.json";
    bundle.putString("url",mUrl);
    bundle.putString("tag",itemColumn.name);
    if (itemColumn.slug.equals("love")){
        ts.replace(R.id.content, LoveLiveListFragment.newInstance(bundle));
    }else {
        ts.replace(R.id.content, BaseLiveWraperFragment.newInstance(bundle));
    }
    ts.commit();
}
 
Example #8
Source File: BaseMediaRouteDialogManager.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void openDialog() {
    if (mAndroidMediaRouter == null) {
        mDelegate.onDialogCancelled();
        return;
    }

    FragmentActivity currentActivity =
            (FragmentActivity) ApplicationStatus.getLastTrackedFocusedActivity();
    if (currentActivity == null)  {
        mDelegate.onDialogCancelled();
        return;
    }

    FragmentManager fm = currentActivity.getSupportFragmentManager();
    if (fm == null)  {
        mDelegate.onDialogCancelled();
        return;
    }

    mDialogFragment = openDialogInternal(fm);
    if (mDialogFragment == null)  {
        mDelegate.onDialogCancelled();
        return;
    }
}
 
Example #9
Source File: RemoteMediaPlayerController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void showMediaRouteDialog(MediaStateListener player, MediaRouteController controller,
        Activity activity) {

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

    MediaRouteDialogFactory factory = new MediaRouteChooserDialogFactory(player, controller,
            activity);

    if (fm.findFragmentByTag(
            "android.support.v7.mediarouter:MediaRouteChooserDialogFragment") != null) {
        Log.w(TAG, "showDialog(): Route chooser dialog already showing!");
        return;
    }
    MediaRouteChooserDialogFragment f = factory.onCreateChooserDialogFragment();

    f.setRouteSelector(controller.buildMediaRouteSelector());
    f.show(fm, "android.support.v7.mediarouter:MediaRouteChooserDialogFragment");
}
 
Example #10
Source File: TabsSwitcher.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Переключиться на скрытую (такие как "Новая вкладка", "Избранное", "История") вкладку
 * @param virtualPosition виртуальная позиция вкладки
 * (см. {@link TabModel#POSITION_NEWTAB}, {@link TabModel#POSITION_FAVORITES}, {@link TabModel#POSITION_HISTORY})
 * @param fragmentManager менеджер фрагментов
 */
public void switchTo(int virtualPosition, FragmentManager fragmentManager) {
    if (currentId != null && currentId.equals(Long.valueOf(virtualPosition))) return;
    Fragment newFragment = null;
    switch (virtualPosition) {
        case TabModel.POSITION_NEWTAB:
            newFragment = new NewTabFragment();
            break;
        case TabModel.POSITION_HISTORY:
            newFragment = new HistoryFragment();
            break;
        case TabModel.POSITION_FAVORITES:
            newFragment = new FavoritesFragment();
            break;
        default:
            newFragment = new NewTabFragment();
    }
    currentFragment = newFragment;
    currentId = (long) virtualPosition;
    replace(fragmentManager, newFragment);
}
 
Example #11
Source File: DoEditorActions.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
public static void doDraw(final Activity a, final EditText editText, final FragmentManager fm) {
    final Intent intent = new Intent(a, Draw.class);
    InputMethodManager imm = (InputMethodManager) editText.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    e = editText.getText();
    TedBottomPicker tedBottomPicker =
            new TedBottomPicker.Builder(editText.getContext()).setOnImageSelectedListener(
                    new TedBottomPicker.OnImageSelectedListener() {
                        @Override
                        public void onImageSelected(List<Uri> uri) {
                            Draw.uri = uri.get(0);
                            Fragment auxiliary = new AuxiliaryFragment();

                            sStart = editText.getSelectionStart();
                            sEnd = editText.getSelectionEnd();

                            fm.beginTransaction().add(auxiliary, "IMAGE_UPLOAD").commit();
                            fm.executePendingTransactions();

                            auxiliary.startActivityForResult(intent, 3333);
                        }
                    })
                    .setLayoutResource(R.layout.image_sheet_dialog)
                    .setTitle("Choose a photo")
                    .create();

    tedBottomPicker.show(fm);
}
 
Example #12
Source File: ShowMessageActivity.java    From xmpp with Apache License 2.0 5 votes vote down vote up
private void initialView() {
    FragmentManager manager = this.getSupportFragmentManager();
    if (manager != null) {
        adapter = new Adapter(manager);
        viewpager.setAdapter(adapter);
        layoutTab.setupWithViewPager(viewpager);
        layoutTab.setTabMode(TabLayout.MODE_FIXED);

    }

}
 
Example #13
Source File: ContactDetailPagerAdapter.java    From Rumble with GNU General Public License v3.0 5 votes vote down vote up
public ContactDetailPagerAdapter(FragmentManager fm, Bundle args) {
    super(fm);
    infoFragment = new FragmentContactInfo();
    infoFragment.setArguments(args);

    statusFragment  = new FragmentStatusList();
    args.putBoolean("noCoordinatorLayout",true);
    statusFragment.setArguments(args);
}
 
Example #14
Source File: ProfileActivity.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
public Fragment getFragment(int res, Class<? extends Fragment> fragmentClass) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(res + "_key");
    if (fragment == null) {
        fragment = Fragment.instantiate(this, fragmentClass.getCanonicalName());
    }
    return fragment;
}
 
Example #15
Source File: OptionDialogFragment.java    From RhymeMusic with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{

    switch ( position )
    {
        case PLAY_MODE:
            MusicApplication application =
                    (MusicApplication) getActivity().getApplication();
            MusicService.MusicBinder musicBinder = application.getMusicBinder();

            musicBinder.changePlayMode();
            break;

        case AUTO_STOP:
            getDialog().dismiss(); // 关闭父对话框

            DialogFragment dialogFragment = new ASDialogFragment();
            FragmentManager manager = getFragmentManager();
            dialogFragment.show(manager, "dialog auto stop");
            break;

        case AUDIO_INFO:
            getDialog().dismiss(); // 关闭父对话框

            DialogFragment dialogFragment1 = new AIDialogFragment();
            FragmentManager manager1 = getFragmentManager();
            dialogFragment1.show(manager1, "dialog audio info");
            break;

        case MORE_INFO:
            getDialog().dismiss(); // 关闭父对话框

            Toast.makeText(getActivity(), "暂未开发", Toast.LENGTH_SHORT).show();
            break;

        default:
            break;
    }
}
 
Example #16
Source File: PLauncher.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
private PRouterV4 getRouterFragmentV4(FragmentActivity activity) {
    PRouterV4 routerFragment = findRouterFragmentV4(activity);
    if (routerFragment == null) {
        routerFragment = PRouterV4.newInstance();
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        fragmentManager
                .beginTransaction()
                .add(routerFragment, TAG)
                .commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
    return routerFragment;
}
 
Example #17
Source File: FragmentHideShowSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_hide_show_support);

    // The content view embeds two fragments; now retrieve them and attach
    // their "hide" button.
    FragmentManager fm = getSupportFragmentManager();
    addShowHideListener(R.id.frag1hide, fm.findFragmentById(R.id.fragment1));
    addShowHideListener(R.id.frag2hide, fm.findFragmentById(R.id.fragment2));
}
 
Example #18
Source File: BaseDialog.java    From android-mvp-architecture with Apache License 2.0 5 votes vote down vote up
public void show(FragmentManager fragmentManager, String tag) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Fragment prevFragment = fragmentManager.findFragmentByTag(tag);
    if (prevFragment != null) {
        transaction.remove(prevFragment);
    }
    transaction.addToBackStack(null);
    show(transaction, tag);
}
 
Example #19
Source File: ErrorDialogManager.java    From KUtils-master with Apache License 2.0 5 votes vote down vote up
public static void attachTo(Activity activity, Object executionScope, boolean finishAfterDialog, Bundle argumentsForErrorDialog) {
    android.app.FragmentManager fm = activity.getFragmentManager();
    HoneycombManagerFragment fragment = (HoneycombManagerFragment) fm
            .findFragmentByTag(TAG_ERROR_DIALOG_MANAGER);
    if (fragment == null) {
        fragment = new HoneycombManagerFragment();
        fm.beginTransaction().add(fragment, TAG_ERROR_DIALOG_MANAGER).commit();
        fm.executePendingTransactions();
    }
    fragment.finishAfterDialog = finishAfterDialog;
    fragment.argumentsForErrorDialog = argumentsForErrorDialog;
    fragment.executionScope = executionScope;
}
 
Example #20
Source File: SingleFragmentActivity.java    From AndroidProgramming3e with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutResId());

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = createFragment();
        fm.beginTransaction()
                .add(R.id.fragment_container, fragment)
                .commit();
    }
}
 
Example #21
Source File: ClassifyFragment.java    From android-galaxyzoo with GNU General Public License v3.0 5 votes vote down vote up
public void update() {
    final Activity activity = getActivity();
    if (activity == null)
        return;


    if (TextUtils.equals(getItemId(), ItemsContentProvider.URI_PART_ITEM_ID_NEXT)) {
        /*
         * Initializes the CursorLoader. The LOADER_ID_NEXT_ID value is eventually passed
         * to onCreateLoader().
         * We use restartLoader(), instead of initLoader(),
         * so we can refresh this fragment to show a different subject,
         * even when using the same query ("next") to do that.
         *
         * However, we don't start another "next" request when one is already in progress,
         * because then we would waste the first one and slow both down.
         * This can happen during resume.
         */
        if(!mGetNextInProgress) {
            mGetNextInProgress = true;

            //Don't stay inverted after a previous classification.
            final FragmentManager fragmentManager = getChildFragmentManager();
            final SubjectFragment fragmentSubject = (SubjectFragment) fragmentManager.findFragmentById(R.id.child_fragment_subject);
            if (fragmentSubject != null) {
                fragmentSubject.setInverted(false);
            }

            //Get the actual ID and other details:
            getLoaderManager().restartLoader(LOADER_ID_NEXT_ID, null, getNextIdLoader);
        }
    } else {
        //Add, or update, the child fragments already, because we know the Item IDs:
        addOrUpdateChildFragments();
    }
}
 
Example #22
Source File: FragmentCompat.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
private static void start(FragmentManager fragmentManager, int containerId, Fragment from, Fragment to) {
    String toName = to.getClass().getName();
    FragmentTransaction ft = fragmentManager.beginTransaction();

    if (from == null) {
        ft.add(containerId, to, toName);
    } else {
        ft.add(containerId, to, toName);
        ft.hide(from);
    }

    //添加至回退站
    ft.addToBackStack(toName);
    ft.commit();
}
 
Example #23
Source File: MainPresenter.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Override public void onModuleChanged(@NonNull FragmentManager fragmentManager, @MainMvp.NavigationType int type) {
    Fragment currentVisible = getVisibleFragment(fragmentManager);
    DeviceAppsView deviceAppsView = (DeviceAppsView) getFragmentByTag(fragmentManager, DeviceAppsView.TAG);
    FoldersView foldersView = (FoldersView) getFragmentByTag(fragmentManager, FoldersView.TAG);
    SelectedAppsView selectedAppsView = (SelectedAppsView) getFragmentByTag(fragmentManager, SelectedAppsView.TAG);
    switch (type) {
        case MainMvp.DEVICE_APPS:
            if (deviceAppsView == null) {
                onAddAndHide(fragmentManager, DeviceAppsView.newInstance(), currentVisible);
            } else {
                onShowHideFragment(fragmentManager, deviceAppsView, currentVisible);
            }
            break;
        case MainMvp.FOLDERS:
            if (foldersView == null) {
                onAddAndHide(fragmentManager, FoldersView.newInstance(), currentVisible);
            } else {
                onShowHideFragment(fragmentManager, foldersView, currentVisible);
            }
            break;
        case MainMvp.SELECTED_APPS:
            if (selectedAppsView == null) {
                onAddAndHide(fragmentManager, SelectedAppsView.newInstance(), currentVisible);
            } else {
                onShowHideFragment(fragmentManager, selectedAppsView, currentVisible);
            }
            break;
    }
}
 
Example #24
Source File: LanguagesFragment.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
public static void showLanguageChooser(@NonNull FragmentManager fm) {
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(TAG);
    if (prev != null) {
        ft.remove(prev);
    }

    try {
        DialogFragment dialog = LanguagesFragment.newInstance();
        dialog.show(ft, TAG);
    } catch (IllegalArgumentException | IllegalStateException ignored) {}
}
 
Example #25
Source File: MainActivity.java    From aware with MIT License 5 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    FragmentManager fm = getSupportFragmentManager();
    for(int i = 0; i < fm.getBackStackEntryCount(); ++i) {
        fm.popBackStack();
    }

    Fragment fragment;
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragment = new Home();

    if (id == R.id.nav_home) {
        setTitle("Home");
        fragment = new Home();

    } else if (id == R.id.nav_news) {
        setTitle("News");
        fragment = new News();

    } else if (id == R.id.nav_maps) {
        setTitle("Maps");
        fragment = new Maps();

    } else if (id == R.id.nav_bulettin) {
        setTitle("Bulletin Board");
        fragment = new Bulletin();

    }

    fragmentManager.beginTransaction().replace(R.id.inc, fragment).commit();

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #26
Source File: SinglePaneActivity.java    From MongoExplorer with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
	FragmentManager fm = getSupportFragmentManager();

	if (fm.getBackStackEntryCount() > 0) {
		fm.popBackStack();
		return;
	}

	super.onBackPressed();
}
 
Example #27
Source File: MainActivity.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRouteNavigate(Route route)
{
       FragmentManager fm = getSupportFragmentManager();
       RouteStart routeStartDialog = new RouteStart(route);
       routeStartDialog.show(fm, "route_start");
}
 
Example #28
Source File: CallInFragment.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onPhoneListener(PhoneEvent event) {
    if (getActivity() != null) {
        try {
            FragmentManager fm = getActivity().getSupportFragmentManager();
            Field stateSaved = fm.getClass().getDeclaredField("mStateSaved");
            stateSaved.setAccessible(true);
            stateSaved.set(fm, false);
            //getActivity().getSupportFragmentManager().popBackStack();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example #29
Source File: ViewPagerAdapter.java    From budgetto with MIT License 4 votes vote down vote up
public ViewPagerAdapter(FragmentManager fm) {
    super(fm);
}
 
Example #30
Source File: WebPageAdapter.java    From Dainty with Apache License 2.0 4 votes vote down vote up
public WebPageAdapter(FragmentManager fm) {
    super(fm);
    //this.fm=fm;
}