Search in sources :

Example 31 with Application

use of android.app.Application in project android_frameworks_base by ParanoidAndroid.

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 32 with Application

use of android.app.Application in project Anki-Android by Ramblurr.

the class Connection method doInBackgroundSendFeedback.

private Payload doInBackgroundSendFeedback(Payload data) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundSendFeedback");
    String feedbackUrl = (String) data.data[0];
    String errorUrl = (String) data.data[1];
    String feedback = (String) data.data[2];
    ArrayList<HashMap<String, String>> errors = (ArrayList<HashMap<String, String>>) data.data[3];
    String groupId = ((Long) data.data[4]).toString();
    Application app = (Application) data.data[5];
    boolean deleteAfterSending = (Boolean) data.data[6];
    String postType = null;
    if (feedback.length() > 0) {
        if (errors.size() > 0) {
            postType = Feedback.TYPE_ERROR_FEEDBACK;
        } else {
            postType = Feedback.TYPE_FEEDBACK;
        }
        publishProgress(postType, 0, Feedback.STATE_UPLOADING);
        Payload reply = Feedback.postFeedback(feedbackUrl, postType, feedback, groupId, 0, null);
        if (reply.success) {
            publishProgress(postType, 0, Feedback.STATE_SUCCESSFUL, reply.returnType, reply.result);
        } else {
            publishProgress(postType, 0, Feedback.STATE_FAILED, reply.returnType, reply.result);
        }
    }
    for (int i = 0; i < errors.size(); i++) {
        HashMap<String, String> error = errors.get(i);
        if (error.containsKey("state") && error.get("state").equals(Feedback.STATE_WAITING)) {
            postType = Feedback.TYPE_STACKTRACE;
            publishProgress(postType, i, Feedback.STATE_UPLOADING);
            Payload reply = Feedback.postFeedback(errorUrl, postType, error.get("filename"), groupId, i, app);
            if (reply.success) {
                publishProgress(postType, i, Feedback.STATE_SUCCESSFUL, reply.returnType, reply.result);
            } else {
                publishProgress(postType, i, Feedback.STATE_FAILED, reply.returnType, reply.result);
            }
            if (deleteAfterSending && (reply.success || reply.returnType == 200)) {
                File file = new File(app.getFilesDir() + "/" + error.get("filename"));
                file.delete();
            }
        }
    }
    app = null;
    return data;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Application(android.app.Application) File(java.io.File)

Example 33 with Application

use of android.app.Application in project scdl by passy.

the class TestHelper method overridenInjector.

public static void overridenInjector(Object instance, AbstractModule module) {
    final Application app = Robolectric.application;
    // Allow overriding of integrated classes like Activity
    Module moduleOverride = Modules.override(RoboGuice.newDefaultRoboModule(app)).with(module);
    // Also allow overriding custom bindings like URLWrapper
    moduleOverride = Modules.override(new SCDLModule()).with(moduleOverride);
    RoboGuice.setBaseApplicationInjector(app, RoboGuice.DEFAULT_STAGE, moduleOverride);
    final Injector injector = TestHelper.getInjector();
    injector.injectMembers(instance);
}
Also used : SCDLModule(net.rdrei.android.scdl2.guice.SCDLModule) Injector(com.google.inject.Injector) Module(com.google.inject.Module) SCDLModule(net.rdrei.android.scdl2.guice.SCDLModule) AbstractModule(com.google.inject.AbstractModule) Application(android.app.Application)

Example 34 with Application

use of android.app.Application in project android_frameworks_base by ResurrectionRemix.

the class WebViewFactory method getWebViewContextAndSetProvider.

private static Context getWebViewContextAndSetProvider() {
    Application initialApplication = AppGlobals.getInitialApplication();
    try {
        WebViewProviderResponse response = null;
        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewUpdateService.waitForAndGetProvider()");
        try {
            response = getUpdateService().waitForAndGetProvider();
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
        }
        if (response.status != LIBLOAD_SUCCESS && response.status != LIBLOAD_FAILED_WAITING_FOR_RELRO) {
            throw new MissingWebViewPackageException("Failed to load WebView provider: " + getWebViewPreparationErrorReason(response.status));
        }
        // Register to be killed before fetching package info - so that we will be
        // killed if the package info goes out-of-date.
        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "ActivityManager.addPackageDependency()");
        try {
            ActivityManagerNative.getDefault().addPackageDependency(response.packageInfo.packageName);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
        }
        // Fetch package info and verify it against the chosen package
        PackageInfo newPackageInfo = null;
        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "PackageManager.getPackageInfo()");
        try {
            newPackageInfo = initialApplication.getPackageManager().getPackageInfo(response.packageInfo.packageName, PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.MATCH_DEBUG_TRIAGED_MISSING | // installed for the current user
            PackageManager.MATCH_UNINSTALLED_PACKAGES | // Fetch signatures for verification
            PackageManager.GET_SIGNATURES | // Get meta-data for meta data flag verification
            PackageManager.GET_META_DATA);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
        }
        // Validate the newly fetched package info, throws MissingWebViewPackageException on
        // failure
        verifyPackageInfo(response.packageInfo, newPackageInfo);
        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "initialApplication.createApplicationContext");
        try {
            // Construct an app context to load the Java code into the current app.
            Context webViewContext = initialApplication.createApplicationContext(newPackageInfo.applicationInfo, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
            sPackageInfo = newPackageInfo;
            return webViewContext;
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
        }
    } catch (RemoteException | PackageManager.NameNotFoundException e) {
        throw new MissingWebViewPackageException("Failed to load WebView provider: " + e);
    }
}
Also used : Context(android.content.Context) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException) Application(android.app.Application)

Example 35 with Application

use of android.app.Application in project android_frameworks_base by ResurrectionRemix.

the class HtmlToSpannedConverter method withinParagraph.

private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
    int next;
    for (int i = start; i < end; i = next) {
        next = text.nextSpanTransition(i, end, CharacterStyle.class);
        CharacterStyle[] style = text.getSpans(i, next, CharacterStyle.class);
        for (int j = 0; j < style.length; j++) {
            if (style[j] instanceof StyleSpan) {
                int s = ((StyleSpan) style[j]).getStyle();
                if ((s & Typeface.BOLD) != 0) {
                    out.append("<b>");
                }
                if ((s & Typeface.ITALIC) != 0) {
                    out.append("<i>");
                }
            }
            if (style[j] instanceof TypefaceSpan) {
                String s = ((TypefaceSpan) style[j]).getFamily();
                if ("monospace".equals(s)) {
                    out.append("<tt>");
                }
            }
            if (style[j] instanceof SuperscriptSpan) {
                out.append("<sup>");
            }
            if (style[j] instanceof SubscriptSpan) {
                out.append("<sub>");
            }
            if (style[j] instanceof UnderlineSpan) {
                out.append("<u>");
            }
            if (style[j] instanceof StrikethroughSpan) {
                out.append("<span style=\"text-decoration:line-through;\">");
            }
            if (style[j] instanceof URLSpan) {
                out.append("<a href=\"");
                out.append(((URLSpan) style[j]).getURL());
                out.append("\">");
            }
            if (style[j] instanceof ImageSpan) {
                out.append("<img src=\"");
                out.append(((ImageSpan) style[j]).getSource());
                out.append("\">");
                // Don't output the dummy character underlying the image.
                i = next;
            }
            if (style[j] instanceof AbsoluteSizeSpan) {
                AbsoluteSizeSpan s = ((AbsoluteSizeSpan) style[j]);
                float sizeDip = s.getSize();
                if (!s.getDip()) {
                    Application application = ActivityThread.currentApplication();
                    sizeDip /= application.getResources().getDisplayMetrics().density;
                }
                // px in CSS is the equivalance of dip in Android
                out.append(String.format("<span style=\"font-size:%.0fpx\";>", sizeDip));
            }
            if (style[j] instanceof RelativeSizeSpan) {
                float sizeEm = ((RelativeSizeSpan) style[j]).getSizeChange();
                out.append(String.format("<span style=\"font-size:%.2fem;\">", sizeEm));
            }
            if (style[j] instanceof ForegroundColorSpan) {
                int color = ((ForegroundColorSpan) style[j]).getForegroundColor();
                out.append(String.format("<span style=\"color:#%06X;\">", 0xFFFFFF & color));
            }
            if (style[j] instanceof BackgroundColorSpan) {
                int color = ((BackgroundColorSpan) style[j]).getBackgroundColor();
                out.append(String.format("<span style=\"background-color:#%06X;\">", 0xFFFFFF & color));
            }
        }
        withinStyle(out, text, i, next);
        for (int j = style.length - 1; j >= 0; j--) {
            if (style[j] instanceof BackgroundColorSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof ForegroundColorSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof RelativeSizeSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof AbsoluteSizeSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof URLSpan) {
                out.append("</a>");
            }
            if (style[j] instanceof StrikethroughSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof UnderlineSpan) {
                out.append("</u>");
            }
            if (style[j] instanceof SubscriptSpan) {
                out.append("</sub>");
            }
            if (style[j] instanceof SuperscriptSpan) {
                out.append("</sup>");
            }
            if (style[j] instanceof TypefaceSpan) {
                String s = ((TypefaceSpan) style[j]).getFamily();
                if (s.equals("monospace")) {
                    out.append("</tt>");
                }
            }
            if (style[j] instanceof StyleSpan) {
                int s = ((StyleSpan) style[j]).getStyle();
                if ((s & Typeface.BOLD) != 0) {
                    out.append("</b>");
                }
                if ((s & Typeface.ITALIC) != 0) {
                    out.append("</i>");
                }
            }
        }
    }
}
Also used : SuperscriptSpan(android.text.style.SuperscriptSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) URLSpan(android.text.style.URLSpan) CharacterStyle(android.text.style.CharacterStyle) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) StyleSpan(android.text.style.StyleSpan) SubscriptSpan(android.text.style.SubscriptSpan) Application(android.app.Application) BackgroundColorSpan(android.text.style.BackgroundColorSpan) TypefaceSpan(android.text.style.TypefaceSpan) StrikethroughSpan(android.text.style.StrikethroughSpan) ImageSpan(android.text.style.ImageSpan)

Aggregations

Application (android.app.Application)125 Test (org.junit.Test)27 Context (android.content.Context)24 Activity (android.app.Activity)23 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 ShadowApplication (org.robolectric.shadows.ShadowApplication)8 MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 PrintWriter (java.io.PrintWriter)6 Date (java.util.Date)6 SuppressLint (android.annotation.SuppressLint)5 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 RemoteException (android.os.RemoteException)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 AndroidRuntimeException (android.util.AndroidRuntimeException)5