Search in sources :

Example 11 with ImageLoader

use of com.nostra13.universalimageloader.core.ImageLoader in project BlogSource by TeachCourse.

the class App method config.

/**
 * 初始化ImageLoader配置
 *
 * @param context
 */
private ImageLoaderConfiguration config(Context context) {
    File cacheDir = StorageUtils.getOwnCacheDirectory(context, CACHE);
    if (!cacheDir.exists()) {
        cacheDir.mkdirs();
    }
    ImageLoaderConfiguration options = new ImageLoaderConfiguration.Builder(context).memoryCacheExtraOptions(480, 800).denyCacheImageMultipleSizesInMemory().tasksProcessingOrder(QueueProcessingType.LIFO).diskCache(new UnlimitedDiskCache(cacheDir)).build();
    return options;
}
Also used : UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) File(java.io.File) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration)

Example 12 with ImageLoader

use of com.nostra13.universalimageloader.core.ImageLoader in project ForPDA by RadiationX.

the class App method initImageLoader.

public static void initImageLoader(Context context) {
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).imageDownloader(new BaseImageDownloader(context) {

        final Pattern pattern4pda = Pattern.compile("(?:http?s?:)?\\/\\/.*?4pda\\.(?:ru|to)");

        @Override
        public InputStream getStream(String imageUri, Object extra) throws IOException {
            if (imageUri.substring(0, 2).equals("//"))
                imageUri = "http:".concat(imageUri);
            Log.d(App.class.getSimpleName(), "ImageLoader getStream " + imageUri);
            return super.getStream(imageUri, extra);
        }

        @Override
        protected HttpURLConnection createConnection(String url, Object extra) throws IOException {
            HttpURLConnection conn = super.createConnection(url, extra);
            if (pattern4pda.matcher(url).find()) {
                Map<String, Cookie> cookies = Client.get().getClientCookies();
                String stringCookies = "";
                for (Map.Entry<String, Cookie> cookieEntry : cookies.entrySet()) {
                    stringCookies = stringCookies.concat(cookieEntry.getKey()).concat("=").concat(cookieEntry.getValue().value()).concat(";");
                }
                conn.setRequestProperty("Cookie", stringCookies);
            }
            return conn;
        }
    }).threadPoolSize(5).threadPriority(Thread.MIN_PRIORITY).denyCacheImageMultipleSizesInMemory().memoryCache(// 5 Mb
    new UsingFreqLimitedMemoryCache(5 * 1024 * 1024)).diskCacheFileNameGenerator(new HashCodeFileNameGenerator()).defaultDisplayImageOptions(options.build()).build();
    ImageLoader.getInstance().init(config);
}
Also used : Cookie(okhttp3.Cookie) Pattern(java.util.regex.Pattern) HashCodeFileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator) UsingFreqLimitedMemoryCache(com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache) HttpURLConnection(java.net.HttpURLConnection) BaseImageDownloader(com.nostra13.universalimageloader.core.download.BaseImageDownloader) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with ImageLoader

use of com.nostra13.universalimageloader.core.ImageLoader in project howabout-android by recomio.

the class MusicPlaylistActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    imageLoader = ImageLoader.getInstance();
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    setAdsContainer(R.id.adView);
    HowaboutApplication application = (HowaboutApplication) getApplication();
    playlistAdapter = application.getPlaylistAdapter();
    if (MusicPlayerService.isLoading()) {
        loadingProgressBar.setVisibility(View.VISIBLE);
        playPauseToggleButton.setVisibility(View.GONE);
    } else {
        if (MusicPlayerService.isPlaying()) {
            playPauseToggleButton.setImageDrawable(pauseIcon);
        } else {
            playPauseToggleButton.setImageDrawable(playIcon);
        }
        loadingProgressBar.setVisibility(View.GONE);
        playPauseToggleButton.setVisibility(View.VISIBLE);
    }
    listView.setAdapter(playlistAdapter);
    playlistAdapter.registerDataSetObserver(new DataSetObserver() {

        @Override
        public void onChanged() {
            try {
                Track track = playlistAdapter.getCurrentItem();
                actionBar.setTitle(track.getTrackTitle());
                actionBar.setSubtitle(track.getArtistName());
                if (MusicPlayerService.isLoading()) {
                    loadingProgressBar.setVisibility(View.VISIBLE);
                    playPauseToggleButton.setVisibility(View.GONE);
                } else {
                    if (MusicPlayerService.isPlaying()) {
                        playPauseToggleButton.setImageDrawable(pauseIcon);
                    } else {
                        playPauseToggleButton.setImageDrawable(playIcon);
                    }
                    loadingProgressBar.setVisibility(View.GONE);
                    playPauseToggleButton.setVisibility(View.VISIBLE);
                }
                imageLoader.displayImage(track.getThumbnailUrl(), songImageView, new ImageLoadingListener() {

                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    }

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {
                    }
                });
                String lyrics = playlistAdapter.getCurrentLyrics();
                if (lyrics == null) {
                    lyricsScrollView.setVisibility(View.GONE);
                    lyricsTextView.setText("");
                } else {
                    lyricsScrollView.setVisibility(View.VISIBLE);
                    lyricsTextView.setText(lyrics);
                }
                listView.invalidate();
            } catch (Exception e) {
            }
        }

        @Override
        public void onInvalidated() {
        }
    });
    playlistAdapter.notifyDataSetChanged();
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            playlistAdapter.play(position);
            playlistAdapter.notifyDataSetChanged();
        }
    });
    listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            playlistAdapter.remove(position);
            return true;
        }
    });
    playPauseToggleButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playlistAdapter.playPauseToggle();
            if (MusicPlayerService.isPlaying()) {
                playPauseToggleButton.setImageDrawable(pauseIcon);
            } else {
                playPauseToggleButton.setImageDrawable(playIcon);
            }
        }
    });
    prevButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playlistAdapter.playPrev();
        }
    });
    nextButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playlistAdapter.playNext();
        }
    });
    UpdateCurrentPositionTask updateCurrentPositionTask = new UpdateCurrentPositionTask();
    updateCurrentPositionTimer.scheduleAtFixedRate(updateCurrentPositionTask, 0, 1000);
}
Also used : ImageLoadingListener(com.nostra13.universalimageloader.core.assist.ImageLoadingListener) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) HowaboutApplication(io.recom.howabout.HowaboutApplication) DataSetObserver(android.database.DataSetObserver) ContentView(roboguice.inject.ContentView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ListView(android.widget.ListView) OnItemLongClickListener(android.widget.AdapterView.OnItemLongClickListener) Bitmap(android.graphics.Bitmap) OnClickListener(android.view.View.OnClickListener) ActionBar(com.actionbarsherlock.app.ActionBar) Track(io.recom.howabout.category.music.model.Track)

Example 14 with ImageLoader

use of com.nostra13.universalimageloader.core.ImageLoader in project SeaStar by 13120241790.

the class SealFragment method configImageLoader.

private void configImageLoader() {
    // 初始化ImageLoader
    DisplayImageOptions options = // 设置图片下载期间显示的图片
    new DisplayImageOptions.Builder().showStubImage(drawable.icon_stub).showImageForEmptyUri(// 设置图片Uri为空或是错误的时候显示的图片
    drawable.icon_stub).showImageOnFail(// 设置图片加载或解码过程中发生错误显示的图片
    drawable.icon_stub).cacheInMemory(// 设置下载的图片是否缓存在内存中
    true).cacheOnDisc(// 设置下载的图片是否缓存在SD卡中
    true).build();
    // 创建配置过得DisplayImageOption对象
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext()).defaultDisplayImageOptions(options).threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().discCacheFileNameGenerator(new Md5FileNameGenerator()).tasksProcessingOrder(QueueProcessingType.LIFO).build();
    ImageLoader.getInstance().init(config);
}
Also used : Md5FileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Example 15 with ImageLoader

use of com.nostra13.universalimageloader.core.ImageLoader in project GalleryFinal by pengjianbo.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mLvPhoto = (HorizontalListView) findViewById(R.id.lv_photo);
    mPhotoList = new ArrayList<>();
    mChoosePhotoListAdapter = new ChoosePhotoListAdapter(this, mPhotoList);
    mLvPhoto.setAdapter(mChoosePhotoListAdapter);
    mOpenGallery = (Button) findViewById(R.id.btn_open_gallery);
    mRbMutiSelect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mLlMaxSize.setVisibility(View.VISIBLE);
                mLlForceCrop.setVisibility(View.GONE);
            } else {
                if (mCbEdit.isChecked()) {
                    mLlForceCrop.setVisibility(View.VISIBLE);
                }
                mLlMaxSize.setVisibility(View.GONE);
            }
        }
    });
    mCbEdit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mLlEdit.setVisibility(View.VISIBLE);
            } else {
                mLlEdit.setVisibility(View.GONE);
            }
        }
    });
    mCbCrop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mLlCropSize.setVisibility(View.VISIBLE);
                mCbCropReplaceSource.setVisibility(View.VISIBLE);
                if (mRbSingleSelect.isChecked()) {
                    mLlForceCrop.setVisibility(View.VISIBLE);
                }
            } else {
                mLlCropSize.setVisibility(View.GONE);
                mCbCropReplaceSource.setVisibility(View.INVISIBLE);
                mLlForceCrop.setVisibility(View.GONE);
            }
        }
    });
    mCbRotate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mCbRotateReplaceSource.setVisibility(View.VISIBLE);
            } else {
                mCbRotateReplaceSource.setVisibility(View.INVISIBLE);
            }
        }
    });
    mCbOpenForceCrop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mCbOpenForceCropEdit.setVisibility(View.VISIBLE);
            } else {
                mCbOpenForceCropEdit.setVisibility(View.INVISIBLE);
            }
        }
    });
    mOpenGallery.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // 公共配置都可以在application中配置,这里只是为了代码演示而写在此处
            ThemeConfig themeConfig = null;
            if (mRbThemeDefault.isChecked()) {
                themeConfig = ThemeConfig.DEFAULT;
            } else if (mRbThemeDark.isChecked()) {
                themeConfig = ThemeConfig.DARK;
            } else if (mRbThemeCyan.isChecked()) {
                themeConfig = ThemeConfig.CYAN;
            } else if (mRbThemeOrange.isChecked()) {
                themeConfig = ThemeConfig.ORANGE;
            } else if (mRbThemeGreen.isChecked()) {
                themeConfig = ThemeConfig.GREEN;
            } else if (mRbThemeTeal.isChecked()) {
                themeConfig = ThemeConfig.TEAL;
            } else if (mRbThemeCustom.isChecked()) {
                ThemeConfig theme = new ThemeConfig.Builder().setTitleBarBgColor(Color.rgb(0xFF, 0x57, 0x22)).setTitleBarTextColor(Color.BLACK).setTitleBarIconColor(Color.BLACK).setFabNornalColor(Color.RED).setFabPressedColor(Color.BLUE).setCheckNornalColor(Color.WHITE).setCheckSelectedColor(Color.BLACK).setIconBack(R.mipmap.ic_action_previous_item).setIconRotate(R.mipmap.ic_action_repeat).setIconCrop(R.mipmap.ic_action_crop).setIconCamera(R.mipmap.ic_action_camera).build();
                themeConfig = theme;
            }
            FunctionConfig.Builder functionConfigBuilder = new FunctionConfig.Builder();
            cn.finalteam.galleryfinal.ImageLoader imageLoader;
            PauseOnScrollListener pauseOnScrollListener = null;
            if (mRbUil.isChecked()) {
                imageLoader = new UILImageLoader();
                pauseOnScrollListener = new UILPauseOnScrollListener(false, true);
            } else if (mRbXutils.isChecked()) {
                imageLoader = new XUtils2ImageLoader(MainActivity.this);
            } else if (mRbXutils3.isChecked()) {
                imageLoader = new XUtilsImageLoader();
            } else if (mRbGlide.isChecked()) {
                imageLoader = new GlideImageLoader();
                pauseOnScrollListener = new GlidePauseOnScrollListener(false, true);
            } else if (mRbFresco.isChecked()) {
                imageLoader = new FrescoImageLoader(MainActivity.this);
            } else {
                imageLoader = new PicassoImageLoader();
                pauseOnScrollListener = new PicassoPauseOnScrollListener(false, true);
            }
            boolean muti = false;
            if (mRbSingleSelect.isChecked()) {
                muti = false;
            } else {
                muti = true;
                if (TextUtils.isEmpty(mEtMaxSize.getText().toString())) {
                    Toast.makeText(getApplicationContext(), "请输入MaxSize", Toast.LENGTH_SHORT).show();
                    return;
                }
                int maxSize = Integer.parseInt(mEtMaxSize.getText().toString());
                functionConfigBuilder.setMutiSelectMaxSize(maxSize);
            }
            final boolean mutiSelect = muti;
            if (mCbEdit.isChecked()) {
                functionConfigBuilder.setEnableEdit(true);
            }
            if (mCbRotate.isChecked()) {
                functionConfigBuilder.setEnableRotate(true);
                if (mCbRotateReplaceSource.isChecked()) {
                    functionConfigBuilder.setRotateReplaceSource(true);
                }
            }
            if (mCbCrop.isChecked()) {
                functionConfigBuilder.setEnableCrop(true);
                if (!TextUtils.isEmpty(mEtCropWidth.getText().toString())) {
                    int width = Integer.parseInt(mEtCropWidth.getText().toString());
                    functionConfigBuilder.setCropWidth(width);
                }
                if (!TextUtils.isEmpty(mEtCropHeight.getText().toString())) {
                    int height = Integer.parseInt(mEtCropHeight.getText().toString());
                    functionConfigBuilder.setCropHeight(height);
                }
                if (mCbCropSquare.isChecked()) {
                    functionConfigBuilder.setCropSquare(true);
                }
                if (mCbCropReplaceSource.isChecked()) {
                    functionConfigBuilder.setCropReplaceSource(true);
                }
                if (mCbOpenForceCrop.isChecked() && mRbSingleSelect.isChecked()) {
                    functionConfigBuilder.setForceCrop(true);
                    if (mCbOpenForceCropEdit.isChecked()) {
                        functionConfigBuilder.setForceCropEdit(true);
                    }
                }
            }
            if (mCbShowCamera.isChecked()) {
                functionConfigBuilder.setEnableCamera(true);
            }
            if (mCbPreview.isChecked()) {
                functionConfigBuilder.setEnablePreview(true);
            }
            // 添加过滤集合
            functionConfigBuilder.setSelected(mPhotoList);
            final FunctionConfig functionConfig = functionConfigBuilder.build();
            CoreConfig coreConfig = new CoreConfig.Builder(MainActivity.this, imageLoader, themeConfig).setFunctionConfig(functionConfig).setPauseOnScrollListener(pauseOnScrollListener).setNoAnimcation(mCbNoAnimation.isChecked()).build();
            GalleryFinal.init(coreConfig);
            ActionSheet.createBuilder(MainActivity.this, getSupportFragmentManager()).setCancelButtonTitle("取消(Cancel)").setOtherButtonTitles("打开相册(Open Gallery)", "拍照(Camera)", "裁剪(Crop)", "编辑(Edit)").setCancelableOnTouchOutside(true).setListener(new ActionSheet.ActionSheetListener() {

                @Override
                public void onDismiss(ActionSheet actionSheet, boolean isCancel) {
                }

                @Override
                public void onOtherButtonClick(ActionSheet actionSheet, int index) {
                    String path = "/sdcard/pk1-2.jpg";
                    switch(index) {
                        case 0:
                            if (mutiSelect) {
                                GalleryFinal.openGalleryMuti(REQUEST_CODE_GALLERY, functionConfig, mOnHanlderResultCallback);
                            } else {
                                GalleryFinal.openGallerySingle(REQUEST_CODE_GALLERY, functionConfig, mOnHanlderResultCallback);
                            }
                            break;
                        case 1:
                            GalleryFinal.openCamera(REQUEST_CODE_CAMERA, functionConfig, mOnHanlderResultCallback);
                            break;
                        case 2:
                            if (new File(path).exists()) {
                                GalleryFinal.openCrop(REQUEST_CODE_CROP, functionConfig, path, mOnHanlderResultCallback);
                            } else {
                                Toast.makeText(MainActivity.this, "图片不存在", Toast.LENGTH_SHORT).show();
                            }
                            break;
                        case 3:
                            if (new File(path).exists()) {
                                GalleryFinal.openEdit(REQUEST_CODE_EDIT, functionConfig, path, mOnHanlderResultCallback);
                            } else {
                                Toast.makeText(MainActivity.this, "图片不存在", Toast.LENGTH_SHORT).show();
                            }
                            break;
                        default:
                            break;
                    }
                }
            }).show();
        }
    });
    initImageLoader(this);
    initFresco();
    x.Ext.init(getApplication());
}
Also used : FunctionConfig(cn.finalteam.galleryfinal.FunctionConfig) CoreConfig(cn.finalteam.galleryfinal.CoreConfig) XUtilsImageLoader(cn.finalteam.galleryfinal.sample.loader.XUtilsImageLoader) ActionSheet(com.baoyz.actionsheet.ActionSheet) PicassoImageLoader(cn.finalteam.galleryfinal.sample.loader.PicassoImageLoader) PicassoPauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.PicassoPauseOnScrollListener) GlideImageLoader(cn.finalteam.galleryfinal.sample.loader.GlideImageLoader) Toolbar(android.support.v7.widget.Toolbar) XUtils2ImageLoader(cn.finalteam.galleryfinal.sample.loader.XUtils2ImageLoader) UILPauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.UILPauseOnScrollListener) UILImageLoader(cn.finalteam.galleryfinal.sample.loader.UILImageLoader) View(android.view.View) HorizontalListView(cn.finalteam.galleryfinal.widget.HorizontalListView) ThemeConfig(cn.finalteam.galleryfinal.ThemeConfig) UILPauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.UILPauseOnScrollListener) PauseOnScrollListener(cn.finalteam.galleryfinal.PauseOnScrollListener) GlidePauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.GlidePauseOnScrollListener) PicassoPauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.PicassoPauseOnScrollListener) FrescoImageLoader(cn.finalteam.galleryfinal.sample.loader.FrescoImageLoader) XUtils2ImageLoader(cn.finalteam.galleryfinal.sample.loader.XUtils2ImageLoader) XUtilsImageLoader(cn.finalteam.galleryfinal.sample.loader.XUtilsImageLoader) UILImageLoader(cn.finalteam.galleryfinal.sample.loader.UILImageLoader) GlideImageLoader(cn.finalteam.galleryfinal.sample.loader.GlideImageLoader) ImageLoader(com.nostra13.universalimageloader.core.ImageLoader) FrescoImageLoader(cn.finalteam.galleryfinal.sample.loader.FrescoImageLoader) PicassoImageLoader(cn.finalteam.galleryfinal.sample.loader.PicassoImageLoader) GlidePauseOnScrollListener(cn.finalteam.galleryfinal.sample.listener.GlidePauseOnScrollListener) File(java.io.File) CompoundButton(android.widget.CompoundButton)

Aggregations

ImageLoaderConfiguration (com.nostra13.universalimageloader.core.ImageLoaderConfiguration)20 Md5FileNameGenerator (com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator)10 ImageLoader (com.nostra13.universalimageloader.core.ImageLoader)8 LruMemoryCache (com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache)6 BaseImageDownloader (com.nostra13.universalimageloader.core.download.BaseImageDownloader)5 File (java.io.File)5 HashCodeFileNameGenerator (com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator)4 View (android.view.View)3 UnlimitedDiskCache (com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache)3 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)3 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 WeakMemoryCache (com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache)2 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)2 IOException (java.io.IOException)2 DataSetObserver (android.database.DataSetObserver)1 Bitmap (android.graphics.Bitmap)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1