Example usage for android.app Fragment isAdded

List of usage examples for android.app Fragment isAdded

Introduction

In this page you can find the example usage for android.app Fragment isAdded.

Prototype

final public boolean isAdded() 

Source Link

Document

Return true if the fragment is currently added to its activity.

Usage

From source file:com.android.calendar.AllInOneActivity.java

@Override
public void handleEvent(EventInfo event) {
    long displayTime = -1;
    if (event.eventType == EventType.GO_TO) {
        if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
            mBackToPreviousView = true;/*ww w.ja  v a 2 s  . c om*/
        } else if (event.viewType != mController.getPreviousViewType() && event.viewType != ViewType.EDIT) {
            // Clear the flag is change to a different view type
            mBackToPreviousView = false;
        }

        setMainPane(null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
        if (mSearchView != null) {
            mSearchView.clearFocus();
        }
        if (mShowCalendarControls) {
            int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? mControlsAnimateWidth
                    : mControlsAnimateHeight;
            boolean noControlsView = event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA;
            if (mControlsMenu != null) {
                mControlsMenu.setVisible(!noControlsView);
                mControlsMenu.setEnabled(!noControlsView);
            }
            if (noControlsView || mHideControls) {
                // hide minimonth and calendar frag
                mShowSideViews = false;
                if (!mHideControls) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", 0,
                            animationSize);
                    slideAnimation.addListener(mSlideAnimationDoneListener);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                } else {
                    mMiniMonth.setVisibility(View.GONE);
                    mCalendarsList.setVisibility(View.GONE);
                    mMiniMonthContainer.setVisibility(View.GONE);
                }
            } else {
                // show minimonth and calendar frag
                mShowSideViews = true;
                mMiniMonth.setVisibility(View.VISIBLE);
                mCalendarsList.setVisibility(View.VISIBLE);
                mMiniMonthContainer.setVisibility(View.VISIBLE);
                if (!mHideControls && (mController.getPreviousViewType() == ViewType.MONTH
                        || mController.getPreviousViewType() == ViewType.AGENDA)) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
                            animationSize, 0);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                }
            }
        }
        displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true)
                : event.startTime.toMillis(true);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(displayTime);
        }
    } else if (event.eventType == EventType.VIEW_EVENT) {

        // If in Agenda view and "show_event_details_with_agenda" is "true",
        // do not create the event info fragment here, it will be created by the Agenda
        // fragment

        if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
            if (event.startTime != null && event.endTime != null) {
                // Event is all day , adjust the goto time to local time
                if (event.isAllDay()) {
                    Utils.convertAlldayUtcToLocal(event.startTime, event.startTime.toMillis(false), mTimeZone);
                    Utils.convertAlldayUtcToLocal(event.endTime, event.endTime.toMillis(false), mTimeZone);
                }
                mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime, event.selectedTime,
                        event.id, ViewType.AGENDA, CalendarController.EXTRA_GOTO_TIME, null, null);
            } else if (event.selectedTime != null) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, event.id,
                        ViewType.AGENDA);
            }
        } else {
            // TODO Fix the temp hack below: && mCurrentView !=
            // ViewType.AGENDA
            if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, -1,
                        ViewType.CURRENT);
            }
            int response = event.getResponse();
            if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda)
                    || ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK)
                            || mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)) {
                // start event info as activity
                Intent intent = new Intent(Intent.ACTION_VIEW);
                Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
                intent.setData(eventUri);
                intent.setClass(this, EventInfoActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
                intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
                intent.putExtra(ATTENDEE_STATUS, response);
                startActivity(intent);
            } else {
                // start event info as a dialog
                EventInfoFragment fragment = new EventInfoFragment(this, event.id,
                        event.startTime.toMillis(false), event.endTime.toMillis(false), response, true,
                        EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */);
                fragment.setDialogParams(event.x, event.y, mActionBar.getHeight());
                FragmentManager fm = getFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                // if we have an old popup replace it
                Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
                if (fOld != null && fOld.isAdded()) {
                    ft.remove(fOld);
                }
                ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
                ft.commit();
            }
        }
        displayTime = event.startTime.toMillis(true);
    } else if (event.eventType == EventType.UPDATE_TITLE) {
        setTitleInActionBar(event);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(mController.getTime());
        }
    }
    updateSecondaryTitleFields(displayTime);
}

From source file:com.geecko.QuickLyric.MainActivity.java

private void selectItem(int position) {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment newFragment;
    String tag;/*from  ww  w.  jav  a  2s .c om*/
    switch (position) {
    default:
        // Lyrics
        tag = LYRICS_FRAGMENT_TAG;
        newFragment = fragmentManager.findFragmentByTag(tag);
        if (newFragment == null || !(newFragment instanceof LyricsViewFragment))
            newFragment = new LyricsViewFragment();
        ((LyricsViewFragment) newFragment).showTransitionAnim = true;
        break;
    case 1:
        // Saved Lyrics
        tag = LOCAL_LYRICS_FRAGMENT_TAG;
        newFragment = fragmentManager.findFragmentByTag(tag);
        if (newFragment == null || !(newFragment instanceof LocalLyricsFragment))
            newFragment = new LocalLyricsFragment();
        ((LocalLyricsFragment) newFragment).showTransitionAnim = true;
        break;
    case 2:
        // Separator
        return;
    case 3:
        // Settings
        if (drawer instanceof DrawerLayout)
            ((DrawerLayout) drawer).closeDrawer(drawerView);
        drawer.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
                startActivityForResult(settingsIntent, 77);
            }
        }, 250);
        return;
    case 4:
        // Feedback
        return;
    case 5:
        // About Dialog
        if (drawer instanceof DrawerLayout)
            ((DrawerLayout) drawer).closeDrawer(drawerView);
        drawer.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class);
                startActivityForResult(aboutIntent, 77);
            }
        }, 250);
        return;
    }

    final Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    prepareAnimations(activeFragment);

    // Insert the fragment by replacing any existing fragment
    if (newFragment != activeFragment) {
        if (mActionMode != null)
            mActionMode.finish();
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.setCustomAnimations(R.animator.slide_in_start, R.animator.slide_out_start,
                R.animator.slide_in_start, R.animator.slide_out_start);
        fragmentTransaction.hide(activeFragment);
        if (newFragment.isAdded())
            fragmentTransaction.show(newFragment);
        else
            fragmentTransaction.add(id.main_fragment_container, newFragment, tag);
        ((CollapsingToolbarLayout) findViewById(R.id.toolbar_layout)).setCollapsedTitleTextColor(Color.WHITE);
        fragmentTransaction.commit();

        if (activeFragment instanceof LyricsViewFragment || newFragment instanceof LyricsViewFragment) {
            final Fragment newFragmentCopy = newFragment;
            activeFragment.getView().postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (activeFragment instanceof LyricsViewFragment) {
                        expandToolbar(false);
                        showRefreshFab(false);
                    } else if (newFragmentCopy instanceof LyricsViewFragment) {
                        expandToolbar(true);
                        showRefreshFab(true);
                    }
                }
            }, getResources().getInteger(android.R.integer.config_longAnimTime));
        }
    }
    if (drawer instanceof DrawerLayout && (newFragment == activeFragment))
        ((DrawerLayout) drawer).closeDrawer(drawerView);
}