Example usage for android.view View getGlobalVisibleRect

List of usage examples for android.view View getGlobalVisibleRect

Introduction

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

Prototype

public final boolean getGlobalVisibleRect(Rect r) 

Source Link

Usage

From source file:com.chromium.fontinstaller.util.ViewUtils.java

public static void reveal(Activity activity, View view, View sourceView, int colorRes) {
    if (activity == null || view == null || sourceView == null)
        return;//from  ww w .  j a  v  a 2s. c  o m
    if (isLollipop()) {
        final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) activity.getWindow().getDecorView()
                .getOverlay();

        final Rect displayRect = new Rect();
        view.getGlobalVisibleRect(displayRect);

        // Make reveal cover the display and status bar.
        final View revealView = new View(activity);
        revealView.setTop(displayRect.top);
        revealView.setBottom(displayRect.bottom);
        revealView.setLeft(displayRect.left);
        revealView.setRight(displayRect.right);
        revealView.setBackgroundColor(ContextCompat.getColor(activity, colorRes));
        groupOverlay.add(revealView);

        final int[] clearLocation = new int[2];
        sourceView.getLocationInWindow(clearLocation);
        clearLocation[0] += sourceView.getWidth() / 2;
        clearLocation[1] += sourceView.getHeight() / 2;

        final int revealCenterX = clearLocation[0] - revealView.getLeft();
        final int revealCenterY = clearLocation[1] - revealView.getTop();

        final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
        final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
        final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
        final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

        try {
            final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
                    revealCenterY, 0.0f, revealRadius);
            revealAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_mediumAnimTime));

            final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
            alphaAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_shortAnimTime));
            alphaAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.abc_fade_in));
                    view.setVisibility(View.VISIBLE);
                }
            });

            final AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.play(revealAnimator).before(alphaAnimator);
            animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    groupOverlay.remove(revealView);
                }
            });

            animatorSet.start();
        } catch (IllegalStateException e) {
            Timber.i("View is detached - not animating");
        }
    } else {
        view.setVisibility(View.VISIBLE);
    }
}

From source file:com.google.android.apps.common.testing.accessibility.framework.ViewAccessibilityUtils.java

/**
 * Determines if the supplied {@link View} is visible to the user, which requires that it be
 * marked visible, that all its parents are visible, that it and all parents have alpha
 * greater than 0, and that it has non-zero size. This code attempts to replicate the protected
 * method {@code View.isVisibleToUser}.//from w w w. jav a  2  s  . c o  m
 *
 * @param view The {@link View} to evaluate
 * @return {@code true} if {@code view} is visible to the user
 */
public static boolean isVisibleToUser(View view) {
    if (view == null) {
        return false;
    }

    Object current = view;
    while (current instanceof View) {
        View currentView = (View) current;
        if ((ViewCompat.getAlpha(currentView) <= 0) || (currentView.getVisibility() != View.VISIBLE)) {
            return false;
        }
        current = currentView.getParent();
    }
    return view.getGlobalVisibleRect(new Rect());
}

From source file:org.onebusaway.android.util.UIUtils.java

/**
 * Returns true if the provided touch event was within the provided view
 *
 * @return true if the provided touch event was within the provided view
 *//*from   w  w  w .j a v  a  2  s.co m*/
public static boolean isTouchInView(View view, MotionEvent event) {
    Rect rect = new Rect();
    view.getGlobalVisibleRect(rect);
    return rect.contains((int) event.getRawX(), (int) event.getRawY());
}

From source file:tyrantgit.explosionfield.ExplosionField.java

public void explode(final View view) {
    Rect r = new Rect();
    view.getGlobalVisibleRect(r);
    int[] location = new int[2];
    getLocationOnScreen(location);//from  ww  w .  j ava2 s.  c o  m
    r.offset(-location[0], -location[1]);
    r.inset(-mExpandInset[0], -mExpandInset[1]);
    int startDelay = 100;
    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration(150);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        Random random = new Random();

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {

            ViewCompat.setTranslationX(view, (random.nextFloat() - 0.5f) * view.getWidth() * 0.05f);
            ViewCompat.setTranslationY(view, (random.nextFloat() - 0.5f) * view.getHeight() * 0.05f);

        }
    });
    animator.start();
    //ViewCompat.animate(view)
    ViewCompat.animate(view).setDuration(150).setStartDelay(startDelay).scaleX(0f).scaleY(0f).alpha(0f).start();
    explode(Utils.createBitmapFromView(view), r, startDelay, ExplosionAnimator.DEFAULT_DURATION);
}

From source file:org.ayo.robot.anim.transitioneverywhere.ExplodeAndEpicenterExample.java

private void letsExplodeIt(View clickedView) {
    // save rect of view in screen coordinated
    final Rect viewRect = new Rect();
    clickedView.getGlobalVisibleRect(viewRect);

    TransitionSet set = new TransitionSet()
            .addTransition(new Explode().setEpicenterCallback(new Transition.EpicenterCallback() {
                @Override/*from   w  w  w  .  j a  v a2  s  . c o  m*/
                public Rect onGetEpicenter(Transition transition) {
                    return viewRect;
                }
            }).excludeTarget(clickedView, true)).addTransition(new Fade().addTarget(clickedView))
            .addListener(new Transition.TransitionListenerAdapter() {
                @Override
                public void onTransitionEnd(Transition transition) {
                    getActivity().onBackPressed();
                }
            });
    TransitionManager.beginDelayedTransition(mRecyclerView, set);

    // remove all views from Recycler View
    mRecyclerView.setAdapter(null);
}

From source file:com.smoothsync.smoothsetup.MicroFragmentHostActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.smoothsetup_activity_microfragment_host);

    mCollapsingToolbar = findViewById(R.id.collapsing_toolbar);
    setSupportActionBar(mCollapsingToolbar.findViewById(R.id.toolbar));
    mActionBar = getSupportActionBar();/*from  ww  w  .  j a  v a  2  s.  c  o  m*/
    mMicroFragmentStateDovecote = new ParcelableDovecote<>(this, "hostactivity", this);
    mBackDovecote = new BooleanDovecote(this, "backresult", aBoolean -> {
        if (!aBoolean) {
            finish();
        }
    });

    if (savedInstanceState == null) {
        // load the initial MicroFragment
        Bundle nestedExtras = getIntent().getBundleExtra("org.dmfs.nestedExtras");
        MicroFragment<?> initialMicroFragment = nestedExtras.getParcelable("MicroFragment");
        mMicroFragmentHost = new SimpleMicroFragmentFlow(initialMicroFragment, R.id.microfragment_host)
                .withPigeonCage(mMicroFragmentStateDovecote.cage()).start(this);
    } else {
        mMicroFragmentHost = savedInstanceState.getParcelable("microfragmenthost");
    }
    mAppBarLayout = findViewById(R.id.appbar);
    mFragmentHostView = findViewById(R.id.microfragment_host);
    mFragmentHostView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
        // collapse appbar if the microfragment content doesn't fit on the screen
        Rect windowRect = new Rect();
        mAppBarLayout.getWindowVisibleDisplayFrame(windowRect);

        FrameLayout bottomView = mFragmentHostView
                .findViewById(org.dmfs.android.microfragments.R.id.microfragments_host);
        if (bottomView.getChildCount() > 0) {
            View childView = bottomView.getChildAt(0);
            Rect childRect = new Rect();
            childView.getGlobalVisibleRect(childRect);
            if (!"collapsed".equals(childView.getTag()) && !windowRect.contains(childRect)) {
                mAppBarLayout.postDelayed(() -> mAppBarLayout.setExpanded(false, true), 100);
                // tag the child as "collapsed" so we don't collapse it again while visible
                childView.setTag("collapsed");
            }
        }
    });
}

From source file:org.mozilla.search.autocomplete.SuggestionsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    suggestionsList = (ListView) inflater.inflate(R.layout.search_sugestions, container, false);
    suggestionsList.setAdapter(autoCompleteAdapter);

    // Attach listener for tapping on a suggestion.
    suggestionsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from  w ww.j  ava  2 s.c o  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final Suggestion suggestion = (Suggestion) suggestionsList.getItemAtPosition(position);

            final Rect startBounds = new Rect();
            view.getGlobalVisibleRect(startBounds);

            // The user tapped on a suggestion from the search engine.
            Telemetry.sendUIEvent(TelemetryContract.Event.SEARCH, TelemetryContract.Method.SUGGESTION,
                    position);

            searchListener.onSearch(suggestion.value, new SuggestionAnimation() {
                @Override
                public Rect getStartBounds() {
                    return startBounds;
                }
            });
        }
    });

    return suggestionsList;
}

From source file:org.mozilla.search.PreSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    final View mainView = inflater.inflate(R.layout.search_fragment_pre_search, container, false);

    // Initialize listview.
    listView = (ListView) mainView.findViewById(R.id.list_view);
    listView.setAdapter(cursorAdapter);/*from w w w  .  ja  v a2  s  .  c  o m*/
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final String query = getQueryAtPosition(position);
            if (!TextUtils.isEmpty(query)) {
                final Rect startBounds = new Rect();
                view.getGlobalVisibleRect(startBounds);

                Telemetry.sendUIEvent(TelemetryContract.Event.SEARCH, TelemetryContract.Method.HOMESCREEN,
                        "history");

                searchListener.onSearch(query, new SuggestionAnimation() {
                    @Override
                    public Rect getStartBounds() {
                        return startBounds;
                    }
                });
            }
        }
    });

    // Create a ListView-specific touch listener. ListViews are given special treatment because
    // by default they handle touches for their list items... i.e. they're in charge of drawing
    // the pressed state (the list selector), handling list item clicks, etc.
    final SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(listView,
            new OnDismissCallback() {
                @Override
                public void onDismiss(ListView listView, final int position) {
                    new AsyncTask<Void, Void, Void>() {
                        @Override
                        protected Void doInBackground(Void... params) {
                            final String query = getQueryAtPosition(position);
                            final int deleted = getActivity().getContentResolver().delete(
                                    SearchHistory.CONTENT_URI, SearchHistory.QUERY + " = ?",
                                    new String[] { query });

                            if (deleted < 1) {
                                Log.w(LOG_TAG, "Search query not deleted: " + query);
                            }
                            return null;
                        }
                    }.execute();
                }
            });
    listView.setOnTouchListener(touchListener);

    // Setting this scroll listener is required to ensure that during ListView scrolling,
    // we don't look for swipes.
    listView.setOnScrollListener(touchListener.makeScrollListener());

    // Setting this recycler listener is required to make sure animated views are reset.
    listView.setRecyclerListener(touchListener.makeRecyclerListener());

    return mainView;
}

From source file:com.ylw.split.splitview.view.SplitView3.java

/**
 * ??view/*  w  w  w .j  av a2 s . c o  m*/
 *
 * @param v
 * @param e
 */
private void initDragView(View v, MotionEvent e) {
    if (v != null) {
        if (v.getGlobalVisibleRect(r)) {
            if (r.contains((int) e.getX(), (int) e.getY())) {
                dragView = v;
            }
        }
    }
}

From source file:com.android.messaging.ui.mediapicker.AudioListView.java

@Override
public void onItemClicked(final View view, final AudioListItemData data, final boolean longClick) {
    if (ContentType.isMediaType(data.getContentType())) {
        if (longClick) {
            // Turn on multi-select mode when an item is long-pressed.
            setMultiSelectEnabled(true);
        }/*www. j  av a2  s  .  co  m*/

        final Rect startRect = new Rect();
        view.getGlobalVisibleRect(startRect);
        if (isMultiSelectEnabled()) {
            toggleItemSelection(startRect, data);
        } else {
            mListener.onItemSelected(data.constructMessagePartData(startRect));
        }
    } else {
        LogUtil.w(LogUtil.BUGLE_TAG, "Selected item has invalid contentType " + data.getContentType());
    }
}