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:org.gnucash.android.ui.transaction.TransactionsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(findViewById(android.R.id.content).getWindowToken(), 0);
        FragmentManager fm = getSupportFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();//w  w  w  .  ja  v  a 2 s  .com
        } else {
            AccountsActivity.start(this);
            finish();
        }
        return true;

    case R.id.menu_favorite_account:
        AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(this);
        boolean isFavorite = accountsDbAdapter.isFavoriteAccount(mAccountId);
        //toggle favorite preference
        accountsDbAdapter.updateAccount(mAccountId, DatabaseHelper.KEY_FAVORITE, isFavorite ? "0" : "1");
        accountsDbAdapter.close();
        supportInvalidateOptionsMenu();
        return true;

    case R.id.menu_edit_account:
        Intent editAccountIntent = new Intent(this, AccountsActivity.class);
        editAccountIntent.setAction(Intent.ACTION_INSERT_OR_EDIT);
        editAccountIntent.putExtra(UxArgument.SELECTED_ACCOUNT_ID, mAccountId);
        startActivityForResult(editAccountIntent, AccountsActivity.REQUEST_EDIT_ACCOUNT);
        return true;

    default:
        return false;
    }
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.ApptentiveBaseFragment.java

/**
 * Delegates the hardware or software back button press to the Interaction Fragment.
 * @return/*ww w .  ja va2s  .  c o  m*/
 */
public boolean onFragmentExit(ApptentiveViewExitType exitType) {
    List fragments = getRetainedChildFragmentManager().getFragments();

    if (fragments != null) {
        Iterator it = fragments.iterator();

        while (it.hasNext()) {
            Fragment fragment = (Fragment) it.next();

            if (fragment != null && fragment.isVisible()) {
                FragmentManager childFragmentManager = fragment.getChildFragmentManager();

                if (childFragmentManager.getBackStackEntryCount() > 0) {
                    childFragmentManager.popBackStack();
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:com.greatspeeches.slides.ScreenSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.description_layout, container, false);

    final android.support.v4.app.FragmentManager fragmentManager = myContext.getSupportFragmentManager();
    fragmentManager.addOnBackStackChangedListener(new OnBackStackChangedListener() {
        @Override/*w w  w  .  j  ava  2  s . co  m*/
        public void onBackStackChanged() {
            if (fragmentManager.getBackStackEntryCount() == 0) {
                closeYVplayer();
            }
        }
    });

    scroll = (StickyScrollView) rootView.findViewById(R.id.topScroll);
    scroll.setTouchListener(touchHandler);
    fragmentsLayout = (FrameLayout) rootView.findViewById(R.id.video_container);
    // Set the title view to show the page number.
    infoData = ((TextView) rootView.findViewById(R.id.person_info));
    infoData.setMaxLines(Integer.MAX_VALUE);
    infoData.setMovementMethod(new ScrollingMovementMethod());
    infoData.setText("\t\t\t" + mPersonObj.getInfo());
    personImg = (ImageView) rootView.findViewById(R.id.person_image);
    personImg.setBackgroundResource(GreateSpeechesUtil.getResId(mPersonObj.getImageId(), R.drawable.class));
    cVideoView = (CustomVideoView) rootView.findViewById(R.id.surface_video);
    closeImg = (ImageView) rootView.findViewById(R.id.closeBtn);
    videoRel = (RelativeLayout) rootView.findViewById(R.id.forVideo);
    videoRel.setOnTouchListener(customTouchListener);
    fragmentsLayout.setOnTouchListener(customTouchListener);

    if (null != mPersonObj.getdDate() && mPersonObj.getdDate().length() == 0) {
        RelativeLayout dRel = (RelativeLayout) rootView.findViewById(R.id.dDateRel);
        dRel.setVisibility(View.GONE);
    }

    TextView bDateTxt = (TextView) rootView.findViewById(R.id.bDate);
    bDateTxt.setText("" + mPersonObj.getbDate());
    TextView bachievementTxt = (TextView) rootView.findViewById(R.id.C_info);
    bachievementTxt.setText("" + mPersonObj.getAchievement());
    //        TextView pNameTxt = (TextView)rootView.findViewById(R.id.acTitleTxt);
    //        pNameTxt.setText(""+getResources().getString(R.string.achievement, mPersonObj.getName()));
    TextView dDateTxt = (TextView) rootView.findViewById(R.id.dDate);
    dDateTxt.setText("" + mPersonObj.getdDate());

    closeImg.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            closeVplayer();
        }
    });

    return rootView;
}

From source file:dev.drsoran.moloko.activities.AbstractTasksListActivity.java

private BackStackEntry getTopOfBackStack() {
    final FragmentManager fragmentManager = getSupportFragmentManager();
    final int backStackSize = fragmentManager.getBackStackEntryCount();

    return backStackSize > 0 ? fragmentManager.getBackStackEntryAt(backStackSize - 1) : null;
}

From source file:com.cnm.cnmrc.fragment.vodtvch.VodTvch.java

@Override
public void onDestroyView() {
    super.onDestroyView();

    if (((MainActivity) getActivity()).noVodTvchDestroy)
        return;/* w  w w .j a  v a 2s.com*/

    // ----------------------------------------------------------------------------------------------
    // vod? ?? vodtopmenu fragment vod destory?  ??? vodtopmenu? ? destory .
    // ?  ???? ? fragment ? vod? ?  ? ? Activity?   .
    // ----------------------------------------------------------------------------------------------
    {
        Fragment f = getActivity().getSupportFragmentManager()
                .findFragmentById(R.id.fragment_vod_tvch_top_menu);
        if (f != null) {
            getActivity().getSupportFragmentManager().beginTransaction().remove(f).commit();
        }
    }

    {
        Fragment f = getActivity().getSupportFragmentManager().findFragmentById(R.id.loading_data_panel);
        if (f != null) {
            // fragment   Base? onDestroyView callBack?.
            // ?  back stack? count ? minus? destoryView?   0??.
            // 0?  Base? onDestroyView()? .

            // ? ? onDestroyView()? ?  R.id.loading_data_panel?  fragment ? backstack  ? minus?.
            // ? ? ??. ? before after ? minus? count?.
            //  remove ? ?. rc  ?.  Base? onDestroyView() callBack .
            //  ? Base? onDestroyView()?   ??  ? remove   ? ? ? .
            // ?? remove Base? onDestroyView()? callBack ?.
            FragmentManager fm = getActivity().getSupportFragmentManager();
            Log.i("hwang", "before at vodTvch : remove(R.id.loading_data_panel).commit fragment count --> "
                    + Integer.toString(fm.getBackStackEntryCount()));
            getActivity().getSupportFragmentManager().beginTransaction().remove(f).commit();
            Log.i("hwang", "after at vodTvch : remove(R.id.loading_data_panel).commit fragment count --> "
                    + Integer.toString(fm.getBackStackEntryCount()));

            //   base? remove ?? TAG_FRAGMENT_BASE  ? ?.
            //   mainActity? backpress?  base? destoryView callback?.
            // .
            // ??  ? ? ?.
            // getActivity().getSupportFragmentManager().executePendingTransactions();   
        }
    }

    // -----------------------
    // ? bottom menu 
    // -----------------------
    {
        Fragment f = ((MainActivity) getActivity()).getFragmentRcBottomMenu();
        if (f != null)
            ((RcBottomMenu) f).setRemoconMode();
    }
}

From source file:com.example.android.threadsample.DisplayActivity.java

@Override
public void onBackStackChanged() {

    // Gets the previous global stack count
    int previousStackCount = mPreviousStackCount;

    // Gets a FragmentManager instance
    FragmentManager localFragmentManager = getSupportFragmentManager();

    // Sets the current back stack count
    int currentStackCount = localFragmentManager.getBackStackEntryCount();

    // Re-sets the global stack count to be the current count
    mPreviousStackCount = currentStackCount;

    /*/*w  ww.  j  ava2s .c o m*/
     * If the current stack count is less than the previous, something was popped off the stack
     * probably because the user clicked Back.
     */
    boolean popping = currentStackCount < previousStackCount;
    Log.d(CLASS_TAG, "backstackchanged: popping = " + popping);

    // When going backwards in the back stack, turns off full screen mode.
    if (popping) {
        setFullScreen(false);
    }
}

From source file:com.cnm.cnmrc.fragment.vodtvch.VodTvchMain.java

/**
 * ? ? ?  fragment VodTvch ?? loadingDataForSidrebar()?
 * addToBackStack?   ?. ? MainActivity onBackPressed()? back
 * key ?. ? VodTvch fragment addToBackStack ?? ?, 
 * ?? Base back key .  back key?   ??... Base?
 * destoryView()?  ? ?. !!!!!!!   ? isFirstDepth true
 * .  4? ?(,?,TV,)?. vod (1st selectedCategory arg :
 * 2nd title arg) : (0:) / (1:?) / (2:TV) / (3:)
 *//* w  w  w .  j  a  va  2 s  .  com*/
private void loadingDataForSidrebar() {
    FragmentManager fm = getActivity().getSupportFragmentManager();
    Log.i("hwang", "before vodTvch fragment count (no add to stack) --> "
            + Integer.toString(fm.getBackStackEntryCount()));

    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    Class<?> classObject;
    try {
        String packageName = this.getClass().getPackage().getName() + ".";
        classObject = Class.forName(packageName + mClassTypeArray[selectedCategory]); // VodList, VodSemi, VodDetail, TvchList, TvchSemi, TvchDetail
        Object obj = classObject.newInstance();

        // vod    (1st arg : 2nd arg) : (0:) / (1:?) / (2:TV) / (3:)
        // tvch (1st arg : 2nd arg) : (0:?) / (1:?) / (2:HD?) / (3:?)
        // true : 1 depth (vod: VodSemi, VodSemi, VodSemi, VodList)
        // true : 1 depth (tvch: TvchSemi, TvchList, TvchSemi, TvchSemi)
        Bundle bundle = new Bundle();
        bundle.putString("genreId", ""); //   ?     ...
        Base base = ((Base) obj).newInstance(selectedCategory, mCategoryArray[selectedCategory], true, bundle); //  true depth   ?.(,?,TV,)(?,?,HD?,)

        //ft.addToBackStack(null);   // addTBackStack  onBackPressed() ? ?... remove fragment onDestroyView() ?.

        // 2013-12-10 update vodsemi after config>adultcert change
        if (mClassTypeArray[selectedCategory].equals("VodSemi")) {
            ft.replace(R.id.loading_data_panel, base, "vod_semi_for_config");
        } else {
            ft.replace(R.id.loading_data_panel, base);
        }
        ft.commit(); //fm.executePendingTransactions();   // fragment? ? pending recursive error,  ?? pending .

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (java.lang.InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    Log.i("hwang", "after vodTvch fragment count (no add to stack) --> "
            + Integer.toString(fm.getBackStackEntryCount()));

    // ------------------------------------
    // ? bottom menu? depth level 
    // ------------------------------------
    Fragment f = getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_rc_bottom_menu);
    if (f != null)
        ((RcBottomMenu) f).setDepthLevelClear(); // set 1 depth
}

From source file:net.reichholf.dreamdroid.fragment.NavigationFragment.java

private void clearBackStack() {
    // Pop the backstack completely everytime the user navigates "away"
    // Avoid's "stacking" fragments due to back-button behaviour that feels
    // really mysterious
    FragmentManager fm = getActionBarActivity().getSupportFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }/*from  w w w .j a va  2s.  c om*/
}

From source file:com.socialapp.eventmanager.LoginActivity.java

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

    if (savedInstanceState != null) {
        userSkippedLogin = savedInstanceState.getBoolean(USER_SKIPPED_LOGIN_KEY);
    }//w w  w .  ja v  a2  s  .  co  m

    try {
        PackageInfo info = getPackageManager().getPackageInfo("com.socialapp.eventmanager",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
            Log.d("************* KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

    FacebookSdk.sdkInitialize(getApplicationContext());

    callbackManager = CallbackManager.Factory.create();

    accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {

            checkAndRedirectOnFBLogin();

            if (isResumed) {
                FragmentManager manager = getSupportFragmentManager();
                int backStackSize = manager.getBackStackEntryCount();
                for (int i = 0; i < backStackSize; i++) {
                    manager.popBackStack();
                }
                if (currentAccessToken != null) {
                    // showFragment(SELECTION, false);
                } else {
                    showFragment(SPLASH, true);
                }
            }
        }
    };

    setContentView(R.layout.activity_login);

    FragmentManager fm = getSupportFragmentManager();
    SplashFragment splashFragment = (SplashFragment) fm.findFragmentById(R.id.splashFragment);
    fragments[SPLASH] = splashFragment;

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

    splashFragment.setSkipLoginCallback(new SplashFragment.SkipLoginCallback() {
        @Override
        public void onSkipLoginPressed() {
            userSkippedLogin = true;
            //showFragment(SELECTION, false);
        }
    });

    accessTokenTracker.startTracking();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String userLoggedIn = prefs.getString("email", null);
    if (userLoggedIn != null) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }
}

From source file:com.sonymobile.dronecontrol.activity.MainActivity.java

private void clearBackStack() {
    final FragmentManager fragmentManager = getSupportFragmentManager();
    while (fragmentManager.getBackStackEntryCount() != 0) {
        fragmentManager.popBackStackImmediate();
    }//from www . j ava2 s .c  o  m
}