Android Open Source - ShareManager Connection Runnable






From Project

Back to project page ShareManager.

License

The source code is released under:

Copyright (c) 2013, Nelspike All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Red...

If you think the Android project ShareManager 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 share.manager.connection;
/*  w w  w .  j av  a  2 s. com*/
import java.io.*;
import java.net.*;
import java.util.ArrayList;

public class ConnectionRunnable implements Runnable {

  private String link;
  private ArrayList<String> resultString = new ArrayList<String>();
  private int readTimeout = 10000, connectionTimeout = 15000;

  public ConnectionRunnable(String link) {
    this.link = link;
  }

  @Override
  public void run() {
    connect();
  }

  private void connect() {
    HttpURLConnection con = null;
    String line = "";
    try {
      URL url = new URL(link);
      con = (HttpURLConnection) url.openConnection();
      con.setReadTimeout(readTimeout);
      con.setConnectTimeout(connectionTimeout);
      con.setRequestMethod("GET");
      con.setDoInput(true);

      // Start the connection
      con.connect();

      // Read results from the query
      BufferedReader reader = new BufferedReader(new InputStreamReader(
          con.getInputStream(), "UTF-8"));

      while ((line = reader.readLine()) != null) {
        resultString.add(line);
      }

      reader.close();
    }
    catch (IOException e) {
      try {
        resultString.add(con.getResponseCode() + "");
      }
      catch (IOException e1) {
        // TODO: Can't figure response code
      }
    }
    finally {
      if (con != null) con.disconnect();
    }
  }

  public ArrayList<String> getResultObject() {
    return resultString;
  }

}




Java Source Code List

share.manager.adapters.CompanyAdapter.java
share.manager.adapters.DialogAdapter.java
share.manager.adapters.MainPagerAdapter.java
share.manager.adapters.SharesAdapter.java
share.manager.connection.ConnectionRunnable.java
share.manager.connection.ConnectionThread.java
share.manager.fragments.MineFragment.java
share.manager.fragments.PortfolioFragment.java
share.manager.fragments.SharesFragment.java
share.manager.listeners.ShareTabListener.java
share.manager.listeners.SwipeListener.java
share.manager.stock.CompanyActivity.java
share.manager.stock.MainActivity.java
share.manager.stock.ResultsActivity.java
share.manager.stock.SettingsActivity.java
share.manager.stock.ShareManager.java
share.manager.utils.CompanyGraphicsBuilder.java
share.manager.utils.FileHandler.java
share.manager.utils.GraphType.java
share.manager.utils.RESTFunction.java
share.manager.utils.ShareUtils.java
share.manager.utils.SharesGraphicsBuilder.java