package me.soundlocker.soundlocker;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import java.util.ArrayList;

public class WebViewer extends Activity{
    private static final String PASSWORD = "password";
    private static final String WEBSITE = "website";
    private ArrayList<String> webEndings;
    private String password = "";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setInitialValues();
    }

    protected void onResume() {
        super.onResume();
        setInitialValues();
    }

    private void setInitialValues() {
        Intent intent = getIntent();
        String website = intent.getStringExtra(WEBSITE);
        password = intent.getStringExtra(PASSWORD);
        webEndings = new ArrayList<String>();
        populateWebEndings(webEndings);

        String url = makeUrl(website);
        WebView webview = new WebView(this);
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webview.getSettings().setDomStorageEnabled(true);

        webview.loadUrl("http://www.facebook.com");

        setContentView(webview);

        //prevents certain sites from defaulting to browser
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                view.evaluateJavascript("document.getElementsByName('pass')[0].value = '"+password+"';",null);
            }
        });

    }

    private void populateWebEndings(ArrayList<String> aL) {
        aL.add(".org");
        aL.add(".com");
        aL.add(".net");
        aL.add(".gov");
        aL.add(".edu");
    }

    private String makeUrl (String siteName){
        if (!siteName.contains("http://")){
            siteName = "http://" + siteName;
        }



        for(int i=0; i<webEndings.size(); i++){
            if(siteName.contains(webEndings.get(i))){
                return siteName;
            }
        }
        String appendedWebSite = siteName+".com";
        return appendedWebSite;

    }

}

@@ -224,37 +224,8 @@
 t;%0A%0A
-import java.util.ArrayList;%0A%0A
 publ
@@ -259,16 +259,17 @@
 Activity
+ 
 %7B%0A    pr
@@ -373,84 +373,8 @@
 te%22;
-%0A    private ArrayList%3CString%3E webEndings;%0A    private String password = %22%22;
 %0A%0A  
@@ -679,24 +679,30 @@
 ();%0A        
+final 
 String websi
@@ -746,16 +746,29 @@
         
+final String 
 password
@@ -807,133 +807,8 @@
 D);%0A
-        webEndings = new ArrayList%3CString%3E();%0A        populateWebEndings(webEndings);%0A%0A        String url = makeUrl(website);
 %0A   
@@ -1012,17 +1012,16 @@
 (true);%0A
-%0A
         
@@ -1041,16 +1041,17 @@
 rl(%22http
+s
 ://www.f
@@ -1065,17 +1065,16 @@
 .com%22);%0A
-%0A
         
@@ -1101,69 +1101,8 @@
 ew);
-%0A%0A        //prevents certain sites from defaulting to browser
 %0A   
@@ -1335,17 +1335,19 @@
 = '%22
-+
+ + 
 password
 +%22';
@@ -1346,14 +1346,17 @@
 word
-+
+ + 
 %22';%22,
+ 
 null
@@ -1388,598 +1388,12 @@
 %7D);%0A
-%0A
     %7D%0A
-%0A    private void populateWebEndings(ArrayList%3CString%3E aL) %7B%0A        aL.add(%22.org%22);%0A        aL.add(%22.com%22);%0A        aL.add(%22.net%22);%0A        aL.add(%22.gov%22);%0A        aL.add(%22.edu%22);%0A    %7D%0A%0A    private String makeUrl (String siteName)%7B%0A        if (!siteName.contains(%22http://%22))%7B%0A            siteName = %22http://%22 + siteName;%0A        %7D%0A%0A%0A%0A        for(int i=0; i%3CwebEndings.size(); i++)%7B%0A            if(siteName.contains(webEndings.get(i)))%7B%0A                return siteName;%0A            %7D%0A        %7D%0A        String appendedWebSite = siteName+%22.com%22;%0A        return appendedWebSite;%0A%0A    %7D%0A%0A
 %7D%0A

Refactor WebViewer