Commit 0cc7b305 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download location: fix storage summary string.

The storage summary string under download home title currently uses
SpannableString that can expand to multiple lines, and can only apply
simple styles defined by Spannale.

This CL adds a view for the summary string.


Bug: 849973
Change-Id: If01d323022e0cc743540a02ba58801c664957aa4
Reviewed-on: https://chromium-review.googlesource.com/1089815Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565309}
parent c7b8b360
...@@ -3,7 +3,24 @@ ...@@ -3,7 +3,24 @@
Use of this source code is governed by a BSD-style license that can be Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. --> found in the LICENSE file. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:chrome="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/BlackHeadline1" /> android:paddingTop="0dp"
\ No newline at end of file android:paddingBottom="0dp"
android:orientation="vertical" >
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/download_home_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/BlackHeadline1" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/download_storage_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textAppearance="@style/BlackDisabledText2" />
</LinearLayout>
...@@ -4,16 +4,10 @@ ...@@ -4,16 +4,10 @@
package org.chromium.chrome.browser.download.ui; package org.chromium.chrome.browser.download.ui;
import android.graphics.Typeface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Environment; import android.os.Environment;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.graphics.drawable.VectorDrawableCompat; import android.support.graphics.drawable.VectorDrawableCompat;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -72,8 +66,8 @@ class FilterAdapter ...@@ -72,8 +66,8 @@ class FilterAdapter
@Override @Override
public View getDropDownView(int position, View convertView, ViewGroup parent) { public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView labelView = TextView labelView = (TextView) getViewFromResource(
getTextViewFromResource(convertView, R.layout.download_manager_spinner_drop_down); convertView, R.layout.download_manager_spinner_drop_down);
labelView.setText(DownloadFilter.getStringIdForFilter(position)); labelView.setText(DownloadFilter.getStringIdForFilter(position));
int iconId = DownloadFilter.getDrawableForFilter(position); int iconId = DownloadFilter.getDrawableForFilter(position);
VectorDrawableCompat iconDrawable = VectorDrawableCompat iconDrawable =
...@@ -88,58 +82,39 @@ class FilterAdapter ...@@ -88,58 +82,39 @@ class FilterAdapter
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
TextView labelView = View labelView = getViewFromResource(convertView, R.layout.download_manager_spinner);
getTextViewFromResource(convertView, R.layout.download_manager_spinner);
SpannableStringBuilder titleBuilder = new SpannableStringBuilder();
CharSequence title = mManagerUi.getActivity().getResources().getText(position == 0 CharSequence title = mManagerUi.getActivity().getResources().getText(position == 0
? R.string.menu_downloads ? R.string.menu_downloads
: DownloadFilter.getStringIdForFilter(position)); : DownloadFilter.getStringIdForFilter(position));
titleBuilder.append(title);
TextView titleView = labelView.findViewById(R.id.download_home_title);
titleView.setText(title);
// Set the storage summary for download location change feature. // Set the storage summary for download location change feature.
TextView summaryView = labelView.findViewById(R.id.download_storage_summary);
if (ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOADS_LOCATION_CHANGE) if (ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOADS_LOCATION_CHANGE)
&& mDirectoryOption != null) { && mDirectoryOption != null) {
titleBuilder.append("\n");
String storageSummary = String storageSummary =
mManagerUi.getActivity().getString(R.string.download_manager_ui_space_using, mManagerUi.getActivity().getString(R.string.download_manager_ui_space_using,
DownloadUtils.getStringForBytes( DownloadUtils.getStringForBytes(
mManagerUi.getActivity(), mDirectoryOption.availableSpace), mManagerUi.getActivity(), mDirectoryOption.availableSpace),
DownloadUtils.getStringForBytes( DownloadUtils.getStringForBytes(
mManagerUi.getActivity(), mDirectoryOption.totalSpace)); mManagerUi.getActivity(), mDirectoryOption.totalSpace));
titleBuilder.append(storageSummary); summaryView.setText(storageSummary);
@SuppressWarnings("deprecation") } else {
int color = mManagerUi.getActivity().getResources().getColor(R.color.black_alpha_38); summaryView.setVisibility(View.GONE);
int start = title.length() + 1;
int end = title.length() + storageSummary.length() + 1;
titleBuilder.setSpan(
new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleBuilder.setSpan(
new RelativeSizeSpan(0.65f), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleBuilder.setSpan(
new StyleSpan(Typeface.NORMAL), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
labelView.setText(titleBuilder);
if (!FeatureUtilities.isChromeModernDesignEnabled()) { if (!FeatureUtilities.isChromeModernDesignEnabled()) {
ApiCompatibilityUtils.setTextAppearance(labelView, R.style.BlackHeadline2); ApiCompatibilityUtils.setTextAppearance(titleView, R.style.BlackHeadline2);
} }
return labelView; return labelView;
} }
private TextView getTextViewFromResource(View convertView, @LayoutRes int resId) { private View getViewFromResource(View convertView, @LayoutRes int resId) {
TextView labelView = null; if (convertView != null) return convertView;
if (convertView instanceof TextView) { return LayoutInflater.from(mManagerUi.getActivity()).inflate(resId, null);
labelView = (TextView) convertView;
} else {
labelView =
(TextView) LayoutInflater.from(mManagerUi.getActivity()).inflate(resId, null);
}
return labelView;
} }
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment