Java Code Examples for android.app.Fragment#isVisible()
The following examples show how to use
android.app.Fragment#isVisible() .
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: MainActivity.java From catnut with MIT License | 6 votes |
/** * 切换fragment,附带一个动画效果 * * @param fragment * @param tag 没有赋null即可 */ private void pendingFragment(Fragment fragment, String tag) { FragmentManager fragmentManager = getFragmentManager(); Fragment tmp = fragmentManager.findFragmentByTag(tag); if (tmp == null || !tmp.isVisible()) { fragmentManager .beginTransaction() .setCustomAnimations( R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit, R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit ) .replace(R.id.fragment_container, fragment, tag) .addToBackStack(null) .commit(); mScrollSettleHandler.post(new Runnable() { @Override public void run() { invalidateOptionsMenu(); } }); } }
Example 2
Source File: MapsAppActivity.java From maps-app-android with Apache License 2.0 | 6 votes |
/** * Opens the content browser that shows the user's maps. */ private void showContentBrowser() { FragmentManager fragmentManager = getFragmentManager(); Fragment browseFragment = fragmentManager.findFragmentByTag(ContentBrowserFragment.TAG); if (browseFragment == null) { browseFragment = new ContentBrowserFragment(); } if (!browseFragment.isVisible()) { FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(R.id.maps_app_activity_content_frame, browseFragment, ContentBrowserFragment.TAG); transaction.addToBackStack(null); transaction.commit(); invalidateOptionsMenu(); // reload the options menu } mDrawerLayout.closeDrawers(); }
Example 3
Source File: LinphoneActivity.java From Linphone4Android with GNU General Public License v3.0 | 5 votes |
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 { Bundle extras = new Bundle(); extras.putSerializable("Contact", contact); extras.putBoolean("ChatAddressOnly", chatOnly); changeCurrentFragment(FragmentsAvailable.CONTACT_DETAIL, extras); } }
Example 4
Source File: HomeActivity.java From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onBackPressed() { FragmentManager fragmentManager = getFragmentManager(); Fragment fragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_HOME); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else if (fragment != null && fragment.isVisible()) { if(backPressedOnce){ finish(); } if(!backPressedOnce) Toast.makeText(this, "Tap back once more to exit.", Toast.LENGTH_SHORT).show(); backPressedOnce=true; new Handler().postDelayed(new Runnable() { @Override public void run() { backPressedOnce= false; } }, 2000); } else { fragmentManager.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) .replace(R.id.container, new HomeFragment(), FRAGMENT_TAG_HOME).commit(); if (getSupportActionBar() != null) { getSupportActionBar().setTitle(R.string.app_name); } navigationView.setCheckedItem(R.id.nav_home); } }
Example 5
Source File: Utilities.java From rss with GNU General Public License v3.0 | 5 votes |
private static void switchToFragment(Fragment fragment, boolean addToBackStack) { if(fragment.isHidden()) { Fragment[] fragments = { s_fragmentFavourites, s_fragmentManage, s_fragmentFeeds, s_fragmentSettings }; FragmentTransaction transaction = s_fragmentManager.beginTransaction(); for(Fragment frag : fragments) { if(frag.isVisible()) { transaction.hide(frag); } } transaction.show(fragment); if(addToBackStack) { transaction.addToBackStack(null); // Set the default transition for adding to the stack. transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); } transaction.commit(); s_fragmentManager.executePendingTransactions(); fragment.getActivity().invalidateOptionsMenu(); } }
Example 6
Source File: LinphoneActivity.java From Linphone4Android with GNU General Public License v3.0 | 4 votes |
public void displayHistoryDetail(String sipUri, LinphoneCallLog log) { LinphoneAddress lAddress; 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); } }
Example 7
Source File: MainActivity.java From catnut with MIT License | 4 votes |
@Override public void onClick(View v) { int id = v.getId(); Fragment fragment = null; String tag = null; mDrawerLayout.closeDrawer(mQuickReturnDrawer); switch (id) { case R.id.tweets_count: case R.id.action_my_tweets: fragment = UserTimelineFragment.getFragment(mApp.getAccessToken().uid, mApp.getPreferences().getString(User.screen_name, null)); tag = UserTimelineFragment.TAG; break; case R.id.following_count: fragment = MyRelationshipFragment.getFragment(true); tag = "true"; break; case R.id.followers_count: fragment = MyRelationshipFragment.getFragment(false); tag = "false"; break; case R.id.action_my_favorites: fragment = FavoriteFragment.getFragment(); tag = FavoriteFragment.TAG; break; case R.id.action_my_drafts: fragment = DraftFragment.getFragment(); tag = DraftFragment.TAG; break; case R.id.action_share_app: Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(getString(R.string.mime_image)); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_app)); intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text)); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(getExternalCacheDir() + File.separator + Constants.SHARE_IMAGE))); startActivity(intent); return; case R.id.action_view_source_code: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.github_link)))); return; case R.id.new_tweet: // 回掉主页时间线 Fragment home = getFragmentManager().findFragmentByTag(HomeTimelineFragment.TAG); // never null, but we still check it. if (home == null || !home.isVisible()) { fragment = HomeTimelineFragment.getFragment(); tag = HomeTimelineFragment.TAG; } else { if (mRefreshCallback != null) { mRefreshCallback.callback(null); } } mNewTweet.setText("0"); break; case R.id.new_mention: fragment = MentionTimelineFragment.getFragment(); tag = MentionTimelineFragment.TAG; mNewMention.setText("0"); break; case R.id.new_comment: fragment = ConversationFragment.getFragment(); tag = ConversationFragment.TAG; mNewComment.setText("0"); break; case R.id.action_my_list: default: Toast.makeText(this, "sorry, not yet implemented =.=", Toast.LENGTH_SHORT).show(); return; } if (fragment != null) { pendingFragment(fragment, tag); } }