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

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

Issue 861103002: Credentials chooser UI for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review, please Created 5 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.infobar;
6
7 import android.view.LayoutInflater;
8 import android.view.MenuItem;
9 import android.view.View;
10 import android.view.View.OnClickListener;
11 import android.view.ViewGroup;
12 import android.widget.Button;
13 import android.widget.ImageView;
14 import android.widget.LinearLayout;
15 import android.widget.PopupMenu;
16 import android.widget.PopupMenu.OnMenuItemClickListener;
17 import android.widget.TextView;
18
19 import org.chromium.base.CalledByNative;
20 import org.chromium.chrome.R;
21 import org.chromium.chrome.browser.ResourceId;
22 import org.chromium.chrome.browser.preferences.PreferencesLauncher;
23
24 /**
25 * An infobar which allows user to choose credentials.
26 * Provides JNI methods for the infobar which allows user to choose account in
27 * Google Smart Lock.
28 */
29 public class AccountChooserInfoBar extends InfoBar implements OnMenuItemClickLis tener {
30 private enum CredentialType {
31 EMPTY(0),
32 LOCAL(1),
33 FEDERATED(2);
34
35 private final int mType;
36 private CredentialType(int type) {
37 mType = type;
38 };
39
40 public int getValue() {
41 return mType;
42 }
43 }
44
45 private final String[] mUsernames;
46
47 /**
48 * Creates and shows the infobar wich allows user to choose credentials for login.
49 * @param nativeInfoBar Pointer to the native infobar.
50 * @param enumeratedIconId Enum ID corresponding to the icon that the infoba r will show.
51 * @param usernames Usernames to display in the infobar.
52 */
53 @CalledByNative
54 private static InfoBar show(long nativeInfoBar, int enumeratedIconId, String [] usernames) {
55 return new AccountChooserInfoBar(
56 nativeInfoBar, ResourceId.mapToDrawableId(enumeratedIconId), use rnames);
57 }
58
59 /**
60 * Creates and shows the infobar which allows user to choose credentials.
61 * @param nativeInfoBar Pointer to the native infobar.
62 * @param iconDrawableId Drawable ID corresponding to the icon that the info bar will show.
63 * @param usernames list of usernames to display in infobar.
64 */
65 public AccountChooserInfoBar(long nativeInfoBar, int iconDrawableId, String[ ] usernames) {
66 super(null /* Infobar Listener */, iconDrawableId, null /* bitmap*/,
67 null /* message to show */);
68 setNativeInfoBar(nativeInfoBar);
69 mUsernames = usernames;
70 }
71
72 /** Called when the user selects a contextual menu item */
73 @Override
74 public boolean onMenuItemClick(MenuItem item) {
75 if (item.getItemId() == R.id.settings) {
76 PreferencesLauncher.launchSettingsPage(getContext(), null);
77 return true;
78 }
79 // TODO(melandory): Learn more should open link to help center
80 // article which is not ready yet.
81 return false;
82 }
83
84 /**
85 * Called when the close button is clicked. Notifies the native infobar, whi ch closes the
86 * infobar.
87 */
88 @Override
89 public void onCloseButtonClicked() {
90 nativeOnCloseButtonClicked(mNativeInfoBarPtr);
91 }
92
93 /**
94 * Used to specify button layout and custom content. Makes infobar display l ist of
95 * credentials
96 * @param layout Handles user interface for the infobar.
97 */
98 @Override
99 public void createContent(InfoBarLayout layout) {
100 layout.setMessage(getContext().getString(R.string.account_chooser_infoba r_title));
101 layout.setCustomContent(createAccountsView(), createCustomButtonsView()) ;
102 }
103
104 private ViewGroup createAccountsView() {
105 ViewGroup accountsView =
106 (ViewGroup) LayoutInflater.from(getContext())
107 .inflate(R.layout.account_chooser_infobar_items, null, f alse);
108 // TODO(melandory): use ListView to represent credentials and make them scrollable.
newt (away) 2015/02/17 21:49:08 Please go ahead and turn this into a ListView as p
melandory 2015/02/18 21:15:34 Implemented this using ListView. But why do you t
newt (away) 2015/02/18 22:26:02 This has to be scrollable because some people have
109 LinearLayout credentialsTable =
110 (LinearLayout) accountsView.findViewById(R.id.account_chooser_la yout);
111 int credentialIndex = 0;
112 for (String username : mUsernames) {
113 LinearLayout row = makeAccountRow(username, credentialIndex);
114 credentialsTable.addView(row);
115 ++credentialIndex;
116 }
117 // TODO(melandory): Restrict height to 2.5 elements in case length of us ernames is more
118 // than 2 elements.
119 return accountsView;
120 }
121
122 /**
123 * Represents row in account chooser infobar, usual row has avatar, username and full name.
124 * @param username username to diplay.
125 * @param credentialIndex index of this row which will be back to native cod e in case user
126 * clicks on that row.
127 */
128 private LinearLayout makeAccountRow(String username, int credentialIndex) {
129 LinearLayout row = (LinearLayout) LayoutInflater.from(getContext())
130 .inflate(R.layout.account_chooser_infobar_ite m, null, false);
131 ViewGroup.LayoutParams row_params = row.getLayoutParams();
132 TextView usernameView = (TextView) row.findViewById(R.id.username);
133 usernameView.setText(username);
134 TextView displayName = (TextView) row.findViewById(R.id.display_name);
135 // TODO(melandory): View should show the full name. Temporarily the view shows
136 // username.
137 displayName.setText(username);
138 // TODO(melandory): View should show proper avatar. Temporarily the view shows
139 // blue man icon.
140 ImageView avatar = (ImageView) row.findViewById(R.id.profile_image);
141 avatar.setImageResource(R.drawable.account_management_no_picture);
142 final Integer currentCredentialIndex = credentialIndex;
newt (away) 2015/02/17 21:49:08 Use int instead of Integer throughout this file. Y
melandory 2015/02/18 21:15:34 Done.
143 row.setOnClickListener(new View.OnClickListener() {
144 @Override
145 public void onClick(View view) {
146 passCredentialsToNative(currentCredentialIndex);
147 }
148 });
149 return row;
150 }
151
152 /**
153 * For the Account Chooser infobar different, than InfobarLayout has, appear ance of button
154 * is required.
155 */
156 private ViewGroup createCustomButtonsView() {
157 ViewGroup buttonsRow =
158 (ViewGroup) LayoutInflater.from(getContext())
159 .inflate(R.layout.account_chooser_infobar_buttonbar, nul l, false);
160 Button moreButton = (Button) buttonsRow.findViewById(R.id.account_choose r_more);
161 // TODO(melandory): Looks like spinner in mocks.
162 moreButton.setOnClickListener(new OnClickListener() {
163 @Override
164 public void onClick(View view) {
165 showMorePopup(view);
166 }
167 });
168
169 Button noThanks = (Button) buttonsRow.findViewById(R.id.account_chooser_ no_thanks);
170 noThanks.setOnClickListener(new OnClickListener() {
171 @Override
172 public void onClick(View view) {
173 onCloseButtonClicked();
174 }
175 });
176 return buttonsRow;
177 }
178
179 private void passCredentialsToNative(Integer credentialIndex) {
180 // TODO(melandory): Adding federated login support should change this
181 // code.
182 nativeOnCredentialClicked(
183 mNativeInfoBarPtr, credentialIndex, CredentialType.LOCAL.getValu e());
184 }
185
186 /** Pops up menu with two items: Setting and Learn More when user clicks mor e button*/
187 private void showMorePopup(View v) {
188 PopupMenu popup = new PopupMenu(getContext(), v);
189 popup.setOnMenuItemClickListener(this);
190 popup.inflate(R.menu.account_chooser_infobar_more_menu_popup);
191 popup.show();
192 }
193
194 private native void nativeOnCredentialClicked(
195 long nativeAccountChooserInfoBar, int credentialId, int credentialTy pe);
196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698