package com.acmapps.openbrowser;

import android.annotation.TargetApi;
import android.app.*;
import android.app.ActionBar;
import android.content.Context;
import android.view.*;
import android.os.*;
import android.webkit.*;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

public class MainActivity extends Activity {

    int version = Build.VERSION.SDK_INT ;

    private WebView mWebView;
    private EditText mEditText;

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

        final ProgressBar loadingProgressBar;
        String URL = "http://google.com/";

        mWebView = (WebView) findViewById(R.id.webView);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl(URL);
        mWebView.setWebViewClient(new MyWebViewClient());
        mWebView.canGoBack();

        loadingProgressBar=(ProgressBar)findViewById(R.id.progressBar);

        mWebView.setWebChromeClient(new WebChromeClient() {

            // this will be called on page loading progress

            @Override

            public void onProgressChanged(WebView view, int newProgress) {

                super.onProgressChanged(view, newProgress);


                loadingProgressBar.setProgress(newProgress);

                if (newProgress == 100) {
                    loadingProgressBar.setVisibility(View.GONE);

                } else {
                    loadingProgressBar.setVisibility(View.VISIBLE);

                }
            }
        }); 
        hideActionBar();

    }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if(keyCode == KeyEvent.KEYCODE_BACK){
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }

    private class MyWebViewClient extends WebViewClient {


        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);
            return true;
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public void hideActionBar(){
        if (version >= Build.VERSION_CODES.HONEYCOMB){
            ActionBar actionBar = getActionBar();
            actionBar.hide();
        }
    }

    public void goClick(View view){
        //Get URL from EditText
        mWebView = (WebView) findViewById(R.id.webView);
        mEditText = (EditText) findViewById(R.id.addressText);

        String url = mEditText.getText().toString();

        mWebView.loadUrl("http://" + url);
    }

    public void backButton(View view){
            if (mWebView.canGoBack() == true){
            mWebView.goBack();
            Button backBtn = (Button) findViewById(R.id.backButton);
            backBtn.setEnabled(true);
        }
    }

    public void fwdButton(View view){
            if (mWebView.canGoForward() == true){
            mWebView.goForward();
            Button fwdBtn = (Button) findViewById(R.id.fwdButton);
            fwdBtn.setEnabled(true);
        }
    }

    public void stopButton(View view){
        mWebView.stopLoading();

        Context context = getApplicationContext();
        CharSequence text = "Stopping Page Load";
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }

    public void refreshButton(View view){
        mWebView.reload();
    }


        @SuppressWarnings("deprecation")
    public void onLowMemory(){
        WebView mWebView = (WebView) findViewById(R.id.webView);

        if(version <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 ){
            //Attemts to free memory from the webView
            mWebView.freeMemory();
        } else{
            return;
        }
    }

    @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.
        switch (item.getItemId()) {
            case R.id.action_settings:
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

@@ -685,16 +685,162 @@
 essBar;%0A
+        %0A        Button backBtn = (Button) findViewById(R.id.backButton);%0A        Button fwdBtn = (Button) findViewById(R.id.fwdButton);%0A        %0A
         
@@ -1109,16 +1109,214 @@
 oBack();
+%0A        %0A        if (mWebView.canGoBack == true)%7B%0A            backBtn.setEnabled(true);%0A        %7D%0A        %0A        if (mWebView.canGoForward == true)%7B%0A            fwdBtn.setEnabled(true);%0A        %7D
 %0A%0A      
@@ -3020,437 +3020,101 @@
     
-    if (mWebView.canGoBack() == true)%7B%0A            mWebView.goBack();%0A            Button backBtn = (Button) findViewById(R.id.backButton);%0A            backBtn.setEnabled(true);%0A        %7D%0A    %7D%0A%0A    public void fwdButton(View view)%7B%0A            if (mWebView.canGoForward() == true)%7B%0A            mWebView.goForward();%0A            Button fwdBtn = (Button) findViewById(R.id.fwdButton);%0A            fwdBtn.setEnabled(true);%0A        %7D
+mWebView.goBack();%0A    %7D%0A%0A    public void fwdButton(View view)%7B%0A        mWebView.goForward();
 %0A   

Update MainActivity.java