Java Code Examples for android.app.fragmentmanager#getBackStackEntryCount()

The following examples show how to use android.app.fragmentmanager#getBackStackEntryCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConversationsActivity.java    From Conversations with GNU General Public License v3.0 7 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (MenuDoubleTabUtil.shouldIgnoreTap()) {
        return false;
    }
    switch (item.getItemId()) {
        case android.R.id.home:
            FragmentManager fm = getFragmentManager();
            if (fm.getBackStackEntryCount() > 0) {
                try {
                    fm.popBackStack();
                } catch (IllegalStateException e) {
                    Log.w(Config.LOGTAG, "Unable to pop back stack after pressing home button");
                }
                return true;
            }
            break;
        case R.id.action_scan_qr_code:
            UriHandlerActivity.scan(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 2
Source File: SettingActivity.java    From RelaxFinger with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onBackPressed() {

    FragmentManager fm = getFragmentManager();
    if (fm.getBackStackEntryCount() > 1) {

        fm.popBackStackImmediate();
        SettingActivity.this.setTitle(R.string.title_activity_setting);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);

    } else {

        clearMemory();
        finish();
    }
}
 
Example 3
Source File: IRKitVirtualDeviceListActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public boolean dispatchKeyEvent(final KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_BACK:
                FragmentManager fm = getFragmentManager();
                int cnt = fm.getBackStackEntryCount();
                if (cnt <= 1) {
                    finish();
                    return false;
                } else {
                    currentPage--;
                }
                break;
            default:
                break;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 4
Source File: ActionBarCastActivity.java    From LyricHere with Apache License 2.0 6 votes vote down vote up
@Override
public void onBackPressed() {
    // If the drawer is open, back will close it
    if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(Gravity.START)) {
        mDrawerLayout.closeDrawers();
        return;
    }
    // Otherwise, it may return to the previous fragment stack
    FragmentManager fragmentManager = getFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack();
    } else {
        // Lastly, it will rely on the system behavior for back
        super.onBackPressed();
    }
}
 
Example 5
Source File: MainActivity.java    From driveimageview with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            FragmentManager fm = getFragmentManager();
            if (fm.getBackStackEntryCount() > 0) {
                fm.popBackStack();
            }
            return true;
        case ch.haclyon.driveimageview.example.R.id.menu_item_help:
            AboutDialog aboutDialog = new AboutDialog(this);
            aboutDialog.show();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 6
Source File: SettingsActivity.java    From Hews with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        FragmentManager fm = getFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        } else {
            finish();
        }
    }
    return super.onOptionsItemSelected(item);
}
 
Example 7
Source File: SettingsActivity.java    From masterpassword with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        FragmentManager fm = getFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
        } else {
            NavUtils.navigateUpFromSameTask(this);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 8
Source File: SubBlacklistActivity.java    From HeadsUp with GNU General Public License v2.0 5 votes vote down vote up
private boolean popFragment() {
    FragmentManager fm = getFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStack();
        return true;
    }
    return false;
}
 
Example 9
Source File: SubBlacklistActivity.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
private boolean popFragment() {
    FragmentManager fm = getFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStack();
        return true;
    }
    return false;
}
 
Example 10
Source File: EnvelopesActivity.java    From budget-envelopes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onBackPressed() {
    FragmentManager fragmentManager = getFragmentManager();
    if (mDrawerLayout.isDrawerOpen(mNavDrawer)) {
        mDrawerLayout.closeDrawers();
    } else if (fragmentManager.getBackStackEntryCount() != 0) {
        fragmentManager.popBackStackImmediate();
        configureFragment(
            fragmentManager.findFragmentById(R.id.content_frame)
        );
    } else {
        super.onBackPressed();
    }
}
 
Example 11
Source File: ChatActivity.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
public void showChatRoomCreation(
        Address peerAddress,
        ArrayList<ContactAddress> participants,
        String subject,
        boolean encrypted,
        boolean isGroupChatRoom,
        boolean cleanBackStack) {
    if (cleanBackStack) {
        FragmentManager fm = getFragmentManager();
        while (fm.getBackStackEntryCount() > 0) {
            fm.popBackStackImmediate();
        }
        if (isTablet()) {
            showEmptyChildFragment();
        }
    }

    Bundle extras = new Bundle();
    if (peerAddress != null) {
        extras.putSerializable("RemoteSipUri", peerAddress.asStringUriOnly());
    }
    extras.putSerializable("Participants", participants);
    extras.putString("Subject", subject);
    extras.putBoolean("Encrypted", encrypted);
    extras.putBoolean("IsGroupChatRoom", isGroupChatRoom);

    ChatRoomCreationFragment fragment = new ChatRoomCreationFragment();
    fragment.setArguments(extras);
    changeFragment(fragment, "Chat room creation", true);
}
 
Example 12
Source File: MainActivity.java    From ZhuanLan with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    closeDrawer();
    // Otherwise, it may return to the previous fragment stack
    FragmentManager fragmentManager = getFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack();
    } else {
        // Lastly, it will rely on the system behavior for back
        super.onBackPressed();
    }
}
 
Example 13
Source File: ConversationsActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (MenuDoubleTabUtil.shouldIgnoreTap()) {
        return false;
    }
    switch (item.getItemId()) {
        case android.R.id.home:
            FragmentManager fm = getFragmentManager();
            if (fm.getBackStackEntryCount() > 0) {
                try {
                    fm.popBackStack();
                } catch (IllegalStateException e) {
                    Log.w(Config.LOGTAG, "Unable to pop back stack after pressing home button");
                }
                return true;
            }
            break;
        case R.id.action_scan_qr_code:
            UriHandlerActivity.scan(this);
            return true;
        case R.id.action_check_updates:
            if (xmppConnectionService.hasInternetConnection()) {
                openInstallFromUnknownSourcesDialogIfNeeded(true);
            } else {
                ToastCompat.makeText(this, R.string.account_status_no_internet, Toast.LENGTH_LONG).show();
            }
            break;
        case R.id.action_invite_user:
            inviteUser();
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 14
Source File: BaseActivity.java    From beaconloc with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            FragmentManager fm = getFragmentManager();
            if (fm.getBackStackEntryCount() > 0) {
                fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
            } else {
                finish();
            }
            return true;
        case R.id.action_settings:
            launchSettingsActivity();
            return true;
        case R.id.action_view_on_github:
            launchGitHubPage();
            return true;
        case R.id.action_help:
            launchHelpPage();
            return true;
        case R.id.action_donate:
            launchDonatePage();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 15
Source File: FilePickerActivity.java    From Pano360 with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    FragmentManager fm = getFragmentManager();

    if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStack();
        mCurrentPath = FileUtils.cutLastSegmentOfPath(mCurrentPath);
        updateTitle();
    } else {
        setResult(RESULT_CANCELED);
        super.onBackPressed();
    }
}
 
Example 16
Source File: FilePickerActivity.java    From stynico with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    FragmentManager fm = getFragmentManager();

    if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStack();
        mCurrentPath = FileUtils.cutLastSegmentOfPath(mCurrentPath);
        updateTitle();
    } else {
        setResult(RESULT_CANCELED);
        super.onBackPressed();
    }
}
 
Example 17
Source File: LinphoneActivity.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
	FragmentManager fm = getFragmentManager();
	FragmentTransaction transaction = fm.beginTransaction();

	/*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
		if (newFragmentType.isRightOf(currentFragment)) {
			transaction.setCustomAnimations(R.anim.slide_in_right_to_left,
					R.anim.slide_out_right_to_left,
					R.anim.slide_in_left_to_right,
					R.anim.slide_out_left_to_right);
		} else {
			transaction.setCustomAnimations(R.anim.slide_in_left_to_right,
					R.anim.slide_out_left_to_right,
					R.anim.slide_in_right_to_left,
					R.anim.slide_out_right_to_left);
		}
	}*/

	if (newFragmentType != FragmentsAvailable.DIALER
			&& newFragmentType != FragmentsAvailable.CONTACTS_LIST
			&& newFragmentType != FragmentsAvailable.CHAT_LIST
			&& newFragmentType != FragmentsAvailable.HISTORY_LIST) {
		transaction.addToBackStack(newFragmentType.toString());
	} else {
		while (fm.getBackStackEntryCount() > 0) {
			fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
		}
	}

	transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString());
	transaction.commitAllowingStateLoss();
	fm.executePendingTransactions();

	currentFragment = newFragmentType;
}
 
Example 18
Source File: Navigator.java    From android-showcase-template with Apache License 2.0 4 votes vote down vote up
public boolean canGoBack(BaseActivity activity) {
    FragmentManager fm = activity.getFragmentManager();
    return fm.getBackStackEntryCount() > 0;
}
 
Example 19
Source File: CommentsActivity.java    From Hews with MIT License 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            if (mIsInReplyMode) {
                showDiscardReplyDialog();
                return true;
            }
            FragmentManager fm = getFragmentManager();
            if (fm.getBackStackEntryCount() > 0) {
                fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
            } else {
                finish();
            }
            break;

        case R.id.action_open_post:
            if (mUrl != null) {
                if (mChromeCustomTabsHelper != null) {
                    // build CustomTabs UI
                    CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
                    Utils.setupIntentBuilder(intentBuilder, this, prefs);
                    ChromeCustomTabsHelper.openCustomTab(this, intentBuilder.build(),
                        Utils.validateAndParseUri(mUrl, mPostId), null);
                } else {
                    Intent urlIntent = new Intent(Intent.ACTION_VIEW);
                    urlIntent.setData(Utils.validateAndParseUri(mUrl, mPostId));
                    startActivity(urlIntent);
                }
            }
            break;

        case R.id.action_bookmark:
            changeBookmarkState();
            break;

        case R.id.action_upvote:
            vote(mPostId, Constants.VOTE_UP);
            break;

        case R.id.action_reply:
            if (!Utils.isOnline(this)) {
                Utils.showLongToast(this, R.string.no_connection_prompt);
                return false;
            }
            switchReplyMode(true, mPostId);
            break;

        case R.id.action_refresh:
            CommentsFragment commentFragment =
                (CommentsFragment) getFragmentManager().findFragmentByTag(Constants.FRAGMENT_TAG_COMMENT);
            commentFragment.getPresenter().refresh();
            break;

        case R.id.action_share:
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            String commentUrl = "https://news.ycombinator.com/item?id=" + mPostId;
            sendIntent.putExtra(Intent.EXTRA_TEXT, commentUrl);
            sendIntent.setType("text/plain");
            startActivity(Intent.createChooser(sendIntent, getString(R.string.share_link_to)));
            break;

        case R.id.action_typography:
            if (!mWindow.isWindowShowing()) {
                mWindow.show();
            } else {
                mWindow.dismiss();
            }
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 20
Source File: MainActivity.java    From linphone-android with GNU General Public License v3.0 4 votes vote down vote up
protected void changeFragment(Fragment fragment, String name, boolean isChild) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (transaction.isAddToBackStackAllowed()) {
        int count = fragmentManager.getBackStackEntryCount();
        if (count > 0) {
            FragmentManager.BackStackEntry entry =
                    fragmentManager.getBackStackEntryAt(count - 1);

            if (entry != null && name.equals(entry.getName())) {
                fragmentManager.popBackStack();
                if (!isChild) {
                    // We just removed it's duplicate from the back stack
                    // And we want at least one in it
                    transaction.addToBackStack(name);
                }
            }
        }

        if (isChild) {
            transaction.addToBackStack(name);
        }
    }

    if (getResources().getBoolean(R.bool.hide_bottom_bar_on_second_level_views)) {
        if (isChild) {
            if (!isTablet()) {
                hideTabBar();
            }
        } else {
            showTabBar();
        }
    }

    Compatibility.setFragmentTransactionReorderingAllowed(transaction, false);
    if (isChild && isTablet()) {
        transaction.replace(R.id.fragmentContainer2, fragment, name);
        findViewById(R.id.fragmentContainer2).setVisibility(View.VISIBLE);
    } else {
        transaction.replace(R.id.fragmentContainer, fragment, name);
    }
    transaction.commitAllowingStateLoss();
    fragmentManager.executePendingTransactions();
}