gt:             if (delegatePageListener != null) {
context: /*
   * This is the source code of ZiosGram for Android v. 3.x.x.
   * It is licensed under GNU GPL v. 2 or later.
   * You should have received a copy of the license in this archive (see LICENSE).
   *
   * Copyright Nikolai Kudashov, 2013-2017.
   */
  
  package org.blaez.ui.Components;
  
  import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.Paint;
  import android.graphics.Paint.Style;
  import android.graphics.drawable.Drawable;
  import android.os.Build;
  import android.support.v4.view.ViewPager;
  import android.support.v4.view.ViewPager.OnPageChangeListener;
  import android.view.View;
  import android.view.ViewTreeObserver.OnGlobalLayoutListener;
  import android.widget.FrameLayout;
  import android.widget.HorizontalScrollView;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  
  import org.blaez.ziosgram.AndroidUtilities;
  
  public class PagerSlidingTabStrip extends HorizontalScrollView {
  
      public interface IconTabProvider {
          Drawable getPageIconDrawable(int position);
          void customOnDraw(Canvas canvas, int position);
      }
  
      private LinearLayout.LayoutParams defaultTabLayoutParams;
  
      private final PageListener pageListener = new PageListener();
      public OnPageChangeListener delegatePageListener;
  
      private LinearLayout tabsContainer;
      private ViewPager pager;
  
      private int tabCount;
  
      private int currentPosition = 0;
      private float currentPositionOffset = 0f;
  
      private Paint rectPaint;
  
      private int indicatorColor = 0xff666666;
      private int underlineColor = 0x1a000000;
  
      private boolean shouldExpand = false;
  
      private int scrollOffset = AndroidUtilities.dp(52);
      private int indicatorHeight = AndroidUtilities.dp(8);
      private int underlineHeight = AndroidUtilities.dp(2);
      private int dividerPadding = AndroidUtilities.dp(12);
      private int tabPadding = AndroidUtilities.dp(24);
  
      private int lastScrollX = 0;
  
      public PagerSlidingTabStrip(Context context) {
          super(context);
  
          setFillViewport(true);
          setWillNotDraw(false);
  
          tabsContainer = new LinearLayout(context);
          tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
          tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
          addView(tabsContainer);
  
          rectPaint = new Paint();
          rectPaint.setAntiAlias(true);
          rectPaint.setStyle(Style.FILL);
  
          defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutHelper.MATCH_PARENT);
      }
  
      public void setViewPager(ViewPager pager) {
          this.pager = pager;
          if (pager.getAdapter() == null) {
              throw new IllegalStateException("ViewPager does not have adapter instance.");
          }
          pager.setOnPageChangeListener(pageListener);
          notifyDataSetChanged();
      }
  
      public void setOnPageChangeListener(OnPageChangeListener listener) {
          this.delegatePageListener = listener;
      }
  
      public void notifyDataSetChanged() {
          tabsContainer.removeAllViews();
          tabCount = pager.getAdapter().getCount();
          for (int i = 0; i < tabCount; i++) {
              if (pager.getAdapter() instanceof IconTabProvider) {
                  addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconDrawable(i));
              }
          }
          updateTabStyles();
          getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                  if (Build.VERSION.SDK_INT < 16) {
                      getViewTreeObserver().removeGlobalOnLayoutListener(this);
                  } else {
                      getViewTreeObserver().removeOnGlobalLayoutListener(this);
                  }
                  currentPosition = pager.getCurrentItem();
                  scrollToChild(currentPosition, 0);
              }
          });
      }
  
      private void addIconTab(final int position, Drawable drawable) {
          ImageView tab = new ImageView(getContext()) {
              @Override
              protected void onDraw(Canvas canvas) {
                  super.onDraw(canvas);
                  if (pager.getAdapter() instanceof IconTabProvider) {
                      ((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position);
                  }
              }
          };
          tab.setFocusable(true);
          tab.setImageDrawable(drawable);
          tab.setScaleType(ImageView.ScaleType.CENTER);
          tab.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  pager.setCurrentItem(position);
              }
          });
          tabsContainer.addView(tab);
          tab.setSelected(position == currentPosition);
      }
  
      private void updateTabStyles() {
          for (int i = 0; i < tabCount; i++) {
              View v = tabsContainer.getChildAt(i);
              v.setLayoutParams(defaultTabLayoutParams);
              if (shouldExpand) {
                  v.setPadding(0, 0, 0, 0);
                  v.setLayoutParams(new LinearLayout.LayoutParams(-1, -1, 1.0F));
              } else {
                  v.setPadding(tabPadding, 0, tabPadding, 0);
              }
          }
      }
  
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
          if (!shouldExpand || MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) {
              return;
          }
          int myWidth = getMeasuredWidth();
          tabsContainer.measure(MeasureSpec.EXACTLY | myWidth, heightMeasureSpec);
      }
  
      private void scrollToChild(int position, int offset) {
          if (tabCount == 0) {
              return;
          }
          int newScrollX = tabsContainer.getChildAt(position).getLeft() + offset;
          if (position > 0 || offset > 0) {
              newScrollX -= scrollOffset;
          }
          if (newScrollX != lastScrollX) {
              lastScrollX = newScrollX;
              scrollTo(newScrollX, 0);
          }
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          super.onDraw(canvas);
  
          if (isInEditMode() || tabCount == 0) {
              return;
          }
  
          final int height = getHeight();
  
          // draw underline
          rectPaint.setColor(underlineColor);
          canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);
  
          // default: line below current tab
          View currentTab = tabsContainer.getChildAt(currentPosition);
          float lineLeft = currentTab.getLeft();
          float lineRight = currentTab.getRight();
  
          // if there is an offset, start interpolating left and right coordinates between current and next tab
          if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
  
              View nextTab = tabsContainer.getChildAt(currentPosition + 1);
              final float nextTabLeft = nextTab.getLeft();
              final float nextTabRight = nextTab.getRight();
  
              lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
              lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
          }
  
          // draw indicator line
          rectPaint.setColor(indicatorColor);
          canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
      }
  
      private class PageListener implements OnPageChangeListener {
  
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
              currentPosition = position;
              currentPositionOffset = positionOffset;
              scrollToChild(position, (int) (positionOffset * tabsContainer.getChildAt(position).getWidth()));
              invalidate();
  