Java Code Examples for android.view.View#addOnLayoutChangeListener()

The following examples show how to use android.view.View#addOnLayoutChangeListener() . These examples are extracted from open source projects. 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 Project: cathode   File: ProgressFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle inState) {
  super.onViewCreated(view, inState);
  content = Views.findRequired(view, R.id.contentContainer);
  progress = Views.findRequired(view, R.id.progressContainer);

  wait = true;
  view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
        int oldTop, int oldRight, int oldBottom) {
      v.removeOnLayoutChangeListener(this);

      wait = false;

      if (currentState == STATE_CONTENT_VISIBLE) {
        content.setAlpha(1.0f);
        content.setVisibility(View.VISIBLE);
        progress.setVisibility(View.GONE);
      } else {
        content.setVisibility(View.GONE);
        progress.setAlpha(1.0f);
        progress.setVisibility(View.VISIBLE);
      }
    }
  });
}
 
Example 2
Source Project: react-native-GPay   File: ReactViewGroup.java    License: MIT License 6 votes vote down vote up
void addViewWithSubviewClippingEnabled(
    View child, int index, ViewGroup.LayoutParams params) {
  Assertions.assertCondition(mRemoveClippedSubviews);
  Assertions.assertNotNull(mClippingRect);
  Assertions.assertNotNull(mAllChildren);
  addInArray(child, index);
  // we add view as "clipped" and then run {@link #updateSubviewClipStatus} to conditionally
  // attach it
  int childIndexOffset = 0;
  for (int i = 0; i < index; i++) {
    if (!isChildInViewGroup(mAllChildren[i])) {
      childIndexOffset++;
    }
  }
  updateSubviewClipStatus(mClippingRect, index, childIndexOffset);
  child.addOnLayoutChangeListener(mChildrenLayoutChangeListener);
}
 
Example 3
@Override
public void onCreate(ItemBridgeAdapter.ViewHolder viewHolder) {
    View headerView = viewHolder.getViewHolder().view;
    headerView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mOnHeaderClickedListener != null) {
                mOnHeaderClickedListener.onHeaderClicked();
            }
        }
    });
    headerView.setFocusable(true);
    headerView.setFocusableInTouchMode(true);
    if (mWrapper != null) {
        viewHolder.itemView.addOnLayoutChangeListener(sLayoutChangeListener);
    } else {
        headerView.addOnLayoutChangeListener(sLayoutChangeListener);
    }
}
 
Example 4
private void addOnLayoutChangeListener(@Nullable final View view) {
  if (view == null) {
    return;
  }
  view.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) {
          if (view.getVisibility() == VISIBLE) {
            tryUpdateBadgeDrawableBounds(view);
          }
        }
      });
}
 
Example 5
@Override
public void onCreate(ItemBridgeAdapter.ViewHolder viewHolder) {
    View headerView = viewHolder.getViewHolder().view;
    headerView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mOnHeaderClickedListener != null) {
                mOnHeaderClickedListener.onHeaderClicked();
            }
        }
    });
    headerView.setFocusable(true);
    headerView.setFocusableInTouchMode(true);
    if (mWrapper != null) {
        viewHolder.itemView.addOnLayoutChangeListener(sLayoutChangeListener);
    } else {
        headerView.addOnLayoutChangeListener(sLayoutChangeListener);
    }
}
 
Example 6
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final View view = getLayoutInflater().inflate(R.layout.activity_viewnatruetransitionanim, null);
    view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            v.removeOnLayoutChangeListener(this);
            mHalfHeight = view.getHeight() / 2;
            mEditModeContainerFL.setTranslationY(mHalfHeight);
            mEditModeContainerFL.setAlpha(0f);
            mCustomAnimator.setEditModeHalfHeight(mHalfHeight);
        }
    });
    setContentView(view);
    initView();
    initListener();
}
 
Example 7
private static PivotSetter getSetter(View view) {
    PivotSetter setter = null;

    if (layoutListeners == null) {
        layoutListeners = new WeakHashMap<>();
    } else {
        setter = layoutListeners.get(view);
    }

    if (setter == null) {
        setter = new PivotSetter();
        view.addOnLayoutChangeListener(setter);
        layoutListeners.put(view, setter);
    }

    return setter;
}
 
Example 8
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 9
public FloatingActionModeHelper(FloatingActionMode mode, View target,
                                FloatingActionMode.Callback callback, int themeResId) {
    mMode = mode;
    mTarget = target;
    mCallback = callback;
    final Context context = target.getContext();
    mMenu = new FloatingMenuImpl(target.getContext());
    mView = new ViewManager(context, themeResId, mode, mMenu, callback);
    final View root = mTarget.getRootView();
    root.addOnLayoutChangeListener(this);
    root.addOnAttachStateChangeListener(this);
    mTarget.addOnAttachStateChangeListener(this);
}
 
Example 10
Source Project: SearchPreference   File: AnimationUtils.java    License: MIT License 5 votes vote down vote up
public static void registerCircularRevealAnimation(final Context context, final View view, final RevealAnimationSetting revealSettings) {
    final int startColor = revealSettings.getColorAccent();
    final int endColor = getBackgroundColor(view);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                v.removeOnLayoutChangeListener(this);
                view.setVisibility(View.VISIBLE);
                int cx = revealSettings.getCenterX();
                int cy = revealSettings.getCenterY();
                int width = revealSettings.getWidth();
                int height = revealSettings.getHeight();
                int duration = context.getResources().getInteger(android.R.integer.config_longAnimTime);

                //Simply use the diagonal of the view
                float finalRadius = (float) Math.sqrt(width * width + height * height);
                Animator anim = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, finalRadius).setDuration(duration);
                anim.setInterpolator(new FastOutSlowInInterpolator());
                anim.start();
                startColorAnimation(view, startColor, endColor, duration);
            }
        });
    }
}
 
Example 11
Source Project: react-native-GPay   File: ReactViewGroup.java    License: MIT License 5 votes vote down vote up
@Override
public void setRemoveClippedSubviews(boolean removeClippedSubviews) {
  if (removeClippedSubviews == mRemoveClippedSubviews) {
    return;
  }
  mRemoveClippedSubviews = removeClippedSubviews;
  if (removeClippedSubviews) {
    mClippingRect = new Rect();
    ReactClippingViewGroupHelper.calculateClippingRect(this, mClippingRect);
    mAllChildrenCount = getChildCount();
    int initialSize = Math.max(12, mAllChildrenCount);
    mAllChildren = new View[initialSize];
    mChildrenLayoutChangeListener = new ChildrenLayoutChangeListener(this);
    for (int i = 0; i < mAllChildrenCount; i++) {
      View child = getChildAt(i);
      mAllChildren[i] = child;
      child.addOnLayoutChangeListener(mChildrenLayoutChangeListener);
    }
    updateClippingRect();
  } else {
    // Add all clipped views back, deallocate additional arrays, remove layoutChangeListener
    Assertions.assertNotNull(mClippingRect);
    Assertions.assertNotNull(mAllChildren);
    Assertions.assertNotNull(mChildrenLayoutChangeListener);
    for (int i = 0; i < mAllChildrenCount; i++) {
      mAllChildren[i].removeOnLayoutChangeListener(mChildrenLayoutChangeListener);
    }
    getDrawingRect(mClippingRect);
    updateClippingToRect(mClippingRect);
    mAllChildren = null;
    mClippingRect = null;
    mAllChildrenCount = 0;
    mChildrenLayoutChangeListener = null;
  }
}
 
Example 12
Source Project: PowerMenu   File: AbstractPowerMenu.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * shows circular revealed animation to a view.
 *
 * @param targetView view for animation target.
 */
private void circularRevealed(View targetView) {
  targetView.addOnLayoutChangeListener(
      new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(
            View view,
            int left,
            int top,
            int right,
            int bottom,
            int oldLeft,
            int oldTop,
            int oldRight,
            int oldBottom) {
          view.removeOnLayoutChangeListener(this);
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Animator animator =
                ViewAnimationUtils.createCircularReveal(
                    view,
                    (view.getLeft() + view.getRight()) / 2,
                    (view.getTop() + view.getBottom()) / 2,
                    0f,
                    Math.max(view.getWidth(), view.getHeight()));
            animator.setDuration(900);
            animator.start();
          }
        }
      });
}
 
Example 13
Source Project: CoolSignIn   File: SignInFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    final View contentView = inflater.inflate(R.layout.fragment_sign_in, container, false);
    contentView.addOnLayoutChangeListener(new View.
            OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                   int oldLeft, int oldTop, int oldRight, int oldBottom) {
            v.removeOnLayoutChangeListener(this);
            setUpGridView(getView());
        }
    });
    return contentView;
}
 
Example 14
Source Project: px-android   File: ViewUtils.java    License: MIT License 5 votes vote down vote up
public static void runWhenViewIsFullyMeasured(@NonNull final View view, @NonNull final Runnable runnable) {
    if (ViewCompat.isLaidOut(view)) {
        runnable.run();
    } else {
        view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(final View v, final int left, final int top, final int right,
                final int bottom, final int oldLeft, final int oldTop, final int oldRight, final int oldBottom) {
                view.removeOnLayoutChangeListener(this);
                runnable.run();
            }
        });
    }
}
 
Example 15
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    View view = getView();
    view.addOnLayoutChangeListener(this);
}
 
Example 16
/**
 * Should be called to allow this drawable to calculate its position within the current display
 * frame. This allows it to apply to specified window padding.
 *
 * @see #detachView(View)
 */
public void setRelativeToView(@Nullable View view) {
  if (view == null) {
    return;
  }
  updateLocationOnScreen(view);
  // Listen for changes that indicate the view has moved so the location can be updated
  view.addOnLayoutChangeListener(attachedViewLayoutChangeListener);
}
 
Example 17
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    View view = getView();
    view.addOnLayoutChangeListener(this);
}
 
Example 18
Source Project: smooth-app-bar-layout   File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
public static void intPreScroll(final SmoothAppBarLayout smoothAppBarLayout, final View target, final int offset) {
  target.addOnLayoutChangeListener(new OnPreScrollListener(smoothAppBarLayout, target, offset));
}
 
Example 19
private void attemptToCorrectMediaPlayerStatus(NoPlayer player, View containerView) {
    preventerListener = new OnPotentialBuggyDriverLayoutListener(player);
    containerView.addOnLayoutChangeListener(preventerListener);
}
 
Example 20
/**
 *
 * @param bottomChangeView 一个在软件盘弹出是bottom会发生改变的View,如:被软件键盘向上顶的View,布局的根View。如果没有监听到,说明该View的bottom值没有随软键盘的弹出而改变
 * @param onKeyboardListener
 */
public static void setListener(View bottomChangeView, OnKeyboardListener onKeyboardListener) {
    bottomChangeView.addOnLayoutChangeListener(new KeyboardListener(bottomChangeView, onKeyboardListener));

}