Index: chrome/android/java/src/org/chromium/chrome/browser/password_manager/AccountChooserDialog.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/password_manager/AccountChooserDialog.java b/chrome/android/java/src/org/chromium/chrome/browser/password_manager/AccountChooserDialog.java |
index 4c41262fb1945784f7eb33a5ab13b333c6e4846c..6dbaa4171c2bb05a3e0d076c838436980eb2a01b 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/password_manager/AccountChooserDialog.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/password_manager/AccountChooserDialog.java |
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.password_manager; |
import android.app.Activity; |
import android.content.Context; |
import android.content.DialogInterface; |
+import android.content.res.Resources; |
import android.graphics.Bitmap; |
import android.support.v7.app.AlertDialog; |
import android.text.SpannableString; |
@@ -14,18 +15,23 @@ import android.text.Spanned; |
import android.text.TextUtils; |
import android.text.method.LinkMovementMethod; |
import android.text.style.ClickableSpan; |
+import android.view.Gravity; |
import android.view.LayoutInflater; |
import android.view.View; |
import android.view.ViewGroup; |
import android.widget.ArrayAdapter; |
+import android.widget.ImageButton; |
import android.widget.ImageView; |
import android.widget.ListView; |
import android.widget.TextView; |
+import org.chromium.base.ApiCompatibilityUtils; |
import org.chromium.base.annotations.CalledByNative; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.signin.AccountManagementFragment; |
+import org.chromium.components.url_formatter.UrlFormatter; |
import org.chromium.ui.base.WindowAndroid; |
+import org.chromium.ui.widget.Toast; |
/** |
* A dialog offers the user the ability to choose credentials for authentication. User is |
@@ -138,6 +144,20 @@ public class AccountChooserDialog |
secondaryNameView.setVisibility(View.VISIBLE); |
} |
+ ImageButton pslInfoButton = |
+ (ImageButton) convertView.findViewById(R.id.psl_info_btn); |
+ final String originUrl = credential.getOriginUrl(); |
+ |
+ if (!originUrl.isEmpty()) { |
+ pslInfoButton.setVisibility(View.VISIBLE); |
+ pslInfoButton.setOnClickListener(new View.OnClickListener() { |
+ @Override |
+ public void onClick(View view) { |
+ prepareButtonView((ImageButton) view, originUrl); |
+ } |
+ }); |
+ } |
+ |
return convertView; |
} |
}; |
@@ -181,6 +201,42 @@ public class AccountChooserDialog |
mDialog.show(); |
} |
+ private void prepareButtonView(ImageButton buttonView, String originUrl) { |
gone
2016/12/13 23:14:30
This isn't really preparing a the buttonView; it's
jdoerrie
2016/12/14 16:04:01
How do you suggest we pass gravity, xOffset, yOffs
gone
2016/12/14 18:20:42
Eh, passing the Toast back would defeat most of th
jdoerrie
2016/12/15 13:27:18
Done.
|
+ Context context = buttonView.getContext(); |
+ Resources resources = context.getResources(); |
+ |
+ LayoutInflater inflater = LayoutInflater.from(context); |
+ View layout = inflater.inflate(R.layout.psl_info_tooltip, |
+ (ViewGroup) buttonView.findViewById(R.id.psl_info_tooltip)); |
gone
2016/12/13 23:14:30
1) I'd avoid having a layout with the same name as
jdoerrie
2016/12/15 13:27:18
Done.
|
+ |
+ TextView text = (TextView) layout.findViewById(R.id.psl_info_tooltip_text); |
+ text.setText(UrlFormatter.formatUrlForSecurityDisplay(originUrl, true /* showScheme */)); |
+ text.announceForAccessibility(text.getText()); |
+ |
+ final int screenWidth = resources.getDisplayMetrics().widthPixels; |
+ final int screenHeight = resources.getDisplayMetrics().heightPixels; |
+ |
+ final int[] screenPos = new int[2]; |
+ buttonView.getLocationOnScreen(screenPos); |
+ |
+ final int width = buttonView.getWidth(); |
+ final int tooltipMargin = resources.getDimensionPixelSize(R.dimen.psl_info_tooltip_margin); |
+ |
+ // The toast should be shown above and to the left (right for RTL) of the info button. |
+ // In order to avoid measuring the size of the toast offsets are specified with regard |
+ // to the bottom right / left corner of the screen. |
+ final int xOffset = ApiCompatibilityUtils.isLayoutRtl(buttonView) |
+ ? screenPos[0] |
+ : screenWidth - screenPos[0] - width; |
+ final int yOffset = screenHeight - screenPos[1] + tooltipMargin; |
+ |
+ Toast toast = new Toast(context); |
+ toast.setGravity(Gravity.BOTTOM | Gravity.END, xOffset, yOffset); |
+ toast.setDuration(Toast.LENGTH_SHORT); |
+ toast.setView(layout); |
+ toast.show(); |
+ } |
+ |
@CalledByNative |
private void imageFetchComplete(int index, Bitmap avatarBitmap) { |
if (mIsDestroyed) return; |