Bug 1258450 - Don't use resources in SwipeDismissListViewTouchListener. r=mcomella
This is just a small simplification to allow us to not depend on
org.mozilla.gecko.R.
MozReview-Commit-ID: TjSYwYyAMS
--- a/mobile/android/base/java/org/mozilla/gecko/widget/SwipeDismissListViewTouchListener.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/SwipeDismissListViewTouchListener.java
@@ -11,33 +11,29 @@
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mozilla.gecko.widget;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ValueAnimator;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.RecyclerListener;
import android.widget.ListView;
-import android.animation.Animator;
-import android.animation.AnimatorListenerAdapter;
-import android.animation.ValueAnimator;
-import android.view.ViewPropertyAnimator;
-
-import org.mozilla.gecko.R;
-
/**
* This code is based off of Jake Wharton's NOA port (https://github.com/JakeWharton/SwipeToDismissNOA)
* of Roman Nurik's SwipeToDismiss library. It has been modified for better support with async
* adapters.
*
* A {@link android.view.View.OnTouchListener} that makes the list items in a {@link ListView}
* dismissable. {@link ListView} is given special treatment because by default it handles touches
* for its list items... i.e. it's in charge of drawing the pressed state (the list selector),
@@ -69,16 +65,18 @@ import org.mozilla.gecko.R;
* </pre>
*
* <p>For a generalized {@link android.view.View.OnTouchListener} that makes any view dismissable,
* see {@link SwipeDismissTouchListener}.</p>
*
* @see SwipeDismissTouchListener
*/
public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
+ private static final int TAG_ORIGINAL_HEIGHT = SwipeDismissListViewTouchListener.class.hashCode();
+
// Cached ViewConfiguration and system-wide constant values
private final int mSlop;
private final int mMinFlingVelocity;
private final int mMaxFlingVelocity;
private final long mAnimationTime;
// Fixed properties
private final ListView mListView;
@@ -162,27 +160,27 @@ public class SwipeDismissListViewTouchLi
/**
* Returns a {@link android.widget.AbsListView.RecyclerListener} to be added to the
* {@link ListView} using {@link ListView#setRecyclerListener(RecyclerListener)}.
*/
public AbsListView.RecyclerListener makeRecyclerListener() {
return new AbsListView.RecyclerListener() {
@Override
public void onMovedToScrapHeap(View view) {
- final Object tag = view.getTag(R.id.original_height);
+ final Object tag = view.getTag(TAG_ORIGINAL_HEIGHT);
// To reset the view to the correct height after its animation, the view's height
// is stored in its tag. Reset the view here.
if (tag instanceof Integer) {
view.setAlpha(1f);
view.setTranslationX(0);
final ViewGroup.LayoutParams lp = view.getLayoutParams();
lp.height = (int) tag;
view.setLayoutParams(lp);
- view.setTag(R.id.original_height, null);
+ view.setTag(TAG_ORIGINAL_HEIGHT, null);
}
}
};
}
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (mViewWidth < 2) {
@@ -331,17 +329,17 @@ public class SwipeDismissListViewTouchLi
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// Since the view is still a part of the ListView, we can't reset the animated
// properties yet; otherwise, the view would briefly reappear. Store the original
// height in the view's tag to flag it for the recycler. This is racy since the user
// could scroll the dismissed view off the screen, then back on the screen, before
// it's removed from the adapter, causing the dismissed view to briefly reappear.
- dismissView.setTag(R.id.original_height, originalHeight);
+ dismissView.setTag(TAG_ORIGINAL_HEIGHT, originalHeight);
mCallback.onDismiss(mListView, dismissPosition);
mDismissing = false;
}
});
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
--- a/mobile/android/base/resources/values/ids.xml
+++ b/mobile/android/base/resources/values/ids.xml
@@ -3,17 +3,16 @@
- 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/. -->
<resources>
<item type="id" name="tabQueueNotification"/>
<item type="id" name="tabQueueSettingsNotification" />
<item type="id" name="guestNotification"/>
- <item type="id" name="original_height"/>
<item type="id" name="menu_items"/>
<item type="id" name="menu_margin"/>
<item type="id" name="recycler_view_click_support" />
<item type="id" name="range_list"/>
<item type="id" name="pref_header_general"/>
<item type="id" name="pref_header_privacy"/>
<item type="id" name="pref_header_search"/>
<item type="id" name="updateServicePermissionNotification" />