Exemplo n.º 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);
        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Notifies that the preview's configuration has changed.
   *
   * @param flags the change flags, a bitmask corresponding to the {@code CHANGE_} constants in
   *     {@link ConfigurationClient}
   */
  public void configurationChanged(int flags) {
    if (!mVisible) {
      mDirty |= flags;
      return;
    }

    if ((flags & MASK_RENDERING) != 0) {
      mResourceResolver.clear();
      // Handle inheritance
      mConfiguration.syncFolderConfig();
      updateForkStatus();
      updateSize();
    }

    // Sanity check to make sure things are working correctly
    if (DEBUG) {
      RenderPreviewMode mode = mManager.getMode();
      if (mode == DEFAULT) {
        assert mConfiguration instanceof VaryingConfiguration;
        VaryingConfiguration config = (VaryingConfiguration) mConfiguration;
        int alternateFlags = config.getAlternateFlags();
        switch (alternateFlags) {
          case Configuration.CFG_DEVICE_STATE:
            {
              State configState = config.getDeviceState();
              State chooserState = mManager.getChooser().getConfiguration().getDeviceState();
              assert configState != null && chooserState != null;
              assert !configState.getName().equals(chooserState.getName())
                  : configState.toString() + ':' + chooserState;

              Device configDevice = config.getDevice();
              Device chooserDevice = mManager.getChooser().getConfiguration().getDevice();
              assert configDevice != null && chooserDevice != null;
              assert configDevice == chooserDevice : configDevice.toString() + ':' + chooserDevice;

              break;
            }
          case Configuration.CFG_DEVICE:
            {
              Device configDevice = config.getDevice();
              Device chooserDevice = mManager.getChooser().getConfiguration().getDevice();
              assert configDevice != null && chooserDevice != null;
              assert configDevice != chooserDevice : configDevice.toString() + ':' + chooserDevice;

              State configState = config.getDeviceState();
              State chooserState = mManager.getChooser().getConfiguration().getDeviceState();
              assert configState != null && chooserState != null;
              assert configState.getName().equals(chooserState.getName())
                  : configState.toString() + ':' + chooserState;

              break;
            }
          case Configuration.CFG_LOCALE:
            {
              Locale configLocale = config.getLocale();
              Locale chooserLocale = mManager.getChooser().getConfiguration().getLocale();
              assert configLocale != null && chooserLocale != null;
              assert configLocale != chooserLocale : configLocale.toString() + ':' + chooserLocale;
              break;
            }
          default:
            {
              // Some other type of override I didn't anticipate
              assert false : alternateFlags;
            }
        }
      }
    }

    mDirty = 0;
    mManager.scheduleRender(this);
  }