From 55f06b482c1a7426f9338e68e89a30659d0d2f8b Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Mon, 25 Feb 2019 14:12:14 -0700 Subject: [PATCH] Add an option to always have home screen shortcuts open in Privacy Browser. https://redmine.stoutner.com/issues/222 --- app/src/free/res/values/strings.xml | 17 ++++++---- .../CreateHomeScreenShortcutDialog.java | 22 +++++++++---- .../create_home_screen_shortcut_dialog.xml | 33 +++++++++++++++++-- app/src/main/res/values-it/strings.xml | 4 +++ app/src/main/res/values/strings.xml | 4 ++- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/app/src/free/res/values/strings.xml b/app/src/free/res/values/strings.xml index cb6b21b5..cead48b1 100644 --- a/app/src/free/res/values/strings.xml +++ b/app/src/free/res/values/strings.xml @@ -29,13 +29,8 @@ Privacy Browser Free - - ca-app-pub-5962503714887045~2738552414 - ca-app-pub-5962503714887045/2738552414 - - + + Open with Privacy Browser Free. Privacy Browser Free displays a banner ad on the bottom of the screen. @@ -43,4 +38,12 @@ \n\nThe standard version of Privacy Browser does not contain app ads. Close Browser Accept Ads + + + ca-app-pub-5962503714887045~2738552414 + ca-app-pub-5962503714887045/2738552414 + + \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateHomeScreenShortcutDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateHomeScreenShortcutDialog.java index 32cd5fac..e3221a21 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateHomeScreenShortcutDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateHomeScreenShortcutDialog.java @@ -39,14 +39,16 @@ import android.view.View; import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; +import android.widget.RadioButton; import androidx.annotation.NonNull; -// `ShortcutInfoCompat`, `ShortcutManagerCompat`, and `IconCompat` can be switched to the non-compat versions once API >= 26. +// `ShortcutInfoCompat`, `ShortcutManagerCompat`, and `IconCompat` can be switched to the non-compat versions once the minimum API >= 26. import androidx.core.content.pm.ShortcutInfoCompat; import androidx.core.content.pm.ShortcutManagerCompat; import androidx.core.graphics.drawable.IconCompat; import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22. +import com.stoutner.privacybrowser.BuildConfig; import com.stoutner.privacybrowser.activities.MainWebViewActivity; import com.stoutner.privacybrowser.R; @@ -59,6 +61,7 @@ public class CreateHomeScreenShortcutDialog extends DialogFragment { private Bitmap favoriteIconBitmap; private EditText shortcutNameEditText; private EditText urlEditText; + private RadioButton openWithPrivacyBrowserRadioButton; private Button createButton; public static CreateHomeScreenShortcutDialog createDialog(String shortcutName, String urlString, Bitmap favoriteIconBitmap) { @@ -168,17 +171,16 @@ public class CreateHomeScreenShortcutDialog extends DialogFragment { // The alert dialog must be shown before the contents may be edited. alertDialog.show(); - // Get a handle for the edit texts. + // Get handles for the views. shortcutNameEditText = alertDialog.findViewById(R.id.shortcut_name_edittext); urlEditText = alertDialog.findViewById(R.id.url_edittext); + openWithPrivacyBrowserRadioButton = alertDialog.findViewById(R.id.open_with_privacy_browser_radiobutton); + createButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); // Populate the edit texts. shortcutNameEditText.setText(initialShortcutName); urlEditText.setText(initialUrlString); - // Get a handle for the create button. - createButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); - // Add a text change listener to the shortcut name edit text. shortcutNameEditText.addTextChangedListener(new TextWatcher() { @Override @@ -292,8 +294,16 @@ public class CreateHomeScreenShortcutDialog extends DialogFragment { // Convert the favorite icon bitmap to an icon. `IconCompat` must be used until the minimum API >= 26. IconCompat favoriteIcon = IconCompat.createWithBitmap(favoriteIconBitmap); - // Setup the shortcut intent. + // Create a shortcut intent. Intent shortcutIntent = new Intent(Intent.ACTION_VIEW); + + // Check to see if the shortcut should open up Privacy Browser explicitly. + if (openWithPrivacyBrowserRadioButton.isChecked()) { + // Set the current application ID as the target package. + shortcutIntent.setPackage(BuildConfig.APPLICATION_ID); + } + + // Add the URL to the intent. shortcutIntent.setData(Uri.parse(urlString)); // Create a shortcut info builder. The shortcut name becomes the shortcut ID. diff --git a/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml b/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml index 3b3c2449..aaadcd45 100644 --- a/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml +++ b/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml @@ -33,7 +33,7 @@ android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginTop="16dp" - android:layout_marginBottom="5dp" + android:layout_marginBottom="4dp" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" > @@ -52,8 +52,8 @@ @@ -67,5 +67,32 @@ android:inputType="textUri" android:selectAllOnFocus="true" /> + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 9c6a23b8..26893f21 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -501,6 +501,8 @@ Schermo intero Navigazione a schermo intero Toccare due volte per avviare la navigazione a schermo intero. + Nascondi la barra dell\'applicazione + Nasconde la barra che contiene l\'URL. Elimina tutto Cancella i cookies, il DOM storage, i dati dei moduli e la cache di WebView. Cancella completamente le cartelle “app_webview” e “cache”. Elimina i cookie @@ -537,6 +539,8 @@ Swipe per aggiornare Alcuni siti non funzionano correttamente se questa opzione è abilitata. + Permetti lo scrolling della barra dell\'applicazione + Permette lo scorrere della barra dell\'applicazione dalla parte alta dello schermo quando si effettua lo scrolling. Mostra icone addizionali nella barra dell\'applicazione Mostra nella barra dell\'applicazione le icone per l\'aggiornamento di WebView e, se lo spazio è sufficiente, per l\'attivazione dei cookie e del DOM storage. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c4e39018..3a8ed17e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -204,6 +204,8 @@ Create Shortcut Shortcut name + Open with default browser. + Open with Privacy Browser. Cancel Create @@ -625,7 +627,7 @@ Display webpage images Disable to conserve bandwidth. - + Privacy Browser PrivacyBrowser/1.0 http://ulrn6sryqaifefld.onion/ -- 2.43.0