From: Soren Stoutner Date: Tue, 14 Mar 2017 04:44:57 +0000 (-0700) Subject: Add color changes to domain settings icons. X-Git-Tag: v2.0~4 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=ade33e21bbdc373ee391b1105d94aeb1aac1b80d;p=PrivacyBrowserAndroid.git Add color changes to domain settings icons. --- diff --git a/.idea/dictionaries/soren.xml b/.idea/dictionaries/soren.xml index 7734ed66..a5cc4b46 100644 --- a/.idea/dictionaries/soren.xml +++ b/.idea/dictionaries/soren.xml @@ -48,6 +48,7 @@ fontsize framelayout gerlach + imageview intl ipleak isfolder diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainSettingsActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainSettingsActivity.java index 65546068..571973db 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainSettingsActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainSettingsActivity.java @@ -76,10 +76,6 @@ public class DomainSettingsActivity extends AppCompatActivity { // Inflate the menu. getMenuInflater().inflate(R.menu.domains_options_menu, menu); - // Show the `MenuItems`. - menu.findItem(R.id.save_domain).setVisible(true); - menu.findItem(R.id.delete_domain).setVisible(true); - // Success! return true; } diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java index 78fbfb53..158fd16a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java @@ -53,6 +53,9 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo // `domainsDatabaseHelper` is used in `onCreate()`, `onOptionsItemSelected()`, `onAddDomain()`, and `updateDomainsRecyclerView()`. private static DomainsDatabaseHelper domainsDatabaseHelper; + // `twoPaneMode` is used in `onCreate()` and `updateDomainsListView()`. + private boolean twoPaneMode; + // `domainsRecyclerView` is used in `onCreate()` and `updateDomainsListView()`. private ListView domainsListView; @@ -87,7 +90,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo domainsDatabaseHelper = new DomainsDatabaseHelper(this, null, null, 0); // Determine if we are in two pane mode. `domains_settings_linearlayout` is only populated if two panes are present. - final boolean twoPaneMode = ((findViewById(R.id.domain_settings_scrollview)) != null); + twoPaneMode = ((findViewById(R.id.domain_settings_scrollview)) != null); // Initialize `domainsListView`. domainsListView = (ListView) findViewById(R.id.domains_listview); @@ -100,9 +103,9 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo // Display the Domain Settings. if (twoPaneMode) { // Display a fragment in two paned mode. - // Display the options `MenuItems`. - saveMenuItem.setVisible(true); - deleteMenuItem.setVisible(true); + // Enable the options `MenuItems`. + saveMenuItem.setEnabled(true); + deleteMenuItem.setEnabled(true); // Store `databaseId` in `argumentsBundle`. Bundle argumentsBundle = new Bundle(); @@ -134,9 +137,6 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo addDomainDialog.show(getSupportFragmentManager(), getResources().getString(R.string.add_domain)); } }); - - // Load the `ListView`. - updateDomainsListView(); } @Override @@ -145,8 +145,15 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo getMenuInflater().inflate(R.menu.domains_options_menu, menu); // Store the `MenuItems` for future use. - saveMenuItem = menu.findItem(R.id.save_domain); deleteMenuItem = menu.findItem(R.id.delete_domain); + saveMenuItem = menu.findItem(R.id.save_domain); + + // Only display the options `MenuItems` in two pane mode. + deleteMenuItem.setVisible(twoPaneMode); + saveMenuItem.setVisible(twoPaneMode); + + // Load the `ListView`. We have to do this from `onCreateOptionsMenu()` instead of `onCreate()` because `updateDomainsListView()` needs the `MenuItems` to be inflated. + updateDomainsListView(); // Success! return true; @@ -206,10 +213,6 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo // Detach the domain settings fragment. getSupportFragmentManager().beginTransaction().detach(getSupportFragmentManager().findFragmentById(R.id.domain_settings_scrollview)).commit(); - // Hide the options `MenuItems`. - saveMenuItem.setVisible(false); - deleteMenuItem.setVisible(false); - // Update the `ListView`. updateDomainsListView(); break; @@ -251,7 +254,38 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo } }; - // Update the `RecyclerView`. + // Update the `ListView`. domainsListView.setAdapter(domainsCursorAdapter); + + // Display the domain settings in the second pane if operating in two pane mode and the database contains at least one domain. + if (twoPaneMode && (domainsCursor.getCount() > 0)) { + // Select the first domain. + domainsListView.setItemChecked(0, true); + + // Get the `databaseId` of the first item. + domainsCursor.moveToFirst(); + databaseId = domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper._ID)); + + // Store `databaseId` in `argumentsBundle`. + Bundle argumentsBundle = new Bundle(); + argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, databaseId); + + // Add `argumentsBundle` to `domainSettingsFragment`. + DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment(); + domainSettingsFragment.setArguments(argumentsBundle); + + // Display `domainSettingsFragment`. + getSupportFragmentManager().beginTransaction().replace(R.id.domain_settings_scrollview, domainSettingsFragment).commit(); + + // Enable the options `MenuItems`. + deleteMenuItem.setEnabled(true); + deleteMenuItem.setIcon(R.drawable.delete); + saveMenuItem.setEnabled(true); + } else { + // Disable the options `MenuItems`. + deleteMenuItem.setEnabled(false); + deleteMenuItem.setIcon(R.drawable.delete_blue); + saveMenuItem.setEnabled(false); + } } } \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 0457af74..d0d8c9c0 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -123,7 +123,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // 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 `BookmarksActivity`, `CreateBookmarkDialog`, and `AddDomainDialog`. // It is also used in `onCreate()`, `onOptionsItemSelected()`, `onCreateHomeScreenShortcutCreate()`, and `loadUrlFromTextBox()`. public static String formattedUrlString; diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.java index e4cf59f0..5b18fe4d 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.java @@ -24,6 +24,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.net.Uri; import android.os.Bundle; // We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <= 22. import android.support.annotation.NonNull; @@ -34,6 +35,7 @@ import android.view.WindowManager; import android.widget.EditText; import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.activities.MainWebViewActivity; public class AddDomainDialog extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. @@ -93,11 +95,17 @@ public class AddDomainDialog extends AppCompatDialogFragment { // Show the keyboard when the `AlertDialog` is displayed on the screen. alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); - // We need to show the `AlertDialog` before w3e can call `setOnKeyListener()` below. + // We need to show the `AlertDialog` before we can edit the contents. alertDialog.show(); - // Allow the `enter` key on the keyboard to create the domain from `add_domain_edittext`. + // Get a handle for `domain_name_edittext`. EditText addDomainEditText = (EditText) alertDialog.findViewById(R.id.domain_name_edittext); + + // Get the current domain from `formattedUrlString`. + Uri currentUri = Uri.parse(MainWebViewActivity.formattedUrlString); + addDomainEditText.setText(currentUri.getHost()); + + // Allow the `enter` key on the keyboard to create the domain from `add_domain_edittext`. addDomainEditText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View view, int keyCode, KeyEvent event) { // If the event is a key-down on the `enter` key, select the `PositiveButton` `Add`. diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java index 2c415dac..aecf8e81 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java @@ -31,7 +31,9 @@ import android.view.ViewGroup; import android.webkit.WebView; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.CompoundButton; import android.widget.EditText; +import android.widget.ImageView; import android.widget.Spinner; import android.widget.Switch; import android.widget.TextView; @@ -54,6 +56,8 @@ public class DomainSettingsFragment extends Fragment { databaseId = getArguments().getInt(DATABASE_ID); } + // We have to use the deprecated `getDrawable()` until the minimum API >= 21. + @SuppressWarnings("deprecation") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate `domain_settings`. `false` does not attach it to the root `container`. @@ -65,10 +69,15 @@ public class DomainSettingsFragment extends Fragment { // Get handles for the views in the fragment. EditText domainNameEditText = (EditText) domainSettingsView.findViewById(R.id.domain_settings_name_edittext); Switch javaScriptEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_javascript_switch); + final ImageView javaScriptImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_javascript_imageview); Switch firstPartyCookiesEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_switch); + final ImageView firstPartyCookiesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_imageview); Switch thirdPartyCookiesEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_switch); + final ImageView thirdPartyCookiesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_imageview); Switch domStorageEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_dom_storage_switch); + final ImageView domStorageImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_dom_storage_imageview); Switch formDataEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_form_data_switch); + final ImageView formDataImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_form_data_imageview); Spinner userAgentSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_user_agent_spinner); final TextView userAgentTextView = (TextView) domainSettingsView.findViewById(R.id.domain_settings_user_agent_textview); final EditText customUserAgentEditText = (EditText) domainSettingsView.findViewById(R.id.domain_settings_custom_user_agent_edittext); @@ -109,12 +118,50 @@ public class DomainSettingsFragment extends Fragment { // Set the domain name from the the database cursor. domainNameEditText.setText(domainNameString); - // Set the status of the `Switches` from the database cursor. - javaScriptEnabledSwitch.setChecked(javaScriptEnabledInt == 1); - firstPartyCookiesEnabledSwitch.setChecked(firstPartyCookiesEnabledInt == 1); - thirdPartyCookiesEnabledSwitch.setChecked(thirdPartyCookiesEnabledInt == 1); - domStorageEnabledSwitch.setChecked(domStorageEnabledInt == 1); - formDataEnabledSwitch.setChecked(formDataEnabledInt == 1); + // Set the JavaScript status. + if (javaScriptEnabledInt == 1) { // JavaScript is enabled. + javaScriptEnabledSwitch.setChecked(true); + javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.javascript_enabled)); + } else { // JavaScript is disabled. + javaScriptEnabledSwitch.setChecked(false); + javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.privacy_mode)); + } + + // Set the first-party cookies status. + if (firstPartyCookiesEnabledInt == 1) { // First-party cookies are enabled. + firstPartyCookiesEnabledSwitch.setChecked(true); + firstPartyCookiesImageView.setEnabled(true); + } else { // First-party cookies are disabled. + firstPartyCookiesEnabledSwitch.setChecked(false); + firstPartyCookiesImageView.setEnabled(false); + } + + // Set the third-party cookies status. + if (thirdPartyCookiesEnabledInt == 1) { // Third-party cookies are enabled. + thirdPartyCookiesEnabledSwitch.setChecked(true); + thirdPartyCookiesImageView.setEnabled(true); + } else { // Third-party cookies are disabled. + thirdPartyCookiesEnabledSwitch.setChecked(false); + thirdPartyCookiesImageView.setEnabled(false); + } + + // Set the DOM storage status. + if (domStorageEnabledInt == 1) { // DOM storage is enabled. + domStorageEnabledSwitch.setChecked(true); + domStorageImageView.setEnabled(true); + } else { // Dom storage is disabled. + domStorageEnabledSwitch.setChecked(false); + domStorageImageView.setEnabled(false); + } + + // Set the form data status. + if (formDataEnabledInt == 1) { // Form data is enabled. + formDataEnabledSwitch.setChecked(true); + formDataImageView.setEnabled(true); + } else { // Form data is disabled. + formDataEnabledSwitch.setChecked(false); + formDataImageView.setEnabled(false); + } // We need to inflated a `WebView` to get the default user agent. // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because we don't want to display `bare_webview` on the screen. `false` does not attach the view to the root. @@ -162,6 +209,55 @@ public class DomainSettingsFragment extends Fragment { int fontSizeArrayPosition = fontSizeEntryValuesArrayAdapter.getPosition(String.valueOf(fontSizeInt)); fontSizeSpinner.setSelection(fontSizeArrayPosition); + // Set the `javaScriptEnabledSwitch` `OnCheckedChangeListener()`. + javaScriptEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // Update the icon. + if (isChecked) { + javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.javascript_enabled)); + } else { + javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.privacy_mode)); + } + } + }); + + // Set the `firstPartyCookiesEnabledSwitch` `OnCheckedChangeListener()`. + firstPartyCookiesEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // Update the icon. + firstPartyCookiesImageView.setEnabled(isChecked); + } + }); + + // Set the `thirdPartyCookiesEnabledSwitch` `OnCheckedChangeListener()`. + thirdPartyCookiesEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // Update the icon. + thirdPartyCookiesImageView.setEnabled(isChecked); + } + }); + + // Set the `domStorageEnabledSwitch` `OnCheckedChangeListener()`. + domStorageEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // Update the icon. + domStorageImageView.setEnabled(isChecked); + } + }); + + // Set the `formDataEnabledSwitch` `OnCheckedChangeListener()`. + formDataEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // Update the icon. + formDataImageView.setEnabled(isChecked); + } + }); + // Set the `userAgentSpinner` `onItemClickListener()`. userAgentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java index d30839fa..be88ee6c 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java @@ -29,8 +29,8 @@ public class DomainsDatabaseHelper extends SQLiteOpenHelper { private static final int SCHEMA_VERSION = 1; private static final String DOMAINS_DATABASE = "domains.db"; private static final String DOMAINS_TABLE = "domains"; - private static final String _ID = "_id"; + public static final String _ID = "_id"; public static final String DOMAIN_NAME = "domainname"; public static final String ENABLE_JAVASCRIPT = "enablejavascript"; public static final String ENABLE_FIRST_PARTY_COOKIES = "enablefirstpartycookies"; diff --git a/app/src/main/res/color/domain_settings_icon_red_tint_selector.xml b/app/src/main/res/color/domain_settings_icon_red_tint_selector.xml new file mode 100644 index 00000000..adead7d6 --- /dev/null +++ b/app/src/main/res/color/domain_settings_icon_red_tint_selector.xml @@ -0,0 +1,28 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/color/domain_settings_icon_yellow_tint_selector.xml b/app/src/main/res/color/domain_settings_icon_yellow_tint_selector.xml new file mode 100644 index 00000000..85c72543 --- /dev/null +++ b/app/src/main/res/color/domain_settings_icon_yellow_tint_selector.xml @@ -0,0 +1,28 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/delete_blue.xml b/app/src/main/res/drawable/delete_blue.xml new file mode 100644 index 00000000..9c35972a --- /dev/null +++ b/app/src/main/res/drawable/delete_blue.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/add_domain_dialog.xml b/app/src/main/res/layout/add_domain_dialog.xml index 981ae13e..b4b7b6c7 100644 --- a/app/src/main/res/layout/add_domain_dialog.xml +++ b/app/src/main/res/layout/add_domain_dialog.xml @@ -36,10 +36,11 @@ + android:inputType="textUri" + android:selectAllOnFocus="true" /> \ No newline at end of file diff --git a/app/src/main/res/layout/domain_settings.xml b/app/src/main/res/layout/domain_settings.xml index d550386e..1ea1417c 100644 --- a/app/src/main/res/layout/domain_settings.xml +++ b/app/src/main/res/layout/domain_settings.xml @@ -76,6 +76,7 @@ android:orientation="horizontal" > - - + + + \ No newline at end of file