Commit 2d438beb authored by Cathy Li's avatar Cathy Li Committed by Commit Bot

Make ExploreSites IPH pulse cover as large an area as possible

Bug: 977621
Change-Id: I78bfea20233d63b97dd48fd7cb6377476940ea3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1698984
Commit-Queue: Cathy Li <chili@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683346}
parent 4a131203
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
package org.chromium.chrome.browser.explore_sites; package org.chromium.chrome.browser.explore_sites;
import android.content.Context; import android.content.Context;
import android.graphics.Rect;
import android.view.View; import android.view.View;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory; import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.widget.PulseDrawable;
import org.chromium.chrome.browser.widget.ViewHighlighter; import org.chromium.chrome.browser.widget.ViewHighlighter;
import org.chromium.chrome.browser.widget.textbubble.TextBubble; import org.chromium.chrome.browser.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.widget.tile.TileView; import org.chromium.chrome.browser.widget.tile.TileView;
...@@ -63,7 +65,23 @@ public class ExploreSitesIPH { ...@@ -63,7 +65,23 @@ public class ExploreSitesIPH {
accessibilityString, true, rectProvider); accessibilityString, true, rectProvider);
textBubble.setDismissOnTouchInteraction(true); textBubble.setDismissOnTouchInteraction(true);
View foregroundView = tileView.findViewById(org.chromium.chrome.R.id.tile_view_highlight); View foregroundView = tileView.findViewById(org.chromium.chrome.R.id.tile_view_highlight);
ViewHighlighter.turnOnHighlight(foregroundView, true); if (foregroundView == null) return;
PulseDrawable pulseDrawable = PulseDrawable.createCustomCircle(
foregroundView.getContext(), new PulseDrawable.Bounds() {
@Override
public float getMaxRadiusPx(Rect bounds) {
return Math.min(bounds.width(), bounds.height()) / 2.f;
}
@Override
public float getMinRadiusPx(Rect bounds) {
// Radius is half of the min of width and height, divided by 1.5.
// This simplifies to min of width and height divided by 3.
return Math.min(bounds.width(), bounds.height()) / 3.f;
}
});
ViewHighlighter.attachViewAsHighlight(foregroundView, pulseDrawable);
textBubble.addOnDismissListener(() -> { textBubble.addOnDismissListener(() -> {
ViewHighlighter.turnOffHighlight(foregroundView); ViewHighlighter.turnOffHighlight(foregroundView);
......
...@@ -61,6 +61,45 @@ public class PulseDrawable extends Drawable implements Animatable { ...@@ -61,6 +61,45 @@ public class PulseDrawable extends Drawable implements Animatable {
void draw(PulseDrawable drawable, Paint paint, Canvas canvas, float interpolation); void draw(PulseDrawable drawable, Paint paint, Canvas canvas, float interpolation);
} }
/**
* Interface for calculating the max and min bounds in a pulsing circle.
*/
public interface Bounds {
/**
* Calculates the maximum radius of a pulsing circle.
* @param bounds the bounds of the canvas.
* @return floating point maximum radius.
*/
float getMaxRadiusPx(Rect bounds);
/**
* @param bounds the bounds of the canvas.
* @return floating point minimum radius.
*/
float getMinRadiusPx(Rect bounds);
}
private static Painter createCirclePainter(Bounds boundsFn) {
return new PulseDrawable.Painter() {
@Override
public void modifyDrawable(PulseDrawable drawable, float interpolation) {
drawable.invalidateSelf();
}
@Override
public void draw(
PulseDrawable drawable, Paint paint, Canvas canvas, float interpolation) {
Rect bounds = drawable.getBounds();
float minRadiusPx = boundsFn.getMinRadiusPx(bounds);
float maxRadiusPx = boundsFn.getMaxRadiusPx(bounds);
float radius = MathUtils.interpolate(minRadiusPx, maxRadiusPx, interpolation);
canvas.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), radius, paint);
}
};
}
/** /**
* Creates a {@link PulseDrawable} that will fill the bounds with a pulsing color. * Creates a {@link PulseDrawable} that will fill the bounds with a pulsing color.
* @param context The {@link Context} under which the drawable is created. * @param context The {@link Context} under which the drawable is created.
...@@ -92,25 +131,28 @@ public class PulseDrawable extends Drawable implements Animatable { ...@@ -92,25 +131,28 @@ public class PulseDrawable extends Drawable implements Animatable {
final int startingPulseRadiusPx = final int startingPulseRadiusPx =
context.getResources().getDimensionPixelSize(R.dimen.iph_pulse_baseline_radius); context.getResources().getDimensionPixelSize(R.dimen.iph_pulse_baseline_radius);
PulseDrawable.Painter painter = new PulseDrawable.Painter() { return createCustomCircle(context, new Bounds() {
@Override @Override
public void modifyDrawable(PulseDrawable drawable, float interpolation) { public float getMaxRadiusPx(Rect bounds) {
drawable.invalidateSelf(); return Math.min(startingPulseRadiusPx * 1.2f,
Math.min(bounds.width(), bounds.height()) / 2.f);
} }
@Override @Override
public void draw( public float getMinRadiusPx(Rect bounds) {
PulseDrawable drawable, Paint paint, Canvas canvas, float interpolation) { return Math.min(
Rect bounds = drawable.getBounds(); startingPulseRadiusPx, Math.min(bounds.width(), bounds.height()) / 2.f);
float maxAvailRadiusPx = Math.min(bounds.width(), bounds.height()) / 2.f;
float minRadiusPx = Math.min(startingPulseRadiusPx, maxAvailRadiusPx);
float maxRadiusPx = Math.min(startingPulseRadiusPx * 1.2f, maxAvailRadiusPx);
float radius = MathUtils.interpolate(minRadiusPx, maxRadiusPx, interpolation);
canvas.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), radius, paint);
} }
}; });
}
/**
* Creates a {@link PulseDrawable} that will draw a pulsing circle as large as possible inside
* the bounds.
* @param context The {@link Context} under which the drawable is created.
* @return A new {@link PulseDrawable} instance.
*/
public static PulseDrawable createCustomCircle(Context context, Bounds boundsfn) {
Painter painter = createCirclePainter(boundsfn);
PulseDrawable drawable = new PulseDrawable( PulseDrawable drawable = new PulseDrawable(
context, PathInterpolatorCompat.create(.8f, 0.f, .6f, 1.f), painter); context, PathInterpolatorCompat.create(.8f, 0.f, .6f, 1.f), painter);
......
...@@ -35,16 +35,28 @@ public class ViewHighlighter { ...@@ -35,16 +35,28 @@ public class ViewHighlighter {
public static void turnOnHighlight(View view, boolean circular) { public static void turnOnHighlight(View view, boolean circular) {
if (view == null) return; if (view == null) return;
PulseDrawable pulseDrawable = circular ? PulseDrawable.createCircle(view.getContext())
: PulseDrawable.createHighlight(view.getContext());
attachViewAsHighlight(view, pulseDrawable);
}
/**
* Attach a custom PulseDrawable as a highlight layer over the view.
*
* Will not highlight if the view is already highlighted.
*
* @param view The view to be highlighted.
* @param pulseDrawable The highlight.
*/
public static void attachViewAsHighlight(View view, PulseDrawable pulseDrawable) {
boolean highlighted = view.getTag(R.id.highlight_state) != null boolean highlighted = view.getTag(R.id.highlight_state) != null
? (boolean) view.getTag(R.id.highlight_state) ? (boolean) view.getTag(R.id.highlight_state)
: false; : false;
if (highlighted) return; if (highlighted) return;
PulseDrawable pulseDrawable = circular ? PulseDrawable.createCircle(view.getContext())
: PulseDrawable.createHighlight(view.getContext());
Resources resources = view.getContext().getResources(); Resources resources = view.getContext().getResources();
Drawable background = (Drawable) view.getBackground(); Drawable background = view.getBackground();
if (background != null) { if (background != null) {
background = background.getConstantState().newDrawable(resources); background = background.getConstantState().newDrawable(resources);
} }
......
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