Search in sources :

Example 36 with ViewTreeObserver

use of android.view.ViewTreeObserver in project Libraries-for-Android-Developers by eoecn.

the class ActivityChooserView method dismissPopup.

/**
     * Dismisses the popup window with activities.
     *
     * @return True if dismissed, false if already dismissed.
     */
public boolean dismissPopup() {
    if (isShowingPopup()) {
        getListPopupWindow().dismiss();
        ViewTreeObserver viewTreeObserver = getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
        }
    }
    return true;
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Example 37 with ViewTreeObserver

use of android.view.ViewTreeObserver in project Libraries-for-Android-Developers by eoecn.

the class ActivityChooserView method onDetachedFromWindow.

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    ActivityChooserModel dataModel = mAdapter.getDataModel();
    if (dataModel != null) {
        try {
            dataModel.unregisterObserver(mModelDataSetOberver);
        } catch (IllegalStateException e) {
        //Oh, well... fixes issue #557
        }
    }
    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
    }
    mIsAttachedToWindow = false;
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Example 38 with ViewTreeObserver

use of android.view.ViewTreeObserver in project zxingfragmentlib by mitoyarzun.

the class SampleStretchedActivity method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stretched_sample);
    FragmentManager fm = getSupportFragmentManager();
    mScannerFragment = (BarCodeScannerFragment) fm.findFragmentById(R.id.scanner_fragment);
    layoutContent = (LinearLayout) findViewById(R.id.layout_content);
    final ViewTreeObserver observer = layoutContent.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            // We're assuming that the other layout is under the scanner
            int activityWidth = layoutContent.getWidth();
            int activityHeight = findViewById(R.id.scanner_fragment).getHeight();
            int usableWidth = layoutContent.getWidth();
            int usableHeight = activityHeight - layoutContent.getHeight();
            int desiredHeight = (int) (usableHeight * 0.8);
            int desiredWidth = (int) (usableWidth * 0.75);
            Rect framingRect = new Rect(// left
            (usableWidth - desiredWidth) / 2, // top
            (usableHeight - desiredHeight) / 2, // right
            (usableWidth - desiredWidth) / 2 + desiredWidth, // bottom
            (usableHeight - desiredHeight) / 2 + desiredHeight);
            Log.v("RECT", "left: " + framingRect.left + " top: " + framingRect.top + " right: " + framingRect.right + " bottom: " + framingRect.bottom + " activityHeight: " + activityHeight + " activitiWidth: " + activityWidth);
        //        mScannerFragment.setFramingRect(framingRect);
        }
    });
//    mToggleButton = (Button) findViewById(R.id.button_flash);
//    mToggleButton.setOnClickListener(createToggleFlashListener());
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) Rect(android.graphics.Rect) ViewTreeObserver(android.view.ViewTreeObserver)

Example 39 with ViewTreeObserver

use of android.view.ViewTreeObserver in project AndroidTraining by mixi-inc.

the class ActivityChooserView method dismissPopup.

/**
     * Dismisses the popup window with activities.
     *
     * @return True if dismissed, false if already dismissed.
     */
public boolean dismissPopup() {
    if (isShowingPopup()) {
        getListPopupWindow().dismiss();
        ViewTreeObserver viewTreeObserver = getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
        }
    }
    return true;
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Example 40 with ViewTreeObserver

use of android.view.ViewTreeObserver in project SmartAndroidSource by jaychou2012.

the class MenuPopupHelper method tryShow.

public boolean tryShow() {
    mPopup = new IcsListPopupWindow(mContext, null, android.R.attr.popupMenuStyle);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mAdapter = new MenuAdapter(mMenu);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);
    View anchor = mAnchorView;
    if (anchor != null) {
        // avoid VTO-related leaks.
        if (anchor.getWindowToken() != null) {
            ViewTreeObserver vto = anchor.getViewTreeObserver();
            if (vto != mTreeObserver) {
                if (mTreeObserver != null && mTreeObserver.isAlive()) {
                    mTreeObserver.removeGlobalOnLayoutListener(this);
                }
                if ((mTreeObserver = vto) != null) {
                    vto.addOnGlobalLayoutListener(this);
                }
            }
        } else if (anchor instanceof View_HasStateListenerSupport) {
            ((View_HasStateListenerSupport) anchor).addOnAttachStateChangeListener(this);
        }
        mPopup.setAnchorView(anchor);
    } else {
        return false;
    }
    mPopup.setContentWidth(Math.min(measureContentWidth(mAdapter), mPopupMaxWidth));
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}
Also used : View_HasStateListenerSupport(com.smartandroid.sa.sherlock.internal.view.View_HasStateListenerSupport) View(android.view.View) AdapterView(android.widget.AdapterView) ViewTreeObserver(android.view.ViewTreeObserver) IcsListPopupWindow(com.smartandroid.sa.sherlock.internal.widget.IcsListPopupWindow)

Aggregations

ViewTreeObserver (android.view.ViewTreeObserver)222 View (android.view.View)56 OnGlobalLayoutListener (android.view.ViewTreeObserver.OnGlobalLayoutListener)25 ImageView (android.widget.ImageView)25 TextView (android.widget.TextView)15 ViewGroup (android.view.ViewGroup)14 SuppressLint (android.annotation.SuppressLint)13 AdapterView (android.widget.AdapterView)12 TypedArray (android.content.res.TypedArray)7 Test (org.junit.Test)7 RectF (android.graphics.RectF)6 DisplayMetrics (android.util.DisplayMetrics)6 ViewParent (android.view.ViewParent)6 LinearLayout (android.widget.LinearLayout)6 ListView (android.widget.ListView)6 Resources (android.content.res.Resources)5 ValueAnimator (android.animation.ValueAnimator)4 TargetApi (android.annotation.TargetApi)4 Activity (android.app.Activity)4 Paint (android.graphics.Paint)4