android.view.View.OnLayoutChangeListener Java Examples

The following examples show how to use android.view.View.OnLayoutChangeListener. 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: GridFragment.java    From animation-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Scrolls the recycler view to show the last viewed item in the grid. This is important when
 * navigating back from the grid.
 */
private void scrollToPosition() {
  recyclerView.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) {
      recyclerView.removeOnLayoutChangeListener(this);
      final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
      View viewAtPosition = layoutManager.findViewByPosition(MainActivity.currentPosition);
      // Scroll to position if the view for the current position is null (not currently part of
      // layout manager children), or it's not completely visible.
      if (viewAtPosition == null || layoutManager
          .isViewPartiallyVisible(viewAtPosition, false, true)) {
        recyclerView.post(() -> layoutManager.scrollToPosition(MainActivity.currentPosition));
      }
    }
  });
}
 
Example #2
Source File: CustomTabBottomBarDelegate.java    From delion with Apache License 2.0 6 votes vote down vote up
private void hideBottomBar() {
    if (mBottomBarView == null) return;
    ((ViewGroup) mBottomBarView.getParent()).removeView(mBottomBarView);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.BOTTOM;
    final ViewGroup compositorView = mActivity.getCompositorViewHolder();
    compositorView.addView(mBottomBarView, lp);
    compositorView.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) {
            compositorView.removeOnLayoutChangeListener(this);
            mBottomBarView.animate().alpha(0f).translationY(mBottomBarView.getHeight())
                    .setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE)
                    .setDuration(SLIDE_ANIMATION_DURATION_MS)
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {
                            ((ViewGroup) mBottomBarView.getParent()).removeView(mBottomBarView);
                            mBottomBarView = null;
                        }
                    }).start();
        }
    });
}
 
Example #3
Source File: FocusAnimator.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs the {@link FocusAnimator}.
 *
 * To get the correct values to animate between, this should be called immediately before the
 * children of the layout are remeasured.
 *
 * @param layout       Layout being animated.
 * @param focusedChild Child being focused, or null if none is being focused.
 * @param callback     Callback to run when children are in the correct places.
 */
public FocusAnimator(
        LinearLayout layout, @Nullable View focusedChild, final Runnable callback) {
    mLayout = layout;
    mFocusedChild = focusedChild;
    mInitialNumberOfChildren = mLayout.getChildCount();
    mInitialTops = calculateChildTops();

    // Add a listener to know when Android has done another measurement pass.  The listener
    // automatically removes itself to prevent triggering the animation multiple times.
    mLayout.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) {
            mLayout.removeOnLayoutChangeListener(this);
            startAnimator(callback);
        }
    });
}
 
Example #4
Source File: CustomTabBottomBarDelegate.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void hideBottomBar() {
    if (mBottomBarView == null) return;
    ((ViewGroup) mBottomBarView.getParent()).removeView(mBottomBarView);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.BOTTOM;
    final ViewGroup compositorView = mActivity.getCompositorViewHolder();
    compositorView.addView(mBottomBarView, lp);
    compositorView.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) {
            compositorView.removeOnLayoutChangeListener(this);
            mBottomBarView.animate().alpha(0f).translationY(mBottomBarView.getHeight())
                    .setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE)
                    .setDuration(SLIDE_ANIMATION_DURATION_MS)
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {
                            ((ViewGroup) mBottomBarView.getParent()).removeView(mBottomBarView);
                            mBottomBarView = null;
                        }
                    }).start();
        }
    });
}
 
Example #5
Source File: FocusAnimator.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs the {@link FocusAnimator}.
 *
 * To get the correct values to animate between, this should be called immediately before the
 * children of the layout are remeasured.
 *
 * @param layout       Layout being animated.
 * @param focusedChild Child being focused, or null if none is being focused.
 * @param callback     Callback to run when children are in the correct places.
 */
public FocusAnimator(
        LinearLayout layout, @Nullable View focusedChild, final Runnable callback) {
    mLayout = layout;
    mFocusedChild = focusedChild;
    mInitialNumberOfChildren = mLayout.getChildCount();
    mInitialTops = calculateChildTops();

    // Add a listener to know when Android has done another measurement pass.  The listener
    // automatically removes itself to prevent triggering the animation multiple times.
    mLayout.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) {
            mLayout.removeOnLayoutChangeListener(this);
            startAnimator(callback);
        }
    });
}
 
Example #6
Source File: CustomTabBottomBarDelegate.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void showRemoteViews(RemoteViews remoteViews) {
    final View inflatedView = remoteViews.apply(mActivity, getBottomBarView());
    if (mClickableIDs != null && mClickPendingIntent != null) {
        for (int id: mClickableIDs) {
            if (id < 0) return;
            View view = inflatedView.findViewById(id);
            if (view != null) view.setOnClickListener(mBottomBarClickListener);
        }
    }
    getBottomBarView().addView(inflatedView, 1);
    inflatedView.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) {
            inflatedView.removeOnLayoutChangeListener(this);
            mFullscreenManager.setBottomControlsHeight(v.getHeight());
        }
    });
}
 
Example #7
Source File: FocusAnimator.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs the {@link FocusAnimator}.
 *
 * To get the correct values to animate between, this should be called immediately before the
 * children of the layout are remeasured.
 *
 * @param layout       Layout being animated.
 * @param focusedChild Child being focused, or null if none is being focused.
 * @param callback     Callback to run when children are in the correct places.
 */
public FocusAnimator(
        LinearLayout layout, @Nullable View focusedChild, final Runnable callback) {
    mLayout = layout;
    mFocusedChild = focusedChild;
    mInitialNumberOfChildren = mLayout.getChildCount();
    mInitialTops = calculateChildTops();

    // Add a listener to know when Android has done another measurement pass.  The listener
    // automatically removes itself to prevent triggering the animation multiple times.
    mLayout.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) {
            mLayout.removeOnLayoutChangeListener(this);
            startAnimator(callback);
        }
    });
}
 
Example #8
Source File: SnackbarView.java    From delion with Apache License 2.0 5 votes vote down vote up
void show() {
    addToParent();
    mView.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) {
            mView.removeOnLayoutChangeListener(this);
            mView.setTranslationY(mView.getHeight() + getLayoutParams().bottomMargin);
            Animator animator = ObjectAnimator.ofFloat(mView, View.TRANSLATION_Y, 0);
            animator.setInterpolator(new DecelerateInterpolator());
            animator.setDuration(mAnimationDuration);
            startAnimatorOnSurfaceView(animator);
        }
    });
}
 
Example #9
Source File: SnackbarView.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
void show() {
    addToParent();
    mView.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) {
            mView.removeOnLayoutChangeListener(this);
            mView.setTranslationY(mView.getHeight() + getLayoutParams().bottomMargin);
            Animator animator = ObjectAnimator.ofFloat(mView, View.TRANSLATION_Y, 0);
            animator.setInterpolator(new DecelerateInterpolator());
            animator.setDuration(mAnimationDuration);
            startAnimatorOnSurfaceView(animator);
        }
    });
}
 
Example #10
Source File: SnackbarView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
void show() {
    addToParent();
    mView.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) {
            mView.removeOnLayoutChangeListener(this);
            mView.setTranslationY(mView.getHeight() + getLayoutParams().bottomMargin);
            Animator animator = ObjectAnimator.ofFloat(mView, View.TRANSLATION_Y, 0);
            animator.setInterpolator(new DecelerateInterpolator());
            animator.setDuration(mAnimationDuration);
            startAnimatorOnSurfaceView(animator);
        }
    });
}
 
Example #11
Source File: DropdownPopupWindow.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an DropdownPopupWindow with specified parameters.
 * @param context Application context.
 * @param anchorView Popup view to be anchored.
 */
public DropdownPopupWindow(Context context, View anchorView) {
    super(context, null, 0, R.style.DropdownPopupWindow);
    mContext = context;
    mAnchorView = anchorView;

    mAnchorView.setId(R.id.dropdown_popup_window);
    mAnchorView.setTag(this);

    mLayoutChangeListener = new OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (v == mAnchorView) DropdownPopupWindow.this.show();
        }
    };
    mAnchorView.addOnLayoutChangeListener(mLayoutChangeListener);

    super.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (mOnDismissListener != null) {
                mOnDismissListener.onDismiss();
            }
            mAnchorView.removeOnLayoutChangeListener(mLayoutChangeListener);
            mAnchorView.setTag(null);
        }
    });

    setAnchorView(mAnchorView);
    Rect originalPadding = new Rect();
    getBackground().getPadding(originalPadding);
    setVerticalOffset(-originalPadding.top);
}
 
Example #12
Source File: AutofillPopup.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates an AutofillWindow with specified parameters.
 * @param context Application context.
 * @param viewAndroidDelegate View delegate used to add and remove views.
 * @param autofillCallback A object that handles the calls to the native AutofillPopupView.
 */
public AutofillPopup(Context context, ViewAndroidDelegate viewAndroidDelegate,
        AutofillPopupDelegate autofillCallback) {
    super(context, null, 0, R.style.AutofillPopupWindow);
    mContext = context;
    mViewAndroidDelegate = viewAndroidDelegate ;
    mAutofillCallback = autofillCallback;

    setOnItemClickListener(this);

    mAnchorView = mViewAndroidDelegate.acquireAnchorView();
    mAnchorView.setId(R.id.autofill_popup_window);
    mAnchorView.setTag(this);

    mViewAndroidDelegate.setAnchorViewPosition(mAnchorView, mAnchorX, mAnchorY, mAnchorWidth,
            mAnchorHeight);

    mLayoutChangeListener = new OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (v == mAnchorView) AutofillPopup.this.show();
        }
    };

    mAnchorView.addOnLayoutChangeListener(mLayoutChangeListener);
    setAnchorView(mAnchorView);
}
 
Example #13
Source File: AutofillPopup.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates an AutofillWindow with specified parameters.
 * @param context Application context.
 * @param viewAndroidDelegate View delegate used to add and remove views.
 * @param autofillCallback A object that handles the calls to the native AutofillPopupView.
 */
public AutofillPopup(Context context, ViewAndroidDelegate viewAndroidDelegate,
        AutofillPopupDelegate autofillCallback) {
    super(context, null, 0, R.style.AutofillPopupWindow);
    mContext = context;
    mViewAndroidDelegate = viewAndroidDelegate ;
    mAutofillCallback = autofillCallback;

    setOnItemClickListener(this);

    mAnchorView = mViewAndroidDelegate.acquireAnchorView();
    mAnchorView.setId(R.id.autofill_popup_window);
    mAnchorView.setTag(this);

    mViewAndroidDelegate.setAnchorViewPosition(mAnchorView, mAnchorX, mAnchorY, mAnchorWidth,
            mAnchorHeight);

    mLayoutChangeListener = new OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (v == mAnchorView) AutofillPopup.this.show();
        }
    };

    mAnchorView.addOnLayoutChangeListener(mLayoutChangeListener);
    setAnchorView(mAnchorView);
}
 
Example #14
Source File: TextureViewHelper.java    From Camera2 with Apache License 2.0 4 votes vote down vote up
public void setOnLayoutChangeListener(OnLayoutChangeListener listener)
{
    mOnLayoutChangeListener = listener;
}
 
Example #15
Source File: DemoUtils.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
public static void addBottomSpaceInsetsIfNeeded(
    ViewGroup scrollableViewAncestor, ViewGroup demoContainer) {
  List<? extends ViewGroup> scrollViews =
      DemoUtils.findViewsWithType(scrollableViewAncestor, ScrollView.class);

  List<? extends ViewGroup> nestedScrollViews = DemoUtils
      .findViewsWithType(scrollableViewAncestor, NestedScrollView.class);

  ArrayList<ViewGroup> scrollingViews = new ArrayList<>();
  scrollingViews.addAll(scrollViews);
  scrollingViews.addAll(nestedScrollViews);
  ViewCompat.setOnApplyWindowInsetsListener(
      demoContainer,
      (view, insets) -> {
        for (ViewGroup scrollView : scrollingViews) {
          scrollView.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) {
                  scrollView.removeOnLayoutChangeListener(this);
                  int systemWindowInsetBottom = insets.getSystemWindowInsetBottom();
                  if (!shouldApplyBottomInset(scrollView, systemWindowInsetBottom)) {
                    return;
                  }

                  int insetBottom = calculateBottomInset(scrollView, systemWindowInsetBottom);
                  View scrollableContent = scrollView.getChildAt(0);
                  scrollableContent.setPadding(
                      scrollableContent.getPaddingLeft(),
                      scrollableContent.getPaddingTop(),
                      scrollableContent.getPaddingRight(),
                      insetBottom);
                }
              });
        }
        return insets;
      });
}
 
Example #16
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void startPlayback() {
    /* start playback only when audio service and both surfaces are ready */
    if (mPlaybackStarted || mService == null)
        return;

    mPlaybackStarted = true;

    /* Dispatch ActionBar touch events to the Activity */
    mActionBarView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            onTouchEvent(event);
            return true;
        }
    });

    if (AndroidUtil.isICSOrLater())
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
                new OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        if (visibility == mUiVisibility)
                            return;
                        if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing && !isFinishing()) {
                            showOverlay();
                        }
                        mUiVisibility = visibility;
                    }
                }
        );

    if (AndroidUtil.isHoneycombOrLater()) {
        if (mOnLayoutChangeListener == null) {
            mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
                private final Runnable mRunnable = new Runnable() {
                    @Override
                    public void run() {
                        changeSurfaceLayout();
                    }
                };
                @Override
                public void onLayoutChange(View v, int left, int top, int right,
                                           int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
                        /* changeSurfaceLayout need to be called after the layout changed */
                        mHandler.removeCallbacks(mRunnable);
                        mHandler.post(mRunnable);
                    }
                }
            };
        }
        mSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
    }
    changeSurfaceLayout();

    /* Listen for changes to media routes. */
    if (mMediaRouter != null)
        mediaRouterAddCallback(true);

    LibVLC().setOnHardwareAccelerationError(this);
    final IVLCVout vlcVout = mService.getVLCVout();
    vlcVout.detachViews();
    if (mPresentation == null) {
        vlcVout.setVideoView(mSurfaceView);
        if (mSubtitlesSurfaceView.getVisibility() != View.GONE)
            vlcVout.setSubtitlesView(mSubtitlesSurfaceView);
    } else {
        vlcVout.setVideoView(mPresentation.mSurfaceView);
        if (mSubtitlesSurfaceView.getVisibility() != View.GONE)
            vlcVout.setSubtitlesView(mPresentation.mSubtitlesSurfaceView);
    }
    mSurfacesAttached = true;
    vlcVout.addCallback(this);
    vlcVout.attachViews();
    mSurfaceView.setKeepScreenOn(true);

    loadMedia();

    // Add any selected subtitle file from the file picker
    if(mSubtitleSelectedFiles.size() > 0) {
        for(String file : mSubtitleSelectedFiles) {
            Log.i(TAG, "Adding user-selected subtitle " + file);
            mService.addSubtitleTrack(file);
        }
    }

    // Set user playback speed
    mService.setRate(mSettings.getFloat(PreferencesActivity.VIDEO_SPEED, 1));
}