Bug 1315717 - Add ripple feedback to AS context menu buttons on Android >= 5 r=sebastian

The circular ripple is only available on API >= 21. We can fallback to a different solution
for older devices, see following patch.

MozReview-Commit-ID: C0aBqsKsuZ5

--HG--
extra : rebase_source : ae5139daca4a61c1dfe78bdca7d686494d36d482
extra : source : 34e9726d1c21fa1d998f8469175e8b91d849b7e7
This commit is contained in:
Andrzej Hunt 2016-11-08 10:11:02 -05:00
parent ae73913d2a
commit 0680c3fa2f
4 changed files with 40 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import org.mozilla.gecko.icons.IconCallback;
import org.mozilla.gecko.icons.IconResponse;
import org.mozilla.gecko.icons.Icons;
import org.mozilla.gecko.util.DrawableUtil;
import org.mozilla.gecko.util.ViewUtil;
import org.mozilla.gecko.util.TouchTargetUtil;
import org.mozilla.gecko.widget.FaviconView;
@ -124,6 +125,8 @@ public abstract class StreamItem extends RecyclerView.ViewHolder {
vIconView.getWidth(), vIconView.getHeight());
}
});
ViewUtil.enableTouchRipple(menuButton);
}
public void bind(Cursor cursor, int tilesWidth, int tilesHeight) {

View File

@ -19,6 +19,7 @@ import org.mozilla.gecko.icons.IconCallback;
import org.mozilla.gecko.icons.IconResponse;
import org.mozilla.gecko.icons.Icons;
import org.mozilla.gecko.util.DrawableUtil;
import org.mozilla.gecko.util.ViewUtil;
import org.mozilla.gecko.util.TouchTargetUtil;
import org.mozilla.gecko.widget.FaviconView;
@ -53,6 +54,8 @@ class TopSitesCard extends RecyclerView.ViewHolder
TouchTargetUtil.ensureTargetHitArea(menuButton, card);
menuButton.setOnClickListener(this);
ViewUtil.enableTouchRipple(menuButton);
}
void bind(final TopSitesPageAdapter.TopSite topSite) {

View File

@ -0,0 +1,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));
}
}

View File

@ -742,6 +742,7 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
'util/DrawableUtil.java',
'util/ResourceDrawableUtils.java',
'util/TouchTargetUtil.java',
'util/ViewUtil.java',
'widget/ActivityChooserModel.java',
'widget/AllCapsTextView.java',
'widget/AnchoredPopup.java',