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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations