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;
public class TileView extends FrameLayout {
private ImageView mBadgeView;
private TextView mTitleView;
private Runnable mOnFocusViaSelectionListener;
protected ImageView mIconView;
/**
......@@ -70,4 +71,22 @@ public class TileView extends FrameLayout {
mTitleView.setLines(titleLines);
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 {
params.height = iconEdgeSize;
params.topMargin = iconTopMarginSize;
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) {
view.setOnClickListener(model.get(TileViewProperties.ON_CLICK));
} else if (propertyKey == TileViewProperties.ON_LONG_CLICK) {
......
......@@ -12,7 +12,7 @@ import org.chromium.ui.modelutil.PropertyModel.WritableIntPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableObjectPropertyKey;
/** TileView properties. */
final class TileViewProperties {
public final class TileViewProperties {
/** The title of the tile. */
public static final WritableObjectPropertyKey<String> TITLE = new WritableObjectPropertyKey<>();
......@@ -30,6 +30,10 @@ final class TileViewProperties {
/** Badge visibility. */
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. */
public static final WritableObjectPropertyKey<View.OnClickListener> ON_CLICK =
new WritableObjectPropertyKey<>();
......@@ -42,6 +46,7 @@ final class TileViewProperties {
public static final WritableObjectPropertyKey<View.OnCreateContextMenuListener>
ON_CREATE_CONTEXT_MENU = new WritableObjectPropertyKey<>();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {ICON, TITLE, TITLE_LINES,
BADGE_VISIBLE, SHOW_LARGE_ICON, ON_CLICK, ON_LONG_CLICK, ON_CREATE_CONTEXT_MENU};
public static final PropertyKey[] ALL_KEYS =
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