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

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

Introduction

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

Prototype

public abstract Fragment findFragmentById(int id);

Source Link

Document

Finds a fragment that was identified by the given id either when inflated from XML or as the container ID when added in a transaction.

Usage

From source file:com.openatk.planting.MainActivity.java

private void setState(int newState, boolean transition) {
    Log.d("SetState!!", "Setting state:" + Integer.toString(newState));
    if (mCurrentState == newState) {
        return;// w w w .ja v a 2s.  c om
    }
    // Exit current state
    if (mCurrentState == STATE_DEFAULT) {

    } else if (mCurrentState == STATE_LIST_VIEW) {
        FragmentManager fm = getSupportFragmentManager();
        // Hide list
        actionBarSearch.setVisibility(View.GONE);
        Fragment fragment = fm.findFragmentById(R.id.list_view);
        FragmentTransaction ft = fm.beginTransaction();
        ft.hide(fragment);
        ft.commit();
        fragmentListView = null;
    }

    // Enter new state
    if (newState == STATE_DEFAULT) {

    } else if (newState == STATE_LIST_VIEW) {
        FragmentManager fm = getSupportFragmentManager();
        // Show List
        actionBarSearch.setVisibility(View.VISIBLE);
        FragmentListView fragmentListView = (FragmentListView) fm.findFragmentById(R.id.list_view);
        fragmentListView.getData();
        FragmentTransaction ft = fm.beginTransaction();
        ft.show(fragmentListView);
        ft.commit();

        this.fragmentListView = fragmentListView;
    }
    // Officially in new state
    mCurrentState = newState;
    this.invalidateOptionsMenu();
}

From source file:com.openatk.planting.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    dbHelper = new DatabaseHelper(this);

    FragmentManager fm = getSupportFragmentManager();
    fragMap = (SupportMapFragment) fm.findFragmentById(R.id.map);

    fragmentEditField = (FragmentEditJobPopup) fm.findFragmentByTag("edit_job");

    if (savedInstanceState == null) {
        // First incarnation of this activity.
        fragMap.setRetainInstance(true);
    } else {/*from  ww w .ja  v a 2s.c  o m*/
        // Reincarnated activity. The obtained map is the same map instance
        // in the previous
        // activity life cycle. There is no need to reinitialize it.
        map = fragMap.getMap();
    }
    checkGPS();

    actionBar = getActionBar();
    // Specify that a dropdown list should be displayed in the action bar.
    // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    // Hide the title
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
    View view;
    LayoutInflater inflater = (LayoutInflater) this.getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.action_bar, null);
    RelativeLayout item = (RelativeLayout) view.findViewById(R.id.action_bar_layout);
    spinnerMenu = (Spinner) view.findViewById(R.id.action_bar_operation_spinner);
    actionBarSearch = (EditText) view.findViewById(R.id.action_bar_search_box);
    actionBar.setCustomView(item, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.LEFT));

    actionBarSearch.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus == false) {
                InputMethodManager imm = (InputMethodManager) v.getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
    });
    actionBarSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (fragmentListView != null)
                fragmentListView.search(s.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }
    });

    Fragment fragment = fm.findFragmentById(R.id.list_view);
    FragmentTransaction ft = fm.beginTransaction();
    ft.hide(fragment);
    ft.commit();

    //Trello
    trelloController = new TrelloController(getApplicationContext());
    syncController = new SyncController(getApplicationContext(), trelloController, this);
    trelloController.setSyncController(syncController);

    // Get last selected operation
    if (savedInstanceState != null) {
        // Find current field
        currentField = FindFieldById(savedInstanceState.getInt("currentField"));

        // Find current job
        currentJob = FindJobById(savedInstanceState.getInt("currentJob"));

        // Find current operation
        currentOperationId = savedInstanceState.getInt("currentOperationId");

        editIsShowing = savedInstanceState.getInt("editIsShowing");
        addIsShowing = savedInstanceState.getInt("addIsShowing");

        this.addingBoundary = savedInstanceState.getString("drawingBoundary", "");

        // Switch to correct state
        setState(savedInstanceState.getInt("mCurrentState"), false);
    }

    // Load operations from database
    loadOperations();

    // Specify a SpinnerAdapter to populate the dropdown list.
    spinnerMenuAdapter = new ArrayAdapter<Operation>(this, R.layout.operation_list_item, operationsList);
    spinnerMenu.setAdapter(spinnerMenuAdapter);
    // Load current from preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    currentOperationId = prefs.getInt("currentOperationId", 0);
    this.showingHazards = prefs.getBoolean("showingHazards", false);
    selectCurrentOperationInSpinner();
    spinnerMenu.setOnItemSelectedListener(this);

    setUpMapIfNeeded();

    Intent intent = this.getIntent();
    String todo = intent.getStringExtra("todo");
    if (todo != null) {
        if (todo.contentEquals("sync")) {
            trelloController.sync();
        }
    }
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:com.zld.ui.ZldNewActivity.java

private void initView() {
    FragmentManager fragmentManager;
    fragmentManager = getSupportFragmentManager();
    titleFragment = (TitleFragment) fragmentManager.findFragmentById(R.id.title_fragment);
    listFragment = (OrderListFragment) fragmentManager.findFragmentById(R.id.order_list_fragment);
    detailsFragment = (OrderDetailsFragment) fragmentManager.findFragmentById(R.id.order_details_fragment);
    cashFragment = (CashFragment) fragmentManager.findFragmentById(R.id.cash_fragment);
    entranceFragment = (EntranceFragment) fragmentManager.findFragmentById(R.id.entrance_fragment);
    recordFragment = (ParkrecordFragment) fragmentManager.findFragmentById(R.id.park_record_fragment);
    parkinfoFragment = (ParkinfoFragment) fragmentManager.findFragmentById(R.id.park_info_fragment);
    exitFragment = (ExitFragment) fragmentManager.findFragmentById(R.id.exit_fragment);
}

From source file:com.aptoide.amethyst.AppViewActivity.java

@Override
protected void onStop() {
    final FragmentManager manager = getSupportFragmentManager();
    final Fragment fragment = manager.findFragmentById(R.id.content);
    manager.beginTransaction().remove(fragment).commitAllowingStateLoss();
    super.onStop();
}

From source file:com.nextgis.mobile.fragment.MapFragment.java

protected void setMode(int mode) {
    mMode = mode;/*www. j  av  a  2s . c om*/

    hideMainButton();
    hideAddByTapButton();
    hideRulerButton();

    final BottomToolbar toolbar = mActivity.getBottomToolbar();
    toolbar.getBackground().setAlpha(128);
    toolbar.setVisibility(View.VISIBLE);
    mActivity.showDefaultToolbar();

    if (mStatusPanelMode != 3)
        mStatusPanel.setVisibility(View.INVISIBLE);

    switch (mode) {
    case MODE_NORMAL:
        if (mSelectedLayer != null)
            mSelectedLayer.setLocked(false);

        mSelectedLayer = null;
        toolbar.setVisibility(View.GONE);
        showMainButton();
        showRulerButton();
        if (mStatusPanelMode != 0)
            mStatusPanel.setVisibility(View.VISIBLE);

        mEditLayerOverlay.showAllFeatures();
        mEditLayerOverlay.setMode(EditLayerOverlay.MODE_NONE);
        mUndoRedoOverlay.clearHistory();
        break;
    case MODE_EDIT:
        if (mSelectedLayer == null) {
            setMode(MODE_NORMAL);
            return;
        }

        mSelectedLayer.setLocked(true);
        mActivity.showEditToolbar();
        mEditLayerOverlay.setMode(EditLayerOverlay.MODE_EDIT);
        toolbar.setOnMenuItemClickListener(new BottomToolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                return onOptionsItemSelected(menuItem.getItemId());
            }
        });
        break;
    case MODE_EDIT_BY_WALK:
        mSelectedLayer.setLocked(true);
        mActivity.showEditToolbar();
        mEditLayerOverlay.setMode(EditLayerOverlay.MODE_EDIT_BY_WALK);
        mUndoRedoOverlay.clearHistory();
        break;
    case MODE_EDIT_BY_TOUCH:
        mSelectedLayer.setLocked(true);
        mActivity.showEditToolbar();
        mEditLayerOverlay.setMode(EditLayerOverlay.MODE_EDIT_BY_TOUCH);
        toolbar.setOnMenuItemClickListener(new BottomToolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                return onOptionsItemSelected(menuItem.getItemId());
            }
        });
        break;
    case MODE_SELECT_ACTION:
        if (mSelectedLayer == null) {
            setMode(MODE_NORMAL);
            return;
        }

        mSelectedLayer.setLocked(true);
        toolbar.setTitle(null);
        toolbar.getMenu().clear();
        toolbar.inflateMenu(R.menu.select_action);
        toolbar.setNavigationIcon(R.drawable.ic_action_cancel_dark);

        mFinishListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setMode(MODE_NORMAL);
            }
        };
        toolbar.setNavigationOnClickListener(mFinishListener);

        toolbar.setOnMenuItemClickListener(new BottomToolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (mSelectedLayer == null)
                    return false;

                switch (item.getItemId()) {
                case R.id.menu_feature_add:
                    mEditLayerOverlay.setSelectedFeature(new Feature());
                    mEditLayerOverlay.createNewGeometry();
                    mUndoRedoOverlay.clearHistory();
                    setMode(MODE_EDIT);
                    mUndoRedoOverlay.saveToHistory(mEditLayerOverlay.getSelectedFeature());
                    mEditLayerOverlay.setHasEdits(true);
                    break;
                case R.id.menu_feature_edit:
                    setMode(MODE_EDIT);
                    mUndoRedoOverlay.saveToHistory(mEditLayerOverlay.getSelectedFeature());
                    mEditLayerOverlay.setHasEdits(false);
                    break;
                case R.id.menu_feature_delete:
                    deleteFeature();
                    break;
                case R.id.menu_feature_attributes:
                    setMode(MODE_INFO);
                    break;
                }

                return true;
            }
        });

        mEditLayerOverlay.setMode(EditLayerOverlay.MODE_HIGHLIGHT);
        mUndoRedoOverlay.clearHistory();
        break;
    case MODE_INFO:
        if (mSelectedLayer == null) {
            setMode(MODE_NORMAL);
            return;
        }

        mSelectedLayer.setLocked(true);
        boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
        FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        //get or create fragment
        final AttributesFragment attributesFragment = getAttributesFragment(fragmentManager);
        attributesFragment.setTablet(tabletSize);
        int container = R.id.mainview;

        if (attributesFragment.isTablet()) {
            container = R.id.fl_attributes;
        } else {
            Fragment hide = fragmentManager.findFragmentById(R.id.map);
            fragmentTransaction.hide(hide);
        }

        if (!attributesFragment.isAdded()) {
            fragmentTransaction.add(container, attributesFragment, "ATTRIBUTES")
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

            if (!attributesFragment.isTablet())
                fragmentTransaction.addToBackStack(null);
        }

        if (!attributesFragment.isVisible()) {
            fragmentTransaction.show(attributesFragment);
        }

        fragmentTransaction.commit();

        attributesFragment.setSelectedFeature(mSelectedLayer, mEditLayerOverlay.getSelectedFeatureId());
        attributesFragment.setToolbar(toolbar, mEditLayerOverlay);

        mFinishListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((MainActivity) getActivity()).finishFragment();

                if (attributesFragment.isTablet())
                    getActivity().getSupportFragmentManager().beginTransaction().remove(attributesFragment)
                            .commit();

                if (view == null)
                    setMode(MODE_NORMAL);
            }
        };

        toolbar.setNavigationIcon(R.drawable.ic_action_cancel_dark);
        toolbar.setNavigationOnClickListener(mFinishListener);

        break;
    }

    if (mModeListener != null)
        mModeListener.onModeChangeListener();

    setMarginsToPanel();
    defineMenuItems();
}

From source file:com.jefftharris.passwdsafe.PasswdSafe.java

/**
 * Change the view of the activity with an optional identifying tag for the
 * transition/*from   www  .  j a  v  a  2  s  . co m*/
 */
private void doChangeView(final ChangeMode mode, final Fragment contentFrag, final String transTag) {
    checkNavigation(true, new Runnable() {
        public void run() {
            FragmentManager fragMgr = getSupportFragmentManager();
            FragmentTransaction txn = fragMgr.beginTransaction();

            boolean clearBackStack = false;
            boolean supportsBack = false;
            switch (mode) {
            case INIT:
            case FILE_OPEN:
            case FILE_NEW:
            case OPEN_INIT: {
                clearBackStack = true;
                break;
            }
            case OPEN:
            case RECORD:
            case EDIT_RECORD:
            case CHANGE_PASSWORD:
            case VIEW_ABOUT:
            case VIEW_EXPIRATION:
            case VIEW_POLICY_LIST:
            case VIEW_PREFERENCES: {
                supportsBack = true;
                break;
            }
            }
            if (clearBackStack) {
                //noinspection StatementWithEmptyBody
                while (fragMgr.popBackStackImmediate()) {
                    // Clear back stack
                }
            }

            txn.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            if (contentFrag != null) {
                txn.replace(R.id.content, contentFrag);
            } else {
                Fragment currFrag = fragMgr.findFragmentById(R.id.content);
                if ((currFrag != null) && currFrag.isAdded()) {
                    txn.remove(currFrag);
                }
            }

            if (supportsBack) {
                txn.addToBackStack(transTag);
            }

            txn.commit();
            itsIsConfirmBackClosed = true;
        }
    });
}

From source file:com.waz.zclient.pages.main.participants.ParticipantFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_participant, container, false);

    FragmentManager fragmentManager = getChildFragmentManager();
    optionsMenuControl = new OptionsMenuControl();
    if (savedInstanceState == null) {
        fragmentManager.beginTransaction()
                .replace(R.id.fl__participant__header__container,
                        ParticipantHeaderFragment.newInstance(userRequester), ParticipantHeaderFragment.TAG)
                .commit();/*from  w ww.j  ava  2 s. c  om*/

        IConversation currentConversation = getStoreFactory() != null && !getStoreFactory().isTornDown()
                ? getStoreFactory().getConversationStore().getCurrentConversation()
                : null;
        if (currentConversation != null && (currentConversation.getType() == IConversation.Type.ONE_TO_ONE
                || userRequester == IConnectStore.UserRequester.POPOVER)) {
            fragmentManager.beginTransaction()
                    .replace(R.id.fl__participant__container,
                            TabbedParticipantBodyFragment.newInstance(getArguments().getInt(ARG__FIRST__PAGE)),
                            TabbedParticipantBodyFragment.TAG)
                    .commit();
        } else {
            fragmentManager.beginTransaction()
                    .replace(R.id.fl__participant__container,
                            ParticipantBodyFragment.newInstance(userRequester), ParticipantBodyFragment.TAG)
                    .commit();
        }

        getChildFragmentManager().beginTransaction().replace(R.id.fl__participant__settings_box,
                OptionsMenuFragment.newInstance(false), OptionsMenuFragment.TAG).commit();

    }

    Fragment overlayFragment = fragmentManager.findFragmentById(R.id.fl__participant__overlay);
    if (overlayFragment != null) {
        fragmentManager.beginTransaction().remove(overlayFragment).commit();
    }

    bodyContainer = ViewUtils.getView(view, R.id.fl__participant__container);
    loadingIndicatorView = ViewUtils.getView(view, R.id.liv__participants__loading_indicator);

    loadingIndicatorView.setColor(getResources().getColor(R.color.people_picker__loading__color));

    participantsContainerView = ViewUtils.getView(view, R.id.ll__participant__container);
    pickUserContainerView = ViewUtils.getView(view, R.id.fl__add_to_conversation__pickuser__container);

    conversationSettingsOverlayLayout = ViewUtils.getView(view, R.id.fl__conversation_actions__sliding_overlay);
    conversationSettingsOverlayLayout.setVisibility(View.GONE);

    return view;
}

From source file:com.jefftharris.passwdsafe.PasswdSafe.java

/**
 * Update the view mode//from www . j av  a  2 s.co m
 */
private void doUpdateView(ViewMode mode, @NonNull PasswdLocation location) {
    PasswdSafeUtil.dbginfo(TAG, "doUpdateView: mode: %s, loc: %s", mode, location);

    itsLocation = location;
    itsFileDataFrag.setLocation(itsLocation);
    itsCurrViewMode = mode;

    FragmentManager fragMgr = getSupportFragmentManager();
    boolean showLeftList = false;
    boolean queryVisibleForMode = false;
    PasswdSafeNavDrawerFragment.Mode drawerMode = PasswdSafeNavDrawerFragment.Mode.INIT;
    boolean fileTimeoutPaused = true;
    String fileNameUpdate = null;
    switch (mode) {
    case INIT:
    case FILE_OPEN:
    case FILE_NEW: {
        itsTitle = PasswdSafeApp.getAppTitle(null, this);
        fileNameUpdate = "";
        break;
    }
    case VIEW_LIST: {
        showLeftList = true;
        queryVisibleForMode = true;
        drawerMode = PasswdSafeNavDrawerFragment.Mode.RECORDS_LIST;
        fileTimeoutPaused = false;
        itsTitle = null;
        String groups = itsLocation.getGroupPath();
        if (TextUtils.isEmpty(groups)) {
            final ObjectHolder<String> fileNameVal = new ObjectHolder<>();
            itsFileDataFrag.useFileData(new PasswdFileDataUser() {
                @Override
                public void useFileData(@NonNull PasswdFileData fileData) {
                    PasswdFileUri uri = fileData.getUri();
                    itsTitle = PasswdSafeApp.getAppFileTitle(uri, PasswdSafe.this);
                    fileNameVal.set(uri.getIdentifier(PasswdSafe.this, true));
                }
            });
            fileNameUpdate = fileNameVal.get();
        }
        if (itsTitle == null) {
            itsTitle = PasswdSafeApp.getAppTitle(groups, this);
        }

        Fragment contentsFrag = fragMgr.findFragmentById(R.id.content);
        if (contentsFrag instanceof PasswdSafeListFragment) {
            PasswdSafeListFragment.Mode contentsMode = itsIsTwoPane ? PasswdSafeListFragment.Mode.RECORDS
                    : PasswdSafeListFragment.Mode.ALL;
            ((PasswdSafeListFragment) contentsFrag).updateLocationView(itsLocation, contentsMode);
        }
        break;
    }
    case VIEW_RECORD: {
        showLeftList = true;
        drawerMode = itsIsTwoPane ? PasswdSafeNavDrawerFragment.Mode.RECORDS_LIST
                : PasswdSafeNavDrawerFragment.Mode.RECORDS_SINGLE;
        fileTimeoutPaused = false;
        itsTitle = null;
        itsFileDataFrag.useFileData(new PasswdFileDataUser() {
            @Override
            public void useFileData(@NonNull PasswdFileData fileData) {
                if (itsLocation.isRecord()) {
                    PwsRecord rec = fileData.getRecord(itsLocation.getRecord());
                    itsTitle = fileData.getTitle(rec);
                }
            }
        });
        if (itsTitle == null) {
            itsTitle = getString(R.string.new_entry);
        }
        break;
    }
    case EDIT_RECORD: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.RECORDS_ACTION;
        itsTitle = null;
        itsFileDataFrag.useFileData(new PasswdFileDataUser() {
            @Override
            public void useFileData(@NonNull PasswdFileData fileData) {
                if (itsLocation.isRecord()) {
                    PwsRecord rec = fileData.getRecord(itsLocation.getRecord());
                    itsTitle = getString(R.string.edit_item, fileData.getTitle(rec));
                }
            }
        });
        if (itsTitle == null) {
            itsTitle = getString(R.string.new_entry);
        }
        break;
    }
    case CHANGING_PASSWORD: {
        itsTitle = getString(R.string.change_password);
        drawerMode = PasswdSafeNavDrawerFragment.Mode.RECORDS_ACTION;
        break;
    }
    case VIEW_ABOUT: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.ABOUT;
        fileTimeoutPaused = false;
        itsTitle = PasswdSafeApp.getAppTitle(getString(R.string.about), this);
        break;
    }
    case VIEW_EXPIRATION: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.EXPIRATIONS;
        fileTimeoutPaused = false;
        itsTitle = PasswdSafeApp.getAppTitle(getString(R.string.password_expiration), this);
        break;
    }
    case VIEW_POLICY_LIST: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.POLICIES;
        fileTimeoutPaused = false;
        itsTitle = PasswdSafeApp.getAppTitle(getString(R.string.password_policies), this);
        break;
    }
    case VIEW_PREFERENCES: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.PREFERENCES;
        fileTimeoutPaused = false;
        itsTitle = PasswdSafeApp.getAppTitle(getString(R.string.preferences), this);
        break;
    }
    }

    GuiUtils.invalidateOptionsMenu(this);
    boolean fileOpen = isFileOpen();
    itsNavDrawerFrag.updateView(drawerMode, fileNameUpdate, fileOpen);
    restoreActionBar();
    itsTimeoutReceiver.updateTimeout(fileTimeoutPaused);

    PasswdFileDataView fileDataView = itsFileDataFrag.getFileDataView();
    GuiUtils.setVisible(itsQueryPanel, queryVisibleForMode && (fileDataView.getRecordFilter() != null));

    if (fileOpen) {
        if (fileDataView.checkExpiryChanged()) {
            GuiUtils.setVisible(itsExpiryPanel, fileDataView.hasExpiredRecords());
            itsExpiry.setText(fileDataView.getExpiredRecordsStr(this));
        }
    } else {
        GuiUtils.setVisible(itsExpiryPanel, false);
    }

    if (itsIsTwoPane) {
        PasswdSafeListFragment.Mode listMode = itsLocation.isRecord() ? PasswdSafeListFragment.Mode.ALL
                : PasswdSafeListFragment.Mode.GROUPS;
        Fragment listFrag = fragMgr.findFragmentById(R.id.content_list);
        if (listFrag instanceof PasswdSafeListFragment) {
            ((PasswdSafeListFragment) listFrag).updateLocationView(itsLocation, listMode);
        }

        if (listFrag != null) {
            FragmentTransaction txn = fragMgr.beginTransaction();
            if (showLeftList) {
                txn.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                txn.show(listFrag);
            } else {
                txn.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
                txn.hide(listFrag);
            }
            txn.commit();
        }
    }
}

From source file:net.tjado.passwdsafe.PasswdSafe.java

/**
 * Update the view mode//from  www . ja v a2s  .co  m
 */
private void doUpdateView(ViewMode mode, @NonNull PasswdLocation location) {
    PasswdSafeUtil.dbginfo(TAG, "doUpdateView: mode: %s, loc: %s", mode, location);

    itsLocation = location;
    itsFileDataFrag.setLocation(itsLocation);
    itsCurrViewMode = mode;

    FragmentManager fragMgr = getSupportFragmentManager();
    boolean showLeftList = false;
    boolean queryVisibleForMode = false;
    PasswdSafeNavDrawerFragment.Mode drawerMode = PasswdSafeNavDrawerFragment.Mode.INIT;
    boolean fileTimeoutPaused = true;
    String fileNameUpdate = null;

    switch (mode) {
    case INIT:
    case FILE_OPEN:
    case FILE_NEW: {
        itsTitle = PasswdSafeApp.getAppTitle(null, this);
        fileNameUpdate = "";
        break;
    }
    case VIEW_LIST: {
        showLeftList = true;
        queryVisibleForMode = true;
        drawerMode = PasswdSafeNavDrawerFragment.Mode.RECORDS_LIST;
        fileTimeoutPaused = false;
        itsTitle = null;
        String groups = itsLocation.getGroupPath();
        if (TextUtils.isEmpty(groups)) {
            final ObjectHolder<String> fileNameVal = new ObjectHolder<>();
            itsFileDataFrag.useFileData(new PasswdFileDataUser() {
                @Override
                public void useFileData(@NonNull PasswdFileData fileData) {
                    PasswdFileUri uri = fileData.getUri();
                    itsTitle = PasswdSafeApp.getAppFileTitle(uri, PasswdSafe.this);
                    fileNameVal.set(uri.getIdentifier(PasswdSafe.this, true));
                }
            });
            fileNameUpdate = fileNameVal.get();
        }
        if (itsTitle == null) {
            itsTitle = PasswdSafeApp.getAppTitle(groups, this);
        }

        Fragment contentsFrag = fragMgr.findFragmentById(R.id.content);
        if (itsIsDisplayListTreeView) {
            if (contentsFrag instanceof PasswdSafeListFragmentTree) {
                PasswdSafeListFragmentTree.Mode contentsMode = itsIsTwoPane
                        ? PasswdSafeListFragmentTree.Mode.RECORDS
                        : PasswdSafeListFragmentTree.Mode.ALL;
            }
        } else {
            if (contentsFrag instanceof PasswdSafeListFragment) {
                PasswdSafeListFragment.Mode contentsMode = itsIsTwoPane ? PasswdSafeListFragment.Mode.RECORDS
                        : PasswdSafeListFragment.Mode.ALL;
                ((PasswdSafeListFragment) contentsFrag).updateLocationView(itsLocation, contentsMode);
            }
        }

        break;
    }
    case VIEW_RECORD: {
        showLeftList = true;
        drawerMode = itsIsTwoPane ? PasswdSafeNavDrawerFragment.Mode.RECORDS_LIST
                : PasswdSafeNavDrawerFragment.Mode.RECORDS_SINGLE;
        fileTimeoutPaused = false;
        itsTitle = null;
        itsFileDataFrag.useFileData(new PasswdFileDataUser() {
            @Override
            public void useFileData(@NonNull PasswdFileData fileData) {
                if (itsLocation.isRecord()) {
                    PwsRecord rec = fileData.getRecord(itsLocation.getRecord());
                    itsTitle = fileData.getTitle(rec);
                }
            }
        });
        if (itsTitle == null) {
            itsTitle = getString(R.string.new_entry);
        }
        break;
    }
    case EDIT_RECORD: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.RECORDS_ACTION;
        itsTitle = null;
        itsFileDataFrag.useFileData(new PasswdFileDataUser() {
            @Override
            public void useFileData(@NonNull PasswdFileData fileData) {
                if (itsLocation.isRecord()) {
                    PwsRecord rec = fileData.getRecord(itsLocation.getRecord());
                    itsTitle = getString(R.string.edit_item, fileData.getTitle(rec));
                }
            }
        });
        if (itsTitle == null) {
            itsTitle = getString(R.string.new_entry);
        }
        break;
    }
    case CHANGING_PASSWORD: {
        itsTitle = getString(R.string.change_password);
        drawerMode = PasswdSafeNavDrawerFragment.Mode.RECORDS_ACTION;
        break;
    }
    case VIEW_ABOUT: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.ABOUT;
        fileTimeoutPaused = false;
        itsTitle = PasswdSafeApp.getAppTitle(getString(R.string.about), this);
        break;
    }
    case VIEW_EXPIRATION: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.EXPIRATIONS;
        fileTimeoutPaused = false;
        itsTitle = PasswdSafeApp.getAppTitle(getString(R.string.password_expiration), this);
        break;
    }
    case VIEW_POLICY_LIST: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.POLICIES;
        fileTimeoutPaused = false;
        itsTitle = PasswdSafeApp.getAppTitle(getString(R.string.password_policies), this);
        break;
    }
    case VIEW_PREFERENCES: {
        drawerMode = PasswdSafeNavDrawerFragment.Mode.PREFERENCES;
        fileTimeoutPaused = false;
        itsTitle = PasswdSafeApp.getAppTitle(getString(R.string.preferences), this);
        break;
    }
    }

    GuiUtils.invalidateOptionsMenu(this);
    boolean fileOpen = isFileOpen();
    itsNavDrawerFrag.updateView(drawerMode, fileNameUpdate, fileOpen);
    restoreActionBar();
    itsTimeoutReceiver.updateTimeout(fileTimeoutPaused);

    PasswdFileDataView fileDataView = itsFileDataFrag.getFileDataView();
    GuiUtils.setVisible(itsQueryPanel, queryVisibleForMode && (fileDataView.getRecordFilter() != null));

    if (fileOpen) {
        if (fileDataView.checkExpiryChanged()) {
            GuiUtils.setVisible(itsExpiryPanel, fileDataView.hasExpiredRecords());
            itsExpiry.setText(fileDataView.getExpiredRecordsStr(this));
        }
    } else {
        GuiUtils.setVisible(itsExpiryPanel, false);
    }

    if (itsIsTwoPane) {
        PasswdSafeListFragment.Mode listMode = itsLocation.isRecord() ? PasswdSafeListFragment.Mode.ALL
                : PasswdSafeListFragment.Mode.GROUPS;
        Fragment listFrag = fragMgr.findFragmentById(R.id.content_list);
        if (listFrag instanceof PasswdSafeListFragment) {
            ((PasswdSafeListFragment) listFrag).updateLocationView(itsLocation, listMode);
        }

        if (listFrag != null) {
            FragmentTransaction txn = fragMgr.beginTransaction();
            if (showLeftList) {
                txn.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                txn.show(listFrag);
            } else {
                txn.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
                txn.hide(listFrag);
            }
            txn.commit();
        }
    }
}