package com.example.gandalf;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.fernandocejas.android10.gandalf.Gandalf;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends Activity {

  private final DataPresenter dataPresenterOne = new DataPresenter();
  private final DataPresenter dataPresenterTwo = new DataPresenter();

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //dataPresenterOne.getData();
    //dataPresenterOne.getData("pi");
    //dataPresenterOne.getData("android10");
    //dataPresenterOne.getData("fernando", 1);
    //dataPresenterOne.getData("fernando", 1, 1);

    dataPresenterOne.anotherMethodOne();
    dataPresenterOne.anotherMethodOne();
    dataPresenterOne.anotherMethodOne();
    dataPresenterTwo.anotherMethodOne();

    dataPresenterTwo.anotherMethodTwo();
    dataPresenterTwo.anotherMethodTwo();

    dataPresenterOne.printMessage("this is tag", "this is message");

    dataPresenterOne.executeDiskIOTaskOnUiThread();

    //this.executeNetworkTaskOnUiThread();
    //this.executeDiskIOTaskOnUiThread();
  }

  @Override protected void onDestroy() {
    super.onDestroy();

    //dataPresenterOne.executeDiskIOTaskOnUiThread();

    Gandalf.printStats();
  }

  private void executeNetworkTaskOnUiThread() {
    try {
      URL url = new URL("http://www.fernandocejas.com");
      HttpURLConnection con = (HttpURLConnection) url.openConnection();
      readStream(con.getInputStream());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void readStream(InputStream in) {
    BufferedReader reader = null;
    try {
      reader = new BufferedReader(new InputStreamReader(in));
      String line = "";
      while ((line = reader.readLine()) != null) {
        Log.d("Penano", "Lineeee ----> " + line);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
}

@@ -82,33 +82,8 @@
 le;%0A
-import android.util.Log;%0A
 impo
@@ -133,185 +133,8 @@
 alf;
-%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL;
 %0A%0Apu
@@ -1059,1055 +1059,102 @@
 ();%0A
-%0A    //this.executeNetworkTaskOnUiThread();%0A    //this.executeDiskIOTaskOnUiThread();%0A  %7D%0A%0A  @Override protected void onDestroy() %7B%0A    super.onDestroy();%0A%0A    //dataPresenterOne.executeDiskIOTaskOnUiThread();%0A%0A    Gandalf.printStats();%0A  %7D%0A%0A  private void executeNetworkTaskOnUiThread() %7B%0A    try %7B%0A      URL url = new URL(%22http://www.fernandocejas.com%22);%0A      HttpURLConnection con = (HttpURLConnection) url.openConnection();%0A      readStream(con.getInputStream());%0A    %7D catch (Exception e) %7B%0A      e.printStackTrace();%0A    %7D%0A  %7D%0A%0A  private void readStream(InputStream in) %7B%0A    BufferedReader reader = null;%0A    try %7B%0A      reader = new BufferedReader(new InputStreamReader(in));%0A      String line = %22%22;%0A      while ((line = reader.readLine()) != null) %7B%0A        Log.d(%22Penano%22, %22Lineeee ----%3E %22 + line);%0A      %7D%0A    %7D catch (IOException e) %7B%0A      e.printStackTrace();%0A    %7D finally %7B%0A      if (reader != null) %7B%0A        try %7B%0A          reader.close();%0A        %7D catch (IOException e) %7B%0A          e.printStackTrace();%0A        %7D%0A      %7D%0A    %7D
+  %7D%0A%0A  @Override protected void onDestroy() %7B%0A    super.onDestroy();%0A    Gandalf.printStats();
 %0A  %7D

Remove unused sample code.