Commit 92ab554a authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Add ON_FOCUS event to TileViews.

This event will allow the parent component to take an action when
the user focuses the TileView using keyboard.

Bug: 1106109
Change-Id: If34debc647637f0834db2bd34804c8e37a74320b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437708Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarCathy Li <chili@chromium.org>
Commit-Queue: Tomasz Wiszkowski <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#812111}
parent 978ba0a0
...@@ -21,6 +21,7 @@ import org.chromium.chrome.R; ...@@ -21,6 +21,7 @@ import org.chromium.chrome.R;
public class TileView extends FrameLayout { public class TileView extends FrameLayout {
private ImageView mBadgeView; private ImageView mBadgeView;
private TextView mTitleView; private TextView mTitleView;
private Runnable mOnFocusViaSelectionListener;
protected ImageView mIconView; protected ImageView mIconView;
/** /**
...@@ -70,4 +71,22 @@ public class TileView extends FrameLayout { ...@@ -70,4 +71,22 @@ public class TileView extends FrameLayout {
mTitleView.setLines(titleLines); mTitleView.setLines(titleLines);
mTitleView.setText(title); mTitleView.setText(title);
} }
/** Specify the handler that will be invoked when this tile is highlighted by the user. */
void setOnFocusViaSelectionListener(Runnable listener) {
mOnFocusViaSelectionListener = listener;
}
@Override
public void setSelected(boolean isSelected) {
super.setSelected(isSelected);
if (isSelected && mOnFocusViaSelectionListener != null) {
mOnFocusViaSelectionListener.run();
}
}
@Override
public boolean isFocused() {
return super.isFocused() || (isSelected() && !isInTouchMode());
}
} }
...@@ -43,6 +43,9 @@ public class TileViewBinder { ...@@ -43,6 +43,9 @@ public class TileViewBinder {
params.height = iconEdgeSize; params.height = iconEdgeSize;
params.topMargin = iconTopMarginSize; params.topMargin = iconTopMarginSize;
iconView.setLayoutParams(params); iconView.setLayoutParams(params);
} else if (propertyKey == TileViewProperties.ON_FOCUS_VIA_SELECTION) {
view.setOnFocusViaSelectionListener(
model.get(TileViewProperties.ON_FOCUS_VIA_SELECTION));
} else if (propertyKey == TileViewProperties.ON_CLICK) { } else if (propertyKey == TileViewProperties.ON_CLICK) {
view.setOnClickListener(model.get(TileViewProperties.ON_CLICK)); view.setOnClickListener(model.get(TileViewProperties.ON_CLICK));
} else if (propertyKey == TileViewProperties.ON_LONG_CLICK) { } else if (propertyKey == TileViewProperties.ON_LONG_CLICK) {
......
...@@ -12,7 +12,7 @@ import org.chromium.ui.modelutil.PropertyModel.WritableIntPropertyKey; ...@@ -12,7 +12,7 @@ import org.chromium.ui.modelutil.PropertyModel.WritableIntPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableObjectPropertyKey; import org.chromium.ui.modelutil.PropertyModel.WritableObjectPropertyKey;
/** TileView properties. */ /** TileView properties. */
final class TileViewProperties { public final class TileViewProperties {
/** The title of the tile. */ /** The title of the tile. */
public static final WritableObjectPropertyKey<String> TITLE = new WritableObjectPropertyKey<>(); public static final WritableObjectPropertyKey<String> TITLE = new WritableObjectPropertyKey<>();
...@@ -30,6 +30,10 @@ final class TileViewProperties { ...@@ -30,6 +30,10 @@ final class TileViewProperties {
/** Badge visibility. */ /** Badge visibility. */
public static final WritableBooleanPropertyKey BADGE_VISIBLE = new WritableBooleanPropertyKey(); public static final WritableBooleanPropertyKey BADGE_VISIBLE = new WritableBooleanPropertyKey();
/** Handler receiving focus events. */
public static final WritableObjectPropertyKey<Runnable> ON_FOCUS_VIA_SELECTION =
new WritableObjectPropertyKey<>();
/** Handler receiving click events. */ /** Handler receiving click events. */
public static final WritableObjectPropertyKey<View.OnClickListener> ON_CLICK = public static final WritableObjectPropertyKey<View.OnClickListener> ON_CLICK =
new WritableObjectPropertyKey<>(); new WritableObjectPropertyKey<>();
...@@ -42,6 +46,7 @@ final class TileViewProperties { ...@@ -42,6 +46,7 @@ final class TileViewProperties {
public static final WritableObjectPropertyKey<View.OnCreateContextMenuListener> public static final WritableObjectPropertyKey<View.OnCreateContextMenuListener>
ON_CREATE_CONTEXT_MENU = new WritableObjectPropertyKey<>(); ON_CREATE_CONTEXT_MENU = new WritableObjectPropertyKey<>();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {ICON, TITLE, TITLE_LINES, public static final PropertyKey[] ALL_KEYS =
BADGE_VISIBLE, SHOW_LARGE_ICON, ON_CLICK, ON_LONG_CLICK, ON_CREATE_CONTEXT_MENU}; new PropertyKey[] {ICON, TITLE, TITLE_LINES, BADGE_VISIBLE, SHOW_LARGE_ICON,
ON_FOCUS_VIA_SELECTION, ON_CLICK, ON_LONG_CLICK, ON_CREATE_CONTEXT_MENU};
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment