/*
 * Copyright (C) 2013 Peng fei Pan <sky@xiaopan.me>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package me.xiaopan.spear.sample;

import android.app.Application;
import android.graphics.Color;
import android.util.Log;
import android.widget.ImageView;

import me.xiaopan.android.gohttp.GoHttp;
import me.xiaopan.spear.DisplayOptions;
import me.xiaopan.spear.LoadOptions;
import me.xiaopan.spear.Spear;
import me.xiaopan.spear.display.ColorTransitionImageDisplayer;
import me.xiaopan.spear.display.TransitionImageDisplayer;
import me.xiaopan.spear.process.GaussianBlurImageProcessor;
import me.xiaopan.spear.process.CircleImageProcessor;
import me.xiaopan.spear.sample.util.Settings;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        GoHttp.with(getBaseContext()).setDebugMode(true);
        Spear.setDebugMode(true);
        Spear.putOptions(
                OptionsType.Rectangle_1,
                new DisplayOptions(getBaseContext())
                        .setLoadingDrawable(R.drawable.image_loading2)
                        .setLoadFailDrawable(R.drawable.image_load_fail2)
                        .setPauseDownloadDrawable(R.drawable.image_click2)
                        .setDecodeGifImage(false)
                        .setImageDisplayer(new TransitionImageDisplayer())
        );

        Spear.putOptions(
                OptionsType.Rectangle_0_75,
                new DisplayOptions(getBaseContext())
                        .setLoadingDrawable(R.drawable.image_loading2)
                        .setLoadFailDrawable(R.drawable.image_load_fail2)
                        .setPauseDownloadDrawable(R.drawable.image_click2)
                        .setImageDisplayer(new TransitionImageDisplayer())
        );

        Spear.putOptions(
                OptionsType.Rectangle_1_56,
                new DisplayOptions(getBaseContext())
                        .setLoadingDrawable(R.drawable.image_loading2)
                        .setLoadFailDrawable(R.drawable.image_load_fail2)
                        .setPauseDownloadDrawable(R.drawable.image_click2)
                        .setImageDisplayer(new TransitionImageDisplayer())
        );

        Spear.putOptions(
                OptionsType.Rectangle_3_2,
                new DisplayOptions(getBaseContext())
                        .setLoadingDrawable(R.drawable.image_loading2)
                        .setLoadFailDrawable(R.drawable.image_load_fail2)
                        .setPauseDownloadDrawable(R.drawable.image_click2)
                        .setImageDisplayer(new TransitionImageDisplayer())
        );

        Spear.putOptions(
                OptionsType.Detail,
                new DisplayOptions(getBaseContext())
                        .setLoadFailDrawable(R.drawable.image_load_fail2)
                        .setPauseDownloadDrawable(R.drawable.image_click2)
                        .setImageDisplayer(new ColorTransitionImageDisplayer(Color.TRANSPARENT))
        );

        Spear.putOptions(
                OptionsType.Circular,
                new DisplayOptions(getBaseContext())
                        .setLoadingDrawable(R.drawable.image_loading2)
                        .setLoadFailDrawable(R.drawable.image_load_fail2)
                        .setPauseDownloadDrawable(R.drawable.image_click2)
                        .setImageDisplayer(new TransitionImageDisplayer())
                        .setImageProcessor(new CircleImageProcessor())
        );

        Spear.putOptions(
                OptionsType.WindowBackground,
                new LoadOptions(getBaseContext())
                        .setScaleType(ImageView.ScaleType.CENTER_CROP)
                        .setImageProcessor(new GaussianBlurImageProcessor(true))
                        .setDecodeGifImage(false)
        );

        boolean isPauseDownload = Settings.with(getBaseContext()).isMobileNetworkPauseDownload();
        Spear.with(getBaseContext()).getConfiguration().setMobileNetworkPauseDownload(isPauseDownload);
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();

        Log.w("Application", "lowMemory");
        Spear.with(getBaseContext()).getConfiguration().getMemoryCache().clear();
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        Log.w("Application", "trimMemory");
    }
}
@@ -705,24 +705,62 @@
 hics.Color;%0A
+import android.text.format.Formatter;%0A
 import andro
@@ -1108,28 +1108,22 @@
 process.
-GaussianBlur
+Circle
 ImagePro
@@ -1154,38 +1154,44 @@
 n.spear.process.
-Circle
+GaussianBlur
 ImageProcessor;%0A
@@ -4738,28 +4738,119 @@
 %22, %22
-low
 Memory
-%22);%0A       
+ is very low, has automatic releasing Spear in memory cache(%22+ Formatter.formatFileSize(getBaseContext(),
  Spe
@@ -4915,156 +4915,104 @@
 e().
-clear(
+getSize())+%22)%22
 );%0A    
-%7D%0A%0A
     
-@Override%0A    public void onTrimMemory(int level) %7B%0A        super.onTrimMemory(level);%0A        Log.w(%22Application%22, %22trimMemory%22
+Spear.with(getBaseContext()).getConfiguration().getMemoryCache().clear(
 );%0A 

optimize low memory log