Java Code Examples for android.view.ViewTreeObserver#OnPreDrawListener
The following examples show how to use
android.view.ViewTreeObserver#OnPreDrawListener .
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: LithoScrollView.java From litho with Apache License 2.0 | 6 votes |
void mount( ComponentTree contentComponentTree, final ScrollPosition scrollPosition, boolean isIncrementalMountEnabled) { mLithoView.setComponentTree(contentComponentTree); mIsIncrementalMountEnabled = isIncrementalMountEnabled; mScrollPosition = scrollPosition; final ViewTreeObserver.OnPreDrawListener onPreDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { setScrollY(scrollPosition.y); ViewTreeObserver currentViewTreeObserver = getViewTreeObserver(); if (currentViewTreeObserver.isAlive()) { currentViewTreeObserver.removeOnPreDrawListener(this); } return true; } }; getViewTreeObserver().addOnPreDrawListener(onPreDrawListener); mOnPreDrawListener = onPreDrawListener; }
Example 2
Source File: EditTextBoldCursor.java From Telegram with GNU General Public License v2.0 | 6 votes |
@SuppressLint("PrivateApi") public void fixHandleView(boolean reset) { if (reset) { fixed = false; } else if (!fixed) { try { if (editorClass == null) { editorClass = Class.forName("android.widget.Editor"); mEditor = TextView.class.getDeclaredField("mEditor"); mEditor.setAccessible(true); editor = mEditor.get(this); } if (listenerFixer == null) { Method initDrawablesMethod = editorClass.getDeclaredMethod("getPositionListener"); initDrawablesMethod.setAccessible(true); listenerFixer = (ViewTreeObserver.OnPreDrawListener) initDrawablesMethod.invoke(editor); } AndroidUtilities.runOnUIThread(listenerFixer::onPreDraw, 500); } catch (Throwable ignore) { } fixed = true; } }
Example 3
Source File: SlidingRelativeLayout.java From Kernel-Tuner with GNU General Public License v3.0 | 6 votes |
public void setXFraction(float fraction) { this.xFraction = fraction; if (getWidth() == 0) { if (preDrawListener == null) { preDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener( preDrawListener); setXFraction(xFraction); return true; } }; getViewTreeObserver().addOnPreDrawListener(preDrawListener); } return; } float translationX = getWidth() * fraction; setTranslationX(translationX); }
Example 4
Source File: SlidingRelativeLayout.java From Kernel-Tuner with GNU General Public License v3.0 | 6 votes |
public void setYFraction(float fraction) { this.yFraction = fraction; if (getHeight() == 0) { if (preDrawListener == null) { preDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener( preDrawListener); setYFraction(yFraction); return true; } }; getViewTreeObserver().addOnPreDrawListener(preDrawListener); } return; } float translationY = getHeight() * fraction; setTranslationY(translationY); }
Example 5
Source File: EditTextBoldCursor.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@SuppressLint("PrivateApi") public void fixHandleView(boolean reset) { if (reset) { fixed = false; } else if (!fixed) { try { if (editorClass == null) { editorClass = Class.forName("android.widget.Editor"); mEditor = TextView.class.getDeclaredField("mEditor"); mEditor.setAccessible(true); editor = mEditor.get(this); } if (listenerFixer == null) { Method initDrawablesMethod = editorClass.getDeclaredMethod("getPositionListener"); initDrawablesMethod.setAccessible(true); listenerFixer = (ViewTreeObserver.OnPreDrawListener) initDrawablesMethod.invoke(editor); } AndroidUtilities.runOnUIThread(listenerFixer::onPreDraw, 500); } catch (Throwable ignore) { } fixed = true; } }
Example 6
Source File: SlidingRelativeLayout.java From TranslateFragment with Apache License 2.0 | 6 votes |
public void setYFraction(float fraction) { this.yFraction = fraction; if (getHeight() == 0) { if (preDrawListener == null) { preDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener(preDrawListener); setYFraction(yFraction); return true; } }; getViewTreeObserver().addOnPreDrawListener(preDrawListener); } return; } float translationY = getHeight() * fraction; setTranslationY(translationY); }
Example 7
Source File: AndroidFragmentFrameLayout.java From FragmentNavigationController with MIT License | 6 votes |
public void setXFraction(float fraction) { this.xFraction = fraction; if (getWidth() == 0) { if (preDrawListener == null) { preDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener( preDrawListener); setXFraction(xFraction); return true; } }; getViewTreeObserver().addOnPreDrawListener(preDrawListener); } return; } float translationX = getWidth() * fraction; setTranslationX(translationX); }
Example 8
Source File: AndroidFragmentFrameLayout.java From FragmentNavigationController with MIT License | 6 votes |
public void setYFraction(float fraction) { this.yFraction = fraction; if (getHeight() == 0) { if (preDrawListener == null) { preDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener( preDrawListener); setYFraction(yFraction); return true; } }; getViewTreeObserver().addOnPreDrawListener(preDrawListener); } return; } float translationY = getHeight() * fraction; setTranslationY(translationY); }
Example 9
Source File: SnakeHackLayout.java From Snake with Apache License 2.0 | 6 votes |
public void setFractionX(final float fractionX) { this.fractionX = fractionX; if(null == mPreDrawListener) { mPreDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener); setTranslateX(fractionX); return true; } }; getViewTreeObserver().addOnPreDrawListener(mPreDrawListener); } setTranslateX(fractionX); }
Example 10
Source File: ShimmerLayout.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
public void startShimmerAnimation() { if (isAnimationStarted) { return; } if (getWidth() == 0) { startAnimationPreDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener(this); startShimmerAnimation(); return true; } }; getViewTreeObserver().addOnPreDrawListener(startAnimationPreDrawListener); return; } Animator animator = getShimmerAnimation(); animator.start(); isAnimationStarted = true; }
Example 11
Source File: ShimmerLayout.java From ShimmerLayout with Apache License 2.0 | 6 votes |
public void startShimmerAnimation() { if (isAnimationStarted) { return; } if (getWidth() == 0) { startAnimationPreDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener(this); startShimmerAnimation(); return true; } }; getViewTreeObserver().addOnPreDrawListener(startAnimationPreDrawListener); return; } Animator animator = getShimmerAnimation(); animator.start(); isAnimationStarted = true; }
Example 12
Source File: AndroidFragmentFrameLayout.java From MusicPlayer with GNU General Public License v3.0 | 6 votes |
public void setXFraction(float fraction) { this.xFraction = fraction; if (getWidth() == 0) { if (preDrawListener == null) { preDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener( preDrawListener); setXFraction(xFraction); return true; } }; getViewTreeObserver().addOnPreDrawListener(preDrawListener); } return; } float translationX = getWidth() * fraction; setTranslationX(translationX); }
Example 13
Source File: AndroidFragmentFrameLayout.java From MusicPlayer with GNU General Public License v3.0 | 6 votes |
public void setYFraction(float fraction) { this.yFraction = fraction; if (getHeight() == 0) { if (preDrawListener == null) { preDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener( preDrawListener); setYFraction(yFraction); return true; } }; getViewTreeObserver().addOnPreDrawListener(preDrawListener); } return; } float translationY = getHeight() * fraction; setTranslationY(translationY); }
Example 14
Source File: FloatingActionButtonImpl.java From material-components-android with Apache License 2.0 | 5 votes |
@NonNull private ViewTreeObserver.OnPreDrawListener getOrCreatePreDrawListener() { if (preDrawListener == null) { preDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { FloatingActionButtonImpl.this.onPreDraw(); return true; } }; } return preDrawListener; }
Example 15
Source File: ViewPositionObserver.java From 365browser with Apache License 2.0 | 5 votes |
/** * @param view The view to observe. */ public ViewPositionObserver(View view) { mView = view; mListeners = new ArrayList<Listener>(); updatePosition(); mPreDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { updatePosition(); return true; } }; }
Example 16
Source File: SectionHeaderLayout.java From sectioned-recycler-view with MIT License | 5 votes |
/** * Runs the code just before the given view is being drawn so that its size has been already * calculated. * * @param view View to be drawn. * @param runnable Code to run. */ private static void runJustBeforeBeingDrawn(final View view, final Runnable runnable) { final ViewTreeObserver.OnPreDrawListener onPreDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); runnable.run(); return true; } }; view.getViewTreeObserver().addOnPreDrawListener(onPreDrawListener); }
Example 17
Source File: ViewPositionObserver.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * @param view The view to observe. */ public ViewPositionObserver(View view) { mView = view; mListeners = new ArrayList<Listener>(); updatePosition(); mPreDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { updatePosition(); return true; } }; }
Example 18
Source File: ViewPositionObserver.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * @param view The view to observe. */ public ViewPositionObserver(View view) { mView = view; mListeners = new ArrayList<Listener>(); updatePosition(); mPreDrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { updatePosition(); return true; } }; }