Android Open Source - image-loader Image Loader Base Activity






From Project

Back to project page image-loader.

License

The source code is released under:

Apache License

If you think the Android project image-loader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.novoda.imageloader.demo.activity.base;
//from w  w  w.j  a  va2 s.c o m
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.widget.SimpleCursorAdapter.ViewBinder;

import com.novoda.imageloader.core.ImageManager;
import com.novoda.imageloader.core.model.ImageTagFactory;
import com.novoda.imageloader.core.util.AnimationHelper;
import com.novoda.imageloader.demo.R;

public abstract class ImageLoaderBaseActivity extends Activity implements View.OnClickListener {

    private static final String[] CURSOR_FROM = new String[]{"url"};
    private static final int[] CURSOR_TO = new int[]{R.id.list_item_image};

    protected ImageTagFactory imageTagFactory;
    protected ImageManager imageManager;

    private boolean useCacheFlag;
    private Button cacheModeButton;

    private AbsListView view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.base_list_activity_layout);
        initView();
        initButtons();
        setAdapter();
    }

    private void initView() {
        view = getListTypeFromIntent();
        view.setVisibility(View.VISIBLE);

    }

    private AbsListView getListTypeFromIntent() {
        if (intentIsGrid()) {
            return (GridView) findViewById(R.id.grid_view);
        } else {
            return (ListView) findViewById(R.id.list_view);
        }
    }

    private boolean intentIsGrid() {
        return getIntent().hasExtra("grid") && getIntent().getBooleanExtra("grid", false);
    }

    private void initButtons() {
        Button button = (Button) this.findViewById(R.id.refresh_button);
        button.setOnClickListener(this);
        cacheModeButton = (Button) this.findViewById(R.id.cache_mode_button);
        cacheModeButton.setOnClickListener(this);
    }

    private void setAdapter() {
        SimpleCursorAdapter adapter = initAdapter();
        ViewBinder binder = getViewBinder();
        if (binder != null) {
            adapter.setViewBinder(binder);
        }
        if (view instanceof ListView) {
            ((ListView) view).setAdapter(adapter);
        } else if (view instanceof GridView) {
            ((GridView) view).setAdapter(adapter);
        }
    }

    protected abstract ViewBinder getViewBinder();

    private SimpleCursorAdapter initAdapter() {
        return new SimpleCursorAdapter(this, getImageItemLayout(), getCursor(), CURSOR_FROM, CURSOR_TO);
    }

    protected int getImageItemLayout() {
        return R.layout.image_item;
    }

    private Cursor getCursor() {
        return managedQuery(Uri.parse("content://com.novoda.imageloader.demo/" + getTableName()), null, null, null, null);
    }

    protected abstract String getTableName();

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.refresh_button:
                refreshData();
                break;
            case R.id.cache_mode_button:
                useCacheFlag = !useCacheFlag;
                setCacheModeText();
                imageTagFactory.setUseOnlyCache(useCacheFlag);
                break;
            default:
                break;
        }
    }

    private void refreshData() {
        ((SimpleCursorAdapter) view.getAdapter()).notifyDataSetChanged();
    }

    private void setCacheModeText() {
        if (useCacheFlag) {
            cacheModeButton.setText(getString(R.string.turn_off_cache_only));
        } else {
            cacheModeButton.setText(getString(R.string.cache_only));
        }
    }

    protected void setAnimationFromIntent(ImageTagFactory imageTagFactory) {
        if (intentHasAnimation()) {
            imageTagFactory.setAnimation(getIntent().getIntExtra("animated", AnimationHelper.ANIMATION_DISABLED));
        }
    }

    private boolean intentHasAnimation() {
        return getIntent().hasExtra("animated") && getIntent().getIntExtra("animated", AnimationHelper.ANIMATION_DISABLED) != AnimationHelper.ANIMATION_DISABLED;
    }

}




Java Source Code List

com.novoda.imageloader.acceptance.BitmapUtilsInstrumentationTest.java
com.novoda.imageloader.acceptance.BitmapUtilsShould.java
com.novoda.imageloader.acceptance.ImageLoaderDemoActivityTest.java
com.novoda.imageloader.acceptance.ImageManagerInstrumentationTest.java
com.novoda.imageloader.acceptance.LruBitmapCacheInstrumentationTest.java
com.novoda.imageloader.core.ImageManager.java
com.novoda.imageloader.core.LoaderContext.java
com.novoda.imageloader.core.LoaderSettings.java
com.novoda.imageloader.core.OnImageLoadedListener.java
com.novoda.imageloader.core.bitmap.BitmapUtil.java
com.novoda.imageloader.core.cache.CacheManager.java
com.novoda.imageloader.core.cache.LruBitmapCache.java
com.novoda.imageloader.core.cache.NoCache.java
com.novoda.imageloader.core.cache.SoftMapCache.java
com.novoda.imageloader.core.cache.util.LruCache.java
com.novoda.imageloader.core.exception.ImageCopyException.java
com.novoda.imageloader.core.exception.ImageNotFoundException.java
com.novoda.imageloader.core.exception.MissingSettingException.java
com.novoda.imageloader.core.file.BasicFileManager.java
com.novoda.imageloader.core.file.FileManager.java
com.novoda.imageloader.core.file.util.AndroidFileContext.java
com.novoda.imageloader.core.file.util.FileUtil.java
com.novoda.imageloader.core.file.util.FlushedInputStream.java
com.novoda.imageloader.core.loader.ConcurrentLoader.java
com.novoda.imageloader.core.loader.Loader.java
com.novoda.imageloader.core.loader.SimpleLoader.java
com.novoda.imageloader.core.loader.util.AsyncResult.java
com.novoda.imageloader.core.loader.util.AsyncTask.java
com.novoda.imageloader.core.loader.util.BitmapDisplayer.java
com.novoda.imageloader.core.loader.util.BitmapRetriever.java
com.novoda.imageloader.core.loader.util.LoaderTask.java
com.novoda.imageloader.core.loader.util.SingleThreadedLoader.java
com.novoda.imageloader.core.model.ImageTagFactory.java
com.novoda.imageloader.core.model.ImageTag.java
com.novoda.imageloader.core.model.ImageWrapper.java
com.novoda.imageloader.core.network.NetworkManager.java
com.novoda.imageloader.core.network.UrlNetworkManager.java
com.novoda.imageloader.core.network.UrlUtil.java
com.novoda.imageloader.core.util.AnimationHelper.java
com.novoda.imageloader.core.util.DirectLoader.java
com.novoda.imageloader.core.util.Log.java
com.novoda.imageloader.demo.DemoApplication.java
com.novoda.imageloader.demo.activity.BigImages.java
com.novoda.imageloader.demo.activity.Demos.java
com.novoda.imageloader.demo.activity.DirectLoading.java
com.novoda.imageloader.demo.activity.ImageLongList.java
com.novoda.imageloader.demo.activity.LongSmallImageList.java
com.novoda.imageloader.demo.activity.base.ImageLoaderBaseActivity.java
com.novoda.imageloader.demo.provider.CustomUriMatcher.java
com.novoda.imageloader.demo.provider.DatabaseManager.java
com.novoda.imageloader.demo.provider.ImageLoaderDemoProvider.java
com.novoda.imageloader.demo.provider.SqlFile.java
com.novoda.imageloader.demo.util.BugSenseHelper.java
com.novoda.imageloader.demo.util.BugsenseApiKeyFailedException.java