@Override
 protected void onDraw(Canvas canvas) {
   canvas.drawLine(
       getPaddingLeft(),
       AndroidUtilities.dp(8),
       getWidth() - getPaddingRight(),
       AndroidUtilities.dp(8),
       paint);
 }
 @Override
 public void onConfigurationChanged(Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   try {
     LocaleController.getInstance().onDeviceConfigurationChange(newConfig);
     AndroidUtilities.checkDisplaySize();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public void draw(Canvas canvas) {
   Drawable thumb = null;
   Paint inner = null;
   Paint outer = null;
   if (type == 0) {
     if (!pressed) {
       thumb = thumbDrawable1;
     } else {
       thumb = thumbDrawablePressed1;
     }
     inner = innerPaint1;
     outer = outerPaint1;
   } else if (type == 1) {
     if (!pressed) {
       thumb = thumbDrawable2;
     } else {
       thumb = thumbDrawablePressed2;
     }
     inner = innerPaint2;
     outer = outerPaint2;
   }
   int y = (height - thumbHeight) / 2;
   canvas.drawRect(
       thumbWidth / 2,
       height / 2 - AndroidUtilities.dp(1),
       width - thumbWidth / 2,
       height / 2 + AndroidUtilities.dp(1),
       inner);
   canvas.drawRect(
       thumbWidth / 2,
       height / 2 - AndroidUtilities.dp(1),
       thumbWidth / 2 + thumbX,
       height / 2 + AndroidUtilities.dp(1),
       outer);
   thumb.setBounds(thumbX, y, thumbX + thumbWidth, y + thumbHeight);
   thumb.draw(canvas);
 }
  public static CharSequence generateSearchName(String name, String name2, String q) {
    if (name == null && name2 == null) {
      return "";
    }
    SpannableStringBuilder builder = new SpannableStringBuilder();
    String wholeString = name;
    if (wholeString == null || wholeString.length() == 0) {
      wholeString = name2;
    } else if (name2 != null && name2.length() != 0) {
      wholeString += " " + name2;
    }
    wholeString = wholeString.trim();
    String lower = " " + wholeString.toLowerCase();
    String hexDarkColor =
        String.format("#%06X", (0xFFFFFF & AndroidUtilities.getIntDarkerColor("themeColor", 0x15)));
    int index = -1;
    int lastIndex = 0;
    while ((index = lower.indexOf(" " + q, lastIndex)) != -1) {
      int idx = index - (index == 0 ? 0 : 1);
      int end = q.length() + (index == 0 ? 0 : 1) + idx;

      if (lastIndex != 0 && lastIndex != idx + 1) {
        builder.append(wholeString.substring(lastIndex, idx));
      } else if (lastIndex == 0 && idx != 0) {
        builder.append(wholeString.substring(0, idx));
      }

      String query = wholeString.substring(idx, end);
      if (query.startsWith(" ")) {
        builder.append(" ");
      }
      query.trim();
      builder.append(Html.fromHtml("<font color=" + hexDarkColor + ">" + query + "</font>"));
      // builder.append(Html.fromHtml("<font color=\"#4d83b3\">" + query + "</font>"));

      lastIndex = end;
    }

    if (lastIndex != -1 && lastIndex != wholeString.length()) {
      builder.append(wholeString.substring(lastIndex, wholeString.length()));
    }

    return builder;
  }
  @Override
  protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    int width = getWidth() - getPaddingLeft() - getPaddingRight();
    int translationX = (int) innerTranslationX + getPaddingRight();
    int clipLeft = getPaddingLeft();
    int clipRight = width + getPaddingLeft();

    if (child == containerViewBack) {
      clipRight = translationX;
    } else if (child == containerView) {
      clipLeft = translationX;
    }

    final int restoreCount = canvas.save();
    if (!transitionAnimationInProgress) {
      canvas.clipRect(clipLeft, 0, clipRight, getHeight());
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (translationX != 0) {
      if (child == containerView) {
        final float alpha =
            Math.max(0, Math.min((width - translationX) / (float) AndroidUtilities.dp(20), 1.0f));
        layerShadowDrawable.setBounds(
            translationX - layerShadowDrawable.getIntrinsicWidth(),
            child.getTop(),
            translationX,
            child.getBottom());
        layerShadowDrawable.setAlpha((int) (0xff * alpha));
        layerShadowDrawable.draw(canvas);
      } else if (child == containerViewBack) {
        final float opacity = Math.min(0.8f, (width - translationX) / (float) width);
        scrimPaint.setColor((int) (((0x99000000 & 0xff000000) >>> 24) * opacity) << 24);
        canvas.drawRect(clipLeft, 0, clipRight, getHeight(), scrimPaint);
      }
    }

    return result;
  }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (event == null) {
      return false;
    }
    float x = event.getX();
    float y = event.getY();

    int width = getMeasuredWidth() - AndroidUtilities.dp(32);
    int startX = (int) (width * progressLeft) + AndroidUtilities.dp(16);
    int endX = (int) (width * progressRight) + AndroidUtilities.dp(16);

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      int additionWidth = AndroidUtilities.dp(12);
      if (startX - additionWidth <= x
          && x <= startX + additionWidth
          && y >= 0
          && y <= getMeasuredHeight()) {
        pressedLeft = true;
        pressDx = (int) (x - startX);
        getParent().requestDisallowInterceptTouchEvent(true);
        invalidate();
        return true;
      } else if (endX - additionWidth <= x
          && x <= endX + additionWidth
          && y >= 0
          && y <= getMeasuredHeight()) {
        pressedRight = true;
        pressDx = (int) (x - endX);
        getParent().requestDisallowInterceptTouchEvent(true);
        invalidate();
        return true;
      }
    } else if (event.getAction() == MotionEvent.ACTION_UP
        || event.getAction() == MotionEvent.ACTION_CANCEL) {
      if (pressedLeft) {
        pressedLeft = false;
        return true;
      } else if (pressedRight) {
        pressedRight = false;
        return true;
      }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
      if (pressedLeft) {
        startX = (int) (x - pressDx);
        if (startX < AndroidUtilities.dp(16)) {
          startX = AndroidUtilities.dp(16);
        } else if (startX > endX) {
          startX = endX;
        }
        progressLeft = (float) (startX - AndroidUtilities.dp(16)) / (float) width;
        if (delegate != null) {
          delegate.onLeftProgressChanged(progressLeft);
        }
        invalidate();
        return true;
      } else if (pressedRight) {
        endX = (int) (x - pressDx);
        if (endX < startX) {
          endX = startX;
        } else if (endX > width + AndroidUtilities.dp(16)) {
          endX = width + AndroidUtilities.dp(16);
        }
        progressRight = (float) (endX - AndroidUtilities.dp(16)) / (float) width;
        if (delegate != null) {
          delegate.onRifhtProgressChanged(progressRight);
        }
        invalidate();
        return true;
      }
    }
    return false;
  }
  @Override
  protected void onDraw(Canvas canvas) {
    int width = getMeasuredWidth() - AndroidUtilities.dp(36);
    int startX = (int) (width * progressLeft) + AndroidUtilities.dp(16);
    int endX = (int) (width * progressRight) + AndroidUtilities.dp(16);

    canvas.save();
    canvas.clipRect(
        AndroidUtilities.dp(16), 0, width + AndroidUtilities.dp(20), AndroidUtilities.dp(44));
    if (frames.isEmpty() && currentTask == null) {
      reloadFrames(0);
    } else {
      int offset = 0;
      for (Bitmap bitmap : frames) {
        if (bitmap != null) {
          canvas.drawBitmap(
              bitmap, AndroidUtilities.dp(16) + offset * frameWidth, AndroidUtilities.dp(2), null);
        }
        offset++;
      }
    }

    canvas.drawRect(
        AndroidUtilities.dp(16), AndroidUtilities.dp(2), startX, AndroidUtilities.dp(42), paint2);
    canvas.drawRect(
        endX + AndroidUtilities.dp(4),
        AndroidUtilities.dp(2),
        AndroidUtilities.dp(16) + width + AndroidUtilities.dp(4),
        AndroidUtilities.dp(42),
        paint2);

    canvas.drawRect(startX, 0, startX + AndroidUtilities.dp(2), AndroidUtilities.dp(44), paint);
    canvas.drawRect(
        endX + AndroidUtilities.dp(2),
        0,
        endX + AndroidUtilities.dp(4),
        AndroidUtilities.dp(44),
        paint);
    canvas.drawRect(
        startX + AndroidUtilities.dp(2),
        0,
        endX + AndroidUtilities.dp(4),
        AndroidUtilities.dp(2),
        paint);
    canvas.drawRect(
        startX + AndroidUtilities.dp(2),
        AndroidUtilities.dp(42),
        endX + AndroidUtilities.dp(4),
        AndroidUtilities.dp(44),
        paint);
    canvas.restore();

    int drawableWidth = pickDrawable.getIntrinsicWidth();
    int drawableHeight = pickDrawable.getIntrinsicHeight();
    pickDrawable.setBounds(
        startX - drawableWidth / 2,
        getMeasuredHeight() - drawableHeight,
        startX + drawableWidth / 2,
        getMeasuredHeight());
    pickDrawable.draw(canvas);

    pickDrawable.setBounds(
        endX - drawableWidth / 2 + AndroidUtilities.dp(4),
        getMeasuredHeight() - drawableHeight,
        endX + drawableWidth / 2 + AndroidUtilities.dp(4),
        getMeasuredHeight());
    pickDrawable.draw(canvas);
  }
  private void reloadFrames(int frameNum) {
    if (mediaMetadataRetriever == null) {
      return;
    }
    if (frameNum == 0) {
      frameHeight = AndroidUtilities.dp(40);
      framesToLoad = (getMeasuredWidth() - AndroidUtilities.dp(16)) / frameHeight;
      frameWidth =
          (int)
              Math.ceil(
                  (float) (getMeasuredWidth() - AndroidUtilities.dp(16)) / (float) framesToLoad);
      frameTimeOffset = videoLength / framesToLoad;
    }
    currentTask =
        new AsyncTask<Integer, Integer, Bitmap>() {
          private int frameNum = 0;

          @Override
          protected Bitmap doInBackground(Integer... objects) {
            frameNum = objects[0];
            Bitmap bitmap = null;
            if (isCancelled()) {
              return null;
            }
            try {
              bitmap = mediaMetadataRetriever.getFrameAtTime(frameTimeOffset * frameNum * 1000);
              if (isCancelled()) {
                return null;
              }
              if (bitmap != null) {
                Bitmap result = Bitmap.createBitmap(frameWidth, frameHeight, bitmap.getConfig());
                Canvas canvas = new Canvas(result);
                float scaleX = (float) frameWidth / (float) bitmap.getWidth();
                float scaleY = (float) frameHeight / (float) bitmap.getHeight();
                float scale = scaleX > scaleY ? scaleX : scaleY;
                int w = (int) (bitmap.getWidth() * scale);
                int h = (int) (bitmap.getHeight() * scale);
                Rect srcRect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
                Rect destRect = new Rect((frameWidth - w) / 2, (frameHeight - h) / 2, w, h);
                Paint paint = new Paint();
                canvas.drawBitmap(bitmap, srcRect, destRect, null);
                bitmap.recycle();
                bitmap = result;
              }
            } catch (Exception e) {
              FileLog.e("tmessages", e);
            }
            return bitmap;
          }

          @Override
          protected void onPostExecute(Bitmap bitmap) {
            if (!isCancelled()) {
              frames.add(bitmap);
              invalidate();
              if (frameNum < framesToLoad) {
                reloadFrames(frameNum + 1);
              }
            }
          }
        };

    if (android.os.Build.VERSION.SDK_INT >= 11) {
      currentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, frameNum, null, null);
    } else {
      currentTask.execute(frameNum, null, null);
    }
  }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(16) + 1);
 }
  public void closeLastFragment(boolean animated) {
    if (delegate != null && !delegate.needCloseLastFragment(this)
        || checkTransitionAnimation()
        || fragmentsStack.isEmpty()) {
      return;
    }
    if (parentActivity.getCurrentFocus() != null) {
      AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
    }
    setInnerTranslationX(0);
    boolean needAnimation =
        Build.VERSION.SDK_INT > 10
            && animated
            && parentActivity
                .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE)
                .getBoolean("view_animations", true);
    final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
    BaseFragment previousFragment = null;
    if (fragmentsStack.size() > 1) {
      previousFragment = fragmentsStack.get(fragmentsStack.size() - 2);
    }

    if (previousFragment != null) {
      LinearLayoutContainer temp = containerView;
      containerView = containerViewBack;
      containerViewBack = temp;
      containerView.setVisibility(View.VISIBLE);

      previousFragment.setParentLayout(this);
      View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater());
      if (previousFragment.needAddActionBar() && previousFragment.actionBar != null) {
        if (removeActionBarExtraHeight) {
          previousFragment.actionBar.setOccupyStatusBar(false);
        }
        ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
        if (parent != null) {
          parent.removeView(previousFragment.actionBar);
        }
        containerView.addView(previousFragment.actionBar);
        previousFragment.actionBar.setTitleOverlayText(titleOverlayText);
      }
      containerView.addView(fragmentView);
      ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
      layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
      fragmentView.setLayoutParams(layoutParams);
      previousFragment.onResume();
      currentActionBar = previousFragment.actionBar;
      if (fragmentView.getBackground() == null) {
        fragmentView.setBackgroundColor(0xffffffff);
      }

      if (!needAnimation) {
        closeLastFragmentInternalRemoveOld(currentFragment);
      }

      if (needAnimation) {
        transitionAnimationStartTime = System.currentTimeMillis();
        transitionAnimationInProgress = true;
        onCloseAnimationEndRunnable =
            new Runnable() {
              @Override
              public void run() {
                closeLastFragmentInternalRemoveOld(currentFragment);
                ViewProxy.setTranslationX(containerViewBack, 0);
              }
            };

        currentAnimation = new AnimatorSetProxy();
        currentAnimation.playTogether(
            ObjectAnimatorProxy.ofFloat(containerViewBack, "alpha", 1.0f, 0.0f),
            ObjectAnimatorProxy.ofFloat(
                containerViewBack, "translationX", 0, AndroidUtilities.dp(48)));
        currentAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
        currentAnimation.setDuration(200);
        currentAnimation.addListener(
            new AnimatorListenerAdapterProxy() {
              @Override
              public void onAnimationStart(Object animation) {
                transitionAnimationStartTime = System.currentTimeMillis();
              }

              @Override
              public void onAnimationEnd(Object animation) {
                onAnimationEndCheck(false);
              }

              @Override
              public void onAnimationCancel(Object animation) {
                onAnimationEndCheck(false);
              }
            });
        currentAnimation.start();
      }
    } else {
      if (useAlphaAnimations) {
        transitionAnimationStartTime = System.currentTimeMillis();
        transitionAnimationInProgress = true;

        onCloseAnimationEndRunnable =
            new Runnable() {
              @Override
              public void run() {
                removeFragmentFromStack(currentFragment);
                setVisibility(GONE);
                if (backgroundView != null) {
                  backgroundView.setVisibility(GONE);
                }
                if (drawerLayoutContainer != null) {
                  drawerLayoutContainer.setAllowOpenDrawer(true);
                }
              }
            };

        ArrayList<Object> animators = new ArrayList<>();
        animators.add(ObjectAnimatorProxy.ofFloat(this, "alpha", 1.0f, 0.0f));
        if (backgroundView != null) {
          animators.add(ObjectAnimatorProxy.ofFloat(backgroundView, "alpha", 1.0f, 0.0f));
        }

        currentAnimation = new AnimatorSetProxy();
        currentAnimation.playTogether(animators);
        currentAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        currentAnimation.setDuration(200);
        currentAnimation.addListener(
            new AnimatorListenerAdapterProxy() {
              @Override
              public void onAnimationStart(Object animation) {
                transitionAnimationStartTime = System.currentTimeMillis();
              }

              @Override
              public void onAnimationEnd(Object animation) {
                onAnimationEndCheck(false);
              }

              @Override
              public void onAnimationCancel(Object animation) {
                onAnimationEndCheck(false);
              }
            });
        currentAnimation.start();
      } else {
        removeFragmentFromStack(currentFragment);
        setVisibility(GONE);
        if (backgroundView != null) {
          backgroundView.setVisibility(GONE);
        }
      }
    }
  }
  public boolean presentFragment(
      final BaseFragment fragment,
      final boolean removeLast,
      boolean forceWithoutAnimation,
      boolean check) {
    if (checkTransitionAnimation()
        || delegate != null
            && check
            && !delegate.needPresentFragment(fragment, removeLast, forceWithoutAnimation, this)
        || !fragment.onFragmentCreate()) {
      return false;
    }
    if (parentActivity.getCurrentFocus() != null) {
      AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
      NotificationCenter.getInstance().postNotificationName(NotificationCenter.hideEmojiKeyboard);
    }
    boolean needAnimation =
        Build.VERSION.SDK_INT > 10
            && !forceWithoutAnimation
            && parentActivity
                .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE)
                .getBoolean("view_animations", true);

    final BaseFragment currentFragment =
        !fragmentsStack.isEmpty() ? fragmentsStack.get(fragmentsStack.size() - 1) : null;

    fragment.setParentLayout(this);
    View fragmentView = fragment.createView(parentActivity.getLayoutInflater());
    if (fragment.needAddActionBar() && fragment.actionBar != null) {
      if (removeActionBarExtraHeight) {
        fragment.actionBar.setOccupyStatusBar(false);
      }
      ViewGroup parent = (ViewGroup) fragment.actionBar.getParent();
      if (parent != null) {
        parent.removeView(fragment.actionBar);
      }
      containerViewBack.addView(fragment.actionBar);
      fragment.actionBar.setTitleOverlayText(titleOverlayText);
    }

    containerViewBack.addView(fragmentView);
    ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
    layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
    layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
    fragmentView.setLayoutParams(layoutParams);
    fragmentsStack.add(fragment);
    fragment.onResume();
    currentActionBar = fragment.actionBar;
    if (fragmentView.getBackground() == null) {
      fragmentView.setBackgroundColor(0xffffffff);
    }

    LinearLayoutContainer temp = containerView;
    containerView = containerViewBack;
    containerViewBack = temp;
    containerView.setVisibility(View.VISIBLE);
    setInnerTranslationX(0);

    bringChildToFront(containerView);

    if (!needAnimation) {
      presentFragmentInternalRemoveOld(removeLast, currentFragment);
      if (backgroundView != null) {
        backgroundView.setVisibility(VISIBLE);
      }
    }

    if (needAnimation) {
      if (useAlphaAnimations && fragmentsStack.size() == 1) {
        presentFragmentInternalRemoveOld(removeLast, currentFragment);

        ArrayList<Object> animators = new ArrayList<>();
        animators.add(ObjectAnimatorProxy.ofFloat(this, "alpha", 0.0f, 1.0f));
        if (backgroundView != null) {
          backgroundView.setVisibility(VISIBLE);
          animators.add(ObjectAnimatorProxy.ofFloat(backgroundView, "alpha", 0.0f, 1.0f));
        }

        currentAnimation = new AnimatorSetProxy();
        currentAnimation.playTogether(animators);
        currentAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        currentAnimation.setDuration(200);
        currentAnimation.addListener(
            new AnimatorListenerAdapterProxy() {
              @Override
              public void onAnimationEnd(Object animation) {
                onAnimationEndCheck(false);
              }

              @Override
              public void onAnimationCancel(Object animation) {
                onAnimationEndCheck(false);
              }
            });
        currentAnimation.start();
      } else {
        transitionAnimationStartTime = System.currentTimeMillis();
        transitionAnimationInProgress = true;
        onOpenAnimationEndRunnable =
            new Runnable() {
              @Override
              public void run() {
                presentFragmentInternalRemoveOld(removeLast, currentFragment);
                fragment.onOpenAnimationEnd();
                ViewProxy.setTranslationX(containerView, 0);
              }
            };
        ViewProxy.setAlpha(containerView, 0.0f);
        ViewProxy.setTranslationX(containerView, 48.0f);
        currentAnimation = new AnimatorSetProxy();
        currentAnimation.playTogether(
            ObjectAnimatorProxy.ofFloat(containerView, "alpha", 0.0f, 1.0f),
            ObjectAnimatorProxy.ofFloat(containerView, "translationX", AndroidUtilities.dp(48), 0));
        currentAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
        currentAnimation.setDuration(200);
        currentAnimation.addListener(
            new AnimatorListenerAdapterProxy() {
              @Override
              public void onAnimationStart(Object animation) {
                transitionAnimationStartTime = System.currentTimeMillis();
              }

              @Override
              public void onAnimationEnd(Object animation) {
                onAnimationEndCheck(false);
              }

              @Override
              public void onAnimationCancel(Object animation) {
                onAnimationEndCheck(false);
              }
            });
        currentAnimation.start();
      }
    } else {
      if (backgroundView != null) {
        ViewProxy.setAlpha(backgroundView, 1.0f);
        backgroundView.setVisibility(VISIBLE);
      }
      fragment.onOpenAnimationEnd();
    }
    return true;
  }
  public boolean onTouchEvent(MotionEvent ev) {
    if (!checkTransitionAnimation() && !inActionMode && !animationInProgress) {
      if (fragmentsStack.size() > 1) {
        if (ev != null
            && ev.getAction() == MotionEvent.ACTION_DOWN
            && !startedTracking
            && !maybeStartTracking) {
          BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
          if (!currentFragment.swipeBackEnabled) {
            return false;
          }
          startedTrackingPointerId = ev.getPointerId(0);
          maybeStartTracking = true;
          startedTrackingX = (int) ev.getX();
          startedTrackingY = (int) ev.getY();
          if (velocityTracker != null) {
            velocityTracker.clear();
          }
        } else if (ev != null
            && ev.getAction() == MotionEvent.ACTION_MOVE
            && ev.getPointerId(0) == startedTrackingPointerId) {
          if (velocityTracker == null) {
            velocityTracker = VelocityTracker.obtain();
          }
          int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
          int dy = Math.abs((int) ev.getY() - startedTrackingY);
          velocityTracker.addMovement(ev);
          if (maybeStartTracking
              && !startedTracking
              && dx >= AndroidUtilities.dp(10)
              && Math.abs(dx) / 3 > dy) {
            prepareForMoving(ev);
          } else if (startedTracking) {
            if (!beginTrackingSent) {
              if (parentActivity.getCurrentFocus() != null) {
                AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
              }
              BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
              currentFragment.onBeginSlide();
              beginTrackingSent = true;
            }
            ViewProxy.setTranslationX(containerView, dx);
            setInnerTranslationX(dx);
          }
        } else if (ev != null
            && ev.getPointerId(0) == startedTrackingPointerId
            && (ev.getAction() == MotionEvent.ACTION_CANCEL
                || ev.getAction() == MotionEvent.ACTION_UP
                || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
          if (velocityTracker == null) {
            velocityTracker = VelocityTracker.obtain();
          }
          velocityTracker.computeCurrentVelocity(1000);
          if (!startedTracking) {
            float velX = velocityTracker.getXVelocity();
            float velY = velocityTracker.getYVelocity();
            if (velX >= 3500 && velX > velY) {
              prepareForMoving(ev);
              if (!beginTrackingSent) {
                if (((Activity) getContext()).getCurrentFocus() != null) {
                  AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
                }
                beginTrackingSent = true;
              }
            }
          }
          if (startedTracking) {
            float x = ViewProxy.getX(containerView);
            AnimatorSetProxy animatorSet = new AnimatorSetProxy();
            float velX = velocityTracker.getXVelocity();
            float velY = velocityTracker.getYVelocity();
            final boolean backAnimation =
                x < containerView.getMeasuredWidth() / 3.0f && (velX < 3500 || velX < velY);
            float distToMove = 0;
            if (!backAnimation) {
              distToMove = containerView.getMeasuredWidth() - x;
              animatorSet.playTogether(
                  ObjectAnimatorProxy.ofFloat(containerView, "x", containerView.getMeasuredWidth()),
                  ObjectAnimatorProxy.ofFloat(
                      this, "innerTranslationX", (float) containerView.getMeasuredWidth()));
            } else {
              distToMove = x;
              animatorSet.playTogether(
                  ObjectAnimatorProxy.ofFloat(containerView, "x", 0),
                  ObjectAnimatorProxy.ofFloat(this, "innerTranslationX", 0.0f));
            }

            animatorSet.setDuration(
                Math.max((int) (200.0f / containerView.getMeasuredWidth() * distToMove), 50));
            animatorSet.addListener(
                new AnimatorListenerAdapterProxy() {
                  @Override
                  public void onAnimationEnd(Object animator) {
                    onSlideAnimationEnd(backAnimation);
                  }

                  @Override
                  public void onAnimationCancel(Object animator) {
                    onSlideAnimationEnd(backAnimation);
                  }
                });
            animatorSet.start();
            animationInProgress = true;
          } else {
            maybeStartTracking = false;
            startedTracking = false;
          }
          if (velocityTracker != null) {
            velocityTracker.recycle();
            velocityTracker = null;
          }
        } else if (ev == null) {
          maybeStartTracking = false;
          startedTracking = false;
          if (velocityTracker != null) {
            velocityTracker.recycle();
            velocityTracker = null;
          }
        }
      }
      return startedTracking;
    }
    return false;
  }