コード例 #1
0
    @Override
    public void run() {
      if (DEBUG_ATLAS) Log.d(LOG_TAG, "Running " + Thread.currentThread().getName());

      Atlas.Entry entry = new Atlas.Entry();
      for (Atlas.Type type : Atlas.Type.values()) {
        for (int width = mEnd; width > mStart; width -= mStep) {
          for (int height = MAX_SIZE; height > MIN_SIZE; height -= STEP) {
            // If the atlas is not big enough, skip it
            if (width * height <= mThreshold) continue;

            final int count = packBitmaps(type, width, height, entry);
            if (count > 0) {
              mResults.add(new WorkerResult(type, width, height, count));
              // If we were able to pack everything let's stop here
              // Increasing the height further won't make things better
              if (count == mBitmaps.size()) {
                break;
              }
            }
          }
        }
      }

      if (mSignal != null) {
        mSignal.countDown();
      }
    }
コード例 #2
0
  /**
   * Reads an atlas configuration from the specified file. This method returns null if an error
   * occurs or if the configuration is invalid.
   */
  private Configuration readConfiguration(File file, String versionName) {
    BufferedReader reader = null;
    Configuration config = null;
    try {
      reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

      if (checkBuildIdentifier(reader, versionName)) {
        Atlas.Type type = Atlas.Type.valueOf(reader.readLine());
        int width = readInt(reader, MIN_SIZE, MAX_SIZE);
        int height = readInt(reader, MIN_SIZE, MAX_SIZE);
        int count = readInt(reader, 0, Integer.MAX_VALUE);
        int flags = readInt(reader, Integer.MIN_VALUE, Integer.MAX_VALUE);

        config = new Configuration(type, width, height, count, flags);
      }
    } catch (IllegalArgumentException e) {
      Log.w(LOG_TAG, "Invalid parameter value in " + file, e);
    } catch (FileNotFoundException e) {
      Log.w(LOG_TAG, "Could not read " + file, e);
    } catch (IOException e) {
      Log.w(LOG_TAG, "Could not read " + file, e);
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          // Ignore
        }
      }
    }
    return config;
  }
コード例 #3
0
 @Override
 public String toString() {
   return type.toString()
       + " ("
       + width
       + "x"
       + height
       + ") flags=0x"
       + Integer.toHexString(flags)
       + " count="
       + count;
 }
コード例 #4
0
 @Override
 public String toString() {
   return String.format("%s %dx%d", type.toString(), width, height);
 }