use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project KJFrameForAndroid by kymjs.
the class CurtainViewController method prepareSlidingLayout.
/**
* 为控件做一些属性设置
*/
protected void prepareSlidingLayout() {
curtainLayoutParams = (FrameLayout.LayoutParams) curtainParent.getLayoutParams();
ViewTreeObserver vto = curtainParent.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
@SuppressLint("NewApi")
public void onGlobalLayout() {
hideCurtainLayout();
ViewTreeObserver obs = curtainParent.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
}
});
curtainParent.setOnTouchListener(new OnContentTouchListener());
curtainParent.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && getSlidingStatus() == SlidingStatus.EXPANDED) {
collapse();
return true;
} else {
return false;
}
}
});
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project BeyondUPnP by kevinshine.
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 superCleanMaster by joyoyao.
the class TextRoundCornerProgressBar method setup.
@SuppressLint("NewApi")
private void setup(Context context, AttributeSet attrs) {
int color;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);
autoTextChange = typedArray.getBoolean(R.styleable.RoundCornerProgress_autoTextChange, false);
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, metrics);
radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_backgroundRadius, radius);
textViewValue = (TextView) findViewById(R.id.round_corner_progress_text);
textSize = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_textProgressSize, textSize);
textViewValue.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
textViewValue.setTextColor(typedArray.getColor(R.styleable.RoundCornerProgress_textProgressColor, textColor));
text = typedArray.getString(R.styleable.RoundCornerProgress_textProgress);
text = (text == null) ? "" : text;
textViewValue.setText(text);
textPadding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_textProgressPadding, textPadding);
textViewValue.setPadding(textPadding, 0, textPadding, 0);
textUnit = typedArray.getString(R.styleable.RoundCornerProgress_textProgressUnit);
textUnit = (textUnit == null) ? "" : textUnit;
textWidth = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_textProgressWidth, textWidth);
layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_backgroundPadding, padding);
layoutBackground.setPadding(padding, padding, padding, padding);
if (!isBackgroundColorSetBeforeDraw) {
color = typedArray.getColor(R.styleable.RoundCornerProgress_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() - textWidth;
height = layoutBackground.getMeasuredHeight();
} else {
backgroundWidth = layoutBackground.getWidth() - textWidth;
height = layoutBackground.getHeight();
}
backgroundHeight = (height == 0) ? (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT) : height;
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) layoutBackground.getLayoutParams();
params.width = backgroundWidth;
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_progressColor, progressColor);
setProgressColor(color);
}
if (!isMaxProgressSetBeforeDraw) {
max = (int) typedArray.getInt(R.styleable.RoundCornerProgress_max, 0);
}
if (!isProgressSetBeforeDraw) {
progress = (int) typedArray.getInt(R.styleable.RoundCornerProgress_progress1, 0);
}
typedArray.recycle();
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project superCleanMaster by joyoyao.
the class SlidingTab 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() {
@Override
public void onGlobalLayout() {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
currentPosition = pager.getCurrentItem();
scrollToChild(currentPosition, 0);
}
});
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project Android-ParallaxHeaderViewPager by kmshack.
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);
}
});
}
Aggregations