From 8ee8e28f3ea0b1cbab0e792fb065475953bb0b55 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 10 Sep 2015 22:50:04 -0700 Subject: [PATCH 1/1] Initial commit. --- .gitignore | 7 + .idea/.name | 1 + .idea/compiler.xml | 22 +++ .idea/copyright/profiles_settings.xml | 3 + .idea/dictionaries/soren.xml | 7 + .idea/gradle.xml | 19 ++ .idea/misc.xml | 22 +++ .idea/modules.xml | 9 + .idea/vcs.xml | 6 + PrivacyBrowser.iml | 19 ++ app/.gitignore | 1 + app/app.iml | 95 ++++++++++ app/build.gradle | 25 +++ app/proguard-rules.pro | 17 ++ .../privacybrowser/ApplicationTest.java | 13 ++ app/src/main/AndroidManifest.xml | 29 +++ .../com/stoutner/privacybrowser/Webview.java | 177 ++++++++++++++++++ app/src/main/res/layout/activity_webview.xml | 38 ++++ app/src/main/res/menu/menu_webview.xml | 18 ++ app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes app/src/main/res/values-w820dp/dimens.xml | 6 + app/src/main/res/values/dimens.xml | 5 + app/src/main/res/values/strings.xml | 12 ++ app/src/main/res/values/styles.xml | 8 + build.gradle | 19 ++ gradle.properties | 18 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 49896 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 164 ++++++++++++++++ gradlew.bat | 90 +++++++++ settings.gradle | 1 + 34 files changed, 857 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/dictionaries/soren.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 PrivacyBrowser.iml create mode 100644 app/.gitignore create mode 100644 app/app.iml create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/stoutner/privacybrowser/ApplicationTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/stoutner/privacybrowser/Webview.java create mode 100644 app/src/main/res/layout/activity_webview.xml create mode 100644 app/src/main/res/menu/menu_webview.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/values-w820dp/dimens.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle 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 @@ + + + + + + +