示例#1
0
  /** Determine whether this configuration has a better match in a different layout file */
  private void updateForkStatus() {
    ConfigurationChooser chooser = mManager.getChooser();
    FolderConfiguration config = mConfiguration.getFullConfig();
    if (mAlternateInput != null && chooser.isBestMatchFor(mAlternateInput, config)) {
      return;
    }

    mAlternateInput = null;
    IFile editedFile = chooser.getEditedFile();
    if (editedFile != null) {
      if (!chooser.isBestMatchFor(editedFile, config)) {
        ProjectResources resources = chooser.getResources();
        if (resources != null) {
          ResourceFile best =
              resources.getMatchingFile(editedFile.getName(), ResourceType.LAYOUT, config);
          if (best != null) {
            IAbstractFile file = best.getFile();
            if (file instanceof IFileWrapper) {
              mAlternateInput = ((IFileWrapper) file).getIFile();
            } else if (file instanceof File) {
              mAlternateInput = AdtUtils.fileToIFile(((File) file));
            }
          }
        }
        if (mAlternateInput != null) {
          mAlternateConfiguration = Configuration.create(mConfiguration, mAlternateInput);
        }
      }
    }
  }
示例#2
0
  private ResourceResolver getResourceResolver(Configuration configuration) {
    ResourceResolver resourceResolver = mResourceResolver.get();
    if (resourceResolver != null) {
      return resourceResolver;
    }

    GraphicalEditorPart graphicalEditor = mCanvas.getEditorDelegate().getGraphicalEditor();
    String theme = configuration.getTheme();
    if (theme == null) {
      return null;
    }

    Map<ResourceType, Map<String, ResourceValue>> configuredFrameworkRes = null;
    Map<ResourceType, Map<String, ResourceValue>> configuredProjectRes = null;

    FolderConfiguration config = configuration.getFullConfig();
    IAndroidTarget target = graphicalEditor.getRenderingTarget();
    ResourceRepository frameworkRes = null;
    if (target != null) {
      Sdk sdk = Sdk.getCurrent();
      if (sdk == null) {
        return null;
      }
      AndroidTargetData data = sdk.getTargetData(target);

      if (data != null) {
        // TODO: SHARE if possible
        frameworkRes = data.getFrameworkResources();
        configuredFrameworkRes = frameworkRes.getConfiguredResources(config);
      } else {
        return null;
      }
    } else {
      return null;
    }
    assert configuredFrameworkRes != null;

    // get the resources of the file's project.
    ProjectResources projectRes =
        ResourceManager.getInstance().getProjectResources(graphicalEditor.getProject());
    configuredProjectRes = projectRes.getConfiguredResources(config);

    if (!theme.startsWith(PREFIX_RESOURCE_REF)) {
      if (frameworkRes.hasResourceItem(ANDROID_STYLE_RESOURCE_PREFIX + theme)) {
        theme = ANDROID_STYLE_RESOURCE_PREFIX + theme;
      } else {
        theme = STYLE_RESOURCE_PREFIX + theme;
      }
    }

    resourceResolver =
        ResourceResolver.create(
            configuredProjectRes,
            configuredFrameworkRes,
            ResourceHelper.styleToTheme(theme),
            ResourceHelper.isProjectStyle(theme));
    mResourceResolver = new SoftReference<ResourceResolver>(resourceResolver);
    return resourceResolver;
  }
  @Override
  public Integer getResourceId(ResourceType type, String name) {
    if (mProjectRes != null) {
      return mProjectRes.getResourceId(type, name);
    }

    return null;
  }
  @Override
  public String resolveResourceId(int[] id) {
    if (mProjectRes != null) {
      return mProjectRes.resolveStyleable(id);
    }

    return null;
  }
  @Override
  public Pair<ResourceType, String> resolveResourceId(int id) {
    if (mProjectRes != null) {
      return mProjectRes.resolveResourceId(id);
    }

    return null;
  }