Example usage for android.app FragmentTransaction hide

List of usage examples for android.app FragmentTransaction hide

Introduction

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

Prototype

public abstract FragmentTransaction hide(Fragment fragment);

Source Link

Document

Hides an existing fragment.

Usage

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

/**
 * Finishes hiding the dialpad fragment after any animations are completed.
 *//*  www  . j av  a 2 s. co m*/
private void commitDialpadFragmentHide() {
    if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
        final FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.hide(mDialpadFragment);
        ft.commit();
    }
    mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
}

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

@Override
public void onAttachFragment(Fragment fragment) {
    if (fragment instanceof DialpadFragment) {
        mDialpadFragment = (DialpadFragment) fragment;
        if (!mIsDialpadShown && !mShowDialpadOnResume) {
            final FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.hide(mDialpadFragment);
            transaction.commit();//w w w  .ja v  a 2  s . c  om
        }
    } else if (fragment instanceof SmartDialSearchFragment) {
        mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
        mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
        if (!TextUtils.isEmpty(mDialpadQuery)) {
            mSmartDialSearchFragment.setAddToContactNumber(mDialpadQuery);
        }
    } else if (fragment instanceof SearchFragment) {
        mRegularSearchFragment = (RegularSearchFragment) fragment;
        mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
    } else if (fragment instanceof ListsFragment) {
        mListsFragment = (ListsFragment) fragment;
        mListsFragment.addOnPageChangeListener(this);
    }
}

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

/**
 * Add search fragment.  Note this is called during onLayout, so there's some restrictions,
 * such as executePendingTransaction can't be used in it.
 *///  www. j a va  2 s .c  om
private void addSearchFragment() {
    // In order to take full advantage of "fragment deferred start", we need to create the
    // search fragment after all other fragments are created.
    // The other fragments are created by the ViewPager on the first onMeasure().
    // We use the first onLayout call, which is after onMeasure().

    // Just return if the fragment is already created, which happens after configuration
    // changes.
    if (mSearchFragment != null)
        return;

    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment searchFragment = new PhoneNumberPickerFragment();

    searchFragment.setUserVisibleHint(false);
    ft.add(R.id.dialtacts_frame, searchFragment);
    ft.hide(searchFragment);
    ft.commitAllowingStateLoss();
}

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));
        }/*from w  w w.ja  va2 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.evandroid.musica.MainLyricActivity.java

public void updateLyricsFragment(int outAnim, int inAnim, boolean transition, Lyrics lyrics) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager()
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(inAnim, outAnim, inAnim, outAnim);
    Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    if (lyricsViewFragment != null && lyricsViewFragment.getView() != null) {
        SharedPreferences preferences = getSharedPreferences("current_music", Context.MODE_PRIVATE);
        String artist = preferences.getString("artist", null);
        String track = preferences.getString("track", null);
        if (lyrics.isLRC()
                && !(lyrics.getOriginalArtist().equals(artist) && lyrics.getOriginalTrack().equals(track))) {
            LrcView parser = new LrcView(this, null);
            parser.setOriginalLyrics(lyrics);
            parser.setSourceLrc(lyrics.getText());
            lyrics = parser.getStaticLyrics();
        }//  w  ww.java 2 s .  c  o m
        lyricsViewFragment.update(lyrics, lyricsViewFragment.getView(), true);
        if (transition) {
            fragmentTransaction.hide(activeFragment).show(lyricsViewFragment);
            prepareAnimations(activeFragment);
            prepareAnimations(lyricsViewFragment);
        }
    } else {
        Bundle lyricsBundle = new Bundle();
        try {
            lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);
        if (!(activeFragment instanceof LyricsViewFragment) && activeFragment != null)
            fragmentTransaction.hide(activeFragment).add(R.id.main_fragment_container, lyricsViewFragment,
                    LYRICS_FRAGMENT_TAG);
        else
            fragmentTransaction.replace(R.id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }
    fragmentTransaction.commitAllowingStateLoss();
}

From source file:com.geecko.QuickLyric.MainActivity.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();
    fragmentTransaction.setCustomAnimations(R.animator.slide_in_end, R.animator.slide_out_start,
            R.animator.slide_in_start, R.animator.slide_out_end);
    if (!lyricsViewFragment.isAdded()) {
        fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }//from   w w w . j a  v a2s .  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.iota.wallet.ui.activity.MainActivity.java

/**
 * Shows a fragment and hides the old one if there was a fragment previously visible
 *//*from  ww w. j a v a2s  . co  m*/
private void showFragment(Fragment fragment, boolean addToBackStack, boolean killFragments) {

    if (fragment == null) {
        // Do nothing
        return;
    }

    FragmentManager fragmentManager = getFragmentManager();
    Fragment currentFragment = fragmentManager.findFragmentByTag(currentFragmentTag);

    if (currentFragment != null && currentFragment.getClass().getName().equals(fragment.getClass().getName())) {
        // Fragment already shown, do nothing
        return;
    }

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();

    if (killFragments) {
        Class[] fragmentsToKill = { AboutFragment.class, GenerateQRCodeFragment.class, NeighborsFragment.class,
                NodeInfoFragment.class, PasswordLoginFragment.class, QRScannerFragment.class,
                SeedLoginFragment.class, SettingsFragment.class, TangleExplorerTabFragment.class,
                NewTransferFragment.class, WalletAddressesFragment.class, WalletTabFragment.class,
                WalletTransfersFragment.class };
        for (Class fragmentClass : fragmentsToKill) {
            String tag = fragmentClass.getSimpleName();
            if (tag.equals(fragment.getClass().getSimpleName())) {
                continue;
            }
            Fragment fragmentToKill = fragmentManager.findFragmentByTag(tag);
            if (fragmentToKill != null) {
                fragmentTransaction.remove(fragmentToKill);
            }
        }
    }

    fragmentTransaction.setCustomAnimations(R.animator.fade_in, R.animator.fade_out, R.animator.fade_in,
            R.animator.fade_out);

    if (currentFragment != null) {
        // Hide old fragment
        fragmentTransaction.hide(currentFragment);
    }

    String tag = fragment.getClass().getSimpleName();
    Fragment cachedFragment = fragmentManager.findFragmentByTag(tag);
    if (cachedFragment != null) {
        // Cached fragment available
        fragmentTransaction.show(cachedFragment);
    } else {
        fragmentTransaction.add(FRAGMENT_CONTAINER_ID, fragment, tag);
    }
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(null);
    }
    fragmentTransaction.commit();

    if (fragment instanceof OnBackPressedClickListener) {
        onBackPressedClickListener = (OnBackPressedClickListener) fragment;
    } else
        onBackPressedClickListener = null;

    // setChecked if open from WalletItemDialog
    if (fragment instanceof TangleExplorerTabFragment)
        navigationView.getMenu().findItem(R.id.nav_tangle_explorer).setChecked(true);

    currentFragmentTag = tag;
}

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

public void updateLyricsFragment(int outAnim, int inAnim, boolean transition, Lyrics lyrics) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager()
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(inAnim, outAnim, inAnim, outAnim);
    Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    if (lyricsViewFragment != null && lyricsViewFragment.getView() != null) {
        SharedPreferences preferences = getSharedPreferences("current_music", Context.MODE_PRIVATE);
        String artist = preferences.getString("artist", null);
        String track = preferences.getString("track", null);
        if (lyrics.isLRC()
                && !(lyrics.getOriginalArtist().equals(artist) && lyrics.getOriginalTrack().equals(track))) {
            LrcView parser = new LrcView(this, null);
            parser.setOriginalLyrics(lyrics);
            parser.setSourceLrc(lyrics.getText());
            lyrics = parser.getStaticLyrics();
        }//w w w  .j a va 2  s  .c o m
        lyricsViewFragment.update(lyrics, lyricsViewFragment.getView(), true);
        if (transition) {
            fragmentTransaction.hide(activeFragment).show(lyricsViewFragment);
            prepareAnimations(activeFragment);
            prepareAnimations(lyricsViewFragment);
        }
        showRefreshFab(true);
        lyricsViewFragment.expandToolbar();
    } else {
        Bundle lyricsBundle = new Bundle();
        try {
            lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);
        if (!(activeFragment instanceof LyricsViewFragment) && activeFragment != null)
            fragmentTransaction.hide(activeFragment).add(id.main_fragment_container, lyricsViewFragment,
                    LYRICS_FRAGMENT_TAG);
        else
            fragmentTransaction.replace(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }
    fragmentTransaction.commitAllowingStateLoss();
}

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

/**
 * Finishes hiding the dialpad fragment after any animations are completed.
 *//*from www . jav a 2 s.c  o m*/
private void commitDialpadFragmentHide() {
    if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
        final FragmentTransaction ft = getChildFragmentManager().beginTransaction();
        ft.hide(mDialpadFragment);
        ft.commit();
    }
    mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);

}

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

@Override
public void onListFragmentScrollStateChange(int scrollState) {
    if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
        Log.e(TAG, "onListFragmentScrollStateChange");
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
        transaction.hide(mCalllogList);
        transaction.commitAllowingStateLoss();
        hideDialpadFragment(true, false);
        DialerUtils.hideInputMethod(mParentLayout);
    }/*from  www  .j  a  va2s .c o  m*/
}