Search in sources :

Example 26 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project XobotOS by xamarin.

the class TextView method getTextThumbnailBuilder.

private DragShadowBuilder getTextThumbnailBuilder(CharSequence text) {
    TextView shadowView = (TextView) inflate(mContext, com.android.internal.R.layout.text_drag_thumbnail, null);
    if (shadowView == null) {
        throw new IllegalArgumentException("Unable to inflate text drag thumbnail");
    }
    if (text.length() > DRAG_SHADOW_MAX_TEXT_LENGTH) {
        text = text.subSequence(0, DRAG_SHADOW_MAX_TEXT_LENGTH);
    }
    shadowView.setText(text);
    shadowView.setTextColor(getTextColors());
    shadowView.setTextAppearance(mContext, 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);
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 27 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project ZI by yixia.

the class QuickAction method show.

/**
	 * Show popup window. Popup is automatically positioned, on top or bottom of
	 * anchor view.
	 * 
	 */
@SuppressWarnings("deprecation")
public void show(View anchor, int x, int y) {
    preShow();
    int xPos, yPos;
    int[] location = new int[2];
    anchor.getLocationOnScreen(location);
    Rect anchorRect = new Rect(location[0], location[1], location[0] + anchor.getWidth(), location[1] + anchor.getHeight());
    mRootView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    int rootHeight = mRootView.getMeasuredHeight();
    int rootWidth = mRootView.getMeasuredWidth();
    int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
    int screenHeight = mWindowManager.getDefaultDisplay().getHeight();
    //automatically get X coord of popup (top left)
    if ((anchorRect.left + rootWidth) > screenWidth) {
        xPos = anchorRect.left - (rootWidth - anchor.getWidth());
    } else {
        if (anchor.getWidth() > rootWidth) {
            xPos = anchorRect.centerX() - (rootWidth / 2);
        } else {
            xPos = anchorRect.left;
        }
    }
    int dyTop = anchorRect.top;
    int dyBottom = screenHeight - anchorRect.bottom;
    boolean onTop = (dyTop > dyBottom) ? true : false;
    if (onTop) {
        if (rootHeight > dyTop) {
            yPos = 15;
            LayoutParams l = mScroller.getLayoutParams();
            l.height = dyTop - anchor.getHeight();
        } else {
            yPos = anchorRect.top - rootHeight;
        }
    } else {
        yPos = anchorRect.bottom;
        if (rootHeight > dyBottom) {
            LayoutParams l = mScroller.getLayoutParams();
            l.height = dyBottom;
        }
    }
    showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), anchorRect.centerX() - xPos);
    setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);
    if (onTop)
        mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos + x, yPos - y);
    else
        mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos + x, yPos + y);
}
Also used : Rect(android.graphics.Rect) LayoutParams(android.view.ViewGroup.LayoutParams)

Example 28 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project XobotOS by xamarin.

the class Activity method dispatchPopulateAccessibilityEvent.

public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    event.setClassName(getClass().getName());
    event.setPackageName(getPackageName());
    LayoutParams params = getWindow().getAttributes();
    boolean isFullScreen = (params.width == LayoutParams.MATCH_PARENT) && (params.height == LayoutParams.MATCH_PARENT);
    event.setFullScreen(isFullScreen);
    CharSequence title = getTitle();
    if (!TextUtils.isEmpty(title)) {
        event.getText().add(title);
    }
    return true;
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams)

Example 29 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project XobotOS by xamarin.

the class KeyboardView method showKey.

private void showKey(final int keyIndex) {
    final PopupWindow previewPopup = mPreviewPopup;
    final Key[] keys = mKeys;
    if (keyIndex < 0 || keyIndex >= mKeys.length)
        return;
    Key key = keys[keyIndex];
    if (key.icon != null) {
        mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon);
        mPreviewText.setText(null);
    } else {
        mPreviewText.setCompoundDrawables(null, null, null, null);
        mPreviewText.setText(getPreviewText(key));
        if (key.label.length() > 1 && key.codes.length < 2) {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
            mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
        } else {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
            mPreviewText.setTypeface(Typeface.DEFAULT);
        }
    }
    mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
    final int popupHeight = mPreviewHeight;
    LayoutParams lp = mPreviewText.getLayoutParams();
    if (lp != null) {
        lp.width = popupWidth;
        lp.height = popupHeight;
    }
    if (!mPreviewCentered) {
        mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + mPaddingLeft;
        mPopupPreviewY = key.y - popupHeight + mPreviewOffset;
    } else {
        // TODO: Fix this if centering is brought back
        mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
        mPopupPreviewY = -mPreviewText.getMeasuredHeight();
    }
    mHandler.removeMessages(MSG_REMOVE_PREVIEW);
    getLocationInWindow(mCoordinates);
    // Offset may be zero
    mCoordinates[0] += mMiniKeyboardOffsetX;
    // Offset may be zero
    mCoordinates[1] += mMiniKeyboardOffsetY;
    // Set the preview background state
    mPreviewText.getBackground().setState(key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
    mPopupPreviewX += mCoordinates[0];
    mPopupPreviewY += mCoordinates[1];
    // If the popup cannot be shown above the key, put it on the side
    getLocationOnScreen(mCoordinates);
    if (mPopupPreviewY + mCoordinates[1] < 0) {
        // the right, offset by enough to see at least one key to the left/right.
        if (key.x + key.width <= getWidth() / 2) {
            mPopupPreviewX += (int) (key.width * 2.5);
        } else {
            mPopupPreviewX -= (int) (key.width * 2.5);
        }
        mPopupPreviewY += popupHeight;
    }
    if (previewPopup.isShowing()) {
        previewPopup.update(mPopupPreviewX, mPopupPreviewY, popupWidth, popupHeight);
    } else {
        previewPopup.setWidth(popupWidth);
        previewPopup.setHeight(popupHeight);
        previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY, mPopupPreviewX, mPopupPreviewY);
    }
    mPreviewText.setVisibility(VISIBLE);
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) PopupWindow(android.widget.PopupWindow) Key(android.inputmethodservice.Keyboard.Key) Paint(android.graphics.Paint)

Example 30 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project platform_frameworks_base by android.

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);
        }
    }
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView)

Aggregations

LayoutParams (android.view.ViewGroup.LayoutParams)265 TextView (android.widget.TextView)56 View (android.view.View)50 ViewGroup (android.view.ViewGroup)50 FrameLayout (android.widget.FrameLayout)35 LinearLayout (android.widget.LinearLayout)33 ImageView (android.widget.ImageView)30 Test (org.junit.Test)26 Paint (android.graphics.Paint)22 ListView (android.widget.ListView)22 ScrollView (android.widget.ScrollView)22 Context (android.content.Context)19 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)19 AdapterView (android.widget.AdapterView)17 RelativeLayout (android.widget.RelativeLayout)14 DisplayMetrics (android.util.DisplayMetrics)12 CheckedTextView (android.widget.CheckedTextView)12 Rect (android.graphics.Rect)9 ViewParent (android.view.ViewParent)9 TypedArray (android.content.res.TypedArray)8