All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.holoeverywhere.app.Application Maven / Gradle / Ivy

The newest version!

package org.holoeverywhere.app;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.holoeverywhere.HoloEverywhere;
import org.holoeverywhere.HoloEverywhere.PreferenceImpl;
import org.holoeverywhere.LayoutInflater;
import org.holoeverywhere.LayoutInflater.LayoutInflaterCreator;
import org.holoeverywhere.SystemServiceManager;
import org.holoeverywhere.SystemServiceManager.SuperSystemService;
import org.holoeverywhere.ThemeManager;
import org.holoeverywhere.ThemeManager.SuperStartActivity;
import org.holoeverywhere.addon.AddonSherlock;
import org.holoeverywhere.addon.IAddon;
import org.holoeverywhere.addon.IAddonApplication;
import org.holoeverywhere.addon.IAddonAttacher;
import org.holoeverywhere.addon.IAddonBasicAttacher;
import org.holoeverywhere.preference.PreferenceManagerHelper;
import org.holoeverywhere.preference.SharedPreferences;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Bundle;

public class Application extends android.app.Application implements
        SuperStartActivity, SuperSystemService, IAddonAttacher {
    private static List> sInitialAddons;
    private static Application sLastInstance;
    static {
        SystemServiceManager.register(LayoutInflaterCreator.class);
        addInitialAddon(AddonSherlock.class);
    }

    public static void addInitialAddon(Class clazz) {
        if (sInitialAddons == null) {
            sInitialAddons = new ArrayList>();
        }
        sInitialAddons.add(clazz);
    }

    public static Application getLastInstance() {
        return Application.sLastInstance;
    }

    public static void init() {
    }

    private final IAddonBasicAttacher mAttacher =
            new IAddonBasicAttacher(this);

    public Application() {
        Application.sLastInstance = this;
    }

    @Override
    public  T addon(Class clazz) {
        return mAttacher.addon(clazz);
    }

    @Override
    public void addon(Collection> classes) {
        mAttacher.addon(classes);
    }

    @Override
    public  T addon(String classname) {
        return mAttacher.addon(classname);
    }

    public SharedPreferences getDefaultSharedPreferences() {
        return PreferenceManagerHelper.getDefaultSharedPreferences(this);
    }

    public SharedPreferences getDefaultSharedPreferences(PreferenceImpl impl) {
        return PreferenceManagerHelper.getDefaultSharedPreferences(this, impl);
    }

    public LayoutInflater getLayoutInflater() {
        return LayoutInflater.from(this);
    }

    public SharedPreferences getSharedPreferences(PreferenceImpl impl, String name, int mode) {
        return PreferenceManagerHelper.wrap(this, impl, name, mode);
    }

    @Override
    public SharedPreferences getSharedPreferences(String name, int mode) {
        return PreferenceManagerHelper.wrap(this, name, mode);
    }

    public Application getSupportApplication() {
        return this;
    }

    @Override
    public Object getSystemService(String name) {
        return SystemServiceManager.getSystemService(this, name);
    }

    @Override
    public boolean isAddonAttached(Class clazz) {
        return mAttacher.isAddonAttached(clazz);
    }

    @Override
    public void lockAttaching() {
        mAttacher.lockAttaching();
    }

    @Override
    public Collection> obtainAddonsList() {
        return mAttacher.obtainAddonsList();
    }

    @Override
    public void onCreate() {
        addon(sInitialAddons);
        performAddonAction(new AddonCallback() {
            @Override
            public void justAction(IAddonApplication addon) {
                addon.onPreCreate();
            }
        });
        lockAttaching();
        super.onCreate();
        performAddonAction(new AddonCallback() {
            @Override
            public void justAction(IAddonApplication addon) {
                addon.onCreate();
            }
        });
    }

    @Override
    public boolean performAddonAction(AddonCallback callback) {
        return mAttacher.performAddonAction(callback);
    }

    @Override
    @SuppressLint("NewApi")
    public void startActivities(Intent[] intents) {
        startActivities(intents, null);
    }

    @Override
    @SuppressLint("NewApi")
    public void startActivities(Intent[] intents, Bundle options) {
        for (Intent intent : intents) {
            startActivity(intent, options);
        }
    }

    @Override
    @SuppressLint("NewApi")
    public void startActivity(Intent intent) {
        startActivity(intent, null);
    }

    @Override
    public void startActivity(Intent intent, Bundle options) {
        if (HoloEverywhere.ALWAYS_USE_PARENT_THEME) {
            ThemeManager.startActivity(this, intent, options);
        } else {
            superStartActivity(intent, -1, options);
        }
    }

    public android.content.SharedPreferences superGetSharedPreferences(
            String name, int mode) {
        return super.getSharedPreferences(name, mode);
    }

    @Override
    public Object superGetSystemService(String name) {
        return super.getSystemService(name);
    }

    @Override
    @SuppressLint("NewApi")
    public void superStartActivity(Intent intent, int requestCode,
            Bundle options) {
        if (VERSION.SDK_INT >= 16) {
            super.startActivity(intent, options);
        } else {
            super.startActivity(intent);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy