List of usage examples for android.view ViewTreeObserver removeGlobalOnLayoutListener
@Deprecated public void removeGlobalOnLayoutListener(OnGlobalLayoutListener victim)
From source file:com.miz.functions.MizLib.java
/** * Helper method to remove a ViewTreeObserver correctly, i.e. * avoiding the deprecated method on API level 16+. * @param vto/* ww w . j a v a 2s.com*/ * @param victim */ @SuppressWarnings("deprecation") public static void removeViewTreeObserver(ViewTreeObserver vto, OnGlobalLayoutListener victim) { if (MizLib.hasJellyBean()) { vto.removeOnGlobalLayoutListener(victim); } else { vto.removeGlobalOnLayoutListener(victim); } }
From source file:com.quran.labs.androidquran.widgets.spinner.SpinnerCompat.java
@Override public void onRestoreInstanceState(Parcelable state) { super.onRestoreInstanceState(state); if (((AbsSpinnerCompat.SavedState) state).showDropdown) { ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) { final ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override//from w w w .ja va 2 s. c o m public void onGlobalLayout() { if (!mPopup.isShowing()) { mPopup.show(); } final ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) { vto.removeGlobalOnLayoutListener(this); } } }; vto.addOnGlobalLayoutListener(listener); } } }
From source file:android.support.v7.internal.widget.SpinnerCompat.java
@Override public void onRestoreInstanceState(Parcelable state) { SavedState ss = (SavedState) state;// ww w . j av a2s. c om super.onRestoreInstanceState(ss.getSuperState()); if (ss.showDropdown) { ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) { final ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (!mPopup.isShowing()) { mPopup.show(); } final ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) { vto.removeGlobalOnLayoutListener(this); } } }; vto.addOnGlobalLayoutListener(listener); } } }
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(); }/* w w w . j a v a2 s . co 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: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;/*from w w w . j a va2s. 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.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. *//* ww w. j a v a 2 s. co 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:de.dreier.mytargets.views.MaterialTapTargetPrompt.java
/** * Removes global layout listener added in {@link #addGlobalLayoutListener()}. *///from www . j av a 2 s. c o m private 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.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;/* w w w .j a v a 2 s .com*/ } 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:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java
/** * Removes global layout listener added in {@link #addGlobalLayoutListener()}. *//*from w w w .j ava 2s . co m*/ 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.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(); }//from w ww .j a va 2 s . c o m 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); } } }); }