本文整理匯總了Java中android.graphics.drawable.Drawable.createFromStream方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.createFromStream方法的具體用法?Java Drawable.createFromStream怎麽用?Java Drawable.createFromStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.Drawable
的用法示例。
在下文中一共展示了Drawable.createFromStream方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: b
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Drawable b(String str) {
Drawable createFromStream;
IOException e;
try {
InputStream open = getAssets().open(str);
createFromStream = Drawable.createFromStream(open, str);
try {
open.close();
} catch (IOException e2) {
e = e2;
e.printStackTrace();
return createFromStream;
}
} catch (IOException e3) {
IOException iOException = e3;
createFromStream = null;
e = iOException;
e.printStackTrace();
return createFromStream;
}
return createFromStream;
}
示例2: getSongData
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public SongData getSongData(String name) {
// Get table data
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.query(TABLE_SONGS, new String[] { KEY_NAME, KEY_PATH, KEY_ARTIST, KEY_ALBUM, KEY_GENRE, KEY_COVER }, KEY_NAME + "=?", new String[] { String.valueOf(name) }, null, null, null, null);
// Search through database
if (cursor != null) {
cursor.moveToFirst();
// Get image from byte arr
byte[] img = cursor.getBlob(KEY_COVER_IDX);
Drawable cover = Drawable.createFromStream(new ByteArrayInputStream(img), null);
SongData songData = new SongData(cursor.getString(KEY_NAME_IDX), cursor.getString(KEY_PATH_IDX), cursor.getString(KEY_ARTIST_IDX),
cursor.getString(KEY_ALBUM_IDX), cursor.getString(KEY_GENRE_IDX), cover);
db.close();
//cursor.close();
return songData;
} else {
Log.e(TAG, "Failed to create database cursor.");
}
Log.e(TAG, "Failed to find song data with that name in database.");
return null;
}
示例3: getSongDataList
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public List<SongData> getSongDataList() {
// Create list and get table data
List<SongData> songDataList = new ArrayList<>();
SQLiteDatabase db = this.getWritableDatabase();
String dbQuery = "SELECT * FROM " + TABLE_SONGS;
Cursor cursor = db.rawQuery(dbQuery, null);
// Go through database and all to list
if (cursor.moveToFirst()) {
do {
// Get image from byte arr
byte[] img = cursor.getBlob(KEY_COVER_IDX);
Drawable cover = Drawable.createFromStream(new ByteArrayInputStream(img), null);
SongData songData = new SongData(cursor.getString(KEY_NAME_IDX), cursor.getString(KEY_PATH_IDX), cursor.getString(KEY_ARTIST_IDX),
cursor.getString(KEY_ALBUM_IDX), cursor.getString(KEY_GENRE_IDX), cover);
songDataList.add(songData);
} while (cursor.moveToNext());
}
//cursor.close();
db.close();
return songDataList;
}
示例4: getDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public Drawable getDrawable(int id) throws NotFoundException {
try {
Var<String> override = getOverrideResource(id);
if (override != null) {
int overrideResId = override.overrideResId();
if (overrideResId != 0) {
return super.getDrawable(overrideResId);
}
if (!override.stringValue.equals(override.defaultValue())) {
Drawable result = Drawable.createFromStream(override.stream(), override.fileValue());
if (result != null) {
return result;
}
}
}
} catch (Throwable t) {
Util.handleException(t);
}
return super.getDrawable(id);
}
示例5: setMenuButtonIcon
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setMenuButtonIcon(@NonNull Uri uri) {
try {
InputStream inputStream = getContext().getContentResolver().openInputStream(uri);
Drawable icon = Drawable.createFromStream(inputStream, uri.toString());
if (icon != null) setMenuButtonIcon(icon);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: getAssetByPath
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* 從Asset路徑獲取Drawable
*
* @param context
* @param filePath
* @return
*/
public static Drawable getAssetByPath(final Context context, final String filePath) {
Drawable drawable = WeakCache.getCache(TAG).get(filePath);
if (drawable == null) {
try {
if (context != null) {
drawable = Drawable.createFromStream(context.getAssets().open(filePath), null);
WeakCache.getCache(TAG).put(filePath, drawable);
}
} catch (Throwable e){
LogUtil.e("[DrawableUtil-getAssetByPath Failed]", e);
}
}
return drawable;
}
示例7: loadDataFromAsset
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void loadDataFromAsset(){
try {
InputStream inputStream = getAssets().open("icon.png");
Drawable drawable = Drawable.createFromStream(inputStream, null);
imageViewIcon.setImageDrawable(drawable);
} catch (IOException ex) {
return;
}
}
示例8: a
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Drawable a(String str, Context context) {
Drawable createFromStream;
IOException e;
try {
InputStream open = context.getApplicationContext().getAssets().open(str);
if (open == null) {
return null;
}
if (str.endsWith(".9.png")) {
Bitmap decodeStream = BitmapFactory.decodeStream(open);
if (decodeStream == null) {
return null;
}
byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
NinePatch.isNinePatchChunk(ninePatchChunk);
return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
}
createFromStream = Drawable.createFromStream(open, str);
try {
open.close();
return createFromStream;
} catch (IOException e2) {
e = e2;
e.printStackTrace();
return createFromStream;
}
} catch (IOException e3) {
IOException iOException = e3;
createFromStream = null;
e = iOException;
e.printStackTrace();
return createFromStream;
}
}
示例9: onPostExecute
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void onPostExecute(String result) {
mWakeLock.release();
runOnUiThread(new Runnable() {
@Override
public void run() {
downloadProgress.dismiss();
}
});
// Get metadata
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(Environment.getExternalStorageDirectory().getPath() + "/Divertio/" + songFileName);
String path = Environment.getExternalStorageDirectory().getPath() + "/Divertio/" + songFileName;
String artist = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
String album = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
String genre = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
Drawable cover;
try {
cover = Drawable.createFromStream(new ByteArrayInputStream(retriever.getEmbeddedPicture()), null);
} catch (Exception e) {
cover = getResources().getDrawable(R.drawable.default_cover);
}
// Change artist if empty
if (artist == null || artist.equals("")) {
artist = "Unknown";
}
// Add to database
SongData songData = new SongData(songName, path, artist, album, genre, cover);
SongDBHandler db = new SongDBHandler(getApplicationContext());
db.addSongData(songData);
// Reset the song list view
setMainView();
}
示例10: getDrawableFromUri
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Gets drawable from uri.
*
* @param path the path
* @return the drawable from uri
*/
public static Drawable getDrawableFromUri(@NonNull Activity activity, @NonNull Uri path) {
Drawable result;
try {
InputStream inputStream = activity.getContentResolver().openInputStream(path);
result = Drawable.createFromStream(inputStream, path.toString());
} catch (FileNotFoundException e) {
result = activity.getResources().getDrawable(R.mipmap.ic_launcher);
}
return result;
}
示例11: doInBackground
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected String doInBackground(String... params) {
switch (action) {
case "add-to-collection":
Chilly.getInstance(ctx).addToTrakt("collection", v);
break;
case "add-to-watchlist":
Chilly.getInstance(ctx).addToTrakt("watchlist", v);
break;
case "mark-as-watched":
Chilly.getInstance(ctx).markAsWatched(v);
break;
case "scrobble-play":
Chilly.getInstance(ctx).scrobble("start", v, progress);
break;
case "scrobble-pause":
Chilly.getInstance(ctx).scrobble("pause", v, progress);
break;
case "scrobble-stop":
Chilly.getInstance(ctx).scrobble("stop", v, progress);
break;
case "get-user-name":
user = Chilly.getInstance(ctx).getTraktUser();
try {
InputStream is = (InputStream)new URL(user.images.get("avatar").get("full")).getContent();
icon = Drawable.createFromStream(is, "src name");
} catch (Exception e) {
System.out.println("Exc=" + e);
}
}
return "";
}
示例12: getDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public Drawable getDrawable(String source) {
try {
InputStream inputStream = context.getAssets().open(source);
Drawable d = Drawable.createFromStream(inputStream, null);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
} catch (IOException e) {
// prevent a crash if the resource still can't be found
Log.e(HtmlTextView.TAG, "source could not be found: " + source);
return null;
}
}
示例13: doInBackground
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected Drawable doInBackground(Void... params) {
Drawable d = null;
try {
InputStream is = (InputStream) new URL(m_URL).getContent();
d = Drawable.createFromStream(is, "src name");
} catch (Exception e) {
Log.e(MFBConstants.LOG_TAG, Log.getStackTraceString(e));
}
return d;
}
示例14: setImage
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void setImage() {
ImageView img = (ImageView) findViewById(R.id.img_logo);
try {
Drawable d = Drawable.createFromStream(getAssets().open("repwifi-logo-0.png"), null);
img.setImageDrawable(d);
} catch (IOException e) {
Utils.logError("Error while loading logo image", e);
}
}
示例15: a
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Drawable a(String str, Context context) {
IOException e;
Drawable createFromStream;
try {
InputStream open = context.getApplicationContext().getAssets().open(str);
if (open == null) {
return null;
}
if (str.endsWith(".9.png")) {
Bitmap decodeStream = BitmapFactory.decodeStream(open);
if (decodeStream == null) {
return null;
}
byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
NinePatch.isNinePatchChunk(ninePatchChunk);
return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
}
createFromStream = Drawable.createFromStream(open, str);
try {
open.close();
return createFromStream;
} catch (IOException e2) {
e = e2;
e.printStackTrace();
return createFromStream;
}
} catch (IOException e3) {
IOException iOException = e3;
createFromStream = null;
e = iOException;
e.printStackTrace();
return createFromStream;
}
}