Example usage for android.support.v4.app FragmentManager getBackStackEntryCount

List of usage examples for android.support.v4.app FragmentManager getBackStackEntryCount

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager getBackStackEntryCount.

Prototype

public abstract int getBackStackEntryCount();

Source Link

Document

Return the number of entries currently in the back stack.

Usage

From source file:com.supremainc.biostar2.main.HomeActivity.java

@Override
public void onBackPressed() {
    FragmentManager fm = getSupportFragmentManager();

    if (fm.getBackStackEntryCount() > 0) {
        super.onBackPressed();
        return;/*from  w  w w .j a  va2  s  .  co  m*/
    }

    if (ScreenType.MAIN == mScreen) {
        mPopup.show(PopupType.ALERT, getString(R.string.quit), getString(R.string.quit_question),
                new OnPopupClickListener() {
                    @Override
                    public void OnPositive() {
                        // finish();
                        moveTaskToBack(true);
                        android.os.Process.killProcess(android.os.Process.myPid());
                    }

                    @Override
                    public void OnNegative() {
                    }
                }, getString(R.string.ok), getString(R.string.cancel));
    } else {
        if (fm.getBackStackEntryCount() > 0) {
            super.onBackPressed();
            // fm.popBackStack();
        } else {
            gotoScreen(ScreenType.MAIN, null, false);
        }
    }
}

From source file:sample.multithreading.DownloaderActivity.java

@Override
public void onCreate(Bundle paramBundle) {
    super.onCreate(paramBundle);
    getWindow().setFlags(/*from  w  ww.j av a  2 s .  c  om*/
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
    CompatibleActionBar localCompatibleActionBar = getCompatibleActionBar();
    localCompatibleActionBar.requestOverlayMode();
    this.mMainView = getLayoutInflater().inflate(R.layout.fragmenthost, null);
    setContentView(this.mMainView);
    localCompatibleActionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbarbg));
    localCompatibleActionBar.setDisplayUseLogoEnabled(true);
    localCompatibleActionBar.setLogo(R.drawable.picasalogo);
    View localView = getLayoutInflater().inflate(R.layout.progress, null);
    localCompatibleActionBar.setCustomView(localView);
    this.mActionBarProgressText = ((TextView) localView.findViewById(R.id.actionBarProgressText));
    IntentFilter localIntentFilter = new IntentFilter(NetworkDownloadService.BROADCAST_ACTION);
    localIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
    this.mReceiver = new ResponseReceiver();
    LocalBroadcastManager.getInstance(this).registerReceiver(this.mReceiver, localIntentFilter);
    IntentFilter fragmentIntentFilter = new IntentFilter(ACTION_VIEW_IMAGE);
    fragmentIntentFilter.addDataScheme("http");
    LocalBroadcastManager.getInstance(this).registerReceiver(mIntentReceiver, fragmentIntentFilter);

    fragmentIntentFilter = new IntentFilter(ACTION_ZOOM_IMAGE);
    LocalBroadcastManager.getInstance(this).registerReceiver(mIntentReceiver, fragmentIntentFilter);

    FragmentManager localFragmentManager = getSupportFragmentManager();
    this.mSideBySide = getResources().getBoolean(R.bool.sideBySide);
    this.mHideNavigation = getResources().getBoolean(R.bool.hideNavigation);
    localFragmentManager.addOnBackStackChangedListener(this);
    if (paramBundle == null) {
        FragmentTransaction localFragmentTransaction = localFragmentManager.beginTransaction();
        localFragmentTransaction.add(R.id.fragmentHost, new ThumbnailFragment(), THUMBNAIL_FRAGMENT_TAG);
        localFragmentTransaction.commit();
    } else {
        mFullScreen = paramBundle.getBoolean(EXTRA_FULLSCREEN);
        setFullScreen(mFullScreen);
        mPreviousStackCount = localFragmentManager.getBackStackEntryCount();
    }
}

From source file:com.example.minigameapp.NewLogin.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 ww  w  .  ja va 2  s .  co m

    setContentView(R.layout.new_login);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        public void onUserInfoFetched(GraphUser user) {
            NewLogin.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);

    }

    // 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:com.supremainc.biostar2.main.HomeActivity.java

/**
 * 1 depth menu???. stack??? clear//  w  w w  .jav a  2s. co m
 *
 * @param type
 * @param args
 */
public void gotoScreen(ScreenType type, Bundle args, boolean skipAni) {
    if (type == null) {
        return;
    }

    if (activityScreen(type, args)) {
        return;
    }

    switch (type) {
    case LOG_OUT:
        logOut();
        return;
    case OPEN_MENU:
        mLayout.onDrawMenu();
        return;
    default:
        break;
    }

    BaseFragment fragment = createFragement(type, args);
    if (fragment == null) {
        if (BuildConfig.DEBUG) {
            Log.e(TAG, "fragment null gotoScreen:" + type);
        }
        mLayout.closeDrawer();
        return;
    }
    mFragment = fragment;

    if (BuildConfig.DEBUG) {
        Log.i(TAG, "gotoScreen:" + type);
    }

    FragmentManager fm = getSupportFragmentManager();
    for (int i = 0; i < fm.getBackStackEntryCount(); ++i) {
        fm.popBackStack();
    }

    FragmentTransaction transaction = fm.beginTransaction();
    if (!skipAni) {
        if (type == ScreenType.MAIN) {
            transaction.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right);
        } else {
            transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left,
                    R.anim.enter_from_left, R.anim.exit_to_right);
        }
    }
    transaction.replace(R.id.content_frame, mFragment);
    transaction.commitAllowingStateLoss();
    if (type != ScreenType.MAIN) {
        mHandler.postDelayed(mCloseDrawer, 200);
    }
}

From source file:org.getlantern.firetweet.activity.support.HomeActivity.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_HOME: {
        final FragmentManager fm = getSupportFragmentManager();
        final int count = fm.getBackStackEntryCount();

        if (mSlidingMenu.isMenuShowing()) {
            mSlidingMenu.showContent();/*from  ww  w.  ja  v a  2s  .co  m*/
            return true;
        } else if (count == 0) {
            mSlidingMenu.showMenu();
            return true;
        }
        return true;
    }
    case MENU_SEARCH: {
        openSearchView(mSelectedAccountToSearch);
        return true;
    }
    case MENU_ACTIONS: {
        triggerActionsClick();
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.nadmm.airports.ActivityBase.java

@Override
public void onBackPressed() {
    // If the drawer is open, back will close it
    if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawers();//from w  w  w .  j  a v  a  2  s  .com
        return;
    }
    // Otherwise, it may return to the previous fragment stack
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack();
    } else {
        // Lastly, it will rely on the system behavior for back
        super.onBackPressed();
    }
}

From source file:cn.edu.zafu.corepage.base.BaseActivity.java

/**
 * ?activitifragment// w  w w  . j  a v  a2s. co  m
 * @param pageName page??
 * @param bundle ?
 * @param findAcitivity ?activity
 * @return ??
 */
protected boolean popFragmentInActivity(final String pageName, Bundle bundle, BaseActivity findAcitivity) {
    if (pageName == null || findAcitivity == null || findAcitivity.isFinishing()) {
        return false;
    } else {
        final FragmentManager fragmentManager = findAcitivity.getSupportFragmentManager();
        if (fragmentManager != null) {
            Fragment frg = fragmentManager.findFragmentByTag(pageName);
            if (frg != null && frg instanceof BaseFragment) {
                if (fragmentManager.getBackStackEntryCount() > 1 && mHandler != null) {
                    mHandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            fragmentManager.popBackStack(pageName, 0);
                        }
                    }, 100);
                }
                ((BaseFragment) frg).onFragmentDataReset(bundle);
                return true;
            }
        }
    }
    return false;
}

From source file:com.dwdesign.tweetings.activity.HomeActivity.java

@Override
public void onBackPressed() {
    final FragmentManager fm = getSupportFragmentManager();
    if (fm.getBackStackEntryCount() == 0
            && !mPreferences.getBoolean(PREFERENCE_KEY_STOP_SERVICE_AFTER_CLOSED, false)
            && mPreferences.getBoolean(PREFERENCE_KEY_KEEP_IN_BACKGROUND, false)) {
        moveTaskToBack(true);/*from   ww  w  .  j av a2  s. c o  m*/
        return;
    }
    super.onBackPressed();
}

From source file:com.sith.login.FBLoginActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getActionBar().setDisplayHomeAsUpEnabled(true);

    // redirectState=getIntent().getExtras().getString("riderect_state");
    isConnect = getIntent().getExtras().getBoolean("isConnect");

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }// www  .  jav a 2s. com

    setContentView(R.layout.login);

    FragmentManager fm1 = getSupportFragmentManager();
    fragments[LOGINMETHOD] = fm1.findFragmentById(R.id.loginMethodFragment);
    fragments[PROFILE] = fm1.findFragmentById(R.id.profileFragment);

    FragmentTransaction transaction = fm1.beginTransaction();
    for (int i = 0; i < fragments.length; i++) {
        transaction.hide(fragments[i]);
    }
    transaction.commit();

    loginButton = (LoginButton) findViewById(R.id.login_button);
    List<String> additionalPermissions = new ArrayList<String>();
    additionalPermissions.add("publish_stream");
    additionalPermissions.add("publish_actions");
    loginButton.setPublishPermissions(additionalPermissions);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        // @Override
        public void onUserInfoFetched(GraphUser user) {
            FBLoginActivity.this.user = user;
            updateUserInfo();
            // It's possible that we were waiting for this.user to
            // be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });

    profilePictureViewFB = (ProfilePictureView) findViewById(R.id.profilePictureFB);
    greeting = (TextView) findViewById(R.id.greeting);

    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);

    }

    // 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);
            }
        }
    });

    // Fonts
    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Medium.ttf");
    greeting.setTypeface(tf);
}

From source file:de.vanita5.twittnuker.activity.support.HomeActivity.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_HOME: {
        final FragmentManager fm = getSupportFragmentManager();
        final int count = fm.getBackStackEntryCount();

        if (mSlidingMenu.isMenuShowing()) {
            mSlidingMenu.showContent();//  w w  w .  j  a  v  a2 s . com
            return true;
        } else if (count == 0 && !mSlidingMenu.isMenuShowing()) {
            mSlidingMenu.showMenu();
            return true;
        }
        return true;
    }
    case MENU_SEARCH: {
        openSearchView(mSelectedAccountToSearch);
        return true;
    }
    case MENU_ACTIONS: {
        triggerActionsClick();
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}