@@ -0,0 +1,2862 @@
+/*%0A * Copyright 2019 The Android Open Source Project%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     https://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.google.android.material.ripple;%0A%0Aimport android.graphics.Canvas;%0Aimport androidx.annotation.RestrictTo;%0Aimport androidx.annotation.RestrictTo.Scope;%0Aimport com.google.android.material.shape.MaterialShapeDrawable;%0Aimport com.google.android.material.shape.ShapeAppearanceModel;%0A%0A/**%0A * A compat %7B@link android.graphics.drawable.Drawable%7D to be used pre-Lollipop for drawing an%0A * overlay on top of a background for pressed, focused, and hovered states.%0A *%0A * %3Cp%3EThis Drawable is a %7B@link MaterialShapeDrawable%7D so that it can be shaped to match a%0A * MaterialShapeDrawable background.%0A *%0A * %3Cp%3EUnlike the framework %7B@link android.graphics.drawable.RippleDrawable%7D, this will %3Cb%3Enot%3C/b%3E%0A * apply different alphas for pressed, focused, and hovered states and it does not provide a ripple%0A * animation for the pressed state.%0A */%0A@RestrictTo(Scope.LIBRARY_GROUP)%0Apublic class RippleDrawableCompat extends MaterialShapeDrawable %7B%0A%0A  /**%0A   * Whether this compat ripple should be drawn. True when enabled and (pressed, focused, or%0A   * enabled).%0A   */%0A  private boolean shouldDrawRipple = false;%0A%0A  /**%0A   * Creates a %7B@link RippleDrawableCompat%7D with the given shape.%0A   *%0A   * @param shapeAppearanceModel the %7B@link ShapeAppearanceModel%7D containing the path that will be%0A   *     rendered in this drawable.%0A   */%0A  public RippleDrawableCompat(ShapeAppearanceModel shapeAppearanceModel) %7B%0A    super(shapeAppearanceModel);%0A  %7D%0A%0A  @Override%0A  public void draw(Canvas canvas) %7B%0A    if (shouldDrawRipple) %7B%0A      super.draw(canvas);%0A    %7D%0A  %7D%0A%0A  @Override%0A  protected boolean onStateChange(int%5B%5D stateSet) %7B%0A    final boolean changed = super.onStateChange(stateSet);%0A    boolean enabled = false;%0A    boolean pressed = false;%0A    boolean focused = false;%0A    boolean hovered = false;%0A%0A    for (int state : stateSet) %7B%0A      if (state == android.R.attr.state_enabled) %7B%0A        enabled = true;%0A      %7D else if (state == android.R.attr.state_focused) %7B%0A        focused = true;%0A      %7D else if (state == android.R.attr.state_pressed) %7B%0A        pressed = true;%0A      %7D else if (state == android.R.attr.state_hovered) %7B%0A        hovered = true;%0A      %7D%0A    %7D%0A    shouldDrawRipple = enabled && (pressed %7C%7C focused %7C%7C hovered);%0A    return changed;%0A  %7D%0A%7D%0A

Create compat ripples that are based on MaterialShapeDrawable and only draw when enabled and in the pressed, focused, or hovered states.