public static void manageAds(Activity activity) {
    final PackageManager pm = activity.getPackageManager();
    // get a list of installed apps.
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    boolean yboTvProFound = false;

    for (ApplicationInfo info : packages) {
      if (PACKAGE_PRO.equals(info.packageName)) {
        yboTvProFound = true;
        break;
      }
    }

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView) activity.findViewById(R.id.adView);
    if (yboTvProFound) {
      View layout = activity.findViewById(R.id.ad_container);
      FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) layout.getLayoutParams();
      layoutParams.bottomMargin = 0;
      layout.setLayoutParams(layoutParams);
      adView.setVisibility(View.GONE);
    } else {
      adView.loadAd(new AdRequest.Builder().build());
    }
  }
  @Override
  protected void onCreateSubMenuPanel(CMenuItem moreItem) {

    if (mMenuPanel != null && mMenuPanel.isShowing()) {
      if (moreItem.hasSubMenu()) {
        updateMenuItem(moreItem);
      } else {
        mMenuPanel.dismiss();
      }
      return;
    }

    if (moreItem == null || !moreItem.hasSubMenu()) {
      return;
    }

    if (mMenuPanel == null) {
      mMenuPanelLayout = new SubMenuPanelLayout(getContext());
      mMenuPanelLayout.setBackgroundColor(Color.BLUE);

      FrameLayout.LayoutParams p =
          new FrameLayout.LayoutParams(
              FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
      p.gravity = Gravity.BOTTOM;
      p.bottomMargin = getBottom() - getTop();
      FrameLayout container = new FrameLayout(getContext());
      container.addView(mMenuPanelLayout, p);

      mMenuPanel = new PopupWindow(container, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      // mMenuPanel.setOutsideTouchable(true);
      mMenuPanel.setTouchable(true);
      mMenuPanel.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
      mMenuPanel.setTouchInterceptor(
          new OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {

              final int menuPanelTop = mMenuPanelLayout.getTop();
              final Rect r = new Rect();
              mMenuPanelLayout.getDrawingRect(r);
              final Rect menuPanelRect =
                  new Rect(
                      r.left, r.top + menuPanelTop,
                      r.right, r.bottom + menuPanelTop);
              if (!menuPanelRect.contains((int) motionEvent.getX(), (int) motionEvent.getY())) {
                if (mMenuPanel != null && mMenuPanel.isShowing()) {
                  mMenuPanel.dismiss();
                }
              }

              return false;
            }
          });
    }

    if (!mMenuPanel.isShowing()) {
      updateMenuItem(moreItem);
      mMenuPanel.showAtLocation(this, Gravity.BOTTOM | Gravity.LEFT, 0, 0);
    }
  }
Exemple #3
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);
 }
  /**
   * Constructs a new Op09CarrierText instance with Context.
   *
   * @param context A Context object.
   */
  public Op09CarrierText(Context context) {
    this.mContext = context;

    mNumOfSub = SIMHelper.getSlotCount();

    final Resources res = mContext.getResources();

    mNetworkNameDefault = res.getString(R.string.lockscreen_carrier_default);
    mSimMissingDefault = res.getString(R.string.lockscreen_missing_sim_message_short);

    mCarrierLabelHeight = res.getDimensionPixelSize(R.dimen.carrier_label_height);
    mCloseHandleHeight = res.getDimensionPixelSize(R.dimen.close_handle_height);
    final FrameLayout.LayoutParams params =
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, mCarrierLabelHeight, Gravity.BOTTOM);
    params.bottomMargin = mCloseHandleHeight;

    mCarrierLayout = (LinearLayout) View.inflate(mContext, R.layout.sys_carrier_label, null);
    mCarrierLayout.setLayoutParams(params);

    // the carrier and carrier divider number is defined in layout: carrier_label.xml
    mCarrierView = new TextView[MAX_CARRIER_TEXT_NUM];
    mCarrierDivider = new TextView[MAX_CARRIER_TEXT_NUM - 1];

    mCarrierView[0] = (TextView) mCarrierLayout.findViewById(R.id.carrier_1);
    mCarrierView[1] = (TextView) mCarrierLayout.findViewById(R.id.carrier_2);
    mCarrierView[2] = (TextView) mCarrierLayout.findViewById(R.id.carrier_3);
    mCarrierView[3] = (TextView) mCarrierLayout.findViewById(R.id.carrier_4);
    mCarrierDivider[0] = (TextView) mCarrierLayout.findViewById(R.id.carrier_divider_1);
    mCarrierDivider[1] = (TextView) mCarrierLayout.findViewById(R.id.carrier_divider_2);
    mCarrierDivider[2] = (TextView) mCarrierLayout.findViewById(R.id.carrier_divider_3);

    for (int i = 0; i < mNumOfSub; i++) {
      mCarrierView[i].setText(mNetworkNameDefault);
      if (i < mNumOfSub - 1) {
        mCarrierDivider[i].setText("|");
      }
    }

    if (mNumOfSub == 2) {
      mCarrierView[0].setGravity(Gravity.END);
      mCarrierView[1].setGravity(Gravity.START);
    }

    if (DEBUG) {
      Log.d(
          TAG,
          "Op09CarrierText, mNumOfSub="
              + mNumOfSub
              + " , mNetworkNameDefault="
              + mNetworkNameDefault
              + " , mSimMissingDefault="
              + mSimMissingDefault);
    }
  }
 /** 初始化加载view准备,_doUIModule是对应当前UIView的model实例 */
 @Override
 public void loadView(DoUIModule _doUIModule) throws Exception {
   this.model = (do_ProgressBar2_MAbstract) _doUIModule;
   FrameLayout.LayoutParams fParams =
       new FrameLayout.LayoutParams(
           FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
   circleProgressView = new CircleProgressView(mContext);
   fParams.gravity = Gravity.CENTER_HORIZONTAL;
   fParams.topMargin = 0;
   fParams.bottomMargin = 0;
   circleProgressView.setLayoutParams(fParams);
   this.addView(circleProgressView);
 }
 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);
 }
  public void setVideoFullSize() {
    if (normalHeight == 0) return;
    FrameLayout.LayoutParams lp =
        (FrameLayout.LayoutParams)
            (nativeMode ? mVideoView.getLayoutParams() : mSurfaceView.getLayoutParams());
    lp.height = normalHeight;
    lp.width = normalWidth;
    if (nativeMode) {
      lp.rightMargin = 0;
      lp.bottomMargin = 0;
      mVideoView.setLayoutParams(lp);
      mVideoView.invalidate();
    } else mSurfaceView.setLayoutParams(lp);

    isContracted = false;
  }
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    adsMogoLayoutCode = new AdsMogoLayout(this, "2bad837a65c040f0aee41cf992b26b21");
    FrameLayout.LayoutParams params =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    // 设置广告出现的位置(悬浮于底部)
    params.bottomMargin = 0;
    // adsMogoLayoutCode.setGListener(this);
    params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;

    params.topMargin = 40;
    addContentView(adsMogoLayoutCode, params);

    this.VP();
    this.JP();
  }
  /** Toggle the Logs View visibility with a nice animation. */
  public void toggleLogsView(boolean showView) {
    final View logsView = findViewById(R.id.logs_layout);
    final View bodyView = findViewById(R.id.container);
    final FrameLayout.LayoutParams logsLayoutParams =
        (FrameLayout.LayoutParams) logsView.getLayoutParams();
    final int startLogsY, endLogsY, startBodyY, endBodyY;

    if (showView) {
      // The logsView height set in XML is a placeholder, we need to compute at runtime
      // how much is 0.4 of the screen height.
      int height = (int) (0.4 * mDrawerLayout.getHeight());

      // The LogsView is hidden being placed off-screen with a negative bottomMargin.
      // We need to update its height and bottomMargin to the correct runtime values.
      logsLayoutParams.bottomMargin = -logsLayoutParams.height;
      logsView.setLayoutParams(logsLayoutParams);
      logsLayoutParams.height = height;

      // Prepare the value for the Show animation.
      startLogsY = logsLayoutParams.bottomMargin;
      endLogsY = 0;
      startBodyY = 0;
      endBodyY = logsLayoutParams.height;
    } else {
      // Prepare the value for the Hide animation.
      startLogsY = 0;
      endLogsY = -logsLayoutParams.height;
      startBodyY = logsLayoutParams.height;
      endBodyY = 0;
    }
    final int deltaLogsY = endLogsY - startLogsY;
    final int deltaBodyY = endBodyY - startBodyY;
    Animation a =
        new Animation() {
          @Override
          protected void applyTransformation(float interpolatedTime, Transformation t) {
            logsLayoutParams.bottomMargin = (int) (startLogsY + deltaLogsY * interpolatedTime);
            logsView.setLayoutParams(logsLayoutParams);
            bodyView.setPadding(0, 0, 0, (int) (startBodyY + deltaBodyY * interpolatedTime));
          }
        };
    a.setDuration(500);
    logsView.startAnimation(a);
  }
  @Override
  public Object instantiateItem(ViewGroup container, int position) {

    View ret = null;
    Integer resId = images.get(position);
    if (position == images.size() - 1) {

      FrameLayout frameLayout = new FrameLayout(context);
      ImageView imageView = new ImageView(context);
      imageView.setImageResource(resId);
      ViewGroup.LayoutParams lp1 =
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
      imageView.setLayoutParams(lp1);
      frameLayout.addView(imageView);

      Button btnGo = new Button(context);
      btnGo.setText(R.string.guide_start_main);
      FrameLayout.LayoutParams lp2 =
          new FrameLayout.LayoutParams(
              ViewGroup.LayoutParams.WRAP_CONTENT,
              ViewGroup.LayoutParams.WRAP_CONTENT,
              // ָ��button��λ��
              Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);

      lp2.bottomMargin = 80;

      btnGo.setLayoutParams(lp2);
      btnGo.setOnClickListener(goOnClickListener);
      frameLayout.addView(btnGo);
      // ���봴����button��û��ID�ģ�ͨ��tag���Խ��а�ť������
      btnGo.setTag("GO");
      ret = frameLayout;
    } else {

      ImageView imageView = new ImageView(context);
      imageView.setImageResource(resId);
      ret = imageView;
    }
    container.addView(ret);

    return ret;
  }
  public void contractVideo(int height) {
    FrameLayout.LayoutParams lp =
        (FrameLayout.LayoutParams)
            (nativeMode ? mVideoView.getLayoutParams() : mSurfaceView.getLayoutParams());
    if (isContracted) return;

    Activity activity = TvApp.getApplication().getCurrentActivity();
    int sw = activity.getWindow().getDecorView().getWidth();
    int sh = activity.getWindow().getDecorView().getHeight();
    float ar = (float) sw / sh;
    lp.height = height;
    lp.width = (int) Math.ceil(height * ar);
    lp.rightMargin = ((lp.width - normalWidth) / 2) - 110;
    lp.bottomMargin = ((lp.height - normalHeight) / 2) - 50;

    if (nativeMode) {
      mVideoView.setLayoutParams(lp);
      mVideoView.invalidate();
    } else mSurfaceView.setLayoutParams(lp);

    isContracted = true;
  }
  @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);
    if (selectedAlbum != null) {
      actionBar.setTitle(selectedAlbum.bucketName);
    } else if (type == 0) {
      actionBar.setTitle(
          LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
    } else if (type == 1) {
      actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
    }
    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();
            }
          }
        });

    if (selectedAlbum == null) {
      ActionBarMenu menu = actionBar.createMenu();
      searchItem =
          menu.addItem(0, R.drawable.ic_ab_search)
              .setIsSearchField(true)
              .setActionBarMenuItemSearchListener(
                  new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                    @Override
                    public void onSearchExpand() {}

                    @Override
                    public boolean canCollapseSearch() {
                      finishFragment();
                      return false;
                    }

                    @Override
                    public void onTextChanged(EditText editText) {
                      if (editText.getText().length() == 0) {
                        searchResult.clear();
                        searchResultKeys.clear();
                        lastSearchString = null;
                        nextSearchBingString = null;
                        giphySearchEndReached = true;
                        searching = false;
                        requestQueue.cancelAll("search");
                        if (type == 0) {
                          emptyView.setText(
                              LocaleController.getString(
                                  "NoRecentPhotos", R.string.NoRecentPhotos));
                        } else if (type == 1) {
                          emptyView.setText(
                              LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
                        }
                        updateSearchInterface();
                      }
                    }

                    @Override
                    public void onSearchPressed(EditText editText) {
                      if (editText.getText().toString().length() == 0) {
                        return;
                      }
                      searchResult.clear();
                      searchResultKeys.clear();
                      nextSearchBingString = null;
                      giphySearchEndReached = true;
                      if (type == 0) {
                        searchBingImages(editText.getText().toString(), 0, 53);
                      } else if (type == 1) {
                        searchGiphyImages(editText.getText().toString(), 0, 53);
                      }
                      lastSearchString = editText.getText().toString();
                      if (lastSearchString.length() == 0) {
                        lastSearchString = null;
                        if (type == 0) {
                          emptyView.setText(
                              LocaleController.getString(
                                  "NoRecentPhotos", R.string.NoRecentPhotos));
                        } else if (type == 1) {
                          emptyView.setText(
                              LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
                        }
                      } else {
                        emptyView.setText(
                            LocaleController.getString("NoResult", R.string.NoResult));
                      }
                      updateSearchInterface();
                    }
                  });
    }

    if (selectedAlbum == null) {
      if (type == 0) {
        searchItem
            .getSearchField()
            .setHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
      } else if (type == 1) {
        searchItem
            .getSearchField()
            .setHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
      }
    }

    fragmentView = new FrameLayout(context);

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

    listView = new GridView(context);
    listView.setPadding(
        AndroidUtilities.dp(4),
        AndroidUtilities.dp(4),
        AndroidUtilities.dp(4),
        AndroidUtilities.dp(4));
    listView.setClipToPadding(false);
    listView.setDrawSelectorOnTop(true);
    listView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    listView.setNumColumns(GridView.AUTO_FIT);
    listView.setVerticalSpacing(AndroidUtilities.dp(4));
    listView.setHorizontalSpacing(AndroidUtilities.dp(4));
    listView.setSelector(R.drawable.list_selector);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (selectedAlbum != null && selectedAlbum.isVideo) {
              if (i < 0 || i >= selectedAlbum.photos.size()) {
                return;
              }
              if (delegate.didSelectVideo(selectedAlbum.photos.get(i).path)) {
                finishFragment();
              }
            } else {
              ArrayList<Object> arrayList;
              if (selectedAlbum != null) {
                arrayList = (ArrayList) selectedAlbum.photos;
              } else {
                if (searchResult.isEmpty() && lastSearchString == null) {
                  arrayList = (ArrayList) recentImages;
                } else {
                  arrayList = (ArrayList) searchResult;
                }
              }
              if (i < 0 || i >= arrayList.size()) {
                return;
              }
              PhotoViewer.getInstance().setParentActivity(getParentActivity());
              PhotoViewer.getInstance()
                  .openPhotoForSelect(
                      arrayList, i, singlePhoto ? 1 : 0, PhotoPickerActivity.this, chatActivity);
            }
          }
        });

    if (selectedAlbum == null) {
      listView.setOnItemLongClickListener(
          new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(
                AdapterView<?> parent, View view, int position, long id) {
              if (searchResult.isEmpty() && lastSearchString == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
                builder.setPositiveButton(
                    LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(),
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialogInterface, int i) {
                        recentImages.clear();
                        if (listAdapter != null) {
                          listAdapter.notifyDataSetChanged();
                        }
                        MessagesStorage.getInstance().clearWebRecent(type);
                      }
                    });
                builder.setNegativeButton(
                    LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
                return true;
              }
              return false;
            }
          });
    }

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

    if (selectedAlbum == null) {
      listView.setOnScrollListener(
          new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
              if (i == SCROLL_STATE_TOUCH_SCROLL) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
              }
            }

            @Override
            public void onScroll(
                AbsListView absListView,
                int firstVisibleItem,
                int visibleItemCount,
                int totalItemCount) {
              if (visibleItemCount != 0
                  && firstVisibleItem + visibleItemCount > totalItemCount - 2
                  && !searching) {
                if (type == 0 && nextSearchBingString != null) {
                  searchBingImages(lastSearchString, searchResult.size(), 54);
                } else if (type == 1 && !giphySearchEndReached) {
                  searchGiphyImages(
                      searchItem.getSearchField().getText().toString(), searchResult.size(), 54);
                }
              }
            }
          });

      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 = singlePhoto ? 0 : AndroidUtilities.dp(48);
      progressView.setLayoutParams(layoutParams);

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

      updateSearchInterface();
    }

    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) {
            delegate.actionButtonPressed(true);
            finishFragment();
          }
        });
    pickerBottomLayout.doneButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            sendSelectedPhotos();
          }
        });
    if (singlePhoto) {
      pickerBottomLayout.setVisibility(View.GONE);
    }

    listView.setEmptyView(emptyView);
    pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);

    return fragmentView;
  }
  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;
          }
        });
  }
  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();
  }
  public Materialize build() {
    // we need an activity for this
    if (mActivity == null) {
      throw new RuntimeException("please pass an activity");
    }

    // if the user has not set a drawerLayout use the default one :D
    mScrimInsetsLayout =
        (ScrimInsetsFrameLayout)
            mActivity.getLayoutInflater().inflate(R.layout.materialize, mRootView, false);

    // check if the activity was initialized correctly
    if (mRootView == null || mRootView.getChildCount() == 0) {
      throw new RuntimeException(
          "You have to set your layout for this activity with setContentView() first. Or you build the drawer on your own with .buildView()");
    }

    // get the content view
    View originalContentView = mRootView.getChildAt(0);

    boolean alreadyInflated = originalContentView.getId() == R.id.materialize_root;

    // define the statusBarColor
    if (mStatusBarColor == 0 && mStatusBarColorRes != -1) {
      mStatusBarColor = mActivity.getResources().getColor(mStatusBarColorRes);
    } else if (mStatusBarColor == 0) {
      mStatusBarColor =
          UIUtils.getThemeColorFromAttrOrRes(
              mActivity, R.attr.colorPrimaryDark, R.color.materialize_primary_dark);
    }

    // handling statusBar / navigationBar tinting
    mScrimInsetsLayout.setInsetForeground(mStatusBarColor);
    mScrimInsetsLayout.setTintStatusBar(mTintStatusBar);
    mScrimInsetsLayout.setTintNavigationBar(mTintNavigationBar);

    // if we are fullscreen remove all insets
    mScrimInsetsLayout.setSystemUIVisible(!mFullscreen && !mSystemUIHidden);

    // do some magic specific to the statusBar
    if (!alreadyInflated && mTranslucentStatusBar) {
      if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
        UIUtils.setTranslucentStatusFlag(mActivity, true);
      }
      if (Build.VERSION.SDK_INT >= 19) {
        if (mTranslucentStatusBarProgrammatically) {
          mActivity
              .getWindow()
              .getDecorView()
              .setSystemUiVisibility(
                  View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
      }
      if (Build.VERSION.SDK_INT >= 21) {
        UIUtils.setTranslucentStatusFlag(mActivity, false);
        if (mTranslucentStatusBarProgrammatically) {
          mActivity.getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
      }
      mScrimInsetsLayout.getView().setPadding(0, UIUtils.getStatusBarHeight(mActivity), 0, 0);
    }

    // do some magic specific to the navigationBar
    if (!alreadyInflated && mTranslucentNavigationBar) {
      if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
        UIUtils.setTranslucentNavigationFlag(mActivity, true);
      }
      if (Build.VERSION.SDK_INT >= 19) {
        if (mTranslucentNavigationBarProgrammatically) {
          mActivity
              .getWindow()
              .getDecorView()
              .setSystemUiVisibility(
                  View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
          UIUtils.setTranslucentNavigationFlag(mActivity, true);
        }
      }
      if (Build.VERSION.SDK_INT >= 21) {
        if (mTranslucentNavigationBarProgrammatically) {
          mActivity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
        }
      }
    }

    // set the flags if we want to hide the system ui
    if (mSystemUIHidden) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        View decorView = this.mActivity.getWindow().getDecorView();
        decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
      }
    }

    // only add the new layout if it wasn't done before
    if (!alreadyInflated) {
      // remove the contentView
      mRootView.removeView(originalContentView);
    } else {
      // if it was already inflated we have to clean up again
      mRootView.removeAllViews();
    }

    // create the layoutParams to use for the contentView
    FrameLayout.LayoutParams layoutParamsContentView =
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    // if we have a translucent navigation bar set the bottom margin
    if (!mFullscreen && mTranslucentNavigationBar && Build.VERSION.SDK_INT >= 19) {
      layoutParamsContentView.bottomMargin = UIUtils.getNavigationBarHeight(mActivity);
    }

    // add the contentView to the drawer content frameLayout
    mScrimInsetsLayout.getView().addView(originalContentView, layoutParamsContentView);

    // if we have a mContainer we use this one
    mContentRoot = mScrimInsetsLayout.getView();
    if (mContainer != null) {
      mContentRoot = mContainer;
      mContentRoot.addView(
          mScrimInsetsLayout.getView(),
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }

    // set the id so we can check if it was already inflated
    mContentRoot.setId(R.id.materialize_root);

    // make sure we have the correct layoutParams
    if (mContainerLayoutParams == null) {
      mContainerLayoutParams =
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }
    // add the drawerLayout to the root
    mRootView.addView(mContentRoot, mContainerLayoutParams);

    // set activity to null as we do not need it anymore
    this.mActivity = null;

    // create a Materialize object with the builder
    return new Materialize(this);
  }
  @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());
  }
  public void layout(Launcher launcher) {
    FrameLayout.LayoutParams lp;
    Resources res = launcher.getResources();
    boolean hasVerticalBarLayout = isVerticalBarLayout();

    // Layout the search bar space
    View searchBar = launcher.getSearchBar();
    lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
    if (hasVerticalBarLayout) {
      // Vertical search bar space
      lp.gravity = Gravity.TOP | Gravity.LEFT;
      lp.width = searchBarSpaceHeightPx;
      lp.height = LayoutParams.WRAP_CONTENT;

      LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar);
      targets.setOrientation(LinearLayout.VERTICAL);
    } else {
      // Horizontal search bar space
      lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
      lp.width = searchBarSpaceWidthPx;
      lp.height = searchBarSpaceHeightPx;
    }
    searchBar.setLayoutParams(lp);

    // Layout the workspace
    PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
    lp = (FrameLayout.LayoutParams) workspace.getLayoutParams();
    lp.gravity = Gravity.CENTER;
    int orientation = isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT;
    Rect padding = getWorkspacePadding(orientation);
    workspace.setLayoutParams(lp);
    workspace.setPadding(padding.left, padding.top, padding.right, padding.bottom);
    workspace.setPageSpacing(getWorkspacePageSpacing(orientation));

    // Layout the hotseat
    View hotseat = launcher.findViewById(R.id.hotseat);
    lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
    if (hasVerticalBarLayout) {
      // Vertical hotseat
      lp.gravity = Gravity.END;
      lp.width = hotseatBarHeightPx;
      lp.height = LayoutParams.MATCH_PARENT;
      hotseat.findViewById(R.id.layout).setPadding(0, 2 * edgeMarginPx, 0, 2 * edgeMarginPx);
    } else if (isTablet()) {
      // Pad the hotseat with the workspace padding calculated above
      lp.gravity = Gravity.BOTTOM;
      lp.width = LayoutParams.MATCH_PARENT;
      lp.height = hotseatBarHeightPx;
      hotseat.setPadding(
          edgeMarginPx + padding.left, 0, edgeMarginPx + padding.right, 2 * edgeMarginPx);
    } else {
      // For phones, layout the hotseat without any bottom margin
      // to ensure that we have space for the folders
      lp.gravity = Gravity.BOTTOM;
      lp.width = LayoutParams.MATCH_PARENT;
      lp.height = hotseatBarHeightPx;
      hotseat.findViewById(R.id.layout).setPadding(2 * edgeMarginPx, 0, 2 * edgeMarginPx, 0);
    }
    hotseat.setLayoutParams(lp);

    // Layout the page indicators
    View pageIndicator = launcher.findViewById(R.id.page_indicator);
    if (pageIndicator != null) {
      if (hasVerticalBarLayout) {
        // Hide the page indicators when we have vertical search/hotseat
        pageIndicator.setVisibility(View.GONE);
      } else {
        // Put the page indicators above the hotseat
        lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
        lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
        lp.width = LayoutParams.WRAP_CONTENT;
        lp.height = LayoutParams.WRAP_CONTENT;
        lp.bottomMargin = hotseatBarHeightPx;
        pageIndicator.setLayoutParams(lp);
      }
    }

    // Layout AllApps
    AppsCustomizeTabHost host =
        (AppsCustomizeTabHost) launcher.findViewById(R.id.apps_customize_pane);
    if (host != null) {
      // Center the all apps page indicator
      int pageIndicatorHeight =
          (int)
              (pageIndicatorHeightPx
                  * Math.min(1f, (allAppsIconSizePx / DynamicGrid.DEFAULT_ICON_SIZE_PX)));
      pageIndicator = host.findViewById(R.id.apps_customize_page_indicator);
      if (pageIndicator != null) {
        LinearLayout.LayoutParams lllp =
            (LinearLayout.LayoutParams) pageIndicator.getLayoutParams();
        lllp.width = LayoutParams.WRAP_CONTENT;
        lllp.height = pageIndicatorHeight;
        pageIndicator.setLayoutParams(lllp);
      }

      AppsCustomizePagedView pagedView =
          (AppsCustomizePagedView) host.findViewById(R.id.apps_customize_pane_content);

      FrameLayout fakePageContainer = (FrameLayout) host.findViewById(R.id.fake_page_container);
      FrameLayout fakePage = (FrameLayout) host.findViewById(R.id.fake_page);

      padding = new Rect();
      if (pagedView != null) {
        // Constrain the dimensions of all apps so that it does not span the full width
        int paddingLR =
            (availableWidthPx - (allAppsCellWidthPx * allAppsNumCols)) / (2 * (allAppsNumCols + 1));
        int paddingTB =
            (availableHeightPx - (allAppsCellHeightPx * allAppsNumRows))
                / (2 * (allAppsNumRows + 1));
        paddingLR = Math.min(paddingLR, (int) ((paddingLR + paddingTB) * 0.75f));
        paddingTB = Math.min(paddingTB, (int) ((paddingLR + paddingTB) * 0.75f));
        int maxAllAppsWidth = (allAppsNumCols * (allAppsCellWidthPx + 2 * paddingLR));
        int gridPaddingLR = (availableWidthPx - maxAllAppsWidth) / 2;
        // Only adjust the side paddings on landscape phones, or tablets
        if ((isTablet() || isLandscape) && gridPaddingLR > (allAppsCellWidthPx / 4)) {
          padding.left = padding.right = gridPaddingLR;
        }

        // The icons are centered, so we can't just offset by the page indicator height
        // because the empty space will actually be pageIndicatorHeight + paddingTB
        padding.bottom = Math.max(0, pageIndicatorHeight - paddingTB);

        pagedView.setWidgetsPageIndicatorPadding(pageIndicatorHeight);
        fakePage.setBackground(res.getDrawable(R.drawable.quantum_panel));

        // Horizontal padding for the whole paged view
        int pagedFixedViewPadding =
            res.getDimensionPixelSize(R.dimen.apps_customize_horizontal_padding);

        padding.left += pagedFixedViewPadding;
        padding.right += pagedFixedViewPadding;

        pagedView.setPadding(padding.left, padding.top, padding.right, padding.bottom);
        fakePageContainer.setPadding(padding.left, padding.top, padding.right, padding.bottom);
      }
    }

    // Layout the Overview Mode
    ViewGroup overviewMode = launcher.getOverviewPanel();
    if (overviewMode != null) {
      Rect r = getOverviewModeButtonBarRect();
      lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
      lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;

      int visibleChildCount = getVisibleChildCount(overviewMode);
      int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
      int maxWidth = totalItemWidth + (visibleChildCount - 1) * overviewModeBarSpacerWidthPx;

      lp.width = Math.min(availableWidthPx, maxWidth);
      lp.height = r.height();
      overviewMode.setLayoutParams(lp);

      if (lp.width > totalItemWidth && visibleChildCount > 1) {
        // We have enough space. Lets add some margin too.
        int margin = (lp.width - totalItemWidth) / (visibleChildCount - 1);
        View lastChild = null;

        // Set margin of all visible children except the last visible child
        for (int i = 0; i < visibleChildCount; i++) {
          if (lastChild != null) {
            MarginLayoutParams clp = (MarginLayoutParams) lastChild.getLayoutParams();
            if (isLayoutRtl) {
              clp.leftMargin = margin;
            } else {
              clp.rightMargin = margin;
            }
            lastChild.setLayoutParams(clp);
            lastChild = null;
          }
          View thisChild = overviewMode.getChildAt(i);
          if (thisChild.getVisibility() != View.GONE) {
            lastChild = thisChild;
          }
        }
      }
    }
  }
  @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());
  }
Exemple #20
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();
  }
  @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;
  }