Android Open Source - OrzEye Youdao Translater






From Project

Back to project page OrzEye.

License

The source code is released under:

GNU General Public License

If you think the Android project OrzEye listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.dylan.orzeye.dictionary;
//from www  .  jav a  2 s  .  c  o m
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URLEncoder;

import com.dylan.orzeye.dictionary.YoudaoTranslaterAPIConnection;

public class YoudaoTranslater {
  private final static String URL_STRING = "http://fanyi.youdao.com/openapi.do?keyfrom=OrzEye&key=1924278310&type=data&doctype=json&version=1.1&q=";

  public static YoudaoJsonParser translate(String text) {

    String jsonStr = "";
    HttpURLConnection httpURLConnection = null;
    String YoudaoAPIURL = getAdressUrl(text);
    httpURLConnection = YoudaoTranslaterAPIConnection
        .getHttpConnection(YoudaoAPIURL);

    YoudaoJsonParser youdaoJsonParser = null;
    try {
      BufferedReader br = new BufferedReader(new InputStreamReader(
          httpURLConnection.getInputStream(), "utf-8"));

      StringBuilder sb = new StringBuilder();
      String str;

      while ((str = br.readLine()) != null) {
        sb.append(str);
        sb.append('\n');
      }

      jsonStr = sb.toString();
      youdaoJsonParser = new YoudaoJsonParser(jsonStr);
      //TODO handel error
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      YoudaoTranslaterAPIConnection
          .closeHttpConnection(httpURLConnection);
    }

    return youdaoJsonParser;
  }

  private static String getAdressUrl(String text) {
    StringBuilder YoudaoAPIURL = new StringBuilder();

    try {
      YoudaoAPIURL.append(URL_STRING).append(
          URLEncoder.encode(text, "utf-8"));
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }

    return YoudaoAPIURL.toString();
  }

}




Java Source Code List

com.dylan.orzeye.CameraActivity.java
com.dylan.orzeye.DrawRectView.java
com.dylan.orzeye.SplashActivity.java
com.dylan.orzeye.dictionary.DictionaryTool.java
com.dylan.orzeye.dictionary.YoudaoJsonParser.java
com.dylan.orzeye.dictionary.YoudaoTranslaterAPIConnection.java
com.dylan.orzeye.dictionary.YoudaoTranslater.java
com.dylan.orzeye.image.ImageProcessTool.java
com.dylan.orzeye.ocr.OCRTool.java