List of usage examples for android.app Fragment getView
@Nullable
public View getView()
From source file:com.geecko.QuickLyric.MainActivity.java
private void selectItem(int position) { FragmentManager fragmentManager = getFragmentManager(); Fragment newFragment;/*from www.j a v a 2 s. c o 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.mail.ui.AbstractActivityController.java
/** * Check if the fragment is attached to an activity and has a root view. * @param in fragment to be checked/*from w w w .ja v a2 s . co m*/ * @return true if the fragment is valid, false otherwise */ private static boolean isValidFragment(Fragment in) { return !(in == null || in.getActivity() == null || in.getView() == null); }