| 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..aabf629a5f872336d0545102402048199b19597f
|
| --- /dev/null
|
| +++ b/ui/android/java/src/org/chromium/ui/ColorGridAdapter.java
|
| @@ -0,0 +1,47 @@
|
| +// 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(GridView.LayoutParams.WRAP_CONTENT, 65));
|
| + }
|
| + ColorSuggestion suggestion = getItem(position);
|
| + LayerDrawable background = (LayerDrawable)layout.getBackground();
|
| + GradientDrawable swatch =
|
| + (GradientDrawable) background.findDrawableByLayerId(R.id.color_button_swatch);
|
| + swatch.setColor(suggestion.mColor);
|
| + String description = suggestion.mLabel;
|
| + if (description.isEmpty())
|
| + description = String.format("#%06X", (0xFFFFFF & suggestion.mColor));
|
| + layout.setContentDescription(description);
|
| + return layout;
|
| + }
|
| +}
|
|
|