package ca.bmaupin.androidplayground;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.support.v7.app.ActionBarActivity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ToggleButton;

public class MainActivity extends ActionBarActivity {

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

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	public void onToggleClicked(View view) {
	    // Is the toggle on?
	    boolean on = ((ToggleButton) view).isChecked();
	    
	    if (on) {
	        ConnectivityManager dataManager;
	        dataManager  = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
	        Method dataMtd = null;
	        try {
	            dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
	        } catch (NoSuchMethodException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
	        dataMtd.setAccessible(true);
	        try {
	            dataMtd.invoke(dataManager, true);
	        } catch (IllegalArgumentException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        } catch (IllegalAccessException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        } catch (InvocationTargetException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
	    } else {
	        // Disable data
	    }
	}
}

@@ -265,16 +265,41 @@
 Bundle;%0A
+import android.util.Log;%0A
 import a
@@ -462,16 +462,67 @@
 tivity %7B
+%0A%09private static final String TAG = %22MainActivity%22;
 %0A%0A%09@Over
@@ -1746,62 +1746,25 @@
     
-// TODO Auto-generated catch block%0A%09            e.prin
+Log.e(TAG, Log.ge
 tSta
@@ -1762,35 +1762,44 @@
 og.getStackTrace
-(
+String(e)
 );
+ 
 %0A%09        %7D%0A%09   
@@ -1956,66 +1956,26 @@
     
-    // TODO Auto-generated catch block%0A%09            e.prin
+%09Log.e(TAG, Log.ge
 tSta
@@ -1973,33 +1973,41 @@
 og.getStackTrace
-(
+String(e)
 );%0A%09        %7D ca
@@ -2052,66 +2052,26 @@
     
-    // TODO Auto-generated catch block%0A%09            e.prin
+%09Log.e(TAG, Log.ge
 tSta
@@ -2069,33 +2069,41 @@
 og.getStackTrace
-(
+String(e)
 );%0A%09        %7D ca
@@ -2151,66 +2151,26 @@
     
-    // TODO Auto-generated catch block%0A%09            e.prin
+%09Log.e(TAG, Log.ge
 tSta
@@ -2176,17 +2176,25 @@
 ackTrace
-(
+String(e)
 );%0A%09    

Clean up logging