Java Code Examples for android.graphics.drawable.Drawable#getOpacity()

The following examples show how to use android.graphics.drawable.Drawable#getOpacity() . 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: ACache.java    From Gank with Apache License 2.0 6 votes vote down vote up
private static Bitmap drawable2Bitmap(Drawable drawable) {
	if (drawable == null) {
		return null;
	}
	// 取 drawable 的长宽
	int w = drawable.getIntrinsicWidth();
	int h = drawable.getIntrinsicHeight();
	// 取 drawable 的颜色格式
	Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
			: Bitmap.Config.RGB_565;
	// 建立对应 bitmap
	Bitmap bitmap = Bitmap.createBitmap(w, h, config);
	// 建立对应 bitmap 的画布
	Canvas canvas = new Canvas(bitmap);
	drawable.setBounds(0, 0, w, h);
	// 把 drawable 内容画到画布中
	drawable.draw(canvas);
	return bitmap;
}
 
Example 2
Source File: ACache.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
private static Bitmap drawable2Bitmap(Drawable drawable) {
	if (drawable == null) {
		return null;
	}
	// 取 drawable 的长宽
	int w = drawable.getIntrinsicWidth();
	int h = drawable.getIntrinsicHeight();
	// 取 drawable 的颜色格式
	Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
			: Bitmap.Config.RGB_565;
	// 建立对应 bitmap
	Bitmap bitmap = Bitmap.createBitmap(w, h, config);
	// 建立对应 bitmap 的画布
	Canvas canvas = new Canvas(bitmap);
	drawable.setBounds(0, 0, w, h);
	// 把 drawable 内容画到画布中
	drawable.draw(canvas);
	return bitmap;
}
 
Example 3
Source File: ACache.java    From ChipHellClient with Apache License 2.0 6 votes vote down vote up
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的长宽
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的颜色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立对应 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立对应 bitmap 的画布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 内容画到画布中
    drawable.draw(canvas);
    return bitmap;
}
 
Example 4
Source File: ACache.java    From CoolApk-Console with GNU General Public License v3.0 6 votes vote down vote up
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的长宽
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的颜色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立对应 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立对应 bitmap 的画布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 内容画到画布中
    drawable.draw(canvas);
    return bitmap;
}
 
Example 5
Source File: ZrcListView.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
public void setDivider(Drawable divider) {
    if (divider != null) {
        mDividerHeight = divider.getIntrinsicHeight();
    } else {
        mDividerHeight = 0;
    }
    mDivider = divider;
    mDividerIsOpaque = divider == null || divider.getOpacity() == PixelFormat.OPAQUE;
    requestLayout();
    invalidate();
}
 
Example 6
Source File: DrawerLayout.java    From guideshow with MIT License 5 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }
    return false;
}
 
Example 7
Source File: ImageUtil.java    From XposedNavigationBar with GNU General Public License v3.0 5 votes vote down vote up
public static Bitmap drawableToBitmap(Drawable drawable) {
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    Bitmap.Config config =
            drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                    : Bitmap.Config.RGB_565;
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);

    return bitmap;
}
 
Example 8
Source File: IconHintView.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
private Bitmap drawableToBitmap(Drawable drawable) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ?
            Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
    Bitmap bitmap = Bitmap.createBitmap(width, height, config);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);
    return bitmap;
}
 
Example 9
Source File: VerticalSlidingPanel.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }
    return false;
}
 
Example 10
Source File: ViewCompat.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean isOpaque(View view) {
    Drawable bg = view.getBackground();
    if (bg == null || bg.getOpacity() != -1) {
        return false;
    }
    return true;
}
 
Example 11
Source File: DrawableUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else {
        int width = drawable.getIntrinsicWidth();// 取drawable的长宽
        int height = drawable.getIntrinsicHeight();
        Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;// 取drawable的颜色格式
        Bitmap bitmap = Bitmap.createBitmap(width, height, config);// 建立对应bitmap
        Canvas canvas = new Canvas(bitmap);// 建立对应bitmap的画布
        drawable.setBounds(0, 0, width, height);
        drawable.draw(canvas);// 把drawable内容画到画布中
        return bitmap;
    }
}
 
Example 12
Source File: IconHintView.java    From styT with Apache License 2.0 5 votes vote down vote up
private Bitmap drawableToBitmap(Drawable drawable) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    Bitmap bitmap = Bitmap.createBitmap(width, height, config);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);
    return bitmap;
}
 
Example 13
Source File: CombinationImageView.java    From RelaxFinger with GNU General Public License v2.0 5 votes vote down vote up
private static Bitmap drawableToBitmap(Drawable drawable) {
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();

    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}
 
Example 14
Source File: BitmapUtil.java    From PluginLoader with Apache License 2.0 5 votes vote down vote up
public static Bitmap drawableToBitmap(Drawable drawable) {
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();

    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;

    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}
 
Example 15
Source File: aa.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public boolean k(View view)
{
    Drawable drawable = view.getBackground();
    boolean flag = false;
    if (drawable != null)
    {
        int l = drawable.getOpacity();
        flag = false;
        if (l == -1)
        {
            flag = true;
        }
    }
    return flag;
}
 
Example 16
Source File: SlidingUpPanelLayout.java    From toktok-android with GNU General Public License v3.0 4 votes vote down vote up
private static boolean hasOpaqueBackground(@NonNull View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
 
Example 17
Source File: SlidingUpPanelLayout.java    From AndroidAnimationExercise with Apache License 2.0 4 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
 
Example 18
Source File: DefaultHeaderTransformer.java    From AndroidPullMenu with Apache License 2.0 4 votes vote down vote up
private void setupViewsFromStyles(Activity activity, View headerView) {
    final TypedArray styleAttrs = obtainStyledAttrsFromThemeAttr(activity,
            R.attr.pmHeaderStyle, R.styleable.PullMenuHeader);

    // Retrieve the Action Bar size from the app theme or the Action Bar's style
    if (mContentLayout != null) {
        final int height = styleAttrs.getDimensionPixelSize(
                R.styleable.PullMenuHeader_pmHeaderHeight, getActionBarSize(activity));
        mContentLayout.getLayoutParams().height = height;
        mContentLayout.requestLayout();
    }

    // Retrieve the Action Bar background from the app theme or the Action Bar's style (see #93)
    Drawable bg = styleAttrs.hasValue(R.styleable.PullMenuHeader_pmHeaderBackground)
            ? styleAttrs.getDrawable(R.styleable.PullMenuHeader_pmHeaderBackground)
            : getActionBarBackground(activity);
    if (bg != null) {
        //mHeaderTextView.setBackgroundDrawable(bg);

        // If we have an opaque background we can remove the background from the content layout
        if (mContentLayout != null && bg.getOpacity() == PixelFormat.OPAQUE) {
            mContentLayout.setBackgroundResource(0);
        }
    }

    // Retrieve the Progress Bar Color the style
    if (styleAttrs.hasValue(R.styleable.PullMenuHeader_pmProgressBarColor)) {
        mProgressDrawableColor = styleAttrs.getColor(
                R.styleable.PullMenuHeader_pmProgressBarColor, mProgressDrawableColor);
    }

    mProgressBarStyle = styleAttrs.getInt(
            R.styleable.PullMenuHeader_pmProgressBarStyle, PROGRESS_BAR_STYLE_INSIDE);

    if (styleAttrs.hasValue(R.styleable.PullMenuHeader_pmProgressBarHeight)) {
        mProgressBarHeight = styleAttrs.getDimensionPixelSize(
                R.styleable.PullMenuHeader_pmProgressBarHeight, mProgressBarHeight);
    }

    //SmoothProgressBar Style
    if (styleAttrs.hasValue(R.styleable.PullMenuHeader_pmSmoothProgressBarStyle)) {
        int spbStyleRes = styleAttrs.getResourceId(R.styleable.PullMenuHeader_pmSmoothProgressBarStyle, 0);
        if (spbStyleRes != 0)
            mHeaderProgressBar.applyStyle(spbStyleRes);

    }

    styleAttrs.recycle();
}
 
Example 19
Source File: SlidingUpPanelLayout.java    From AndroidSlidingUpPanel with Apache License 2.0 4 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
 
Example 20
Source File: DefaultHeaderTransformer.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onViewCreated(Activity activity, View headerView) {
    // Get ProgressBar and TextView. Also set initial text on TextView
    mHeaderProgressBar = (ProgressBar) headerView.findViewById(R.id.ptr_progress);
    mHeaderTextView = (TextView) headerView.findViewById(R.id.ptr_text);

    // Apply any custom ProgressBar colors
    applyProgressBarColor();

    // Labels to display
    mPullRefreshLabel = activity.getString(R.string.pull_to_refresh_pull_label);
    mRefreshingLabel = activity.getString(R.string.pull_to_refresh_refreshing_label);
    mReleaseLabel = activity.getString(R.string.pull_to_refresh_release_label);

    // Retrieve the Action Bar size from the Activity's theme
    mContentLayout = (ViewGroup) headerView.findViewById(R.id.ptr_content);
    if (mContentLayout != null) {
        mContentLayout.getLayoutParams().height = getActionBarSize(activity);
        mContentLayout.requestLayout();
    }

    // Retrieve the Action Bar background from the Activity's theme (see #93).
    Drawable abBg = getActionBarBackground(activity);
    if (abBg != null) {
        // If we do not have a opaque background we just display a solid solid behind it
        if (abBg.getOpacity() != PixelFormat.OPAQUE) {
            View view = headerView.findViewById(R.id.ptr_text_opaque_bg);
            if (view != null) {
                view.setVisibility(View.VISIBLE);
            }
        }

        mHeaderTextView.setBackgroundDrawable(abBg);
    }

    // Retrieve the Action Bar Title Style from the Action Bar's theme
    Context abContext = headerView.getContext();
    final int titleTextStyle = getActionBarTitleStyle(abContext);
    if (titleTextStyle != 0) {
        mHeaderTextView.setTextAppearance(abContext, titleTextStyle);
    }

    // Call onReset to make sure that the View is consistent
    onReset();
}