List of usage examples for android.view ViewTreeObserver isAlive
public boolean isAlive()
From source file:despotoski.nikola.github.com.bottomnavigationlayout.Util.java
public static void runOnAttachedToLayout(View v, final Runnable runnable) { if (ViewCompat.isLaidOut(v)) runnable.run();/* w w w. ja v a 2 s . com*/ else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { v.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { runnable.run(); v.removeOnLayoutChangeListener(this); } }); return; } final ViewTreeObserver viewTreeObserver = v.getViewTreeObserver(); if (viewTreeObserver != null && viewTreeObserver.isAlive()) { viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { runnable.run(); if (viewTreeObserver.isAlive()) //noinspection deprecation viewTreeObserver.removeGlobalOnLayoutListener(this); } }); } } }
From source file:com.getkeepsafe.taptargetview.ViewUtil.java
/** Executes the given {@link java.lang.Runnable} when the view is laid out **/ static void onLaidOut(final View view, final Runnable runnable) { if (isLaidOut(view)) { runnable.run();//from w ww .ja v a 2 s.c o m return; } final ViewTreeObserver observer = view.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { final ViewTreeObserver trueObserver; if (observer.isAlive()) { trueObserver = observer; } else { trueObserver = view.getViewTreeObserver(); } removeOnGlobalLayoutListener(trueObserver, this); runnable.run(); } }); }
From source file:com.agenmate.lollipop.util.ViewUtils.java
public static void waitForLayoutPrepared(final View view, final LayoutPreparedListener listener) { final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver(); if (viewTreeObserver != null) { viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override//from www. ja va2s . c om public void onGlobalLayout() { invokeLayoutListener(); removeGlobalOnLayoutListenerIfNeeded(); } private void invokeLayoutListener() { if (listener != null) { listener.onLayoutPrepared(view); } } private void removeGlobalOnLayoutListenerIfNeeded() { final ViewTreeObserver laterViewTreeObserver = view.getViewTreeObserver(); if (laterViewTreeObserver != null && laterViewTreeObserver.isAlive()) { laterViewTreeObserver.removeGlobalOnLayoutListener(this); } } }); } }
From source file:eu.inmite.android.lib.validations.form.FormValidator.java
/** * stop previously started live validation by {@link #startLiveValidation(Object, android.view.View, eu.inmite.android.lib.validations.form.iface.IValidationCallback)} * @param target live validation is recognized by target object * @return true if there was live validation to stop *//*ww w .ja v a 2 s .c om*/ public static boolean stopLiveValidation(final Object target) { if (sLiveValidations == null || !sLiveValidations.containsKey(target)) { return false; } final ViewGlobalFocusChangeListener removed = sLiveValidations.remove(target); final ViewTreeObserver treeObserver = removed.formContainer.getViewTreeObserver(); if (treeObserver.isAlive()) { treeObserver.removeOnGlobalFocusChangeListener(removed); return true; } return false; }
From source file:org.cyanogenmod.designertools.ui.CreditsActivity.java
@Override protected void onResume() { super.onResume(); final View rootLayout = findViewById(R.id.activity_credits); rootLayout.setVisibility(View.INVISIBLE); ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override/*from w w w . ja va 2 s.c o m*/ public void onGlobalLayout() { circularRevealActivity(rootLayout); rootLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); } }
From source file:com.android.incallui.CircularRevealActivity.java
private void setupDecorView(final Point touchPoint, MaterialPalette palette) { final View view = getWindow().getDecorView(); // The circle starts from an initial size of 0 so clip it such that it is invisible. When // the animation later starts, this clip will be clobbered by the circular reveal clip. // See ViewAnimationUtils.createCircularReveal. view.setOutlineProvider(new ViewOutlineProvider() { @Override/* www . ja v a 2 s.c om*/ public void getOutline(View view, Outline outline) { // Using (0, 0, 0, 0) will not work since the outline will simply be treated as // an empty outline. outline.setOval(-1, -1, 0, 0); } }); view.setClipToOutline(true); if (palette != null) { view.findViewById(R.id.outgoing_call_animation_circle).setBackgroundColor(palette.mPrimaryColor); getWindow().setStatusBarColor(palette.mSecondaryColor); } view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { final ViewTreeObserver vto = view.getViewTreeObserver(); if (vto.isAlive()) { vto.removeOnPreDrawListener(this); } final Animator animator = getRevealAnimator(touchPoint); // Since this animator is a RenderNodeAnimator (native animator), add an arbitary // start delay to force the onAnimationStart callback to happen later on the UI // thread. Otherwise it would happen right away inside animator.start() animator.setStartDelay(5); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { InCallPresenter.getInstance().onCircularRevealStarted(CircularRevealActivity.this); } @Override public void onAnimationEnd(Animator animation) { view.setClipToOutline(false); super.onAnimationEnd(animation); } }); animator.start(); return false; } }); }
From source file:pl.edu.agh.schedule.details.DetailFragment.java
private void initViews() { mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.detail_max_header_elevation); mScrollView = (ObservableScrollView) getActivity().findViewById(R.id.scroll_view); mScrollView.addCallbacks(this); ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.addOnGlobalLayoutListener(mGlobalLayoutListener); }//from ww w .j a v a 2s . com mScrollViewChild = getActivity().findViewById(R.id.scroll_view_child); mScrollViewChild.setVisibility(View.INVISIBLE); mDetailsContainer = getActivity().findViewById(R.id.details_container); mHeaderBox = getActivity().findViewById(R.id.header_session); mTitle = (TextView) getActivity().findViewById(R.id.session_title); mPhotoViewContainer = getActivity().findViewById(R.id.session_photo_container); mPhotoView = (ImageView) getActivity().findViewById(R.id.session_photo); mAbstract = (TextView) getActivity().findViewById(R.id.session_abstract); ViewCompat.setTransitionName(mPhotoView, "photo"); mNoPlaceholderImageLoader = new ImageLoader(getContext()); }
From source file:fr.tvbarthel.apps.sayitfromthesky.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.inject(this); mActionBarTitleColorSpan = new AlphaForegroundColorSpan(getResources().getColor(R.color.material_grey_300)); mActionBarTitleSpannable = new SpannableString(getString(R.string.app_name)); setActionBarTitleAlpha(1);/*from ww w .j a v a 2 s . c o m*/ // Compute the action bar size mActionBarSize = ActionBarHelper.getActionBarSize(this); // Set the height of the header container to 1/3.5 of the root height. ViewTreeObserver vto = mRootView.getViewTreeObserver(); if (vto.isAlive()) { vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { ViewHelper.removeOnGlobalLayoutListener(mRootView, this); final int headerHeight = (int) (mRootView.getHeight() / 3.5); mHeaderContainer.getLayoutParams().height = headerHeight; mListView.setPadding(0, headerHeight - mActionBarSize, 0, 0); final int actionBarLogoSize = getResources() .getDimensionPixelSize(R.dimen.action_bar_logo_size); final int actionBarMarginLeft = getResources() .getDimensionPixelOffset(R.dimen.action_bar_margin_left); mHeaderLogoMaxTranslationX = (mHeaderContainer.getWidth() - actionBarLogoSize) / 2 - actionBarMarginLeft; mHeaderLogoFinalScale = ((float) actionBarLogoSize) / mHeaderLogo.getWidth(); } }); } mDrawingAdapter = new DrawingAdapter(this); initListView(); getLoaderManager().initLoader(LOADER_ID_DRAWINGS, null, this); ViewHelper.slideFromBottom(mBtnNewDrawing); }
From source file:com.example.linhdq.test.MonitoredActivity.java
/** * position the app icon at the bottom of the action bar and start animation *///from w ww . j a v a2 s .c o m private void initAppIcon(final int dialogId, ImageView appIcon) { setDialogId(dialogId); mAppIcon = appIcon; final ViewTreeObserver viewTreeObserver = appIcon.getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver.addOnGlobalLayoutListener(this); } }
From source file:quickbeer.android.features.barcodescanner.BarcodeScanActivity.java
/** * Initializes the UI and creates the detector pipeline. */// www .j a v a2 s . co m @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); analytics = new Analytics(this); analytics.createEvent(Events.Screen.BARCODE_SCANNER); setContentView(R.layout.barcode_scan_activity); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay); ViewTreeObserver viewTreeObserver = mPreview.getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mPreview.getViewTreeObserver().removeOnGlobalLayoutListener(this); viewWidth = mPreview.getWidth(); viewHeight = mPreview.getHeight(); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ContextCompat.checkSelfPermission(BarcodeScanActivity.this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(); startCameraSource(); } else { requestCameraPermission(); } } }); } }