private void onInit() {
    String excludedLanguages = Settings.getExcludedLanguages();
    if (null == excludedLanguages) {
      return;
    }

    String[] languages = excludedLanguages.split("x");

    int iLength = languages.length;
    int jLength = LANGUAGES.length;
    for (int i = 0, j = 0; i < iLength; i++) {
      String language = languages[i];
      if (!isDecimal(language)) {
        continue;
      }

      for (; j < jLength; j++) {
        String pattern = LANGUAGES[j];
        if (pattern.equals(language)) {
          // Get it
          int row = (j + 1) / 3;
          int column = (j + 1) % 3;
          mSelections[row][column] = true;
          break;
        }
      }
    }
  }
  @Override
  public void onClick(View v) {
    if (null == mAdapter) {
      return;
    }

    if (v == mCancel) {
      finish();
    } else if (v == mOk) {
      StringBuilder sb = new StringBuilder();
      int i = -1;
      boolean first = true;
      for (boolean[] selections : mSelections) {
        for (boolean b : selections) {
          i++;
          if (i == 0) {
            continue;
          }
          if (b) {
            if (!first) {
              sb.append("x");
            } else {
              first = false;
            }
            sb.append(LANGUAGES[i - 1]);
          }
        }
      }

      String excludedLanguages = sb.toString();
      Settings.putExcludedLanguages(excludedLanguages);
      finish();
    } else if (v == mSelectAll) {
      for (boolean[] selections : mSelections) {
        int length = selections.length;
        for (int i = 0; i < length; i++) {
          selections[i] = true;
        }
      }
      mAdapter.notifyDataSetChanged();
    } else if (v == mDeselectAll) {
      for (boolean[] selections : mSelections) {
        int length = selections.length;
        for (int i = 0; i < length; i++) {
          selections[i] = false;
        }
      }
      mAdapter.notifyDataSetChanged();
    } else if (v == mInvertSelection) {
      for (boolean[] selections : mSelections) {
        int length = selections.length;
        for (int i = 0; i < length; i++) {
          selections[i] = !selections[i];
        }
      }
      mAdapter.notifyDataSetChanged();
    }
  }
Ejemplo n.º 3
0
  public static UniFile getGalleryDownloadDir(GalleryInfo galleryInfo) {
    UniFile dir = Settings.getDownloadLocation();
    if (dir != null) {
      // Read from DB
      String dirname = EhDB.getDownloadDirname(galleryInfo.gid);
      if (null != dirname) {
        // Some dirname may be invalid in some version
        dirname = FileUtils.sanitizeFilename(dirname);
        EhDB.putDownloadDirname(galleryInfo.gid, dirname);
      }

      // Find it
      if (null == dirname) {
        UniFile[] files = dir.listFiles(new StartWithFilenameFilter(galleryInfo.gid + "-"));
        if (null != files) {
          // Get max-length-name dir
          int maxLength = -1;
          for (UniFile file : files) {
            if (file.isDirectory()) {
              String name = file.getName();
              int length = name.length();
              if (length > maxLength) {
                maxLength = length;
                dirname = name;
              }
            }
          }
          if (null != dirname) {
            EhDB.putDownloadDirname(galleryInfo.gid, dirname);
          }
        }
      }

      // Create it
      if (null == dirname) {
        dirname =
            FileUtils.sanitizeFilename(
                galleryInfo.gid + "-" + EhUtils.getSuitableTitle(galleryInfo));
        EhDB.putDownloadDirname(galleryInfo.gid, dirname);
      }

      return dir.subFile(dirname);
    } else {
      return null;
    }
  }
Ejemplo n.º 4
0
 public static void initialize(Context context) {
   sCache =
       new SimpleDiskCache(
           new File(context.getCacheDir(), "image"),
           MathUtils.clamp(Settings.getReadCacheSize(), 40, 640) * 1024 * 1024);
 }