| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java
|
| index 9d458062a26ef78de94e11073a0a2b1fec999743..797c767c684bcaefe7d53ec1944cf55b2ee8388c 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java
|
| @@ -4,127 +4,72 @@
|
|
|
| package org.chromium.chrome.browser.infobar;
|
|
|
| -import android.text.Spannable;
|
| import android.text.SpannableString;
|
| -import android.text.TextUtils;
|
| +import android.text.Spanned;
|
| import android.text.style.ClickableSpan;
|
| -import android.view.Menu;
|
| -import android.view.MenuItem;
|
| import android.view.View;
|
| -import android.widget.PopupMenu;
|
| -import android.widget.TextView;
|
| +import android.widget.Spinner;
|
|
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.ResourceId;
|
| +import org.chromium.chrome.browser.infobar.InfoBarControlLayout.InfoBarArrayAdapter;
|
|
|
| /**
|
| * The Update Password infobar offers the user the ability to update a password for the site.
|
| */
|
| -public class UpdatePasswordInfoBar
|
| - extends ConfirmInfoBar implements PopupMenu.OnMenuItemClickListener {
|
| - private final long mNativePtr;
|
| +public class UpdatePasswordInfoBar extends ConfirmInfoBar {
|
| private final String[] mUsernames;
|
| - private final boolean mShowMultipleAccounts;
|
| - private final boolean mIsSmartLockEnabled;
|
| - private final SpannableString mBrandingSpan;
|
| - private int mSelectedUsername;
|
| - private TextView mMessageView;
|
| + private final int mTitleLinkRangeStart;
|
| + private final int mTitleLinkRangeEnd;
|
| + private final String mTitle;
|
| + private Spinner mUsernamesSpinner;
|
|
|
| @CalledByNative
|
| - private static InfoBar show(long nativePtr, int enumeratedIconId, String[] usernames,
|
| - String primaryButtonText, String secondaryButtonText, String branding,
|
| - boolean showMultipleAccounts, boolean isSmartLockEnabled) {
|
| - return new UpdatePasswordInfoBar(nativePtr, ResourceId.mapToDrawableId(enumeratedIconId),
|
| - usernames, primaryButtonText, secondaryButtonText, branding, showMultipleAccounts,
|
| - isSmartLockEnabled);
|
| + private static InfoBar show(int enumeratedIconId, String[] usernames, String message,
|
| + int titleLinkStart, int titleLinkEnd, String primaryButtonText,
|
| + String secondaryButtonText) {
|
| + return new UpdatePasswordInfoBar(ResourceId.mapToDrawableId(enumeratedIconId), usernames,
|
| + message, titleLinkStart, titleLinkEnd, primaryButtonText, secondaryButtonText);
|
| }
|
|
|
| - private UpdatePasswordInfoBar(long nativePtr, int iconDrawbleId, String[] usernames,
|
| - String primaryButtonText, String secondaryButtonText, String branding,
|
| - boolean showMultipleAccounts, boolean isSmartLockEnabled) {
|
| - super(iconDrawbleId, null, null, null, primaryButtonText, secondaryButtonText);
|
| - mNativePtr = nativePtr;
|
| + private UpdatePasswordInfoBar(int iconDrawbleId, String[] usernames, String message,
|
| + int titleLinkStart, int titleLinkEnd, String primaryButtonText,
|
| + String secondaryButtonText) {
|
| + super(iconDrawbleId, null, message, null, primaryButtonText, secondaryButtonText);
|
| + mTitleLinkRangeStart = titleLinkStart;
|
| + mTitleLinkRangeEnd = titleLinkEnd;
|
| + mTitle = message;
|
| mUsernames = usernames;
|
| - mShowMultipleAccounts = showMultipleAccounts;
|
| - mIsSmartLockEnabled = isSmartLockEnabled;
|
| - mBrandingSpan = new SpannableString(branding);
|
| - }
|
| -
|
| - private void onUsernameLinkClicked(View v) {
|
| - PopupMenu popup = new PopupMenu(getContext(), v);
|
| - for (int i = 0; i < mUsernames.length; ++i) {
|
| - MenuItem item = popup.getMenu().add(Menu.NONE, i, i, mUsernames[i]);
|
| - }
|
| - popup.setOnMenuItemClickListener(this);
|
| - popup.show();
|
| - }
|
| -
|
| - /**
|
| - * Returns the infobar message for the case when PasswordManager has a guess which credentials
|
| - * pair should be updated. There are two cases possible: there is only one credential pair that
|
| - * should be updated and there several guesses available. In the first case user is presented
|
| - * with the username of the credentials that should be updated in the second case user is able
|
| - * to choose which of the available credentials to update.
|
| - * It also remembered the choice made.
|
| - */
|
| - private CharSequence createUsernameMessageText(int selectedUsername) {
|
| - CharSequence message;
|
| - mSelectedUsername = selectedUsername;
|
| - final String template = getContext().getString(R.string.update_password_for_account);
|
| - final String usernameToDisplay = mUsernames[mSelectedUsername];
|
| - if (mShowMultipleAccounts) {
|
| - final String downPointingArrow = " \u25BE";
|
| - SpannableString usernameSelector =
|
| - new SpannableString(usernameToDisplay + downPointingArrow);
|
| - usernameSelector.setSpan(new ClickableSpan() {
|
| - @Override
|
| - public void onClick(View view) {
|
| - onUsernameLinkClicked(view);
|
| - }
|
| - }, 0, usernameSelector.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
| - message = TextUtils.expandTemplate(template, mBrandingSpan, usernameSelector);
|
| - } else {
|
| - message = TextUtils.expandTemplate(template, mBrandingSpan, usernameToDisplay);
|
| - }
|
| - return message;
|
| - }
|
| -
|
| - /**
|
| - * If user have chosen different than was shown username to update, then we need to change the
|
| - * infobar message in order to reflect this choice.
|
| - */
|
| - public boolean onMenuItemClick(MenuItem item) {
|
| - mMessageView.setText(
|
| - createUsernameMessageText(item.getItemId()), TextView.BufferType.SPANNABLE);
|
| - return false;
|
| }
|
|
|
| @Override
|
| public void createContent(InfoBarLayout layout) {
|
| super.createContent(layout);
|
| - CharSequence message;
|
| - if (mIsSmartLockEnabled) {
|
| - mBrandingSpan.setSpan(new ClickableSpan() {
|
| + if (mTitleLinkRangeStart != 0 && mTitleLinkRangeEnd != 0) {
|
| + SpannableString title = new SpannableString(mTitle);
|
| + title.setSpan(new ClickableSpan() {
|
| @Override
|
| public void onClick(View view) {
|
| onLinkClicked();
|
| }
|
| - }, 0, mBrandingSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
| + }, mTitleLinkRangeStart, mTitleLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
| + layout.setMessage(title);
|
| }
|
| - if (mShowMultipleAccounts || mUsernames.length != 0) {
|
| - message = createUsernameMessageText(0);
|
| +
|
| + InfoBarControlLayout controlLayout = layout.addControlLayout();
|
| + if (mUsernames.length > 1) {
|
| + InfoBarArrayAdapter<String> usernamesAdapter =
|
| + new InfoBarArrayAdapter<String>(getContext(), mUsernames);
|
| + mUsernamesSpinner = controlLayout.addSpinner(
|
| + R.id.password_infobar_accounts_spinner, usernamesAdapter);
|
| } else {
|
| - String template = getContext().getString(R.string.update_password);
|
| - message = TextUtils.expandTemplate(template, mBrandingSpan);
|
| + controlLayout.addDescription(mUsernames[0]);
|
| }
|
| -
|
| - mMessageView = layout.getMessageTextView();
|
| - mMessageView.setText(message, TextView.BufferType.SPANNABLE);
|
| }
|
|
|
| @CalledByNative
|
| private int getSelectedUsername() {
|
| - return mSelectedUsername;
|
| + return mUsernames.length == 1 ? 0 : mUsernamesSpinner.getSelectedItemPosition();
|
| }
|
| }
|
|
|