Example usage for android.app Fragment isVisible

List of usage examples for android.app Fragment isVisible

Introduction

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

Prototype

final public boolean isVisible() 

Source Link

Document

Return true if the fragment is currently visible to the user.

Usage

From source file:com.samsung.msca.samsungvr.sampleapp.LoggedInFragment.java

private void selectItem(int position) {
    if (null == mUser || position == mCurrentSelection) {
        return;/*  w  ww . j a v  a2s  .  c om*/
    }
    mCurrentSelection = position;
    mDrawerList.setItemChecked(position, true);
    mDrawerLayout.closeDrawer(mDrawerList);

    Bundle args = null;
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    Fragment fragment = null;
    String tag = null;

    switch (position) {
    case 1: /* Create live event */

        tag = CreateLiveEventFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = CreateLiveEventFragment.newFragment();
        }
        args = new Bundle();
        args.putString(PARAM_USER, mUser.getUserId());
        break;

    case 2: /* List live events */

        tag = ListLiveEventsFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = ListLiveEventsFragment.newFragment();
        }
        args = new Bundle();
        args.putString(PARAM_USER, mUser.getUserId());
        break;

    case 3: /* Upload video */

        tag = UploadVideoFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = UploadVideoFragment.newFragment();
        }
        args = new Bundle();
        args.putString(PARAM_USER, mUser.getUserId());
        break;

    case 4: /* Get user by session id */

        tag = GetUserBySessionInfoFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = GetUserBySessionInfoFragment.newFragment();
        }
        break;

    }
    if (null != fragment && !fragment.isVisible()) {
        if (null != args) {
            fragment.setArguments(args);
        }
        ft.replace(R.id.content_frame, fragment, tag);
        ft.commitAllowingStateLoss();
    }
}

From source file:co.taqat.call.LinphoneActivity.java

public void displayContact(LinphoneContact contact, boolean chatOnly) {
    Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
    if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CONTACT_DETAIL) {
        ContactDetailsFragment contactFragment = (ContactDetailsFragment) fragment2;
        contactFragment.changeDisplayedContact(contact);
    } else {//  w w  w  . j a  v  a  2  s  .  co m
        Bundle extras = new Bundle();
        extras.putSerializable("Contact", contact);
        extras.putBoolean("ChatAddressOnly", chatOnly);
        changeCurrentFragment(FragmentsAvailable.CONTACT_DETAIL, extras);
    }
}

From source file:co.taqat.call.LinphoneActivity.java

public void displayHistoryDetail(String sipUri, LinphoneCallLog log) {
    LinphoneAddress lAddress;/*from   w w  w .  jav a2  s .  c  o m*/
    try {
        lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
    } catch (LinphoneCoreException e) {
        Log.e("Cannot display history details", e);
        //TODO display error message
        return;
    }
    LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(lAddress);

    String displayName = c != null ? c.getFullName() : LinphoneUtils.getAddressDisplayName(sipUri);
    String pictureUri = c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null;

    String status;
    if (log.getDirection() == CallDirection.Outgoing) {
        status = getString(R.string.outgoing);
    } else {
        if (log.getStatus() == CallStatus.Missed) {
            status = getString(R.string.missed);
        } else {
            status = getString(R.string.incoming);
        }
    }

    String callTime = secondsToDisplayableString(log.getCallDuration());
    String callDate = String.valueOf(log.getTimestamp());

    Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
    if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.HISTORY_DETAIL) {
        HistoryDetailFragment historyDetailFragment = (HistoryDetailFragment) fragment2;
        historyDetailFragment.changeDisplayedHistory(lAddress.asStringUriOnly(), displayName, pictureUri,
                status, callTime, callDate);
    } else {
        Bundle extras = new Bundle();
        extras.putString("SipUri", lAddress.asString());
        if (displayName != null) {
            extras.putString("DisplayName", displayName);
            extras.putString("PictureUri", pictureUri);
        }
        extras.putString("CallStatus", status);
        extras.putString("CallTime", callTime);
        extras.putString("CallDate", callDate);

        changeCurrentFragment(FragmentsAvailable.HISTORY_DETAIL, extras);
    }
}

From source file:co.taqat.call.LinphoneActivity.java

public void displayChat(String sipUri) {
    if (getResources().getBoolean(R.bool.disable_chat)) {
        return;/* w  ww  .j av a  2s  .  c o  m*/
    }

    String pictureUri = null;
    String thumbnailUri = null;
    String displayName = null;

    LinphoneAddress lAddress = null;
    if (sipUri != null) {
        try {
            lAddress = LinphoneManager.getLc().interpretUrl(sipUri);
        } catch (LinphoneCoreException e) {
            //TODO display error message
            Log.e("Cannot display chat", e);
            return;
        }
        LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(lAddress);
        displayName = contact != null ? contact.getFullName() : null;

        if (contact != null && contact.getPhotoUri() != null) {
            pictureUri = contact.getPhotoUri().toString();
            thumbnailUri = contact.getThumbnailUri().toString();
        }
    }

    if (currentFragment == FragmentsAvailable.CHAT_LIST || currentFragment == FragmentsAvailable.CHAT) {
        Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
        if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CHAT
                && !emptyFragment) {
            ChatFragment chatFragment = (ChatFragment) fragment2;
            chatFragment.changeDisplayedChat(sipUri, displayName, pictureUri);
        } else {
            Bundle extras = new Bundle();
            extras.putString("SipUri", sipUri);
            if (sipUri != null && lAddress.getDisplayName() != null) {
                extras.putString("DisplayName", displayName);
                extras.putString("PictureUri", pictureUri);
                extras.putString("ThumbnailUri", thumbnailUri);
            }
            changeCurrentFragment(FragmentsAvailable.CHAT, extras);
        }
    } else {
        if (isTablet()) {
            changeCurrentFragment(FragmentsAvailable.CHAT_LIST, null);
            displayChat(sipUri);
        } else {
            Bundle extras = new Bundle();
            extras.putString("SipUri", sipUri);
            if (sipUri != null && lAddress.getDisplayName() != null) {
                extras.putString("DisplayName", displayName);
                extras.putString("PictureUri", pictureUri);
                extras.putString("ThumbnailUri", thumbnailUri);
            }
            changeCurrentFragment(FragmentsAvailable.CHAT, extras);
        }
    }

    LinphoneService.instance().resetMessageNotifCount();
    LinphoneService.instance().removeMessageNotification();
    displayMissedChats(getUnreadMessageCount());
}

From source file:com.android.mail.ui.AbstractActivityController.java

/**
 * Check if the fragment given here is visible. Checking {@link Fragment#isVisible()} is
 * insufficient because that doesn't check if the window is currently in focus or not.
 *//*from w  w w .  ja va  2s.com*/
private boolean isFragmentVisible(Fragment in) {
    return in != null && in.isVisible() && mActivity.hasWindowFocus();
}