use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project PagerSlidingTabStrip by astuetz.
the class PagerSlidingTabStrip method notifyDataSetChanged.
public void notifyDataSetChanged() {
tabsContainer.removeAllViews();
tabCount = pager.getAdapter().getCount();
for (int i = 0; i < tabCount; i++) {
if (pager.getAdapter() instanceof IconTabProvider) {
addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
} else {
addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
}
}
updateTabStyles();
getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
currentPosition = pager.getCurrentItem();
scrollToChild(currentPosition, 0);
}
});
}
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 UltimateAndroid by cymcsg.
the class IconRoundCornerProgressBar 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);
padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padding, metrics);
padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundPadding, padding);
imageIcon = (ImageView) findViewById(R.id.round_corner_progress_icon);
imageIcon.setScaleType(ScaleType.CENTER_CROP);
if (!isIconSetBeforeDraw) {
int iconResource = (int) typedArray.getResourceId(R.styleable.RoundCornerProgress_rcp_iconSrc, R.drawable.round_corner_progress_icon);
imageIcon.setImageResource(iconResource);
}
iconSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, iconSize, metrics);
iconSize = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_iconSize, iconSize);
imageIcon.setLayoutParams(new LayoutParams(iconSize, iconSize));
layoutHeader = (LinearLayout) findViewById(R.id.round_corner_progress_header);
iconPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, iconPadding, metrics);
iconPadding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_iconPadding, iconPadding);
layoutHeader.setPadding(iconPadding, iconPadding, iconPadding, iconPadding);
if (!isHeaderColorSetBeforeDraw) {
color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_headerColor, headerColor);
setHeaderColor(color);
}
ViewTreeObserver observer = layoutHeader.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layoutHeader.getViewTreeObserver().removeOnGlobalLayoutListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
headerWidth = layoutHeader.getMeasuredWidth();
} else {
headerWidth = layoutHeader.getWidth();
}
if (backgroundWidth > 0)
setProgress(progress);
}
});
layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
layoutBackground.setPadding(padding, padding, padding, padding);
if (!isBackgroundColorSetBeforeDraw) {
color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_backgroundColor, backgroundColor);
setBackgroundColor(color);
}
observer = layoutBackground.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layoutBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
backgroundWidth = layoutBackground.getMeasuredWidth();
} else {
backgroundWidth = layoutBackground.getWidth();
}
if (headerWidth > 0)
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 = typedArray.getInt(R.styleable.RoundCornerProgress_rcp_max, 0);
}
if (!isProgressSetBeforeDraw) {
progress = typedArray.getInt(R.styleable.RoundCornerProgress_rcp_progress, 0);
}
typedArray.recycle();
}
Aggregations