Search in sources :

Example 21 with Application

use of android.app.Application in project freeline by alibaba.

the class FreelineApplication method createRealApplication.

private void createRealApplication() {
    String applicationClass = getConfigValue("applicationClass");
    if (TextUtils.isEmpty(applicationClass)) {
        realApplication = new Application();
        Log.d(TAG, "create empty application.");
    } else {
        try {
            Class realClass = Class.forName(applicationClass);
            Constructor<? extends Application> constructor = realClass.getConstructor();
            this.realApplication = constructor.newInstance();
            Log.d(TAG, "create application: " + applicationClass);
        } catch (Exception e) {
            FreelineCore.printStackTrace(e);
            Log.e(TAG, "create real application error");
        }
    }
}
Also used : Application(android.app.Application)

Example 22 with Application

use of android.app.Application in project platform_frameworks_base by android.

the class FalsingLog method wtf.

public static synchronized void wtf(String tag, String s) {
    if (!ENABLED) {
        return;
    }
    e(tag, s);
    Application application = ActivityThread.currentApplication();
    String fileMessage = "";
    if (Build.IS_DEBUGGABLE && application != null) {
        File f = new File(application.getDataDir(), "falsing-" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".txt");
        PrintWriter pw = null;
        try {
            pw = new PrintWriter(f);
            dump(pw);
            pw.close();
            fileMessage = "Log written to " + f.getAbsolutePath();
        } catch (IOException e) {
            Log.e(TAG, "Unable to write falsing log", e);
        } finally {
            if (pw != null) {
                pw.close();
            }
        }
    } else {
        Log.e(TAG, "Unable to write log, build must be debuggable.");
    }
    Log.wtf(TAG, tag + " " + s + "; " + fileMessage);
}
Also used : IOException(java.io.IOException) Application(android.app.Application) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 23 with Application

use of android.app.Application in project platform_frameworks_base by android.

the class DpiTestActivity method init.

public void init(boolean noCompat) {
    try {
        // This is all a dirty hack.  Don't think a real application should
        // be doing it.
        Application app = ActivityThread.currentActivityThread().getApplication();
        ApplicationInfo ai = app.getPackageManager().getApplicationInfo("com.google.android.test.dpi", 0);
        if (noCompat) {
            ai.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS | ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
            app.getResources().setCompatibilityInfo(new CompatibilityInfo(ai, getResources().getConfiguration().screenLayout, getResources().getConfiguration().smallestScreenWidthDp, false));
        }
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("ouch", e);
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) Application(android.app.Application)

Example 24 with Application

use of android.app.Application in project platform_packages_apps_launcher by android.

the class Launcher method registerIntentReceivers.

/**
     * Registers various intent receivers. The current implementation registers
     * only a wallpaper intent receiver to let other applications change the
     * wallpaper.
     */
private void registerIntentReceivers() {
    if (sWallpaperReceiver == null) {
        final Application application = getApplication();
        sWallpaperReceiver = new WallpaperIntentReceiver(application, this);
        IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
        application.registerReceiver(sWallpaperReceiver, filter);
    } else {
        sWallpaperReceiver.setLauncher(this);
    }
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    registerReceiver(mApplicationsReceiver, filter);
}
Also used : IntentFilter(android.content.IntentFilter) Application(android.app.Application)

Example 25 with Application

use of android.app.Application in project freeline by alibaba.

the class GradleDynamic method applyDynamicRes.

@Override
public boolean applyDynamicRes(HashMap<String, String> dynamicRes) {
    String dynamicResPath = dynamicRes.get(FreelineCore.DEFAULT_PACKAGE_ID);
    Log.i(TAG, "dynamicResPath: " + dynamicResPath);
    if (!TextUtils.isEmpty(dynamicResPath)) {
        Application realApplication = FreelineCore.getRealApplication();
        MonkeyPatcher.monkeyPatchApplication(app, app, realApplication, dynamicResPath);
        MonkeyPatcher.monkeyPatchExistingResources(app, dynamicResPath, Arrays.asList(ActivityManager.getAllActivities()));
        Log.i(TAG, "GradleDynamic apply dynamic resource successfully");
    }
    return true;
}
Also used : Application(android.app.Application)

Aggregations

Application (android.app.Application)123 Test (org.junit.Test)26 Context (android.content.Context)24 Activity (android.app.Activity)22 ApplicationInfo (android.content.pm.ApplicationInfo)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 File (java.io.File)10 MvpPresenter (com.hannesdorfmann.mosby3.mvp.MvpPresenter)8 Before (org.junit.Before)8 MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)7 ShadowApplication (org.robolectric.shadows.ShadowApplication)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 PrintWriter (java.io.PrintWriter)6 Date (java.util.Date)6 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 RemoteException (android.os.RemoteException)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 BackgroundColorSpan (android.text.style.BackgroundColorSpan)5 CharacterStyle (android.text.style.CharacterStyle)5