use of android.view.ViewTreeObserver in project android-extendedactionbar by Takhion.
the class ExtendedActionBarActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
final Resources res = getResources();
final boolean isKitkat = Build.VERSION.SDK_INT >= 19;
// replace window background to reduce overdraw
final Window window = getWindow();
final ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
final View content = contentView.getChildAt(0);
final Drawable extendedWindowBackground = window.getDecorView().getBackground();
final Drawable windowBackground = !isKitkat ? extendedWindowBackground : getWindowBackgroundLayer(extendedWindowBackground, R.id.window_background, "window_background");
window.setBackgroundDrawable(null);
setBackground(content, windowBackground);
// add statusbar background
if (isKitkat) {
// check if translucent bars are enabled
final int config_enableTranslucentDecor_id = res.getIdentifier("config_enableTranslucentDecor", "bool", "android");
if (config_enableTranslucentDecor_id > 0 && res.getBoolean(config_enableTranslucentDecor_id)) {
// get ActionBar container
final View actionBarContainer = findViewById("action_bar_container", "android");
if (actionBarContainer != null) {
// add layout listener (can't get margin before layout)
//noinspection ConstantConditions
actionBarContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressWarnings("ConstantConditions")
@Override
public void onGlobalLayout() {
// remove layout listener
final ViewTreeObserver vto = actionBarContainer.getViewTreeObserver();
if (Build.VERSION.SDK_INT < 16)
vto.removeGlobalOnLayoutListener(this);
else
vto.removeOnGlobalLayoutListener(this);
// create and add statusbar background view
final Drawable statusBarBackground = getWindowBackgroundLayer(extendedWindowBackground, R.id.statusbar_background, "statusbar_background");
final int statusBarHeight = ((ViewGroup.MarginLayoutParams) actionBarContainer.getLayoutParams()).topMargin;
final View statusBarView = new View(ExtendedActionBarActivity.this);
setBackground(statusBarView, statusBarBackground);
final FrameLayout.LayoutParams statusBarBackground_lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight, Gravity.TOP | Gravity.FILL_HORIZONTAL);
contentView.addView(statusBarView, 0, statusBarBackground_lp);
// shift content under actionbar
final ViewGroup.MarginLayoutParams content_lp = (ViewGroup.MarginLayoutParams) content.getLayoutParams();
content_lp.topMargin = getActionBar().getHeight() + statusBarHeight;
content.setLayoutParams(content_lp);
}
});
}
}
}
}
use of android.view.ViewTreeObserver in project ElasticDownload by Tibolte.
the class ElasticDownloadView method onFinishInflate.
/**
* MARK: Overrides
*/
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mIntroView = (IntroView) findViewById(R.id.intro_view);
mIntroView.setListener(this);
mProgressDownloadView = (ProgressDownloadView) findViewById(R.id.progress_download_view);
ViewTreeObserver vto = mProgressDownloadView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mProgressDownloadView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
mProgressDownloadView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
mIntroView.getLayoutParams().width = mProgressDownloadView.getWidth();
mIntroView.getLayoutParams().height = mProgressDownloadView.getHeight();
mProgressDownloadView.setBackgroundColor(mBackgroundColor);
}
});
}
use of android.view.ViewTreeObserver in project HoloEverywhere by Prototik.
the class ActivityChooserView method onDetachedFromWindow.
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
ActivityChooserModel dataModel = mAdapter.getDataModel();
if (dataModel != null) {
dataModel.unregisterObserver(mModelDataSetOberver);
}
ViewTreeObserver viewTreeObserver = getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
}
if (isShowingPopup()) {
dismissPopup();
}
mIsAttachedToWindow = false;
}
use of android.view.ViewTreeObserver in project HoloEverywhere by Prototik.
the class PopupWindow method registerForScrollChanged.
private void registerForScrollChanged(View anchor, int xoff, int yoff) {
unregisterForScrollChanged();
mAnchor = new WeakReference<View>(anchor);
ViewTreeObserver vto = anchor.getViewTreeObserver();
if (vto != null) {
vto.addOnScrollChangedListener(mOnScrollChangedListener);
}
mAnchorXoff = xoff;
mAnchorYoff = yoff;
}
use of android.view.ViewTreeObserver in project android_frameworks_base by ParanoidAndroid.
the class LayoutTransition method runChangeTransition.
/**
* This function sets up animations on all of the views that change during layout.
* For every child in the parent, we create a change animation of the appropriate
* type (appearing, disappearing, or changing) and ask it to populate its start values from its
* target view. We add layout listeners to all child views and listen for changes. For
* those views that change, we populate the end values for those animations and start them.
* Animations are not run on unchanging views.
*
* @param parent The container which is undergoing a change.
* @param newView The view being added to or removed from the parent. May be null if the
* changeReason is CHANGING.
* @param changeReason A value of APPEARING, DISAPPEARING, or CHANGING, indicating whether the
* transition is occurring because an item is being added to or removed from the parent, or
* if it is running in response to a layout operation (that is, if the value is CHANGING).
*/
private void runChangeTransition(final ViewGroup parent, View newView, final int changeReason) {
Animator baseAnimator = null;
Animator parentAnimator = null;
final long duration;
switch(changeReason) {
case APPEARING:
baseAnimator = mChangingAppearingAnim;
duration = mChangingAppearingDuration;
parentAnimator = defaultChangeIn;
break;
case DISAPPEARING:
baseAnimator = mChangingDisappearingAnim;
duration = mChangingDisappearingDuration;
parentAnimator = defaultChangeOut;
break;
case CHANGING:
baseAnimator = mChangingAnim;
duration = mChangingDuration;
parentAnimator = defaultChange;
break;
default:
// Shouldn't reach here
duration = 0;
break;
}
// If the animation is null, there's nothing to do
if (baseAnimator == null) {
return;
}
// reset the inter-animation delay, in case we use it later
staggerDelay = 0;
// used for later cleanup
final ViewTreeObserver observer = parent.getViewTreeObserver();
if (!observer.isAlive()) {
// If the observer's not in a good state, skip the transition
return;
}
int numChildren = parent.getChildCount();
for (int i = 0; i < numChildren; ++i) {
final View child = parent.getChildAt(i);
// only animate the views not being added or removed
if (child != newView) {
setupChangeAnimation(parent, changeReason, baseAnimator, duration, child);
}
}
if (mAnimateParentHierarchy) {
ViewGroup tempParent = parent;
while (tempParent != null) {
ViewParent parentParent = tempParent.getParent();
if (parentParent instanceof ViewGroup) {
setupChangeAnimation((ViewGroup) parentParent, changeReason, parentAnimator, duration, tempParent);
tempParent = (ViewGroup) parentParent;
} else {
tempParent = null;
}
}
}
// This is the cleanup step. When we get this rendering event, we know that all of
// the appropriate animations have been set up and run. Now we can clear out the
// layout listeners.
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
parent.getViewTreeObserver().removeOnPreDrawListener(this);
int count = layoutChangeListenerMap.size();
if (count > 0) {
Collection<View> views = layoutChangeListenerMap.keySet();
for (View view : views) {
View.OnLayoutChangeListener listener = layoutChangeListenerMap.get(view);
view.removeOnLayoutChangeListener(listener);
}
}
layoutChangeListenerMap.clear();
return true;
}
});
}
Aggregations