Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(674)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/AccountChooserInfoBar.java

Issue 925593006: Pass all info to account chooser infobar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@java_cpp_enum
Patch Set: Removing avatar URL Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.infobar; 5 package org.chromium.chrome.browser.infobar;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
9 import android.view.View; 9 import android.view.View;
10 import android.view.ViewGroup; 10 import android.view.ViewGroup;
11 import android.widget.ArrayAdapter; 11 import android.widget.ArrayAdapter;
12 import android.widget.FrameLayout; 12 import android.widget.FrameLayout;
13 import android.widget.ImageView; 13 import android.widget.ImageView;
14 import android.widget.LinearLayout; 14 import android.widget.LinearLayout;
15 import android.widget.ListView; 15 import android.widget.ListView;
16 import android.widget.TextView; 16 import android.widget.TextView;
17 17
18 import org.chromium.base.CalledByNative; 18 import org.chromium.base.CalledByNative;
19 import org.chromium.chrome.R; 19 import org.chromium.chrome.R;
20 import org.chromium.chrome.browser.ResourceId; 20 import org.chromium.chrome.browser.ResourceId;
21 import org.chromium.chrome.browser.password_manager.Credential;
21 22
22 /** 23 /**
23 * An infobar offers the user the ability to choose credentials for 24 * An infobar offers the user the ability to choose credentials for
24 * authentication. User is presented with username along with avatar and 25 * authentication. User is presented with username along with avatar and
25 * full name in case they are available. 26 * full name in case they are available.
26 */ 27 */
27 public class AccountChooserInfoBar extends InfoBar { 28 public class AccountChooserInfoBar extends InfoBar {
28 private enum CredentialType { 29 private final Credential[] mCredentials;
29 EMPTY(0),
30 LOCAL(1),
31 FEDERATED(2);
32
33 private final int mType;
34 private CredentialType(int type) {
35 mType = type;
36 };
37
38 public int getValue() {
39 return mType;
40 }
41 }
42
43 private final String[] mUsernames;
44 30
45 /** 31 /**
46 * Creates and shows the infobar wich allows user to choose credentials for login. 32 * Creates and shows the infobar wich allows user to choose credentials for login.
47 * @param nativeInfoBar Pointer to the native infobar. 33 * @param nativeInfoBar Pointer to the native infobar.
48 * @param enumeratedIconId Enum ID corresponding to the icon that the infoba r will show. 34 * @param enumeratedIconId Enum ID corresponding to the icon that the infoba r will show.
49 * @param usernames Usernames to display in the infobar. 35 * @param credentials Credentials to display in the infobar.
50 */ 36 */
51 @CalledByNative 37 @CalledByNative
52 private static InfoBar show(long nativeInfoBar, int enumeratedIconId, String [] usernames) { 38 private static InfoBar show(
39 long nativeInfoBar, int enumeratedIconId, Credential[] credentials) {
53 return new AccountChooserInfoBar( 40 return new AccountChooserInfoBar(
54 nativeInfoBar, ResourceId.mapToDrawableId(enumeratedIconId), use rnames); 41 nativeInfoBar, ResourceId.mapToDrawableId(enumeratedIconId), cre dentials);
55 } 42 }
56 43
57 /** 44 /**
58 * Creates and shows the infobar which allows user to choose credentials. 45 * Creates and shows the infobar which allows user to choose credentials.
59 * @param nativeInfoBar Pointer to the native infobar. 46 * @param nativeInfoBar Pointer to the native infobar.
60 * @param iconDrawableId Drawable ID corresponding to the icon that the info bar will show. 47 * @param iconDrawableId Drawable ID corresponding to the icon that the info bar will show.
61 * @param usernames list of usernames to display in infobar. 48 * @param credentials Credentials to display in the infobar.
62 */ 49 */
63 public AccountChooserInfoBar(long nativeInfoBar, int iconDrawableId, String[ ] usernames) { 50 public AccountChooserInfoBar(long nativeInfoBar, int iconDrawableId, Credent ial[] credentials) {
64 super(null /* Infobar Listener */, iconDrawableId, null /* bitmap*/, 51 super(null /* Infobar Listener */, iconDrawableId, null /* bitmap*/,
65 null /* message to show */); 52 null /* message to show */);
66 setNativeInfoBar(nativeInfoBar); 53 setNativeInfoBar(nativeInfoBar);
67 mUsernames = usernames.clone(); 54 mCredentials = credentials.clone();
68 } 55 }
69 56
70 57
71 @Override 58 @Override
72 public void onCloseButtonClicked() { 59 public void onCloseButtonClicked() {
73 // Notifies the native infobar, which closes the infobar. 60 // Notifies the native infobar, which closes the infobar.
74 nativeOnCloseButtonClicked(mNativeInfoBarPtr); 61 nativeOnCloseButtonClicked(mNativeInfoBarPtr);
75 } 62 }
76 63
77 @Override 64 @Override
78 public void onButtonClicked(boolean isPrimaryButton) { 65 public void onButtonClicked(boolean isPrimaryButton) {
79 onCloseButtonClicked(); 66 onCloseButtonClicked();
80 } 67 }
81 68
82 @Override 69 @Override
83 public void createContent(InfoBarLayout layout) { 70 public void createContent(InfoBarLayout layout) {
84 layout.setMessage(getContext().getString(R.string.account_chooser_infoba r_title)); 71 layout.setMessage(getContext().getString(R.string.account_chooser_infoba r_title));
85 createAccountsView(layout); 72 createAccountsView(layout);
86 createCustomButtonsView(layout); 73 createCustomButtonsView(layout);
87 } 74 }
88 75
89 private void createAccountsView(InfoBarLayout layout) { 76 private void createAccountsView(InfoBarLayout layout) {
90 ViewGroup accountsView = (ViewGroup) LayoutInflater.from(getContext()).i nflate( 77 ViewGroup accountsView = (ViewGroup) LayoutInflater.from(getContext()).i nflate(
91 R.layout.account_chooser_infobar_list, null, false); 78 R.layout.account_chooser_infobar_list, null, false);
92 ArrayAdapter<String> adapter = generateAccountsArrayAdapter(getContext() , mUsernames); 79 ArrayAdapter<Credential> adapter = generateAccountsArrayAdapter(getConte xt(), mCredentials);
93 ListView listView = (ListView) accountsView.findViewById(R.id.account_li st); 80 ListView listView = (ListView) accountsView.findViewById(R.id.account_li st);
94 listView.setAdapter(adapter); 81 listView.setAdapter(adapter);
95 float numVisibleItems = adapter.getCount() > 2 ? 2.5f : adapter.getCount (); 82 float numVisibleItems = adapter.getCount() > 2 ? 2.5f : adapter.getCount ();
96 int listViewHeight = (int) (numVisibleItems * getContext().getResources( ).getDimension( 83 int listViewHeight = (int) (numVisibleItems * getContext().getResources( ).getDimension(
97 R.dimen.account_chooser_infobar_item_height)); 84 R.dimen.account_chooser_infobar_item_height));
98 listView.setLayoutParams(new FrameLayout.LayoutParams( 85 listView.setLayoutParams(new FrameLayout.LayoutParams(
99 FrameLayout.LayoutParams.MATCH_PARENT, listViewHeight)); 86 FrameLayout.LayoutParams.MATCH_PARENT, listViewHeight));
100 layout.setCustomContent(accountsView); 87 layout.setCustomContent(accountsView);
101 } 88 }
102 89
103 private ArrayAdapter<String> generateAccountsArrayAdapter(Context context, S tring[] usernames) { 90 private ArrayAdapter<Credential> generateAccountsArrayAdapter(
104 return new ArrayAdapter<String>(context, 0, usernames) { 91 Context context, Credential[] credentials) {
92 return new ArrayAdapter<Credential>(context, 0, credentials) {
105 @Override 93 @Override
106 public View getView(int position, View convertView, ViewGroup parent ) { 94 public View getView(int position, View convertView, ViewGroup parent ) {
107 if (convertView == null) { 95 if (convertView == null) {
108 convertView = (LinearLayout) LayoutInflater.from(getContext( )).inflate( 96 convertView = (LinearLayout) LayoutInflater.from(getContext( )).inflate(
109 R.layout.account_chooser_infobar_item, parent, false); 97 R.layout.account_chooser_infobar_item, parent, false);
110 } 98 }
111 ImageView avatarView = (ImageView) convertView.findViewById(R.id .profile_image); 99 ImageView avatarView = (ImageView) convertView.findViewById(R.id .profile_image);
112 TextView usernameView = (TextView) convertView.findViewById(R.id .username); 100 TextView usernameView = (TextView) convertView.findViewById(R.id .username);
113 TextView displayNameView = (TextView) convertView.findViewById(R .id.display_name); 101 TextView displayNameView = (TextView) convertView.findViewById(R .id.display_name);
114 String username = getItem(position); 102 Credential credential = getItem(position);
115 usernameView.setText(username); 103 usernameView.setText(credential.getUsername());
116 // TODO(melandory): View should show the full name. Temporarily the view shows 104 displayNameView.setText(credential.getDisplayName());
117 // username.
118 displayNameView.setText(username);
119 // TODO(melandory): View should show proper avatar. Temporarily the view shows 105 // TODO(melandory): View should show proper avatar. Temporarily the view shows
120 // blue man icon. 106 // blue man icon.
121 avatarView.setImageResource(R.drawable.account_management_no_pic ture); 107 avatarView.setImageResource(R.drawable.account_management_no_pic ture);
122 final int currentCredentialIndex = position; 108 final int currentCredentialIndex = credential.getIndex();
newt (away) 2015/03/17 06:04:17 You can use the local variable "position" here, in
melandory 2015/03/17 13:05:33 Nope, |position| here is an index in array array o
109 final int credentialType = credential.getType();
123 convertView.setOnClickListener(new View.OnClickListener() { 110 convertView.setOnClickListener(new View.OnClickListener() {
124 @Override 111 @Override
125 public void onClick(View view) { 112 public void onClick(View view) {
126 passCredentialsToNative(currentCredentialIndex); 113 passCredentialsToNative(currentCredentialIndex, credenti alType);
127 } 114 }
128 }); 115 });
129 return convertView; 116 return convertView;
130 } 117 }
131 }; 118 };
132 } 119 }
133 120
134 /** 121 /**
135 * Creates button row which consists of "No thanks" button and "More" button . 122 * Creates button row which consists of "No thanks" button and "More" button .
136 * "No thanks" buttons dismisses infobar. "More" button opens a popup menu, 123 * "No thanks" buttons dismisses infobar. "More" button opens a popup menu,
137 * which allows to go to help center article or Settings. 124 * which allows to go to help center article or Settings.
138 */ 125 */
139 private void createCustomButtonsView(InfoBarLayout layout) { 126 private void createCustomButtonsView(InfoBarLayout layout) {
140 layout.setButtons(getContext().getString(R.string.no_thanks), null); 127 layout.setButtons(getContext().getString(R.string.no_thanks), null);
141 layout.setCustomViewInButtonRow(OverflowSelector.createOverflowSelector( getContext())); 128 layout.setCustomViewInButtonRow(OverflowSelector.createOverflowSelector( getContext()));
142 } 129 }
143 130
144 private void passCredentialsToNative(int credentialIndex) { 131 private void passCredentialsToNative(int credentialIndex, int credentialType ) {
145 // TODO(melandory): Adding federated login support should change this 132 nativeOnCredentialClicked(mNativeInfoBarPtr, credentialIndex, credential Type);
newt (away) 2015/03/17 06:04:17 I'd inline this method. No need for the extra indi
melandory 2015/03/17 13:05:33 Done.
146 // code.
147 nativeOnCredentialClicked(
148 mNativeInfoBarPtr, credentialIndex, CredentialType.LOCAL.getValu e());
149 } 133 }
150 134
151 135
152 private native void nativeOnCredentialClicked( 136 private native void nativeOnCredentialClicked(
153 long nativeAccountChooserInfoBar, int credentialId, int credentialTy pe); 137 long nativeAccountChooserInfoBar, int credentialId, int credentialTy pe);
154 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698