| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.chrome.browser.widget.selection; | 5 package org.chromium.chrome.browser.widget.selection; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.util.AttributeSet; | 8 import android.util.AttributeSet; |
| 9 import android.view.View; | 9 import android.view.View; |
| 10 import android.view.View.OnClickListener; | 10 import android.view.View.OnClickListener; |
| 11 import android.view.View.OnLongClickListener; | 11 import android.view.View.OnLongClickListener; |
| 12 import android.view.ViewGroup.MarginLayoutParams; |
| 12 import android.widget.Checkable; | 13 import android.widget.Checkable; |
| 13 import android.widget.FrameLayout; | 14 import android.widget.FrameLayout; |
| 14 | 15 |
| 16 import org.chromium.base.ApiCompatibilityUtils; |
| 15 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
| 16 import org.chromium.chrome.browser.widget.selection.SelectionDelegate.SelectionO
bserver; | 18 import org.chromium.chrome.browser.widget.selection.SelectionDelegate.SelectionO
bserver; |
| 17 | 19 |
| 18 import java.util.List; | 20 import java.util.List; |
| 19 | 21 |
| 20 /** | 22 /** |
| 21 * An item that can be selected. When selected, the item will be highlighted. A
selection is | 23 * An item that can be selected. When selected, the item will be highlighted. A
selection is |
| 22 * initially established via long-press. If a selection is already established,
clicking on the item | 24 * initially established via long-press. If a selection is already established,
clicking on the item |
| 23 * will toggle its selection. | 25 * will toggle its selection. |
| 24 * | 26 * |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 setChecked(mSelectionDelegate.isItemSelected(mItem)); | 145 setChecked(mSelectionDelegate.isItemSelected(mItem)); |
| 144 } | 146 } |
| 145 | 147 |
| 146 /** | 148 /** |
| 147 * Same as {@link OnClickListener#onClick(View)} on this. | 149 * Same as {@link OnClickListener#onClick(View)} on this. |
| 148 * Subclasses should override this instead of setting their own OnClickListe
ner because this | 150 * Subclasses should override this instead of setting their own OnClickListe
ner because this |
| 149 * class handles onClick events in selection mode, and won't forward events
to subclasses in | 151 * class handles onClick events in selection mode, and won't forward events
to subclasses in |
| 150 * that case. | 152 * that case. |
| 151 */ | 153 */ |
| 152 protected abstract void onClick(); | 154 protected abstract void onClick(); |
| 155 |
| 156 /** |
| 157 * Sets the background resource for this view using the item's positioning i
n its group. |
| 158 * @param isFirstInGroup Whether this item is the first in its group. |
| 159 * @param isLastInGroup Whether this item is the last in its group. |
| 160 */ |
| 161 public void setBackgroundResourceForGroupPosition( |
| 162 boolean isFirstInGroup, boolean isLastInGroup) { |
| 163 int backgroundResource; |
| 164 |
| 165 if (!isLastInGroup && !isFirstInGroup) { |
| 166 backgroundResource = R.drawable.list_item_middle; |
| 167 } else if (!isLastInGroup) { |
| 168 backgroundResource = R.drawable.list_item_top; |
| 169 } else if (!isFirstInGroup) { |
| 170 backgroundResource = R.drawable.list_item_bottom; |
| 171 } else { |
| 172 backgroundResource = R.drawable.list_item_single; |
| 173 } |
| 174 |
| 175 setBackgroundResource(backgroundResource); |
| 176 } |
| 177 |
| 178 /** |
| 179 * Sets lateral margins to effectively hide the lateral shadow and rounded c
orners on the |
| 180 * list_item* 9-patches used as backgrounds. |
| 181 * @param contentView The container view surrounding the list item content.
Extra start and end |
| 182 * padding will be added to this view to account for inco
rrect internal |
| 183 * padding in the 9-patches. |
| 184 */ |
| 185 public void setLateralMarginsForDefaultDisplay(View contentView) { |
| 186 MarginLayoutParams layoutParams = (MarginLayoutParams) getLayoutParams()
; |
| 187 layoutParams.setMargins( |
| 188 SelectableListLayout.getDefaultListItemLateralMarginPx(getResour
ces()), |
| 189 layoutParams.topMargin, |
| 190 SelectableListLayout.getDefaultListItemLateralMarginPx(getResour
ces()), |
| 191 layoutParams.bottomMargin); |
| 192 |
| 193 // TODO(twellington): remove this when new assets with the correct built
in padding are |
| 194 // available. This can move to XML once the bookmark
and download layouts |
| 195 // are width constrained to 600dp. |
| 196 int lateralPaddingOffset = |
| 197 getResources().getDimensionPixelSize(R.dimen.list_item_lateral_p
adding); |
| 198 int startPadding = ApiCompatibilityUtils.getPaddingStart(contentView); |
| 199 int endPadding = ApiCompatibilityUtils.getPaddingEnd(contentView); |
| 200 ApiCompatibilityUtils.setPaddingRelative(contentView, startPadding + lat
eralPaddingOffset, |
| 201 contentView.getPaddingTop(), endPadding + lateralPaddingOffset, |
| 202 contentView.getPaddingBottom()); |
| 203 } |
| 153 } | 204 } |
| OLD | NEW |