Example usage for android.app FragmentTransaction show

List of usage examples for android.app FragmentTransaction show

Introduction

In this page you can find the example usage for android.app FragmentTransaction show.

Prototype

public abstract FragmentTransaction show(Fragment fragment);

Source Link

Document

Shows a previously hidden fragment.

Usage

From source file:com.zte.permissioncontrol.ui.PermissionControlPageActivity.java

protected void addUI() {
    Log.d(TAG, "addUI()");
    // must get a new transaction each time
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    // set empty view to gone
    mEmptyView.setVisibility(View.GONE);
    // add all the fragment
    mPermissionsFragment = (PermissionsFragment) getFragmentManager().findFragmentByTag(mPermissionsTag);
    mAppsFragment = (AppsFragment) getFragmentManager().findFragmentByTag(mAppsTag);

    if (mPermissionsFragment == null) {
        mPermissionsFragment = new PermissionsFragment();
        mAppsFragment = new AppsFragment();
        transaction.add(R.id.tab_pager, mPermissionsFragment, mPermissionsTag);
        transaction.add(R.id.tab_pager, mAppsFragment, mAppsTag);
    }/*ww w.  j a v a2s  .c  o  m*/
    transaction.show(mPermissionsFragment);
    transaction.show(mAppsFragment);

    transaction.commit();

    getFragmentManager().executePendingTransactions();
    // firstly remove tabs ,then add tabs and update it
    mActionBarAdapter.removeAllTab();
    mActionBarAdapter.addUpdateTab(mSavedInstanceState);
}

From source file:com.evandroid.musica.MainLyricActivity.java

private LyricsViewFragment init(FragmentManager fragmentManager, boolean startEmpty) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) fragmentManager
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment == null || lyricsViewFragment.isDetached())
        lyricsViewFragment = new LyricsViewFragment();
    lyricsViewFragment.startEmpty(startEmpty);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    if (!lyricsViewFragment.isAdded()) {
        fragmentTransaction.add(R.id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }//from   ww w .j  a  v a 2 s . c  o m

    Fragment[] activeFragments = getActiveFragments();
    displayedFragment = getDisplayedFragment(activeFragments);

    for (Fragment fragment : activeFragments)
        if (fragment != null) {
            if (fragment != displayedFragment && !fragment.isHidden()) {
                fragmentTransaction.hide(fragment);
                fragment.onHiddenChanged(true);
            } else if (fragment == displayedFragment)
                fragmentTransaction.show(fragment);
        }
    fragmentTransaction.commit();
    return lyricsViewFragment;
}

From source file:org.chromium.chrome.browser.bookmark.ManageBookmarkActivity.java

/**
 * Initializes the fragment state after a state restoration.
 * <p>//from  w  ww . j  a  va  2 s. c  o m
 * Reinitializes all of the event listeners on the fragments as they are not persisted across
 * activity recreation (and were referencing the old activity anyway).
 * <p>
 * The hidden state of the fragments are also not persisted across activity changes, so we need
 * to hide and show the fragments accordingly (since we know that hierarchy of the fragments
 * we can do this as a simple nested conditional).
 */
private void initializeFragmentState() {
    AddEditBookmarkFragment baseAddEditFragment = (AddEditBookmarkFragment) getFragmentManager()
            .findFragmentByTag(BASE_ADD_EDIT_FRAGMENT_TAG);
    setActionListenerOnAddEdit(baseAddEditFragment);

    Fragment selectFolderFragment = getFragmentManager().findFragmentByTag(BASE_SELECT_FOLDER_FRAGMENT_TAG);
    if (selectFolderFragment != null) {
        setActionListenerOnFolderSelection((SelectBookmarkFolderFragment) selectFolderFragment);

        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.hide(baseAddEditFragment);

        Fragment addFolderFragment = getFragmentManager().findFragmentByTag(ADD_FOLDER_FRAGMENT_TAG);
        if (addFolderFragment != null) {
            fragmentTransaction.hide(selectFolderFragment);
            setActionListenerOnAddEdit((AddEditBookmarkFragment) addFolderFragment);

            Fragment addFolderSelectFolderFragment = getFragmentManager()
                    .findFragmentByTag(ADD_FOLDER_SELECT_FOLDER_FRAGMENT_TAG);
            if (addFolderSelectFolderFragment != null) {
                setActionListenerOnFolderSelection(
                        (SelectBookmarkFolderFragment) addFolderSelectFolderFragment);
                fragmentTransaction.hide(addFolderFragment);
                fragmentTransaction.show(addFolderSelectFolderFragment);
            } else {
                fragmentTransaction.show(addFolderFragment);
            }
        } else {
            fragmentTransaction.show(selectFolderFragment);
        }
        fragmentTransaction.commit();
    }
}

From source file:am.project.x.business.main.MainActivity.java

private void setFragment(String tag) {
    final String oldTag = mCurrent;
    mCurrent = tag;/* w  w  w.j  a va  2 s.  c o m*/
    final FragmentManager manager = getFragmentManager();
    final FragmentTransaction transaction = manager.beginTransaction();
    if (!TextUtils.isEmpty(oldTag)) {
        final Fragment old = manager.findFragmentByTag(oldTag);
        if (old != null && old.isVisible()) {
            transaction.hide(old);
        }
    }
    Fragment target = manager.findFragmentByTag(tag);
    if (target != null && target.isVisible())
        return;
    if (target == null) {
        switch (tag) {
        default:
        case TAG_WIDGETS:
            target = WidgetsFragment.newInstance();
            break;
        case TAG_DRAWABLES:
            target = DrawablesFragment.newInstance();
            break;
        case TAG_OTHERS:
            target = OthersFragment.newInstance();
            break;
        case TAG_DEVELOP:
            target = DevelopFragment.newInstance();
            break;
        }
        transaction.add(mVContent.getId(), target, tag);
    }
    transaction.show(target);
    transaction.commit();
}

From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java

/**
 * Reappear panel after it has been hidden.
 *///from www. ja v a 2s.com
public void showPanel(SplitPanel p) {
    Log.d(LOG, "ReaderActivity.showPanel");

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
    fragmentTransaction.show(p);
    fragmentTransaction.commit();
}

From source file:com.geecko.QuickLyric.MainActivity.java

private void selectItem(int position) {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment newFragment;//w  w  w .  ja va2  s . co  m
    String tag;
    switch (position) {
    default:
        // Lyrics
        tag = LYRICS_FRAGMENT_TAG;
        newFragment = fragmentManager.findFragmentByTag(tag);
        if (newFragment == null || !(newFragment instanceof LyricsViewFragment))
            newFragment = new LyricsViewFragment();
        ((LyricsViewFragment) newFragment).showTransitionAnim = true;
        break;
    case 1:
        // Saved Lyrics
        tag = LOCAL_LYRICS_FRAGMENT_TAG;
        newFragment = fragmentManager.findFragmentByTag(tag);
        if (newFragment == null || !(newFragment instanceof LocalLyricsFragment))
            newFragment = new LocalLyricsFragment();
        ((LocalLyricsFragment) newFragment).showTransitionAnim = true;
        break;
    case 2:
        // Separator
        return;
    case 3:
        // Settings
        if (drawer instanceof DrawerLayout)
            ((DrawerLayout) drawer).closeDrawer(drawerView);
        drawer.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
                startActivityForResult(settingsIntent, 77);
            }
        }, 250);
        return;
    case 4:
        // Feedback
        return;
    case 5:
        // About Dialog
        if (drawer instanceof DrawerLayout)
            ((DrawerLayout) drawer).closeDrawer(drawerView);
        drawer.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class);
                startActivityForResult(aboutIntent, 77);
            }
        }, 250);
        return;
    }

    final Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    prepareAnimations(activeFragment);

    // Insert the fragment by replacing any existing fragment
    if (newFragment != activeFragment) {
        if (mActionMode != null)
            mActionMode.finish();
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.setCustomAnimations(R.animator.slide_in_start, R.animator.slide_out_start,
                R.animator.slide_in_start, R.animator.slide_out_start);
        fragmentTransaction.hide(activeFragment);
        if (newFragment.isAdded())
            fragmentTransaction.show(newFragment);
        else
            fragmentTransaction.add(id.main_fragment_container, newFragment, tag);
        ((CollapsingToolbarLayout) findViewById(R.id.toolbar_layout)).setCollapsedTitleTextColor(Color.WHITE);
        fragmentTransaction.commit();

        if (activeFragment instanceof LyricsViewFragment || newFragment instanceof LyricsViewFragment) {
            final Fragment newFragmentCopy = newFragment;
            activeFragment.getView().postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (activeFragment instanceof LyricsViewFragment) {
                        expandToolbar(false);
                        showRefreshFab(false);
                    } else if (newFragmentCopy instanceof LyricsViewFragment) {
                        expandToolbar(true);
                        showRefreshFab(true);
                    }
                }
            }, getResources().getInteger(android.R.integer.config_longAnimTime));
        }
    }
    if (drawer instanceof DrawerLayout && (newFragment == activeFragment))
        ((DrawerLayout) drawer).closeDrawer(drawerView);
}

From source file:com.android.contacts.activities.DialtactsActivity.java

/**
 * Hides every tab and shows search UI for phone lookup.
 *///from   w ww . j  a va  2  s. com
private void enterSearchUi() {
    if (mSearchFragment == null) {
        // We add the search fragment dynamically in the first onLayoutChange() and
        // mSearchFragment is set sometime later when the fragment transaction is actually
        // executed, which means there's a window when users are able to hit the (physical)
        // search key but mSearchFragment is still null.
        // It's quite hard to handle this case right, so let's just ignore the search key
        // in this case.  Users can just hit it again and it will work this time.
        return;
    }
    if (mSearchView == null) {
        prepareSearchView();
    }

    final ActionBar actionBar = getActionBar();

    final Tab tab = actionBar.getSelectedTab();

    // User can search during the call, but we don't want to remember the status.
    if (tab != null && !DialpadFragment.phoneIsInUse()) {
        mLastManuallySelectedFragment = tab.getPosition();
    }

    mSearchView.setQuery(null, true);

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    updateFakeMenuButtonsVisibility(false);

    for (int i = 0; i < TAB_INDEX_COUNT; i++) {
        sendFragmentVisibilityChange(i, false /* not visible */ );
    }

    // Show the search fragment and hide everything else.
    mSearchFragment.setUserVisibleHint(true);
    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.show(mSearchFragment);
    transaction.commitAllowingStateLoss();
    mViewPager.setVisibility(View.GONE);

    // We need to call this and onActionViewCollapsed() manually, since we are using a custom
    // layout instead of asking the search menu item to take care of SearchView.
    mSearchView.onActionViewExpanded();
    mInSearchUi = true;
}

From source file:com.ppgllrd.alfil.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d("ppgllrd", "onCreate: " + savedInstanceState);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_double);

    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ListView drawerList = (ListView) findViewById(R.id.drawer_list);

    Course[] courses = Course.getCourses();
    String currentYear = "";
    drawerItems = new ArrayList<DrawerItem>();
    for (Course course : courses) {
        if (course.getYear().compareTo(currentYear) != 0) {
            currentYear = course.getYear();
            drawerItems.add(new DrawerSection(currentYear));
        }//  ww  w.  ja  va 2  s.  c o  m
        drawerItems.add(new DrawerCourse(course));
    }

    // set up the drawer's list view with items and click listener
    drawerList.setAdapter(new DrawerAdapter(this, R.layout.drawer_course_item, drawerItems));

    drawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    actionBarTitleController = new ActionBarTitleController(this, /* host Activity */
            drawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    );

    FragmentManager fm = getFragmentManager();

    drawerSelectedIdx = 1; // start by selecting first course
    if (fm.findFragmentByTag(StudentsListFragment.FragmentTag) == null) {
        DrawerCourse drawerCourse = (DrawerCourse) drawerItems.get(drawerSelectedIdx);
        studentsListFragment = new StudentsListFragment();
        Bundle args = new Bundle();
        args.putParcelable(StudentsListFragment.ARG_GROUP_STUDENTS_COURSE, drawerCourse.getCourse());
        studentsListFragment.setArguments(args);

        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.list_Fragment_Placeholder, studentsListFragment, StudentsListFragment.FragmentTag);
        ft.commit();
    } else {
        studentsListFragment = (StudentsListFragment) getFragmentManager()
                .findFragmentByTag(StudentsListFragment.FragmentTag);
    }

    if (fm.findFragmentByTag(StudentInfoFragment.FragmentTag) == null) {
        studentInfoFragment = new StudentInfoFragment();
        Bundle args = new Bundle();
        args.putParcelable(StudentInfoFragment.ARG_STUDENT,
                new Student(((DrawerCourse) drawerItems.get(drawerSelectedIdx)).getCourse()));
        studentInfoFragment.setArguments(args);

        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.info_Fragment_Placeholder, studentInfoFragment, StudentInfoFragment.FragmentTag);
        ft.commit();
    } else {
        studentInfoFragment = (StudentInfoFragment) getFragmentManager()
                .findFragmentByTag(StudentInfoFragment.FragmentTag);
    }

    FragmentTransaction ft = fm.beginTransaction();
    ft.hide(studentInfoFragment);
    ft.show(studentsListFragment);
    //ft.addToBackStack(null);
    ft.commit();

    // ActivitySwipeDetector activitySwipeDetector = new ActivitySwipeDetector(this);
    // DrawerLayout lowestLayout = (DrawerLayout)this.findViewById(R.id.drawer_layout);
    // lowestLayout.setOnTouchListener(activitySwipeDetector);

}

From source file:com.example.android.touroflondon.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    //Verify that Google Play Services is available
    int playStatus = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    if (playStatus != ConnectionResult.SUCCESS) {
        // Google Play services is not available, prompt user and close application when dialog is dismissed
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(playStatus, this, 0);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override/*w  w w .  j ava 2s  .c o m*/
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        dialog.show();

        // Hide all active fragments
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.hide(mMapFragment);
        if (mPoiListFragment != null) {
            ft.hide(mPoiListFragment);
        }
        ft.commit();

    } else {

        // Getting reference to the SupportMapFragment of activity_main.xml
        TourMapFragment fm = (TourMapFragment) getFragmentManager().findFragmentById(R.id.fragment_map);

        // Getting GoogleMap object from the fragment
        googleMap = fm.getMap();

        // Enabling MyLocation Layer of Google Map
        googleMap.setMyLocationEnabled(true);

        // Getting LocationManager object from System Service LOCATION_SERVICE
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 0, mMapFragment);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 20000, 0, mMapFragment);
        //            Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        // Make sure active fragments are shown when returning from Play Services dialog interaction
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.show(mMapFragment);
        if (mPoiListFragment != null) {
            ft.show(mPoiListFragment);
        }
        ft.commit();

    }

}

From source file:com.android.dialer.DialtactsActivity.java

/**
 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
 * @see #onDialpadShown/*from  w w  w .j  a  v a 2  s . c  o  m*/
 */
private void showDialpadFragment(boolean animate) {
    if (mIsDialpadShown || mStateSaved) {
        return;
    }
    mIsDialpadShown = true;

    mListsFragment.setUserVisibleHint(false);

    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    if (mDialpadFragment == null) {
        mDialpadFragment = new DialpadFragment();
        ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
    } else {
        ft.show(mDialpadFragment);
    }

    mDialpadFragment.setAnimate(animate);
    Logger.logScreenView(ScreenEvent.DIALPAD, this);
    ft.commit();

    if (animate) {
        mFloatingActionButtonController.scaleOut();
    } else {
        mFloatingActionButtonController.setVisible(false);
        maybeEnterSearchUi();
    }
    mActionBarController.onDialpadUp();

    mListsFragment.getView().animate().alpha(0).withLayer();

    //adjust the title, so the user will know where we're at when the activity start/resumes.
    setTitle(R.string.launcherDialpadActivityLabel);
}