Search in sources :

Example 6 with ViewGroup

use of android.view.ViewGroup in project cw-omnibus by commonsguy.

the class IcsListPopupWindow method buildDropDown.

private int buildDropDown() {
    ViewGroup dropDownView;
    int otherHeights = 0;
    if (mDropDownList == null) {
        Context context = mContext;
        mDropDownList = new DropDownListView(context, !mModal);
        if (mDropDownListHighlight != null) {
            mDropDownList.setSelector(mDropDownListHighlight);
        }
        mDropDownList.setAdapter(mAdapter);
        mDropDownList.setOnItemClickListener(mItemClickListener);
        mDropDownList.setFocusable(true);
        mDropDownList.setFocusableInTouchMode(true);
        mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (position != -1) {
                    DropDownListView dropDownList = mDropDownList;
                    if (dropDownList != null) {
                        dropDownList.mListSelectionHidden = false;
                    }
                }
            }

            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        mDropDownList.setOnScrollListener(mScrollListener);
        if (mItemSelectedListener != null) {
            mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
        }
        dropDownView = mDropDownList;
        View hintView = mPromptView;
        if (hintView != null) {
            // if an hint has been specified, we accomodate more space for it and
            // add a text view in the drop down menu, at the bottom of the list
            LinearLayout hintContainer = new LinearLayout(context);
            hintContainer.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f);
            switch(mPromptPosition) {
                case POSITION_PROMPT_BELOW:
                    hintContainer.addView(dropDownView, hintParams);
                    hintContainer.addView(hintView);
                    break;
                case POSITION_PROMPT_ABOVE:
                    hintContainer.addView(hintView);
                    hintContainer.addView(dropDownView, hintParams);
                    break;
                default:
                    break;
            }
            // measure the hint's height to find how much more vertical space
            // we need to add to the drop down's height
            int widthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.AT_MOST);
            int heightSpec = MeasureSpec.UNSPECIFIED;
            hintView.measure(widthSpec, heightSpec);
            hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams();
            otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
            dropDownView = hintContainer;
        }
        mPopup.setContentView(dropDownView);
    } else {
        dropDownView = (ViewGroup) mPopup.getContentView();
        final View view = mPromptView;
        if (view != null) {
            LinearLayout.LayoutParams hintParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
        }
    }
    // getMaxAvailableHeight() subtracts the padding, so we put it back
    // to get the available height for the whole window
    int padding = 0;
    Drawable background = mPopup.getBackground();
    if (background != null) {
        background.getPadding(mTempRect);
        padding = mTempRect.top + mTempRect.bottom;
        // background so that content will line up.
        if (!mDropDownVerticalOffsetSet) {
            mDropDownVerticalOffset = -mTempRect.top;
        }
    }
    // Max height available on the screen for a popup.
    boolean ignoreBottomDecorations = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
    final int maxHeight = /*mPopup.*/
    getMaxAvailableHeight(mDropDownAnchorView, mDropDownVerticalOffset, ignoreBottomDecorations);
    if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
        return maxHeight + padding;
    }
    final int listContent = /*mDropDownList.*/
    measureHeightOfChildren(MeasureSpec.UNSPECIFIED, 0, -1, /*ListView.NO_POSITION*/
    maxHeight - otherHeights, -1);
    // the popup if it is not needed
    if (listContent > 0)
        otherHeights += padding;
    return listContent + otherHeights;
}
Also used : Context(android.content.Context) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) AbsListView(android.widget.AbsListView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout)

Example 7 with ViewGroup

use of android.view.ViewGroup in project cw-omnibus by commonsguy.

the class IcsListPopupWindow method dismiss.

public void dismiss() {
    mPopup.dismiss();
    if (mPromptView != null) {
        final ViewParent parent = mPromptView.getParent();
        if (parent instanceof ViewGroup) {
            final ViewGroup group = (ViewGroup) parent;
            group.removeView(mPromptView);
        }
    }
    mPopup.setContentView(null);
    mDropDownList = null;
    mHandler.removeCallbacks(mResizePopupRunnable);
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup)

Example 8 with ViewGroup

use of android.view.ViewGroup in project cw-omnibus by commonsguy.

the class TextIconGenerator method makeIcon.

/**
     * Creates an icon with the current content and style.
     * <p/>
     * This method is useful if a custom view has previously been set, or if text content is not
     * applicable.
     */
public Bitmap makeIcon() {
    ViewGroup container = getContainer();
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    container.measure(measureSpec, measureSpec);
    int measuredWidth = container.getMeasuredWidth();
    int measuredHeight = container.getMeasuredHeight();
    container.layout(0, 0, measuredWidth, measuredHeight);
    if (mRotation == 1 || mRotation == 3) {
        measuredHeight = container.getMeasuredWidth();
        measuredWidth = container.getMeasuredHeight();
    }
    Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
    r.eraseColor(Color.TRANSPARENT);
    Canvas canvas = new Canvas(r);
    if (mRotation == 0) {
    // do nothing
    } else if (mRotation == 1) {
        canvas.translate(measuredWidth, 0);
        canvas.rotate(90);
    } else if (mRotation == 2) {
        canvas.rotate(180, measuredWidth / 2, measuredHeight / 2);
    } else {
        canvas.translate(0, measuredHeight);
        canvas.rotate(270);
    }
    container.draw(canvas);
    return r;
}
Also used : Bitmap(android.graphics.Bitmap) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas)

Example 9 with ViewGroup

use of android.view.ViewGroup in project UltimateAndroid by cymcsg.

the class LoadToastLibActivity method onCreate.

// Example activity
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.load_toast_lib_activity_main);
    final String text = "Sending reply...";
    final LoadToast lt = new LoadToast(this).setText(text).setTranslationY(100).show();
    final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
    View v = new View(this);
    v.setBackgroundColor(Color.RED);
    root.addView(v, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 400));
    findViewById(R.id.show).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            lt.show();
        }
    });
    findViewById(R.id.error).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            lt.error();
        }
    });
    findViewById(R.id.success).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            lt.success();
        }
    });
    findViewById(R.id.refresh).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            View v = new View(LoadToastLibActivity.this);
            v.setBackgroundColor(Color.rgb((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255)));
            root.addView(v, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 400));
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) LoadToast(net.steamcrafted.loadtoast.LoadToast) View(android.view.View)

Example 10 with ViewGroup

use of android.view.ViewGroup in project GeekNews by codeestX.

the class CircularAnimUtil method startActivityForResult.

/**
     * 从指定View开始向四周伸张(伸张颜色或图片为colorOrImageRes), 然后进入另一个Activity,
     * 返回至 @thisActivity 后显示收缩动画。
     */
@SuppressLint("NewApi")
public static void startActivityForResult(final Activity thisActivity, final Intent intent, final Integer requestCode, final Bundle bundle, final View triggerView, int colorOrImageRes, long durationMills) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        thisActivity.startActivity(intent);
        return;
    }
    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth() / 2;
    final int cy = location[1] + triggerView.getHeight() / 2;
    final ImageView view = new ImageView(thisActivity);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageResource(colorOrImageRes);
    final ViewGroup decorView = (ViewGroup) thisActivity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);
    // 计算中心点至view边界的最大距离
    int maxW = Math.max(cx, w - cx);
    int maxH = Math.max(cy, h - cy);
    final int finalRadius = (int) Math.sqrt(maxW * maxW + maxH * maxH) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    int maxRadius = (int) Math.sqrt(w * w + h * h) + 1;
    // 若使用默认时长,则需要根据水波扩散的距离来计算实际时间
    if (durationMills == PERFECT_MILLS) {
        // 算出实际边距与最大边距的比率
        double rate = 1d * finalRadius / maxRadius;
        // 水波扩散的距离与扩散时间成正比
        durationMills = (long) (PERFECT_MILLS * rate);
    }
    final long finalDuration = durationMills;
    anim.setDuration(finalDuration);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (requestCode == null)
                thisActivity.startActivity(intent);
            else if (bundle == null)
                thisActivity.startActivityForResult(intent, requestCode);
            else
                thisActivity.startActivityForResult(intent, requestCode, bundle);
            // 默认渐隐过渡动画.
            thisActivity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            // 默认显示返回至当前Activity的动画.
            triggerView.postDelayed(new Runnable() {

                @Override
                public void run() {
                    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, finalRadius, 0);
                    anim.setDuration(finalDuration);
                    anim.addListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            try {
                                decorView.removeView(view);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    anim.start();
                }
            }, 1000);
        }
    });
    anim.start();
}
Also used : Animator(android.animation.Animator) ViewGroup(android.view.ViewGroup) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ImageView(android.widget.ImageView) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

ViewGroup (android.view.ViewGroup)2280 View (android.view.View)1268 TextView (android.widget.TextView)439 ImageView (android.widget.ImageView)279 ArrayList (java.util.ArrayList)198 ViewParent (android.view.ViewParent)184 ListView (android.widget.ListView)156 Paint (android.graphics.Paint)125 FrameLayout (android.widget.FrameLayout)121 LayoutInflater (android.view.LayoutInflater)115 AdapterView (android.widget.AdapterView)115 LinearLayout (android.widget.LinearLayout)110 AbsListView (android.widget.AbsListView)106 Animator (android.animation.Animator)94 Drawable (android.graphics.drawable.Drawable)93 RecyclerView (android.support.v7.widget.RecyclerView)91 AnimatedView (carbon.animation.AnimatedView)88 ComponentView (carbon.component.ComponentView)88 RippleView (carbon.drawable.ripple.RippleView)88 ShadowView (carbon.shadow.ShadowView)88