List of usage examples for android.view ViewTreeObserver removeOnGlobalLayoutListener
public void removeOnGlobalLayoutListener(OnGlobalLayoutListener victim)
From source file:com.example.ray.firstapp.bottombar.BottomBar.java
/** * Get this BottomBar's height (or width), depending if the BottomBar * is on the bottom (phones) or the left (tablets) of the screen. * * @param listener {@link OnSizeDeterminedListener} to get the size when it's ready. *//*w ww . j a v a2s . c o m*/ public void getBarSize(final OnSizeDeterminedListener listener) { final int sizeCandidate = mIsTabletMode ? mOuterContainer.getWidth() : mOuterContainer.getHeight(); if (sizeCandidate == 0) { mOuterContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { listener.onSizeReady( mIsTabletMode ? mOuterContainer.getWidth() : mOuterContainer.getHeight()); ViewTreeObserver obs = mOuterContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); return; } listener.onSizeReady(sizeCandidate); }
From source file:com.example.ray.firstapp.bottombar.BottomBar.java
private void initializeViews() { mIsTabletMode = !mIgnoreTabletLayout && mContext.getResources().getBoolean(R.bool.bb_bottom_bar_is_tablet_mode); View rootView = View.inflate(mContext, mIsTabletMode ? R.layout.bb_bottom_bar_item_container_tablet : R.layout.bb_bottom_bar_item_container, null); mTabletRightBorder = rootView.findViewById(R.id.bb_tablet_right_border); mUserContentContainer = (ViewGroup) rootView.findViewById(R.id.bb_user_content_container); mShadowView = rootView.findViewById(R.id.bb_bottom_bar_shadow); mOuterContainer = (ViewGroup) rootView.findViewById(R.id.bb_bottom_bar_outer_container); mItemContainer = (ViewGroup) rootView.findViewById(R.id.bb_bottom_bar_item_container); mBackgroundView = rootView.findViewById(R.id.bb_bottom_bar_background_view); mBackgroundOverlay = rootView.findViewById(R.id.bb_bottom_bar_background_overlay); if (mIsShy && mIgnoreTabletLayout) { mPendingUserContentView = null;// www . j ava 2s . co m } if (mPendingUserContentView != null) { ViewGroup.LayoutParams params = mPendingUserContentView.getLayoutParams(); if (params == null) { params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); } if (mIsTabletMode && mIsShy) { ((ViewGroup) mPendingUserContentView.getParent()).removeView(mPendingUserContentView); } mUserContentContainer.addView(mPendingUserContentView, 0, params); mPendingUserContentView = null; } if (mIsShy && !mIsTabletMode) { getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { if (!mShyHeightAlreadyCalculated) { ((CoordinatorLayout.LayoutParams) getLayoutParams()) .setBehavior(new BottomNavigationBehavior(getOuterContainer().getHeight(), 0)); } ViewTreeObserver obs = getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } addView(rootView); }
From source file:com.android.incallui.CallCardFragment.java
@Override public void onResume() { super.onResume(); // If the previous launch animation is still running, cancel it so that we don't get // stuck in an intermediate animation state. if (mAnimatorSet != null && mAnimatorSet.isRunning()) { mAnimatorSet.cancel();/*from w w w . ja v a 2 s . co m*/ } mIsLandscape = getResources().getBoolean(R.bool.is_layout_landscape); mHasLargePhoto = getResources().getBoolean(R.bool.has_large_photo); final ViewGroup parent = ((ViewGroup) mPrimaryCallCardContainer.getParent()); final ViewTreeObserver observer = parent.getViewTreeObserver(); parent.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { ViewTreeObserver viewTreeObserver = observer; if (!viewTreeObserver.isAlive()) { viewTreeObserver = parent.getViewTreeObserver(); } viewTreeObserver.removeOnGlobalLayoutListener(this); mFloatingActionButtonController.setScreenWidth(parent.getWidth()); updateFabPosition(); } }); updateColors(); }
From source file:com.android.incallui.CallCardFragment.java
/** * Adds a global layout listener to update the FAB's positioning on the next layout. This allows * us to position the FAB after the secondary call info's height has been calculated. *//*w ww . j a v a 2 s .co m*/ private void updateFabPositionForSecondaryCallInfo() { mSecondaryCallInfo.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { final ViewTreeObserver observer = mSecondaryCallInfo.getViewTreeObserver(); if (!observer.isAlive()) { return; } observer.removeOnGlobalLayoutListener(this); onDialpadVisibilityChange(mIsDialpadShowing); } }); }
From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java
private void initializeViews() { mIsTabletMode = !mIgnoreTabletLayout && mContext.getResources().getBoolean(R.bool.bb_bottom_bar_is_tablet_mode); ViewCompat.setElevation(this, MiscUtils.dpToPixel(mContext, 8)); View rootView = View.inflate(mContext, mIsTabletMode ? R.layout.bb_bottom_bar_item_container_tablet : R.layout.bb_bottom_bar_item_container, null); mTabletRightBorder = rootView.findViewById(R.id.bb_tablet_right_border); mUserContentContainer = (ViewGroup) rootView.findViewById(R.id.bb_user_content_container); mShadowView = rootView.findViewById(R.id.bb_bottom_bar_shadow); mOuterContainer = (ViewGroup) rootView.findViewById(R.id.bb_bottom_bar_outer_container); mItemContainer = (ViewGroup) rootView.findViewById(R.id.bb_bottom_bar_item_container); mBackgroundView = rootView.findViewById(R.id.bb_bottom_bar_background_view); mBackgroundOverlay = rootView.findViewById(R.id.bb_bottom_bar_background_overlay); if (mIsShy && mIgnoreTabletLayout) { mPendingUserContentView = null;//from www .ja v a 2s . co m } if (mPendingUserContentView != null) { ViewGroup.LayoutParams params = mPendingUserContentView.getLayoutParams(); if (params == null) { params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); } if (mIsTabletMode && mIsShy) { ((ViewGroup) mPendingUserContentView.getParent()).removeView(mPendingUserContentView); } mUserContentContainer.addView(mPendingUserContentView, 0, params); mPendingUserContentView = null; } if (mIsShy && !mIsTabletMode) { getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { if (!mShyHeightAlreadyCalculated) { ((CoordinatorLayout.LayoutParams) getLayoutParams()) .setBehavior(new BottomNavigationBehavior(getOuterContainer().getHeight(), 0, isShy(), mIsTabletMode)); } ViewTreeObserver obs = getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } addView(rootView); }
From source file:com.android.dialer.DialtactsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Trace.beginSection(TAG + " onCreate"); super.onCreate(savedInstanceState); mFirstLaunch = true;//from w w w.j av a2 s. com final Resources resources = getResources(); mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large); Trace.beginSection(TAG + " setContentView"); setContentView(R.layout.dialtacts_activity); Trace.endSection(); getWindow().setBackgroundDrawable(null); Trace.beginSection(TAG + " setup Views"); final ActionBar actionBar = getSupportActionBar(); actionBar.setCustomView(R.layout.search_edittext); actionBar.setDisplayShowCustomEnabled(true); actionBar.setBackgroundDrawable(null); SearchEditTextLayout searchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView() .findViewById(R.id.search_view_container); searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener); mActionBarController = new ActionBarController(this, searchEditTextLayout); mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view); mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button); searchEditTextLayout.findViewById(R.id.search_magnifying_glass) .setOnClickListener(mSearchViewOnClickListener); searchEditTextLayout.findViewById(R.id.search_box_start_search) .setOnClickListener(mSearchViewOnClickListener); searchEditTextLayout.setOnClickListener(mSearchViewOnClickListener); searchEditTextLayout.setCallback(new SearchEditTextLayout.Callback() { @Override public void onBackButtonClicked() { onBackPressed(); } @Override public void onSearchViewClicked() { // Hide FAB, as the keyboard is shown. mFloatingActionButtonController.scaleOut(); } }); mIsLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; mPreviouslySelectedTabIndex = ListsFragment.TAB_INDEX_SPEED_DIAL; final View floatingActionButtonContainer = findViewById(R.id.floating_action_button_container); ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button); floatingActionButton.setOnClickListener(this); mFloatingActionButtonController = new FloatingActionButtonController(this, floatingActionButtonContainer, floatingActionButton); ImageButton optionsMenuButton = (ImageButton) searchEditTextLayout .findViewById(R.id.dialtacts_options_menu_button); optionsMenuButton.setOnClickListener(this); mOverflowMenu = buildOptionsMenu(searchEditTextLayout); optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener()); // Add the favorites fragment but only if savedInstanceState is null. Otherwise the // fragment manager is responsible for recreating it. if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT).commit(); } else { mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI); mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI); mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN); mActionBarController.restoreInstanceState(savedInstanceState); } final boolean isLayoutRtl = DialerUtils.isRtl(); if (mIsLandscape) { mSlideIn = AnimationUtils.loadAnimation(this, isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right); mSlideOut = AnimationUtils.loadAnimation(this, isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right); } else { mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom); mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom); } mSlideIn.setInterpolator(AnimUtils.EASE_IN); mSlideOut.setInterpolator(AnimUtils.EASE_OUT); mSlideIn.setAnimationListener(mSlideInListener); mSlideOut.setAnimationListener(mSlideOutListener); mParentLayout = (CoordinatorLayout) findViewById(R.id.dialtacts_mainlayout); mParentLayout.setOnDragListener(new LayoutOnDragListener()); floatingActionButtonContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { final ViewTreeObserver observer = floatingActionButtonContainer.getViewTreeObserver(); if (!observer.isAlive()) { return; } observer.removeOnGlobalLayoutListener(this); int screenWidth = mParentLayout.getWidth(); mFloatingActionButtonController.setScreenWidth(screenWidth); mFloatingActionButtonController.align(getFabAlignment(), false /* animate */); } }); Trace.endSection(); Trace.beginSection(TAG + " initialize smart dialing"); mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this); SmartDialPrefix.initializeNanpSettings(this); Trace.endSection(); Trace.endSection(); }
From source file:com.androzic.MapFragment.java
private void updateMapViewArea() { final ViewTreeObserver vto = map.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressLint("NewApi") @SuppressWarnings("deprecation") public void onGlobalLayout() { View root = getView(); Rect area = new Rect(); map.getLocalVisibleRect(area); View v = root.findViewById(R.id.topbar); if (v != null) area.top = v.getBottom(); v = root.findViewById(R.id.bottombar); if (v != null) area.bottom = v.getTop(); v = root.findViewById(R.id.rightbar); if (v != null) area.right = v.getLeft(); if (mapButtons.isShown()) { // Landscape mode if (v != null) area.bottom = mapButtons.getTop(); else area.right = mapButtons.getLeft(); }/*from ww w . j a v a 2 s .c o m*/ if (!area.isEmpty()) map.updateViewArea(area); ViewTreeObserver ob; if (vto.isAlive()) ob = vto; else ob = map.getViewTreeObserver(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { ob.removeGlobalOnLayoutListener(this); } else { ob.removeOnGlobalLayoutListener(this); } } }); }
From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java
/** * Removes global layout listener added in {@link #addGlobalLayoutListener()}. *//*from w w w . j a v a 2s . c om*/ void removeGlobalLayoutListener() { final ViewTreeObserver viewTreeObserver = getParentView().getViewTreeObserver(); if (viewTreeObserver.isAlive()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { viewTreeObserver.removeOnGlobalLayoutListener(mGlobalLayoutListener); } else { //noinspection deprecation viewTreeObserver.removeGlobalOnLayoutListener(mGlobalLayoutListener); } } }
From source file:com.android.incallui.CallCardFragment.java
@Override public void animateForNewOutgoingCall() { final ViewGroup parent = (ViewGroup) mPrimaryCallCardContainer.getParent(); final ViewTreeObserver observer = getView().getViewTreeObserver(); mIsAnimating = true;// w w w .j a v a 2 s. c o m observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { final ViewTreeObserver observer = getView().getViewTreeObserver(); if (!observer.isAlive()) { return; } observer.removeOnGlobalLayoutListener(this); final LayoutIgnoringListener listener = new LayoutIgnoringListener(); mPrimaryCallCardContainer.addOnLayoutChangeListener(listener); // Prepare the state of views before the slide animation final int originalHeight = mPrimaryCallCardContainer.getHeight(); mPrimaryCallCardContainer.setTag(R.id.view_tag_callcard_actual_height, originalHeight); mPrimaryCallCardContainer.setBottom(parent.getHeight()); // Set up FAB. mFloatingActionButtonContainer.setVisibility(View.GONE); mFloatingActionButtonController.setScreenWidth(parent.getWidth()); mCallButtonsContainer.setAlpha(0); mCallStateLabel.setAlpha(0); mPrimaryName.setAlpha(0); mCallTypeLabel.setAlpha(0); mCallNumberAndLabel.setAlpha(0); assignTranslateAnimation(mCallStateLabel, 1); assignTranslateAnimation(mCallStateIcon, 1); assignTranslateAnimation(mPrimaryName, 2); assignTranslateAnimation(mCallNumberAndLabel, 3); assignTranslateAnimation(mCallTypeLabel, 4); assignTranslateAnimation(mCallButtonsContainer, 5); final Animator animator = getShrinkAnimator(parent.getHeight(), originalHeight); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mPrimaryCallCardContainer.setTag(R.id.view_tag_callcard_actual_height, null); setViewStatePostAnimation(listener); mIsAnimating = false; InCallPresenter.getInstance().onShrinkAnimationComplete(); } }); animator.start(); } }); }
From source file:com.androzic.vnspeech.MapFragment.java
private void updateMapViewArea() { final ViewTreeObserver vto = map.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressLint("NewApi") @SuppressWarnings("deprecation") public void onGlobalLayout() { View root = getView(); Rect area = new Rect(); map.getLocalVisibleRect(area); View v = root.findViewById(R.id.topbar); if (v != null) area.top = v.getBottom(); v = root.findViewById(R.id.bottombar); if (v != null) area.bottom = v.getTop(); if (mapLicense.isShown()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mapLicense.getRotation() != 0f) area.left = mapLicense.getHeight(); // rotated view does not correctly report it's position else area.bottom = mapLicense.getTop(); }/* w w w . j a v a 2s .c om*/ v = root.findViewById(R.id.rightbar); if (v != null) area.right = v.getLeft(); if (mapButtons.isShown()) { // Landscape mode if (v != null) area.bottom = mapButtons.getTop(); else area.right = mapButtons.getLeft(); } if (!area.isEmpty()) map.updateViewArea(area); ViewTreeObserver ob; if (vto.isAlive()) ob = vto; else ob = map.getViewTreeObserver(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { ob.removeGlobalOnLayoutListener(this); } else { ob.removeOnGlobalLayoutListener(this); } } }); }