Merge "remeasure when overlay views change size"
diff --git a/src/com/android/mail/providers/Settings.java b/src/com/android/mail/providers/Settings.java
index 2b581c8..c7f42c6 100644
--- a/src/com/android/mail/providers/Settings.java
+++ b/src/com/android/mail/providers/Settings.java
@@ -36,6 +36,7 @@
     public boolean confirmArchive;
     public boolean confirmSend;
     public Uri defaultInbox;
+    public boolean forceReplyFromDefault;
 
     public Settings(Parcel inParcel) {
         signature = inParcel.readString();
@@ -49,6 +50,7 @@
         confirmSend = inParcel.readInt() != 0;
         final String inbox = inParcel.readString();
         defaultInbox = !TextUtils.isEmpty(inbox) ? Uri.parse(inbox) : null;
+        forceReplyFromDefault = inParcel.readInt() != 0;
     }
 
     public Settings(Cursor cursor) {
@@ -63,6 +65,8 @@
         confirmSend = cursor.getInt(UIProvider.SETTINGS_CONFIRM_SEND_COLUMN) != 0;
         final String inbox = cursor.getString(UIProvider.SETTINGS_DEFAULT_INBOX_COLUMN);
         defaultInbox = !TextUtils.isEmpty(inbox) ? Uri.parse(inbox) : null;
+        forceReplyFromDefault = cursor.getInt(
+                UIProvider.SETTINGS_FORCE_REPLY_FROM_DEFAULT_COLUMN) != 0;
     }
 
     @Override
@@ -82,6 +86,7 @@
         dest.writeInt(confirmArchive? 1 : 0);
         dest.writeInt(confirmSend? 1 : 0);
         dest.writeString(defaultInbox.toString());
+        dest.writeInt(forceReplyFromDefault ? 1 : 0);
     }
 
     @SuppressWarnings("hiding")
diff --git a/src/com/android/mail/providers/UIProvider.java b/src/com/android/mail/providers/UIProvider.java
index 97c27bc..d9131bd 100644
--- a/src/com/android/mail/providers/UIProvider.java
+++ b/src/com/android/mail/providers/UIProvider.java
@@ -1226,7 +1226,8 @@
             SettingsColumns.CONFIRM_DELETE,
             SettingsColumns.CONFIRM_ARCHIVE,
             SettingsColumns.CONFIRM_SEND,
-            SettingsColumns.DEFAULT_INBOX
+            SettingsColumns.DEFAULT_INBOX,
+            SettingsColumns.FORCE_REPLY_FROM_DEFAULT
     };
 
     public static final int SETTINGS_SIGNATURE_COLUMN = 0;
@@ -1239,6 +1240,7 @@
     public static final int SETTINGS_CONFIRM_ARCHIVE_COLUMN = 7;
     public static final int SETTINGS_CONFIRM_SEND_COLUMN = 8;
     public static final int SETTINGS_DEFAULT_INBOX_COLUMN = 9;
+    public static final int SETTINGS_FORCE_REPLY_FROM_DEFAULT_COLUMN = 10;
 
     public static final class AutoAdvance {
         public static final int UNSET = 0;
@@ -1327,6 +1329,11 @@
          * String folder containing the serialized default inbox folder for an account.
          */
         public static final String DEFAULT_INBOX = "default_inbox";
+        /**
+         * Integer column containing a non zero value if replies should always be sent from
+         * a default address instead of a recipient.
+         */
+        public static String FORCE_REPLY_FROM_DEFAULT = "force_reply_from_default";
     }
 
     /**
diff --git a/src/com/android/mail/ui/SwipeHelper.java b/src/com/android/mail/ui/SwipeHelper.java
index 67d8108..9b1331e 100644
--- a/src/com/android/mail/ui/SwipeHelper.java
+++ b/src/com/android/mail/ui/SwipeHelper.java
@@ -101,14 +101,6 @@
         mPagingTouchSlop = pagingTouchSlop;
     }
 
-    private float getPos(MotionEvent ev) {
-        return mSwipeDirection == X ? ev.getX() : ev.getY();
-    }
-
-    private float getTranslation(View v) {
-        return mSwipeDirection == X ? v.getTranslationX() : v.getTranslationY();
-    }
-
     private float getVelocity(VelocityTracker vt) {
         return mSwipeDirection == X ? vt.getXVelocity() :
                 vt.getYVelocity();
@@ -153,7 +145,7 @@
         float viewSize = getSize(view);
         final float fadeSize = ALPHA_FADE_END * viewSize;
         float result = 1.0f;
-        float pos = getTranslation(view);
+        float pos = view.getTranslationX();
         if (pos >= viewSize * ALPHA_FADE_START) {
             result = 1.0f - (pos - viewSize * ALPHA_FADE_START) / fadeSize;
         } else if (pos < viewSize * (1.0f - ALPHA_FADE_START)) {
@@ -206,7 +198,7 @@
                     mCurrAnimView = mCallback.getChildContentView(mCurrView);
                     mCanCurrViewBeDimissed = mCallback.canChildBeDismissed(mCurrView);
                     mVelocityTracker.addMovement(ev);
-                    mInitialTouchPosX = getPos(ev);
+                    mInitialTouchPosX = ev.getX();
                     mInitialTouchPosY = ev.getY();
                 }
                 break;
@@ -222,7 +214,7 @@
                         }
                     }
                     mVelocityTracker.addMovement(ev);
-                    float pos = getPos(ev);
+                    float pos = ev.getX();
                     float delta = pos - mInitialTouchPosX;
                     if (Math.abs(delta) > mPagingTouchSlop) {
                         if (mCallback.getSelectionSet().isEmpty()
@@ -230,8 +222,9 @@
                                         && mCurrView.isChecked())) {
                             mCallback.onBeginDrag(mCurrView);
                             mDragging = true;
-                            mInitialTouchPosX = getPos(ev) - getTranslation(mCurrAnimView);
+                            mInitialTouchPosX = ev.getX() - mCurrAnimView.getTranslationX();
                             mInitialTouchPosY = ev.getY();
+                            mCurrView.cancelTap();
                         }
                     }
                 }
@@ -338,7 +331,7 @@
         if (velocity != 0) {
             duration = Math
                     .min(duration,
-                            (int) (Math.abs(newPos - getTranslation(animView)) * 1000f / Math
+                            (int) (Math.abs(newPos - animView.getTranslationX()) * 1000f / Math
                                     .abs(velocity)));
         } else {
             duration = DEFAULT_ESCAPE_ANIMATION_DURATION;
@@ -348,9 +341,9 @@
 
     private float determinePos(View animView, float velocity) {
         float newPos = 0;
-        if (velocity < 0 || (velocity == 0 && getTranslation(animView) < 0)
+        if (velocity < 0 || (velocity == 0 && animView.getTranslationX() < 0)
         // if we use the Menu to dismiss an item in landscape, animate up
-                || (velocity == 0 && getTranslation(animView) == 0 && mSwipeDirection == Y)) {
+                || (velocity == 0 && animView.getTranslationX() == 0 && mSwipeDirection == Y)) {
             newPos = -getSize(animView);
         } else {
             newPos = getSize(animView);
@@ -391,7 +384,7 @@
             case MotionEvent.ACTION_OUTSIDE:
             case MotionEvent.ACTION_MOVE:
                 if (mCurrView != null) {
-                    float deltaX = getPos(ev) - mInitialTouchPosX;
+                    float deltaX = ev.getX() - mInitialTouchPosX;
                     float deltaY = Math.abs(ev.getY() - mInitialTouchPosY);
                     // If the user has gone vertical and not gone horizontal AT
                     // LEAST minBeforeLock, switch to scroll. Otherwise, cancel
@@ -448,7 +441,7 @@
                     // Decide whether to dismiss the current view
                     // Tweak constants below as required to prevent erroneous
                     // swipe/dismiss
-                    float translation = Math.abs(getTranslation(mCurrAnimView));
+                    float translation = Math.abs(mCurrAnimView.getTranslationX());
                     float currAnimViewSize = getSize(mCurrAnimView);
                     // Long swipe = translation of .4 * width
                     boolean childSwipedFarEnough = DISMISS_IF_SWIPED_FAR_ENOUGH
@@ -457,7 +450,7 @@
                     // width
                     boolean childSwipedFastEnough = (Math.abs(velocity) > escapeVelocity)
                             && (Math.abs(velocity) > Math.abs(perpendicularVelocity))
-                            && (velocity > 0) == (getTranslation(mCurrAnimView) > 0)
+                            && (velocity > 0) == (mCurrAnimView.getTranslationX() > 0)
                             && translation > 0.05 * currAnimViewSize;
                     if (LOG_SWIPE_DISMISS_VELOCITY) {
                         Log.v(TAG, "Swipe/Dismiss: " + velocity + "/" + escapeVelocity + "/"
diff --git a/src/com/android/mail/ui/SwipeableListView.java b/src/com/android/mail/ui/SwipeableListView.java
index 57f36b9..06b1f89 100644
--- a/src/com/android/mail/ui/SwipeableListView.java
+++ b/src/com/android/mail/ui/SwipeableListView.java
@@ -20,9 +20,11 @@
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.content.Context;
+import android.content.res.Configuration;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.ViewConfiguration;
 import android.widget.ListAdapter;
 import android.widget.ListView;
 
@@ -62,14 +64,24 @@
     public SwipeableListView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         float densityScale = getResources().getDisplayMetrics().density;
+        float pagingTouchSlop = ViewConfiguration.get(context).getScaledPagingTouchSlop();
         float scrollSlop = context.getResources().getInteger(R.integer.swipeScrollSlop);
         float minSwipe = context.getResources().getDimension(R.dimen.min_swipe);
         float minVert = context.getResources().getDimension(R.dimen.min_vert);
         float minLock = context.getResources().getDimension(R.dimen.min_lock);
-        mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, densityScale,
+        mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop,
                 scrollSlop, minSwipe, minVert, minLock);
     }
 
+    @Override
+    protected void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        float densityScale = getResources().getDisplayMetrics().density;
+        mSwipeHelper.setDensityScale(densityScale);
+        float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
+        mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
+    }
+
     /**
      * Enable swipe gestures.
      */