Search in sources :

Example 1 with Application

use of org.holoeverywhere.app.Application in project HoloEverywhere by Prototik.

the class _HoloActivity method onInit.

/**
     * Do not override this method. Use {@link #onPreInit(Holo, Bundle)} and
     * {@link #onPostInit(Holo, Bundle)}
     */
protected void onInit(Holo config, Bundle savedInstanceState) {
    if (mInited) {
        throw new IllegalStateException("This instance was already inited");
    }
    mInited = true;
    if (config == null) {
        config = createConfig(savedInstanceState);
    }
    if (config == null) {
        config = Holo.defaultConfig();
    }
    onPreInit(config, savedInstanceState);
    if (!config.ignoreApplicationInstanceCheck && !(getApplication() instanceof Application)) {
        boolean throwError = true;
        if (config.allowMockApplicationInstance) {
            try {
                throwError = !(getApplication() instanceof MockApplication);
                if (!throwError) {
                    Log.w("HoloEverywhere", "Application instance is MockApplication. Wow. Let's begin tests...");
                }
            } catch (Exception e) {
            }
        }
        if (throwError) {
            String text = "Application instance isn't HoloEverywhere.\n";
            if (getApplication().getClass() == android.app.Application.class) {
                text += "Put attr 'android:name=\"org.holoeverywhere.app.Application\"'" + " in <application> tag of AndroidManifest.xml";
            } else {
                text += "Please sure that you extend " + getApplication().getClass() + " from a org.holoeverywhere.app.Application";
            }
            throw new IllegalStateException(text);
        }
    }
    getLayoutInflater().setFragmentActivity(this);
    if (this instanceof Activity) {
        final Activity activity = (Activity) this;
        ThemeManager.applyTheme(activity, mLastThemeResourceId == 0);
        if (!config.ignoreThemeCheck && ThemeManager.getThemeType(this) == ThemeManager.INVALID) {
            throw new HoloThemeException(activity);
        }
        TypedArray a = obtainStyledAttributes(new int[] { android.R.attr.windowActionBarOverlay, R.attr.windowActionBarOverlay });
        if (a.getBoolean(0, false) || a.getBoolean(1, false)) {
            supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
        }
        a.recycle();
        a = obtainStyledAttributes(new int[] { android.R.attr.windowActionModeOverlay, R.attr.windowActionBarOverlay });
        if (a.getBoolean(0, false) || a.getBoolean(1, false)) {
            supportRequestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
        }
        a.recycle();
    }
    onPostInit(config, savedInstanceState);
    lockAttaching();
}
Also used : MockApplication(android.test.mock.MockApplication) TypedArray(android.content.res.TypedArray) SuperStartActivity(org.holoeverywhere.ThemeManager.SuperStartActivity) IAddonActivity(org.holoeverywhere.addon.IAddonActivity) ActionBarActivity(android.support.v7.app.ActionBarActivity) Activity(org.holoeverywhere.app.Activity) Application(org.holoeverywhere.app.Application) MockApplication(android.test.mock.MockApplication) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 2 with Application

use of org.holoeverywhere.app.Application in project little-bear-dictionary by daimajia.

the class ThemeManager method restartWithTheme.

/**
     * Like {@link #restartWithTheme(Activity, int)}, but if third arg is true -
     * restart activity regardless theme.
     * 
     * @param activity Activity
     * @param theme Theme flags for check
     * @param force Force restart activity
     */
public static void restartWithTheme(Activity activity, int theme, boolean force) {
    if (theme < _START_RESOURCES_ID) {
        if (ThemeManager._THEME_MODIFIER > 0) {
            theme |= ThemeManager._THEME_MODIFIER;
        }
        theme &= ThemeManager._THEME_MASK;
    }
    if (force || ThemeManager.getTheme(activity) != theme) {
        Intent intent = activity.getIntent();
        intent.setClass(activity, activity.getClass());
        intent.putExtra(ThemeManager._THEME_TAG, theme);
        if (activity.isRestricted()) {
            Application app = Application.getLastInstance();
            if (app != null && !app.isRestricted()) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                app.superStartActivity(intent, -1, null);
            }
        } else {
            if (!activity.isFinishing()) {
                activity.finish();
            }
            if (activity instanceof SuperStartActivity) {
                ((SuperStartActivity) activity).superStartActivity(intent, -1, null);
            } else {
                activity.startActivity(intent);
            }
        }
    }
}
Also used : Intent(android.content.Intent) Application(org.holoeverywhere.app.Application)

Example 3 with Application

use of org.holoeverywhere.app.Application in project HoloEverywhere by Prototik.

the class ThemeManager method restartWithTheme.

/**
     * Like {@link #restartWithTheme(Activity, int)}, but if third arg is true -
     * restart activity regardless theme.
     *
     * @param activity Activity
     * @param theme    Theme flags for check
     * @param force    Force restart activity
     */
@SuppressLint("InlinedApi")
public static void restartWithTheme(Activity activity, int theme, boolean force) {
    if (theme < _START_RESOURCES_ID && theme > 0) {
        if (ThemeManager._THEME_MODIFIER > 0) {
            theme |= ThemeManager._THEME_MODIFIER;
        }
        theme &= ThemeManager._THEME_MASK;
    }
    if (force || ThemeManager.getTheme(activity) != theme) {
        Intent intent = new Intent(activity.getIntent());
        intent.setClass(activity, activity.getClass());
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        if (theme > 0) {
            intent.putExtra(ThemeManager._THEME_TAG, theme);
        }
        intent.putExtra(KEY_INSTANCE_STATE, activity.saveInstanceState());
        intent.putExtra(KEY_CREATED_BY_THEME_MANAGER, true);
        if (activity.isRestricted()) {
            Application app = Application.getLastInstance();
            if (app != null && !app.isRestricted()) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                app.superStartActivity(intent, -1, null);
            }
        } else {
            if (!activity.isFinishing()) {
                activity.finish();
                activity.overridePendingTransition(0, 0);
            }
            if (activity != null) {
                activity.superStartActivity(intent, -1, null);
            }
        }
    }
}
Also used : Intent(android.content.Intent) Application(org.holoeverywhere.app.Application) SuppressLint(android.annotation.SuppressLint)

Aggregations

Application (org.holoeverywhere.app.Application)3 Intent (android.content.Intent)2 SuppressLint (android.annotation.SuppressLint)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 TypedArray (android.content.res.TypedArray)1 ActionBarActivity (android.support.v7.app.ActionBarActivity)1 MockApplication (android.test.mock.MockApplication)1 SuperStartActivity (org.holoeverywhere.ThemeManager.SuperStartActivity)1 IAddonActivity (org.holoeverywhere.addon.IAddonActivity)1 Activity (org.holoeverywhere.app.Activity)1