summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java
blob: 180e821e7c586bfbb35ebb31ee067f464e4e53c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.util;

import android.content.res.TypedArray;
import android.view.View;

import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.R;

public class ViewUtil {

    /**
     * Enable a circular touch ripple for a given view. This is intended for borderless views,
     * such as (3-dot) menu buttons.
     *
     * Because of platform limitations a square ripple is used on Android 4.
     */
    public static void enableTouchRipple(View view) {
        final TypedArray backgroundDrawableArray;
        if (AppConstants.Versions.feature21Plus) {
            backgroundDrawableArray = view.getContext().obtainStyledAttributes(new int[] { R.attr.selectableItemBackgroundBorderless });
        } else {
            backgroundDrawableArray = view.getContext().obtainStyledAttributes(new int[] { R.attr.selectableItemBackground });
        }

        // This call is deprecated, but the replacement setBackground(Drawable) isn't available
        // until API 16.
        view.setBackgroundDrawable(backgroundDrawableArray.getDrawable(0));
    }
}