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:com.android.incallui.CallCardFragment.java

@Override
public void onResume() {
    super.onResume();
    // If the previous launch animation is still running, cancel it so that we don't get
    // stuck in an intermediate animation state.
    if (mAnimatorSet != null && mAnimatorSet.isRunning()) {
        mAnimatorSet.cancel();//from ww w .  j  a  v a 2  s  . com
    }

    mIsLandscape = getResources().getBoolean(R.bool.is_layout_landscape);
    mHasLargePhoto = getResources().getBoolean(R.bool.has_large_photo);

    final ViewGroup parent = ((ViewGroup) mPrimaryCallCardContainer.getParent());
    final ViewTreeObserver observer = parent.getViewTreeObserver();
    parent.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            ViewTreeObserver viewTreeObserver = observer;
            if (!viewTreeObserver.isAlive()) {
                viewTreeObserver = parent.getViewTreeObserver();
            }
            viewTreeObserver.removeOnGlobalLayoutListener(this);
            mFloatingActionButtonController.setScreenWidth(parent.getWidth());
            updateFabPosition();
        }
    });

    updateColors();
}

From source file:com.android.incallui.CallCardFragment.java

/**
 * Adds a global layout listener to update the FAB's positioning on the next layout. This allows
 * us to position the FAB after the secondary call info's height has been calculated.
 *///from ww  w  .  j  a v a 2s  . c o  m
private void updateFabPositionForSecondaryCallInfo() {
    mSecondaryCallInfo.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    final ViewTreeObserver observer = mSecondaryCallInfo.getViewTreeObserver();
                    if (!observer.isAlive()) {
                        return;
                    }
                    observer.removeOnGlobalLayoutListener(this);

                    onDialpadVisibilityChange(mIsDialpadShowing);
                }
            });
}

From source file:com.android.dialer.DialtactsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Trace.beginSection(TAG + " onCreate");
    super.onCreate(savedInstanceState);

    mFirstLaunch = true;//from w w w. j a va2s  . c o  m

    final Resources resources = getResources();
    mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);

    Trace.beginSection(TAG + " setContentView");
    setContentView(R.layout.dialtacts_activity);
    Trace.endSection();
    getWindow().setBackgroundDrawable(null);

    Trace.beginSection(TAG + " setup Views");
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setCustomView(R.layout.search_edittext);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setBackgroundDrawable(null);

    SearchEditTextLayout searchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView()
            .findViewById(R.id.search_view_container);
    searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);

    mActionBarController = new ActionBarController(this, searchEditTextLayout);

    mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
    mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
    mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
    searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
            .setOnClickListener(mSearchViewOnClickListener);
    searchEditTextLayout.findViewById(R.id.search_box_start_search)
            .setOnClickListener(mSearchViewOnClickListener);
    searchEditTextLayout.setOnClickListener(mSearchViewOnClickListener);
    searchEditTextLayout.setCallback(new SearchEditTextLayout.Callback() {
        @Override
        public void onBackButtonClicked() {
            onBackPressed();
        }

        @Override
        public void onSearchViewClicked() {
            // Hide FAB, as the keyboard is shown.
            mFloatingActionButtonController.scaleOut();
        }
    });

    mIsLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    mPreviouslySelectedTabIndex = ListsFragment.TAB_INDEX_SPEED_DIAL;
    final View floatingActionButtonContainer = findViewById(R.id.floating_action_button_container);
    ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
    floatingActionButton.setOnClickListener(this);
    mFloatingActionButtonController = new FloatingActionButtonController(this, floatingActionButtonContainer,
            floatingActionButton);

    ImageButton optionsMenuButton = (ImageButton) searchEditTextLayout
            .findViewById(R.id.dialtacts_options_menu_button);
    optionsMenuButton.setOnClickListener(this);
    mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
    optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());

    // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
    // fragment manager is responsible for recreating it.
    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
                .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT).commit();
    } else {
        mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
        mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
        mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
        mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
        mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
        mActionBarController.restoreInstanceState(savedInstanceState);
    }

    final boolean isLayoutRtl = DialerUtils.isRtl();
    if (mIsLandscape) {
        mSlideIn = AnimationUtils.loadAnimation(this,
                isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
        mSlideOut = AnimationUtils.loadAnimation(this,
                isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
    } else {
        mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
        mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
    }

    mSlideIn.setInterpolator(AnimUtils.EASE_IN);
    mSlideOut.setInterpolator(AnimUtils.EASE_OUT);

    mSlideIn.setAnimationListener(mSlideInListener);
    mSlideOut.setAnimationListener(mSlideOutListener);

    mParentLayout = (CoordinatorLayout) findViewById(R.id.dialtacts_mainlayout);
    mParentLayout.setOnDragListener(new LayoutOnDragListener());
    floatingActionButtonContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    final ViewTreeObserver observer = floatingActionButtonContainer.getViewTreeObserver();
                    if (!observer.isAlive()) {
                        return;
                    }
                    observer.removeOnGlobalLayoutListener(this);
                    int screenWidth = mParentLayout.getWidth();
                    mFloatingActionButtonController.setScreenWidth(screenWidth);
                    mFloatingActionButtonController.align(getFabAlignment(), false /* animate */);
                }
            });

    Trace.endSection();

    Trace.beginSection(TAG + " initialize smart dialing");
    mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
    SmartDialPrefix.initializeNanpSettings(this);
    Trace.endSection();
    Trace.endSection();
}

From source file:com.segma.trim.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MobileAds.initialize(getApplicationContext(), ADMOB_KEY);
    setContentView(R.layout.activity_main);
    loadAds();/*  ww  w .  ja va  2s  .c om*/
    MEMORY_SIZE = ((ActivityManager) getSystemService(ACTIVITY_SERVICE)).getMemoryClass();
    MAX_BITMAP_PIXELS = calculateMaxBitmapPixels();
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ipv = (ImageProcessingView) findViewById(R.id.ipv);
    loadLicense();
    loadUserSetting();
    final Runnable runnableOnTextView = new Runnable() {
        @Override
        public void run() {
            ipv.setVisibility(View.VISIBLE);
            // TODO: update pending: the image enlarges due to larger space
            rawBitmap = getSampleImage();
            rawBitmapWidth = rawBitmap.getWidth();
            rawBitmapHeight = rawBitmap.getHeight();
            STATE = STATE_PROCESSING_IMAGE;
            textView.setVisibility(View.GONE);
            ipv.process(rawBitmap);
        }
    };
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();
    }

    initControls();
    textView = (TextView) findViewById(R.id.tv_message);
    textView.setEnabled(false);
    ViewTreeObserver viewTreeObserver = ipv.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                ImageProcessingViewWidth = ipv.getWidth();
                ImageProcessingViewHeight = ipv.getHeight();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    ipv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                } else {
                    ipv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
                if (ImageProcessingViewHeight != 0)
                    textView.setEnabled(true);
            }
        });
    }
    textView.setText(MESSAGE_STARTUP);
    textView.setOnTouchListener(new View.OnTouchListener() {
        float original_text_size;

        @Override
        public boolean onTouch(View v, final MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                original_text_size = textView.getTextSize();
                //textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, Math.round(original_text_size * 1.15));
                handlerOnTextView.postDelayed(runnableOnTextView, LONG_PRESS_TIME_ON_TEXTVIEW);
                textView.setEnabled(false);
                break;
            case MotionEvent.ACTION_MOVE:
                handlerOnTextView.removeCallbacks(runnableOnTextView);
                break;
            case MotionEvent.ACTION_UP:
                //textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, original_text_size);
                handlerOnTextView.removeCallbacks(runnableOnTextView);
                v.setEnabled(true);
                break;
            }
            return false;
        }
    });
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    actionBar = getSupportActionBar();
    //actionBar.setDisplayHomeAsUpEnabled(true);
    ipv.setVisibility(View.INVISIBLE);

    if (MODE_DEBUG) {
        LICENSE = LICENSE_PREMIUM;
        getPackageManager().clearPackagePreferredActivities(getApplicationContext().getPackageName());
    }
}

From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java

/**
 * Adds layout listener to view parent to capture layout changes.
 *//*from  ww w .j  a v  a2  s. co  m*/
void addGlobalLayoutListener() {
    final ViewTreeObserver viewTreeObserver = getParentView().getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }
}

From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java

/**
 * Removes global layout listener added in {@link #addGlobalLayoutListener()}.
 *//*from ww w. j  a  v a  2s  .co m*/
void removeGlobalLayoutListener() {
    final ViewTreeObserver viewTreeObserver = getParentView().getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            viewTreeObserver.removeOnGlobalLayoutListener(mGlobalLayoutListener);
        } else {
            //noinspection deprecation
            viewTreeObserver.removeGlobalOnLayoutListener(mGlobalLayoutListener);
        }
    }
}

From source file:com.android.incallui.CallCardFragment.java

@Override
public void animateForNewOutgoingCall() {
    final ViewGroup parent = (ViewGroup) mPrimaryCallCardContainer.getParent();

    final ViewTreeObserver observer = getView().getViewTreeObserver();

    mIsAnimating = true;// w  ww  . ja  v  a2s  . c  o m

    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ViewTreeObserver observer = getView().getViewTreeObserver();
            if (!observer.isAlive()) {
                return;
            }
            observer.removeOnGlobalLayoutListener(this);

            final LayoutIgnoringListener listener = new LayoutIgnoringListener();
            mPrimaryCallCardContainer.addOnLayoutChangeListener(listener);

            // Prepare the state of views before the slide animation
            final int originalHeight = mPrimaryCallCardContainer.getHeight();
            mPrimaryCallCardContainer.setTag(R.id.view_tag_callcard_actual_height, originalHeight);
            mPrimaryCallCardContainer.setBottom(parent.getHeight());

            // Set up FAB.
            mFloatingActionButtonContainer.setVisibility(View.GONE);
            mFloatingActionButtonController.setScreenWidth(parent.getWidth());

            mCallButtonsContainer.setAlpha(0);
            mCallStateLabel.setAlpha(0);
            mPrimaryName.setAlpha(0);
            mCallTypeLabel.setAlpha(0);
            mCallNumberAndLabel.setAlpha(0);

            assignTranslateAnimation(mCallStateLabel, 1);
            assignTranslateAnimation(mCallStateIcon, 1);
            assignTranslateAnimation(mPrimaryName, 2);
            assignTranslateAnimation(mCallNumberAndLabel, 3);
            assignTranslateAnimation(mCallTypeLabel, 4);
            assignTranslateAnimation(mCallButtonsContainer, 5);

            final Animator animator = getShrinkAnimator(parent.getHeight(), originalHeight);

            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mPrimaryCallCardContainer.setTag(R.id.view_tag_callcard_actual_height, null);
                    setViewStatePostAnimation(listener);
                    mIsAnimating = false;
                    InCallPresenter.getInstance().onShrinkAnimationComplete();
                }
            });
            animator.start();
        }
    });
}

From source file:com.android.dialer.DialtactsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final View MenuButtonContainer = view.findViewById(R.id.dialtacts_bottom_menu_container);
    mMenuButtonCall = (ImageButton) view.findViewById(R.id.dialtacts_bottom_menu_button_call);
    mMenuButtonCall.setOnClickListener(this);
    mMenuButtonContacts = (ImageButton) view.findViewById(R.id.dialtacts_bottom_menu_button_contacts);
    mMenuButtonContacts.setOnClickListener(this);
    mMenuButtonSetting = (ImageButton) view.findViewById(R.id.dialtacts_bottom_menu_button_group);
    mMenuButtonSetting.setOnClickListener(this);
    mMenuButtonDelete = (ImageButton) view.findViewById(R.id.dialtacts_bottom_menu_button_delete);

    mMenuButtonDelete.setOnClickListener(this);
    //        mFloatingActionButtonController = new FloatingActionButtonController(this,
    //                MenuButtonContainer, MenuButtonCall);

    final View floatingActionButtonContainer = view.findViewById(R.id.floating_action_button_container);
    //?//www  . ja va2 s  .com
    ImageButton floatingActionButton = (ImageButton) view.findViewById(R.id.floating_action_button);
    floatingActionButton.setOnClickListener(this);

    mFloatingActionButtonController = new FloatingActionButtonController(getActivity(),
            floatingActionButtonContainer, floatingActionButton);

    mParentLayout = (FrameLayout) view.findViewById(R.id.dialtacts_mainlayout);
    mParentLayout.setOnDragListener(new LayoutOnDragListener());
    floatingActionButtonContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    final ViewTreeObserver observer = floatingActionButtonContainer.getViewTreeObserver();
                    if (!observer.isAlive()) {
                        return;
                    }
                    observer.removeOnGlobalLayoutListener(this);
                    int screenWidth = mParentLayout.getWidth();
                    mFloatingActionButtonController.setScreenWidth(screenWidth);
                    mFloatingActionButtonController.align(getFabAlignment(), false /* animate */);

                }
            });
}

From source file:com.androzic.MapFragment.java

private void updateMapViewArea() {
    final ViewTreeObserver vto = map.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        public void onGlobalLayout() {
            View root = getView();
            Rect area = new Rect();
            map.getLocalVisibleRect(area);
            View v = root.findViewById(R.id.topbar);
            if (v != null)
                area.top = v.getBottom();
            v = root.findViewById(R.id.bottombar);
            if (v != null)
                area.bottom = v.getTop();
            v = root.findViewById(R.id.rightbar);
            if (v != null)
                area.right = v.getLeft();
            if (mapButtons.isShown()) {
                // Landscape mode
                if (v != null)
                    area.bottom = mapButtons.getTop();
                else
                    area.right = mapButtons.getLeft();
            }//from   w  w w .  ja  v  a 2s  .  c  o  m
            if (!area.isEmpty())
                map.updateViewArea(area);
            ViewTreeObserver ob;
            if (vto.isAlive())
                ob = vto;
            else
                ob = map.getViewTreeObserver();

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                ob.removeGlobalOnLayoutListener(this);
            } else {
                ob.removeOnGlobalLayoutListener(this);
            }
        }
    });
}

From source file:com.androzic.MapActivity.java

private void updateMapViewArea() {
    final ViewTreeObserver vto = map.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            Rect area = new Rect();
            map.getLocalVisibleRect(area);
            View v = findViewById(R.id.topbar);
            if (v != null)
                area.top = v.getBottom();
            v = findViewById(R.id.bottombar);
            if (v != null)
                area.bottom = v.getTop();
            v = findViewById(R.id.rightbar);
            if (v != null)
                area.right = v.getLeft();
            if (!area.isEmpty())
                map.updateViewArea(area);
            if (vto.isAlive()) {
                vto.removeGlobalOnLayoutListener(this);
            } else {
                final ViewTreeObserver vto1 = map.getViewTreeObserver();
                vto1.removeGlobalOnLayoutListener(this);
            }//from w ww  .  ja  v a  2 s .  c  o  m
        }
    });
}