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(new GridView.LayoutParams(60, 60)); | |
newt (away)
2013/08/29 05:35:33
you're actually respecifying the width and height
| |
34 } | |
35 ColorSuggestion suggestion = getItem(position); | |
36 LayerDrawable background = (LayerDrawable)layout.getBackground(); | |
newt (away)
2013/08/29 05:35:33
space before "layout"
| |
37 GradientDrawable swatch = | |
38 (GradientDrawable) background.findDrawableByLayerId(R.id.color_b utton_swatch); | |
newt (away)
2013/08/29 05:35:33
where is color_button_swatch defined?
| |
39 swatch.setColor(suggestion.mColor); | |
40 String description = suggestion.mLabel; | |
41 if (description.isEmpty()) | |
newt (away)
2013/08/29 05:35:33
need curly braces in Java. also, could description
| |
42 description = String.format("#%06X", (0xFFFFFF & suggestion.mColor)) ; | |
43 layout.setContentDescription(description); | |
44 return layout; | |
45 } | |
46 } | |
OLD | NEW |