package com.elation.demo;

//import android.app.Fragment;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.support.v4.app.Fragment;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.webkit.ConsoleMessage;
import java.util.ArrayList;

public class ElationDebugConsoleFragment extends android.support.v4.app.Fragment {
  private ListView consoleList;
  private ArrayAdapter consoleListAdapter;
  private ArrayList<ConsoleMessage> consoleEntries;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.debug_console_fragment, container, false);
    consoleList = (ListView) view.findViewById(R.id.debug_console_list);

    if (consoleListAdapter == null) {
      // onCreateView is called every time this fragment is loaded in a tab, but we can reuse most of these objects
      ElationWebView webview = ((ElationDemoActivity) getActivity()).getWebView();
      consoleEntries = webview.getConsoleMessages();

      //consoleListAdapter = new ArrayAdapter(getActivity(), R.layout.debug_console_list_entry, R.id.label, consoleEntries);
      consoleListAdapter = new ElationDebugConsoleMessageAdapter(getActivity(), R.layout.debug_console_message, consoleEntries);
      
      webview.setConsoleMessageAdapter(consoleListAdapter);
    }
    consoleList.setAdapter(consoleListAdapter);

    return view;
  }
}

@@ -134,16 +134,46 @@
 wGroup;%0A
+import android.view.KeyEvent;%0A
 import a
@@ -232,32 +232,96 @@
 4.app.Fragment;%0A
+import android.widget.EditText;%0Aimport android.widget.TextView;%0A
 import android.w
@@ -410,16 +410,17 @@
 essage;%0A
+%0A
 import j
@@ -438,16 +438,72 @@
 rayList;
+%0Aimport java.util.Observable;%0Aimport java.util.Observer;
 %0A%0Apublic
@@ -577,16 +577,36 @@
 ragment 
+implements Observer 
 %7B%0A  priv
@@ -631,16 +631,49 @@
 leList;%0A
+  private EditText consoleInput;%0A
   privat
@@ -761,16 +761,47 @@
 ries;%0A  
+private ElationWebView webview;
 %0A  @Over
@@ -1064,16 +1064,91 @@
 e_list);
+%0A    consoleInput = (EditText) view.findViewById(R.id.debug_console_input);
 %0A%0A    if
@@ -1301,31 +1301,16 @@
 s%0A      
-ElationWebView 
 webview 
@@ -1363,16 +1363,65 @@
 View();%0A
+      webview.mAdapterObservable.register(this);%0A
       co
@@ -1472,18 +1472,16 @@
 %0A%0A      
-//
 consoleL
@@ -1497,21 +1497,42 @@
 r = new 
-Array
+ElationDebugConsoleMessage
 Adapter(
@@ -1573,30 +1573,15 @@
 ole_
-list_entry, R.id.label
+message
 , co
@@ -1595,26 +1595,34 @@
 tries);%0A    
-  
+%7D%0A    if (
 consoleListA
@@ -1624,257 +1624,740 @@
 List
-Adapter = new ElationDebugConsoleMessageAdapter(getActivity(), R.layout.debug_console_message, consoleEntries);%0A      %0A      webview.setConsoleMessageAdapter(consoleListAdapter);%0A    %7D%0A    consoleList.setAdapter(consoleListAdapter);%0A%0A    return view
+ != null) %7B%0A      consoleList.setAdapter(consoleListAdapter);%0A    %7D%0A    if (consoleInput != null) %7B%0A      final ElationDebugConsoleFragment self = this;%0A      consoleInput.setOnEditorActionListener(new TextView.OnEditorActionListener() %7B%0A        @Override%0A        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) %7B%0A          self.webview.injectJavascript(v.getText().toString());%0A          v.setText(%22%22);%0A          return true;%0A        %7D%0A      %7D);%0A    %7D%0A%0A    return view;%0A  %7D%0A  @Override%0A  public void onDestroy() %7B%0A    webview.mAdapterObservable.unregister(this);%0A    super.onDestroy();%0A  %7D%0A%0A  @Override%0A  public void update(Observable observable, Object data) %7B%0A    consoleListAdapter.notifyDataSetChanged()
 ;%0A  

Implement Observer and add JS injection text input to console