From: Soren Stoutner Date: Fri, 11 Sep 2015 05:50:04 +0000 (-0700) Subject: Initial commit. X-Git-Tag: v1.0~59 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff_plain;h=8ee8e28f3ea0b1cbab0e792fb065475953bb0b55 Initial commit. --- 8ee8e28f3ea0b1cbab0e792fb065475953bb0b55 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9c4de582 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..ca458fec --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Privacy Browser \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..9a8b7e5c --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..e7bedf33 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/dictionaries/soren.xml b/.idea/dictionaries/soren.xml new file mode 100644 index 00000000..750cd221 --- /dev/null +++ b/.idea/dictionaries/soren.xml @@ -0,0 +1,7 @@ + + + + duckduckgo + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..c595ad9b --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..b0c0cbc0 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..46c3407b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..6564d52d --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PrivacyBrowser.iml b/PrivacyBrowser.iml new file mode 100644 index 00000000..2934ed3f --- /dev/null +++ b/PrivacyBrowser.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 00000000..9dac3062 --- /dev/null +++ b/app/app.iml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 00000000..c749baaf --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" + + defaultConfig { + applicationId "com.stoutner.privacybrowser" + minSdkVersion 8 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:22.2.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 00000000..189b5801 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/soren/Android/Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses Webview with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/com/stoutner/privacybrowser/ApplicationTest.java b/app/src/androidTest/java/com/stoutner/privacybrowser/ApplicationTest.java new file mode 100644 index 00000000..28839c67 --- /dev/null +++ b/app/src/androidTest/java/com/stoutner/privacybrowser/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.stoutner.privacybrowser; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..17718ffb --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/stoutner/privacybrowser/Webview.java b/app/src/main/java/com/stoutner/privacybrowser/Webview.java new file mode 100644 index 00000000..ab78eee0 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/Webview.java @@ -0,0 +1,177 @@ +package com.stoutner.privacybrowser; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.webkit.WebView; +import android.widget.EditText; + +import java.net.URL; + + +public class Webview extends ActionBarActivity { + + static String formattedUrlString; + static WebView mainWebView; + static final String homepage = "https://www.duckduckgo.com"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_webview); + + final EditText urlTextBox = (EditText) findViewById(R.id.urlTextBox); + mainWebView = (WebView) findViewById(R.id.mainWebView); + + // Allow pinch to zoom. + mainWebView.getSettings().setBuiltInZoomControls(true); + + // Hide zoom controls. + mainWebView.getSettings().setDisplayZoomControls(false); + + // Enable JavaScript. + mainWebView.getSettings().setJavaScriptEnabled(true); + + // Enable DOM Storage. + mainWebView.getSettings().setDomStorageEnabled(true); + + // Get the intent information that started the app. + final Intent intent = getIntent(); + + if (intent.getData() != null) { + // Get the intent data. + final Uri intentUriData = intent.getData(); + + // Try to parse the intent data and store it in urlData. + URL urlData = null; + try { + urlData = new URL(intentUriData.getScheme(), intentUriData.getHost(), intentUriData.getPath()); + } catch (Exception e) { + e.printStackTrace(); + } + + Webview.formattedUrlString = urlData.toString(); + } + + // If formattedUrlString is null assign the homepage to it. + if (formattedUrlString == null) { + formattedUrlString = homepage; + } + + // Place the formattedUrlString in the address bar and load the website. + urlTextBox.setText(formattedUrlString); + mainWebView.loadUrl(formattedUrlString); + + // Set the "go" button on the keyboard to load the URL. + urlTextBox.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down event on the "enter" button + if ((event.getAction() == KeyEvent.ACTION_DOWN) && + (keyCode == KeyEvent.KEYCODE_ENTER)) { + // Load the URL into the mainWebView and consume the event. + loadUrl(mainWebView); + return true; + } + // Do not consume the event. + return false; + } + }); + + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_webview, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem menuItem) { + int menuItemId = menuItem.getItemId(); + final WebView mainWebView = (WebView) findViewById(R.id.mainWebView); + + // Use the menu items to go forward or back. + switch (menuItemId) { + case R.id.back: + mainWebView.goBack(); + break; + case R.id.forward: + mainWebView.goForward(); + break; + } + + return super.onOptionsItemSelected(menuItem); + } + + // Override onBackPressed so that if mainWebView can go back it does when the system back button is pressed. + @Override + public void onBackPressed() { + if (mainWebView.canGoBack()) { + mainWebView.goBack(); + } else { + super.onBackPressed(); + } + } + + public void loadUrl(View view) { + // Get the text from urlTextInput and convert it to a string. + final EditText urlTextBox = (EditText) findViewById(R.id.urlTextBox); + final String unformattedUrlString = urlTextBox.getText().toString(); + + // Don't do anything unless unformattedUrlString is at least 6 characters long. + if (unformattedUrlString.length() < 6) { return; } + + // Add correct protocol formatting to the beginning of the URL if needed. + final String firstSixCharacters = unformattedUrlString.substring(0, 6); + + switch (firstSixCharacters) { + case "http:/": + formattedUrlString = unformattedUrlString; + break; + case "https:": + formattedUrlString = unformattedUrlString; + break; + case "ftp://": + formattedUrlString = unformattedUrlString; + break; + default: + formattedUrlString = "http://" + unformattedUrlString; + } + + /* + // Parse the unformattedURLString into a Uri. + + final Uri uriData = Uri.parse(unformattedUrlString); + + // Convert the Uri to a URL, chicking for any problems with the formatting. + URL urlData = null; + + try { + urlData = new URL(uriData.getScheme(), uriData.getHost(), uriData.getPath()); + } catch (Exception e) { + e.printStackTrace(); + } + + // Convert urlData to a string, which is reqauired by loadUrl method. + formattedUrlString = urlData.toString(); + */ + + final WebView mainWebView = (WebView) findViewById(R.id.mainWebView); + + // Place the URL text back in the address bar and load the website. + urlTextBox.setText(formattedUrlString); + mainWebView.loadUrl(formattedUrlString); + + // Hides the keyboard so we can see the webpage. + InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); + inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0); + } +} diff --git a/app/src/main/res/layout/activity_webview.xml b/app/src/main/res/layout/activity_webview.xml new file mode 100644 index 00000000..2e4bc603 --- /dev/null +++ b/app/src/main/res/layout/activity_webview.xml @@ -0,0 +1,38 @@ + + + + + + +