OSDN Git Service

Eleven: Cleanup all the whitespace
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / ElevenApplication.java
1 /*
2  * Copyright (C) 2012 Andrew Neal
3  * Copyright (C) 2014 The CyanogenMod Project
4  * Licensed under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
8  * or agreed to in writing, software distributed under the License is
9  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10  * KIND, either express or implied. See the License for the specific language
11  * governing permissions and limitations under the License.
12  */
13
14 package com.cyanogenmod.eleven;
15
16 import android.app.Application;
17 import android.os.StrictMode;
18
19 import com.cyanogenmod.eleven.cache.ImageCache;
20
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23
24 /**
25  * Used to turn off logging for jaudiotagger and free up memory when
26  * {@code #onLowMemory()} is called on pre-ICS devices. On post-ICS memory is
27  * released within {@link ImageCache}.
28  *
29  * @author Andrew Neal (andrewdneal@gmail.com)
30  */
31 public class ElevenApplication extends Application {
32     private static final boolean DEBUG = false;
33
34     /**
35      * {@inheritDoc}
36      */
37     @Override
38     public void onCreate() {
39         // Enable strict mode logging
40         enableStrictMode();
41         // Turn off logging for jaudiotagger.
42         Logger.getLogger("org.jaudiotagger").setLevel(Level.OFF);
43     }
44
45     /**
46      * {@inheritDoc}
47      */
48     @Override
49     public void onLowMemory() {
50         ImageCache.getInstance(this).evictAll();
51         super.onLowMemory();
52     }
53
54     private void enableStrictMode() {
55         if (DEBUG) {
56             final StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder()
57                     .detectAll().penaltyLog();
58             final StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder()
59                     .detectAll().penaltyLog();
60
61             threadPolicyBuilder.penaltyFlashScreen();
62             StrictMode.setThreadPolicy(threadPolicyBuilder.build());
63             StrictMode.setVmPolicy(vmPolicyBuilder.build());
64         }
65     }
66 }