Search in sources :

Example 11 with MergedManifest

use of com.android.tools.idea.model.MergedManifest in project android by JetBrains.

the class LaunchUtils method isWatchFaceApp.

/**
   * Returns whether the given module corresponds to a watch face app.
   * A module is considered to be a watch face app if there are no activities, and a single service with
   * a specific intent filter. This definition is likely stricter than it needs to be to but we are only
   * interested in matching the watch face template application.
   */
public static boolean isWatchFaceApp(@NotNull AndroidFacet facet) {
    if (AndroidFacet.getInstance(facet.getModule()) == null) {
        Logger.getInstance(LaunchUtils.class).warn("calling isWatchFaceApp when facet is not ready yet");
        return false;
    }
    MergedManifest info = MergedManifest.get(facet);
    if (!info.getActivities().isEmpty()) {
        return false;
    }
    final List<Element> services = info.getServices();
    if (services.size() != 1) {
        return false;
    }
    Element service = services.get(0);
    List<Element> filters = LintUtils.getChildren(service);
    return filters.size() == 1 && ActivityLocatorUtils.containsAction(filters.get(0), AndroidUtils.WALLPAPER_SERVICE_ACTION_NAME) && ActivityLocatorUtils.containsCategory(filters.get(0), AndroidUtils.WATCHFACE_CATEGORY_NAME);
}
Also used : MergedManifest(com.android.tools.idea.model.MergedManifest) Element(org.w3c.dom.Element)

Example 12 with MergedManifest

use of com.android.tools.idea.model.MergedManifest in project android by JetBrains.

the class ConfigurationManager method computePreferredTheme.

/**
   * Returns the preferred theme
   */
@NotNull
public String computePreferredTheme(@NotNull Configuration configuration) {
    MergedManifest manifest = MergedManifest.get(myModule);
    // TODO: If we are rendering a layout in included context, pick the theme
    // from the outer layout instead
    String activity = configuration.getActivity();
    if (activity != null) {
        String activityFqcn = activity;
        if (activity.startsWith(".")) {
            String pkg = StringUtil.notNullize(manifest.getPackage());
            activityFqcn = pkg + activity;
        }
        ActivityAttributes attributes = manifest.getActivityAttributes(activityFqcn);
        if (attributes != null) {
            String theme = attributes.getTheme();
            // Check that the theme looks like a reference
            if (theme != null && theme.startsWith(SdkConstants.PREFIX_RESOURCE_REF)) {
                return theme;
            }
        }
        // Try with the package name from the manifest.
        attributes = manifest.getActivityAttributes(activity);
        if (attributes != null) {
            String theme = attributes.getTheme();
            // Check that the theme looks like a reference
            if (theme != null && theme.startsWith(SdkConstants.PREFIX_RESOURCE_REF)) {
                return theme;
            }
        }
    }
    // in the manifest)
    return manifest.getDefaultTheme(configuration.getTarget(), configuration.getScreenSize(), configuration.getDevice());
}
Also used : MergedManifest(com.android.tools.idea.model.MergedManifest) ActivityAttributes(com.android.tools.idea.model.MergedManifest.ActivityAttributes) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with MergedManifest

use of com.android.tools.idea.model.MergedManifest in project android by JetBrains.

the class ManifestConflictTest method getErrorHtml.

private String[] getErrorHtml() {
    MergedManifest manifest = MergedManifest.get(myAndroidFacet);
    manifest.clear();
    ImmutableList<MergingReport.Record> records = manifest.getLoggingRecords();
    String[] errors = new String[records.size()];
    for (int c = 0; c < records.size(); c++) {
        MergingReport.Record record = records.get(c);
        errors[c] = ManifestPanel.getErrorHtml(myAndroidFacet, record.getMessage(), record.getSourceLocation(), myHtmlLinkManager, null);
    }
    return errors;
}
Also used : MergingReport(com.android.manifmerger.MergingReport) MergedManifest(com.android.tools.idea.model.MergedManifest)

Example 14 with MergedManifest

use of com.android.tools.idea.model.MergedManifest in project android by JetBrains.

the class NlProperties method currentActivityIfFoundIsDerivedFromAppCompatActivity.

private static boolean currentActivityIfFoundIsDerivedFromAppCompatActivity(@NotNull List<NlComponent> components) {
    assert !components.isEmpty();
    NlModel model = components.get(0).getModel();
    Configuration configuration = model.getConfiguration();
    String activityClassName = configuration.getActivity();
    if (activityClassName == null) {
        // Assume we are since this is how the default activities are created.
        return true;
    }
    if (activityClassName.startsWith(".")) {
        MergedManifest manifest = MergedManifest.get(model.getModule());
        String pkg = StringUtil.notNullize(manifest.getPackage());
        activityClassName = pkg + activityClassName;
    }
    JavaPsiFacade facade = JavaPsiFacade.getInstance(model.getProject());
    PsiClass activityClass = facade.findClass(activityClassName, model.getModule().getModuleScope());
    while (activityClass != null && !CLASS_APP_COMPAT_ACTIVITY.equals(activityClass.getQualifiedName())) {
        activityClass = activityClass.getSuperClass();
    }
    return activityClass != null;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Configuration(com.android.tools.idea.configurations.Configuration) MergedManifest(com.android.tools.idea.model.MergedManifest) PsiClass(com.intellij.psi.PsiClass) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Aggregations

MergedManifest (com.android.tools.idea.model.MergedManifest)14 NotNull (org.jetbrains.annotations.NotNull)5 Module (com.intellij.openapi.module.Module)4 Nullable (org.jetbrains.annotations.Nullable)3 Element (org.w3c.dom.Element)3 ResourceResolver (com.android.ide.common.resources.ResourceResolver)2 Configuration (com.android.tools.idea.configurations.Configuration)2 ActivityAttributes (com.android.tools.idea.model.MergedManifest.ActivityAttributes)2 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)2 PsiClass (com.intellij.psi.PsiClass)2 IOException (java.io.IOException)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 SourceFile (com.android.ide.common.blame.SourceFile)1 SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)1 SourcePosition (com.android.ide.common.blame.SourcePosition)1 LayoutDirectionQualifier (com.android.ide.common.resources.configuration.LayoutDirectionQualifier)1 Actions (com.android.manifmerger.Actions)1 MergingReport (com.android.manifmerger.MergingReport)1 XmlNode (com.android.manifmerger.XmlNode)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1