Java Code Examples for androidx.core.view.ViewCompat#isAttachedToWindow()
The following examples show how to use
androidx.core.view.ViewCompat#isAttachedToWindow() .
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: BottomSheetBehavior.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
private void settleToStatePendingLayout(@State int state) { final V child = viewRef.get(); if (child == null) { return; } // Start the animation; wait until a pending layout if there is one. ViewParent parent = child.getParent(); if (parent != null && parent.isLayoutRequested() && ViewCompat.isAttachedToWindow(child)) { final int finalState = state; child.post( new Runnable() { @Override public void run() { settleToState(child, finalState); } }); } else { settleToState(child, state); } }
Example 2
Source File: GalleryDetailScene.java From EhViewer with Apache License 2.0 | 6 votes |
private boolean createCircularReveal() { if (mColorBg == null) { return false; } int w = mColorBg.getWidth(); int h = mColorBg.getHeight(); if (ViewCompat.isAttachedToWindow(mColorBg) && w != 0 && h != 0) { Resources resources = getContext2().getResources(); int keylineMargin = resources.getDimensionPixelSize(R.dimen.keyline_margin); int thumbWidth = resources.getDimensionPixelSize(R.dimen.gallery_detail_thumb_width); int thumbHeight = resources.getDimensionPixelSize(R.dimen.gallery_detail_thumb_height); int x = thumbWidth / 2 + keylineMargin; int y = thumbHeight / 2 + keylineMargin; int radiusX = Math.max(Math.abs(x), Math.abs(w - x)); int radiusY = Math.max(Math.abs(y), Math.abs(h - y)); float radius = (float) Math.hypot(radiusX, radiusY); ViewAnimationUtils.createCircularReveal(mColorBg, x, y, 0, radius).setDuration(300).start(); return true; } else { return false; } }
Example 3
Source File: FuncView.java From pandora with Apache License 2.0 | 6 votes |
public boolean open() { if (ViewCompat.isAttachedToWindow(this)) { return true; } WindowManager.LayoutParams params = new WindowManager.LayoutParams(); params.width = WindowManager.LayoutParams.WRAP_CONTENT; params.height = ViewKnife.dip2px(62); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; } else { params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; } params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; params.format = PixelFormat.TRANSLUCENT; params.gravity = Gravity.TOP | Gravity.START; params.x = 0; params.y = (int) Config.getDragY(); return Utils.addViewToWindow(this, params); }
Example 4
Source File: GalleryDetailScene.java From MHViewer with Apache License 2.0 | 6 votes |
private boolean createCircularReveal() { if (mColorBg == null) { return false; } int w = mColorBg.getWidth(); int h = mColorBg.getHeight(); if (ViewCompat.isAttachedToWindow(mColorBg) && w != 0 && h != 0) { Resources resources = getContext2().getResources(); int keylineMargin = resources.getDimensionPixelSize(R.dimen.keyline_margin); int thumbWidth = resources.getDimensionPixelSize(R.dimen.gallery_detail_thumb_width); int thumbHeight = resources.getDimensionPixelSize(R.dimen.gallery_detail_thumb_height); int x = thumbWidth / 2 + keylineMargin; int y = thumbHeight / 2 + keylineMargin; int radiusX = Math.max(Math.abs(x), Math.abs(w - x)); int radiusY = Math.max(Math.abs(y), Math.abs(h - y)); float radius = (float) Math.hypot(radiusX, radiusY); ViewAnimationUtils.createCircularReveal(mColorBg, x, y, 0, radius).setDuration(300).start(); return true; } else { return false; } }
Example 5
Source File: BottomSheetBehavior.java From bottomsheetrecycler with Apache License 2.0 | 6 votes |
private void startSettlingAnimationPendingLayout(@State int state) { final V child = viewRef.get(); if (child == null) { return; } // Start the animation; wait until a pending layout if there is one. ViewParent parent = child.getParent(); if (parent != null && parent.isLayoutRequested() && ViewCompat.isAttachedToWindow(child)) { final int finalState = state; child.post( new Runnable() { @Override public void run() { startSettlingAnimation(child, finalState); } }); } else { startSettlingAnimation(child, state); } }
Example 6
Source File: DynamicTooltip.java From dynamic-support with Apache License 2.0 | 5 votes |
/** * Show the tooltip. * * @param fromTouch {@code true} to show from the touch. */ private void show(boolean fromTouch) { if (!ViewCompat.isAttachedToWindow(mAnchor)) { return; } setPendingHandler(null); if (sActiveHandler != null) { sActiveHandler.hide(); } sActiveHandler = this; mFromTouch = fromTouch; mPopup = new DynamicTooltipPopup(mAnchor.getContext(), mBackgroundColor, mTintColor); mPopup.show(mAnchor, mAnchorX, mAnchorY, mFromTouch, mTooltipIcon, mTooltipText); // Only listen for attach state change while the popup is being shown. mAnchor.addOnAttachStateChangeListener(this); final long timeout; if (mFromTouch) { timeout = LONG_CLICK_HIDE_TIMEOUT_MS; } else if ((ViewCompat.getWindowSystemUiVisibility(mAnchor) & SYSTEM_UI_FLAG_LOW_PROFILE) == SYSTEM_UI_FLAG_LOW_PROFILE) { timeout = HOVER_HIDE_TIMEOUT_SHORT_MS - ViewConfiguration.getLongPressTimeout(); } else { timeout = HOVER_HIDE_TIMEOUT_MS - ViewConfiguration.getLongPressTimeout(); } mAnchor.removeCallbacks(mHideRunnable); mAnchor.postDelayed(mHideRunnable, timeout); }
Example 7
Source File: FloatingView.java From FloatingView with Apache License 2.0 | 5 votes |
/** * Check if it is attached to the Window and call WindowManager.updateLayout() */ private void updateViewLayout() { if (!ViewCompat.isAttachedToWindow(this)) { return; } mWindowManager.updateViewLayout(this, mParams); }
Example 8
Source File: ProgressView.java From EhViewer with Apache License 2.0 | 5 votes |
@Override public void setVisibility(int v) { if (getVisibility() != v) { super.setVisibility(v); if (mIndeterminate) { if (v == GONE || v == INVISIBLE) { stopAnimation(); } else if (ViewCompat.isAttachedToWindow(this)) { startAnimation(); } } } }
Example 9
Source File: NotePreviewFragment.java From nextcloud-notes with GNU General Public License v3.0 | 5 votes |
@Override protected void colorWithText(@NonNull String newText, @Nullable Integer current, int mainColor, int textColor) { if (binding != null && ViewCompat.isAttachedToWindow(binding.singleNoteContent)) { binding.singleNoteContent.setText( searchAndColor(new SpannableString(parseCompat(markdownProcessor, getContent())), newText, requireContext(), current, mainColor, textColor), TextView.BufferType.SPANNABLE); } }
Example 10
Source File: SkinCompatDelegate.java From Android-skin-support with MIT License | 5 votes |
private boolean shouldInheritContext(ViewParent parent) { if (parent == null) { // The initial parent is null so just return false return false; } if (mContext instanceof Activity) { final View windowDecor = ((Activity) mContext).getWindow().getDecorView(); while (true) { if (parent == null) { // Bingo. We've hit a view which has a null parent before being terminated from // the loop. This is (most probably) because it's the root view in an inflation // call, therefore we should inherit. This works as the inflated layout is only // added to the hierarchy at the end of the inflate() call. return true; } else if (parent == windowDecor || !(parent instanceof View) || ViewCompat.isAttachedToWindow((View) parent)) { // We have either hit the window's decor view, a parent which isn't a View // (i.e. ViewRootImpl), or an attached view, so we know that the original parent // is currently added to the view hierarchy. This means that it has not be // inflated in the current inflate() call and we should not inherit the context. return false; } parent = parent.getParent(); } } return false; }
Example 11
Source File: SkinAppCompatViewInflater.java From Android-skin-support with MIT License | 5 votes |
private boolean shouldInheritContext(Context context, ViewParent parent) { if (parent == null) { // The initial parent is null so just return false return false; } if (context instanceof Activity) { final View windowDecor = ((Activity) context).getWindow().getDecorView(); while (true) { if (parent == null) { // Bingo. We've hit a view which has a null parent before being terminated from // the loop. This is (most probably) because it's the root view in an inflation // call, therefore we should inherit. This works as the inflated layout is only // added to the hierarchy at the end of the inflate() call. return true; } else if (parent == windowDecor || !(parent instanceof View) || ViewCompat.isAttachedToWindow((View) parent)) { // We have either hit the window's decor view, a parent which isn't a View // (i.e. ViewRootImpl), or an attached view, so we know that the original parent // is currently added to the view hierarchy. This means that it has not be // inflated in the current inflate() call and we should not inherit the context. return false; } parent = parent.getParent(); } } return false; }
Example 12
Source File: ViewOverlayApi14.java From material-components-android with Apache License 2.0 | 5 votes |
public void add(View child) { assertNotDisposed(); if (child.getParent() instanceof ViewGroup) { ViewGroup parent = (ViewGroup) child.getParent(); if (parent != hostView && parent.getParent() != null && ViewCompat.isAttachedToWindow(parent)) { // Moving to different container; figure out how to position child such that // it is in the same location on the screen int[] parentLocation = new int[2]; int[] hostViewLocation = new int[2]; parent.getLocationOnScreen(parentLocation); hostView.getLocationOnScreen(hostViewLocation); ViewCompat.offsetLeftAndRight(child, parentLocation[0] - hostViewLocation[0]); ViewCompat.offsetTopAndBottom(child, parentLocation[1] - hostViewLocation[1]); } parent.removeView(child); // if (parent.getLayoutTransition() != null) { // // LayoutTransition will cause the child to delay removal - cancel it // parent.getLayoutTransition().cancel(LayoutTransition.DISAPPEARING); // } // fail-safe if view is still attached for any reason if (child.getParent() != null) { parent.removeView(child); } } super.addView(child); }
Example 13
Source File: HasOnViewAttachListener.java From grblcontroller with GNU General Public License v3.0 | 5 votes |
public void setOnViewAttachListener(OnViewAttachListener listener) { if (this.listener != null) this.listener.onDetach(); this.listener = listener; if (ViewCompat.isAttachedToWindow(view) && listener != null) { listener.onAttach(); } }
Example 14
Source File: CustomScrollView.java From FirefoxReality with Mozilla Public License 2.0 | 5 votes |
@Override protected void onVisibilityChanged(View changedView, int visibility) { super.onVisibilityChanged(changedView, visibility); if (visibility == VISIBLE) { if (ViewCompat.isAttachedToWindow(this)) { initialAwakenScrollBars(); } } }
Example 15
Source File: ProgressView.java From EhViewer with Apache License 2.0 | 5 votes |
@Override protected void onVisibilityChanged(@NonNull View changedView, int visibility) { super.onVisibilityChanged(changedView, visibility); if (mIndeterminate && ViewCompat.isAttachedToWindow(this)) { if (visibility == GONE || visibility == INVISIBLE) { stopAnimation(); } else if (ViewCompat.isAttachedToWindow(this)) { startAnimation(); } } }
Example 16
Source File: FloatingView.java From dingo with GNU General Public License v3.0 | 5 votes |
/** * Check if it is attached to the Window and call WindowManager.updateLayout() */ private void updateViewLayout() { if (!ViewCompat.isAttachedToWindow(this)) { return; } mWindowManager.updateViewLayout(this, mParams); }
Example 17
Source File: MaterialScrollBar.java From MaterialScrollBar with Apache License 2.0 | 5 votes |
/** * The scrollBar should attempt to use dev provided scrolling logic and not default logic. * * The adapter must implement {@link ICustomScroller}. */ private void checkCustomScrolling() { if(ViewCompat.isAttachedToWindow(this)) { checkCustomScrollingInterface(); } else { addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { MaterialScrollBar.this.removeOnLayoutChangeListener(this); checkCustomScrollingInterface(); } }); } }
Example 18
Source File: ProgressView.java From MHViewer with Apache License 2.0 | 5 votes |
@Override public void setVisibility(int v) { if (getVisibility() != v) { super.setVisibility(v); if (mIndeterminate) { if (v == GONE || v == INVISIBLE) { stopAnimation(); } else if (ViewCompat.isAttachedToWindow(this)) { startAnimation(); } } } }
Example 19
Source File: CurInfoView.java From pandora with Apache License 2.0 | 4 votes |
public boolean isOpen() { return ViewCompat.isAttachedToWindow(this); }
Example 20
Source File: GridLineView.java From pandora with Apache License 2.0 | 4 votes |
public boolean isOpen() { return ViewCompat.isAttachedToWindow(this); }