Chromium Code Reviews| 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..312552ffb198d2c70bafceb0724d492030d16a5a |
| --- /dev/null |
| +++ b/ui/android/java/src/org/chromium/ui/ColorGridAdapter.java |
| @@ -0,0 +1,46 @@ |
| +// 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.graphics.drawable.GradientDrawable; |
| +import android.graphics.drawable.LayerDrawable; |
| +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); |
| + layout.setLayoutParams(new GridView.LayoutParams(60, 60)); |
|
newt (away)
2013/08/29 05:35:33
you're actually respecifying the width and height
|
| + } |
| + ColorSuggestion suggestion = getItem(position); |
| + LayerDrawable background = (LayerDrawable)layout.getBackground(); |
|
newt (away)
2013/08/29 05:35:33
space before "layout"
|
| + GradientDrawable swatch = |
| + (GradientDrawable) background.findDrawableByLayerId(R.id.color_button_swatch); |
|
newt (away)
2013/08/29 05:35:33
where is color_button_swatch defined?
|
| + swatch.setColor(suggestion.mColor); |
| + String description = suggestion.mLabel; |
| + if (description.isEmpty()) |
|
newt (away)
2013/08/29 05:35:33
need curly braces in Java. also, could description
|
| + description = String.format("#%06X", (0xFFFFFF & suggestion.mColor)); |
| + layout.setContentDescription(description); |
| + return layout; |
| + } |
| +} |