Java Code Examples for android.view.ViewGroup#getBackground()

The following examples show how to use android.view.ViewGroup#getBackground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HintLayout.java    From AndroidProject with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化提示的布局
 */
private void initLayout() {

    mMainLayout = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.widget_hint_layout, this, false);

    mImageView = mMainLayout.findViewById(R.id.iv_hint_icon);
    mTextView = mMainLayout.findViewById(R.id.iv_hint_text);

    if (mMainLayout.getBackground() == null) {
        // 默认使用 windowBackground 作为背景
        TypedArray ta = getContext().obtainStyledAttributes(new int[]{android.R.attr.windowBackground});
        mMainLayout.setBackground(ta.getDrawable(0));
        ta.recycle();
    }

    addView(mMainLayout);
}
 
Example 2
Source File: CompositorViewHolder.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onSwapBuffersCompleted(int pendingSwapBuffersCount) {
    TraceEvent.instant("onSwapBuffersCompleted");

    // Wait until the second frame to turn off the placeholder background on
    // tablets so the tab strip has time to start drawing.
    final ViewGroup controlContainer = (ViewGroup) mControlContainer;
    if (controlContainer != null && controlContainer.getBackground() != null && mHasDrawnOnce) {
        post(new Runnable() {
            @Override
            public void run() {
                controlContainer.setBackgroundResource(0);
            }
        });
    }

    mHasDrawnOnce = true;

    mPendingSwapBuffersCount = pendingSwapBuffersCount;

    if (!mSkipInvalidation || pendingSwapBuffersCount == 0) flushInvalidation();
    mSkipInvalidation = !mSkipInvalidation;
}
 
Example 3
Source File: CompositorViewHolder.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onSwapBuffersCompleted(int pendingSwapBuffersCount) {
    TraceEvent.instant("onSwapBuffersCompleted");

    // Wait until the second frame to turn off the placeholder background on
    // tablets so the tab strip has time to start drawing.
    final ViewGroup controlContainer = (ViewGroup) mControlContainer;
    if (controlContainer != null && controlContainer.getBackground() != null && mHasDrawnOnce) {
        post(new Runnable() {
            @Override
            public void run() {
                controlContainer.setBackgroundResource(0);
            }
        });
    }

    mHasDrawnOnce = true;

    mPendingSwapBuffersCount = pendingSwapBuffersCount;

    if (!mSkipInvalidation || pendingSwapBuffersCount == 0) flushInvalidation();
    mSkipInvalidation = !mSkipInvalidation;
}
 
Example 4
Source File: BlurBehindView.java    From BlurView with Apache License 2.0 6 votes vote down vote up
private void printViewsBehind(ViewGroup rootView) {
    if (!this.isInEditMode() && !(rootView instanceof BlurBehindView) && rootView.getVisibility() == View.VISIBLE && rootView.getAlpha() != 0.0F) {
        if (rootView.getBackground() != null) {
            this.blurCanvas.save();
            this.blurCanvas.translate((float) (this.childPositionInWindow[0] - this.thisPositionInWindow[0] + this.halfPaddingOnSides), (float) (this.halfPaddingOnSides + this.childPositionInWindow[1] - this.thisPositionInWindow[1]));
            rootView.getBackground().draw(this.blurCanvas);
            this.blurCanvas.restore();
        }

        for (int i = 0; i < rootView.getChildCount(); ++i) {
            View childView = rootView.getChildAt(i);
            if (childView.findViewWithTag(TAG_VIEW) != null & rootView.getVisibility() == View.VISIBLE) {
                this.printViewsBehind((ViewGroup) childView);
            } else if (childView.getVisibility() == View.VISIBLE) {
                this.blurCanvas.save();
                childView.getLocationOnScreen(this.childPositionInWindow);
                this.blurCanvas.translate((float) (this.halfPaddingOnSides + this.childPositionInWindow[0] - this.thisPositionInWindow[0]), (float) (this.halfPaddingOnSides + this.childPositionInWindow[1] - this.thisPositionInWindow[1]));
                this.blurCanvas.scale(childView.getScaleX(), childView.getScaleY());
                childView.draw(this.blurCanvas);
                this.blurCanvas.restore();
            }
        }
    }
}
 
Example 5
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void didSwapFrame(int pendingFrameCount) {
    TraceEvent.instant("didSwapFrame");

    // Wait until the second frame to turn off the placeholder background on
    // tablets so the tab strip has time to start drawing.
    final ViewGroup controlContainer = (ViewGroup) mControlContainer;
    if (controlContainer != null && controlContainer.getBackground() != null && mHasDrawnOnce) {
        post(new Runnable() {
            @Override
            public void run() {
                controlContainer.setBackgroundResource(0);
            }
        });
    }

    mHasDrawnOnce = true;

    mPendingFrameCount = pendingFrameCount;

    if (!mSkipInvalidation || pendingFrameCount == 0) flushInvalidation();
    mSkipInvalidation = !mSkipInvalidation;
}
 
Example 6
Source File: EnterTransitionCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onTransitionsComplete() {
    moveSharedElementsFromOverlay();
    final ViewGroup decorView = getDecor();
    if (decorView != null) {
        decorView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);

        Window window = getWindow();
        if (window != null && mReplacedBackground == decorView.getBackground()) {
            window.setBackgroundDrawable(null);
        }
    }
}
 
Example 7
Source File: EnterTransitionCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void stop() {
    // Restore the background to its previous state since the
    // Activity is stopping.
    if (mBackgroundAnimator != null) {
        mBackgroundAnimator.end();
        mBackgroundAnimator = null;
    } else if (mWasOpaque) {
        ViewGroup decorView = getDecor();
        if (decorView != null) {
            Drawable drawable = decorView.getBackground();
            if (drawable != null) {
                drawable.setAlpha(1);
            }
        }
    }
    makeOpaque();
    mIsCanceled = true;
    mResultReceiver = null;
    mActivity = null;
    moveSharedElementsFromOverlay();
    if (mTransitioningViews != null) {
        showViews(mTransitioningViews, true);
        setTransitioningViewsVisiblity(View.VISIBLE, true);
    }
    showViews(mSharedElements, true);
    clearState();
}
 
Example 8
Source File: ExitTransitionCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void fadeOutBackground() {
    if (mBackgroundAnimator == null) {
        ViewGroup decor = getDecor();
        Drawable background;
        if (decor != null && (background = decor.getBackground()) != null) {
            background = background.mutate();
            getWindow().setBackgroundDrawable(background);
            mBackgroundAnimator = ObjectAnimator.ofInt(background, "alpha", 0);
            mBackgroundAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mBackgroundAnimator = null;
                    if (!mIsCanceled) {
                        mIsBackgroundReady = true;
                        notifyComplete();
                    }
                    backgroundAnimatorComplete();
                }
            });
            mBackgroundAnimator.setDuration(getFadeDuration());
            mBackgroundAnimator.start();
        } else {
            backgroundAnimatorComplete();
            mIsBackgroundReady = true;
        }
    }
}
 
Example 9
Source File: NotificationMainView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mTextAndBackground = (ViewGroup) findViewById(R.id.text_and_background);
    ColorDrawable colorBackground = (ColorDrawable) mTextAndBackground.getBackground();
    mBackgroundColor = colorBackground.getColor();
    RippleDrawable rippleBackground = new RippleDrawable(ColorStateList.valueOf(
            ThemeUtils.getAttrColor(getContext(), android.R.attr.colorControlHighlight)),
            colorBackground, null);
    mTextAndBackground.setBackground(rippleBackground);
    mTitleView = (TextView) mTextAndBackground.findViewById(R.id.title);
    mTextView = (TextView) mTextAndBackground.findViewById(R.id.text);
}
 
Example 10
Source File: ViewGroupColorAdapter.java    From Scoops with Apache License 2.0 5 votes vote down vote up
@Override
public int getColor(ViewGroup view) {
    Drawable bg = view.getBackground();
    if(bg instanceof ColorDrawable){
        return ((ColorDrawable) bg).getColor();
    }
    return 0;
}
 
Example 11
Source File: ExitTransitionCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public void startExit(int resultCode, Intent data) {
    if (!mIsExitStarted) {
        mIsExitStarted = true;
        pauseInput();
        ViewGroup decorView = getDecor();
        if (decorView != null) {
            decorView.suppressLayout(true);
        }
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                mIsCanceled = true;
                finish();
            }
        };
        delayCancel();
        moveSharedElementsToOverlay();
        if (decorView != null && decorView.getBackground() == null) {
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        }
        final boolean targetsM = decorView == null || decorView.getContext()
                .getApplicationInfo().targetSdkVersion >= VERSION_CODES.M;
        ArrayList<String> sharedElementNames = targetsM ? mSharedElementNames :
                mAllSharedElementNames;
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(mActivity, this,
                sharedElementNames, resultCode, data);
        mActivity.convertToTranslucent(new Activity.TranslucentConversionListener() {
            @Override
            public void onTranslucentConversionComplete(boolean drawComplete) {
                if (!mIsCanceled) {
                    fadeOutBackground();
                }
            }
        }, options);
        startTransition(new Runnable() {
            @Override
            public void run() {
                startExitTransition();
            }
        });
    }
}
 
Example 12
Source File: ASViewGroupUtil.java    From AutoScalingLayout with MIT License 4 votes vote down vote up
public void init(ViewGroup vg, AttributeSet attrs){
    mScaleType = TYPE_FIT_INSIDE;
    String scaleTypeStr = null;
    TypedArray a = null;
    try{
        a = vg.getContext().obtainStyledAttributes(
                attrs, R.styleable.AutoScalingLayout);

        // 获得设计宽高
        mDesignWidth = a.getDimensionPixelOffset(R.styleable.AutoScalingLayout_designWidth, 0);
        mDesignHeight = a.getDimensionPixelOffset(R.styleable.AutoScalingLayout_designHeight, 0);
        // 是否开启自动缩放
        mAutoScaleEnable = a.getBoolean(R.styleable.AutoScalingLayout_autoScaleEnable, true);
        mPreScaling = a.getBoolean(R.styleable.AutoScalingLayout_preScaling, false);
        scaleTypeStr = a.getString(R.styleable.AutoScalingLayout_autoScaleType);
    }catch (Throwable e){
        // 用户使用jar时,没有R.styleable.AutoScalingLayout,需要根据字符串解析参数
        mAutoScaleEnable = true;
        mDesignWidth = 0;
        mDesignHeight = 0;
        for (int i = 0; i < attrs.getAttributeCount(); i++){
            if ("designWidth".equals(attrs.getAttributeName(i))){
                String designWidthStr = attrs.getAttributeValue(i);
                mDesignWidth = getDimensionPixelOffset(vg.getContext(), designWidthStr);
            }
            else if ("designHeight".equals(attrs.getAttributeName(i))) {
                String designHeightStr = attrs.getAttributeValue(i);
                mDesignHeight = getDimensionPixelOffset(vg.getContext(), designHeightStr);
            }
            else if ("autoScaleEnable".equals(attrs.getAttributeName(i))) {
                String autoScaleEnableStr = attrs.getAttributeValue(i);
                if (autoScaleEnableStr.equals("false"))
                    mAutoScaleEnable = false;
            }
            else if ("preScaling".equals(attrs.getAttributeName(i))) {
                String preScalingStr = attrs.getAttributeValue(i);
                if (preScalingStr.equals("true"))
                    mPreScaling = true;
            }
            else if ("autoScaleType".equals(attrs.getAttributeName(i))) {
                scaleTypeStr = attrs.getAttributeValue(i);
            }
        }
    }finally {
        if(null != a)
            a.recycle();
    }

    if (null != scaleTypeStr){
        if (scaleTypeStr.equals("fitWidth"))
            mScaleType = TYPE_FIT_WIDTH;
        else if (scaleTypeStr.equals("fitHeight"))
            mScaleType = TYPE_FIT_HEIGHT;
    }

    mCurrentWidth = mDesignWidth;
    mCurrentHeight = mDesignHeight;

    // 背景为空时,不进入draw函数,这里必须设置默认背景
    if (null == vg.getBackground())
        vg.setBackgroundColor(Color.TRANSPARENT);

    if (DEBUG){
        Log.v("AutoScalingLayout", "mDesignWidth=" + mDesignWidth + " mDesignHeight=" + mDesignHeight);
        //Log.v("AutoScalingLayout", "1dp=" + getDimensionPixelOffset(vg.getContext(), "1dp") + "px");
    }
}