use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project UltimateAndroid by cymcsg.
the class RoundCornerProgressBar method setup.
@SuppressLint("NewApi")
private void setup(Context context, AttributeSet attrs) {
int color;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
radius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, metrics);
radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundRadius, radius);
layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padding, metrics);
padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundPadding, padding);
layoutBackground.setPadding(padding, padding, padding, padding);
if (!isBackgroundColorSetBeforeDraw) {
color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_backgroundColor, backgroundColor);
setBackgroundColor(color);
}
ViewTreeObserver observer = layoutBackground.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layoutBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int height = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
backgroundWidth = layoutBackground.getMeasuredWidth();
height = layoutBackground.getMeasuredHeight();
} else {
backgroundWidth = layoutBackground.getWidth();
height = layoutBackground.getHeight();
}
backgroundHeight = (height == 0) ? (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT) : height;
LayoutParams params = (LayoutParams) layoutBackground.getLayoutParams();
params.height = backgroundHeight;
layoutBackground.setLayoutParams(params);
setProgress(progress);
}
});
layoutProgress = (LinearLayout) findViewById(R.id.round_corner_progress_progress);
if (!isProgressColorSetBeforeDraw) {
color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_progressColor, progressColor);
setProgressColor(color);
}
if (!isMaxProgressSetBeforeDraw) {
max = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_max, 0);
}
if (!isProgressSetBeforeDraw) {
progress = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_progress, 0);
}
typedArray.recycle();
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project Launcher3 by chislon.
the class WallpaperPickerActivity method initializeScrollForRtl.
private void initializeScrollForRtl() {
final HorizontalScrollView scroll = (HorizontalScrollView) findViewById(R.id.wallpaper_scroll_container);
if (scroll.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
final ViewTreeObserver observer = scroll.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
public void onGlobalLayout() {
LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);
scroll.scrollTo(masterWallpaperList.getWidth(), 0);
scroll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project Launcher3 by chislon.
the class CropView method moveToLeft.
public void moveToLeft() {
if (getWidth() == 0 || getHeight() == 0) {
final ViewTreeObserver observer = getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
public void onGlobalLayout() {
moveToLeft();
getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
final RectF edges = mTempEdges;
getEdgesHelper(edges);
final float scale = mRenderer.scale;
mCenterX += Math.ceil(edges.left / scale);
updateCenter();
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project UltimateAndroid by cymcsg.
the class FlowerFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mConverView = LayoutInflater.from(getActivity()).inflate(R.layout.switch_animation_view_fragment, null);
mConverView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
new SwitchAnimationUtil().startAnimation(mConverView, Constant.mType);
}
});
return mConverView;
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project FadingActionBar by ManuelPeinado.
the class FadingActionBarHelperBase method createView.
public final View createView(LayoutInflater inflater) {
//
// Prepare everything
mInflater = inflater;
if (mContentView == null) {
mContentView = inflater.inflate(mContentLayoutResId, null);
}
if (mHeaderView == null) {
mHeaderView = inflater.inflate(mHeaderLayoutResId, null, false);
}
//
// See if we are in a ListView, WebView or ScrollView scenario
ListView listView = (ListView) mContentView.findViewById(android.R.id.list);
View root;
if (listView != null) {
root = createListView(listView);
} else if (mContentView instanceof ObservableWebViewWithHeader) {
root = createWebView();
} else {
root = createScrollView();
}
if (mHeaderOverlayView == null && mHeaderOverlayLayoutResId != 0) {
mHeaderOverlayView = inflater.inflate(mHeaderOverlayLayoutResId, mMarginView, false);
}
if (mHeaderOverlayView != null) {
mMarginView.addView(mHeaderOverlayView);
}
// Use measured height here as an estimate of the header height, later on after the layout is complete
// we'll use the actual height
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.MATCH_PARENT, MeasureSpec.EXACTLY);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY);
mHeaderView.measure(widthMeasureSpec, heightMeasureSpec);
updateHeaderHeight(mHeaderView.getMeasuredHeight());
root.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int headerHeight = mHeaderContainer.getHeight();
if (!mFirstGlobalLayoutPerformed && headerHeight != 0) {
updateHeaderHeight(headerHeight);
mFirstGlobalLayoutPerformed = true;
}
}
});
return root;
}
Aggregations