當前位置: 首頁>>代碼示例>>Java>>正文


Java Drawable.createFromStream方法代碼示例

本文整理匯總了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;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:23,代碼來源:ImageActivity.java

示例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;
    }
 
開發者ID:Davarco,項目名稱:Divertio,代碼行數:27,代碼來源:SongDBHandler.java

示例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;
    }
 
開發者ID:Davarco,項目名稱:Divertio,代碼行數:26,代碼來源:SongDBHandler.java

示例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);
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:22,代碼來源:LeanplumResources.java

示例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();
    }
}
 
開發者ID:jahirfiquitiva,項目名稱:FABsMenu,代碼行數:10,代碼來源:FABsMenu.java

示例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;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:22,代碼來源:DrawableUtil.java

示例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;
    }
}
 
開發者ID:kerick-jeff,項目名稱:MyBP,代碼行數:10,代碼來源:SplashActivity.java

示例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;
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:35,代碼來源:AuthAgent.java

示例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();
}
 
開發者ID:Davarco,項目名稱:Divertio,代碼行數:38,代碼來源:MainActivity.java

示例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;
}
 
開發者ID:davideas,項目名稱:AndroidBlueprints,代碼行數:18,代碼來源:ResourcesHelper.java

示例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 "";

        }
 
開發者ID:ad-on-is,項目名稱:chilly,代碼行數:40,代碼來源:ChillyTasks.java

示例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;
    }

}
 
開發者ID:SysdataSpA,項目名稱:SDHtmlTextView,代碼行數:16,代碼來源:HtmlAssetsImageGetter.java

示例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;
}
 
開發者ID:ericberman,項目名稱:MyFlightbookAndroid,代碼行數:12,代碼來源:MFBImageInfo.java

示例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);
        }

    }
 
開發者ID:vaginessa,項目名稱:RepWifiApp,代碼行數:13,代碼來源:MainActivity.java

示例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;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:35,代碼來源:AuthAgent.java


注:本文中的android.graphics.drawable.Drawable.createFromStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。