public void showDialog(
     @EventType int modelEventType, List<ConfigurationItem> selectedConfigurationItems) {
   if (isDialogVisible()
       && isFastModeEnabled()
       && modelEventType == EVENT_TYPE_VIEW_LONG_CLICKED) {
     return;
   } else if (!isDialogVisible()
       && (modelEventType == EVENT_TYPE_VIEW_CLICKED
           || modelEventType == EVENT_TYPE_VIEW_FOCUSED)) {
     return;
   }
   helper.clearConfigurationVariables();
   setSortedConfigurationItems(selectedConfigurationItems);
   if (!isDialogVisible()) {
     setExpandIconVisible(true);
     setDialogVisible(true);
     notifyPropertyChanged(PROPERTY_DIALOG_INITIAL_POSITION);
   }
   notifyPropertyChanged(PROPERTY_DATA_SET);
   notifyPropertyChanged(PROPERTY_DATA_SET_SCROLL_POSITION);
   if (isFastModeEnabled() || modelEventType == EVENT_TYPE_VIEW_LONG_CLICKED) {
     setSelectedConfigItem(sortedConfigurationItems.get(0));
     actionCallbacks.setText(getSelectedConfigItemValue());
     notifyPropertyChanged(PROPERTY_DATA_SET);
   }
 }
 public void setFastModeEnabled(boolean enabled) {
   boolean saveFastModeToSharedPrefs = fastModeEnabled != enabled;
   this.fastModeEnabled = enabled;
   if (saveFastModeToSharedPrefs) {
     actionCallbacks.saveFastModeState(isFastModeEnabled());
   }
   notifyPropertyChanged(PROPERTY_FAST_MODE_BUTTON_ICON);
 }
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
      mViewWidth = mListView.getWidth();
    }

    switch (motionEvent.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (mPaused) {
            return false;
          }

          // TODO: ensure this is a finger, and set a flag

          // Find the child view that was touched (perform a hit test)
          Rect rect = new Rect();
          int childCount = mListView.getChildCount();
          int[] listViewCoords = new int[2];
          mListView.getLocationOnScreen(listViewCoords);
          int x = (int) motionEvent.getRawX() - listViewCoords[0];
          int y = (int) motionEvent.getRawY() - listViewCoords[1];
          View child;
          for (int i = 0; i < childCount; i++) {
            child = mListView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
              try {
                mDownViewGroup = (SwipeViewGroup) child;
                mDownView = mFixedBackgrounds ? mDownViewGroup.getContentView() : child;
                if (!mFixedBackgrounds) mDownViewGroup.translateBackgrounds();
              } catch (Exception e) {
                mDownView = child;
              }
              break;
            }
          }

          if (mDownView != null) {
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mListView.getPositionForView(mDownView);
            if (mCallbacks.hasActions(mDownPosition)) {
              mVelocityTracker = VelocityTracker.obtain();
              mVelocityTracker.addMovement(motionEvent);
            } else {
              mDownView = null;
            }
          }
          return false;
        }

      case MotionEvent.ACTION_CANCEL:
        {
          if (mVelocityTracker == null) {
            break;
          }

          if (mDownView != null && mSwiping) {
            // cancel
            mDownView
                .animate()
                .translationX(0)
                .alpha(1)
                .setDuration(mAnimationTime)
                .setListener(
                    new AnimatorListenerAdapter() {
                      @Override
                      public void onAnimationEnd(Animator animation) {
                        mDownViewGroup.showBackground(SwipeDirections.DIRECTION_NEUTRAL, false);
                      }
                    });
          }
          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          mSwiping = false;
          mDirection = SwipeDirections.DIRECTION_NEUTRAL;
          mFar = false;
          break;
        }

      case MotionEvent.ACTION_UP:
        {
          if (mVelocityTracker == null) {
            break;
          }

          float deltaX = motionEvent.getRawX() - mDownX;
          mVelocityTracker.addMovement(motionEvent);
          mVelocityTracker.computeCurrentVelocity(1000);
          float velocityX = mVelocityTracker.getXVelocity();
          float absVelocityX = Math.abs(velocityX);
          float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
          boolean dismiss = false;
          boolean dismissRight = false;
          if (Math.abs(deltaX) > (mViewWidth * mNormalSwipeFraction) && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
          } else if (mMinFlingVelocity <= absVelocityX
              && absVelocityX <= mMaxFlingVelocity
              && absVelocityY < absVelocityX
              && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
          }
          if (dismiss && mDownPosition != ListView.INVALID_POSITION) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            final int direction = mDirection;
            ++mDismissAnimationRefCount;
            mDownView
                .animate()
                .translationX(dismissRight ? mViewWidth : -mViewWidth)
                .alpha(mFadeOut ? 0 : 1)
                .setDuration(mAnimationTime)
                .setListener(
                    new AnimatorListenerAdapter() {
                      @Override
                      public void onAnimationEnd(Animator animation) {
                        boolean performDismiss =
                            mCallbacks.onPreAction(mListView, downPosition, direction);
                        if (performDismiss) performDismiss(downView, downPosition, direction);
                        else slideBack(downView, downPosition, direction);
                      }
                    });
          } else {
            // cancel
            mDownView
                .animate()
                .translationX(0)
                .alpha(1)
                .setDuration(mAnimationTime)
                .setListener(
                    new AnimatorListenerAdapter() {
                      @Override
                      public void onAnimationEnd(Animator animation) {
                        mDownViewGroup.showBackground(SwipeDirections.DIRECTION_NEUTRAL, false);
                      }
                    });
          }
          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          mSwiping = false;
          mDirection = SwipeDirections.DIRECTION_NEUTRAL;
          mFar = false;
          break;
        }

      case MotionEvent.ACTION_MOVE:
        {
          if (mVelocityTracker == null || mPaused) {
            break;
          }

          mVelocityTracker.addMovement(motionEvent);
          float deltaX = motionEvent.getRawX() - mDownX;
          float deltaY = motionEvent.getRawY() - mDownY;
          if (!mSwiping && Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);

            mListView.requestDisallowInterceptTouchEvent(true);

            // Cancel ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(
                MotionEvent.ACTION_CANCEL
                    | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
            mListView.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
          }

          if (mSwiping) {
            if (mDirection * deltaX < 0) mFar = false;
            if (!mFar && Math.abs(deltaX) > mViewWidth * mFarSwipeFraction) mFar = true;
            if (!mFar)
              mDirection =
                  (deltaX > 0
                      ? SwipeDirections.DIRECTION_NORMAL_RIGHT
                      : SwipeDirections.DIRECTION_NORMAL_LEFT);
            else
              mDirection =
                  (deltaX > 0
                      ? SwipeDirections.DIRECTION_FAR_RIGHT
                      : SwipeDirections.DIRECTION_FAR_LEFT);
            mDownViewGroup.showBackground(
                mDirection,
                mDimBackgrounds && (Math.abs(deltaX) < mViewWidth * mNormalSwipeFraction));

            mDownView.setTranslationX(deltaX - mSwipingSlop);
            if (mFadeOut)
              mDownView.setAlpha(
                  Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
          }
          break;
        }
    }
    return false;
  }
 public void onOpenFillTheFormAppButtonClicked() {
   if (isDialogVisible()) {
     onCloseButtonClicked();
     actionCallbacks.openFillTheFormApp();
   }
 }
 public void onConfigurationItemLongClicked(int position) {
   setSelectedConfigItem(position);
   actionCallbacks.pasteText(getSelectedConfigItemValue());
   notifyPropertyChanged(PROPERTY_DATA_SET);
 }