List of usage examples for android.view ViewTreeObserver addOnDrawListener
public void addOnDrawListener(OnDrawListener listener)
Register a callback to be invoked when the view tree is about to be drawn.
Note: this method cannot be invoked from android.view.ViewTreeObserver.OnDrawListener#onDraw() .
From source file:com.google.android.apps.forscience.whistlepunk.RunReviewOverlay.java
public void refreshAfterChartLoad(final boolean backUpdateProgressBar) { if (!mChartController.hasDrawnChart()) { // Refresh the Run Review Overlay after the line graph presenter's chart // has finished drawing itself. final ViewTreeObserver observer = mChartController.getChartViewTreeObserver(); if (observer == null) { return; }//from www .j a v a 2 s .c om observer.removeOnDrawListener(mOnDrawListener); mOnDrawListener = new ViewTreeObserver.OnDrawListener() { @Override public void onDraw() { RunReviewOverlay.this.post(new Runnable() { @Override public void run() { // The ViewTreeObserver calls its listeners without an iterator, // so we need to remove the listener outside the flow or we risk // an index-out-of-bounds crash in the case of multiple listeners. observer.removeOnDrawListener(mOnDrawListener); mOnDrawListener = null; refresh(backUpdateProgressBar); } }); } }; observer.addOnDrawListener(mOnDrawListener); } else { refresh(backUpdateProgressBar); } }
From source file:com.android.launcher3.Launcher.java
public void onWindowVisibilityChanged(int visibility) { mVisible = visibility == View.VISIBLE; updateAutoAdvanceState();/*from w w w . j a va 2s . co m*/ // The following code used to be in onResume, but it turns out onResume is called when // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged // is a more appropriate event to handle if (mVisible) { if (!mWorkspaceLoading) { final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); // We want to let Launcher draw itself at least once before we force it to build // layers on all the workspace pages, so that transitioning to Launcher from other // apps is nice and speedy. observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { private boolean mStarted = false; public void onDraw() { if (mStarted) return; mStarted = true; // We delay the layer building a bit in order to give // other message processing a time to run. In particular // this avoids a delay in hiding the IME if it was // currently shown, because doing that may involve // some communication back with the app. mWorkspace.postDelayed(mBuildLayersRunnable, 500); final ViewTreeObserver.OnDrawListener listener = this; mWorkspace.post(new Runnable() { public void run() { if (mWorkspace != null && mWorkspace.getViewTreeObserver() != null) { mWorkspace.getViewTreeObserver().removeOnDrawListener(listener); } } }); return; } }); } clearTypedText(); } }
From source file:com.android.soma.Launcher.java
public void onWindowVisibilityChanged(int visibility) { mVisible = visibility == View.VISIBLE; updateRunning();// w w w . ja v a2s .c o m // The following code used to be in onResume, but it turns out onResume is called when // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged // is a more appropriate event to handle if (mVisible) { mAppsCustomizeTabHost.onWindowVisible(); if (!mWorkspaceLoading) { final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); // We want to let Launcher draw itself at least once before we force it to build // layers on all the workspace pages, so that transitioning to Launcher from other // apps is nice and speedy. observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { private boolean mStarted = false; public void onDraw() { if (mStarted) return; mStarted = true; // We delay the layer building a bit in order to give // other message processing a time to run. In particular // this avoids a delay in hiding the IME if it was // currently shown, because doing that may involve // some communication back with the app. mWorkspace.postDelayed(mBuildLayersRunnable, 500); final ViewTreeObserver.OnDrawListener listener = this; mWorkspace.post(new Runnable() { public void run() { if (mWorkspace != null && mWorkspace.getViewTreeObserver() != null) { mWorkspace.getViewTreeObserver().removeOnDrawListener(listener); } } }); return; } }); } // When Launcher comes back to foreground, a different Activity might be responsible for // the app market intent, so refresh the icon if (!DISABLE_MARKET_BUTTON) { updateAppMarketIcon(); } clearTypedText(); } }
From source file:g7.bluesky.launcher3.Launcher.java
public void onWindowVisibilityChanged(int visibility) { mVisible = visibility == View.VISIBLE; updateRunning();//w ww . java 2 s .co m // The following code used to be in onResume, but it turns out onResume is called when // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged // is a more appropriate event to handle if (mVisible) { mAppsCustomizeTabHost.onWindowVisible(); if (!mWorkspaceLoading) { final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); // We want to let Launcher draw itself at least once before we force it to build // layers on all the workspace pages, so that transitioning to Launcher from other // apps is nice and speedy. observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { private boolean mStarted = false; public void onDraw() { if (mStarted) return; mStarted = true; // We delay the layer building a bit in order to give // other message processing a time to run. In particular // this avoids a delay in hiding the IME if it was // currently shown, because doing that may involve // some communication back with the app. mWorkspace.postDelayed(mBuildLayersRunnable, 500); final ViewTreeObserver.OnDrawListener listener = this; mWorkspace.post(new Runnable() { public void run() { if (mWorkspace != null && mWorkspace.getViewTreeObserver() != null) { mWorkspace.getViewTreeObserver().removeOnDrawListener(listener); } } }); return; } }); } clearTypedText(); } }