+ 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);