Search in sources :

Example 1 with ImageScaleType

use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project Android-Universal-Image-Loader by nostra13.

the class BaseImageDecoder method prepareDecodingOptions.

protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    int scale;
    if (scaleType == ImageScaleType.NONE) {
        scale = 1;
    } else if (scaleType == ImageScaleType.NONE_SAFE) {
        scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
    } else {
        ImageSize targetSize = decodingInfo.getTargetSize();
        boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
        scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
    }
    if (scale > 1 && loggingEnabled) {
        L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
    }
    Options decodingOptions = decodingInfo.getDecodingOptions();
    decodingOptions.inSampleSize = scale;
    return decodingOptions;
}
Also used : ImageScaleType(com.nostra13.universalimageloader.core.assist.ImageScaleType) Options(android.graphics.BitmapFactory.Options) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize)

Example 2 with ImageScaleType

use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project Android-Universal-Image-Loader by nostra13.

the class LoadAndDisplayImageTask method resizeAndSaveImage.

/** Decodes image file into Bitmap, resize it and save it back */
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException {
    // Decode image file, compress and re-save it
    boolean saved = false;
    File targetFile = configuration.diskCache.get(uri);
    if (targetFile != null && targetFile.exists()) {
        ImageSize targetImageSize = new ImageSize(maxWidth, maxHeight);
        DisplayImageOptions specialOptions = new DisplayImageOptions.Builder().cloneFrom(options).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
        ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), uri, targetImageSize, ViewScaleType.FIT_INSIDE, getDownloader(), specialOptions);
        Bitmap bmp = decoder.decode(decodingInfo);
        if (bmp != null && configuration.processorForDiskCache != null) {
            L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey);
            bmp = configuration.processorForDiskCache.process(bmp);
            if (bmp == null) {
                L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey);
            }
        }
        if (bmp != null) {
            saved = configuration.diskCache.save(uri, bmp);
            bmp.recycle();
        }
    }
    return saved;
}
Also used : Bitmap(android.graphics.Bitmap) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize) ImageDecodingInfo(com.nostra13.universalimageloader.core.decode.ImageDecodingInfo) File(java.io.File)

Example 3 with ImageScaleType

use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project JamsMusicPlayer by psaravan.

the class PlaylistEditorActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    //Initialize Context and SharedPreferences.
    mContext = this;
    mApp = (Common) this.getApplicationContext();
    sharedPreferences = mContext.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);
    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        setTheme(R.style.AppTheme);
    } else {
        setTheme(R.style.AppThemeLight);
    }
    super.onCreate(savedInstanceState);
    //Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;
    //Display Image Options.
    displayImageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.default_album_art).showImageOnFail(R.drawable.default_album_art).showStubImage(R.drawable.transparent_drawable).cacheInMemory(false).cacheOnDisc(true).decodingOptions(options).imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(400)).delayBeforeLoading(100).build();
    //Attach tabs to the ActionBar.
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    //Add the artists tab.
    String artistsLabel = getResources().getString(R.string.artists);
    Tab tab = actionBar.newTab();
    tab.setText(artistsLabel);
    TabListener<ArtistsPickerFragment> artistsTabListener = new TabListener<ArtistsPickerFragment>(this, artistsLabel, ArtistsPickerFragment.class);
    tab.setTabListener(artistsTabListener);
    actionBar.addTab(tab);
    //Add the albums tab.
    String albumsLabel = getResources().getString(R.string.albums);
    tab = actionBar.newTab();
    tab.setText(albumsLabel);
    TabListener<AlbumsPickerFragment> albumsTabListener = new TabListener<AlbumsPickerFragment>(this, albumsLabel, AlbumsPickerFragment.class);
    tab.setTabListener(albumsTabListener);
    actionBar.addTab(tab);
    //Add the songs tab.
    String songsLabel = getResources().getString(R.string.songs);
    tab = actionBar.newTab();
    tab.setText(songsLabel);
    TabListener<SongsPickerFragment> songsTabListener = new TabListener<SongsPickerFragment>(this, songsLabel, SongsPickerFragment.class);
    tab.setTabListener(songsTabListener);
    actionBar.addTab(tab);
}
Also used : DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions) SpannableString(android.text.SpannableString) Tab(android.app.ActionBar.Tab) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer) BitmapFactory(android.graphics.BitmapFactory) ActionBar(android.app.ActionBar)

Example 4 with ImageScaleType

use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project JamsMusicPlayer by psaravan.

the class Common method initDisplayImageOptions.

/**
     * Initializes a DisplayImageOptions object. The drawable shown
     * while an image is loading is based on the current theme.
     */
public void initDisplayImageOptions() {
    //Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;
    int emptyColorPatch = UIElementsHelper.getEmptyColorPatch(this);
    mDisplayImageOptions = null;
    mDisplayImageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(emptyColorPatch).showImageOnFail(emptyColorPatch).showImageOnLoading(emptyColorPatch).cacheInMemory(true).cacheOnDisc(true).decodingOptions(options).imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).bitmapConfig(Bitmap.Config.ARGB_4444).delayBeforeLoading(400).displayer(new FadeInBitmapDisplayer(200)).build();
}
Also used : DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer) BitmapFactory(android.graphics.BitmapFactory)

Example 5 with ImageScaleType

use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project JamsMusicPlayer by psaravan.

the class MusicLibraryEditorActivity method onCreate.

@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
    //Initialize Context and SharedPreferences.
    mContext = this;
    mApp = (Common) mContext.getApplicationContext();
    //Retrieve the name/icon of the library from the arguments.
    libraryName = getIntent().getExtras().getString("LIBRARY_NAME");
    libraryIconName = getIntent().getExtras().getString("LIBRARY_ICON");
    if (getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET") != null) {
        songDBIdsList = (HashSet<String>) getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET");
    }
    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        setTheme(R.style.AppTheme);
    } else {
        setTheme(R.style.AppThemeLight);
    }
    super.onCreate(savedInstanceState);
    //Initialize the database helper.
    dbHelper = new DBAccessHelper(mContext.getApplicationContext());
    //Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;
    //Display Image Options.
    int defaultArt = UIElementsHelper.getIcon(mContext, "default_album_art_padded");
    displayImageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.default_album_art).showImageOnFail(R.drawable.default_album_art).showStubImage(R.drawable.transparent_drawable).cacheInMemory(false).cacheOnDisc(true).decodingOptions(options).imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(400)).delayBeforeLoading(100).build();
    //Attach tabs to the ActionBar.
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    //Add the artists tab.
    String artistsLabel = getResources().getString(R.string.artists);
    Tab tab = actionBar.newTab();
    tab.setText(artistsLabel);
    TabListener<ArtistsPickerFragment> artistsTabListener = new TabListener<ArtistsPickerFragment>(this, artistsLabel, ArtistsPickerFragment.class);
    tab.setTabListener(artistsTabListener);
    actionBar.addTab(tab);
    //Add the albums tab.
    String albumsLabel = getResources().getString(R.string.albums);
    tab = actionBar.newTab();
    tab.setText(albumsLabel);
    TabListener<AlbumsPickerFragment> albumsTabListener = new TabListener<AlbumsPickerFragment>(this, albumsLabel, AlbumsPickerFragment.class);
    tab.setTabListener(albumsTabListener);
    actionBar.addTab(tab);
    //Add the songs tab.
    String songsLabel = getResources().getString(R.string.songs);
    tab = actionBar.newTab();
    tab.setText(songsLabel);
    TabListener<SongsPickerFragment> songsTabListener = new TabListener<SongsPickerFragment>(this, songsLabel, SongsPickerFragment.class);
    tab.setTabListener(songsTabListener);
    actionBar.addTab(tab);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
        int topPadding = Common.getStatusBarHeight(mContext);
        View activityView = (View) findViewById(android.R.id.content);
        //Calculate ActionBar height
        TypedValue tv = new TypedValue();
        int actionBarHeight = 0;
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        }
        if (activityView != null) {
            activityView.setPadding(0, topPadding + actionBarHeight, 0, 0);
        }
    }
}
Also used : DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions) DBAccessHelper(com.jams.music.player.DBHelpers.DBAccessHelper) SpannableString(android.text.SpannableString) View(android.view.View) Tab(android.app.ActionBar.Tab) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer) BitmapFactory(android.graphics.BitmapFactory) ActionBar(android.app.ActionBar) TypedValue(android.util.TypedValue)

Aggregations

DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)7 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)6 BitmapFactory (android.graphics.BitmapFactory)4 File (java.io.File)4 UnlimitedDiskCache (com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache)3 LruMemoryCache (com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache)3 ImageLoaderConfiguration (com.nostra13.universalimageloader.core.ImageLoaderConfiguration)3 ImageSize (com.nostra13.universalimageloader.core.assist.ImageSize)3 ActionBar (android.app.ActionBar)2 Tab (android.app.ActionBar.Tab)2 Bitmap (android.graphics.Bitmap)2 SpannableString (android.text.SpannableString)2 TypedValue (android.util.TypedValue)2 View (android.view.View)2 HashCodeFileNameGenerator (com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator)2 ImageScaleType (com.nostra13.universalimageloader.core.assist.ImageScaleType)2 BaseImageDecoder (com.nostra13.universalimageloader.core.decode.BaseImageDecoder)2 BaseImageDownloader (com.nostra13.universalimageloader.core.download.BaseImageDownloader)2 Options (android.graphics.BitmapFactory.Options)1 Matrix (android.graphics.Matrix)1