Example usage for android.view View isAttachedToWindow

List of usage examples for android.view View isAttachedToWindow

Introduction

In this page you can find the example usage for android.view View isAttachedToWindow.

Prototype

public boolean isAttachedToWindow() 

Source Link

Document

Returns true if this view is currently attached to a window.

Usage

From source file:Main.java

public static void circleReveal(final View targetView, int centerX, int centerY, boolean isReverse) {
    if (targetView == null || !targetView.isAttachedToWindow())
        return;/*from   www  .j  av a  2s.c o m*/
    int radius = (int) Math.hypot(targetView.getHeight(), targetView.getWidth());

    Animator animator;
    if (isReverse) {
        animator = isCircleRevealSupported()
                ? ViewAnimationUtils.createCircularReveal(targetView, centerX, centerY, radius, 0)
                : createFade(targetView, 1, 0);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                targetView.setVisibility(View.GONE);
            }
        });
    } else {
        animator = isCircleRevealSupported()
                ? ViewAnimationUtils.createCircularReveal(targetView, centerX, centerY, 0, radius)
                : createFade(targetView, 0, 1);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                targetView.setVisibility(View.VISIBLE);
            }
        });
    }
    animator.setDuration(DURATION);
    animator.start();
}

From source file:com.example.ray.firstapp.bottombar.MiscUtils.java

/**
 * Animate a background color change. Uses Circular Reveal if supported,
 * otherwise crossfades the background color in.
 *
 * @param clickedView    the view that was clicked for calculating the start position
 *                       for the Circular Reveal.
 * @param backgroundView the currently showing background color.
 * @param bgOverlay      the overlay view for the new background color that will be
 *                       animated in./*ww w  .  j  a  va2  s.com*/
 * @param newColor       the new color.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected static void animateBGColorChange(View clickedView, final View backgroundView, final View bgOverlay,
        final int newColor) {
    int centerX = (int) (ViewCompat.getX(clickedView) + (clickedView.getMeasuredWidth() / 2));
    int centerY = clickedView.getMeasuredHeight() / 2;
    int finalRadius = backgroundView.getWidth();

    backgroundView.clearAnimation();
    bgOverlay.clearAnimation();

    Object animator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (!bgOverlay.isAttachedToWindow()) {
            return;
        }

        animator = ViewAnimationUtils.createCircularReveal(bgOverlay, centerX, centerY, 0, finalRadius);
    } else {
        ViewCompat.setAlpha(bgOverlay, 0);
        animator = ViewCompat.animate(bgOverlay).alpha(1);
    }

    if (animator instanceof ViewPropertyAnimatorCompat) {
        ((ViewPropertyAnimatorCompat) animator).setListener(new ViewPropertyAnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(View view) {
                onCancel();
            }

            @Override
            public void onAnimationCancel(View view) {
                onCancel();
            }

            private void onCancel() {
                backgroundView.setBackgroundColor(newColor);
                bgOverlay.setVisibility(View.INVISIBLE);
                ViewCompat.setAlpha(bgOverlay, 1);
            }
        }).start();
    } else if (animator != null) {
        ((Animator) animator).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                onCancel();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                onCancel();
            }

            private void onCancel() {
                backgroundView.setBackgroundColor(newColor);
                bgOverlay.setVisibility(View.INVISIBLE);
                ViewCompat.setAlpha(bgOverlay, 1);
            }
        });

        ((Animator) animator).start();
    }

    bgOverlay.setBackgroundColor(newColor);
    bgOverlay.setVisibility(View.VISIBLE);
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean isViewAttachedToWindow(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return v.isAttachedToWindow();
    } else {/*from www. ja va 2 s. co m*/
        // A proxy call which returns null, if the view is not attached to the window.
        return v.getKeyDispatcherState() != null;
    }
}

From source file:com.ruesga.rview.fragments.RevealDialogFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void performEnterRevealTransition() {
    if (!mDoReveal || getDialog() == null || getDialog().getWindow() == null) {
        mDoReveal = false;//from   ww w  .ja  va  2  s.  c  o m
        return;
    }

    final View v = getDialog().getWindow().getDecorView();
    if (!v.isAttachedToWindow()) {
        mDoReveal = false;
        return;
    }
    v.setVisibility(View.VISIBLE);
    Rect dialogRect = computeViewOnScreen(v);

    int cx = v.getMeasuredWidth() / 2;
    int cy = v.getMeasuredHeight() / 2;
    if (mAnchorRect != null) {
        cx = Math.min(Math.max(mAnchorRect.centerX(), dialogRect.left), dialogRect.right) - dialogRect.left;
        cy = Math.min(Math.max(mAnchorRect.centerY(), dialogRect.top), dialogRect.bottom) - dialogRect.top;
    }

    int finalRadius = Math.max(v.getWidth(), v.getHeight());
    Animator anim = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, finalRadius);
    anim.setDuration(350);
    anim.setInterpolator(new AccelerateInterpolator());
    anim.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            onDialogReveled();
            mDoReveal = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    anim.start();
}

From source file:com.fastbootmobile.encore.app.PlaylistActivity.java

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    setContentView(R.layout.activity_playlist);

    FragmentManager fm = getSupportFragmentManager();
    mActiveFragment = (PlaylistViewFragment) fm.findFragmentByTag(TAG_FRAGMENT);
    if (savedInstance == null) {
        mInitialIntent = getIntent().getExtras();
    } else {//from  w  ww  .ja v a  2  s .com
        mInitialIntent = savedInstance.getBundle(EXTRA_RESTORE_INTENT);
    }

    if (mActiveFragment == null) {
        mActiveFragment = new PlaylistViewFragment();
        fm.beginTransaction().add(R.id.playlist_container, mActiveFragment, TAG_FRAGMENT).commit();
        mActiveFragment.setArguments(mInitialIntent);
    }

    // Remove the activity title as we don't want it here
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setTitle("");
    }

    mIsEntering = true;

    if (Utils.hasLollipop()) {
        setEnterSharedElementCallback(new SharedElementCallback() {
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                View imageHeader = mActiveFragment.getHeroImageView();
                if (imageHeader != null) {
                    sharedElements.put("itemImage", imageHeader);
                }

                View albumName = mActiveFragment.findViewById(R.id.tvAlbumName);
                if (albumName != null) {
                    final int cx = albumName.getMeasuredWidth() / 4;
                    final int cy = albumName.getMeasuredHeight() / 2;
                    final int duration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
                    final int radius = Utils.getEnclosingCircleRadius(albumName, cx, cy);

                    if (albumName.isAttachedToWindow()) {
                        if (mIsEntering) {
                            albumName.setVisibility(View.INVISIBLE);
                            Utils.animateCircleReveal(albumName, cx, cy, 0, radius, duration, 300);
                        } else {
                            albumName.setVisibility(View.VISIBLE);
                            Utils.animateCircleReveal(albumName, cx, cy, radius, 0, duration, 0);
                        }
                    }
                }
            }
        });
    }

    getWindow().getDecorView()
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

From source file:org.telegram.ui.Components.ChatAttachAlert.java

private void checkCameraViewPosition() {
    if (!deviceHasGoodCamera) {
        return;/*from ww  w .j  a  va 2  s  . c o m*/
    }
    int count = attachPhotoRecyclerView.getChildCount();
    for (int a = 0; a < count; a++) {
        View child = attachPhotoRecyclerView.getChildAt(a);
        if (child instanceof PhotoAttachCameraCell) {
            if (Build.VERSION.SDK_INT >= 19) {
                if (!child.isAttachedToWindow()) {
                    break;
                }
            }
            child.getLocationInWindow(cameraViewLocation);
            float listViewX = listView.getX() + backgroundPaddingLeft;
            if (cameraViewLocation[0] < listViewX) {
                cameraViewOffsetX = (int) (listViewX - cameraViewLocation[0]);
                if (cameraViewOffsetX >= AndroidUtilities.dp(80)) {
                    cameraViewOffsetX = 0;
                    cameraViewLocation[0] = AndroidUtilities.dp(-100);
                    cameraViewLocation[1] = 0;
                } else {
                    cameraViewLocation[0] += cameraViewOffsetX;
                }
            } else {
                cameraViewOffsetX = 0;
            }
            if (Build.VERSION.SDK_INT >= 21 && cameraViewLocation[1] < AndroidUtilities.statusBarHeight) {
                cameraViewOffsetY = AndroidUtilities.statusBarHeight - cameraViewLocation[1];
                if (cameraViewOffsetY >= AndroidUtilities.dp(80)) {
                    cameraViewOffsetY = 0;
                    cameraViewLocation[0] = AndroidUtilities.dp(-100);
                    cameraViewLocation[1] = 0;
                } else {
                    cameraViewLocation[1] += cameraViewOffsetY;
                }
            } else {
                cameraViewOffsetY = 0;
            }
            applyCameraViewPosition();
            return;
        }
    }
    cameraViewOffsetX = 0;
    cameraViewOffsetY = 0;
    cameraViewLocation[0] = AndroidUtilities.dp(-100);
    cameraViewLocation[1] = 0;
    applyCameraViewPosition();
}