From ae2ee09aa7a2afc19f5603c9bc021f98888d7b78 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 15 Nov 2016 21:16:23 -0700 Subject: [PATCH] Create Java subpackage folders. --- app/build.gradle | 4 +- .../com/stoutner/privacybrowser/BannerAd.java | 14 +- app/src/free/res/layout/main_webview.xml | 2 +- app/src/main/AndroidManifest.xml | 22 +-- .../About.java} | 9 +- .../Bookmarks.java} | 114 +++++++------ .../BookmarksDatabaseView.java} | 31 ++-- .../Guide.java} | 9 +- .../MainWebView.java} | 36 +++-- .../Settings.java} | 6 +- .../{ => adapters}/HistoryArrayAdapter.java | 9 +- .../{ => definitions}/History.java | 10 +- .../dialogs/CreateBookmark.java | 152 ++++++++++++++++++ .../{ => dialogs}/CreateBookmarkFolder.java | 7 +- .../CreateHomeScreenShortcut.java | 7 +- .../{ => dialogs}/DownloadFile.java | 4 +- .../{ => dialogs}/DownloadImage.java | 4 +- .../{ => dialogs}/EditBookmark.java | 21 ++- .../{ => dialogs}/EditBookmarkFolder.java | 19 ++- .../{ => dialogs}/MoveToFolder.java | 40 ++--- .../{ => dialogs}/SslCertificateError.java | 4 +- .../{ => dialogs}/UrlHistory.java | 6 +- .../{ => dialogs}/ViewSslCertificate.java | 11 +- .../AboutTab.java} | 13 +- .../GuideTab.java} | 12 +- .../{ => fragments}/SettingsFragment.java | 4 +- .../BookmarksDatabaseHelper.java} | 58 +++---- .../{ => helpers}/OrbotProxyHelper.java | 13 +- app/src/main/res/layout/bare_webview.xml | 2 +- app/src/main/res/layout/guide_tab_webview.xml | 2 +- .../res/layout/main_coordinatorlayout.xml | 2 +- app/src/main/res/layout/main_webview.xml | 2 +- .../main/res/menu/webview_options_menu.xml | 2 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- .../com/stoutner/privacybrowser/BannerAd.java | 14 +- 36 files changed, 448 insertions(+), 221 deletions(-) rename app/src/main/java/com/stoutner/privacybrowser/{AboutActivity.java => activities/About.java} (93%) rename app/src/main/java/com/stoutner/privacybrowser/{BookmarksActivity.java => activities/Bookmarks.java} (90%) rename app/src/main/java/com/stoutner/privacybrowser/{BookmarksDatabaseViewActivity.java => activities/BookmarksDatabaseView.java} (88%) rename app/src/main/java/com/stoutner/privacybrowser/{GuideActivity.java => activities/Guide.java} (94%) rename app/src/main/java/com/stoutner/privacybrowser/{MainWebViewActivity.java => activities/MainWebView.java} (98%) rename app/src/main/java/com/stoutner/privacybrowser/{SettingsActivity.java => activities/Settings.java} (88%) rename app/src/main/java/com/stoutner/privacybrowser/{ => adapters}/HistoryArrayAdapter.java (90%) rename app/src/main/java/com/stoutner/privacybrowser/{ => definitions}/History.java (84%) create mode 100644 app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmark.java rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/CreateBookmarkFolder.java (96%) rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/CreateHomeScreenShortcut.java (97%) rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/DownloadFile.java (99%) rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/DownloadImage.java (98%) rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/EditBookmark.java (91%) rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/EditBookmarkFolder.java (91%) rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/MoveToFolder.java (89%) rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/SslCertificateError.java (99%) rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/UrlHistory.java (98%) rename app/src/main/java/com/stoutner/privacybrowser/{ => dialogs}/ViewSslCertificate.java (96%) rename app/src/main/java/com/stoutner/privacybrowser/{AboutTabFragment.java => fragments/AboutTab.java} (97%) rename app/src/main/java/com/stoutner/privacybrowser/{GuideTabFragment.java => fragments/GuideTab.java} (91%) rename app/src/main/java/com/stoutner/privacybrowser/{ => fragments}/SettingsFragment.java (99%) rename app/src/main/java/com/stoutner/privacybrowser/{BookmarksDatabaseHandler.java => helpers/BookmarksDatabaseHelper.java} (89%) rename app/src/main/java/com/stoutner/privacybrowser/{ => helpers}/OrbotProxyHelper.java (90%) diff --git a/app/build.gradle b/app/build.gradle index 04c77a8a..5e97dbee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,9 +57,9 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:design:24.2.1' - // Only compile `com.google.android.gms:play-services-ads` for the free flavor. + // Only compile `com.google.firebase:firebase-ads:9.8.0` for the free flavor. freeCompile 'com.google.firebase:firebase-ads:9.8.0' } diff --git a/app/src/free/java/com/stoutner/privacybrowser/BannerAd.java b/app/src/free/java/com/stoutner/privacybrowser/BannerAd.java index cc933817..3f9d9a73 100644 --- a/app/src/free/java/com/stoutner/privacybrowser/BannerAd.java +++ b/app/src/free/java/com/stoutner/privacybrowser/BannerAd.java @@ -28,8 +28,8 @@ import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdSize; import com.google.android.gms.ads.AdView; -class BannerAd extends AppCompatActivity{ - static void requestAd(View view) { +public class BannerAd extends AppCompatActivity{ + public static void requestAd(View view) { // Cast view to an AdView. AdView adView = (AdView) view; @@ -38,7 +38,7 @@ class BannerAd extends AppCompatActivity{ adView.loadAd(adRequest); } - static void reloadAfterRotate (View view, Context applicationContext, String ad_id) { + public static void reloadAfterRotate (View view, Context applicationContext, String ad_id) { // Cast view to an AdView. AdView adView = (AdView) view; @@ -64,7 +64,7 @@ class BannerAd extends AppCompatActivity{ adView.loadAd(adRequest); } - static void hideAd(View view) { + public static void hideAd(View view) { // Cast view to an AdView. AdView adView = (AdView) view; @@ -72,7 +72,7 @@ class BannerAd extends AppCompatActivity{ adView.setVisibility(View.GONE); } - static void showAd(View view) { + public static void showAd(View view) { // Cast view to an AdView. AdView adView = (AdView) view; @@ -80,7 +80,7 @@ class BannerAd extends AppCompatActivity{ adView.setVisibility(View.VISIBLE); } - static void pauseAd(View view) { + public static void pauseAd(View view) { // Cast view to an AdView. AdView adView = (AdView) view; @@ -88,7 +88,7 @@ class BannerAd extends AppCompatActivity{ adView.pause(); } - static void resumeAd(View view) { + public static void resumeAd(View view) { // Cast view to an AdView. AdView adView = (AdView) view; diff --git a/app/src/free/res/layout/main_webview.xml b/app/src/free/res/layout/main_webview.xml index 403bb649..a342a0e7 100644 --- a/app/src/free/res/layout/main_webview.xml +++ b/app/src/free/res/layout/main_webview.xml @@ -28,7 +28,7 @@ android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" - tools:context="com.stoutner.privacybrowser.MainWebViewActivity" + tools:context="com.stoutner.privacybrowser.activities.MainWebView" tools:showIn="@layout/coordinator_layout"> . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.activities; import android.os.Bundle; import android.support.design.widget.TabLayout; @@ -29,7 +29,10 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; -public class AboutActivity extends AppCompatActivity { +import com.stoutner.privacybrowser.fragments.AboutTab; +import com.stoutner.privacybrowser.R; + +public class About extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -97,7 +100,7 @@ public class AboutActivity extends AppCompatActivity { @Override // Setup each tab. public Fragment getItem(int tab) { - return AboutTabFragment.createTab(tab); + return AboutTab.createTab(tab); } } } diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/Bookmarks.java similarity index 90% rename from app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java rename to app/src/main/java/com/stoutner/privacybrowser/activities/Bookmarks.java index 15264c69..78cb806e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/Bookmarks.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.activities; import android.app.Activity; import android.content.Context; @@ -51,15 +51,23 @@ import android.widget.ListView; import android.widget.RadioButton; import android.widget.TextView; +import com.stoutner.privacybrowser.dialogs.EditBookmark; +import com.stoutner.privacybrowser.dialogs.EditBookmarkFolder; +import com.stoutner.privacybrowser.dialogs.MoveToFolder; +import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper; +import com.stoutner.privacybrowser.dialogs.CreateBookmark; +import com.stoutner.privacybrowser.dialogs.CreateBookmarkFolder; + import java.io.ByteArrayOutputStream; -public class BookmarksActivity extends AppCompatActivity implements CreateBookmark.CreateBookmarkListener, +public class Bookmarks extends AppCompatActivity implements CreateBookmark.CreateBookmarkListener, CreateBookmarkFolder.CreateBookmarkFolderListener, EditBookmark.EditBookmarkListener, EditBookmarkFolder.EditBookmarkFolderListener, MoveToFolder.MoveToFolderListener { - // `bookmarksDatabaseHandler` is public static so it can be accessed from `EditBookmark` and `MoveToFolder`. It is also used in `onCreate()`, + // `bookmarksDatabaseHelper` is public static so it can be accessed from `EditBookmark` and `MoveToFolder`. It is also used in `onCreate()`, // `onCreateBookmarkCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`. - public static BookmarksDatabaseHandler bookmarksDatabaseHandler; + public static BookmarksDatabaseHelper bookmarksDatabaseHelper; // `currentFolder` is public static so it can be accessed from `MoveToFolder`. // It is used in `onCreate`, `onOptionsItemSelected()`, `onCreateBookmarkCreate`, `onCreateBookmarkFolderCreate`, and `onEditBookmarkSave`. @@ -105,8 +113,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Initialize the database handler and the ListView. // `this` specifies the context. The two `null`s do not specify the database name or a `CursorFactory`. - // The `0` is to specify a database version, but that is set instead using a constant in `BookmarksDatabaseHandler`. - bookmarksDatabaseHandler = new BookmarksDatabaseHandler(this, null, null, 0); + // The `0` is to specify a database version, but that is set instead using a constant in `BookmarksDatabaseHelper`. + bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this, null, null, 0); bookmarksListView = (ListView) findViewById(R.id.bookmarks_listview); // Set currentFolder to the home folder, which is null in the database. @@ -125,19 +133,19 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma int databaseID = (int) id; // Get the bookmark `Cursor` and move it to the first row. - Cursor bookmarkCursor = bookmarksDatabaseHandler.getBookmarkCursor(databaseID); + Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(databaseID); bookmarkCursor.moveToFirst(); // If the bookmark is a folder load its contents into the ListView. - if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1) { + if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) { // Update `currentFolder`. - currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); // Reload the ListView with `currentFolder`. updateBookmarksListView(currentFolder); } else { // Load the URL into `mainWebView`. - // Get the bookmark URL and assign it to formattedUrlString. `mainWebView` will automatically reload when `BookmarksActivity` closes. - MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_URL)); + // Get the bookmark URL and assign it to formattedUrlString. `mainWebView` will automatically reload when `Bookmarks` closes. + MainWebView.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)); NavUtils.navigateUpFromSameTask(bookmarksActivity); } @@ -282,15 +290,15 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma if (databaseId == selectedBookmarkDatabaseId || nextBookmarkDatabaseId == selectedBookmarkDatabaseId) { if (databaseId == selectedBookmarkDatabaseId) { // Move the selected bookmark up one and store the new bookmark position. - bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i - 1); + bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i - 1); selectedBookmarkNewPosition = i - 1; } else { // Move the bookmark above the selected bookmark down one. - bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i + 1); + bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i + 1); } } else { // Reset the rest of the bookmarks' DISPLAY_ORDER to match the position in the ListView. // This isn't necessary, but it clears out any stray values that might have crept into the database. - bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i); + bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i); } } @@ -319,15 +327,15 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma if (databaseId == selectedBookmarkDatabaseId || previousBookmarkDatabaseId == selectedBookmarkDatabaseId) { if (databaseId == selectedBookmarkDatabaseId) { // Move the selected bookmark down one and store the new bookmark position. - bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i + 1); + bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i + 1); selectedBookmarkNewPosition = i + 1; } else { // Move the bookmark below the selected bookmark up one. - bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i - 1); + bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i - 1); } } else { // Reset the rest of the bookmark' DISPLAY_ORDER to match the position in the ListView. // This isn't necessary, but it clears out any stray values that might have crept into the database. - bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i); + bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i); } } @@ -360,14 +368,14 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Move to the selected database ID and find out if it is a folder. bookmarksCursor.moveToPosition(selectedBookmarkPosition); - boolean isFolder = (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1); + boolean isFolder = (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1); // Store `checkedItemIds` for use by the `AlertDialog`. checkedItemIds = bookmarksListView.getCheckedItemIds(); if (isFolder) { // Save the current folder name. - oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); // Show the `EditBookmarkFolder` `AlertDialog` and name the instance `@string/edit_folder`. AppCompatDialogFragment editFolderDialog = new EditBookmarkFolder(); @@ -447,12 +455,12 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Convert `databaseIdLong` to an int. int databaseIdInt = (int) databaseIdLong; - if (bookmarksDatabaseHandler.isFolder(databaseIdInt)) { + if (bookmarksDatabaseHelper.isFolder(databaseIdInt)) { deleteBookmarkFolderContents(databaseIdInt); } // Delete `databaseIdInt`. - bookmarksDatabaseHandler.deleteBookmark(databaseIdInt); + bookmarksDatabaseHelper.deleteBookmark(databaseIdInt); } break; } @@ -515,12 +523,12 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma switch (menuItemId) { case android.R.id.home: - // Exit BookmarksActivity if currently at the home folder. + // Exit Bookmarks if currently at the home folder. if (currentFolder.isEmpty()) { NavUtils.navigateUpFromSameTask(this); } else { // Navigate up one folder. // Place the former parent folder in `currentFolder`. - currentFolder = bookmarksDatabaseHandler.getParentFolder(currentFolder); + currentFolder = bookmarksDatabaseHelper.getParentFolder(currentFolder); updateBookmarksListView(currentFolder); } @@ -541,8 +549,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma break; case R.id.bookmarks_database_view: - // Launch `BookmarksDatabaseViewActivity`. - Intent bookmarksDatabaseViewIntent = new Intent(this, BookmarksDatabaseViewActivity.class); + // Launch `BookmarksDatabaseView`. + Intent bookmarksDatabaseViewIntent = new Intent(this, BookmarksDatabaseView.class); startActivity(bookmarksDatabaseViewIntent); break; } @@ -560,14 +568,14 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Convert the favoriteIcon Bitmap to a byte array. ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream(); // `0` is for lossless compression (the only option for a PNG). - MainWebViewActivity.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream); + MainWebView.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream); byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray(); // Display the new bookmark below the current items in the (0 indexed) list. int newBookmarkDisplayOrder = bookmarksListView.getCount(); // Create the bookmark. - bookmarksDatabaseHandler.createBookmark(bookmarkNameString, bookmarkUrlString, newBookmarkDisplayOrder, currentFolder, favoriteIconByteArray); + bookmarksDatabaseHelper.createBookmark(bookmarkNameString, bookmarkUrlString, newBookmarkDisplayOrder, currentFolder, favoriteIconByteArray); // Refresh the ListView. `setSelection` scrolls to the bottom of the list. updateBookmarksListView(currentFolder); @@ -581,7 +589,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma String folderNameString = createFolderNameEditText.getText().toString(); // Check to see if the folder already exists. - Cursor bookmarkFolderCursor = bookmarksDatabaseHandler.getFolderCursor(folderNameString); + Cursor bookmarkFolderCursor = bookmarksDatabaseHelper.getFolderCursor(folderNameString); int existingFoldersWithNewName = bookmarkFolderCursor.getCount(); bookmarkFolderCursor.close(); if (folderNameString.isEmpty() || (existingFoldersWithNewName > 0)) { @@ -598,7 +606,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable; folderIconBitmap = folderIconBitmapDrawable.getBitmap(); } else { // Assign `favoriteIcon` from the `WebView`. - folderIconBitmap = MainWebViewActivity.favoriteIcon; + folderIconBitmap = MainWebView.favoriteIcon; } // Convert `folderIconBitmap` to a byte array. `0` is for lossless compression (the only option for a PNG). @@ -609,11 +617,11 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Move all the bookmarks down one in the display order. for (int i = 0; i < bookmarksListView.getCount(); i++) { int databaseId = (int) bookmarksListView.getItemIdAtPosition(i); - bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i + 1); + bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i + 1); } // Create the folder, placing it at the top of the ListView - bookmarksDatabaseHandler.createFolder(folderNameString, 0, currentFolder, folderIconByteArray); + bookmarksDatabaseHelper.createFolder(folderNameString, 0, currentFolder, folderIconByteArray); // Refresh the ListView. updateBookmarksListView(currentFolder); @@ -636,14 +644,14 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma RadioButton currentBookmarkIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton); if (currentBookmarkIconRadioButton.isChecked()) { // Update the bookmark without changing the favorite icon. - bookmarksDatabaseHandler.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString); + bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString); } else { // Update the bookmark using the `WebView` favorite icon. ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream(); - MainWebViewActivity.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream); + MainWebView.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream); byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray(); // Update the bookmark and the favorite icon. - bookmarksDatabaseHandler.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, newFavoriteIconByteArray); + bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, newFavoriteIconByteArray); } // Close the contextual action mode. @@ -661,7 +669,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma String newFolderNameString = editFolderNameEditText.getText().toString(); // Check to see if the new folder name is unique. - Cursor bookmarkFolderCursor = bookmarksDatabaseHandler.getFolderCursor(newFolderNameString); + Cursor bookmarkFolderCursor = bookmarksDatabaseHelper.getFolderCursor(newFolderNameString); int existingFoldersWithNewName = bookmarkFolderCursor.getCount(); bookmarkFolderCursor.close(); if ( ((existingFoldersWithNewName == 0) || newFolderNameString.equals(oldFolderNameString)) && !newFolderNameString.isEmpty()) { @@ -677,7 +685,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma if (currentFolderIconRadioButton.isChecked()) { // Update the folder name if it has changed without modifying the favorite icon. if (!newFolderNameString.equals(oldFolderNameString)) { - bookmarksDatabaseHandler.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString); + bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString); // Refresh the `ListView`. `setSelection` scrolls to the position of the folder that was edited. updateBookmarksListView(currentFolder); @@ -693,7 +701,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable; folderIconBitmap = folderIconBitmapDrawable.getBitmap(); } else { // Get the web page icon `ImageView` from the `Dialog`. - folderIconBitmap = MainWebViewActivity.favoriteIcon; + folderIconBitmap = MainWebView.favoriteIcon; } // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG). @@ -701,7 +709,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream); byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray(); - bookmarksDatabaseHandler.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray); + bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray); // Refresh the `ListView`. `setSelection` scrolls to the position of the folder that was edited. updateBookmarksListView(currentFolder); @@ -736,7 +744,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma newFolderName = ""; } else { // Get the new folder name from the database. - newFolderName = bookmarksDatabaseHandler.getFolderName(newFolderDatabaseId); + newFolderName = bookmarksDatabaseHelper.getFolderName(newFolderDatabaseId); } // Get a long array with the the database ID of the selected bookmarks. @@ -746,7 +754,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma int databaseIdInt = (int) databaseIdLong; // Move the selected bookmark to the new folder. - bookmarksDatabaseHandler.moveToFolder(databaseIdInt, newFolderName); + bookmarksDatabaseHelper.moveToFolder(databaseIdInt, newFolderName); } // Refresh the `ListView`. @@ -759,7 +767,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma private void updateBookmarksListView(String folderName) { // Get a `Cursor` with the current contents of the bookmarks database. - bookmarksCursor = bookmarksDatabaseHandler.getAllBookmarksCursorByDisplayOrder(folderName); + bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(folderName); // Setup `bookmarksCursorAdapter` with `this` context. `false` disables autoRequery. CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) { @@ -772,7 +780,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma @Override public void bindView(View view, Context context, Cursor cursor) { // Get the favorite icon byte array from the `Cursor`. - byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last. Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length); @@ -783,12 +791,12 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Get the bookmark name from the cursor and display it in `bookmarkNameTextView`. - String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmark_name); bookmarkNameTextView.setText(bookmarkNameString); // Make the font bold for folders. - if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1) { + if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) { bookmarkNameTextView.setTypeface(Typeface.DEFAULT_BOLD); } else { // Reset the font to default for normal bookmarks. bookmarkNameTextView.setTypeface(Typeface.DEFAULT); @@ -809,7 +817,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma private void updateBookmarksListViewExcept(long[] exceptIdLongArray, String folderName) { // Get a `Cursor` with the current contents of the bookmarks database except for the specified database IDs. - bookmarksCursor = bookmarksDatabaseHandler.getBookmarksCursorExcept(exceptIdLongArray, folderName); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksCursorExcept(exceptIdLongArray, folderName); // Setup `bookmarksCursorAdapter` with `this` context. `false` disables autoRequery. CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) { @@ -822,7 +830,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma @Override public void bindView(View view, Context context, Cursor cursor) { // Get the favorite icon byte array from the cursor. - byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a Bitmap beginning at the first byte and ending at the last. Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length); @@ -833,12 +841,12 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Get the bookmark name from the cursor and display it in `bookmarkNameTextView`. - String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmark_name); bookmarkNameTextView.setText(bookmarkNameString); // Make the font bold for folders. - if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1) { + if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) { // The first argument is `null` because we don't want to change the font. bookmarkNameTextView.setTypeface(null, Typeface.BOLD); } else { // Reset the font to default. @@ -853,24 +861,24 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma private void deleteBookmarkFolderContents(int databaseId) { // Get the name of the folder. - String folderName = bookmarksDatabaseHandler.getFolderName(databaseId); + String folderName = bookmarksDatabaseHelper.getFolderName(databaseId); // Get the contents of the folder. - Cursor folderCursor = bookmarksDatabaseHandler.getAllBookmarksCursorByDisplayOrder(folderName); + Cursor folderCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(folderName); for (int i = 0; i < folderCursor.getCount(); i++) { // Move `folderCursor` to the current row. folderCursor.moveToPosition(i); // Get the database ID of the item. - int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndex(BookmarksDatabaseHandler._ID)); + int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndex(BookmarksDatabaseHelper._ID)); // If this is a folder, delete the contents first. - if (bookmarksDatabaseHandler.isFolder(itemDatabaseId)) { + if (bookmarksDatabaseHelper.isFolder(itemDatabaseId)) { deleteBookmarkFolderContents(itemDatabaseId); } - bookmarksDatabaseHandler.deleteBookmark(itemDatabaseId); + bookmarksDatabaseHelper.deleteBookmark(itemDatabaseId); } } } \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseView.java similarity index 88% rename from app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseViewActivity.java rename to app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseView.java index a24e6948..e7795fbb 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseView.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.activities; import android.content.Context; import android.database.Cursor; @@ -36,9 +36,12 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; -public class BookmarksDatabaseViewActivity extends AppCompatActivity { - // `bookmarksDatabaseHandler` is used in `onCreate()` and `updateBookmarksListView()`. - private BookmarksDatabaseHandler bookmarksDatabaseHandler; +import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper; + +public class BookmarksDatabaseView extends AppCompatActivity { + // `bookmarksDatabaseHelper` is used in `onCreate()` and `updateBookmarksListView()`. + private BookmarksDatabaseHelper bookmarksDatabaseHelper; // `bookmarksListView` is used in `onCreate()` and `updateBookmarksListView()`. private ListView bookmarksListView; @@ -59,8 +62,8 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity { // Initialize the database handler and the ListView. // `this` specifies the context. The two `null`s do not specify the database name or a `CursorFactory`. - // The `0` is to specify a database version, but that is set instead using a constant in `BookmarksDatabaseHandler`. - bookmarksDatabaseHandler = new BookmarksDatabaseHandler(this, null, null, 0); + // The `0` is to specify a database version, but that is set instead using a constant in `BookmarksDatabaseHelper`. + bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this, null, null, 0); bookmarksListView = (ListView) findViewById(R.id.bookmarks_database_view_listview); // Display the bookmarks in the ListView. @@ -70,7 +73,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity { private void updateBookmarksListView() { // Get a `Cursor` with the current contents of the bookmarks database. - final Cursor bookmarksCursor = bookmarksDatabaseHandler.getAllBookmarksCursor(); + final Cursor bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursor(); // Setup `bookmarksCursorAdapter` with `this` context. The `false` disables autoRequery. CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) { @@ -82,15 +85,15 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity { @Override public void bindView(View view, Context context, Cursor cursor) { - boolean isFolder = (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1); + boolean isFolder = (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1); // Get the database ID from the `Cursor` and display it in `bookmarkDatabaseIdTextView`. - int bookmarkDatabaseId = cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler._ID)); + int bookmarkDatabaseId = cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper._ID)); TextView bookmarkDatabaseIdTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_database_id); bookmarkDatabaseIdTextView.setText(String.valueOf(bookmarkDatabaseId)); // Get the favorite icon byte array from the `Cursor`. - byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a `Bitmap` beginning at the beginning at the first byte and ending at the last. Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length); // Display the bitmap in `bookmarkFavoriteIcon`. @@ -98,7 +101,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity { bookmarkFavoriteIcon.setImageBitmap(favoriteIconBitmap); // Get the bookmark name from the `Cursor` and display it in `bookmarkNameTextView`. - String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_bookmark_name); bookmarkNameTextView.setText(bookmarkNameString); // Make the font bold for folders. @@ -110,12 +113,12 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity { } // Get the display order from the `Cursor` and display it in `bookmarkDisplayOrderTextView`. - int bookmarkDisplayOrder = cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.DISPLAY_ORDER)); + int bookmarkDisplayOrder = cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)); TextView bookmarkDisplayOrderTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_display_order); bookmarkDisplayOrderTextView.setText(String.valueOf(bookmarkDisplayOrder)); // Get the parent folder from the `Cursor` and display it in `bookmarkParentFolder`. - String bookmarkParentFolder = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.PARENT_FOLDER)); + String bookmarkParentFolder = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.PARENT_FOLDER)); ImageView parentFolderImageView = (ImageView) view.findViewById(R.id.bookmarks_database_view_parent_folder_icon); TextView bookmarkParentFolderTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_parent_folder); // Make the folder name gray if it is the home folder. @@ -130,7 +133,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity { } // Get the bookmark URL form the `Cursor` and display it in `bookmarkUrlTextView`. - String bookmarkUrlString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_URL)); + String bookmarkUrlString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)); TextView bookmarkUrlTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_bookmark_url); bookmarkUrlTextView.setText(bookmarkUrlString); if (isFolder) { diff --git a/app/src/main/java/com/stoutner/privacybrowser/GuideActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/Guide.java similarity index 94% rename from app/src/main/java/com/stoutner/privacybrowser/GuideActivity.java rename to app/src/main/java/com/stoutner/privacybrowser/activities/Guide.java index 22b92852..2861f0e3 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/GuideActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/Guide.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.activities; import android.os.Bundle; import android.support.design.widget.TabLayout; @@ -29,7 +29,10 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; -public class GuideActivity extends AppCompatActivity { +import com.stoutner.privacybrowser.fragments.GuideTab; +import com.stoutner.privacybrowser.R; + +public class Guide extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -102,7 +105,7 @@ public class GuideActivity extends AppCompatActivity { @Override // Setup each tab. public Fragment getItem(int tab) { - return GuideTabFragment.createTab(tab); + return GuideTab.createTab(tab); } } diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebView.java similarity index 98% rename from app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java rename to app/src/main/java/com/stoutner/privacybrowser/activities/MainWebView.java index 077aa49b..5fdd814e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebView.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.activities; import android.annotation.SuppressLint; import android.app.DialogFragment; @@ -76,6 +76,16 @@ import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; +import com.stoutner.privacybrowser.BannerAd; +import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.helpers.OrbotProxyHelper; +import com.stoutner.privacybrowser.dialogs.CreateHomeScreenShortcut; +import com.stoutner.privacybrowser.dialogs.DownloadFile; +import com.stoutner.privacybrowser.dialogs.DownloadImage; +import com.stoutner.privacybrowser.dialogs.SslCertificateError; +import com.stoutner.privacybrowser.dialogs.UrlHistory; +import com.stoutner.privacybrowser.dialogs.ViewSslCertificate; + import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; @@ -84,18 +94,18 @@ import java.util.HashMap; import java.util.Map; // We need to use AppCompatActivity from android.support.v7.app.AppCompatActivity to have access to the SupportActionBar until the minimum API is >= 21. -public class MainWebViewActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, CreateHomeScreenShortcut.CreateHomeScreenSchortcutListener, +public class MainWebView extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, CreateHomeScreenShortcut.CreateHomeScreenSchortcutListener, SslCertificateError.SslCertificateErrorListener, DownloadFile.DownloadFileListener, DownloadImage.DownloadImageListener, UrlHistory.UrlHistoryListener { // `appBar` is public static so it can be accessed from `OrbotProxyHelper`. // It is also used in `onCreate()`, `onOptionsItemSelected()`, and `closeFindOnPage()`. public static ActionBar appBar; - // `favoriteIcon` is public static so it can be accessed from `CreateHomeScreenShortcut`, `BookmarksActivity`, `CreateBookmark`, `CreateBookmarkFolder`, and `EditBookmark`. + // `favoriteIcon` is public static so it can be accessed from `CreateHomeScreenShortcut`, `Bookmarks`, `CreateBookmark`, `CreateBookmarkFolder`, and `EditBookmark`. // It is also used in `onCreate()` and `onCreateHomeScreenShortcutCreate()`. public static Bitmap favoriteIcon; - // `formattedUrlString` is public static so it can be accessed from `BookmarksActivity`. + // `formattedUrlString` is public static so it can be accessed from `Bookmarks`. // It is also used in `onCreate()`, `onOptionsItemSelected()`, `onCreateHomeScreenShortcutCreate()`, and `loadUrlFromTextBox()`. public static String formattedUrlString; @@ -942,8 +952,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation break; case R.id.bookmarks: - // Launch BookmarksActivity. - Intent bookmarksIntent = new Intent(this, BookmarksActivity.class); + // Launch Bookmarks. + Intent bookmarksIntent = new Intent(this, Bookmarks.class); startActivity(bookmarksIntent); break; @@ -958,20 +968,20 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation break; case R.id.settings: - // Launch `SettingsActivity`. - Intent settingsIntent = new Intent(this, SettingsActivity.class); + // Launch `Settings`. + Intent settingsIntent = new Intent(this, Settings.class); startActivity(settingsIntent); break; case R.id.guide: - // Launch `GuideActivity`. - Intent guideIntent = new Intent(this, GuideActivity.class); + // Launch `Guide`. + Intent guideIntent = new Intent(this, Guide.class); startActivity(guideIntent); break; case R.id.about: - // Launch `AboutActivity`. - Intent aboutIntent = new Intent(this, AboutActivity.class); + // Launch `About`. + Intent aboutIntent = new Intent(this, About.class); startActivity(aboutIntent); break; @@ -1341,7 +1351,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation public void onRestart() { super.onRestart(); - // Apply the settings from shared preferences, which might have been changed in `SettingsActivity`. + // Apply the settings from shared preferences, which might have been changed in `Settings`. applySettings(); // Update the privacy icon. `true` runs `invalidateOptionsMenu` as the last step. diff --git a/app/src/main/java/com/stoutner/privacybrowser/SettingsActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/Settings.java similarity index 88% rename from app/src/main/java/com/stoutner/privacybrowser/SettingsActivity.java rename to app/src/main/java/com/stoutner/privacybrowser/activities/Settings.java index 39051382..027482c7 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/SettingsActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/Settings.java @@ -17,13 +17,15 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.activities; import android.os.Bundle; import android.preference.PreferenceFragment; import android.support.v7.app.AppCompatActivity; -public class SettingsActivity extends AppCompatActivity { +import com.stoutner.privacybrowser.fragments.SettingsFragment; + +public class Settings extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/com/stoutner/privacybrowser/HistoryArrayAdapter.java b/app/src/main/java/com/stoutner/privacybrowser/adapters/HistoryArrayAdapter.java similarity index 90% rename from app/src/main/java/com/stoutner/privacybrowser/HistoryArrayAdapter.java rename to app/src/main/java/com/stoutner/privacybrowser/adapters/HistoryArrayAdapter.java index 6b7f0561..1135638c 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/HistoryArrayAdapter.java +++ b/app/src/main/java/com/stoutner/privacybrowser/adapters/HistoryArrayAdapter.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.adapters; import android.content.Context; import android.graphics.Typeface; @@ -29,14 +29,17 @@ import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; +import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.definitions.History; + import java.util.ArrayList; -class HistoryArrayAdapter extends ArrayAdapter { +public class HistoryArrayAdapter extends ArrayAdapter { // `currentPage` is used in `HistoryArrayAdapter` and `getView()`. private int currentPage; - HistoryArrayAdapter(Context context, ArrayList historyArrayList, int currentPageId) { + public HistoryArrayAdapter(Context context, ArrayList historyArrayList, int currentPageId) { // We need to call `super` from the base `ArrayAdapter`. `0` is the `textViewResourceId`. super(context, 0, historyArrayList); diff --git a/app/src/main/java/com/stoutner/privacybrowser/History.java b/app/src/main/java/com/stoutner/privacybrowser/definitions/History.java similarity index 84% rename from app/src/main/java/com/stoutner/privacybrowser/History.java rename to app/src/main/java/com/stoutner/privacybrowser/definitions/History.java index 0548c2b5..e5804218 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/History.java +++ b/app/src/main/java/com/stoutner/privacybrowser/definitions/History.java @@ -17,17 +17,17 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.definitions; import android.graphics.Bitmap; // Create a `History` object. -class History { +public class History { // Create the `History` package-local variables. - Bitmap entryFavoriteIcon; - String entryUrl; + public Bitmap entryFavoriteIcon; + public String entryUrl; - History(Bitmap entryFavoriteIcon, String entryUrl){ + public History(Bitmap entryFavoriteIcon, String entryUrl){ // Populate the package-local variables. this.entryFavoriteIcon = entryFavoriteIcon; this.entryUrl = entryUrl; diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmark.java new file mode 100644 index 00000000..77c58607 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmark.java @@ -0,0 +1,152 @@ +/** + * Copyright 2016 Soren Stoutner . + * + * This file is part of Privacy Browser . + * + * Privacy Browser is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privacy Browser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Privacy Browser. If not, see . + */ + +package com.stoutner.privacybrowser.dialogs; + +import android.annotation.SuppressLint; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.annotation.NonNull; +// If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard. +import android.support.v7.app.AlertDialog; +// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. +import android.support.v7.app.AppCompatDialogFragment; +import android.view.KeyEvent; +import android.view.View; +import android.view.WindowManager; +import android.widget.EditText; + +import com.stoutner.privacybrowser.activities.MainWebView; +import com.stoutner.privacybrowser.R; + +public class CreateBookmark extends AppCompatDialogFragment { + // The public interface is used to send information back to the parent activity. + public interface CreateBookmarkListener { + void onCreateBookmark(AppCompatDialogFragment dialogFragment); + } + + // `createBookmarkListener` is used in `onAttach()` and `onCreateDialog()` + private CreateBookmarkListener createBookmarkListener; + + + public void onAttach(Context context) { + super.onAttach(context); + + // Get a handle for `CreateBookmarkListener` from `context`. + try { + createBookmarkListener = (CreateBookmarkListener) context; + } catch(ClassCastException exception) { + throw new ClassCastException(context.toString() + " must implement CreateBookmarkListener."); + } + } + + // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`. + @SuppressLint("InflateParams") + @Override + @NonNull + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Create a drawable version of the favorite icon. + Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebView.favoriteIcon); + + // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); + dialogBuilder.setTitle(R.string.create_bookmark); + dialogBuilder.setIcon(favoriteIconDrawable); + // The parent view is `null` because it will be assigned by the `AlertDialog`. + dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.create_bookmark_dialog, null)); + + // Set an `onClick()` listener for the negative button. + dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Do nothing. The `AlertDialog` will close automatically. + } + }); + + // Set an `onClick()` listener for the positive button. + dialogBuilder.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Return the `DialogFragment` to the parent activity on create. + createBookmarkListener.onCreateBookmark(CreateBookmark.this); + } + }); + + + // Create an `AlertDialog` from the `AlertDialog.Builder`. + final AlertDialog alertDialog = dialogBuilder.create(); + + // Remove the warning below that `setSoftInputMode` might produce `java.lang.NullPointerException`. + assert alertDialog.getWindow() != null; + + // Show the keyboard when the `Dialog` is displayed on the screen. + alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + + // We need to show the `AlertDialog` before we can call `setOnKeyListener()` below. + alertDialog.show(); + + // Allow the `enter` key on the keyboard to create the bookmark from `create_bookmark_name_edittext`. + EditText createBookmarkNameEditText = (EditText) alertDialog.findViewById(R.id.create_bookmark_name_edittext); + assert createBookmarkNameEditText != null; // Remove the warning below that `createBookmarkNameEditText` might be `null`. + createBookmarkNameEditText.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down on the `enter` button, select the `PositiveButton` `Create`. + if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + // Trigger `createBookmarkListener` and return the `DialogFragment` to the parent activity. + createBookmarkListener.onCreateBookmark(CreateBookmark.this); + // Manually dismiss the `AlertDialog`. + alertDialog.dismiss(); + // Consume the event. + return true; + } else { // If any other key was pressed, do not consume the event. + return false; + } + } + }); + + // Set the formattedUrlString as the initial text of `create_bookmark_url_edittext`. + EditText createBookmarkUrlEditText = (EditText) alertDialog.findViewById(R.id.create_bookmark_url_edittext); + assert createBookmarkUrlEditText != null;// Remove the warning below that `createBookmarkUrlEditText` might be `null`. + createBookmarkUrlEditText.setText(MainWebView.formattedUrlString); + + // Allow the `enter` key on the keyboard to create the bookmark from `create_bookmark_url_edittext`. + createBookmarkUrlEditText.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down on the "enter" button, select the PositiveButton "Create". + if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + // Trigger `createBookmarkListener` and return the DialogFragment to the parent activity. + createBookmarkListener.onCreateBookmark(CreateBookmark.this); + // Manually dismiss the `AlertDialog`. + alertDialog.dismiss(); + // Consume the event. + return true; + } else { // If any other key was pressed, do not consume the event. + return false; + } + } + }); + + // `onCreateDialog()` requires the return of an `AlertDialog`. + return alertDialog; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkFolder.java similarity index 96% rename from app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkFolder.java index 46d2ed96..e3afd11b 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkFolder.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.Dialog; @@ -35,6 +35,9 @@ import android.view.WindowManager; import android.widget.EditText; import android.widget.ImageView; +import com.stoutner.privacybrowser.activities.MainWebView; +import com.stoutner.privacybrowser.R; + public class CreateBookmarkFolder extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface CreateBookmarkFolderListener { @@ -118,7 +121,7 @@ public class CreateBookmarkFolder extends AppCompatDialogFragment { // Display the current favorite icon. ImageView webPageIconImageView = (ImageView) alertDialog.findViewById(R.id.create_folder_web_page_icon); assert webPageIconImageView != null; // Remove the warning that `webPageIconImageView` may be null. - webPageIconImageView.setImageBitmap(MainWebViewActivity.favoriteIcon); + webPageIconImageView.setImageBitmap(MainWebView.favoriteIcon); // `onCreateDialog()` requires the return of an `AlertDialog`. return alertDialog; diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateHomeScreenShortcut.java similarity index 97% rename from app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateHomeScreenShortcut.java index 6159f8da..d55f7ff7 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateHomeScreenShortcut.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.Dialog; @@ -37,6 +37,9 @@ import android.view.View; import android.view.WindowManager; import android.widget.EditText; +import com.stoutner.privacybrowser.activities.MainWebView; +import com.stoutner.privacybrowser.R; + public class CreateHomeScreenShortcut extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface CreateHomeScreenSchortcutListener { @@ -65,7 +68,7 @@ public class CreateHomeScreenShortcut extends AppCompatDialogFragment { LayoutInflater layoutInflater = getActivity().getLayoutInflater(); // Create a drawable version of the favorite icon. - Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIcon); + Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebView.favoriteIcon); // Use `AlertDialog.Builder` to create the `AlertDialog`. `R.style.LightAlertDialog` formats the color of the button text. AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); diff --git a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadFile.java similarity index 99% rename from app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadFile.java index 1a68f71f..fe2048af 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadFile.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.Dialog; @@ -37,6 +37,8 @@ import android.view.WindowManager; import android.widget.EditText; import android.widget.TextView; +import com.stoutner.privacybrowser.R; + import java.util.Locale; public class DownloadFile extends AppCompatDialogFragment { diff --git a/app/src/main/java/com/stoutner/privacybrowser/DownloadImage.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadImage.java similarity index 98% rename from app/src/main/java/com/stoutner/privacybrowser/DownloadImage.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadImage.java index 3b9ee79c..ceb0d624 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/DownloadImage.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadImage.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.Dialog; @@ -34,6 +34,8 @@ import android.view.View; import android.view.WindowManager; import android.widget.EditText; +import com.stoutner.privacybrowser.R; + // `android.support.v7.app.AlertDialog` uses more of the horizontal screen real estate versus `android.app.AlertDialog's` smaller width. // We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. public class DownloadImage extends AppCompatDialogFragment { diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmark.java similarity index 91% rename from app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmark.java index 3ce8204d..a02a4deb 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmark.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.Dialog; @@ -38,6 +38,11 @@ import android.view.WindowManager; import android.widget.EditText; import android.widget.ImageView; +import com.stoutner.privacybrowser.activities.Bookmarks; +import com.stoutner.privacybrowser.activities.MainWebView; +import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper; + public class EditBookmark extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface EditBookmarkListener { @@ -64,11 +69,11 @@ public class EditBookmark extends AppCompatDialogFragment { @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`. - long[] selectedBookmarkLongArray = BookmarksActivity.checkedItemIds; + long[] selectedBookmarkLongArray = Bookmarks.checkedItemIds; int selectedBookmarkDatabaseId = (int) selectedBookmarkLongArray[0]; // Get a `Cursor` with the specified bookmark and move it to the first position. - Cursor bookmarkCursor = BookmarksActivity.bookmarksDatabaseHandler.getBookmarkCursor(selectedBookmarkDatabaseId); + Cursor bookmarkCursor = Bookmarks.bookmarksDatabaseHelper.getBookmarkCursor(selectedBookmarkDatabaseId); bookmarkCursor.moveToFirst(); // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. @@ -108,7 +113,7 @@ public class EditBookmark extends AppCompatDialogFragment { alertDialog.show(); // Get the current favorite icon byte array from the `Cursor`. - byte[] currentIconByteArray = bookmarkCursor.getBlob(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + byte[] currentIconByteArray = bookmarkCursor.getBlob(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last. Bitmap currentIconBitmap = BitmapFactory.decodeByteArray(currentIconByteArray, 0, currentIconByteArray.length); // Display `currentIconBitmap` in `edit_bookmark_current_icon`. @@ -116,15 +121,15 @@ public class EditBookmark extends AppCompatDialogFragment { assert currentIconImageView != null; // Remove the warning below that `currentIconImageView` might be null; currentIconImageView.setImageBitmap(currentIconBitmap); - // Get a `Bitmap` of the favorite icon from `MainWebViewActivity` and display it in `edit_bookmark_web_page_favorite_icon`. + // Get a `Bitmap` of the favorite icon from `MainWebView` and display it in `edit_bookmark_web_page_favorite_icon`. ImageView newFavoriteIconImageView = (ImageView) alertDialog.findViewById(R.id.edit_bookmark_web_page_favorite_icon); assert newFavoriteIconImageView != null; // Remove the warning below that `newFavoriteIcon` might be null. - newFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIcon); + newFavoriteIconImageView.setImageBitmap(MainWebView.favoriteIcon); // Load the text for `edit_bookmark_name_edittext`. EditText bookmarkNameEditText = (EditText) alertDialog.findViewById(R.id.edit_bookmark_name_edittext); assert bookmarkNameEditText != null; // Remove the warning below that `bookmarkNameEditText` might be null. - bookmarkNameEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME))); + bookmarkNameEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME))); // Allow the `enter` key on the keyboard to save the bookmark from `edit_bookmark_name_edittext`. bookmarkNameEditText.setOnKeyListener(new View.OnKeyListener() { @@ -147,7 +152,7 @@ public class EditBookmark extends AppCompatDialogFragment { // Load the text for `edit_bookmark_url_edittext`. EditText bookmarkUrlEditText = (EditText) alertDialog.findViewById(R.id.edit_bookmark_url_edittext); assert bookmarkUrlEditText != null;// Remove the warning below that `bookmarkUrlEditText` might be null. - bookmarkUrlEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_URL))); + bookmarkUrlEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL))); // Allow the "enter" key on the keyboard to save the bookmark from `edit_bookmark_url_edittext`. bookmarkUrlEditText.setOnKeyListener(new View.OnKeyListener() { diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkFolder.java similarity index 91% rename from app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkFolder.java index c04012b9..74bd8903 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkFolder.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.Dialog; @@ -38,6 +38,11 @@ import android.view.WindowManager; import android.widget.EditText; import android.widget.ImageView; +import com.stoutner.privacybrowser.activities.MainWebView; +import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.activities.Bookmarks; +import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper; + public class EditBookmarkFolder extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface EditBookmarkFolderListener { @@ -64,11 +69,11 @@ public class EditBookmarkFolder extends AppCompatDialogFragment { @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`. - long[] selectedBookmarkLongArray = BookmarksActivity.checkedItemIds; + long[] selectedBookmarkLongArray = Bookmarks.checkedItemIds; int selectedBookmarkDatabaseId = (int) selectedBookmarkLongArray[0]; // Get a `Cursor` with the specified bookmark and move it to the first position. - Cursor bookmarkCursor = BookmarksActivity.bookmarksDatabaseHandler.getBookmarkCursor(selectedBookmarkDatabaseId); + Cursor bookmarkCursor = Bookmarks.bookmarksDatabaseHelper.getBookmarkCursor(selectedBookmarkDatabaseId); bookmarkCursor.moveToFirst(); // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. @@ -108,7 +113,7 @@ public class EditBookmarkFolder extends AppCompatDialogFragment { alertDialog.show(); // Get the current favorite icon byte array from the `Cursor`. - byte[] currentIconByteArray = bookmarkCursor.getBlob(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + byte[] currentIconByteArray = bookmarkCursor.getBlob(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last. Bitmap currentIconBitmap = BitmapFactory.decodeByteArray(currentIconByteArray, 0, currentIconByteArray.length); // Display `currentIconBitmap` in `edit_folder_current_icon`. @@ -116,15 +121,15 @@ public class EditBookmarkFolder extends AppCompatDialogFragment { assert currentIconImageView != null; // Remove the warning below that `currentIconImageView` might be null. currentIconImageView.setImageBitmap(currentIconBitmap); - // Get a `Bitmap` of the favorite icon from `MainWebViewActivity` and display it in `edit_folder_web_page_favorite_icon`. + // Get a `Bitmap` of the favorite icon from `MainWebView` and display it in `edit_folder_web_page_favorite_icon`. ImageView webPageFavoriteIconImageView = (ImageView) alertDialog.findViewById(R.id.edit_folder_web_page_favorite_icon); assert webPageFavoriteIconImageView != null; // Remove the warning below that `webPageFavoriteIcon` might be null. - webPageFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIcon); + webPageFavoriteIconImageView.setImageBitmap(MainWebView.favoriteIcon); // Load the text for `edit_folder_name_edittext`. EditText folderNameEditText = (EditText) alertDialog.findViewById(R.id.edit_folder_name_edittext); assert folderNameEditText != null; // Remove the warning below that `bookmarkNameEditText` might be null. - folderNameEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME))); + folderNameEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME))); // Allow the `enter` key on the keyboard to save the bookmark from `edit_bookmark_name_edittext`. folderNameEditText.setOnKeyListener(new View.OnKeyListener() { diff --git a/app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/MoveToFolder.java similarity index 89% rename from app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/MoveToFolder.java index 60f7707f..e2e2f88f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/MoveToFolder.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.Dialog; @@ -45,6 +45,10 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; +import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.activities.Bookmarks; +import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper; + import java.io.ByteArrayOutputStream; public class MoveToFolder extends AppCompatDialogFragment { @@ -109,20 +113,20 @@ public class MoveToFolder extends AppCompatDialogFragment { CursorAdapter foldersCursorAdapter; // Check to see if we are in the `Home Folder`. - if (BookmarksActivity.currentFolder.isEmpty()) { // Don't display `Home Folder` at the top of the `ListView`. + if (Bookmarks.currentFolder.isEmpty()) { // Don't display `Home Folder` at the top of the `ListView`. // Initialize `exceptFolders`. exceptFolders = ""; // If a folder is selected, add it and all children to the list of folders not to display. - long[] selectedBookmarksLongArray = BookmarksActivity.checkedItemIds; + long[] selectedBookmarksLongArray = Bookmarks.checkedItemIds; for (long databaseIdLong : selectedBookmarksLongArray) { // Get `databaseIdInt` for each selected bookmark. int databaseIdInt = (int) databaseIdLong; // If `databaseIdInt` is a folder. - if (BookmarksActivity.bookmarksDatabaseHandler.isFolder(databaseIdInt)) { + if (Bookmarks.bookmarksDatabaseHelper.isFolder(databaseIdInt)) { // Get the name of the selected folder. - String folderName = BookmarksActivity.bookmarksDatabaseHandler.getFolderName(databaseIdInt); + String folderName = Bookmarks.bookmarksDatabaseHelper.getFolderName(databaseIdInt); if (exceptFolders.isEmpty()){ // Add the selected folder to the list of folders not to display. @@ -138,7 +142,7 @@ public class MoveToFolder extends AppCompatDialogFragment { } // Get a `Cursor` containing the folders to display. - foldersCursor = BookmarksActivity.bookmarksDatabaseHandler.getFoldersCursorExcept(exceptFolders); + foldersCursor = Bookmarks.bookmarksDatabaseHelper.getFoldersCursorExcept(exceptFolders); // Setup `foldersCursorAdaptor` with `this` context. `false` disables autoRequery. foldersCursorAdapter = new CursorAdapter(alertDialog.getContext(), foldersCursor, false) { @@ -151,7 +155,7 @@ public class MoveToFolder extends AppCompatDialogFragment { @Override public void bindView(View view, Context context, Cursor cursor) { // Get the folder icon from `cursor`. - byte[] folderIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + byte[] folderIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last. Bitmap folderIconBitmap = BitmapFactory.decodeByteArray(folderIconByteArray, 0, folderIconByteArray.length); // Display `folderIconBitmap` in `move_to_folder_icon`. @@ -160,7 +164,7 @@ public class MoveToFolder extends AppCompatDialogFragment { folderIconImageView.setImageBitmap(folderIconBitmap); // Get the folder name from `cursor` and display it in `move_to_folder_name_textview`. - String folderName = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + String folderName = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); TextView folderNameTextView = (TextView) view.findViewById(R.id.move_to_folder_name_textview); folderNameTextView.setText(folderName); } @@ -176,23 +180,23 @@ public class MoveToFolder extends AppCompatDialogFragment { byte[] homeFolderIconByteArray = homeFolderIconByteArrayOutputStream.toByteArray(); // Setup a `MatrixCursor` for the `Home Folder`. - String[] homeFolderMatrixCursorColumnNames = {BookmarksDatabaseHandler._ID, BookmarksDatabaseHandler.BOOKMARK_NAME, BookmarksDatabaseHandler.FAVORITE_ICON}; + String[] homeFolderMatrixCursorColumnNames = {BookmarksDatabaseHelper._ID, BookmarksDatabaseHelper.BOOKMARK_NAME, BookmarksDatabaseHelper.FAVORITE_ICON}; MatrixCursor homeFolderMatrixCursor = new MatrixCursor(homeFolderMatrixCursorColumnNames); homeFolderMatrixCursor.addRow(new Object[]{0, getString(R.string.home_folder), homeFolderIconByteArray}); // Add the parent folder to the list of folders not to display. - exceptFolders = DatabaseUtils.sqlEscapeString(BookmarksActivity.currentFolder); + exceptFolders = DatabaseUtils.sqlEscapeString(Bookmarks.currentFolder); // If a folder is selected, add it and all children to the list of folders not to display. - long[] selectedBookmarksLongArray = BookmarksActivity.checkedItemIds; + long[] selectedBookmarksLongArray = Bookmarks.checkedItemIds; for (long databaseIdLong : selectedBookmarksLongArray) { // Get `databaseIdInt` for each selected bookmark. int databaseIdInt = (int) databaseIdLong; // If `databaseIdInt` is a folder. - if (BookmarksActivity.bookmarksDatabaseHandler.isFolder(databaseIdInt)) { + if (Bookmarks.bookmarksDatabaseHelper.isFolder(databaseIdInt)) { // Get the name of the selected folder. - String folderName = BookmarksActivity.bookmarksDatabaseHandler.getFolderName(databaseIdInt); + String folderName = Bookmarks.bookmarksDatabaseHelper.getFolderName(databaseIdInt); // Add the selected folder to the end of the list of folders not to display. exceptFolders = exceptFolders + "," + DatabaseUtils.sqlEscapeString(folderName); @@ -203,7 +207,7 @@ public class MoveToFolder extends AppCompatDialogFragment { } // Get a `foldersCursor`. - foldersCursor = BookmarksActivity.bookmarksDatabaseHandler.getFoldersCursorExcept(exceptFolders); + foldersCursor = Bookmarks.bookmarksDatabaseHelper.getFoldersCursorExcept(exceptFolders); // Combine `homeFolderMatrixCursor` and `foldersCursor`. MergeCursor foldersMergeCursor = new MergeCursor(new Cursor[]{homeFolderMatrixCursor, foldersCursor}); @@ -219,7 +223,7 @@ public class MoveToFolder extends AppCompatDialogFragment { @Override public void bindView(View view, Context context, Cursor cursor) { // Get the folder icon from `cursor`. - byte[] folderIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + byte[] folderIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last. Bitmap folderIconBitmap = BitmapFactory.decodeByteArray(folderIconByteArray, 0, folderIconByteArray.length); // Display `folderIconBitmap` in `move_to_folder_icon`. @@ -228,7 +232,7 @@ public class MoveToFolder extends AppCompatDialogFragment { folderIconImageView.setImageBitmap(folderIconBitmap); // Get the folder name from `cursor` and display it in `move_to_folder_name_textview`. - String folderName = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + String folderName = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); TextView folderNameTextView = (TextView) view.findViewById(R.id.move_to_folder_name_textview); folderNameTextView.setText(folderName); } @@ -246,14 +250,14 @@ public class MoveToFolder extends AppCompatDialogFragment { private void addSubfoldersToExceptFolders(String folderName) { // Get a `Cursor` will all the immediate subfolders. - Cursor subfoldersCursor = BookmarksActivity.bookmarksDatabaseHandler.getSubfoldersCursor(folderName); + Cursor subfoldersCursor = Bookmarks.bookmarksDatabaseHelper.getSubfoldersCursor(folderName); for (int i = 0; i < subfoldersCursor.getCount(); i++) { // Move `subfolderCursor` to the current item. subfoldersCursor.moveToPosition(i); // Get the name of the subfolder. - String subfolderName = subfoldersCursor.getString(subfoldersCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + String subfolderName = subfoldersCursor.getString(subfoldersCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); // Run the same tasks for any subfolders of the subfolder. addSubfoldersToExceptFolders(subfolderName); diff --git a/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateError.java similarity index 99% rename from app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateError.java index 388a09bd..1e956162 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateError.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.AlertDialog; @@ -35,6 +35,8 @@ import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; import android.widget.TextView; +import com.stoutner.privacybrowser.R; + import java.util.Date; public class SslCertificateError extends AppCompatDialogFragment { diff --git a/app/src/main/java/com/stoutner/privacybrowser/UrlHistory.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/UrlHistory.java similarity index 98% rename from app/src/main/java/com/stoutner/privacybrowser/UrlHistory.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/UrlHistory.java index ec0b45e4..46a7bbb5 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/UrlHistory.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/UrlHistory.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.Dialog; @@ -40,6 +40,10 @@ import android.webkit.WebBackForwardList; import android.widget.AdapterView; import android.widget.ListView; +import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.adapters.HistoryArrayAdapter; +import com.stoutner.privacybrowser.definitions.History; + import java.io.ByteArrayOutputStream; import java.util.ArrayList; diff --git a/app/src/main/java/com/stoutner/privacybrowser/ViewSslCertificate.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/ViewSslCertificate.java similarity index 96% rename from app/src/main/java/com/stoutner/privacybrowser/ViewSslCertificate.java rename to app/src/main/java/com/stoutner/privacybrowser/dialogs/ViewSslCertificate.java index 76b6abe6..d977cbed 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/ViewSslCertificate.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/ViewSslCertificate.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; import android.app.AlertDialog; @@ -33,6 +33,9 @@ import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; import android.widget.TextView; +import com.stoutner.privacybrowser.activities.MainWebView; +import com.stoutner.privacybrowser.R; + import java.util.Date; // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`. @@ -43,7 +46,7 @@ public class ViewSslCertificate extends DialogFragment { LayoutInflater layoutInflater = getActivity().getLayoutInflater(); // Create a drawable version of the favorite icon. - Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIcon); + Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebView.favoriteIcon); // Use `AlertDialog.Builder` to create the `AlertDialog`. `R.style.LightAlertDialog` formats the color of the button text. AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); @@ -53,7 +56,7 @@ public class ViewSslCertificate extends DialogFragment { dialogBuilder.setNegativeButton(R.string.close, null); // Check to see if the website is encrypted. - if (MainWebViewActivity.sslCertificate == null) { // The website is not encrypted. + if (MainWebView.sslCertificate == null) { // The website is not encrypted. // Set the title. dialogBuilder.setTitle(R.string.unencrypted_website); @@ -100,7 +103,7 @@ public class ViewSslCertificate extends DialogFragment { String endDateLabel = getString(R.string.end_date) + " "; // Get the SSL certificate. - SslCertificate sslCertificate = MainWebViewActivity.sslCertificate; + SslCertificate sslCertificate = MainWebView.sslCertificate; // Get the strings from the SSL certificate. String issuedToCNameString = sslCertificate.getIssuedTo().getCName(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/AboutTabFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTab.java similarity index 97% rename from app/src/main/java/com/stoutner/privacybrowser/AboutTabFragment.java rename to app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTab.java index baddf5c3..7baff969 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/AboutTabFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTab.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.fragments; import android.os.Build; import android.os.Bundle; @@ -31,15 +31,18 @@ import android.view.ViewGroup; import android.webkit.WebView; import android.widget.TextView; -public class AboutTabFragment extends Fragment { +import com.stoutner.privacybrowser.BuildConfig; +import com.stoutner.privacybrowser.R; + +public class AboutTab extends Fragment { private int tabNumber; - // AboutTabFragment.createTab stores the tab number in the bundle arguments so it can be referenced from onCreate(). - public static AboutTabFragment createTab(int tab) { + // AboutTab.createTab stores the tab number in the bundle arguments so it can be referenced from onCreate(). + public static AboutTab createTab(int tab) { Bundle thisTabArguments = new Bundle(); thisTabArguments.putInt("Tab", tab); - AboutTabFragment thisTab = new AboutTabFragment(); + AboutTab thisTab = new AboutTab(); thisTab.setArguments(thisTabArguments); return thisTab; } diff --git a/app/src/main/java/com/stoutner/privacybrowser/GuideTabFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/GuideTab.java similarity index 91% rename from app/src/main/java/com/stoutner/privacybrowser/GuideTabFragment.java rename to app/src/main/java/com/stoutner/privacybrowser/fragments/GuideTab.java index 4fa96779..8857aca4 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/GuideTabFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/GuideTab.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.fragments; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -26,15 +26,17 @@ import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; -public class GuideTabFragment extends Fragment { +import com.stoutner.privacybrowser.R; + +public class GuideTab extends Fragment { private int tabNumber; - // GuideTabFragment.createTab stores the tab number in the bundle arguments so it can be referenced from onCreate(). - public static GuideTabFragment createTab (int tab) { + // GuideTab.createTab stores the tab number in the bundle arguments so it can be referenced from onCreate(). + public static GuideTab createTab (int tab) { Bundle thisTabArguments = new Bundle(); thisTabArguments.putInt("Tab", tab); - GuideTabFragment thisTab = new GuideTabFragment(); + GuideTab thisTab = new GuideTab(); thisTab.setArguments(thisTabArguments); return thisTab; } diff --git a/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java similarity index 99% rename from app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java rename to app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java index 5d73e193..2149df50 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.fragments; import android.annotation.SuppressLint; import android.content.SharedPreferences; @@ -28,6 +28,8 @@ import android.view.LayoutInflater; import android.view.View; import android.webkit.WebView; +import com.stoutner.privacybrowser.R; + public class SettingsFragment extends PreferenceFragment { private SharedPreferences.OnSharedPreferenceChangeListener preferencesListener; private SharedPreferences savedPreferences; diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java similarity index 89% rename from app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java rename to app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java index 3d4b7f81..051da668 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.helpers; import android.content.ContentValues; import android.content.Context; @@ -26,21 +26,21 @@ import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; -class BookmarksDatabaseHandler extends SQLiteOpenHelper { +public class BookmarksDatabaseHelper extends SQLiteOpenHelper { private static final int SCHEMA_VERSION = 1; private static final String BOOKMARKS_DATABASE = "bookmarks.db"; private static final String BOOKMARKS_TABLE = "bookmarks"; - static final String _ID = "_id"; - static final String DISPLAY_ORDER = "displayorder"; - static final String BOOKMARK_NAME = "bookmarkname"; - static final String BOOKMARK_URL = "bookmarkurl"; - static final String PARENT_FOLDER = "parentfolder"; - static final String IS_FOLDER = "isfolder"; - static final String FAVORITE_ICON = "favoriteicon"; + public static final String _ID = "_id"; + public static final String DISPLAY_ORDER = "displayorder"; + public static final String BOOKMARK_NAME = "bookmarkname"; + public static final String BOOKMARK_URL = "bookmarkurl"; + public static final String PARENT_FOLDER = "parentfolder"; + public static final String IS_FOLDER = "isfolder"; + public static final String FAVORITE_ICON = "favoriteicon"; // Initialize the database. The lint warnings for the unused parameters are suppressed. - BookmarksDatabaseHandler(Context context, @SuppressWarnings("UnusedParameters") String name, SQLiteDatabase.CursorFactory factory, @SuppressWarnings("UnusedParameters") int version) { + public BookmarksDatabaseHelper(Context context, @SuppressWarnings("UnusedParameters") String name, SQLiteDatabase.CursorFactory factory, @SuppressWarnings("UnusedParameters") int version) { super(context, BOOKMARKS_DATABASE, factory, SCHEMA_VERSION); } @@ -64,7 +64,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { // Code for upgrading the database will be added here when the schema version > 1. } - void createBookmark(String bookmarkName, String bookmarkURL, int displayOrder, String parentFolder, byte[] favoriteIcon) { + public void createBookmark(String bookmarkName, String bookmarkURL, int displayOrder, String parentFolder, byte[] favoriteIcon) { ContentValues bookmarkContentValues = new ContentValues(); // ID is created automatically. @@ -85,7 +85,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { bookmarksDatabase.close(); } - void createFolder(String folderName, int displayOrder, String parentFolder, byte[] favoriteIcon) { + public void createFolder(String folderName, int displayOrder, String parentFolder, byte[] favoriteIcon) { ContentValues bookmarkContentValues = new ContentValues(); // ID is created automatically. @@ -105,7 +105,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { bookmarksDatabase.close(); } - Cursor getBookmarkCursor(int databaseId) { + public Cursor getBookmarkCursor(int databaseId) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -118,7 +118,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return bookmarksDatabase.rawQuery(GET_ONE_BOOKMARK, null); } - String getFolderName (int databaseId) { + public String getFolderName (int databaseId) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -141,7 +141,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return folderName; } - Cursor getFolderCursor(String folderName) { + public Cursor getFolderCursor(String folderName) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -158,7 +158,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return bookmarksDatabase.rawQuery(GET_FOLDER, null); } - Cursor getFoldersCursorExcept(String exceptFolders) { + public Cursor getFoldersCursorExcept(String exceptFolders) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -173,7 +173,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return bookmarksDatabase.rawQuery(GET_FOLDERS_EXCEPT, null); } - Cursor getSubfoldersCursor(String currentFolder) { + public Cursor getSubfoldersCursor(String currentFolder) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -190,7 +190,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return bookmarksDatabase.rawQuery(GET_SUBFOLDERS, null); } - String getParentFolder(String currentFolder) { + public String getParentFolder(String currentFolder) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -215,7 +215,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return parentFolder; } - Cursor getAllBookmarksCursor() { + public Cursor getAllBookmarksCursor() { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -227,7 +227,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return bookmarksDatabase.rawQuery(GET_ALL_BOOKMARKS, null); } - Cursor getAllBookmarksCursorByDisplayOrder(String folderName) { + public Cursor getAllBookmarksCursorByDisplayOrder(String folderName) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -244,7 +244,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return bookmarksDatabase.rawQuery(GET_ALL_BOOKMARKS, null); } - Cursor getBookmarksCursorExcept(long[] exceptIdLongArray, String folderName) { + public Cursor getBookmarksCursorExcept(long[] exceptIdLongArray, String folderName) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -274,7 +274,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return bookmarksDatabase.rawQuery(GET_All_BOOKMARKS_EXCEPT_SPECIFIED, null); } - boolean isFolder(int databaseId) { + public boolean isFolder(int databaseId) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -296,7 +296,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { return isFolder; } - void updateBookmark(int databaseId, String bookmarkName, String bookmarkUrl) { + public void updateBookmark(int databaseId, String bookmarkName, String bookmarkUrl) { // Store the updated values in `bookmarkContentValues`. ContentValues bookmarkContentValues = new ContentValues(); @@ -313,7 +313,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { bookmarksDatabase.close(); } - void updateBookmark(int databaseId, String bookmarkName, String bookmarkUrl, byte[] favoriteIcon) { + public void updateBookmark(int databaseId, String bookmarkName, String bookmarkUrl, byte[] favoriteIcon) { // Store the updated values in `bookmarkContentValues`. ContentValues bookmarkContentValues = new ContentValues(); @@ -331,7 +331,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { bookmarksDatabase.close(); } - void updateFolder(int databaseId, String oldFolderName, String newFolderName) { + public void updateFolder(int databaseId, String oldFolderName, String newFolderName) { // Get a writable database handle. SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); @@ -359,7 +359,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { bookmarksDatabase.close(); } - void updateFolder(int databaseId, String oldFolderName, String newFolderName, byte[] folderIcon) { + public void updateFolder(int databaseId, String oldFolderName, String newFolderName, byte[] folderIcon) { // Get a writable database handle. SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); @@ -388,7 +388,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { bookmarksDatabase.close(); } - void updateBookmarkDisplayOrder(int databaseId, int displayOrder) { + public void updateBookmarkDisplayOrder(int databaseId, int displayOrder) { // Get a writable database handle. SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); @@ -403,7 +403,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { bookmarksDatabase.close(); } - void moveToFolder(int databaseId, String newFolder) { + public void moveToFolder(int databaseId, String newFolder) { // Get a writable database handle. SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); @@ -435,7 +435,7 @@ class BookmarksDatabaseHandler extends SQLiteOpenHelper { bookmarksDatabase.close(); } - void deleteBookmark(int databaseId) { + public void deleteBookmark(int databaseId) { // Get a writable database handle. SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/OrbotProxyHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/OrbotProxyHelper.java similarity index 90% rename from app/src/main/java/com/stoutner/privacybrowser/OrbotProxyHelper.java rename to app/src/main/java/com/stoutner/privacybrowser/helpers/OrbotProxyHelper.java index 58084ad2..97b2f9d7 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/OrbotProxyHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/OrbotProxyHelper.java @@ -17,7 +17,7 @@ * along with Privacy Browser. If not, see . */ -package com.stoutner.privacybrowser; +package com.stoutner.privacybrowser.helpers; import android.app.Activity; import android.content.Context; @@ -30,12 +30,15 @@ import android.support.v7.app.AlertDialog; import android.util.ArrayMap; import android.util.Log; +import com.stoutner.privacybrowser.activities.MainWebView; +import com.stoutner.privacybrowser.R; + import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -class OrbotProxyHelper { - static void setProxy(Context privacyBrowserContext, Activity parentActivity, String proxyHost, String proxyPort) { +public class OrbotProxyHelper { + public static void setProxy(Context privacyBrowserContext, Activity parentActivity, String proxyHost, String proxyPort) { // Set the proxy values System.setProperty("http.proxyHost", proxyHost); System.setProperty("http.proxyPort", proxyPort); @@ -74,7 +77,7 @@ class OrbotProxyHelper { if (proxyPort.equals("8118")) { // Orbot proxy was turned on. // Set the `appBar` background to be light blue if Orbot proxy support is enabled. - MainWebViewActivity.appBar.setBackgroundDrawable(ContextCompat.getDrawable(privacyBrowserContext, R.color.blue_50)); + MainWebView.appBar.setBackgroundDrawable(ContextCompat.getDrawable(privacyBrowserContext, R.color.blue_50)); try { // Check to see if Orbot is installed. PackageManager packageManager = privacyBrowserContext.getPackageManager(); @@ -95,7 +98,7 @@ class OrbotProxyHelper { alertDialog.show(); } } else { // Otherwise set the default grey `appBar` background. - MainWebViewActivity.appBar.setBackgroundDrawable(ContextCompat.getDrawable(privacyBrowserContext, R.color.grey_100)); + MainWebView.appBar.setBackgroundDrawable(ContextCompat.getDrawable(privacyBrowserContext, R.color.grey_100)); } } } diff --git a/app/src/main/res/layout/bare_webview.xml b/app/src/main/res/layout/bare_webview.xml index 7960ca5e..9e628092 100644 --- a/app/src/main/res/layout/bare_webview.xml +++ b/app/src/main/res/layout/bare_webview.xml @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with Privacy Browser. If not, see . --> - + . --> - + diff --git a/app/src/main/res/menu/webview_options_menu.xml b/app/src/main/res/menu/webview_options_menu.xml index 8dee5b1d..06fa1ac4 100644 --- a/app/src/main/res/menu/webview_options_menu.xml +++ b/app/src/main/res/menu/webview_options_menu.xml @@ -22,7 +22,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - tools:context=".MainWebViewActivity"> + tools:context=".activities.MainWebView"> Privacy Browser Einstellungen de - + Privatsphäre-Modus JavaScript aktiviert JavaScript deaktiviert diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8d6f5c7..9af909e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,7 +28,7 @@ Privacy Browser Settings en - + Privacy Mode JavaScript enabled JavaScript disabled diff --git a/app/src/standard/java/com/stoutner/privacybrowser/BannerAd.java b/app/src/standard/java/com/stoutner/privacybrowser/BannerAd.java index a6f98a6d..caf6e623 100644 --- a/app/src/standard/java/com/stoutner/privacybrowser/BannerAd.java +++ b/app/src/standard/java/com/stoutner/privacybrowser/BannerAd.java @@ -22,28 +22,28 @@ package com.stoutner.privacybrowser; import android.content.Context; import android.view.View; -class BannerAd { - static void requestAd(View view) { +public class BannerAd { + public static void requestAd(View view) { // Do nothing because this is the standard flavor. } - static void reloadAfterRotate(View view, Context applicationContext, String ad_id) { + public static void reloadAfterRotate(View view, Context applicationContext, String ad_id) { // Do nothing because this is the standard flavor. } - static void hideAd(View view) { + public static void hideAd(View view) { // Do nothing because this is the standard flavor. } - static void showAd(View view) { + public static void showAd(View view) { // Do nothing because this is the standard flavor. } - static void pauseAd(View view) { + public static void pauseAd(View view) { // Do nothing because this is the standard flavor. } - static void resumeAd(View view) { + public static void resumeAd(View view) { // Do nothing because this is the standard flavor. } } \ No newline at end of file -- 2.45.2