예제 #1
0
  public String uri2string(Uri intent_uri)
      throws FileNotFoundException, MalformedURLException, IOException {

    if (intent_uri.toString().startsWith("/"))
      return FileHelper.file2String(new File(intent_uri.toString()));

    InputStream in;

    if (intent_uri.toString().startsWith("content://"))
      in = getContentResolver().openInputStream(intent_uri);
    else in = new BufferedInputStream(new URL("" + intent_uri).openStream(), 4096);

    FileOutputStream file_writer = null;

    // if it comes from network
    if (intent_uri.toString().startsWith("http")) { // https catched also
      new File(GoPrefs.getSGFPath() + "/downloads").mkdirs();
      File f = new File(GoPrefs.getSGFPath() + "/downloads/" + intent_uri.getLastPathSegment());
      f.createNewFile();
      file_writer = new FileOutputStream(f);
    }

    StringBuffer out = new StringBuffer();
    byte[] b = new byte[4096];
    for (int n; (n = in.read(b)) != -1; ) {
      out.append(new String(b, 0, n));
      if (file_writer != null) file_writer.write(b, 0, n);
    }
    if (file_writer != null) file_writer.close();

    return out.toString();
  }
예제 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    GoPrefs.init(this);

    progress = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
    progress.setMax(100);
    progress.setProgress(10);

    LinearLayout lin = new LinearLayout(this);

    ImageView img = new ImageView(this);
    img.setImageResource(R.drawable.ic_launcher);
    img.setLayoutParams(
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    lin.setOrientation(LinearLayout.VERTICAL);

    lin.addView(img);

    FrameLayout frame = new FrameLayout(this);
    frame.addView(progress);
    message_tv = new TextView(this);
    message_tv.setText("starting");
    message_tv.setTextColor(0xFF000000);
    message_tv.setPadding(7, 0, 0, 0);
    frame.addView(message_tv);

    lin.addView(frame);

    alert_dlg =
        new AlertDialog.Builder(this)
            .setCancelable(false)
            .setTitle(R.string.loading_sgf)
            .setView(lin)
            .show();

    EasyTracker.getTracker()
        .trackEvent("ui_action", "load_sgf", getIntent().getData().toString(), null);
    new Thread(this).start();
  }