Index: ui/android/java/src/org/chromium/ui/ColorGridAdapter.java |
diff --git a/ui/android/java/src/org/chromium/ui/ColorGridAdapter.java b/ui/android/java/src/org/chromium/ui/ColorGridAdapter.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9541a44a2147d085c0c1f3c06ecd37a15cc86b71 |
--- /dev/null |
+++ b/ui/android/java/src/org/chromium/ui/ColorGridAdapter.java |
@@ -0,0 +1,41 @@ |
+// Copyright 2013 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.ui; |
+ |
+import android.content.Context; |
+import android.view.LayoutInflater; |
+import android.view.View; |
+import android.view.ViewGroup; |
+import android.widget.ArrayAdapter; |
+import android.widget.GridView; |
+ |
+import java.util.ArrayList; |
+ |
+public class ColorGridAdapter extends ArrayAdapter<ColorSuggestion> { |
+ private Context mContext; |
+ |
+ ColorGridAdapter(Context context, ArrayList<ColorSuggestion> suggestions) { |
+ super(context, R.layout.color_button, suggestions); |
+ mContext = context; |
+ } |
+ |
+ @Override |
+ public View getView(int position, View convertView, ViewGroup parent) { |
+ View layout = convertView; |
+ if (convertView == null) { |
+ LayoutInflater inflater = |
+ (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
+ layout = inflater.inflate(R.layout.color_button, null); |
+ } |
+ View swatch = layout.findViewById(R.id.color_button_swatch); |
+ ColorSuggestion suggestion = getItem(position); |
+ swatch.setBackgroundColor(suggestion.mValueAsColor); |
+ String description = suggestion.mLabel; |
+ if (description.isEmpty()) |
+ description = suggestion.mValueAsText; |
+ layout.setContentDescription(description); |
+ return layout; |
+ } |
+} |