List of usage examples for android.support.v4.app FragmentManager getBackStackEntryCount
public abstract int getBackStackEntryCount();
From source file:android.support.v17.leanback.app.GuidedStepSupportFragment.java
/** * Convenient method to close GuidedStepSupportFragments on top of other content or finish Activity if * GuidedStepSupportFragments were started in a separate activity. Pops all stack entries including * {@link #UI_STYLE_ENTRANCE}; if {@link #UI_STYLE_ENTRANCE} is not found, finish the activity. * Note that this method must be paired with {@link #add(FragmentManager, GuidedStepSupportFragment, * int)} which sets up the stack entry name for finding which fragment we need to pop back to. *///from www .j a va2 s .c om public void finishGuidedStepSupportFragments() { final FragmentManager fragmentManager = getFragmentManager(); final int entryCount = fragmentManager.getBackStackEntryCount(); if (entryCount > 0) { for (int i = entryCount - 1; i >= 0; i--) { BackStackEntry entry = fragmentManager.getBackStackEntryAt(i); if (isStackEntryUiStyleEntrance(entry.getName())) { GuidedStepSupportFragment top = getCurrentGuidedStepSupportFragment(fragmentManager); if (top != null) { top.setUiStyle(UI_STYLE_ENTRANCE); } fragmentManager.popBackStack(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } ActivityCompat.finishAfterTransition(getActivity()); }
From source file:android.support.v17.leanback.app.GuidedStepSupportFragment.java
/** * Convenient method to pop to fragment with Given class. * @param guidedStepFragmentClass Name of the Class of GuidedStepSupportFragment to pop to. * @param flags Either 0 or {@link FragmentManager#POP_BACK_STACK_INCLUSIVE}. *///from w w w . j a v a 2 s . co m public void popBackStackToGuidedStepSupportFragment(Class guidedStepFragmentClass, int flags) { if (!GuidedStepSupportFragment.class.isAssignableFrom(guidedStepFragmentClass)) { return; } final FragmentManager fragmentManager = getFragmentManager(); final int entryCount = fragmentManager.getBackStackEntryCount(); String className = guidedStepFragmentClass.getName(); if (entryCount > 0) { for (int i = entryCount - 1; i >= 0; i--) { BackStackEntry entry = fragmentManager.getBackStackEntryAt(i); String entryClassName = getGuidedStepSupportFragmentClassName(entry.getName()); if (className.equals(entryClassName)) { fragmentManager.popBackStack(entry.getId(), flags); return; } } } }
From source file:suny.com.softwareeng.WatZonLogin.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); }// w w w . j a va 2 s . c om setContentView(R.layout.main); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Override public void onUserInfoFetched(GraphUser user) { WatZonLogin.this.user = user; updateUI(); // It's possible that we were waiting for this.user to be populated in order to post a // status update. handlePendingAction(); } }); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // Listen for changes in the back stack so we know if a fragment got popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); // Can we present the share dialog for regular links? canPresentShareDialog = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.SHARE_DIALOG); // Can we present the share dialog for photos? canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.PHOTOS); }
From source file:facebook.samples.hellofacebook.HelloFacebookSampleActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); }/*from w w w. j a v a 2s . c om*/ setContentView(R.layout.main); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Override public void onUserInfoFetched(GraphUser user) { HelloFacebookSampleActivity.this.user = user; updateUI(); // It's possible that we were waiting for this.user to be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton); postStatusUpdateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostStatusUpdate(); } }); postPhotoButton = (Button) findViewById(R.id.postPhotoButton); postPhotoButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostPhoto(); } }); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // Listen for changes in the back stack so we know if a fragment got popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); canPresentShareDialog = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.SHARE_DIALOG); }
From source file:com.facebook.samples.hellofacebook.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); }//w w w.java 2 s. c o m setContentView(R.layout.main); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Override public void onUserInfoFetched(GraphUser user) { MainActivity.this.user = user; updateUI(); // It's possible that we were waiting for this.user to be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton); postStatusUpdateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostStatusUpdate(); } }); postPhotoButton = (Button) findViewById(R.id.postPhotoButton); postPhotoButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostPhoto(); } }); pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton); pickFriendsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickFriends(); } }); pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton); pickPlaceButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickPlace(); } }); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // Listen for changes in the back stack so we know if a fragment got popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); }
From source file:com.mario22gmail.license.nfc_project.NavigationDrawerActivity.java
public void ChangeFragment(Fragment fragment) { Log.i(nfcDebugTag, "Change fragment method"); // ||//w w w. ja v a 2 s . c o m FragmentManager fm = getSupportFragmentManager(); if (fm.getBackStackEntryCount() == 0) { android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager() .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.slide_left_animation, R.anim.slide_right_animation, R.anim.slide_left_back_animation, R.anim.slide_right_back_animation); fragmentTransaction.replace(R.id.FragmentContainer, fragment, fragment.getClass().getName()); fragmentTransaction.addToBackStack(fragment.getClass().getName()); fragmentTransaction.commit(); } else { int lengthStack = getSupportFragmentManager().getFragments().size(); Fragment lastFragment = getSupportFragmentManager().getFragments().get(lengthStack - 1); boolean isFragmentLast = fragment.getClass().isInstance(lastFragment); if (!isFragmentLast) { android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager() .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.slide_left_animation, R.anim.slide_right_animation, R.anim.slide_left_back_animation, R.anim.slide_right_back_animation); fragmentTransaction.replace(R.id.FragmentContainer, fragment, fragment.getClass().getName()); fragmentTransaction.addToBackStack(fragment.getClass().getName()); fragmentTransaction.commit(); } } }
From source file:com.koushikdutta.widgets.ListContentFragmentInternal.java
public void setContent(FragmentInterfaceWrapper content, boolean clearChoices, String breadcrumb) { mCurrentContent = content;//from ww w .j a v a2s . c o m if (getActivity() instanceof FragmentActivity) { Fragment f = (Fragment) mCurrentContent; FragmentActivity fa = (FragmentActivity) getActivity(); final FragmentManager fm = fa.getSupportFragmentManager(); FragmentTransaction ft = fa.getSupportFragmentManager().beginTransaction(); if (isPaged()) { View v = getFragment().getView(); Assert.assertNotNull(v); final View l = v.findViewById(R.id.list_fragment); Assert.assertNotNull(l); l.setVisibility(View.GONE); fm.addOnBackStackChangedListener(new OnBackStackChangedListener() { { listener = this; } @Override public void onBackStackChanged() { Fragment f = (Fragment) getFragment(); if (f.isDetached() || f.isRemoving()) { fm.removeOnBackStackChangedListener(this); return; } View v = getFragment().getView(); if (v == null) return; final View l = v.findViewById(R.id.list_fragment); if (l == null) return; if (fm.getBackStackEntryCount() > 0 && "content" .equals(fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName())) { l.setVisibility(View.GONE); } else { l.setVisibility(View.VISIBLE); } } }); fm.popBackStack("content", FragmentManager.POP_BACK_STACK_INCLUSIVE); ft.setBreadCrumbTitle(breadcrumb); ft.setBreadCrumbShortTitle(breadcrumb); ft.addToBackStack("content"); } ft.replace(getContentId(), f, "content"); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit(); } else { setContentNative(breadcrumb); } if (clearChoices) getListView().clearChoices(); }
From source file:m2.android.archetype.example.facebook.HelloFacebookSampleActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); }/*from w ww. j a v a 2 s.c o m*/ setContentView(R.layout.activity_hello_facebook); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Override public void onUserInfoFetched(GraphUser user) { HelloFacebookSampleActivity.this.user = user; updateUI(); // It's possible that we were waiting for this.user to be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton); postStatusUpdateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostStatusUpdate(); } }); postPhotoButton = (Button) findViewById(R.id.postPhotoButton); postPhotoButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostPhoto(); } }); pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton); pickFriendsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickFriends(); } }); pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton); pickPlaceButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickPlace(); } }); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // Listen for changes in the back stack so we know if a fragment got popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); }
From source file:edu.upenn.tempmaniac.AccountActivityNew.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); currentLocation = new Location("") { {// w w w . j av a2s. c o m GPSTracker mGPS = new GPSTracker(AccountActivityNew.this); double mLat = 0; double mLong = 0; if (mGPS.canGetLocation) { mLat = mGPS.getLatitude(); mLong = mGPS.getLongitude(); Log.v("gps handler:", "latitude: " + mLat + ", Longitude: " + mLong); } else { Log.v("gps handler:", "no response"); } setLatitude(mLat); setLongitude(mLong); } }; uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.account_new); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { public void onUserInfoFetched(GraphUser user) { AccountActivityNew.this.user = user; updateUI(); // It's possible that we were waiting for this.user to be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton); postStatusUpdateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostStatusUpdate(); } }); pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton); pickPlaceButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickPlace(); } }); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // Listen for changes in the back stack so we know if a fragment got popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); }
From source file:il.co.togetthere.LoginActivity.java
@SuppressLint("InlinedApi") @Override//ww w.j a va2 s . c o m public void onCreate(Bundle savedInstanceState) { // Hide the status bar. //View decorView = getWindow().getDecorView(); //int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; //decorView.setSystemUiVisibility(uiOptions); // Remember that you should never show the action bar if the // status bar is hidden, so hide that too if necessary. android.app.ActionBar actionBar = getActionBar(); actionBar.hide(); super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.activity_login); //initialize db credentialis for registering user clientManager = new AmazonClientManager(this); // Configure the Facebook login button buttonLoginFacebook = (LoginButton) findViewById(R.id.button_login_facebook); buttonLoginFacebook.setBackgroundResource(R.drawable.button_login_facebook); buttonLoginFacebook.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); buttonLoginFacebook.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Override public void onUserInfoFetched(GraphUser user) { LoginActivity.this.facebookUser = user; LoginActivity.user.init(user); //set facebook user in user //TelephonyManager tMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); //LoginActivity.user.setPhone(tMgr.getLine1Number()); if (user != null) { LoginActivity.user.syncDB(); continuteToNextScreen(); } // It's possible that we were waiting for this.user to be populated in order to post a // status update. handlePendingAction(); } }); // Configure the Google login button buttonLoginGoogle = (Button) findViewById(R.id.button_login_google); buttonLoginGoogle.setBackgroundResource(R.drawable.button_login_google); buttonLoginGoogle.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); buttonLoginGoogle.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(getApplicationContext(), "Google+ support is coming soon...", Toast.LENGTH_SHORT) .show(); } }); // Configure the Twitter login button buttonLoginTwitter = (Button) findViewById(R.id.button_login_twitter); buttonLoginTwitter.setBackgroundResource(R.drawable.button_login_twitter); buttonLoginTwitter.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); buttonLoginTwitter.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(getApplicationContext(), "Twitter support is coming soon...", Toast.LENGTH_SHORT) .show(); } }); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // Listen for changes in the back stack so we know if a fragment got popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); // Can we present the share dialog for regular links? canPresentShareDialog = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.SHARE_DIALOG); // Can we present the share dialog for photos? canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.PHOTOS); }