android---notes AppContext extends Application

8664 단어 application
package com.fuda;

import org.apache.http.client.CookieStore;

import com.fuda.model.StudentInfoModel;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

import net.tsz.afinal.FinalBitmap;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.view.Display;

public class AppContext extends Application {

    public ImageLoader imageLoader ;
    // http://www.2cto.com/kf/201209/154696.html
    public CookieStore cookieStore;
    // 
    public StudentInfoModel studentInfoModel;

    public StudentInfoModel getStudentInfoModel() {
        return studentInfoModel;
    }

    public void setStudentInfoModel(StudentInfoModel studentInfoModel) {
        this.studentInfoModel = studentInfoModel;
    }

    public CookieStore getCookieStore() {
        return cookieStore;
    }

    public void setCookieStore(CookieStore cookieStore) {
        this.cookieStore = null;
        this.cookieStore = cookieStore;
    }

    public void clearCookieStore() {
        cookieStore.clear();
        this.cookieStore = null;
    }

    //http://blog.csdn.net/chenzheng_java/article/details/6387116/
    public boolean isNetworkConnected() {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        return ni != null && ni.isConnectedOrConnecting();
    }

    public void onCreate() {
        super.onCreate();
        initImageLoader(getApplicationContext());
        this.imageLoader = ImageLoader.getInstance();
    }
    
    public static void initImageLoader(Context context) {
        // This configuration tuning is custom. You can tune every option, you may tune some of them, 
        // or you can create default configuration by
        //  ImageLoaderConfiguration.createDefault(this);
        // method.
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                .discCacheFileNameGenerator(new Md5FileNameGenerator())
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .enableLogging() // Not necessary in common
                .build();
        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config);
    }
    
    public static class Config {
        public static final boolean DEVELOPER_MODE = false;
    }

}

좋은 웹페이지 즐겨찾기