OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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.chrome.browser.enhancedbookmarks; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.graphics.drawable.Drawable; |
| 9 import android.graphics.drawable.LayerDrawable; |
| 10 import android.util.AttributeSet; |
| 11 import android.view.View; |
| 12 import android.widget.Checkable; |
| 13 |
| 14 import com.google.android.apps.chrome.R; |
| 15 |
| 16 import org.chromium.base.ApiCompatibilityUtils; |
| 17 |
| 18 /** |
| 19 * Highlight overlay view for items on the main grid. |
| 20 */ |
| 21 public class EnhancedBookmarkItemHighlightView extends View implements Checkable
{ |
| 22 public static final int ANIMATION_DURATION_MS = 150; |
| 23 private static final int[] CHECKED_STATE_SET = {android.R.attr.state_checked
}; |
| 24 private boolean mIsChecked; |
| 25 |
| 26 /** |
| 27 * Constructor for inflating from XML. |
| 28 */ |
| 29 public EnhancedBookmarkItemHighlightView(Context context, AttributeSet attrs
) { |
| 30 super(context, attrs); |
| 31 Drawable clickDrawable = context.obtainStyledAttributes(new int[] { |
| 32 android.R.attr.selectableItemBackground }).getDrawable(0); |
| 33 Drawable longClickDrawable = ApiCompatibilityUtils.getDrawable(context.g
etResources(), |
| 34 R.drawable.eb_item_highlight); |
| 35 LayerDrawable ld = new LayerDrawable(new Drawable[] {clickDrawable, long
ClickDrawable}); |
| 36 setBackground(ld); |
| 37 } |
| 38 |
| 39 @Override |
| 40 public boolean isChecked() { |
| 41 return mIsChecked; |
| 42 } |
| 43 |
| 44 @Override |
| 45 public void toggle() { |
| 46 setChecked(!mIsChecked); |
| 47 } |
| 48 |
| 49 @Override |
| 50 public void setChecked(boolean checked) { |
| 51 if (checked == mIsChecked) return; |
| 52 mIsChecked = checked; |
| 53 refreshDrawableState(); |
| 54 } |
| 55 |
| 56 @Override |
| 57 public int[] onCreateDrawableState(int extraSpace) { |
| 58 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); |
| 59 if (mIsChecked) { |
| 60 mergeDrawableStates(drawableState, CHECKED_STATE_SET); |
| 61 } |
| 62 return drawableState; |
| 63 } |
| 64 } |
OLD | NEW |