Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.ui; | 5 package org.chromium.ui; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.graphics.Color; | 8 import android.graphics.Color; |
| 9 import android.graphics.Typeface; | 9 import android.graphics.Typeface; |
| 10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 DropdownItem item = getItem(i); | 45 DropdownItem item = getItem(i); |
| 46 if (item.isEnabled() && !item.isGroupHeader()) { | 46 if (item.isEnabled() && !item.isGroupHeader()) { |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 | 52 |
| 53 @Override | 53 @Override |
| 54 public View getView(int position, View convertView, ViewGroup parent) { | 54 public View getView(int position, View convertView, ViewGroup parent) { |
| 55 DropdownItem item = getItem(position); | |
| 56 | |
| 55 View layout = convertView; | 57 View layout = convertView; |
| 56 if (convertView == null) { | 58 if (convertView == null) { |
| 57 LayoutInflater inflater = | 59 LayoutInflater inflater = |
| 58 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_IN FLATER_SERVICE); | 60 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_IN FLATER_SERVICE); |
| 59 layout = inflater.inflate(R.layout.dropdown_item, null); | 61 if (item.isIconOnLeft()) { |
| 62 layout = inflater.inflate(R.layout.dropdown_item_left_icon, null ); | |
|
Ted C
2016/11/28 18:29:11
You can't actually use different layouts. getView
lshang
2016/11/30 10:35:43
Done.
| |
| 63 } else { | |
| 64 layout = inflater.inflate(R.layout.dropdown_item, null); | |
| 65 } | |
| 60 layout.setBackground(new DropdownDividerDrawable()); | 66 layout.setBackground(new DropdownDividerDrawable()); |
| 61 } | 67 } |
| 62 | 68 |
| 63 DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBa ckground(); | 69 DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBa ckground(); |
| 64 int height = mContext.getResources().getDimensionPixelSize(R.dimen.dropd own_item_height); | 70 int height = mContext.getResources().getDimensionPixelSize(R.dimen.dropd own_item_height); |
| 65 if (position == 0) { | 71 if (position == 0) { |
| 66 divider.setColor(Color.TRANSPARENT); | 72 divider.setColor(Color.TRANSPARENT); |
| 67 } else { | 73 } else { |
| 68 int dividerHeight = mContext.getResources().getDimensionPixelSize( | 74 int dividerHeight = mContext.getResources().getDimensionPixelSize( |
| 69 R.dimen.dropdown_item_divider_height); | 75 R.dimen.dropdown_item_divider_height); |
| 70 height += dividerHeight; | 76 height += dividerHeight; |
| 71 divider.setHeight(dividerHeight); | 77 divider.setHeight(dividerHeight); |
| 72 if (mSeparators != null && mSeparators.contains(position)) { | 78 if (mSeparators != null && mSeparators.contains(position)) { |
| 73 divider.setColor(ApiCompatibilityUtils.getColor(mContext.getReso urces(), | 79 divider.setColor(ApiCompatibilityUtils.getColor(mContext.getReso urces(), |
| 74 R.color.dropdown_dark_divider_color)); | 80 R.color.dropdown_dark_divider_color)); |
| 75 } else { | 81 } else { |
| 76 divider.setColor(ApiCompatibilityUtils.getColor(mContext.getReso urces(), | 82 divider.setColor(ApiCompatibilityUtils.getColor(mContext.getReso urces(), |
| 77 R.color.dropdown_divider_color)); | 83 R.color.dropdown_divider_color)); |
| 78 } | 84 } |
| 79 } | 85 } |
| 80 | 86 |
| 81 DropdownItem item = getItem(position); | |
| 82 | |
| 83 // Note: trying to set the height of the root LinearLayout breaks access ibility, | 87 // Note: trying to set the height of the root LinearLayout breaks access ibility, |
| 84 // so we have to adjust the height of this LinearLayout that wraps the T extViews instead. | 88 // so we have to adjust the height of this LinearLayout that wraps the T extViews instead. |
| 85 // If you need to modify this layout, don't forget to test it with TalkB ack and make sure | 89 // If you need to modify this layout, don't forget to test it with TalkB ack and make sure |
| 86 // it doesn't regress. | 90 // it doesn't regress. |
| 87 // http://crbug.com/429364 | 91 // http://crbug.com/429364 |
| 88 View wrapper = layout.findViewById(R.id.dropdown_label_wrapper); | 92 LinearLayout wrapper = (LinearLayout) layout.findViewById(R.id.dropdown_ label_wrapper); |
| 89 if (item.isMultilineLabel()) height = LayoutParams.WRAP_CONTENT; | 93 if (item.isMultilineLabel()) height = LayoutParams.WRAP_CONTENT; |
| 94 wrapper.setOrientation(item.getLabelSublabelOrientation()); | |
| 90 wrapper.setLayoutParams(new LinearLayout.LayoutParams(0, height, 1)); | 95 wrapper.setLayoutParams(new LinearLayout.LayoutParams(0, height, 1)); |
| 91 | 96 |
| 92 TextView labelView = (TextView) layout.findViewById(R.id.dropdown_label) ; | 97 TextView labelView = (TextView) layout.findViewById(R.id.dropdown_label) ; |
| 93 labelView.setText(item.getLabel()); | 98 labelView.setText(item.getLabel()); |
| 94 labelView.setSingleLine(!item.isMultilineLabel()); | 99 labelView.setSingleLine(!item.isMultilineLabel()); |
|
Ted C
2016/11/28 18:29:12
Do the labels align correctly per the mocks with t
lshang
2016/11/30 10:35:43
You're amazing! Yeah I tried fixing it by gravity
| |
| 95 | 100 |
| 96 labelView.setEnabled(item.isEnabled()); | 101 labelView.setEnabled(item.isEnabled()); |
| 97 if (item.isGroupHeader()) { | 102 if (item.isGroupHeader()) { |
| 98 labelView.setTypeface(null, Typeface.BOLD); | 103 labelView.setTypeface(null, Typeface.BOLD); |
| 99 } else { | 104 } else { |
| 100 labelView.setTypeface(null, Typeface.NORMAL); | 105 labelView.setTypeface(null, Typeface.NORMAL); |
| 101 } | 106 } |
| 102 | 107 |
| 103 labelView.setTextColor(ApiCompatibilityUtils.getColor( | 108 labelView.setTextColor(ApiCompatibilityUtils.getColor( |
| 104 mContext.getResources(), item.getLabelFontColorResId())); | 109 mContext.getResources(), item.getLabelFontColorResId())); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 130 return mAreAllItemsEnabled; | 135 return mAreAllItemsEnabled; |
| 131 } | 136 } |
| 132 | 137 |
| 133 @Override | 138 @Override |
| 134 public boolean isEnabled(int position) { | 139 public boolean isEnabled(int position) { |
| 135 if (position < 0 || position >= getCount()) return false; | 140 if (position < 0 || position >= getCount()) return false; |
| 136 DropdownItem item = getItem(position); | 141 DropdownItem item = getItem(position); |
| 137 return item.isEnabled() && !item.isGroupHeader(); | 142 return item.isEnabled() && !item.isGroupHeader(); |
| 138 } | 143 } |
| 139 } | 144 } |
| OLD | NEW |