use of android.graphics.drawable.BitmapDrawable in project Launcher3 by chislon.
the class SavedWallpaperImages method loadThumbnailsAndImageIdList.
public void loadThumbnailsAndImageIdList() {
mImages = new ArrayList<SavedWallpaperTile>();
SQLiteDatabase db = mDb.getReadableDatabase();
Cursor result = db.query(ImageDb.TABLE_NAME, new String[] { ImageDb.COLUMN_ID, // cols to return
ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME }, // select query
null, // args to select query
null, null, null, ImageDb.COLUMN_ID + " DESC", null);
while (result.moveToNext()) {
String filename = result.getString(1);
File file = new File(mContext.getFilesDir(), filename);
Bitmap thumb = BitmapFactory.decodeFile(file.getAbsolutePath());
if (thumb != null) {
mImages.add(new SavedWallpaperTile(result.getInt(0), new BitmapDrawable(thumb)));
}
}
result.close();
}
use of android.graphics.drawable.BitmapDrawable in project UltimateAndroid by cymcsg.
the class CircularImageView method drawableToBitmap.
/**
* Convert a drawable object into a Bitmap.
* @param drawable Drawable to extract a Bitmap from.
* @return A Bitmap created from the drawable parameter.
*/
public Bitmap drawableToBitmap(Drawable drawable) {
if (// Don't do anything without a proper drawable
drawable == null)
return null;
else if (drawable instanceof BitmapDrawable) {
// Use the getBitmap() method instead if BitmapDrawable
Log.i(TAG, "Bitmap drawable!");
return ((BitmapDrawable) drawable).getBitmap();
}
int intrinsicWidth = drawable.getIntrinsicWidth();
int intrinsicHeight = drawable.getIntrinsicHeight();
if (!(intrinsicWidth > 0 && intrinsicHeight > 0))
return null;
try {
// Create Bitmap object out of the drawable
Bitmap bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (OutOfMemoryError e) {
// Simply return null of failed bitmap creations
Log.e(TAG, "Encountered OutOfMemoryError while generating bitmap!");
return null;
}
}
use of android.graphics.drawable.BitmapDrawable in project DragSortRecycler by emileb.
the class DragSortRecycler method createFloatingBitmap.
private BitmapDrawable createFloatingBitmap(View v) {
floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
floatingItemBounds = new Rect(floatingItemStatingBounds);
Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(), floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
v.draw(canvas);
BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap);
retDrawable.setBounds(floatingItemBounds);
return retDrawable;
}
use of android.graphics.drawable.BitmapDrawable in project Libraries-for-Android-Developers by eoecn.
the class IcsProgressBar method tileify.
/**
* Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress));
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else /* else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = in.getStateCount();
for (int i = 0; i < numStates; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
}*/
if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
}
use of android.graphics.drawable.BitmapDrawable in project QuantumFlux by himanshu-soni.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// For sync adapter
mAccount = SyncUtils.createSyncAccount(this, "Dummy Account");
SyncUtils.startPeriodicSync(mAccount);
// delete all previous data
QuantumFlux.deleteAll(Book.class);
QuantumFlux.deleteAll(Author.class);
QuantumFlux.deleteAll(Publisher.class);
Book book = new Book();
book.name = "Sorcerer's Stone";
book.isbn = "122342564";
Drawable drawable = getResources().getDrawable(R.drawable.hpsc);
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
book.bookCover = stream.toByteArray();
QuantumFlux.insert(book);
Author author = new Author();
author.name = "J.K. Rollings";
author.save();
Publisher publisher = new Publisher();
publisher.name = "Bloomsbury";
QuantumFlux.insert(publisher);
ImageView cover = (ImageView) findViewById(R.id.cover);
TextView bookName = (TextView) findViewById(R.id.book_name);
TextView authorName = (TextView) findViewById(R.id.author_name);
TextView pubName = (TextView) findViewById(R.id.publisher_name);
Book firstBook = Select.from(Book.class).first();
Author firstAuthor = Select.from(Author.class).first();
Publisher firstPublisher = Select.from(Publisher.class).first();
bookName.setText(firstBook.name);
authorName.setText(firstAuthor.name);
pubName.setText(firstPublisher.name);
Bitmap decodedByte = BitmapFactory.decodeByteArray(firstBook.bookCover, 0, firstBook.bookCover.length);
cover.setImageBitmap(decodedByte);
// update
Author first = Select.from(Author.class).first();
first.name = "J. K. Rowling";
first.update();
authorName.setText(first.name);
// update from QuantumFlux
Book isbnBook = Select.from(Book.class).whereEquals("isbn", "122342564").first();
isbnBook.isbn = "122342567";
QuantumFlux.update(isbnBook);
// batch insert example
int batchSize = 100;
QuantumFluxBatchDispatcher<Book> dispatcher = new QuantumFluxBatchDispatcher<Book>(this, Book.class, batchSize);
for (int i = 0; i < batchSize; i++) {
Book b = new Book();
b.name = "Book " + i;
b.isbn = "ISBN" + b.hashCode();
dispatcher.add(b);
}
dispatcher.release(true);
int count = Select.from(Book.class).queryAsCount();
Toast.makeText(this, "Total Books : " + count, Toast.LENGTH_LONG).show();
// To notify sync
try {
Book newBook = new Book();
newBook.name = "Chamber of Secrets";
QuantumFluxSyncHelper.insert(getContentResolver().acquireContentProviderClient(SyncConstants.AUTHORITY), newBook);
} catch (RemoteException e) {
e.printStackTrace();
}
SyncUtils.refreshManually(mAccount);
}
Aggregations