Search in sources :

Example 6 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project UltimateAndroid by cymcsg.

the class ImageUtils_Deprecated method toRoundCorner.

/** */
/**
     * 使圆角功能支持BitampDrawable
     *
     * @param bitmapDrawable
     * @param pixels
     * @return
     */
public static BitmapDrawable toRoundCorner(BitmapDrawable bitmapDrawable, int pixels) {
    Bitmap bitmap = bitmapDrawable.getBitmap();
    bitmapDrawable = new BitmapDrawable(toRoundCorner(bitmap, pixels));
    return bitmapDrawable;
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 7 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project SimplifyReader by chentao0707.

the class PluginFullScreenPauseAD method loadImageFromUrl.

private Bitmap loadImageFromUrl(String url) {
    URL u;
    InputStream i = null;
    Bitmap d = null;
    DiskLruCache cache = null;
    try {
        u = new URL(url);
        d = getImageFromCache(url);
        if (d != null) {
            return d;
        }
        i = (InputStream) u.getContent();
    } catch (Exception e) {
    }
    if (mActivity != null && mActivity.mImageWorker != null && mActivity.mImageWorker.getImageCache() != null) {
        cache = mActivity.mImageWorker.getImageCache().getDiskCache();
    }
    if (cache == null) {
        return null;
    }
    final String fileName = Utils.urlToFileName(url);
    final File cacheFile = new File(cache.createFilePath(fileName));
    BufferedOutputStream out = null;
    try {
        BitmapDrawable bitDrawable;
        bitDrawable = (BitmapDrawable) BitmapDrawable.createFromStream(i, "src");
        if (bitDrawable == null) {
            return null;
        }
        d = bitDrawable.getBitmap();
        if (d != null) {
            addImageToCache(url, d);
        }
        out = new BufferedOutputStream(new FileOutputStream(cacheFile), Utils.IO_BUFFER_SIZE);
        d.compress(CompressFormat.PNG, 85, out);
        out.flush();
    } catch (final IOException e) {
    } catch (OutOfMemoryError e) {
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (final IOException e) {
                Logger.e(TAG, "Error in downloadBitmap - " + e);
            }
        }
    }
    return d;
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) DiskLruCache(com.baseproject.image.DiskLruCache) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) URL(java.net.URL) GoplayException(com.youku.player.base.GoplayException) PBException(com.punchbox.exception.PBException) IOException(java.io.IOException)

Example 8 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project UltimateRecyclerView by cymcsg.

the class FloatingActionButton method createAlphaDrawble.

protected Drawable createAlphaDrawble(RectF circleRect, int color, float alpha) {
    final Bitmap bitmap = Bitmap.createBitmap(mDrawableSize, mDrawableSize, Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(color);
    paint.setAlpha(opacityToAlpha(alpha));
    canvas.drawOval(circleRect, paint);
    return new BitmapDrawable(getResources(), bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 9 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project MultipleTheme by dersoncheng.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn = (ColorButton) findViewById(R.id.btn);
    btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SharedPreferencesMgr.getInt("theme", 0) == 1) {
                SharedPreferencesMgr.setInt("theme", 0);
                setTheme(R.style.theme_1);
            } else {
                SharedPreferencesMgr.setInt("theme", 1);
                setTheme(R.style.theme_2);
            }
            final View rootView = getWindow().getDecorView();
            if (Build.VERSION.SDK_INT >= 14) {
                rootView.setDrawingCacheEnabled(true);
                rootView.buildDrawingCache(true);
                final Bitmap localBitmap = Bitmap.createBitmap(rootView.getDrawingCache());
                rootView.setDrawingCacheEnabled(false);
                if (null != localBitmap && rootView instanceof ViewGroup) {
                    final View localView2 = new View(getApplicationContext());
                    localView2.setBackgroundDrawable(new BitmapDrawable(getResources(), localBitmap));
                    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    ((ViewGroup) rootView).addView(localView2, params);
                    localView2.animate().alpha(0).setDuration(400).setListener(new Animator.AnimatorListener() {

                        @Override
                        public void onAnimationStart(Animator animation) {
                            ColorUiUtil.changeTheme(rootView, getTheme());
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            ((ViewGroup) rootView).removeView(localView2);
                            localBitmap.recycle();
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {
                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {
                        }
                    }).start();
                }
            } else {
                ColorUiUtil.changeTheme(rootView, getTheme());
            }
        }
    });
    btn_next = (ColorButton) findViewById(R.id.btn_2);
    btn_next.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, SecondActivity.class));
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) Animator(android.animation.Animator) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) View(android.view.View)

Example 10 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project Android-ShareEverywhere by dgmltn.

the class IcsListPopupWindow method show.

public void show() {
    int height = buildDropDown();
    int widthSpec = 0;
    int heightSpec = 0;
    boolean noInputMethod = isInputMethodNotNeeded();
    if (mPopup.isShowing()) {
        if (mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT) {
            // The call to PopupWindow's update method below can accept -1 for any
            // value you do not want to update.
            widthSpec = -1;
        } else if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) {
            widthSpec = mDropDownAnchorView.getWidth();
        } else {
            widthSpec = mDropDownWidth;
        }
        if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
            // The call to PopupWindow's update method below can accept -1 for any
            // value you do not want to update.
            heightSpec = noInputMethod ? height : ViewGroup.LayoutParams.MATCH_PARENT;
            if (noInputMethod) {
                mPopup.setWindowLayoutMode(mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT ? ViewGroup.LayoutParams.MATCH_PARENT : 0, 0);
            } else {
                mPopup.setWindowLayoutMode(mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT ? ViewGroup.LayoutParams.MATCH_PARENT : 0, ViewGroup.LayoutParams.MATCH_PARENT);
            }
        } else if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
            heightSpec = height;
        } else {
            heightSpec = mDropDownHeight;
        }
        mPopup.setOutsideTouchable(true);
        mPopup.update(mDropDownAnchorView, mDropDownHorizontalOffset, mDropDownVerticalOffset, widthSpec, heightSpec);
    } else {
        if (mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT) {
            widthSpec = ViewGroup.LayoutParams.MATCH_PARENT;
        } else {
            if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) {
                mPopup.setWidth(mDropDownAnchorView.getWidth());
            } else {
                mPopup.setWidth(mDropDownWidth);
            }
        }
        if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
            heightSpec = ViewGroup.LayoutParams.MATCH_PARENT;
        } else {
            if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
                mPopup.setHeight(height);
            } else {
                mPopup.setHeight(mDropDownHeight);
            }
        }
        mPopup.setWindowLayoutMode(widthSpec, heightSpec);
        //http://stackoverflow.com/questions/3121232/android-popup-window-dismissal
        if (mPopup.getBackground() == null) {
            mPopup.setBackgroundDrawable(new BitmapDrawable());
        }
        // use outside touchable to dismiss drop down when touching outside of it, so
        // only set this if the dropdown is not always visible
        mPopup.setOutsideTouchable(true);
        mPopup.setTouchInterceptor(mTouchInterceptor);
        mPopup.showAsDropDown(mDropDownAnchorView, mDropDownHorizontalOffset, mDropDownVerticalOffset);
        mDropDownList.setSelection(ListView.INVALID_POSITION);
        if (!mModal || mDropDownList.isInTouchMode()) {
            clearListSelection();
        }
        if (!mModal) {
            mHandler.post(mHideSelector);
        }
    }
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

BitmapDrawable (android.graphics.drawable.BitmapDrawable)617 Bitmap (android.graphics.Bitmap)413 Drawable (android.graphics.drawable.Drawable)185 Canvas (android.graphics.Canvas)176 Paint (android.graphics.Paint)107 Rect (android.graphics.Rect)76 View (android.view.View)74 ColorDrawable (android.graphics.drawable.ColorDrawable)58 ImageView (android.widget.ImageView)58 TextView (android.widget.TextView)49 IOException (java.io.IOException)39 Resources (android.content.res.Resources)35 LayerDrawable (android.graphics.drawable.LayerDrawable)33 AnimationDrawable (android.graphics.drawable.AnimationDrawable)30 File (java.io.File)27 Test (org.junit.Test)24 Intent (android.content.Intent)23 Matrix (android.graphics.Matrix)22 StateListDrawable (android.graphics.drawable.StateListDrawable)22 InputStream (java.io.InputStream)22