android.view.View.OnSystemUiVisibilityChangeListener#android.view.View.OnLayoutChangeListener源码实例Demo

下面列出了android.view.View.OnSystemUiVisibilityChangeListener#android.view.View.OnLayoutChangeListener 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: animation-samples   文件: GridFragment.java
/**
 * 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));
      }
    }
  });
}
 
源代码2 项目: delion   文件: CustomTabBottomBarDelegate.java
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();
        }
    });
}
 
源代码3 项目: delion   文件: FocusAnimator.java
/**
 * 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);
        }
    });
}
 
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();
        }
    });
}
 
源代码5 项目: AndroidChromium   文件: FocusAnimator.java
/**
 * 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);
        }
    });
}
 
源代码6 项目: 365browser   文件: CustomTabBottomBarDelegate.java
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());
        }
    });
}
 
源代码7 项目: 365browser   文件: FocusAnimator.java
/**
 * 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);
        }
    });
}
 
源代码8 项目: delion   文件: SnackbarView.java
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);
        }
    });
}
 
源代码9 项目: AndroidChromium   文件: SnackbarView.java
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);
        }
    });
}
 
源代码10 项目: 365browser   文件: SnackbarView.java
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);
        }
    });
}
 
源代码11 项目: 365browser   文件: DropdownPopupWindow.java
/**
 * 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);
}
 
源代码12 项目: android-chromium   文件: AutofillPopup.java
/**
 * 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);
}
 
源代码13 项目: android-chromium   文件: AutofillPopup.java
/**
 * 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);
}
 
源代码14 项目: Camera2   文件: TextureViewHelper.java
public void setOnLayoutChangeListener(OnLayoutChangeListener listener)
{
    mOnLayoutChangeListener = listener;
}
 
源代码15 项目: material-components-android   文件: DemoUtils.java
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;
      });
}
 
源代码16 项目: VCL-Android   文件: VideoPlayerActivity.java
@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));
}