Android Open Source - test-gradle My Web App Activity






From Project

Back to project page test-gradle.

License

The source code is released under:

Copyright (c) <2013> <Paul Estrada> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the S...

If you think the Android project test-gradle 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 com.example.listexample.webapp;
/*from   w w w .j ava 2s .com*/
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.example.listexample.R;
import com.example.listexample.utils.HttpUtils;

public class MyWebAppActivity extends Activity {
  
  private WebView webView = null;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webapp);
    
    webView = (WebView) findViewById(R.id.wvBrowser);
    initBrowser();
  }
  
  protected void initBrowser() {
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.addJavascriptInterface(new WebViewBridge(this), "AndroidInterface");
    webView.setWebViewClient(new MyWebViewClient());
    webView.loadData(getHtml(), "text/html", "utf-8");
  }
  
  protected String getHtml() {
    InputStream is = null;
    String html = "";
    
    try {
      is = getAssets().open("htdocs/index.html");
      html = HttpUtils.convertStreamtoString(is);
      return html;
    } catch (IOException e) {
      html = "";
      e.printStackTrace();
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    return null;
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
      if (webView.canGoBack()) {
        webView.goBack();
        return true;
      }
    }
    return super.onKeyDown(keyCode, event);
  }

}




Java Source Code List

com.example.listexample.GpsActivity.java
com.example.listexample.MainActivity.java
com.example.listexample.MultiListActivity.java
com.example.listexample.MyAdapter.java
com.example.listexample.NavigationAActivity.java
com.example.listexample.NavigationBActivity.java
com.example.listexample.ViewHolderRB.java
com.example.listexample.ViewHolderTV.java
com.example.listexample.ViewHolder.java
com.example.listexample.sql.DBConstants.java
com.example.listexample.sql.MyDatabaseHelper.java
com.example.listexample.sql.MySqliteHelper.java
com.example.listexample.sql.SqliteActivity.java
com.example.listexample.sql.User.java
com.example.listexample.utils.GetTweetsTask.java
com.example.listexample.utils.HttpUtils.java
com.example.listexample.utils.JsonParser.java
com.example.listexample.utils.Tweet.java
com.example.listexample.webapp.MyWebAppActivity.java
com.example.listexample.webapp.MyWebViewClient.java
com.example.listexample.webapp.WebViewBridge.java