private void applyViewsLayoutParams(int xOffset) {
   FrameLayout.LayoutParams layoutParams;
   int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
   if (leftView != null) {
     layoutParams = (FrameLayout.LayoutParams) leftView.getLayoutParams();
     layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
     layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
     layoutParams.width = widht;
     layoutParams.leftMargin = -widht + xOffset;
     leftView.setLayoutParams(layoutParams);
   }
   if (centerView != null) {
     layoutParams = (FrameLayout.LayoutParams) centerView.getLayoutParams();
     layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
     layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
     layoutParams.width = widht;
     layoutParams.leftMargin = xOffset;
     centerView.setLayoutParams(layoutParams);
   }
   if (rightView != null) {
     layoutParams = (FrameLayout.LayoutParams) rightView.getLayoutParams();
     layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
     layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
     layoutParams.width = widht;
     layoutParams.leftMargin = widht + xOffset;
     rightView.setLayoutParams(layoutParams);
   }
   messageContainer.invalidate();
 }
 private void prepareLayouts(int move) {
   if (move == 0) {
     reuseView(centerView);
     reuseView(leftView);
     reuseView(rightView);
     for (int a = currentMessageNum - 1; a < currentMessageNum + 2; a++) {
       if (a == currentMessageNum - 1) {
         leftView = getViewForMessage(a, true);
       } else if (a == currentMessageNum) {
         centerView = getViewForMessage(a, true);
       } else if (a == currentMessageNum + 1) {
         rightView = getViewForMessage(a, true);
       }
     }
   } else if (move == 1) {
     reuseView(rightView);
     rightView = centerView;
     centerView = leftView;
     leftView = getViewForMessage(currentMessageNum - 1, true);
   } else if (move == 2) {
     reuseView(leftView);
     leftView = centerView;
     centerView = rightView;
     rightView = getViewForMessage(currentMessageNum + 1, true);
   } else if (move == 3) {
     if (rightView != null) {
       int offset = ((FrameLayout.LayoutParams) rightView.getLayoutParams()).leftMargin;
       reuseView(rightView);
       rightView = getViewForMessage(currentMessageNum + 1, false);
       int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
       FrameLayout.LayoutParams layoutParams =
           (FrameLayout.LayoutParams) rightView.getLayoutParams();
       layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
       layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
       layoutParams.width = widht;
       layoutParams.leftMargin = offset;
       rightView.setLayoutParams(layoutParams);
       rightView.invalidate();
     }
   } else if (move == 4) {
     if (leftView != null) {
       int offset = ((FrameLayout.LayoutParams) leftView.getLayoutParams()).leftMargin;
       reuseView(leftView);
       leftView = getViewForMessage(0, false);
       int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
       FrameLayout.LayoutParams layoutParams =
           (FrameLayout.LayoutParams) leftView.getLayoutParams();
       layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
       layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
       layoutParams.width = widht;
       layoutParams.leftMargin = offset;
       leftView.setLayoutParams(layoutParams);
       leftView.invalidate();
     }
   }
 }
  public ShadowViewGroup(Context context, int id, int width) {
    super(context);

    FrameLayout.LayoutParams lp =
        new FrameLayout.LayoutParams(width + SHADOW_WIDTH, ViewGroup.LayoutParams.FILL_PARENT);
    lp.gravity = Gravity.LEFT;
    this.setLayoutParams(lp);

    FrameLayout shadowView = new FrameLayout(context);
    FrameLayout.LayoutParams shadowViewLayoutParams =
        new FrameLayout.LayoutParams(SHADOW_WIDTH, ViewGroup.LayoutParams.FILL_PARENT);
    shadowViewLayoutParams.gravity = Gravity.LEFT;
    shadowView.setLayoutParams(shadowViewLayoutParams);
    shadowView.setBackgroundResource(R.drawable.drop_shadow);

    FrameLayout slideView = new FrameLayout(context);
    slideView.setId(id);
    FrameLayout.LayoutParams slideViewLayoutParams =
        new FrameLayout.LayoutParams(width + SHADOW_WIDTH, ViewGroup.LayoutParams.FILL_PARENT);
    slideViewLayoutParams.gravity = Gravity.LEFT;
    slideViewLayoutParams.leftMargin = SHADOW_WIDTH;
    slideView.setLayoutParams(slideViewLayoutParams);

    addView(slideView);
    addView(shadowView);

    this.showShadow(false);
  }
  public void showShadow(boolean showShadow) {
    if (showShadow) {
      getChildAt(1).setVisibility(View.VISIBLE);
      FrameLayout.LayoutParams lp = (LayoutParams) this.getLayoutParams();
      lp.gravity = Gravity.LEFT;
      lp.width = getChildAt(0).getLayoutParams().width;
      this.setLayoutParams(lp);

      FrameLayout.LayoutParams slideViewLayoutParams =
          new FrameLayout.LayoutParams(
              getChildAt(0).getLayoutParams().width, ViewGroup.LayoutParams.FILL_PARENT);
      slideViewLayoutParams.gravity = Gravity.LEFT;
      slideViewLayoutParams.leftMargin = SHADOW_WIDTH;
      getChildAt(0).setLayoutParams(slideViewLayoutParams);

    } else {
      getChildAt(1).setVisibility(View.GONE);
      FrameLayout.LayoutParams lp = (LayoutParams) this.getLayoutParams();
      lp.gravity = Gravity.LEFT;
      lp.width = getChildAt(0).getLayoutParams().width;
      this.setLayoutParams(lp);
      FrameLayout.LayoutParams slideViewLayoutParams =
          new FrameLayout.LayoutParams(
              getChildAt(0).getLayoutParams().width, ViewGroup.LayoutParams.FILL_PARENT);
      slideViewLayoutParams.gravity = Gravity.LEFT; //
      getChildAt(0).setLayoutParams(slideViewLayoutParams);
    }
  }
  private void updatelayoutIconVideo() {
    // update for video ion big
    LayoutParams lpImageBox;
    if (mImage != null) {
      lpImageBox = (LayoutParams) mImage.getLayoutParams();
    } else {
      lpImageBox = (LayoutParams) mLLTitle.getLayoutParams();
    }

    int width = lpImageBox.width;
    int height = lpImageBox.height;

    FrameLayout.LayoutParams lpLLTitle = (LayoutParams) mLLTitle.getLayoutParams();

    int heightPortion = height - lpLLTitle.height;

    if (heightPortion == 0) {
      height = getBoxSupposeHeight();
      heightPortion = height - lpLLTitle.height;
    }

    FrameLayout.LayoutParams lpVideoIcon = (LayoutParams) mIvVideoIconBig.getLayoutParams();

    if (lpLLTitle.height > height / 2) {
      lpVideoIcon.gravity = Gravity.CENTER_VERTICAL;
      lpVideoIcon.leftMargin = width / 2 - lpVideoIcon.width / 2;
    }

    if (Math.abs(heightPortion) > height / 3) {
      lpVideoIcon.gravity = Gravity.CENTER_HORIZONTAL;
      lpVideoIcon.topMargin = heightPortion / 2 - lpVideoIcon.height / 2;
    }
    mIvVideoIconBig.setLayoutParams(lpVideoIcon);
    mIvVideoIconBig.setVisibility(VISIBLE);
  }
Example #6
0
 public void setBadgeMargin(
     int leftDipMargin, int topDipMargin, int rightDipMargin, int bottomDipMargin) {
   FrameLayout.LayoutParams params = (LayoutParams) getLayoutParams();
   params.leftMargin = dip2Px(leftDipMargin);
   params.topMargin = dip2Px(topDipMargin);
   params.rightMargin = dip2Px(rightDipMargin);
   params.bottomMargin = dip2Px(bottomDipMargin);
   setLayoutParams(params);
 }
Example #7
0
 /**
  * 更新fouccusview的中心
  *
  * @param x
  * @param y
  */
 public void updateFouccusCenter(float x, float y, Rect rect) {
   //        mFocus.setBackgroundColor(Color.WHITE);
   mFocus.setVisibility(View.VISIBLE);
   FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
   lp.width = rect.width();
   lp.height = rect.height();
   lp.leftMargin = (int) (x - rect.width() / 2);
   lp.topMargin = (int) (y - rect.height() / 2);
   setLayoutParams(lp);
 }
Example #8
0
  @Override
  public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    // Translate overlay and image
    float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize;
    int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight();
    ViewHelper.setTranslationY(
        mOverlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0));
    ViewHelper.setTranslationY(
        mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0));

    // Change alpha of overlay
    ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1));

    // Scale title text
    float scale =
        1
            + ScrollUtils.getFloat(
                (flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA);
    ViewHelper.setPivotX(mTitleView, 0);
    ViewHelper.setPivotY(mTitleView, 0);
    ViewHelper.setScaleX(mTitleView, scale);
    ViewHelper.setScaleY(mTitleView, scale);

    // Translate title text
    int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale);
    int titleTranslationY = maxTitleTranslationY - scrollY;
    ViewHelper.setTranslationY(mTitleView, titleTranslationY);

    // Translate FAB
    int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2;
    float fabTranslationY =
        ScrollUtils.getFloat(
            -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2,
            mActionBarSize - mFab.getHeight() / 2,
            maxFabTranslationY);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      // On pre-honeycomb, ViewHelper.setTranslationX/Y does not set margin,
      // which causes FAB's OnClickListener not working.
      FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFab.getLayoutParams();
      lp.leftMargin = mOverlayView.getWidth() - mFabMargin - mFab.getWidth();
      lp.topMargin = (int) fabTranslationY;
      mFab.requestLayout();
    } else {
      ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth());
      ViewHelper.setTranslationY(mFab, fabTranslationY);
    }

    // Show/hide FAB
    if (fabTranslationY < mFlexibleSpaceShowFabOffset) {
      hideFab();
    } else {
      showFab();
    }
  }
Example #9
0
 public void setWebViewRect(int left, int top, int maxWidth, int maxHeight) {
   FrameLayout.LayoutParams layoutParams =
       new FrameLayout.LayoutParams(
           FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
   layoutParams.leftMargin = left;
   layoutParams.topMargin = top;
   layoutParams.width = maxWidth;
   layoutParams.height = maxHeight;
   layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
   this.setLayoutParams(layoutParams);
 }
 private void addView2CurrentWindow(View child, RelativeLayout.LayoutParams parms) {
   int l = (int) (parms.leftMargin);
   int t = (int) (parms.topMargin);
   int w = parms.width;
   int h = parms.height;
   FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(w, h);
   lp.gravity = Gravity.NO_GRAVITY;
   lp.leftMargin = l;
   lp.topMargin = t;
   adptLayoutParams(parms, lp);
   mBrwView.addViewToCurrentWindow(child, lp);
 }
 public void setCustomButton(final CustomButtonVO dataVO) {
   CustomButtonResultVO resultVO = new CustomButtonResultVO();
   resultVO.setId(dataVO.getId());
   if (!isAlreadyAdded(dataVO.getId())) {
     FrameLayout.LayoutParams lpParams =
         new FrameLayout.LayoutParams(dataVO.getWidth(), dataVO.getHeight());
     lpParams.leftMargin = dataVO.getX();
     lpParams.topMargin = dataVO.getY();
     Button btn = new Button(this);
     btn.setLayoutParams(lpParams);
     btn.setPadding(0, 0, 0, 0);
     if (!TextUtils.isEmpty(dataVO.getTitle())) {
       btn.setText(dataVO.getTitle());
     }
     if (dataVO.getTextSize() > 0) {
       btn.setTextSize(dataVO.getTextSize());
     }
     if (!TextUtils.isEmpty(dataVO.getTitleColor())) {
       btn.setTextColor(BUtility.parseColor(dataVO.getTitleColor()));
     }
     if (!TextUtils.isEmpty(dataVO.getBgImage())) {
       Drawable bg = new BitmapDrawable(GaodeUtils.getImage(this, dataVO.getBgImage()));
       int version = Build.VERSION.SDK_INT;
       if (version < 16) {
         btn.setBackgroundDrawable(bg);
       } else {
         btn.setBackground(bg);
       }
     }
     mContent.addView(btn);
     btn.setVisibility(View.GONE);
     btn.setOnClickListener(
         new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             if (mListener != null) {
               EUExGaodeMap gaodeMap = mButtons.get(dataVO.getId()).getGaodeMap();
               mListener.onButtonClick(dataVO.getId(), gaodeMap);
             }
           }
         });
     CustomButtonBean button = new CustomButtonBean();
     button.setButton(btn);
     mButtons.put(dataVO.getId(), button);
     resultVO.setIsSuccess(true);
   } else {
     resultVO.setIsSuccess(false);
   }
   if (mListener != null) {
     mListener.cbSetCustomButton(resultVO);
   }
 }
Example #12
0
 public static void resetFL(View... view) {
   float rote = Handler_System.getWidthRoate(ApplicationBean.getApplication().getMode_w());
   if (view == null || rote == 1) {
     return;
   }
   for (View view2 : view) {
     FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view2.getLayoutParams();
     layoutParams.leftMargin = (int) (layoutParams.leftMargin * rote);
     layoutParams.rightMargin = (int) (layoutParams.rightMargin * rote);
     layoutParams.topMargin = (int) (layoutParams.topMargin * rote);
     layoutParams.bottomMargin = (int) (layoutParams.bottomMargin * rote);
     view2.setLayoutParams(layoutParams);
   }
 }
 private void init(Context context, AttributeSet attrs) {
   mListView = new ListView(context, attrs);
   mListView.setPadding(0, 0, 0, 0);
   FrameLayout.LayoutParams params =
       new FrameLayout.LayoutParams(
           ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
   params.bottomMargin = 0;
   params.topMargin = 0;
   params.leftMargin = 0;
   params.rightMargin = 0;
   mListView.setLayoutParams(params);
   mListView.setId(android.R.id.list);
   mListView.setOnScrollListener(mOnScrollListener);
   addView(mListView);
 }
Example #14
0
  public CustVideoView(final Context context, Video video) {
    super(context);
    this.context = context;
    this.setVideo(video);
    String frame = video.getFrame();
    String closesOnEnd = video.getClosesOnEnd();
    if (closesOnEnd != null && closesOnEnd.equalsIgnoreCase("true")) {
      autoClose = true;
    }
    fullscreen = video.getFullscreen();
    FrameLayout.LayoutParams params;
    int[] frames = FrameUtil.frame2int(frame);
    frames = FrameUtil.autoAdjust(frames, context);
    // 全屏模式
    if (fullscreen.equalsIgnoreCase("true")) {
      act = (Activity) context;
      Display display = act.getWindowManager().getDefaultDisplay();
      int width = display.getWidth();
      int height = display.getHeight();
      params = new FrameLayout.LayoutParams(width, height);
      params.topMargin = 0;
      params.leftMargin = 0;
      setMeasuredDimension(width, height);
    } else {
      params = new FrameLayout.LayoutParams(frames[2], frames[3]);
      params.setMargins(frames[0], frames[1], 0, 0);
    }
    setLayoutParams(params);
    String path = AppConfigUtil.getAppResource(AppConfigUtil.MAGAZINE_ID) + video.getResource();
    setVideoPath(path);
    setVisibility(View.VISIBLE);
    setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer mp) {
            MagazineActivity act = (MagazineActivity) context;
            act.getvControllers().remove(this);
            if (autoClose) {
              setVisibility(View.INVISIBLE);
              showLayers();
            }
          }
        });
    setOnClickListener(this);
  }
  private void InitButton() {
    FrameLayout layout = (FrameLayout) view.findViewById(R.id.container);
    oval = new View(context);
    oval.setBackgroundResource(R.drawable.oval);
    layout.addView(oval);
    spinner = (Spinner) view.findViewById(R.id.spinner);
    arrStage = new String[stageList.length];
    for (int i = 0; i < stageList.length; i++) {
      arrStage[i] = new String(stageList[i].stageName);
      for (int j = 0; j < stageList[i].nodeList.length; j++) {
        for (int k = 0; k < stageList[i].nodeList[j].deviceList.length; k++) {
          Button curButton = new Button(context);
          curButton.setBackgroundResource(R.drawable.focus_false);
          FrameLayout.LayoutParams imagebtn_params = new FrameLayout.LayoutParams(60, 80);
          imagebtn_params.leftMargin = GetX(stageList[i].nodeList[j].deviceList[k].px);
          imagebtn_params.topMargin = GetY(stageList[i].nodeList[j].deviceList[k].py);
          curButton.setId(i * 1000 + j * 100 + k);
          curButton.setLayoutParams(imagebtn_params);
          layout.addView(curButton);
          curButton.setOnClickListener(new deviceButtonListener());
          if (i == curStage) curButton.setVisibility(View.VISIBLE);
          else curButton.setVisibility(View.GONE);
        }
      }
    }
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(context, R.layout.spinner_board, arrStage) {
          @Override
          public View getDropDownView(int position, View convertView, ViewGroup parent) {

            View adapterView =
                getActivity().getLayoutInflater().inflate(R.layout.spinner_item, parent, false);
            TextView label = (TextView) adapterView.findViewById(R.id.label);
            label.setText(getItem(position));
            ImageView icon = (ImageView) adapterView.findViewById(R.id.icon);
            icon.setVisibility(
                spinner.getSelectedItemPosition() == position ? View.VISIBLE : View.INVISIBLE);
            return adapterView;
          }
        };
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new stageOnItemSelectedListener());
  }
 private void ChangeButton(int status) {
   int x = status / 1000, y = status % 1000 / 100, z = status % 100;
   ovalParams.leftMargin = GetX(stageList[x].nodeList[y].deviceList[z].px) - 40;
   ovalParams.topMargin = GetY(stageList[x].nodeList[y].deviceList[z].py) + 30;
   oval.setLayoutParams(ovalParams);
   TextView deviceName = (TextView) view.findViewById(R.id.device_name);
   deviceName.setText(stageList[x].nodeList[y].deviceList[z].deviceName);
   TextView process = (TextView) view.findViewById(R.id.process);
   process.setText("[" + stageList[x].nodeList[y].deviceList[z].process + "]");
   TextView place = (TextView) view.findViewById(R.id.place);
   place.setText(stageList[x].nodeList[y].deviceList[z].place);
   TextView type = (TextView) view.findViewById(R.id.type);
   type.setText(stageList[x].nodeList[y].deviceList[z].type);
   TextView nodeName = (TextView) view.findViewById(R.id.node_name);
   nodeName.setText(stageList[x].nodeList[y].nodeName);
   if (stageList[x].nodeList[y].deviceList[z].type.equals("hik"))
     videoButton.setVisibility(View.VISIBLE);
   else videoButton.setVisibility(View.GONE);
 }
Example #17
0
  public DialogHolder(
      Context context, FrameLayout fl, final OnItemClickedListener<Dialog> onClickListener) {
    super(fl);

    this.context = context;

    final int paddingH = Screen.dp(11);
    final int paddingV = Screen.dp(9);

    pendingColor = context.getResources().getColor(R.color.chats_state_pending);
    sentColor = context.getResources().getColor(R.color.chats_state_sent);
    receivedColor = context.getResources().getColor(R.color.chats_state_delivered);
    readColor = context.getResources().getColor(R.color.chats_state_read);
    errorColor = context.getResources().getColor(R.color.chats_state_error);

    fl.setLayoutParams(
        new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(73)));
    fl.setBackgroundResource(R.drawable.selector_fill);

    avatar = new AvatarView(context);
    avatar.init(Screen.dp(52), 24);
    {
      FrameLayout.LayoutParams avatarLayoutParams =
          new FrameLayout.LayoutParams(Screen.dp(52), Screen.dp(52));
      avatarLayoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
      avatarLayoutParams.leftMargin = paddingH;
      avatar.setLayoutParams(avatarLayoutParams);
    }
    fl.addView(avatar);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.TOP);
    {
      FrameLayout.LayoutParams layoutParams =
          new FrameLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
      layoutParams.rightMargin = paddingH;
      layoutParams.leftMargin = Screen.dp(79);
      layoutParams.topMargin = paddingV;
      layoutParams.bottomMargin = paddingV;
      linearLayout.setLayoutParams(layoutParams);
    }

    LinearLayout firstRow = new LinearLayout(context);
    firstRow.setOrientation(LinearLayout.HORIZONTAL);
    {
      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      firstRow.setLayoutParams(params);
    }

    title = new TextView(context);
    title.setTextColor(context.getResources().getColor(R.color.chats_title));
    title.setTypeface(Fonts.medium());
    title.setTextSize(17);
    title.setPadding(0, Screen.dp(1), 0, 0);
    title.setSingleLine();
    title.setCompoundDrawablePadding(Screen.dp(4));
    title.setEllipsize(TextUtils.TruncateAt.END);
    {
      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
      params.weight = 1;
      title.setLayoutParams(params);
    }
    firstRow.addView(title);

    time = new TextView(context);
    time.setTextColor(context.getResources().getColor(R.color.chats_time));
    time.setTypeface(Fonts.regular());
    time.setTextSize(13);
    time.setPadding(Screen.dp(6), 0, 0, 0);
    time.setSingleLine();
    firstRow.addView(time);

    linearLayout.addView(firstRow);

    text = new TextView(context);
    text.setTypeface(Fonts.regular());
    text.setTextColor(context.getResources().getColor(R.color.chats_text));
    text.setTextSize(15);
    text.setPadding(0, Screen.dp(5), Screen.dp(28), 0);
    text.setSingleLine();
    text.setEllipsize(TextUtils.TruncateAt.END);
    linearLayout.addView(text);

    fl.addView(linearLayout);

    separator = new View(context);
    separator.setBackgroundColor(context.getResources().getColor(R.color.chats_divider));
    FrameLayout.LayoutParams divLayoutParams =
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            context.getResources().getDimensionPixelSize(R.dimen.div_size));
    divLayoutParams.leftMargin = Screen.dp(76);
    divLayoutParams.gravity = Gravity.BOTTOM;
    fl.addView(separator, divLayoutParams);

    state = new TintImageView(context);
    {
      FrameLayout.LayoutParams params =
          new FrameLayout.LayoutParams(
              Screen.dp(28), Screen.dp(12), Gravity.BOTTOM | Gravity.RIGHT);
      params.bottomMargin = Screen.dp(16);
      params.rightMargin = Screen.dp(9);
      state.setLayoutParams(params);
      fl.addView(state);
    }

    counter = new TextView(context);
    counter.setTextColor(context.getResources().getColor(R.color.chats_counter));
    counter.setBackgroundColor(context.getResources().getColor(R.color.chats_counter_bg));
    counter.setPadding(Screen.dp(4), 0, Screen.dp(4), 0);
    counter.setTextSize(10);
    counter.setTypeface(Fonts.regular());
    counter.setGravity(Gravity.CENTER);
    counter.setIncludeFontPadding(false);
    counter.setMinWidth(Screen.dp(14));
    {
      FrameLayout.LayoutParams params =
          new FrameLayout.LayoutParams(
              ViewGroup.LayoutParams.WRAP_CONTENT, Screen.dp(14), Gravity.BOTTOM | Gravity.RIGHT);
      params.bottomMargin = Screen.dp(12);
      params.rightMargin = Screen.dp(10);
      counter.setLayoutParams(params);
      fl.addView(counter);
    }

    fl.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (bindedItem != null) {
              onClickListener.onClicked(bindedItem);
            }
          }
        });
    fl.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            if (bindedItem != null) {
              return onClickListener.onLongClicked(bindedItem);
            }
            return false;
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    classGuid = ConnectionsManager.getInstance().generateClassGuid();
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.pushMessagesUpdated);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    typingDotsDrawable = new TypingDotsDrawable();
    recordStatusDrawable = new RecordStatusDrawable();

    SizeNotifierRelativeLayout contentView = new SizeNotifierRelativeLayout(this);
    setContentView(contentView);
    contentView.setBackgroundColor(0x99000000);

    RelativeLayout relativeLayout = new RelativeLayout(this);
    contentView.addView(relativeLayout);
    RelativeLayout.LayoutParams layoutParams3 =
        (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.MATCH_PARENT;
    relativeLayout.setLayoutParams(layoutParams3);

    RelativeLayout popupContainer = new RelativeLayout(this);
    popupContainer.setBackgroundColor(0xffffffff);
    relativeLayout.addView(popupContainer);
    layoutParams3 = (RelativeLayout.LayoutParams) popupContainer.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = AndroidUtilities.dp(240);
    layoutParams3.leftMargin = AndroidUtilities.dp(12);
    layoutParams3.rightMargin = AndroidUtilities.dp(12);
    layoutParams3.addRule(RelativeLayout.CENTER_IN_PARENT);
    popupContainer.setLayoutParams(layoutParams3);

    if (chatActivityEnterView != null) {
      chatActivityEnterView.onDestroy();
    }
    chatActivityEnterView = new ChatActivityEnterView(this, contentView, null, false);
    popupContainer.addView(chatActivityEnterView);
    layoutParams3 = (RelativeLayout.LayoutParams) chatActivityEnterView.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    chatActivityEnterView.setLayoutParams(layoutParams3);
    chatActivityEnterView.setDelegate(
        new ChatActivityEnterView.ChatActivityEnterViewDelegate() {
          @Override
          public void onMessageSend(String message) {
            if (currentMessageObject == null) {
              return;
            }
            if (currentMessageNum >= 0
                && currentMessageNum < NotificationsController.getInstance().popupMessages.size()) {
              NotificationsController.getInstance().popupMessages.remove(currentMessageNum);
            }
            MessagesController.getInstance()
                .markDialogAsRead(
                    currentMessageObject.getDialogId(),
                    currentMessageObject.getId(),
                    Math.max(0, currentMessageObject.getId()),
                    0,
                    currentMessageObject.messageOwner.date,
                    true,
                    true);
            currentMessageObject = null;
            getNewMessage();
          }

          @Override
          public void onTextChanged(CharSequence text, boolean big) {}

          @Override
          public void needSendTyping() {
            if (currentMessageObject != null) {
              MessagesController.getInstance()
                  .sendTyping(currentMessageObject.getDialogId(), 0, classGuid);
            }
          }

          @Override
          public void onAttachButtonHidden() {}

          @Override
          public void onAttachButtonShow() {}

          @Override
          public void onWindowSizeChanged(int size) {}
        });

    messageContainer = new FrameLayoutTouch(this);
    popupContainer.addView(messageContainer, 0);

    actionBar = new ActionBar(this);
    actionBar.setOccupyStatusBar(false);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setBackgroundColor(0xff54759e);
    actionBar.setItemsBackground(R.drawable.bar_selector);
    popupContainer.addView(actionBar);
    ViewGroup.LayoutParams layoutParams = actionBar.getLayoutParams();
    layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    actionBar.setLayoutParams(layoutParams);

    ActionBarMenu menu = actionBar.createMenu();
    View view = menu.addItemResource(2, R.layout.popup_count_layout);
    countText = (TextView) view.findViewById(R.id.count_text);

    avatarContainer = new FrameLayoutFixed(this);
    avatarContainer.setBackgroundResource(R.drawable.bar_selector);
    avatarContainer.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
    actionBar.addView(avatarContainer);
    FrameLayout.LayoutParams layoutParams2 =
        (FrameLayout.LayoutParams) avatarContainer.getLayoutParams();
    layoutParams2.height = LayoutHelper.MATCH_PARENT;
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.rightMargin = AndroidUtilities.dp(48);
    layoutParams2.leftMargin = AndroidUtilities.dp(60);
    layoutParams2.gravity = Gravity.TOP | Gravity.LEFT;
    avatarContainer.setLayoutParams(layoutParams2);

    avatarImageView = new BackupImageView(this);
    avatarImageView.setRoundRadius(AndroidUtilities.dp(21));
    avatarContainer.addView(avatarImageView);
    layoutParams2 = (FrameLayout.LayoutParams) avatarImageView.getLayoutParams();
    layoutParams2.width = AndroidUtilities.dp(42);
    layoutParams2.height = AndroidUtilities.dp(42);
    layoutParams2.topMargin = AndroidUtilities.dp(3);
    avatarImageView.setLayoutParams(layoutParams2);

    nameTextView = new TextView(this);
    nameTextView.setTextColor(0xffffffff);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    nameTextView.setLines(1);
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setGravity(Gravity.LEFT);
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    avatarContainer.addView(nameTextView);
    layoutParams2 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.leftMargin = AndroidUtilities.dp(54);
    layoutParams2.bottomMargin = AndroidUtilities.dp(22);
    layoutParams2.gravity = Gravity.BOTTOM;
    nameTextView.setLayoutParams(layoutParams2);

    onlineTextView = new TextView(this);
    onlineTextView.setTextColor(0xffd7e8f7);
    onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    onlineTextView.setLines(1);
    onlineTextView.setMaxLines(1);
    onlineTextView.setSingleLine(true);
    onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
    onlineTextView.setGravity(Gravity.LEFT);
    avatarContainer.addView(onlineTextView);
    layoutParams2 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.leftMargin = AndroidUtilities.dp(54);
    layoutParams2.bottomMargin = AndroidUtilities.dp(4);
    layoutParams2.gravity = Gravity.BOTTOM;
    onlineTextView.setLayoutParams(layoutParams2);

    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              onFinish();
              finish();
            } else if (id == 1) {
              openCurrentMessage();
            } else if (id == 2) {
              switchToNextMessage();
            }
          }
        });

    PowerManager pm =
        (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
    wakeLock =
        pm.newWakeLock(
            PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "screen");
    wakeLock.setReferenceCounted(false);

    handleIntent(getIntent());
  }
Example #19
0
  public void createControls() {
    // 1. Create view groups and controls
    statusBar.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_top));
    rightStack = new StackWidgetView(view.getContext());
    leftStack = new StackWidgetView(view.getContext());

    // 2. Preparations
    Rect topRectPadding = new Rect();
    view.getResources().getDrawable(R.drawable.box_top).getPadding(topRectPadding);
    // for measurement
    statusBar.addView(backToLocation);
    STATUS_BAR_MARGIN_X = (int) (STATUS_BAR_MARGIN_X * scaleCoefficient);
    statusBar.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    Rect statusBarPadding = new Rect();
    statusBar.getBackground().getPadding(statusBarPadding);
    // 3. put into frame parent layout controls
    FrameLayout parent = (FrameLayout) view.getParent();
    // status bar hides own top part
    int topMargin = statusBar.getMeasuredHeight() - statusBarPadding.top - statusBarPadding.bottom;
    // we want that status bar lays over map stack controls
    topMargin -= topRectPadding.top;

    FrameLayout.LayoutParams flp =
        new FrameLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.RIGHT);
    flp.rightMargin = STATUS_BAR_MARGIN_X;
    flp.topMargin = topMargin;
    rightStack.setLayoutParams(flp);

    flp =
        new FrameLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.CENTER_HORIZONTAL | Gravity.TOP);
    flp.topMargin = (int) (topMargin + scaleCoefficient * 8);
    lanesControl.setLayoutParams(flp);

    flp =
        new FrameLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.LEFT);
    flp.leftMargin = STATUS_BAR_MARGIN_X;
    flp.topMargin = topMargin;
    leftStack.setLayoutParams(flp);

    flp =
        new FrameLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.TOP);
    flp.leftMargin = STATUS_BAR_MARGIN_X;
    flp.rightMargin = STATUS_BAR_MARGIN_X;
    flp.topMargin = -topRectPadding.top;
    statusBar.setLayoutParams(flp);

    flp =
        new FrameLayout.LayoutParams(
            (int) (78 * scaleCoefficient),
            (int) (78 * scaleCoefficient),
            Gravity.RIGHT | Gravity.BOTTOM);
    flp.rightMargin = (int) (10 * scaleCoefficient);
    flp.bottomMargin = (int) (85 * scaleCoefficient);
    alarmControl.setLayoutParams(flp);

    parent.addView(rightStack);
    parent.addView(leftStack);
    parent.addView(statusBar);
    parent.addView(lanesControl);
    parent.addView(alarmControl);
    alarmControl.setVisibility(View.GONE);
    lanesControl.setVisibility(View.GONE);

    // update and create controls
    recreateControls();
  }
Example #20
0
  public void createTopBarElements() {
    // 1. Create view groups and controls
    statusBar = createStatusBar();
    statusBar.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_top));

    lanesControl = createLanesControl();
    lanesControl.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free));

    rightStack = new MapStackControl(view.getContext());
    rightStack.addStackView(createAltitudeControl());
    rightStack.addStackView(createDistanceControl());
    rightStack.addCollapsedView(createSpeedControl());
    rightStack.addCollapsedView(createTimeControl());

    leftStack = new MapStackControl(view.getContext());
    leftStack.addStackView(createNextInfoControl());
    leftStack.addStackView(createMiniMapControl());
    leftStack.addStackView(createNextNextInfoControl());
    //		leftStack.addStackView(createAlarmInfoControl());

    // 2. Preparations
    Rect topRectPadding = new Rect();
    view.getResources().getDrawable(R.drawable.box_top).getPadding(topRectPadding);

    STATUS_BAR_MARGIN_X = (int) (STATUS_BAR_MARGIN_X * scaleCoefficient);
    statusBar.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    Rect statusBarPadding = new Rect();
    statusBar.getBackground().getPadding(statusBarPadding);
    // 3. put into frame parent layout controls
    FrameLayout parent = (FrameLayout) view.getParent();
    // status bar hides own top part
    int topMargin = statusBar.getMeasuredHeight() - statusBarPadding.top - statusBarPadding.bottom;
    // we want that status bar lays over map stack controls
    topMargin -= topRectPadding.top;

    FrameLayout.LayoutParams flp =
        new FrameLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.RIGHT);
    flp.rightMargin = STATUS_BAR_MARGIN_X;
    flp.topMargin = topMargin;
    rightStack.setLayoutParams(flp);

    flp =
        new FrameLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.CENTER_HORIZONTAL | Gravity.TOP);
    flp.topMargin = (int) (topMargin + scaleCoefficient * 8);
    lanesControl.setLayoutParams(flp);

    flp =
        new FrameLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.LEFT);
    flp.leftMargin = STATUS_BAR_MARGIN_X;
    flp.topMargin = topMargin;
    leftStack.setLayoutParams(flp);

    flp =
        new FrameLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.TOP);
    flp.leftMargin = STATUS_BAR_MARGIN_X;
    flp.rightMargin = STATUS_BAR_MARGIN_X;
    flp.topMargin = -topRectPadding.top;
    statusBar.setLayoutParams(flp);

    parent.addView(rightStack);
    parent.addView(leftStack);
    parent.addView(statusBar);
    parent.addView(lanesControl);
  }
  private void updateContentOverlayVisibility(boolean show) {
    if (mView == null) return;

    sCachedCVCList.clear();
    if (mLayoutManager != null) {
      mLayoutManager.getActiveLayout().getAllContentViewCores(sCachedCVCList);
    }
    if (show) {
      if (mView.getParent() != this) {
        // Make sure the view isn't a child of something else before we attempt to add it.
        if (mView.getParent() != null && mView.getParent() instanceof ViewGroup) {
          ((ViewGroup) mView.getParent()).removeView(mView);
        }

        for (int i = 0; i < sCachedCVCList.size(); i++) {
          ContentViewCore content = sCachedCVCList.get(i);
          assert content.isAlive();
          content.getContainerView().setVisibility(View.VISIBLE);
          if (mFullscreenManager != null) {
            mFullscreenManager.updateContentViewViewportSize(content);
          }
        }

        FrameLayout.LayoutParams layoutParams =
            new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        if (mView.getLayoutParams() instanceof MarginLayoutParams) {
          MarginLayoutParams existingLayoutParams = (MarginLayoutParams) mView.getLayoutParams();
          layoutParams.leftMargin = existingLayoutParams.leftMargin;
          layoutParams.rightMargin = existingLayoutParams.rightMargin;
          layoutParams.topMargin = existingLayoutParams.topMargin;
          layoutParams.bottomMargin = existingLayoutParams.bottomMargin;
        }
        addView(mView, layoutParams);

        setFocusable(false);
        setFocusableInTouchMode(false);

        // Claim focus for the new view unless the user is currently using the URL bar.
        if (mUrlBar == null || !mUrlBar.hasFocus()) mView.requestFocus();
      }
    } else {
      if (mView.getParent() == this) {
        setFocusable(true);
        setFocusableInTouchMode(true);

        for (int i = 0; i < sCachedCVCList.size(); i++) {
          ContentViewCore content = sCachedCVCList.get(i);
          if (content.isAlive()) content.getContainerView().setVisibility(View.INVISIBLE);
        }

        if (hasFocus()) {
          InputMethodManager manager =
              (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
          if (manager.isActive(this)) {
            manager.hideSoftInputFromWindow(getWindowToken(), 0, null);
          }
        }
        removeView(mView);
      }
    }
    sCachedCVCList.clear();
  }
  @SuppressWarnings("unchecked")
  @Override
  public View createView(Context context) {
    actionBar.setBackgroundColor(0xff333333);
    actionBar.setItemsBackground(R.drawable.bar_selector_picker);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              if (Build.VERSION.SDK_INT < 11) {
                listView.setAdapter(null);
                listView = null;
                listAdapter = null;
              }
              finishFragment();
            } else if (id == 1) {
              if (delegate != null) {
                finishFragment(false);
                delegate.startPhotoSelectActivity();
              }
            } else if (id == item_photos) {
              if (selectedMode == 0) {
                return;
              }
              selectedMode = 0;
              dropDown.setText(LocaleController.getString("PickerPhotos", R.string.PickerPhotos));
              emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
              listAdapter.notifyDataSetChanged();
            } else if (id == item_video) {
              if (selectedMode == 1) {
                return;
              }
              selectedMode = 1;
              dropDown.setText(LocaleController.getString("PickerVideo", R.string.PickerVideo));
              emptyView.setText(LocaleController.getString("NoVideo", R.string.NoVideo));
              listAdapter.notifyDataSetChanged();
            }
          }
        });

    ActionBarMenu menu = actionBar.createMenu();
    menu.addItem(1, R.drawable.ic_ab_other);

    fragmentView = new FrameLayout(context);

    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(0xff000000);

    if (!singlePhoto) {
      selectedMode = 0;

      dropDownContainer = new ActionBarMenuItem(context, menu, R.drawable.bar_selector_picker);
      dropDownContainer.setSubMenuOpenSide(1);
      dropDownContainer.addSubItem(
          item_photos, LocaleController.getString("PickerPhotos", R.string.PickerPhotos), 0);
      dropDownContainer.addSubItem(
          item_video, LocaleController.getString("PickerVideo", R.string.PickerVideo), 0);
      actionBar.addView(dropDownContainer);
      FrameLayout.LayoutParams layoutParams =
          (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
      layoutParams.height = LayoutHelper.MATCH_PARENT;
      layoutParams.width = LayoutHelper.WRAP_CONTENT;
      layoutParams.rightMargin = AndroidUtilities.dp(40);
      layoutParams.leftMargin =
          AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56);
      layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
      dropDownContainer.setLayoutParams(layoutParams);
      dropDownContainer.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              dropDownContainer.toggleSubMenu();
            }
          });

      dropDown = new TextView(context);
      dropDown.setGravity(Gravity.LEFT);
      dropDown.setSingleLine(true);
      dropDown.setLines(1);
      dropDown.setMaxLines(1);
      dropDown.setEllipsize(TextUtils.TruncateAt.END);
      dropDown.setTextColor(0xffffffff);
      dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
      dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
      dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
      dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
      dropDown.setText(LocaleController.getString("PickerPhotos", R.string.PickerPhotos));
      dropDownContainer.addView(dropDown);
      layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
      layoutParams.width = LayoutHelper.WRAP_CONTENT;
      layoutParams.height = LayoutHelper.WRAP_CONTENT;
      layoutParams.leftMargin = AndroidUtilities.dp(16);
      layoutParams.gravity = Gravity.CENTER_VERTICAL;
      dropDown.setLayoutParams(layoutParams);
    } else {
      actionBar.setTitle(LocaleController.getString("Gallery", R.string.Gallery));
    }

    listView = new ListView(context);
    listView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), AndroidUtilities.dp(4));
    listView.setClipToPadding(false);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    listView.setSelector(new ColorDrawable(0));
    listView.setDividerHeight(0);
    listView.setDivider(null);
    listView.setDrawingCacheEnabled(false);
    listView.setScrollingCacheEnabled(false);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(48);
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);

    emptyView = new TextView(context);
    emptyView.setTextColor(0xff808080);
    emptyView.setTextSize(20);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setVisibility(View.GONE);
    emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
    frameLayout.addView(emptyView);
    layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(48);
    emptyView.setLayoutParams(layoutParams);
    emptyView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.GONE);
    frameLayout.addView(progressView);
    layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(48);
    progressView.setLayoutParams(layoutParams);

    ProgressBar progressBar = new ProgressBar(context);
    progressView.addView(progressBar);
    layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.WRAP_CONTENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.gravity = Gravity.CENTER;
    progressView.setLayoutParams(layoutParams);

    pickerBottomLayout = new PickerBottomLayout(context);
    frameLayout.addView(pickerBottomLayout);
    layoutParams = (FrameLayout.LayoutParams) pickerBottomLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    layoutParams.gravity = Gravity.BOTTOM;
    pickerBottomLayout.setLayoutParams(layoutParams);
    pickerBottomLayout.cancelButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            finishFragment();
          }
        });
    pickerBottomLayout.doneButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            sendSelectedPhotos();
            finishFragment();
          }
        });

    if (loading && (albumsSorted == null || albumsSorted != null && albumsSorted.isEmpty())) {
      progressView.setVisibility(View.VISIBLE);
      listView.setEmptyView(null);
    } else {
      progressView.setVisibility(View.GONE);
      listView.setEmptyView(emptyView);
    }
    pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);

    return fragmentView;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
      Intent intent = getIntent();
      if (intent != null) {
        isTemp = intent.getBooleanExtra("isTemp", false);
      }
    } catch (Exception exception) {
    }
    FrameLayout rootLayout = new FrameLayout(this);
    FrameLayout.LayoutParams layoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    rootLayout.setLayoutParams(layoutParams);
    InputStream inputStream =
        getResources().openRawResource(EUExUtil.getResDrawableID("startup_bg_16_9"));
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    Bitmap bm = BUtility.createBitmapWithStream(inputStream, dm.widthPixels, dm.heightPixels);
    if (bm != null) {
      ImageView imageView = new ImageView(this);
      imageView.setScaleType(ImageView.ScaleType.FIT_XY);
      imageView.setImageBitmap(bm);
      rootLayout.addView(imageView);
    }
    setContentView(rootLayout);

    mHandler.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            if (!isTemp) {
              try {
                Intent intent = new Intent(LoadingActivity.this, EBrowserActivity.class);
                Bundle bundle = getIntent().getExtras();
                if (null != bundle) {
                  intent.putExtras(bundle);
                }
                startActivity(intent);
                overridePendingTransition(
                    EUExUtil.getResAnimID("platform_myspace_no_anim"),
                    EUExUtil.getResAnimID("platform_myspace_no_anim"));
              } catch (Exception e) {
              }
            }
          }
        },
        700);

    mBroadcastReceiver = new MyBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BROADCAST_ACTION);
    LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
    if (EBrowserActivity.develop) {
      TextView worn = new TextView(this);
      worn.setText(EUExUtil.getString("platform_only_test"));
      worn.setTextColor(0xffff0000);
      worn.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
      FrameLayout.LayoutParams wornPa = new FrameLayout.LayoutParams(Compat.FILL, Compat.WRAP);
      wornPa.gravity = Gravity.TOP;
      wornPa.leftMargin = 10;
      wornPa.topMargin = 10;
      worn.setLayoutParams(wornPa);
      rootLayout.addView(worn);
    }
    try {
      getWindow()
          .clearFlags(
              WindowManager.LayoutParams.class.getField("FLAG_NEEDS_MENU_KEY").getInt(null));
    } catch (Exception e) {
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    classGuid = ConnectionsManager.getInstance().generateClassGuid();
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.pushMessagesUpdated);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    typingDotsDrawable = new TypingDotsDrawable();
    recordStatusDrawable = new RecordStatusDrawable();

    SizeNotifierFrameLayout contentView =
        new SizeNotifierFrameLayout(this) {
          @Override
          protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthMode = MeasureSpec.getMode(widthMeasureSpec);
            int heightMode = MeasureSpec.getMode(heightMeasureSpec);
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);

            setMeasuredDimension(widthSize, heightSize);

            int keyboardSize = getKeyboardHeight();

            if (keyboardSize <= AndroidUtilities.dp(20)) {
              heightSize -= chatActivityEnterView.getEmojiPadding();
            }

            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
              View child = getChildAt(i);
              if (child.getVisibility() == GONE) {
                continue;
              }
              if (chatActivityEnterView.isPopupView(child)) {
                child.measure(
                    MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(
                        child.getLayoutParams().height, MeasureSpec.EXACTLY));
              } else {
                child.measure(
                    MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(
                        Math.max(AndroidUtilities.dp(10), heightSize + AndroidUtilities.dp(2)),
                        MeasureSpec.EXACTLY));
              }
            }
          }

          @Override
          protected void onLayout(boolean changed, int l, int t, int r, int b) {
            final int count = getChildCount();

            int paddingBottom =
                getKeyboardHeight() <= AndroidUtilities.dp(20)
                    ? chatActivityEnterView.getEmojiPadding()
                    : 0;

            for (int i = 0; i < count; i++) {
              final View child = getChildAt(i);
              if (child.getVisibility() == GONE) {
                continue;
              }
              final LayoutParams lp = (LayoutParams) child.getLayoutParams();

              int width = child.getMeasuredWidth();
              int height = child.getMeasuredHeight();

              int childLeft;
              int childTop;

              int gravity = lp.gravity;
              if (gravity == -1) {
                gravity = Gravity.TOP | Gravity.LEFT;
              }

              final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
              final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

              switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.CENTER_HORIZONTAL:
                  childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
                  break;
                case Gravity.RIGHT:
                  childLeft = r - width - lp.rightMargin;
                  break;
                case Gravity.LEFT:
                default:
                  childLeft = lp.leftMargin;
              }

              switch (verticalGravity) {
                case Gravity.TOP:
                  childTop = lp.topMargin;
                  break;
                case Gravity.CENTER_VERTICAL:
                  childTop =
                      ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
                  break;
                case Gravity.BOTTOM:
                  childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
                  break;
                default:
                  childTop = lp.topMargin;
              }
              if (chatActivityEnterView.isPopupView(child)) {
                childTop =
                    paddingBottom != 0 ? getMeasuredHeight() - paddingBottom : getMeasuredHeight();
              }
              child.layout(childLeft, childTop, childLeft + width, childTop + height);
            }

            notifyHeightChanged();
          }
        };
    setContentView(contentView);
    contentView.setBackgroundColor(0x99000000);

    RelativeLayout relativeLayout = new RelativeLayout(this);
    contentView.addView(
        relativeLayout,
        LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    RelativeLayout popupContainer = new RelativeLayout(this);
    popupContainer.setBackgroundColor(0xffffffff);
    relativeLayout.addView(
        popupContainer,
        LayoutHelper.createRelative(
            LayoutHelper.MATCH_PARENT, 240, 12, 0, 12, 0, RelativeLayout.CENTER_IN_PARENT));

    if (chatActivityEnterView != null) {
      chatActivityEnterView.onDestroy();
    }
    chatActivityEnterView = new ChatActivityEnterView(this, contentView, null, false);
    popupContainer.addView(
        chatActivityEnterView,
        LayoutHelper.createRelative(
            LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT,
            RelativeLayout.ALIGN_PARENT_BOTTOM));
    chatActivityEnterView.setDelegate(
        new ChatActivityEnterView.ChatActivityEnterViewDelegate() {
          @Override
          public void onMessageSend(String message) {
            if (currentMessageObject == null) {
              return;
            }
            if (currentMessageNum >= 0
                && currentMessageNum < NotificationsController.getInstance().popupMessages.size()) {
              NotificationsController.getInstance().popupMessages.remove(currentMessageNum);
            }
            MessagesController.getInstance()
                .markDialogAsRead(
                    currentMessageObject.getDialogId(),
                    currentMessageObject.getId(),
                    Math.max(0, currentMessageObject.getId()),
                    0,
                    currentMessageObject.messageOwner.date,
                    true,
                    true);
            currentMessageObject = null;
            getNewMessage();
          }

          @Override
          public void onTextChanged(CharSequence text, boolean big) {}

          @Override
          public void needSendTyping() {
            if (currentMessageObject != null) {
              MessagesController.getInstance()
                  .sendTyping(currentMessageObject.getDialogId(), 0, classGuid);
            }
          }

          @Override
          public void onAttachButtonHidden() {}

          @Override
          public void onAttachButtonShow() {}

          @Override
          public void onWindowSizeChanged(int size) {}
        });

    messageContainer = new FrameLayoutTouch(this);
    popupContainer.addView(messageContainer, 0);

    actionBar = new ActionBar(this);
    actionBar.setOccupyStatusBar(false);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setBackgroundColor(0xff54759e);
    actionBar.setItemsBackground(R.drawable.bar_selector);
    popupContainer.addView(actionBar);
    ViewGroup.LayoutParams layoutParams = actionBar.getLayoutParams();
    layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    actionBar.setLayoutParams(layoutParams);

    ActionBarMenu menu = actionBar.createMenu();
    View view = menu.addItemResource(2, R.layout.popup_count_layout);
    countText = (TextView) view.findViewById(R.id.count_text);

    avatarContainer = new FrameLayoutFixed(this);
    avatarContainer.setBackgroundResource(R.drawable.bar_selector);
    avatarContainer.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
    actionBar.addView(avatarContainer);
    FrameLayout.LayoutParams layoutParams2 =
        (FrameLayout.LayoutParams) avatarContainer.getLayoutParams();
    layoutParams2.height = LayoutHelper.MATCH_PARENT;
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.rightMargin = AndroidUtilities.dp(48);
    layoutParams2.leftMargin = AndroidUtilities.dp(60);
    layoutParams2.gravity = Gravity.TOP | Gravity.LEFT;
    avatarContainer.setLayoutParams(layoutParams2);

    avatarImageView = new BackupImageView(this);
    avatarImageView.setRoundRadius(AndroidUtilities.dp(21));
    avatarContainer.addView(avatarImageView);
    layoutParams2 = (FrameLayout.LayoutParams) avatarImageView.getLayoutParams();
    layoutParams2.width = AndroidUtilities.dp(42);
    layoutParams2.height = AndroidUtilities.dp(42);
    layoutParams2.topMargin = AndroidUtilities.dp(3);
    avatarImageView.setLayoutParams(layoutParams2);

    nameTextView = new TextView(this);
    nameTextView.setTextColor(0xffffffff);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    nameTextView.setLines(1);
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setGravity(Gravity.LEFT);
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    avatarContainer.addView(nameTextView);
    layoutParams2 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.leftMargin = AndroidUtilities.dp(54);
    layoutParams2.bottomMargin = AndroidUtilities.dp(22);
    layoutParams2.gravity = Gravity.BOTTOM;
    nameTextView.setLayoutParams(layoutParams2);

    onlineTextView = new TextView(this);
    onlineTextView.setTextColor(0xffd7e8f7);
    onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    onlineTextView.setLines(1);
    onlineTextView.setMaxLines(1);
    onlineTextView.setSingleLine(true);
    onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
    onlineTextView.setGravity(Gravity.LEFT);
    avatarContainer.addView(onlineTextView);
    layoutParams2 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.leftMargin = AndroidUtilities.dp(54);
    layoutParams2.bottomMargin = AndroidUtilities.dp(4);
    layoutParams2.gravity = Gravity.BOTTOM;
    onlineTextView.setLayoutParams(layoutParams2);

    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              onFinish();
              finish();
            } else if (id == 1) {
              openCurrentMessage();
            } else if (id == 2) {
              switchToNextMessage();
            }
          }
        });

    PowerManager pm =
        (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
    wakeLock =
        pm.newWakeLock(
            PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "screen");
    wakeLock.setReferenceCounted(false);

    handleIntent(getIntent());
  }
  private ViewGroup getViewForMessage(int num, boolean applyOffset) {
    if (NotificationsController.getInstance().popupMessages.size() == 1
        && (num < 0 || num >= NotificationsController.getInstance().popupMessages.size())) {
      return null;
    }
    if (num == -1) {
      num = NotificationsController.getInstance().popupMessages.size() - 1;
    } else if (num == NotificationsController.getInstance().popupMessages.size()) {
      num = 0;
    }
    ViewGroup view;
    MessageObject messageObject = NotificationsController.getInstance().popupMessages.get(num);
    if (messageObject.type == 1 || messageObject.type == 4) {
      if (imageViews.size() > 0) {
        view = imageViews.get(0);
        imageViews.remove(0);
      } else {
        view = new FrameLayoutAnimationListener(this);
        view.addView(getLayoutInflater().inflate(R.layout.popup_image_layout, null));
        view.setTag(2);

        view.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                openCurrentMessage();
              }
            });
      }

      TextView messageText = (TextView) view.findViewById(R.id.message_text);
      BackupImageView imageView = (BackupImageView) view.findViewById(R.id.message_image);
      imageView.setAspectFit(true);

      if (messageObject.type == 1) {
        TLRPC.PhotoSize currentPhotoObject =
            FileLoader.getClosestPhotoSizeWithSize(
                messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
        TLRPC.PhotoSize thumb =
            FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
        boolean photoSet = false;
        if (currentPhotoObject != null) {
          boolean photoExist = true;
          if (messageObject.type == 1) {
            File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
            if (!cacheFile.exists()) {
              photoExist = false;
            }
          }
          if (photoExist
              || MediaController.getInstance()
                  .canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
            imageView.setImage(
                currentPhotoObject.location, "100_100", thumb.location, currentPhotoObject.size);
            photoSet = true;
          } else {
            if (thumb != null) {
              imageView.setImage(thumb.location, null, (Drawable) null);
              photoSet = true;
            }
          }
        }
        if (!photoSet) {
          imageView.setVisibility(View.GONE);
          messageText.setVisibility(View.VISIBLE);
          messageText.setTextSize(
              TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize);
          messageText.setText(messageObject.messageText);
        } else {
          imageView.setVisibility(View.VISIBLE);
          messageText.setVisibility(View.GONE);
        }
      } else if (messageObject.type == 4) {
        messageText.setVisibility(View.GONE);
        messageText.setText(messageObject.messageText);
        imageView.setVisibility(View.VISIBLE);
        double lat = messageObject.messageOwner.media.geo.lat;
        double lon = messageObject.messageOwner.media.geo._long;
        String currentUrl =
            String.format(
                Locale.US,
                "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false",
                lat,
                lon,
                Math.min(2, (int) Math.ceil(AndroidUtilities.density)),
                lat,
                lon);
        imageView.setImage(currentUrl, null, null);
      }
    } else if (messageObject.type == 2) {
      PopupAudioView cell;
      if (audioViews.size() > 0) {
        view = audioViews.get(0);
        audioViews.remove(0);
        cell = (PopupAudioView) view.findViewWithTag(300);
      } else {
        view = new FrameLayoutAnimationListener(this);
        view.addView(getLayoutInflater().inflate(R.layout.popup_audio_layout, null));
        view.setTag(3);

        view.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                openCurrentMessage();
              }
            });

        ViewGroup audioContainer = (ViewGroup) view.findViewById(R.id.audio_container);
        cell = new PopupAudioView(this);
        cell.setTag(300);
        audioContainer.addView(cell);
      }

      cell.setMessageObject(messageObject);
      if (MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_AUDIO)) {
        cell.downloadAudioIfNeed();
      }
    } else {
      if (textViews.size() > 0) {
        view = textViews.get(0);
        textViews.remove(0);
      } else {
        view = new FrameLayoutAnimationListener(this);
        view.addView(getLayoutInflater().inflate(R.layout.popup_text_layout, null));
        view.setTag(1);

        View textContainer = view.findViewById(R.id.text_container);
        textContainer.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                openCurrentMessage();
              }
            });
      }
      TextView messageText = (TextView) view.findViewById(R.id.message_text);
      messageText.setTag(301);
      messageText.setTextSize(
          TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize);
      messageText.setText(messageObject.messageText);
    }
    if (view.getParent() == null) {
      messageContainer.addView(view);
    }
    view.setVisibility(View.VISIBLE);

    if (applyOffset) {
      int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
      FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
      layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
      layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
      layoutParams.width = widht;
      if (num == currentMessageNum) {
        layoutParams.leftMargin = 0;
      } else if (num == currentMessageNum - 1) {
        layoutParams.leftMargin = -widht;
      } else if (num == currentMessageNum + 1) {
        layoutParams.leftMargin = widht;
      }
      view.setLayoutParams(layoutParams);
      view.invalidate();
    }

    return view;
  }
  @Override
  public View createView(LayoutInflater inflater) {
    if (fragmentView == null) {
      searching = false;
      searchWas = false;

      actionBar.setBackButtonImage(R.drawable.ic_ab_back);
      actionBar.setAllowOverlayTitle(true);
      if (isAlwaysShare) {
        actionBar.setTitle(
            LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
      } else if (isNeverShare) {
        actionBar.setTitle(
            LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
      } else {
        actionBar.setTitle(
            isBroadcast
                ? LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList)
                : LocaleController.getString("NewGroup", R.string.NewGroup));
        actionBar.setSubtitle(
            LocaleController.formatString(
                "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
      }

      actionBar.setActionBarMenuOnItemClick(
          new ActionBar.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
              if (id == -1) {
                finishFragment();
              } else if (id == done_button) {
                if (selectedContacts.isEmpty()) {
                  return;
                }
                ArrayList<Integer> result = new ArrayList<>();
                result.addAll(selectedContacts.keySet());
                if (isAlwaysShare || isNeverShare) {
                  if (delegate != null) {
                    delegate.didSelectUsers(result);
                  }
                  finishFragment();
                } else {
                  Bundle args = new Bundle();
                  args.putIntegerArrayList("result", result);
                  args.putBoolean("broadcast", isBroadcast);
                  presentFragment(new GroupCreateFinalActivity(args));
                }
              }
            }
          });
      ActionBarMenu menu = actionBar.createMenu();
      menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

      searchListViewAdapter = new ContactsSearchAdapter(getParentActivity(), null, false);
      searchListViewAdapter.setCheckedMap(selectedContacts);
      searchListViewAdapter.setUseUserCell(true);
      listViewAdapter = new ContactsAdapter(getParentActivity(), true, false, null);
      listViewAdapter.setCheckedMap(selectedContacts);

      fragmentView = new LinearLayout(getParentActivity());
      LinearLayout linearLayout = (LinearLayout) fragmentView;
      linearLayout.setOrientation(LinearLayout.VERTICAL);

      FrameLayout frameLayout = new FrameLayout(getParentActivity());
      linearLayout.addView(frameLayout);
      LinearLayout.LayoutParams layoutParams =
          (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
      layoutParams.gravity = Gravity.TOP;
      frameLayout.setLayoutParams(layoutParams);

      userSelectEditText = new EditText(getParentActivity());
      userSelectEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      userSelectEditText.setHintTextColor(0xff979797);
      userSelectEditText.setTextColor(0xff212121);
      userSelectEditText.setInputType(
          InputType.TYPE_TEXT_VARIATION_FILTER
              | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
              | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
      userSelectEditText.setMinimumHeight(AndroidUtilities.dp(54));
      userSelectEditText.setSingleLine(false);
      userSelectEditText.setLines(2);
      userSelectEditText.setMaxLines(2);
      userSelectEditText.setVerticalScrollBarEnabled(true);
      userSelectEditText.setHorizontalScrollBarEnabled(false);
      userSelectEditText.setPadding(0, 0, 0, 0);
      userSelectEditText.setImeOptions(
          EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
      userSelectEditText.setGravity(
          (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
      AndroidUtilities.clearCursorDrawable(userSelectEditText);
      frameLayout.addView(userSelectEditText);
      FrameLayout.LayoutParams layoutParams1 =
          (FrameLayout.LayoutParams) userSelectEditText.getLayoutParams();
      layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
      layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
      layoutParams1.leftMargin = AndroidUtilities.dp(10);
      layoutParams1.rightMargin = AndroidUtilities.dp(10);
      layoutParams1.gravity = Gravity.TOP;
      userSelectEditText.setLayoutParams(layoutParams1);

      if (isAlwaysShare) {
        userSelectEditText.setHint(
            LocaleController.getString(
                "AlwaysShareWithPlaceholder", R.string.AlwaysShareWithPlaceholder));
      } else if (isNeverShare) {
        userSelectEditText.setHint(
            LocaleController.getString(
                "NeverShareWithPlaceholder", R.string.NeverShareWithPlaceholder));
      } else {
        userSelectEditText.setHint(
            LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
      }
      if (Build.VERSION.SDK_INT >= 11) {
        userSelectEditText.setTextIsSelectable(false);
      }
      userSelectEditText.addTextChangedListener(
          new TextWatcher() {
            @Override
            public void beforeTextChanged(
                CharSequence charSequence, int start, int count, int after) {
              if (!ignoreChange) {
                beforeChangeIndex = userSelectEditText.getSelectionStart();
                changeString = new SpannableString(charSequence);
              }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

            @Override
            public void afterTextChanged(Editable editable) {
              if (!ignoreChange) {
                boolean search = false;
                int afterChangeIndex = userSelectEditText.getSelectionEnd();
                if (editable.toString().length() < changeString.toString().length()) {
                  String deletedString = "";
                  try {
                    deletedString =
                        changeString.toString().substring(afterChangeIndex, beforeChangeIndex);
                  } catch (Exception e) {
                    FileLog.e("tmessages", e);
                  }
                  if (deletedString.length() > 0) {
                    if (searching && searchWas) {
                      search = true;
                    }
                    Spannable span = userSelectEditText.getText();
                    for (int a = 0; a < allSpans.size(); a++) {
                      XImageSpan sp = allSpans.get(a);
                      if (span.getSpanStart(sp) == -1) {
                        allSpans.remove(sp);
                        selectedContacts.remove(sp.uid);
                      }
                    }
                    if (!isAlwaysShare && !isNeverShare) {
                      actionBar.setSubtitle(
                          LocaleController.formatString(
                              "MembersCount",
                              R.string.MembersCount,
                              selectedContacts.size(),
                              maxCount));
                    }
                    listView.invalidateViews();
                  } else {
                    search = true;
                  }
                } else {
                  search = true;
                }
                if (search) {
                  String text = userSelectEditText.getText().toString().replace("<", "");
                  if (text.length() != 0) {
                    searching = true;
                    searchWas = true;
                    if (listView != null) {
                      listView.setAdapter(searchListViewAdapter);
                      searchListViewAdapter.notifyDataSetChanged();
                      if (android.os.Build.VERSION.SDK_INT >= 11) {
                        listView.setFastScrollAlwaysVisible(false);
                      }
                      listView.setFastScrollEnabled(false);
                      listView.setVerticalScrollBarEnabled(true);
                    }
                    if (emptyTextView != null) {
                      emptyTextView.setText(
                          LocaleController.getString("NoResult", R.string.NoResult));
                    }
                    searchListViewAdapter.searchDialogs(text);
                  } else {
                    searchListViewAdapter.searchDialogs(null);
                    searching = false;
                    searchWas = false;
                    listView.setAdapter(listViewAdapter);
                    listViewAdapter.notifyDataSetChanged();
                    if (android.os.Build.VERSION.SDK_INT >= 11) {
                      listView.setFastScrollAlwaysVisible(true);
                    }
                    listView.setFastScrollEnabled(true);
                    listView.setVerticalScrollBarEnabled(false);
                    emptyTextView.setText(
                        LocaleController.getString("NoContacts", R.string.NoContacts));
                  }
                }
              }
            }
          });

      LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
      emptyTextLayout.setVisibility(View.INVISIBLE);
      emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
      linearLayout.addView(emptyTextLayout);
      layoutParams = (LinearLayout.LayoutParams) emptyTextLayout.getLayoutParams();
      layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
      emptyTextLayout.setLayoutParams(layoutParams);
      emptyTextLayout.setOnTouchListener(
          new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
              return true;
            }
          });

      emptyTextView = new TextView(getParentActivity());
      emptyTextView.setTextColor(0xff808080);
      emptyTextView.setTextSize(20);
      emptyTextView.setGravity(Gravity.CENTER);
      emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
      emptyTextLayout.addView(emptyTextView);
      layoutParams = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.weight = 0.5f;
      emptyTextView.setLayoutParams(layoutParams);

      FrameLayout frameLayout2 = new FrameLayout(getParentActivity());
      emptyTextLayout.addView(frameLayout2);
      layoutParams = (LinearLayout.LayoutParams) frameLayout2.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.weight = 0.5f;
      frameLayout2.setLayoutParams(layoutParams);

      listView = new LetterSectionsListView(getParentActivity());
      listView.setEmptyView(emptyTextLayout);
      listView.setVerticalScrollBarEnabled(false);
      listView.setDivider(null);
      listView.setDividerHeight(0);
      listView.setFastScrollEnabled(true);
      listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
      listView.setAdapter(listViewAdapter);
      if (Build.VERSION.SDK_INT >= 11) {
        listView.setFastScrollAlwaysVisible(true);
        listView.setVerticalScrollbarPosition(
            LocaleController.isRTL
                ? ListView.SCROLLBAR_POSITION_LEFT
                : ListView.SCROLLBAR_POSITION_RIGHT);
      }
      linearLayout.addView(listView);
      layoutParams = (LinearLayout.LayoutParams) listView.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
      listView.setLayoutParams(layoutParams);
      listView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
              TLRPC.User user = null;
              if (searching && searchWas) {
                user = searchListViewAdapter.getItem(i);
              } else {
                int section = listViewAdapter.getSectionForPosition(i);
                int row = listViewAdapter.getPositionInSectionForPosition(i);
                if (row < 0 || section < 0) {
                  return;
                }
                user = (TLRPC.User) listViewAdapter.getItem(section, row);
              }
              if (user == null) {
                return;
              }

              boolean check = true;
              if (selectedContacts.containsKey(user.id)) {
                check = false;
                try {
                  XImageSpan span = selectedContacts.get(user.id);
                  selectedContacts.remove(user.id);
                  SpannableStringBuilder text =
                      new SpannableStringBuilder(userSelectEditText.getText());
                  text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                  allSpans.remove(span);
                  ignoreChange = true;
                  userSelectEditText.setText(text);
                  userSelectEditText.setSelection(text.length());
                  ignoreChange = false;
                } catch (Exception e) {
                  FileLog.e("tmessages", e);
                }
              } else {
                if (selectedContacts.size() == maxCount) {
                  return;
                }
                ignoreChange = true;
                XImageSpan span = createAndPutChipForUser(user);
                span.uid = user.id;
                ignoreChange = false;
              }
              if (!isAlwaysShare && !isNeverShare) {
                actionBar.setSubtitle(
                    LocaleController.formatString(
                        "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
              }
              if (searching || searchWas) {
                ignoreChange = true;
                SpannableStringBuilder ssb = new SpannableStringBuilder("");
                for (ImageSpan sp : allSpans) {
                  ssb.append("<<");
                  ssb.setSpan(
                      sp,
                      ssb.length() - 2,
                      ssb.length(),
                      SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                userSelectEditText.setText(ssb);
                userSelectEditText.setSelection(ssb.length());
                ignoreChange = false;

                searchListViewAdapter.searchDialogs(null);
                searching = false;
                searchWas = false;
                listView.setAdapter(listViewAdapter);
                listViewAdapter.notifyDataSetChanged();
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                  listView.setFastScrollAlwaysVisible(true);
                }
                listView.setFastScrollEnabled(true);
                listView.setVerticalScrollBarEnabled(false);
                emptyTextView.setText(
                    LocaleController.getString("NoContacts", R.string.NoContacts));
              } else {
                if (view instanceof UserCell) {
                  ((UserCell) view).setChecked(check, true);
                }
              }
            }
          });
      listView.setOnScrollListener(
          new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
              if (i == SCROLL_STATE_TOUCH_SCROLL) {
                AndroidUtilities.hideKeyboard(userSelectEditText);
              }
              if (listViewAdapter != null) {
                listViewAdapter.setIsScrolling(i != SCROLL_STATE_IDLE);
              }
            }

            @Override
            public void onScroll(
                AbsListView absListView,
                int firstVisibleItem,
                int visibleItemCount,
                int totalItemCount) {
              if (absListView.isFastScrollEnabled()) {
                AndroidUtilities.clearDrawableAnimation(absListView);
              }
            }
          });
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }