Example #1
0
 @Override
 protected void onNewIntent(Intent intent) {
   super.onNewIntent(intent);
   if (intent.getAction() == null) {
     return;
   } else if (intent.getAction().equals("co.wakarimasen.chanexplorer.ACTION_VIEW")) {
     Board b = Board.getBoardById(intent.getStringExtra("Board"));
     int threadId = intent.getIntExtra("Thread", -1);
     int postId = intent.getIntExtra("Post", -1);
     getHomeFragment().selectOrAddThread(b, threadId, postId);
   } else if (intent.getAction().equals("co.wakarimasen.chanexplorer.FIX_POST")) {
     Board b = Board.getBoardById(intent.getStringExtra("Board"));
     int threadId = intent.getIntExtra("Thread", -1);
     NewPost np = intent.getParcelableExtra("NewPostInfo");
     getHomeFragment().selectOrAddThread(b, threadId, -1);
     ChanPage cp = getHomeFragment().getCurrentChanPage();
     mNewPostView.setNewPost(cp.getBoard(), cp.getThreadId(), np);
     cp.setNewPost(np);
     mNewPostView.refreshCaptcha();
     getSlidingMenu().showContent();
   } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
     Uri data = getIntent().getData();
     if (data == null) {
       return;
     }
     String host = data.getHost(); // "twitter.com"
     if (host.equals("boards.4chan.org")) {
       List<String> params = data.getPathSegments();
       if (params.size() == 1) {
         Board b = Board.getBoardById(params.get(0));
         if (b != null) {
           getHomeFragment().selectOrAddThread(b, -1, -1);
         }
       }
       if (params.size() == 3) {
         Board b = Board.getBoardById(params.get(0));
         if (b != null) {
           int threadId = Integer.parseInt(params.get(2));
           int postId = -1;
           if (data.getFragment() != null) {
             postId = Integer.parseInt(data.getFragment());
           }
           getHomeFragment().selectOrAddThread(b, threadId, postId);
         }
       }
     }
   }
 }
  /**
   * Handles the redirect response from the social login flow
   *
   * @param intent the new received intent
   */
  private void handleSocialResult(Intent intent) {
    Uri data = intent.getData();
    if (data != null && data.getScheme().equals(DEEPLINK_SCHEME)) {
      // coming from a social redirect
      String fragment = data.getFragment();
      if (fragment == null) {
        Log.e(TAG, "Missing response data.");
        sendBackResult(null);
        return;
      }

      int tokenStart = fragment.indexOf(HASH_ACCESS_TOKEN) + HASH_ACCESS_TOKEN.length();
      int tokenEnd = fragment.indexOf("&", tokenStart);
      if (tokenEnd == -1) {
        tokenEnd = fragment.length();
      }
      String resultToken = fragment.substring(tokenStart, tokenEnd);
      int stateStart = fragment.indexOf(HASH_STATE) + HASH_STATE.length();
      int stateEnd = fragment.indexOf("&", stateStart);
      if (stateEnd == -1) {
        stateEnd = fragment.length();
      }
      String resultState = fragment.substring(stateStart, stateEnd);
      String lastState = getLastState();
      boolean stateIsOK = lastState.equals(resultState);
      Log.d(
          TAG,
          String.format("Social login result: %s, %s, %b", resultToken, resultState, stateIsOK));
      sendBackResult(resultToken);
    }
  }
  @Override
  protected void processImport() throws SudokuInvalidFormatException {
    try {
      InputStreamReader streamReader;
      if (mUri.getScheme().equals("content")) {
        ContentResolver contentResolver = mContext.getContentResolver();
        streamReader = new InputStreamReader(contentResolver.openInputStream(mUri));
      } else {
        java.net.URI juri;
        juri = new java.net.URI(mUri.getScheme(), mUri.getSchemeSpecificPart(), mUri.getFragment());
        streamReader = new InputStreamReader(juri.toURL().openStream());
      }

      try {
        importXml(streamReader);
      } finally {
        streamReader.close();
      }
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }
  }
  private void fillData(@Nullable Intent intent, @NonNull TextView textView) {
    Uri data = intent == null ? null : intent.getData();
    if (data == null) {
      textView.setText(Printer.EMPTY);
      return;
    }

    Truss truss = new Truss();
    Printer.append(truss, "raw", data);
    Printer.append(truss, "scheme", data.getScheme());
    Printer.append(truss, "host", data.getHost());
    Printer.append(truss, "port", data.getPort());
    Printer.append(truss, "path", data.getPath());
    Printer.appendKey(truss, "query");
    boolean query = false;
    if (data.isHierarchical()) {
      for (String queryParameterName : data.getQueryParameterNames()) {
        Printer.appendSecondary(
            truss, queryParameterName, data.getQueryParameter(queryParameterName));
        query = true;
      }
    }
    if (!query) {
      Printer.appendValue(truss, null);
    }
    Printer.append(truss, "fragment", data.getFragment());
    textView.setText(truss.build());
  }
  /** Put path information into data block */
  private void setPathData(JSONObject dataObject, Uri originalUri) throws JSONException {
    dataObject.put(JSDataKeys.HASH, originalUri.getFragment());
    dataObject.put(JSDataKeys.PATH, originalUri.getPath());

    final JSONObject queryParams = getQueryParamsFromUri(originalUri);
    dataObject.put(JSDataKeys.PARAMS, queryParams);
  }
Example #6
0
 @Override
 protected void onNewIntent(Intent intent) {
   final Uri data = intent.getData();
   final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance();
   if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
     super.onNewIntent(intent);
   } else if (Intent.ACTION_VIEW.equals(intent.getAction())
       && data != null
       && "fbreader-action".equals(data.getScheme())) {
     fbReader.runAction(data.getEncodedSchemeSpecificPart(), data.getFragment());
   } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
     final String pattern = intent.getStringExtra(SearchManager.QUERY);
     final Runnable runnable =
         new Runnable() {
           public void run() {
             final TextSearchPopup popup =
                 (TextSearchPopup) fbReader.getPopupById(TextSearchPopup.ID);
             popup.initPosition();
             fbReader.TextSearchPatternOption.setValue(pattern);
             if (fbReader.getTextView().search(pattern, true, false, false, false) != 0) {
               runOnUiThread(
                   new Runnable() {
                     public void run() {
                       fbReader.showPopup(popup.getId());
                     }
                   });
             } else {
               runOnUiThread(
                   new Runnable() {
                     public void run() {
                       UIUtil.showErrorMessage(FBReader.this, "textNotFound");
                       popup.StartPosition = null;
                     }
                   });
             }
           }
         };
     UIUtil.wait("search", runnable, this);
   } else {
     super.onNewIntent(intent);
   }
 }
Example #7
0
  /**
   * Get a file path from a Uri.
   *
   * <p>from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/
   * afilechooser/utils/FileUtils.java
   *
   * @param context
   * @param uri
   * @return
   * @author paulburke
   */
  public static String getPath(Context context, Uri uri) {

    Log.d(
        Constants.TAG + " File -",
        "Authority: "
            + uri.getAuthority()
            + ", Fragment: "
            + uri.getFragment()
            + ", Port: "
            + uri.getPort()
            + ", Query: "
            + uri.getQuery()
            + ", Scheme: "
            + uri.getScheme()
            + ", Host: "
            + uri.getHost()
            + ", Segments: "
            + uri.getPathSegments().toString());

    if ("content".equalsIgnoreCase(uri.getScheme())) {
      String[] projection = {"_data"};
      Cursor cursor = null;

      try {
        cursor = context.getContentResolver().query(uri, projection, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow("_data");
        if (cursor.moveToFirst()) {
          return cursor.getString(column_index);
        }
      } catch (Exception e) {
        // Eat it
      }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
      return uri.getPath();
    }

    return null;
  }
Example #8
0
  public MDLink parseStandardUrl(String url) {
    Timber.d("Parsing standard topic URL : %s", url);

    Uri parsedUri = Uri.parse(url);

    String categoryId = parsedUri.getQueryParameter("cat");
    String pageNumber = parsedUri.getQueryParameter("page");
    String topicId = parsedUri.getQueryParameter("post");
    String anchor = parsedUri.getFragment();

    // Set default page number as 1 (first page)
    if (pageNumber == null) {
      pageNumber = "1";
    }

    if (categoryId == null || topicId == null) {
      Timber.e("URL '%s' is invalid, category, or topic id not found", url);
      return MDLink.invalid();
    }

    try {
      Category topicCategory = categoriesStore.getCategoryById(Integer.parseInt(categoryId));
      if (topicCategory == null) {
        Timber.e("Category with id '%s' is unknown", categoryId);
        return MDLink.invalid();
      } else {
        Timber.d("Link is for category '%s'", topicCategory.name());
        return MDLink.forTopic(topicCategory, Integer.parseInt(topicId))
            .atPage(Integer.parseInt(pageNumber))
            .atPost(parseAnchor(anchor))
            .build();
      }
    } catch (NumberFormatException e) {
      Timber.e(e, "Error while parsing standard URL");
      return MDLink.invalid();
    }
  }
Example #9
0
  String getAdditionInfo(String url) {
    String s = "";
    if (url.contains("bongda")) {
      try {
        HtmlCleaner cleaner = new HtmlCleaner();
        String id = url.substring(url.lastIndexOf("/"));
        id = id.substring(1, id.indexOf("."));
        Uri ss = Uri.parse("http://m.bongdaplus.vn/Story.aspx?sid=" + id);

        URI fine =
            new URI(
                ss.getScheme(),
                ss.getUserInfo(),
                ss.getHost(),
                ss.getPort(),
                ss.getPath(),
                ss.getQuery(),
                ss.getFragment());
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
        HttpGet httpget = new HttpGet(fine);
        httpget.addHeader(
            "user-agent", "Mozilla/5.0 (Linux; U; Android 2.3.3) Gecko/20100101 Firefox/8.0");
        httpget.addHeader("accept-language", "en-us,en;q=0.5");
        HttpResponse response = httpclient.execute(httpget);
        InputStream binaryreader = new BufferedInputStream(response.getEntity().getContent());
        BufferedReader buf = new BufferedReader(new InputStreamReader(binaryreader));
        String sss;
        StringBuilder sb = new StringBuilder();
        while ((sss = buf.readLine()) != null) {
          sb.append(sss);
        }

        //	    		URL u = new URL(ss.getScheme(), ss.getHost(), ss.getPort(), ss.getPath());
        TagNode root = cleaner.clean(sb.toString());
        TagNode div = root.findElementByAttValue("class", "story-body", true, false);
        TagNode[] child = div.getElementsByName("strong", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("class", "listing", true, false);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("ul", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("img", true);
        for (int i = 0; i < child.length; i++)
          child[i].setAttribute("style", "width: 100%; height: auto;");
        s = cleaner.getInnerHtml(div);
        if (s.indexOf("VideoPlaying(") > 0) {
          int x = s.indexOf("VideoPlaying(");
          int st = s.indexOf("'", x);
          int en = s.indexOf("'", st + 1);
          String urlvideo = "http://bongdaplus.vn" + s.substring(st + 1, en);
          s = s + "<a href=\"" + urlvideo + "\"> Video </a></br></br>";
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (url.contains("teamtalk")) {
      try {
        HtmlCleaner cleaner = new HtmlCleaner();
        Uri ss = Uri.parse(url);
        URL u = new URL(ss.getScheme(), ss.getHost(), ss.getPort(), ss.getPath());
        TagNode root = cleaner.clean(u);
        TagNode div = root.findElementByAttValue("class", "tt-article-text", true, false);
        TagNode[] child = div.getElementsByName("p", true);
        for (int i = 0; i < child.length; i++)
          if (child[i].hasAttribute("class") || child[i].hasAttribute("style"))
            child[i].removeFromTree();
        child = div.getElementsByName("img", true);
        for (int i = 0; i < child.length; i++)
          child[i].setAttribute("style", "max-width: 80%; height: auto;");
        s = cleaner.getInnerHtml(div);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (url.contains("licheuro")) {
      try {
        HtmlCleaner cleaner = new HtmlCleaner();
        Uri ss = Uri.parse(url);
        URL u = new URL(ss.getScheme(), ss.getHost(), ss.getPort(), ss.getPath());
        TagNode root = cleaner.clean(u);
        TagNode div = root.findElementByAttValue("class", "entry", true, false);

        TagNode[] child = div.getElementsByName("span", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("strong", true);
        for (int i = 0; i < child.length; i++) {
          child[i].getParent().addChildren(child[i].getChildren());
          child[i].getParent().addChild(child[i].getText());
          child[i].removeFromTree();
        }
        child = div.getElementsByName("h1", true);
        for (int i = 0; i < child.length; i++) {
          child[i].getParent().addChildren(child[i].getChildren());
          child[i].getParent().addChild(child[i].getText());
          child[i].removeFromTree();
        }
        child = div.getElementsByAttValue("class", "boxpost", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("class", "ratingblock ", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("iframe", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("blockqoute", true);
        for (int i = 0; i < child.length; i++) {
          child[i].getParent().addChildren(child[i].getChildren());
          child[i].removeFromTree();
        }

        child = div.getElementsByAttValue("class", "dd_outer", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("id", "fb-root", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("id", "fbSEOComments", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("id", "ajax_comments_wrapper", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("table", true);
        for (int i = 0; i < child.length; i++) {
          child[i].setAttribute("style", "max-width: 100%; height: auto;");
          child[i].setAttribute("width", "100%");
        }
        child = div.getElementsByName("script", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("img", true);
        for (int i = 0; i < child.length; i++)
          child[i].setAttribute("style", "max-width: 80%; height: auto;");
        s = cleaner.getInnerHtml(div);
        if (s.indexOf("\"file\":") > 0) {
          int x = s.indexOf("\"file\":");
          int st = s.indexOf("http", x);
          int en = s.indexOf("\"", st + 1);
          String urlvideo = s.substring(st, en);
          s = s + "<a href=\"" + urlvideo + "\"> Video </a></br></br>";
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    System.out.println(s);
    return s;
  }
Example #10
0
 private static String getSubpath(Uri in) {
   final String fragment = in.getFragment();
   return fragment != null ? fragment : "";
 }
Example #11
0
  /**
   * Get a file path from a Uri. This will get the the path for Storage Access Framework Documents,
   * as well as the _data field for the MediaStore and other file-based ContentProviders.<br>
   * <br>
   * Callers should only use this for display purposes and not for accessing the file directly via
   * the file system
   *
   * @param context The context.
   * @param uri The Uri to query.
   * @see #isLocal(String)
   * @see #getFile(Context, Uri)
   * @author paulburke
   */
  @TargetApi(Build.VERSION_CODES.KITKAT)
  public static String getPath(final Context context, final Uri uri) {

    if (DEBUG)
      Log.d(
          TAG + " File -",
          "Authority: "
              + uri.getAuthority()
              + ", Fragment: "
              + uri.getFragment()
              + ", Port: "
              + uri.getPort()
              + ", Query: "
              + uri.getQuery()
              + ", Scheme: "
              + uri.getScheme()
              + ", Host: "
              + uri.getHost()
              + ", Segments: "
              + uri.getPathSegments().toString());

    // DocumentProvider
    if (isDocumentUri(context, uri)) {
      // ExternalStorageProvider
      if (isExternalStorageDocument(uri)) {
        final String docId = DocumentsContract.getDocumentId(uri);
        final String[] split = docId.split(":");
        final String type = split[0];

        if ("primary".equalsIgnoreCase(type)) {
          String path = Environment.getExternalStorageDirectory().getPath();
          if (split.length > 1) {
            path += "/" + split[1];
          }
          return path;
        }
        // there is no documented way of returning a path to a file on non primary storage.
        // so what we do is displaying the documentId to the user which is better than just null
        return docId;
      }
      // DownloadsProvider
      else if (isDownloadsDocument(uri)) {

        final String id = DocumentsContract.getDocumentId(uri);
        final Uri contentUri =
            ContentUris.withAppendedId(
                Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

        return getDataColumn(context, contentUri, null, null);
      }
      // MediaProvider
      else if (isMediaDocument(uri)) {
        final String docId = DocumentsContract.getDocumentId(uri);
        final String[] split = docId.split(":");
        final String type = split[0];

        Uri contentUri = null;
        if ("image".equals(type)) {
          contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        } else if ("video".equals(type)) {
          contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        } else if ("audio".equals(type)) {
          contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        }

        final String selection = "_id=?";
        final String[] selectionArgs = new String[] {split[1]};

        return getDataColumn(context, contentUri, selection, selectionArgs);
      }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

      // Return the remote address
      if (isGooglePhotosUri(uri)) return uri.getLastPathSegment();

      return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
      return uri.getPath();
    }

    return null;
  }