OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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.ui; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.graphics.drawable.GradientDrawable; |
| 9 import android.graphics.drawable.LayerDrawable; |
| 10 import android.view.LayoutInflater; |
| 11 import android.view.View; |
| 12 import android.view.ViewGroup; |
| 13 import android.widget.ArrayAdapter; |
| 14 import android.widget.GridView; |
| 15 |
| 16 import java.util.ArrayList; |
| 17 |
| 18 public class ColorGridAdapter extends ArrayAdapter<ColorSuggestion> { |
| 19 private Context mContext; |
| 20 |
| 21 ColorGridAdapter(Context context, ArrayList<ColorSuggestion> suggestions) { |
| 22 super(context, R.layout.color_button, suggestions); |
| 23 mContext = context; |
| 24 } |
| 25 |
| 26 @Override |
| 27 public View getView(int position, View convertView, ViewGroup parent) { |
| 28 View layout = convertView; |
| 29 if (convertView == null) { |
| 30 LayoutInflater inflater = |
| 31 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_IN
FLATER_SERVICE); |
| 32 layout = inflater.inflate(R.layout.color_button, null); |
| 33 layout.setLayoutParams( |
| 34 new GridView.LayoutParams(GridView.LayoutParams.WRAP_CONTENT
, 65)); |
| 35 } |
| 36 ColorSuggestion suggestion = getItem(position); |
| 37 LayerDrawable background = (LayerDrawable)layout.getBackground(); |
| 38 GradientDrawable swatch = |
| 39 (GradientDrawable) background.findDrawableByLayerId(R.id.color_b
utton_swatch); |
| 40 swatch.setColor(suggestion.mColor); |
| 41 String description = suggestion.mLabel; |
| 42 if (description.isEmpty()) |
| 43 description = String.format("#%06X", (0xFFFFFF & suggestion.mColor))
; |
| 44 layout.setContentDescription(description); |
| 45 return layout; |
| 46 } |
| 47 } |
OLD | NEW |