package org.kobjects.demo.htmlview;

//Copyright 2013 Google Inc.
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

import org.kobjects.htmlview.HtmlView;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ScrollView;

public class HtmlDemo extends Activity {

  HtmlView htmlView;
  ScrollView scrollView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    scrollView = new ScrollView(this);
    htmlView = new HtmlView(this);
    scrollView.addView(htmlView);
    setContentView(scrollView);
    loadDemo();
  }

  @Override
  public void onBackPressed() {
    if (htmlView.getBaseUrl().equals(HtmlView.ASSET_BASE_URL.resolve("index.html"))) {
      super.onBackPressed();
    } else {
      loadDemo();
    }
  }
  
  void loadDemo() {
    htmlView.loadUrl("index.html");
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    menu.add("Reset");
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    String title = item.getTitle().toString();
    if (title.equals("Reset")) {
      loadDemo();
      return true;
    }
    return super.onContextItemSelected(item);
  }
}

@@ -776,20 +776,151 @@
 id.w
-idget.Scroll
+ebkit.WebView;%0Aimport android.widget.LinearLayout;%0Aimport android.widget.ListView;%0Aimport android.widget.ScrollView;%0Aimport android.widget.Text
 View
@@ -985,16 +985,45 @@
 mlView;%0A
+  LinearLayout linearLayout;%0A
   Scroll
@@ -1194,36 +1194,171 @@
     
-htmlView = new HtmlView(this
+linearLayout = new LinearLayout(this);%0A    linearLayout.setOrientation(LinearLayout.VERTICAL);%0A    htmlView = new HtmlView(this);%0A    linearLayout.addView(htmlView
 );%0A 
@@ -1375,32 +1375,36 @@
 iew.addView(
-htmlView
+linearLayout
 );%0A    setCo
@@ -1707,16 +1707,134 @@
 html%22);%0A
+    while(linearLayout.getChildCount() %3E 1) %7B%0A    %09linearLayout.removeViewAt(linearLayout.getChildCount() - 1);%0A    %7D%0A
   %7D%0A%0A  @
@@ -1911,24 +1911,91 @@
 d(%22Reset%22);%0A
+    menu.add(%22Add 10 WebViews%22);%0A    menu.add(%22Add 10 HtmlViews%22);%0A
     return t
@@ -2195,24 +2195,708 @@
 ;%0A    %7D%0A    
+TextView label = new TextView(this);%0A    label.setText(%22View count: %22 + (linearLayout.getChildCount() + 10));%0A    if (title.equals(%22Add 10 HtmlViews%22)) %7B%0A      for (int i = 0; i %3C 10; i++) %7B%0A        HtmlView htmlView = new HtmlView(this);%0A        linearLayout.addView(htmlView);%0A        htmlView.loadUrl(%22index.html%22);%0A      %7D%0A      linearLayout.addView(label);%0A      return true;%0A    %7D%0A    if (title.equals(%22Add 10 WebViews%22)) %7B%0A      for (int i = 0; i %3C 10; i++) %7B%0A        WebView webView = new WebView(this);%0A        linearLayout.addView(webView);%0A        webView.loadUrl(%22file:///android_asset/index.html%22);%0A      %7D%0A      linearLayout.addView(label);%0A      return true;%0A    %7D%0A   %09
 return super

Add 10 HtmlViews / Add 10 WebViews stress test added