Commit a5706304 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download location: Add prefix to download location preference summary.

This CL adds a prefix with bold text style to download location
preference summary.

Bug: 847541
Change-Id: I9260197460b055b3ffa161e13bf98c7a7459d594
Reviewed-on: https://chromium-review.googlesource.com/1077651
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563027}
parent b458879b
...@@ -6,12 +6,16 @@ package org.chromium.chrome.browser.preferences.download; ...@@ -6,12 +6,16 @@ package org.chromium.chrome.browser.preferences.download;
import android.content.Context; import android.content.Context;
import android.preference.DialogPreference; import android.preference.DialogPreference;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.download.DirectoryOption;
/** /**
* The preference used to save the download directory in download settings page. * The preference used to save the download directory in download settings page.
...@@ -35,6 +39,22 @@ public class DownloadLocationPreference extends DialogPreference { ...@@ -35,6 +39,22 @@ public class DownloadLocationPreference extends DialogPreference {
mAdapter = new DownloadLocationPreferenceAdapter(context, this); mAdapter = new DownloadLocationPreferenceAdapter(context, this);
} }
/**
* Updates the summary that shows the download location directory.
*/
public void updateSummary() {
DirectoryOption directoryOption =
(DirectoryOption) mAdapter.getItem(mAdapter.getSelectedItemId());
final SpannableStringBuilder summaryBuilder = new SpannableStringBuilder();
summaryBuilder.append(directoryOption.name);
summaryBuilder.append(" ");
summaryBuilder.append(directoryOption.location.getAbsolutePath());
summaryBuilder.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
directoryOption.name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
setSummary(summaryBuilder);
}
@Override @Override
protected View onCreateDialogView() { protected View onCreateDialogView() {
View view = LayoutInflater.from(getContext()) View view = LayoutInflater.from(getContext())
......
...@@ -101,10 +101,12 @@ public class DownloadLocationPreferenceAdapter ...@@ -101,10 +101,12 @@ public class DownloadLocationPreferenceAdapter
editor.putString( editor.putString(
DownloadPreferences.PREF_LOCATION_CHANGE, option.location.getAbsolutePath()); DownloadPreferences.PREF_LOCATION_CHANGE, option.location.getAbsolutePath());
editor.apply(); editor.apply();
mPreference.setSummary(option.location.getAbsolutePath());
mSelectedPosition = selectedId; mSelectedPosition = selectedId;
// Update the preference after selected position is updated.
mPreference.updateSummary();
option.recordDirectoryOptionType(); option.recordDirectoryOptionType();
// Refresh the list of download directories UI. // Refresh the list of download directories UI.
......
...@@ -50,8 +50,7 @@ public class DownloadPreferences ...@@ -50,8 +50,7 @@ public class DownloadPreferences
private void updateData() { private void updateData() {
if (mLocationChangePref != null) { if (mLocationChangePref != null) {
mLocationChangePref.setSummary( mLocationChangePref.updateSummary();
PrefServiceBridge.getInstance().getDownloadDefaultDirectory());
} }
if (mLocationPromptEnabledPref != null) { if (mLocationPromptEnabledPref != null) {
......
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