use of android.view.ViewGroup.LayoutParams in project NoHttp by yanzhenjie.
the class ImageLocalLoader method measureSize.
/**
* According to the ImageView obtains appropriate width and height of compression.
*
* @param imageView {@link ImageView}.
* @param viewSizes ViewSize.
*/
public void measureSize(ImageView imageView, int[] viewSizes) {
final DisplayMetrics displayMetrics = NoHttp.getContext().getResources().getDisplayMetrics();
final LayoutParams params = imageView.getLayoutParams();
if (params == null) {
viewSizes[0] = displayMetrics.widthPixels;
viewSizes[1] = displayMetrics.heightPixels;
} else {
// Get actual image
viewSizes[0] = params.width == LayoutParams.WRAP_CONTENT ? 0 : imageView.getWidth();
// width
// Get actual
viewSizes[1] = params.height == LayoutParams.WRAP_CONTENT ? 0 : imageView.getHeight();
if (viewSizes[0] <= 0)
// Get layout width parameter
viewSizes[0] = displayMetrics.widthPixels;
if (viewSizes[1] <= 0)
// Get layout height parameter
viewSizes[1] = displayMetrics.heightPixels;
}
}
use of android.view.ViewGroup.LayoutParams in project android_frameworks_base by ResurrectionRemix.
the class AlertController method setupTitle.
protected void setupTitle(ViewGroup topPanel) {
if (mCustomTitleView != null && mShowTitle) {
// Add the custom title view directly to the topPanel layout
final LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
topPanel.addView(mCustomTitleView, 0, lp);
// Hide the title template
final View titleTemplate = mWindow.findViewById(R.id.title_template);
titleTemplate.setVisibility(View.GONE);
} else {
mIconView = (ImageView) mWindow.findViewById(R.id.icon);
final boolean hasTextTitle = !TextUtils.isEmpty(mTitle);
if (hasTextTitle && mShowTitle) {
// Display the title if a title is supplied, else hide it.
mTitleView = (TextView) mWindow.findViewById(R.id.alertTitle);
mTitleView.setText(mTitle);
// specified 0 then make it disappear.
if (mIconId != 0) {
mIconView.setImageResource(mIconId);
} else if (mIcon != null) {
mIconView.setImageDrawable(mIcon);
} else {
// Apply the padding from the icon to ensure the title is
// aligned correctly.
mTitleView.setPadding(mIconView.getPaddingLeft(), mIconView.getPaddingTop(), mIconView.getPaddingRight(), mIconView.getPaddingBottom());
mIconView.setVisibility(View.GONE);
}
} else {
// Hide the title template
final View titleTemplate = mWindow.findViewById(R.id.title_template);
titleTemplate.setVisibility(View.GONE);
mIconView.setVisibility(View.GONE);
topPanel.setVisibility(View.GONE);
}
}
}
use of android.view.ViewGroup.LayoutParams in project android_frameworks_base by ResurrectionRemix.
the class AlertController method setupCustomContent.
private void setupCustomContent(ViewGroup customPanel) {
final View customView;
if (mView != null) {
customView = mView;
} else if (mViewLayoutResId != 0) {
final LayoutInflater inflater = LayoutInflater.from(mContext);
customView = inflater.inflate(mViewLayoutResId, customPanel, false);
} else {
customView = null;
}
final boolean hasCustomView = customView != null;
if (!hasCustomView || !canTextInput(customView)) {
mWindow.setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}
if (hasCustomView) {
final FrameLayout custom = (FrameLayout) mWindow.findViewById(R.id.custom);
custom.addView(customView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
if (mViewSpacingSpecified) {
custom.setPadding(mViewSpacingLeft, mViewSpacingTop, mViewSpacingRight, mViewSpacingBottom);
}
if (mListView != null) {
((LinearLayout.LayoutParams) customPanel.getLayoutParams()).weight = 0;
}
} else {
customPanel.setVisibility(View.GONE);
}
}
use of android.view.ViewGroup.LayoutParams in project android_frameworks_base by ResurrectionRemix.
the class DayPickerViewPager method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
populate();
// Everything below is mostly copied from FrameLayout.
int count = getChildCount();
final boolean measureMatchParentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY;
int maxHeight = 0;
int maxWidth = 0;
int childState = 0;
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
measureChild(child, widthMeasureSpec, heightMeasureSpec);
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
maxWidth = Math.max(maxWidth, child.getMeasuredWidth());
maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
childState = combineMeasuredStates(childState, child.getMeasuredState());
if (measureMatchParentChildren) {
if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) {
mMatchParentChildren.add(child);
}
}
}
}
// Account for padding too
maxWidth += getPaddingLeft() + getPaddingRight();
maxHeight += getPaddingTop() + getPaddingBottom();
// Check against our minimum height and width
maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
// Check against our foreground's minimum height and width
final Drawable drawable = getForeground();
if (drawable != null) {
maxHeight = Math.max(maxHeight, drawable.getMinimumHeight());
maxWidth = Math.max(maxWidth, drawable.getMinimumWidth());
}
setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT));
count = mMatchParentChildren.size();
if (count > 1) {
for (int i = 0; i < count; i++) {
final View child = mMatchParentChildren.get(i);
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int childWidthMeasureSpec;
final int childHeightMeasureSpec;
if (lp.width == LayoutParams.MATCH_PARENT) {
childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), MeasureSpec.EXACTLY);
} else {
childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width);
}
if (lp.height == LayoutParams.MATCH_PARENT) {
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY);
} else {
childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom(), lp.height);
}
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
}
}
mMatchParentChildren.clear();
}
use of android.view.ViewGroup.LayoutParams in project android_frameworks_base by ResurrectionRemix.
the class Editor method getTextThumbnailBuilder.
private DragShadowBuilder getTextThumbnailBuilder(int start, int end) {
TextView shadowView = (TextView) View.inflate(mTextView.getContext(), com.android.internal.R.layout.text_drag_thumbnail, null);
if (shadowView == null) {
throw new IllegalArgumentException("Unable to inflate text drag thumbnail");
}
if (end - start > DRAG_SHADOW_MAX_TEXT_LENGTH) {
final long range = getCharClusterRange(start + DRAG_SHADOW_MAX_TEXT_LENGTH);
end = TextUtils.unpackRangeEndFromLong(range);
}
final CharSequence text = mTextView.getTransformedText(start, end);
shadowView.setText(text);
shadowView.setTextColor(mTextView.getTextColors());
shadowView.setTextAppearance(R.styleable.Theme_textAppearanceLarge);
shadowView.setGravity(Gravity.CENTER);
shadowView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
final int size = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
shadowView.measure(size, size);
shadowView.layout(0, 0, shadowView.getMeasuredWidth(), shadowView.getMeasuredHeight());
shadowView.invalidate();
return new DragShadowBuilder(shadowView);
}
Aggregations