List of usage examples for android.app FragmentManager findFragmentById
public abstract Fragment findFragmentById(int id);
From source file:com.jforce.chapelhillnextbus.HomeActivity.java
public void saveFavorite(View view) { FragmentManager fragmentManager = getFragmentManager(); PredictionsFragment fragment = (PredictionsFragment) fragmentManager.findFragmentById(R.id.content_frame); fragment.saveFavorite();/*from w ww .j av a 2 s . c o m*/ }
From source file:com.jforce.chapelhillnextbus.HomeActivity.java
public void mapClick(View view) { FragmentManager fragmentManager = getFragmentManager(); PredictionsFragment fragment = (PredictionsFragment) fragmentManager.findFragmentById(R.id.content_frame); fragment.mapClick();/*from w w w . ja v a2 s. co m*/ }
From source file:com.jforce.chapelhillnextbus.HomeActivity.java
@Override public void onBackPressed() { FragmentManager fm = getFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.content_frame); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = sharedPreferences.edit(); boolean confirmExit = sharedPreferences.getBoolean("confirmExit", true); if (((Object) fragment).getClass() == PredictionsFragment.class) { PredictionsFragment predictionsFragment = (PredictionsFragment) fragment; int navLevel = predictionsFragment.getNavigationLevel(); if (navLevel == 0) { if (confirmExit) { showConfirmExitDialog(); } else { super.onBackPressed(); }/*from w ww .j a v a2 s . c om*/ } else if (navLevel == 1) { predictionsFragment.routeClick(); } else if (navLevel == 2) { predictionsFragment.directionClick(); } else if (navLevel == 3) { predictionsFragment.stopClick(); } } else if (((Object) fragment).getClass() == MapFragment.class) { MapFragment mapFragment = (MapFragment) fragment; if (mapFragment.isRouteListVisible()) { mapFragment.backFromRoutes(); } else { if (confirmExit) { showConfirmExitDialog(); } else { super.onBackPressed(); } } } else { if (confirmExit) { showConfirmExitDialog(); } else { super.onBackPressed(); } } }
From source file:com.chen.mail.ui.OnePaneController.java
@Override protected void showConversation(Conversation conversation, boolean inLoaderCallbacks) { super.showConversation(conversation, inLoaderCallbacks); mConversationListVisible = false;/*from ww w. j av a 2s . c o m*/ if (conversation == null) { transitionBackToConversationListMode(); return; } disableCabMode(); if (ConversationListContext.isSearchResult(mConvListContext)) { mViewMode.enterSearchResultsConversationMode(); } else { mViewMode.enterConversationMode(); } final FragmentManager fm = mActivity.getFragmentManager(); final FragmentTransaction ft = fm.beginTransaction(); // Switching to conversation view is an incongruous transition: // we are not replacing a fragment with another fragment as // usual. Instead, reveal the heretofore inert conversation // ViewPager and just remove the previously visible fragment // e.g. conversation list, or possibly label list?). final Fragment f = fm.findFragmentById(R.id.content_pane); // FragmentManager#findFragmentById can return fragments that are not added to the activity. // We want to make sure that we don't attempt to remove fragments that are not added to the // activity, as when the transaction is popped off, the FragmentManager will attempt to // readd the same fragment twice if (f != null && f.isAdded()) { ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.remove(f); ft.commitAllowingStateLoss(); fm.executePendingTransactions(); } mPagerController.show(mAccount, mFolder, conversation, true /* changeVisibility */); onConversationVisibilityChanged(true); onConversationListVisibilityChanged(false); }
From source file:com.jforce.chapelhillnextbus.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dev_home); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w .ja va 2s. c o m*/ mTitle = mDrawerTitle = getTitle(); mSubtitle = ""; mDrawerTitles = getResources().getStringArray(R.array.drawer_array); mDrawerTitlesSecondary = getResources().getStringArray(R.array.drawer_array2); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerArea = (LinearLayout) findViewById(R.id.drawer_area); fragmentCache = new Fragment[] { null, null, null }; mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerListSecondary = (ListView) findViewById(R.id.left_drawer2); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new DrawerArrayAdapter(this, mDrawerTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); mDrawerListSecondary.setAdapter(new DrawerArrayAdapter2(this, mDrawerTitlesSecondary)); mDrawerListSecondary.setOnItemClickListener(new DrawerItemClickListener2()); routeListCache = null; // enable ActionBar app icon to behave as action to toggle nav drawer //getSupportActionBar().setIcon(R.drawable.ic_logo_white_nobezel_small); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ toolbar, /* 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 */ ) { public void onDrawerClosed(View view) { getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() FragmentManager fragmentManager = getFragmentManager(); Fragment fragment = fragmentManager.findFragmentById(R.id.content_frame); if (fragment.getClass() == MapFragment.class) { MapFragment mf = (MapFragment) fragment; mf.resetSubtitle(); } } public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(mDrawerTitle); getSupportActionBar().setSubtitle(""); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0, true); } fetchWeather(); initPreferences(); }
From source file:com.example.android.cloudnotes.ui.HomeActivity.java
/** * This method controls both fragments, instructing them to display a * certain note.//from ww w . java2 s . c om * * @param noteUri The {@link Uri} of the note to show. To create a new note, * pass {@code null}. */ private void showNote(final Uri noteUri) { if (mTwoPaneView) { // check if the NoteEditFragment has been added FragmentManager fm = getFragmentManager(); NoteEditFragment edit = (NoteEditFragment) fm.findFragmentByTag(NOTE_EDIT_TAG); final boolean editNoteAdded = (edit != null); if (editNoteAdded) { if (edit.mCurrentNote != null && edit.mCurrentNote.equals(noteUri)) { // clicked on the currently selected note return; } NoteEditFragment editFrag = (NoteEditFragment) fm.findFragmentByTag(NOTE_EDIT_TAG); if (noteUri != null) { // load an existing note editFrag.loadNote(noteUri); NoteListFragment list = (NoteListFragment) fm.findFragmentById(R.id.list); list.setActivatedNote(Long.valueOf(noteUri.getLastPathSegment())); } else { // creating a new note - clear the form & list // activation if (editNoteAdded) { editFrag.clear(); } NoteListFragment list = (NoteListFragment) fm.findFragmentById(R.id.list); list.clearActivation(); } } else { // add the NoteEditFragment to the container FragmentTransaction ft = fm.beginTransaction(); edit = new NoteEditFragment(); ft.add(R.id.note_detail_container, edit, NOTE_EDIT_TAG); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); edit.loadNote(noteUri); } } else { startActivity(new Intent(NoteEditFragment.ACTION_VIEW_NOTE, noteUri)); } }
From source file:com.tct.mail.ui.OnePaneController.java
@Override protected void showConversation(Conversation conversation) { super.showConversation(conversation); // TS: tao.gan 2015-09-21 EMAIL FEATURE-559893 ADD_S //we change from ConversationListFragment to ConversationViewFragment, should let the toolbar show animateShow(null);//from w ww. jav a2 s . c om // TS: tao.gan 2015-09-21 EMAIL FEATURE-559893 ADD_E mConversationListVisible = false; if (conversation == null) { transitionBackToConversationListMode(); return; } disableCabMode(); if (ConversationListContext.isSearchResult(mConvListContext)) { mViewMode.enterSearchResultsConversationMode(); } else { mViewMode.enterConversationMode(); } final FragmentManager fm = mActivity.getFragmentManager(); final FragmentTransaction ft = fm.beginTransaction(); // Switching to conversation view is an incongruous transition: // we are not replacing a fragment with another fragment as // usual. Instead, reveal the heretofore inert conversation // ViewPager and just remove the previously visible fragment // e.g. conversation list, or possibly label list?). final Fragment f = fm.findFragmentById(R.id.content_pane); // FragmentManager#findFragmentById can return fragments that are not added to the activity. // We want to make sure that we don't attempt to remove fragments that are not added to the // activity, as when the transaction is popped off, the FragmentManager will attempt to // readd the same fragment twice if (f != null && f.isAdded()) { ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.remove(f); ft.commitAllowingStateLoss(); //TS: jin.dong 2015-8-28 EMAIL BUGFIX-1075110 MOD_S try { fm.executePendingTransactions(); } catch (IllegalArgumentException e) { LogUtils.d(LOG_TAG, e, "IllegalArgumentException occurred"); } //TS: jin.dong 2015-8-28 EMAIL BUGFIX-1075110 MOD_E } mPagerController.show(mAccount, mFolder, conversation, true /* changeVisibility */); onConversationVisibilityChanged(true); onConversationListVisibilityChanged(false); }
From source file:com.dsna.android.main.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.demo_activity_main); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); _initMenu();// w ww. j a va 2s . c om mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer); mDrawer.setDrawerListener(mDrawerToggle); //----------------------------------------------------------------- //BaseFragment baseFragment = null; if (savedInstanceState != null) { mSelectedFragment = savedInstanceState.getInt(BUNDLE_SELECTEDFRAGMENT); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (fragmentManager.findFragmentById(R.id.fragment_main) == null) mBaseFragment = selectFragment(mSelectedFragment); //if (mBaseFragment==null) // mBaseFragment = selectFragment(mSelectedFragment); } else { mBaseFragment = new NewFeedsFragment(feeds); openFragment(mBaseFragment); } // Store the booting information to pass to the service mBootIp = getIntent().getStringExtra(bIp); mBootPort = getIntent().getStringExtra(bPort); mBindPort = getIntent().getStringExtra(biPort); mUsername = getIntent().getStringExtra(uName); // Initiate database helper dbHelper = new DatabaseHandler(this, mUsername); // Initiate cipher parameters publicKeys = null; secretKeys = null; ps06 = new PS06(); cd07 = new IBBECD07(); GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(this, java.util.Arrays.asList(DriveScopes.DRIVE)); credential.setSelectedAccountName(mUsername); new googleCloudAuthorizationRequestTask().execute(credential); }
From source file:org.proninyaroslav.libretorrent.fragments.MainFragment.java
private void showDetailTorrent(String id) { if (Utils.isTwoPane(activity.getApplicationContext())) { FragmentManager fm = getFragmentManager(); DetailTorrentFragment detail = DetailTorrentFragment.newInstance(id); Fragment fragment = fm.findFragmentById(R.id.detail_torrent_fragmentContainer); if (fragment != null && fragment instanceof DetailTorrentFragment) { String oldId = ((DetailTorrentFragment) fragment).getTorrentId(); if (oldId != null && id.equals(oldId)) { return; }/*from w w w . j a v a 2s .c o m*/ } fm.beginTransaction().replace(R.id.detail_torrent_fragmentContainer, detail) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit(); } else { Intent i = new Intent(activity, DetailTorrentActivity.class); i.putExtra(DetailTorrentActivity.TAG_TORRENT_ID, id); startActivity(i); } }
From source file:com.android.calendar.AllInOneActivity.java
@Override public void onSaveInstanceState(Bundle outState) { mOnSaveInstanceStateCalled = true;/*from w w w . j a va2s. co m*/ super.onSaveInstanceState(outState); outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime()); outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView); if (mCurrentView == ViewType.EDIT) { outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId()); } else if (mCurrentView == ViewType.AGENDA) { FragmentManager fm = getFragmentManager(); Fragment f = fm.findFragmentById(R.id.main_pane); if (f instanceof AgendaFragment) { outState.putLong(BUNDLE_KEY_EVENT_ID, ((AgendaFragment) f).getLastShowEventId()); } } outState.putBoolean(BUNDLE_KEY_CHECK_ACCOUNTS, mCheckForAccounts); }