Example usage for android.view ViewTreeObserver isAlive

List of usage examples for android.view ViewTreeObserver isAlive

Introduction

In this page you can find the example usage for android.view ViewTreeObserver isAlive.

Prototype

public boolean isAlive() 

Source Link

Document

Indicates whether this ViewTreeObserver is alive.

Usage

From source file:ca.zadrox.dota2esportticker.ui.TeamDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_team_detail);

    getLoaderManager().initLoader(GGLOADER_ID, null, ggTeamLoaderCallbacks);

    final Toolbar toolbar = getActionBarToolbar();
    toolbar.setNavigationIcon(R.drawable.ic_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*from   ww  w. ja va 2 s .c o m*/
        public void onClick(View v) {
            onBackPressed();
        }
    });

    mHandler.post(new Runnable() {
        @Override
        public void run() {
            toolbar.setTitle("");
        }
    });

    mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.session_detail_max_header_elevation);

    mScrollView = (ObservableScrollView) findViewById(R.id.scroll_view);
    mScrollView.addCallbacks(this);
    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }

    mScrollViewChild = findViewById(R.id.scroll_view_child);
    mHeaderBox = (FrameLayout) findViewById(R.id.header_bar);

    mHeaderTeamName = (TextView) mHeaderBox.findViewById(R.id.team_name);
    mHeaderTeamLogo = (BezelImageView) mHeaderBox.findViewById(R.id.team_logo);
    mHeaderTeamLogo.setVisibility(View.INVISIBLE);

    mHeaderTeamName.getLayoutParams().height = UIUtils.calculateActionBarSize(this);
    mHeaderTeamName.setAlpha(0f);

    mDetailsContainer = (LinearLayout) mScrollViewChild.findViewById(R.id.card_container);

    recomputeScrollingConstants();

}

From source file:com.nikola.despotoski.drawerlayoutedgetoggle.DrawerLayoutEdgeToggle.java

public DrawerLayoutEdgeToggle(Activity a, DrawerLayout l, int drawerOpen, int drawerClose,
        boolean keepShadowOnHandle, int drawerGravity) {

    if (drawerGravity != GravityCompat.END && drawerGravity != GravityCompat.START
            && drawerGravity != Gravity.LEFT && drawerGravity != Gravity.RIGHT)
        throw new IllegalArgumentException(
                "Use: GravityCompat.END, GravityCompat.START, Gravity.LEFT or Gravity.RIGHT for drawerGravity parameter");
    mGravity = drawerGravity;//from  w  w  w .  j  a  va2  s . co  m
    mActivity = a;
    mDrawerLayout = l;
    mOpenDrawable = a.getResources().getDrawable(drawerOpen);
    mCloseDrawable = a.getResources().getDrawable(drawerClose);
    rootLayout = (FrameLayout) mActivity.findViewById(android.R.id.content);
    mHandle = new ImageView(a);
    final ViewTreeObserver viewTreeObserver = mHandle.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @SuppressLint("NewApi")
            @Override
            public void onGlobalLayout() {
                mDrawerLayout.measure(MeasureSpec.EXACTLY, MeasureSpec.EXACTLY);
                syncState();
                removeOnGlobalLayoutListener(mHandle, this);
            }
        });
    }

    mHandle.setOnClickListener(mHandleClickListenerInt);
    mHandle.setOnTouchListener(mHandleTouchListenerInt);
    mHandle.setSaveEnabled(true);
    mDrawerLayout.setOnTouchListener(mHandleTouchListenerInt);
    rootLayout.addView(mHandle,
            new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, drawerGravity));
    mKeepShadowOnHandle = keepShadowOnHandle;
    mCurrentDrawable = mCloseDrawable;
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

/**
 * This method is used to setup the various object configurations
 *
 * @param context      can be also referenced through {@link #getContext()}
 * @param keyboardRows//from  w ww .j a  v  a2s .  c  o m
 */
private void initialize(Context context, List<KeyboardRow> keyboardRows) {
    mKeyboardRows = keyboardRows;
    verifyInitMode();
    mActivity = (Activity) context;
    mWindow = mActivity.getWindow();
    mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    setOrientation(VERTICAL);
    setVisibility(GONE);
    setWillNotDraw(true);
    setBackgroundColor(Color.parseColor("#a1a6aa"));

    //mCharTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/nyala.ttf");
    mRootView = (ViewGroup) mWindow.getDecorView().findViewById(android.R.id.content);
    mRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            ViewTreeObserver viewTreeObserver = mRootView.getViewTreeObserver();
            if (viewTreeObserver.isAlive()) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    viewTreeObserver.removeOnGlobalLayoutListener(this);
                } else {
                    viewTreeObserver.removeGlobalOnLayoutListener(this);
                }
            }
            createKeyboard(mKeyboardRows);
        }
    });
    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //Consume event[intercept touch for not letting pass and click views under the keyboard]
            return true;
        }
    });
}

From source file:fr.tvbarthel.apps.simpleweatherforcast.MainActivity.java

private void initRootPadding() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        final Resources resources = getResources();
        final boolean isPortrait = resources.getBoolean(R.bool.is_portrait);
        final ActionBar actionBar = getSupportActionBar();

        final ViewTreeObserver vto = mRootView.getViewTreeObserver();
        if (vto.isAlive()) {
            vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                @Override//w w w.j av a  2  s. co m
                public boolean onPreDraw() {
                    mRootView.getViewTreeObserver().removeOnPreDrawListener(this);

                    int paddingBottom = mRootView.getPaddingBottom();
                    int paddingTop = mRootView.getPaddingTop();
                    int paddingRight = mRootView.getPaddingRight();
                    int paddingLeft = mRootView.getPaddingLeft();

                    // Add the status bar height to the top padding.
                    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
                    if (resourceId > 0) {
                        paddingTop += resources.getDimensionPixelSize(resourceId);
                    }

                    if (isPortrait) {
                        // Add the navigation bar height to the bottom padding.
                        resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
                        if (resourceId > 0) {
                            paddingBottom += resources.getDimensionPixelSize(resourceId);
                        }
                    } else {
                        // Add the navigation bar width to the right padding.
                        resourceId = resources.getIdentifier("navigation_bar_width", "dimen", "android");
                        if (resourceId > 0) {
                            paddingRight += resources.getDimensionPixelSize(resourceId);
                        }
                    }

                    mRootView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
                    return true;
                }
            });
        }
    }
}

From source file:ca.zadrox.dota2esportticker.ui.LiveContentView.java

@Override
protected void onDestroy() {
    super.onDestroy();
    if (mGameUpdaterRunnable != null) {
        mHandler.removeCallbacks(mGameUpdaterRunnable);
    }/*from  w  w  w . ja v a  2  s.c o m*/

    if (mGameResultRunnable != null) {
        mHandler.removeCallbacks(mGameResultRunnable);
    }

    if (mScrollView == null) {
        return;
    }

    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.removeOnGlobalLayoutListener(mGlobalLayoutListener);
    }
}

From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java

/**
 * Register the event OnGlobalLayoutListener to fill the moneybox when the
 * layout is created./*  w w w . j  av  a  2s. c om*/
 */
private void registerLayoutListener() {
    final View v;
    final ViewTreeObserver vto;
    Activity parent;

    parent = getActivity();

    v = parent.findViewById(R.id.moneyDropLayout);
    vto = v.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                initMoneybox();

                v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });
    }
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

@Override
public void onDestroyView() {
    super.onDestroyView();
    if (mScrollView == null) {
        return;/*from   ww w.j ava  2 s .co m*/
    }

    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.removeGlobalOnLayoutListener(mGlobalLayoutListener);
    }
}

From source file:com.shalzz.attendance.fragment.AttendanceListFragment.java

@Override
public void onItemExpanded(final View view) {
    final int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    final ExpandableListAdapter.GenericViewHolder viewHolder = (ExpandableListAdapter.GenericViewHolder) view
            .getTag();//from  w w w .  j a va2  s .c  o  m
    final RelativeLayout childView = viewHolder.childView;
    childView.measure(spec, spec);
    final int startingHeight = view.getHeight();
    final ViewTreeObserver observer = mRecyclerView.getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // We don'mTracker want to continue getting called for every draw.
            if (observer.isAlive()) {
                observer.removeOnPreDrawListener(this);
            }
            // Calculate some values to help with the animation.
            final int endingHeight = view.getHeight();
            final int distance = Math.abs(endingHeight - startingHeight);
            final int baseHeight = Math.min(endingHeight, startingHeight);
            final boolean isExpanded = endingHeight > startingHeight;

            // Set the views back to the start state of the animation
            view.getLayoutParams().height = startingHeight;
            if (!isExpanded) {
                viewHolder.childView.setVisibility(View.VISIBLE);
            }

            // Set up the fade effect for the action buttons.
            if (isExpanded) {
                // Start the fade in after the expansion has partly completed, otherwise it
                // will be mostly over before the expansion completes.
                viewHolder.childView.setAlpha(0f);
                viewHolder.childView.animate().alpha(1f).setStartDelay(mFadeInStartDelay)
                        .setDuration(mFadeInDuration).start();
            } else {
                viewHolder.childView.setAlpha(1f);
                viewHolder.childView.animate().alpha(0f).setDuration(mFadeOutDuration).start();
            }
            view.requestLayout();

            // Set up the animator to animate the expansion and shadow depth.
            ValueAnimator animator = isExpanded ? ValueAnimator.ofFloat(0f, 1f) : ValueAnimator.ofFloat(1f, 0f);

            // scroll to make the view fully visible.
            mRecyclerView.smoothScrollToPosition(viewHolder.position);

            animator.addUpdateListener(animator1 -> {
                Float value = (Float) animator1.getAnimatedValue();

                // For each value from 0 to 1, animate the various parts of the layout.
                view.getLayoutParams().height = (int) (value * distance + baseHeight);
                float z = mExpandedItemTranslationZ * value;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    view.setTranslationZ(z);
                }
                view.requestLayout();
            });

            // Set everything to their final values when the animation's done.
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;

                    if (!isExpanded) {
                        viewHolder.childView.setVisibility(View.GONE);
                    } else {
                        // This seems like it should be unnecessary, but without this, after
                        // navigating out of the activity and then back, the action view alpha
                        // is defaulting to the value (0) at the start of the expand animation.
                        viewHolder.childView.setAlpha(1);
                    }
                }
            });

            animator.setDuration(mExpandCollapseDuration);
            animator.start();

            // Return false so this draw does not occur to prevent the final frame from
            // being drawn for the single frame before the animations start.
            return false;
        }
    });
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

private void setupCustomScrolling(View rootView) {
    mAddSchedulePlaceholderView = rootView.findViewById(R.id.add_to_schedule_button_placeholder);
    if (mAddSchedulePlaceholderView == null) {
        if (mType != null && !ScheduleContract.Sessions.SESSION_TYPE_KEYNOTE.equals(mType)) {
            mAddScheduleButton.setVisibility(View.VISIBLE);
        }//from w w w .  j a  v  a  2  s.  co m
        return;
    }

    mScrollView = (ObservableScrollView) rootView.findViewById(R.id.scroll_view);
    mScrollView.setCallbacks(this);
    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }
}

From source file:org.mozilla.gecko.animation.PropertyAnimator.java

public void start() {
    if (mDuration == 0) {
        return;//from w ww. j  a  va  2  s .  co  m
    }

    mStartTime = AnimationUtils.currentAnimationTimeMillis();

    // Fix the from value based on current position and property
    for (ElementHolder element : mElementsList) {
        if (element.property == Property.ALPHA)
            element.from = element.proxy.getAlpha();
        else if (element.property == Property.TRANSLATION_Y)
            element.from = element.proxy.getTranslationY();
        else if (element.property == Property.TRANSLATION_X)
            element.from = element.proxy.getTranslationX();
        else if (element.property == Property.SCROLL_Y)
            element.from = element.proxy.getScrollY();
        else if (element.property == Property.SCROLL_X)
            element.from = element.proxy.getScrollX();
        else if (element.property == Property.WIDTH)
            element.from = element.proxy.getWidth();
        else if (element.property == Property.HEIGHT)
            element.from = element.proxy.getHeight();

        ViewCompat.setHasTransientState(element.view, true);

        if (shouldEnableHardwareLayer(element))
            element.view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        else
            element.view.setDrawingCacheEnabled(true);
    }

    // Get ViewTreeObserver from any of the participant views
    // in the animation.
    final ViewTreeObserver treeObserver;
    if (mElementsList.size() > 0) {
        treeObserver = mElementsList.get(0).view.getViewTreeObserver();
    } else {
        treeObserver = null;
    }

    final ViewTreeObserver.OnPreDrawListener preDrawListener = new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (treeObserver.isAlive()) {
                treeObserver.removeOnPreDrawListener(this);
            }

            mFramePoster.postFirstAnimationFrame();
            return true;
        }
    };

    // Try to start animation after any on-going layout round
    // in the current view tree. OnPreDrawListener seems broken
    // on pre-Honeycomb devices, start animation immediatelly
    // in this case.
    if (Versions.feature11Plus && treeObserver != null && treeObserver.isAlive()) {
        treeObserver.addOnPreDrawListener(preDrawListener);
    } else {
        mFramePoster.postFirstAnimationFrame();
    }

    if (mListeners != null) {
        for (PropertyAnimationListener listener : mListeners) {
            listener.onPropertyAnimationStart();
        }
    }
}