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;
}
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;
}
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);
}
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));
}
});
}
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);
}
}
}
Aggregations