Exemplo n.º 1
0
  @SuppressLint("InlinedApi")
  public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CHOOSE_IMAGE_RESULT_ID && data != null && data.getData() != null) {
      Uri uri = data.getData();
      log.info("Image picked: %s", uri);

      // If we can query for with/height, that can save us loading the image twice. Not
      // all content providers support it, though.
      int width = 0;
      int height = 0;
      Cursor cursor = null;
      try {
        cursor =
            mActivity
                .getContentResolver()
                .query(
                    uri,
                    new String[] {MediaStore.MediaColumns.WIDTH, MediaStore.MediaColumns.HEIGHT},
                    null,
                    null,
                    null);
        if (cursor.moveToFirst()) {
          width = cursor.getInt(0);
          height = cursor.getInt(1);
          log.info("Got image size: %dx%d", width, height);
        }
      } catch (Exception e) {
        // There can be various exceptions, all of which result in us ignoring width/height.
        log.info("Could not get image size: %s", e.getMessage());
        width = height = 0;
      } finally {
        if (cursor != null) {
          cursor.close();
        }
      }

      try {
        mImageHelper =
            new ImageHelper(mActivity.getContentResolver().openInputStream(uri), width, height);
      } catch (FileNotFoundException e) {
      }

      return true;
    }
    return false;
  }
Exemplo n.º 2
0
  private static void ensureFilter() {
    if (!sProfaneWords.isEmpty()) {
      return;
    }

    String sql = "SELECT * FROM chat_profane_words";
    try (SqlStmt stmt = DB.prepare(sql)) {
      SqlResult res = stmt.select();
      while (res.next()) {
        int profanityLevel = res.getInt("profanity_level");
        String words = res.getString("words");

        for (String word : words.split("\\s+")) {
          sProfaneWords.put(word.trim().toLowerCase(), profanityLevel);
        }
      }
    } catch (Exception e) {
      log.error("Error fetching profane words list.", e);
    }
  }