gt:         int height = MeasureSpec.getSize(heightMeasureSpec);
context: /*
   * This is the source code of Telegram for Android v. 1.4.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-2014.
   */
  
  package org.telegram.ui.ActionBar;
  
  import android.content.Context;
  import android.content.res.Configuration;
  import android.graphics.drawable.Drawable;
  import android.os.Build;
  import android.text.TextUtils;
  import android.util.TypedValue;
  import android.view.Gravity;
  import android.view.MotionEvent;
  import android.view.View;
  import android.widget.FrameLayout;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import org.telegram.android.AndroidUtilities;
  import org.telegram.messenger.ApplicationLoader;
  import org.telegram.messenger.R;
  import org.telegram.ui.Components.LayoutHelper;
  
  public class ActionBar extends FrameLayout {
  
      public static class ActionBarMenuOnItemClick {
          public void onItemClick(int id) {
  
          }
  
          public boolean canOpenMenu() {
              return true;
          }
      }
  
      private ImageView backButtonImageView;
      private TextView titleTextView;
      private TextView subTitleTextView;
      private View actionModeTop;
      private ActionBarMenu menu;
      private ActionBarMenu actionMode;
      private boolean occupyStatusBar = Build.VERSION.SDK_INT >= 21;
  
      private boolean allowOverlayTitle;
      private CharSequence lastTitle;
      private boolean castShadows = true;
  
      protected boolean isSearchFieldVisible;
      protected int itemsBackgroundResourceId;
      private boolean isBackOverlayVisible;
      protected BaseFragment parentFragment;
      public ActionBarMenuOnItemClick actionBarMenuOnItemClick;
      private int extraHeight;
  
      public ActionBar(Context context) {
          super(context);
      }
  
      private void createBackButtonImage() {
          if (backButtonImageView != null) {
              return;
          }
          backButtonImageView = new ImageView(getContext());
          backButtonImageView.setScaleType(ImageView.ScaleType.CENTER);
          backButtonImageView.setBackgroundResource(itemsBackgroundResourceId);
          addView(backButtonImageView, LayoutHelper.createFrame(54, 54, Gravity.LEFT | Gravity.TOP));
  
          backButtonImageView.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (isSearchFieldVisible) {
                      closeSearchField();
                      return;
                  }
                  if (actionBarMenuOnItemClick != null) {
                      actionBarMenuOnItemClick.onItemClick(-1);
                  }
              }
          });
      }
  
      public void setBackButtonDrawable(Drawable drawable) {
          if (backButtonImageView == null) {
              createBackButtonImage();
          }
          backButtonImageView.setVisibility(drawable == null ? GONE : VISIBLE);
          backButtonImageView.setImageDrawable(drawable);
      }
  
      public void setBackButtonImage(int resource) {
          if (backButtonImageView == null) {
              createBackButtonImage();
          }
          backButtonImageView.setVisibility(resource == 0 ? GONE : VISIBLE);
          backButtonImageView.setImageResource(resource);
      }
  
      private void createSubtitleTextView() {
          if (subTitleTextView != null) {
              return;
          }
          subTitleTextView = new TextView(getContext());
          subTitleTextView.setGravity(Gravity.LEFT);
          subTitleTextView.setTextColor(0xffd7e8f7);
          subTitleTextView.setSingleLine(true);
          subTitleTextView.setLines(1);
          subTitleTextView.setMaxLines(1);
          subTitleTextView.setEllipsize(TextUtils.TruncateAt.END);
          addView(subTitleTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
      }
  
      public void setSubtitle(CharSequence value) {
          if (value != null && subTitleTextView == null) {
              createSubtitleTextView();
          }
          if (subTitleTextView != null) {
              subTitleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
              subTitleTextView.setText(value);
          }
      }
  
      private void createTitleTextView() {
          if (titleTextView != null) {
              return;
          }
          titleTextView = new TextView(getContext());
          titleTextView.setGravity(Gravity.LEFT);
          titleTextView.setLines(1);
          titleTextView.setMaxLines(1);
          titleTextView.setSingleLine(true);
          titleTextView.setEllipsize(TextUtils.TruncateAt.END);
          titleTextView.setTextColor(0xffffffff);
          titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
          addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
      }
  
      public void setTitle(CharSequence value) {
          if (value != null && titleTextView == null) {
              createTitleTextView();
          }
          if (titleTextView != null) {
              lastTitle = value;
              titleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
              titleTextView.setText(value);
          }
      }
  
      public TextView getSubTitleTextView() {
          return subTitleTextView;
      }
  
      public TextView getTitleTextView() {
          return titleTextView;
      }
  
      public Drawable getSubTitleIcon() {
          return subTitleTextView.getCompoundDrawables()[0];
      }
  
      public String getTitle() {
          if (titleTextView == null) {
              return null;
          }
          return titleTextView.getText().toString();
      }
  
      public ActionBarMenu createMenu() {
          if (menu != null) {
              return menu;
          }
          menu = new ActionBarMenu(getContext(), this);
          addView(menu);
          FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)menu.getLayoutParams();
          layoutParams.height = LayoutHelper.MATCH_PARENT;
          layoutParams.width = LayoutHelper.WRAP_CONTENT;
          layoutParams.gravity = Gravity.RIGHT;
          menu.setLayoutParams(layoutParams);
          return menu;
      }
  
      public void setActionBarMenuOnItemClick(ActionBarMenuOnItemClick listener) {
          actionBarMenuOnItemClick = listener;
      }
  
      public ActionBarMenu createActionMode() {
          if (actionMode != null) {
              return actionMode;
          }
          actionMode = new ActionBarMenu(getContext(), this);
          actionMode.setBackgroundResource(R.drawable.editheader);
          addView(actionMode);
          actionMode.setPadding(0, occupyStatusBar ? AndroidUtilities.statusBarHeight : 0, 0, 0);
          FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)actionMode.getLayoutParams();
          layoutParams.height = LayoutHelper.MATCH_PARENT;
          layoutParams.width = LayoutHelper.MATCH_PARENT;
          layoutParams.gravity = Gravity.RIGHT;
          actionMode.setLayoutParams(layoutParams);
          actionMode.setVisibility(INVISIBLE);
  
          if (occupyStatusBar && actionModeTop == null) {
              actionModeTop = new View(getContext());
              actionModeTop.setBackgroundColor(0x99000000);
              addView(actionModeTop);
              layoutParams = (FrameLayout.LayoutParams)actionModeTop.getLayoutParams();
              layoutParams.height = AndroidUtilities.statusBarHeight;
              layoutParams.width = LayoutHelper.MATCH_PARENT;
              layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
              actionModeTop.setLayoutParams(layoutParams);
              actionModeTop.setVisibility(INVISIBLE);
          }
  
          return actionMode;
      }
  
      public void showActionMode() {
          if (actionMode == null) {
              return;
          }
          actionMode.setVisibility(VISIBLE);
          if (occupyStatusBar && actionModeTop != null) {
              actionModeTop.setVisibility(VISIBLE);
          }
          if (titleTextView != null) {
              titleTextView.setVisibility(INVISIBLE);
          }
          if (subTitleTextView != null) {
              subTitleTextView.setVisibility(INVISIBLE);
          }
          if (backButtonImageView != null) {
              backButtonImageView.setVisibility(INVISIBLE);
          }
          if (menu != null) {
              menu.setVisibility(INVISIBLE);
          }
      }
  
      public void hideActionMode() {
          if (actionMode == null) {
              return;
          }
          actionMode.setVisibility(INVISIBLE);
          if (occupyStatusBar && actionModeTop != null) {
              actionModeTop.setVisibility(INVISIBLE);
          }
          if (titleTextView != null) {
              titleTextView.setVisibility(VISIBLE);
          }
          if (subTitleTextView != null) {
              subTitleTextView.setVisibility(VISIBLE);
          }
          if (backButtonImageView != null) {
              backButtonImageView.setVisibility(VISIBLE);
          }
          if (menu != null) {
              menu.setVisibility(VISIBLE);
          }
      }
  
      public void showActionModeTop() {
          if (occupyStatusBar && actionModeTop == null) {
              actionModeTop = new View(getContext());
              actionModeTop.setBackgroundColor(0x99000000);
              addView(actionModeTop);
              FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) actionModeTop.getLayoutParams();
              layoutParams.height = AndroidUtilities.statusBarHeight;
              layoutParams.width = LayoutHelper.MATCH_PARENT;
              layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
              actionModeTop.setLayoutParams(layoutParams);
          }
      }
  
      public boolean isActionModeShowed() {
          return actionMode != null && actionMode.getVisibility() == VISIBLE;
      }
  
      protected void onSearchFieldVisibilityChanged(boolean visible) {
          isSearchFieldVisible = visible;
          if (titleTextView != null) {
              titleTextView.setVisibility(visible ? INVISIBLE : VISIBLE);
          }
          if (subTitleTextView != null) {
              subTitleTextView.setVisibility(visible ? INVISIBLE : VISIBLE);
          }
          Drawable drawable = backButtonImageView.getDrawable();
          if (drawable != null && drawable instanceof MenuDrawable) {
              ((MenuDrawable)drawable).setRotation(visible ? 1 : 0, true);
          }
      }
  
      public void closeSearchField() {
          if (!isSearchFieldVisible || menu == null) {
              return;
          }
          menu.closeSearchField();
      }
  
      public void openSearchField(String text) {
          if (menu == null || text == null) {
              return;
          }
          menu.openSearchField(!isSearchFieldVisible, text);
      }
  
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          int width = MeasureSpec.getSize(widthMeasureSpec);
  