Index: chrome/android/java/src/org/chromium/chrome/browser/signin/AccountListAdapter.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountListAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountListAdapter.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed295a36003b0518b4649367594fe7b5820f2a70 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountListAdapter.java |
@@ -0,0 +1,82 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.signin; |
+ |
+import android.content.Context; |
+import android.view.LayoutInflater; |
+import android.view.View; |
+import android.view.ViewGroup; |
+import android.widget.ArrayAdapter; |
+import android.widget.ImageView; |
+import android.widget.TextView; |
+ |
+import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.firstrun.ProfileDataCache; |
+ |
+/** |
+* Adapter for AccountListView. |
newt (away)
2016/04/01 23:43:11
This comment could be more helpful. For example, w
gogerald1
2016/04/12 01:21:12
Done.
|
+*/ |
+public class AccountListAdapter extends ArrayAdapter<String> { |
+ private LayoutInflater mInflater; |
+ private String mAddAccount; |
+ private ProfileDataCache mProfileData; |
+ private int mSelectedAccountPosition = 0; |
+ |
+ public AccountListAdapter(Context context) { |
+ super(context, 0); |
+ mInflater = LayoutInflater.from(context); |
+ mAddAccount = context.getResources().getString(R.string.signin_add_account); |
+ } |
+ |
+ /** |
+ * Sets the profile data cache. |
+ * @param profileData ProfileDataCache that will be used to call to retrieve user account info. |
newt (away)
2016/04/01 23:43:11
remove "to call"
gogerald1
2016/04/12 01:21:12
Done.
|
+ */ |
+ public void setProfileDataCache(ProfileDataCache profileData) { |
newt (away)
2016/04/01 23:43:11
Let's pass the ProfileDataCache in the constructor
gogerald1
2016/04/12 01:21:12
Done.
|
+ mProfileData = profileData; |
+ } |
+ |
+ @Override |
+ public View getView(int position, View convertView, ViewGroup parent) { |
+ View view = convertView; |
+ if (view == null) { |
+ view = mInflater.inflate(R.layout.account_signin_account_view, null, false); |
newt (away)
2016/04/01 23:43:11
Pass in "parent" instead of "null". That ensures t
gogerald1
2016/04/12 01:21:12
Done.
|
+ } |
+ |
+ // Sets account profile image, name and selection status. |
+ String accountName = getItem(position); |
+ ImageView accountImage = (ImageView) view.findViewById(R.id.account_image); |
+ if (accountName.equalsIgnoreCase(mAddAccount)) { |
newt (away)
2016/04/01 23:43:11
We know that the "Add account" item is always last
gogerald1
2016/04/12 01:21:12
Done.
|
+ accountImage.setImageResource(R.drawable.add_circle_blue); |
+ } else { |
+ if (mProfileData != null) { |
+ accountImage.setImageBitmap(mProfileData.getImage(accountName)); |
+ } |
+ } |
+ ((TextView) view.findViewById(R.id.account_name)).setText(accountName); |
+ if (position == mSelectedAccountPosition) { |
+ view.findViewById(R.id.account_selection_mark).setVisibility(View.VISIBLE); |
+ } else { |
+ view.findViewById(R.id.account_selection_mark).setVisibility(View.GONE); |
+ } |
+ |
+ return view; |
+ } |
+ |
+ /** |
+ * Sets selected account position. |
+ * @param position Position in the collection of the associated items. |
+ */ |
+ public void setSelectedAccountPosition(int position) { |
+ mSelectedAccountPosition = position; |
+ } |
+ |
+ /** |
+ * Gets selected account position. |
+ */ |
+ public int getSelectedAccountPosition() { |
+ return mSelectedAccountPosition; |
+ } |
+} |