From: Soren Stoutner Date: Fri, 26 Aug 2016 20:47:54 +0000 (-0700) Subject: Refactor About:Version code to remove unicode literal codes in strings.xml. X-Git-Tag: v1.9~1 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=0cb3e2266b503767b74535e794c674ea97773154;p=PrivacyBrowserAndroid.git Refactor About:Version code to remove unicode literal codes in strings.xml. --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/AboutTabFragment.java b/app/src/main/java/com/stoutner/privacybrowser/AboutTabFragment.java index ab29dd0d..5c670bcd 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/AboutTabFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/AboutTabFragment.java @@ -22,6 +22,9 @@ package com.stoutner.privacybrowser; import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.text.SpannableStringBuilder; +import android.text.Spanned; +import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -53,84 +56,114 @@ public class AboutTabFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View tabLayout; - // Load the about tab layout. Tab numbers start at 0. - if (tabNumber == 0) { + // Load the tabs. Tab numbers start at 0. + if (tabNumber == 0) { // Load the about tab. // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. // The fragment will take care of attaching the root automatically. tabLayout = inflater.inflate(R.layout.about_tab_version, container, false); - // Version. - TextView versionNumberText = (TextView) tabLayout.findViewById(R.id.about_version_number_text); + // Get handles for the `TextViews`. + TextView versionNumberTextView = (TextView) tabLayout.findViewById(R.id.about_version_number); + TextView versionBrandTextView = (TextView) tabLayout.findViewById(R.id.about_version_brand); + TextView versionManufacturerTextView = (TextView) tabLayout.findViewById(R.id.about_version_manufacturer); + TextView versionModelTextView = (TextView) tabLayout.findViewById(R.id.about_version_model); + TextView versionDeviceTextView = (TextView) tabLayout.findViewById(R.id.about_version_device); + TextView versionBootloaderTextView = (TextView) tabLayout.findViewById(R.id.about_version_bootloader); + TextView versionRadioTextView = (TextView) tabLayout.findViewById(R.id.about_version_radio); + TextView versionAndroidTextView = (TextView) tabLayout.findViewById(R.id.about_version_android); + TextView versionBuildTextView = (TextView) tabLayout.findViewById(R.id.about_version_build); + TextView versionSecurityPatchTextView = (TextView) tabLayout.findViewById(R.id.about_version_securitypatch); + TextView versionWebKitTextView = (TextView) tabLayout.findViewById(R.id.about_version_webkit); + TextView versionChromeText = (TextView) tabLayout.findViewById(R.id.about_version_chrome); + + // Setup the labels. String version = getString(R.string.version) + " " + BuildConfig.VERSION_NAME + " (" + getString(R.string.version_code) + " " + Integer.toString(BuildConfig.VERSION_CODE) + ")"; - versionNumberText.setText(version); - - // Brand. - TextView versionBrandText = (TextView) tabLayout.findViewById(R.id.about_version_brand_text); - versionBrandText.setText(Build.BRAND); - - // Manufacturer. - TextView versionManufacturerText = (TextView) tabLayout.findViewById(R.id.about_version_manufacturer_text); - versionManufacturerText.setText(Build.MANUFACTURER); - - // Model. - TextView versionModelText = (TextView) tabLayout.findViewById(R.id.about_version_model_text); - versionModelText.setText(Build.MODEL); - - // Device. - TextView versionDeviceText = (TextView) tabLayout.findViewById(R.id.about_version_device_text); - versionDeviceText.setText(Build.DEVICE); - - // Bootloader. - TextView versionBootloaderText = (TextView) tabLayout.findViewById(R.id.about_version_bootloader_text); - versionBootloaderText.setText(Build.BOOTLOADER); - - // Radio. - TextView versionRadioText = (TextView) tabLayout.findViewById(R.id.about_version_radio_text); - // Hide versionRadioTextView if there is no radio. - if (Build.getRadioVersion().equals("")) { - TextView versionRadioTitle = (TextView) tabLayout.findViewById(R.id.about_version_radio_title); - versionRadioTitle.setVisibility(View.GONE); - versionRadioText.setVisibility(View.GONE); - } else { // Else, set the text. - versionRadioText.setText(Build.getRadioVersion()); - } + String brandLabel = getString(R.string.brand) + " "; + String manufacturerLabel = getString(R.string.manufacturer) + " "; + String modelLabel = getString(R.string.model) + " "; + String deviceLabel = getString(R.string.device) + " "; + String bootloaderLabel = getString(R.string.bootloader) + " "; + String androidLabel = getString(R.string.android) + " "; + String buildLabel = getString(R.string.build) + " "; + String webKitLabel = getString(R.string.webkit) + " "; + String chromeLabel = getString(R.string.chrome) + " "; + + // `webViewLayout` is only used to get the default user agent from `about_tab_webview`. It is not used to render content on the screen. + View webViewLayout = inflater.inflate(R.layout.about_tab_webview, container, false); + WebView tabLayoutWebView = (WebView) webViewLayout.findViewById(R.id.about_tab_webview); + String userAgentString = tabLayoutWebView.getSettings().getUserAgentString(); - // Android. - TextView versionAndroidText = (TextView) tabLayout.findViewById(R.id.about_version_android_text); + // Get the device's information and store it in strings. + String brand = Build.BRAND; + String manufacturer = Build.MANUFACTURER; + String model = Build.MODEL; + String device = Build.DEVICE; + String bootloader = Build.BOOTLOADER; + String radio = Build.getRadioVersion(); String android = Build.VERSION.RELEASE + " (" + getString(R.string.api) + " " + Integer.toString(Build.VERSION.SDK_INT) + ")"; - versionAndroidText.setText(android); - - // Build. - TextView versionBuildText = (TextView) tabLayout.findViewById(R.id.about_version_build_text); - versionBuildText.setText(Build.DISPLAY); + String build = Build.DISPLAY; + // Select the substring that begins after "Safari/" and goes to the end of the string. + String webKit = userAgentString.substring(userAgentString.indexOf("Safari/") + 7); + // Select the substring that begins after "Chrome/" and goes until the next " ". + String chrome = userAgentString.substring(userAgentString.indexOf("Chrome/") + 7, userAgentString.indexOf(" ", userAgentString.indexOf("Chrome/"))); + + // Create a `SpannableStringBuilder` for each `TextView` that needs multiple colors of text. + SpannableStringBuilder brandStringBuilder = new SpannableStringBuilder(brandLabel + brand); + SpannableStringBuilder manufacturerStringBuilder = new SpannableStringBuilder(manufacturerLabel + manufacturer); + SpannableStringBuilder modelStringBuilder = new SpannableStringBuilder(modelLabel + model); + SpannableStringBuilder deviceStringBuilder = new SpannableStringBuilder(deviceLabel + device); + SpannableStringBuilder bootloaderStringBuilder = new SpannableStringBuilder(bootloaderLabel + bootloader); + SpannableStringBuilder androidStringBuilder = new SpannableStringBuilder(androidLabel + android); + SpannableStringBuilder buildStringBuilder = new SpannableStringBuilder(buildLabel + build); + SpannableStringBuilder webKitStringBuilder = new SpannableStringBuilder(webKitLabel + webKit); + SpannableStringBuilder chromeStringBuilder = new SpannableStringBuilder(chromeLabel + chrome); + + // Create a blue `ForegroundColorSpan`. We have to use the deprecated `getColor` until API >= 23. + ForegroundColorSpan blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue)); + + // Setup the spans to display the device information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction. + brandStringBuilder.setSpan(blueColorSpan, brandLabel.length(), brandStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + manufacturerStringBuilder.setSpan(blueColorSpan, manufacturerLabel.length(), manufacturerStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + modelStringBuilder.setSpan(blueColorSpan, modelLabel.length(), modelStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + deviceStringBuilder.setSpan(blueColorSpan, deviceLabel.length(), deviceStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + bootloaderStringBuilder.setSpan(blueColorSpan, bootloaderLabel.length(), bootloaderStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + androidStringBuilder.setSpan(blueColorSpan, androidLabel.length(), androidStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + buildStringBuilder.setSpan(blueColorSpan, buildLabel.length(), buildStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + webKitStringBuilder.setSpan(blueColorSpan, webKitLabel.length(), webKitStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + chromeStringBuilder.setSpan(blueColorSpan, chromeLabel.length(), chromeStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + + // Display the strings. + versionNumberTextView.setText(version); + versionBrandTextView.setText(buildStringBuilder); + versionManufacturerTextView.setText(manufacturerStringBuilder); + versionModelTextView.setText(modelStringBuilder); + versionDeviceTextView.setText(deviceStringBuilder); + versionBootloaderTextView.setText(bootloaderStringBuilder); + versionAndroidTextView.setText(androidStringBuilder); + versionBuildTextView.setText(buildStringBuilder); + versionWebKitTextView.setText(webKitStringBuilder); + versionChromeText.setText(chromeStringBuilder); - // Security Patch. - TextView versionSecurityPatchText = (TextView) tabLayout.findViewById(R.id.about_version_securitypatch_text); // Build.VERSION.SECURITY_PATCH is only available for SDK_INT >= 23. if (Build.VERSION.SDK_INT >= 23) { - versionSecurityPatchText.setText(Build.VERSION.SECURITY_PATCH); - } else { // Hide versionSecurityPatchTextView. - TextView versionSecurityPatchTitle = (TextView) tabLayout.findViewById(R.id.about_version_securitypatch_title); - versionSecurityPatchTitle.setVisibility(View.GONE); - versionSecurityPatchText.setVisibility(View.GONE); + String securityPatchLabel = getString(R.string.security_patch) + " "; + String securityPatch = Build.VERSION.SECURITY_PATCH; + SpannableStringBuilder securityPatchStringBuilder = new SpannableStringBuilder(securityPatchLabel + securityPatch); + securityPatchStringBuilder.setSpan(blueColorSpan, securityPatchLabel.length(), securityPatchStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + versionSecurityPatchTextView.setText(securityPatchStringBuilder); + } else { // Hide `versionSecurityPatchTextView`. + versionSecurityPatchTextView.setVisibility(View.GONE); } - // webViewLayout is only used to get the default user agent from about_tab_webview. It is not used to render content on the screen. - View webViewLayout = inflater.inflate(R.layout.about_tab_webview, container, false); - WebView tabLayoutWebView = (WebView) webViewLayout.findViewById(R.id.about_tab_webview); - String userAgentString = tabLayoutWebView.getSettings().getUserAgentString(); - - // WebKit. - TextView versionWebKitText = (TextView) tabLayout.findViewById(R.id.about_version_webkit_text); - // Select the substring that begins after "Safari/" and goes to the end of the string. - String webkitVersion = userAgentString.substring(userAgentString.indexOf("Safari/") + 7); - versionWebKitText.setText(webkitVersion); - - // Chrome. - TextView versionChromeText = (TextView) tabLayout.findViewById(R.id.about_version_chrome_text); - // Select the substring that begins after "Chrome/" and goes until the next " ". - String chromeVersion = userAgentString.substring(userAgentString.indexOf("Chrome/") + 7, userAgentString.indexOf(" ", userAgentString.indexOf("Chrome/"))); - versionChromeText.setText(chromeVersion); + // Only populate `versionRadioTextView` if there is a radio in the device. + if (!radio.equals("")) { + String radioLabel = getString(R.string.radio) + " "; + SpannableStringBuilder radioStringBuilder = new SpannableStringBuilder(radioLabel + radio); + radioStringBuilder.setSpan(blueColorSpan, radioLabel.length(), radioStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + versionRadioTextView.setText(radioStringBuilder); + } else { // Hide `versionRadioTextView`. + versionRadioTextView.setVisibility(View.GONE); + } } else { // load a WebView for all the other tabs. Tab numbers start at 0. // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. // The fragment will take care of attaching the root automatically. diff --git a/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java b/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java index 80c9c1e7..45702f62 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java +++ b/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java @@ -204,7 +204,7 @@ public class SslCertificateError extends DialogFragment{ String startDateLabel = getString(R.string.start_date) + " "; String endDateLabel = getString(R.string.end_date) + " "; - // Create a `SpannableStringBuilder` for each item. + // Create a `SpannableStringBuilder` for each `TextView` that needs multiple colors of text. SpannableStringBuilder urlStringBuilder = new SpannableStringBuilder(urlLabel + urlWithError); SpannableStringBuilder issuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + issuedToCName); SpannableStringBuilder issuedToONameStringBuilder = new SpannableStringBuilder(oNameLabel + issuedToOName); @@ -218,8 +218,7 @@ public class SslCertificateError extends DialogFragment{ // Create a blue `ForegroundColorSpan`. We have to use the deprecated `getColor` until API >= 23. ForegroundColorSpan blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue)); - // Setup the spans to display the certificate information in blue. - // `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction. + // Setup the spans to display the certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction. urlStringBuilder.setSpan(blueColorSpan, urlLabel.length(), urlStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); issuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); issuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), issuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); diff --git a/app/src/main/java/com/stoutner/privacybrowser/ViewSslCertificate.java b/app/src/main/java/com/stoutner/privacybrowser/ViewSslCertificate.java index 8b370748..2a81362a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/ViewSslCertificate.java +++ b/app/src/main/java/com/stoutner/privacybrowser/ViewSslCertificate.java @@ -112,7 +112,7 @@ public class ViewSslCertificate extends DialogFragment { Date startDate = sslCertificate.getValidNotBeforeDate(); Date endDate = sslCertificate.getValidNotAfterDate(); - // Create a `SpannableStringBuilder` for each item. + // Create a `SpannableStringBuilder` for each `TextView` that needs multiple colors of text. SpannableStringBuilder issuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + issuedToCNameString); SpannableStringBuilder issuedToONameStringBuilder = new SpannableStringBuilder(oNameLabel + issuedToONameString); SpannableStringBuilder issuedToUNameStringBuilder = new SpannableStringBuilder(uNameLabel + issuedToUNameString); @@ -125,8 +125,7 @@ public class ViewSslCertificate extends DialogFragment { // Create a blue `ForegroundColorSpan`. We have to use the deprecated `getColor` until API >= 23. ForegroundColorSpan blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue)); - // Setup the spans to display the certificate information in blue. - // `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction. + // Setup the spans to display the certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction. issuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); issuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), issuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); issuedToUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), issuedToUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); diff --git a/app/src/main/res/layout/about_tab_version.xml b/app/src/main/res/layout/about_tab_version.xml index 97a5293f..0fd52013 100644 --- a/app/src/main/res/layout/about_tab_version.xml +++ b/app/src/main/res/layout/about_tab_version.xml @@ -18,29 +18,26 @@ You should have received a copy of the GNU General Public License along with Privacy Browser. If not, see . --> - + - + + android:layout_height="wrap_content" > - + - + android:layout_toEndOf="@id/about_version_icon" /> - + android:layout_toEndOf="@id/about_version_icon" /> - + + android:paddingEnd="0dp" > - - + android:layout_height="wrap_content" /> - - - - - - - - - - - - + android:layout_height="wrap_content" /> - - - - + android:layout_height="wrap_content" /> - - - - - + android:layout_height="wrap_content"/> - - - - - - - - - - - - + android:layout_height="wrap_content" /> - - - - - - - + android:layout_height="wrap_content"/> - - - - - - - + android:layout_height="wrap_content"/> - - - - + android:layout_height="wrap_content"/> - - - - - - - - - - + android:layout_height="wrap_content" /> - - - - + android:layout_height="wrap_content"/> - - - - - - - - - - + android:layout_height="wrap_content" /> \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c090615d..4ee7ccde 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -177,20 +177,19 @@ Version Versions-Code Hardware - - Marke:\u00A0 - Hersteller:\u00A0 - Modell:\u00A0 - Gerät:\u00A0 - Bootloader:\u00A0 - Radio:\u00A0 + Marke: + Hersteller: + Modell: + Gerät: + Bootloader: + Radio: Software - Android:\u00A0 + Android: API - Build:\u00A0 - Sicherheits-Patch:\u00A0 - WebKit:\u00A0 - Chrome:\u00A0 + Build: + Sicherheits-Patch: + WebKit: + Chrome: Berechtigungen Datenschutzrichtlinie Changelog diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ac11edcf..50fe3591 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -41,7 +41,7 @@ View SSL Certificate Unencrypted Website - Communicated with this website is not encrypted by an SSL certificate. + Communication with this website is not encrypted by an SSL certificate. SSL Certificate Close Issued To @@ -176,7 +176,7 @@ Edge 13 on Windows 10 Custom - + Default user agent PrivacyBrowser/1.0 Mozilla/5.0 (Android 6.0.1; Mobile; rv:46.0) Gecko/46.0 Firefox/46.0 @@ -200,7 +200,7 @@ Yahoo Custom - + https://duckduckgo.com/html/?q= https://www.google.com/search?q= https://www.bing.com/search?q= @@ -216,7 +216,7 @@ Yahoo Custom - + https://duckduckgo.com/?q= https://www.google.com/search?q= https://www.bing.com/search?q= @@ -237,7 +237,7 @@ 175% 200% - + 50 75 100 @@ -254,20 +254,19 @@ Version version code Hardware - - Brand:\u00A0 - Manufacturer:\u00A0 - Model:\u00A0 - Device:\u00A0 - Bootloader:\u00A0 - Radio:\u00A0 + Brand: + Manufacturer: + Model: + Device: + Bootloader: + Radio: Software - Android:\u00A0 + Android: API - Build:\u00A0 - Security Patch:\u00A0 - WebKit:\u00A0 - Chrome:\u00A0 + Build: + Security Patch: + WebKit: + Chrome: Permissions Privacy Policy Changelog