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 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();
     }
   }
 }
  @Override
  public void onResize(int mode, int delta) {
    if (mTarget == null) return;
    if (mResizeFrame == null) return;

    int w = getMeasuredWidth() - (getPaddingLeft() + getPaddingRight());
    int h = getMeasuredHeight() - (getPaddingTop() + getPaddingBottom());
    int minWidth = (w / mCols) + (w / mCols) / 2;
    int minHeight = (h / mRows) + (h / mRows) / 2;

    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mResizeFrame.getLayoutParams();
    switch (mode) {
      case Gravity.LEFT:
        float newpos = mResizeFrame.getX() + delta;
        if ((delta < 0 && newpos < (getPaddingLeft() * -1))
            || (delta > 0 && newpos > (mResizeFrame.getX() + params.width - minWidth))) {
          return;
        }
        mResizeFrame.setX(newpos);
        params.width -= delta;
        break;
      case Gravity.RIGHT:
        if ((delta < 0 && ((params.width + delta) < minWidth))
            || (delta > 0
                && (mResizeFrame.getX() + delta + params.width)
                    > (getPaddingLeft() + getMeasuredWidth()))) {
          return;
        }
        params.width += delta;
        break;
      case Gravity.TOP:
        newpos = mResizeFrame.getY() + delta;
        if ((delta < 0 && newpos < (getPaddingTop() * -1))
            || (delta > 0 && newpos > (mResizeFrame.getY() + params.height - minHeight))) {
          return;
        }
        mResizeFrame.setY(newpos);
        params.height -= delta;
        break;
      case Gravity.BOTTOM:
        if ((delta < 0 && ((params.height + delta) < minHeight))
            || (delta > 0
                && (mResizeFrame.getY() + delta + params.height)
                    > (getPaddingTop() + getMeasuredHeight()))) {
          return;
        }
        params.height += delta;
        break;

      default:
        break;
    }
    mResizeFrame.setLayoutParams(params);
  }
Beispiel #5
0
 public static void imageFLViewReset(ImageView imageView, int bitmapW, int bitmapH) {
   FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) imageView.getLayoutParams();
   HashMap<String, Integer> data = Handler_System.getDisplayMetrics();
   int width = data.get(Handler_System.systemWidth);
   int height = data.get(Handler_System.systemHeight);
   if (width > height) {
     layoutParams.width = (int) (bitmapW * 1.00f / bitmapH * height);
     layoutParams.height = height;
   } else {
     layoutParams.width = width;
     layoutParams.height = (int) (bitmapH * 1.00f / bitmapW * width);
   }
   imageView.setLayoutParams(layoutParams);
 }
    private void updateIndicatorPosition(int position, float positionOffset) {
      // 現在の位置のタブのView
      final View view = mTrack.getChildAt(position);
      // 現在の位置の次のタブのView、現在の位置が最後のタブのときはnull
      final View view2 =
          position == (mTrack.getChildCount() - 1) ? null : mTrack.getChildAt(position + 1);

      // 現在の位置のタブの左端座標取得
      int left = view.getLeft();

      // 現在の位置のタブの横幅
      int width = view.getWidth();
      // 現在の位置の次のタブの横幅
      int width2 = view2 == null ? width : view2.getWidth();

      // インディケータの幅
      // width2 × スライドした割合 + (width × スライドした割合 - 1)
      int indicatorWidth = (int) (width2 * positionOffset + width * (1 - positionOffset));
      // インディケータの左端の位置
      // 今選択中のタブの左端 + width * スライドした割合
      int indicatorLeft = (int) (left + positionOffset * width);

      // インディケータの幅と左端の位置をセット
      final FrameLayout.LayoutParams layoutParams =
          (FrameLayout.LayoutParams) mIndicator.getLayoutParams();
      layoutParams.width = indicatorWidth;
      layoutParams.setMargins(indicatorLeft, 0, 0, 0);
      mIndicator.setLayoutParams(layoutParams);

      // インディケータが画面に入るように、タブの領域をスクロール
      mTrackScroller.scrollTo(indicatorLeft - mIndicatorOffset, 0);

      mIndicator.setBackgroundColor(getResources().getColor(R.color.ferrari_red));
    }
  /**
   * Sets {@code LayoutAdjustment} and {@code narrowMode}.
   *
   * <p>They are highly dependent on one another so this method sets both at the same time. This
   * decision makes caller-side simpler.
   */
  public void setLayoutAdjustmentAndNarrowMode(
      LayoutAdjustment layoutAdjustment, boolean narrowMode) {
    checkInflated();

    this.layoutAdjustment = layoutAdjustment;
    this.narrowMode = narrowMode;

    // If on narrowMode, the view is always shown with full-width regard less of given
    // layoutAdjustment.
    LayoutAdjustment temporaryAdjustment = narrowMode ? LayoutAdjustment.FILL : layoutAdjustment;

    View view = getForegroundFrame();
    FrameLayout.LayoutParams layoutParams =
        FrameLayout.LayoutParams.class.cast(view.getLayoutParams());
    Resources resources = getResources();
    layoutParams.width =
        temporaryAdjustment == LayoutAdjustment.FILL
            ? resources.getDisplayMetrics().widthPixels
            : getSideAdjustedWidth();
    layoutParams.gravity = Gravity.BOTTOM;
    if (temporaryAdjustment == LayoutAdjustment.LEFT) {
      layoutParams.gravity |= Gravity.LEFT;
    } else if (temporaryAdjustment == LayoutAdjustment.RIGHT) {
      layoutParams.gravity |= Gravity.RIGHT;
    }
    view.setLayoutParams(layoutParams);

    leftFrameStubProxy.setFrameVisibility(
        temporaryAdjustment == LayoutAdjustment.RIGHT ? VISIBLE : GONE);
    rightFrameStubProxy.setFrameVisibility(
        temporaryAdjustment == LayoutAdjustment.LEFT ? VISIBLE : GONE);

    // Set candidate and desciption text size.
    float candidateTextSize =
        layoutAdjustment == LayoutAdjustment.FILL
            ? resources.getDimension(R.dimen.candidate_text_size)
            : resources.getDimension(R.dimen.candidate_text_size_aligned_layout);
    float descriptionTextSize =
        layoutAdjustment == LayoutAdjustment.FILL
            ? resources.getDimension(R.dimen.candidate_description_text_size)
            : resources.getDimension(R.dimen.candidate_description_text_size_aligned_layout);
    getCandidateView().setCandidateTextDimension(candidateTextSize, descriptionTextSize);
    getSymbolInputView().setCandidateTextDimension(candidateTextSize, descriptionTextSize);
    getConversionCandidateWordContainerView().setCandidateTextDimension(candidateTextSize);

    // In narrow mode, hide software keyboard and show narrow status bar.
    getCandidateView().setNarrowMode(narrowMode);
    if (narrowMode) {
      getKeyboardFrame().setVisibility(GONE);
      getNarrowFrame().setVisibility(VISIBLE);
    } else {
      getKeyboardFrame().setVisibility(VISIBLE);
      getNarrowFrame().setVisibility(GONE);
      resetKeyboardFrameVisibility();
    }

    updateInputFrameHeight();
    updateBackgroundColor();
  }
  public synchronized void fillFreeList(int animationLen) {
    final Context ctx = getContext();
    final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(mCellSize, mCellSize);

    while (!mFreeList.isEmpty()) {
      Point pt = mFreeList.iterator().next();
      mFreeList.remove(pt);
      final int i = pt.x;
      final int j = pt.y;

      if (mCells[j * mColumns + i] != null) continue;
      final ImageView v = new ImageView(ctx);
      v.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View view) {
              place(v, true);
              postDelayed(
                  new Runnable() {
                    public void run() {
                      fillFreeList();
                    }
                  },
                  DURATION / 2);
            }
          });

      final int c = random_color();
      v.setBackgroundColor(c);

      final float which = frand();
      final Drawable d;
      if (which < 0.0005f) {
        d = mDrawables.get(pick(XXRARE_PASTRIES));
      } else if (which < 0.005f) {
        d = mDrawables.get(pick(XRARE_PASTRIES));
      } else if (which < 0.5f) {
        d = mDrawables.get(pick(RARE_PASTRIES));
      } else if (which < 0.7f) {
        d = mDrawables.get(pick(PASTRIES));
      } else {
        d = null;
      }
      if (d != null) {
        v.getOverlay().add(d);
      }

      lp.width = lp.height = mCellSize;
      addView(v, lp);
      place(v, pt, false);
      if (animationLen > 0) {
        final float s = (Integer) v.getTag(TAG_SPAN);
        v.setScaleX(0.5f * s);
        v.setScaleY(0.5f * s);
        v.setAlpha(0f);
        v.animate().withLayer().scaleX(s).scaleY(s).alpha(1f).setDuration(animationLen);
      }
    }
  }
Beispiel #9
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);
 }
Beispiel #10
0
 public void setStyle(Style style) {
   this.style = style;
   android.widget.FrameLayout.LayoutParams layoutParams =
       (android.widget.FrameLayout.LayoutParams) content.getLayoutParams();
   if (style == Style.Floating) {
     layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
     layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
     int margin = (int) getResources().getDimension(R.dimen.carbon_padding);
     layoutParams.setMargins(margin, 0, margin, margin);
     layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
   } else {
     layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
     layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
     layoutParams.setMargins(0, 0, 0, 0);
     layoutParams.gravity = Gravity.BOTTOM;
   }
   content.setLayoutParams(layoutParams);
   requestLayout();
 }
Beispiel #11
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);
 }
 /**
  * 根据分辨率设置透明按钮的大小
  *
  * @author [email protected] 2013-7-29 下午5:12:27
  * @param view
  * @return void
  */
 public static void resetFLBack(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.height = (int) (layoutParams.height * rote);
     layoutParams.width = (int) (layoutParams.width * rote);
     view2.setLayoutParams(layoutParams);
   }
 }
  public void init(ArrayList<BaseFragment> stack) {
    fragmentsStack = stack;
    containerViewBack = new LinearLayoutContainer(parentActivity);
    addView(containerViewBack);
    FrameLayout.LayoutParams layoutParams =
        (FrameLayout.LayoutParams) containerViewBack.getLayoutParams();
    layoutParams.width = LayoutParams.MATCH_PARENT;
    layoutParams.height = LayoutParams.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    containerViewBack.setLayoutParams(layoutParams);

    containerView = new LinearLayoutContainer(parentActivity);
    addView(containerView);
    layoutParams = (FrameLayout.LayoutParams) containerView.getLayoutParams();
    layoutParams.width = LayoutParams.MATCH_PARENT;
    layoutParams.height = LayoutParams.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    containerView.setLayoutParams(layoutParams);

    for (BaseFragment fragment : fragmentsStack) {
      fragment.setParentLayout(this);
    }
  }
  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;
  }
  private void init(Context context, AttributeSet attrs) {
    mImageView = new CropperImageView(context, attrs);
    mGridView = new CropperGridView(context, attrs);

    FrameLayout.LayoutParams params =
        new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);

    if (context.getResources().getConfiguration().orientation
        == Configuration.ORIENTATION_LANDSCAPE) {
      params.width = 0;
      params.height = ViewGroup.LayoutParams.MATCH_PARENT;
    }

    addView(mImageView, 0, params);
    addView(mGridView, 1, params);

    mImageView.setGestureCallback(new TouchGestureCallback());
  }
Beispiel #16
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // mOverlay.setTranslationY(800);

    Log.d("mPaintSeekInfo", "draw with mPaintSeekInfo => " + mPaintSeekInfo);

    if (isInEditMode()) {
      return;
    }

    if (mPaintSeekInfo) {
      Log.d("PlayerSeekbar", "Draw seekinfo");
      if (params.height == 0) {
        mOverlay.setVisibility(INVISIBLE);
        params.height = mOverlay.getHeight();
        params.width = mOverlay.getWidth();
        mOverlay.bringToFront();
      }

      mBackwards.setText(mBackwardsText);
      mCurrent.setText(mCurrentText);
      mForwards.setText(mForwardText);

      this.getLocationOnScreen(loc);
      int offset =
          loc[1] - (int) UIUtils.convertDpToPixel(200, getContext()); // FIXME this.getHeight()*4;
      int translationY = (int) ((View) this.getParent()).getTranslationY();
      Log.d("PlayerSeekbar", "trans => " + translationY);
      Log.d("PlayerSeekbar", "loc0 => " + loc[0] + " loc0 => " + loc[1]);
      params.setMargins(mSideMargin, offset, mSideMargin, 0);

      if (mOverlay != null) {
        mOverlay.setLayoutParams(params);
        mOverlay.setVisibility(VISIBLE);
      }
    } else {
      Log.d("PlayerSeekbar", "Remove seekinfo");
      if (mOverlay != null) {
        mOverlay.setVisibility(GONE);
      }
    }
  }
  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;
  }
  private void setupAlignment(RecyclerView recycler) {
    if (!mAlreadyAligned) {
      // setting alignment of header
      ViewGroup.LayoutParams currentParams = getLayoutParams();
      FrameLayout.LayoutParams newHeaderParams;
      int width = ViewGroup.LayoutParams.WRAP_CONTENT;
      int height = ViewGroup.LayoutParams.WRAP_CONTENT;
      int gravity = (mReversed ? Gravity.BOTTOM : Gravity.TOP) | Gravity.CENTER_HORIZONTAL;
      if (currentParams != null) {
        newHeaderParams =
            new FrameLayout.LayoutParams(getLayoutParams()); // to copy all the margins
        newHeaderParams.width = width;
        newHeaderParams.height = height;
        newHeaderParams.gravity = gravity;
      } else {
        newHeaderParams = new FrameLayout.LayoutParams(width, height, gravity);
      }
      RecyclerViewHeader.this.setLayoutParams(newHeaderParams);

      // setting alignment of recycler
      FrameLayout newRootParent = new FrameLayout(recycler.getContext());
      newRootParent.setLayoutParams(recycler.getLayoutParams());
      ViewParent currentParent = recycler.getParent();
      if (currentParent instanceof ViewGroup) {
        int indexWithinParent = ((ViewGroup) currentParent).indexOfChild(recycler);

        ((ViewGroup) currentParent).removeViewAt(indexWithinParent);
        recycler.setLayoutParams(
            new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        newRootParent.addView(recycler);
        newRootParent.addView(RecyclerViewHeader.this);
        ((ViewGroup) currentParent).addView(newRootParent, indexWithinParent);
      }
    }
  }
  /**
   * Method that select a view as the target of to resize
   *
   * @param v The target view
   */
  boolean selectTarget(View v) {
    // Do not do long click if we do not have a target
    if (mTarget != null && v.equals(mTarget)) return false;
    if (mResizeFrame == null) return false;

    // Show the resize frame view just in place of the current clicked view

    mResizeFrame.hide();
    FrameLayout.LayoutParams frameParams =
        (FrameLayout.LayoutParams) mResizeFrame.getLayoutParams();
    int padding = mInternalPadding + mResizeFrame.getNeededPadding();
    frameParams.width = v.getWidth() + (padding * 2);
    frameParams.height = v.getHeight() + (padding * 2);
    mResizeFrame.setX(v.getX() - padding);
    mResizeFrame.setY(v.getY() - padding);
    mResizeFrame.show();

    // Save the new view
    mTarget = v;
    if (mOnFrameSelectedListener != null) {
      mOnFrameSelectedListener.onFrameSelectedListener(v);
    }
    return true;
  }
  public View getView(final int position, View convertView, ViewGroup parent) {
    final ViewHolder2 holder;
    WindowManager mWinMgr = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    deviceHeight = mWinMgr.getDefaultDisplay().getHeight();
    deviceWidth = mWinMgr.getDefaultDisplay().getWidth();

    if (convertView == null) {
      holder = new ViewHolder2();

      convertView = mInflater.inflate(R.layout.picturecategory, null);
      try {
        int buttonwidth = (int) (deviceWidth * .48);
        int imagewidth = (int) (deviceWidth * .48);
        int imageHeight = (int) (deviceWidth * .48f * .75f);

        holder.ButtonGrid = (FrameLayout) convertView.findViewById(R.id.ButtonGrid);
        LinearLayout.LayoutParams params_ButtonGrid =
            (LinearLayout.LayoutParams) holder.ButtonGrid.getLayoutParams();
        params_ButtonGrid =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT,
                Gravity.TOP | Gravity.LEFT);
        params_ButtonGrid.width = buttonwidth;
        params_ButtonGrid.height = (int) (.9f * buttonwidth);
        params_ButtonGrid.leftMargin = (int) (0.02 * deviceWidth);
        params_ButtonGrid.rightMargin = (int) (0.02 * deviceWidth);
        holder.ButtonGrid.setLayoutParams(params_ButtonGrid);

        LinearLayout.LayoutParams marginparam_ButtonGrid =
            (LinearLayout.LayoutParams) holder.ButtonGrid.getLayoutParams();
        marginparam_ButtonGrid.topMargin = (int) (.02f * deviceHeight);

        holder.ButtonGV = (ImageView) convertView.findViewById(R.id.ButtonGV);
        ViewGroup.LayoutParams params_ButtonGV = holder.ButtonGV.getLayoutParams();
        params_ButtonGV.width = buttonwidth;
        params_ButtonGV.height = (int) (.9f * buttonwidth);
        holder.ButtonGV.setLayoutParams(params_ButtonGV);

        holder.THImage = (ImageView) convertView.findViewById(R.id.THImage);
        FrameLayout.LayoutParams params_THImage =
            (FrameLayout.LayoutParams) holder.THImage.getLayoutParams();
        params_THImage.width = imagewidth;
        params_THImage.height = (int) (.65 * .9f * buttonwidth);
        params_THImage.topMargin = (int) (deviceHeight * .025f);
        holder.THImage.setLayoutParams(params_THImage);

        holder.GridButtonTV = (TextView) convertView.findViewById(R.id.GridButtonTV);
        ViewGroup.LayoutParams params_GridButtonTV = holder.GridButtonTV.getLayoutParams();
        params_GridButtonTV.height = (int) (.3 * .9f * buttonwidth);
        holder.GridButtonTV.setPadding(0, (int) (.05 * .9f * buttonwidth), 0, 0);
        holder.GridButtonTV.setLayoutParams(params_GridButtonTV);
      } catch (Exception e) {
        System.out.println("Exception in Grid Item's Width Please Define the Width" + e);

        holder.ButtonGrid = (FrameLayout) convertView.findViewById(R.id.ButtonGrid);
        ViewGroup.LayoutParams params_ButtonGrid = holder.ButtonGrid.getLayoutParams();
        int buttonwidth = (int) (.2f * deviceWidth);
        params_ButtonGrid.width = buttonwidth;
        params_ButtonGrid.height = (int) (1.07f * buttonwidth);
        holder.ButtonGrid.setLayoutParams(params_ButtonGrid);

        LinearLayout.LayoutParams marginparam_ButtonGrid =
            (LinearLayout.LayoutParams) holder.ButtonGrid.getLayoutParams();
        //				marginparam_ButtonGrid.leftMargin = (int)(.025f*deviceWidth);
        marginparam_ButtonGrid.topMargin = (int) (.025f * deviceHeight);

        holder.ButtonGV = (ImageView) convertView.findViewById(R.id.ButtonGV);
        ViewGroup.LayoutParams params_ButtonGV = holder.ButtonGV.getLayoutParams();
        params_ButtonGV.width = buttonwidth;
        params_ButtonGV.height = (int) (.6f * buttonwidth);
        holder.ButtonGV.setLayoutParams(params_ButtonGV);

        holder.GridButtonTV = (TextView) convertView.findViewById(R.id.GridButtonTV);
        ViewGroup.LayoutParams params_GridButtonTV = holder.GridButtonTV.getLayoutParams();
        params_GridButtonTV.height = (int) (.0725f * deviceHeight);
        holder.GridButtonTV.setLayoutParams(params_GridButtonTV);
      }

      convertView.setTag(holder);
    } else {
      holder = (ViewHolder2) convertView.getTag();
    }

    holder.ButtonGrid.setOnTouchListener(
        new OnTouchListener() {
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                //					holder.THImage.getBackground().setAlpha(150);
                try {
                  holder.THImage.setAlpha(100);
                } catch (Exception e) {
                  // TODO: handle exception
                }
                //		        	holder.GridButtonTV.getBackground().setAlpha(150);
                //					return false;
                return true;
              case MotionEvent.ACTION_UP:
                //					holder.THImage.getBackground().setAlpha(255);
                try {
                  holder.THImage.setAlpha(255);
                } catch (Exception e) {
                  // TODO: handle exception
                }
                //					String
                // screenNumber=MyUIApplication._objEWList.get(position).OnClick.substring(12);
                //					String mailto=MyUIApplication._objEWList.get(position).mailto;
                //					String body=MyUIApplication._objEWList.get(position).body;
                //					String subject=MyUIApplication._objEWList.get(position).subject;

                //					if(screenNumber.equals("1"))   //  "1" For Mail
                //					{
                //						UtilMail mail = new UtilMail();
                //						mail.OpenMail(mContext ,mailto ,body,subject);
                //					}
                //					else
                //					{
                //					if(((Home)mContext).LLLayout.getVisibility()==View.VISIBLE)
                //					{
                //
                //	((Home)mContext).LLLayoutCopy.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.slide_in_left));
                //
                //	((Home)mContext).LLLayout.startAnimation(AnimationUtils.loadAnimation(mContext,
                // R.anim.slide_out_left));
                //					}
                //					if(((Home)mContext).LLLayoutCopy.getVisibility()==View.VISIBLE)
                //					{
                //
                //	((Home)mContext).LLLayout.startAnimation(AnimationUtils.loadAnimation(mContext,
                // R.anim.slide_in_left));
                //
                //	((Home)mContext).LLLayoutCopy.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.slide_out_left));
                //					}

                try {
                  ((Home) mContext).inLayoutAnim();
                } catch (Exception e) {
                  // TODO: handle exception
                }

                MyUIApplication.CatagoryCode =
                    MyUIApplication.PictureGaleryCategoryList.get(position).CatagoryCode;
                MyUIApplication.CatagoryName =
                    MyUIApplication.PictureGaleryCategoryList.get(position).CatagoryName;

                //					if(ScreenNumberr.equals("100"))
                //					{
                //
                //	((Home)mContext).OpenHtmlPage("11",MyUIApplication.PictureGaleryCategoryList.get(position).CatagoryCode);
                //						MyUIApplication.StateMachine.add("11");
                //					}
                //					else if(ScreenNumberr.equals("101"))
                //					{
                //
                //	((Home)mContext).OpenHtmlPage("115",MyUIApplication.PictureGaleryCategoryList.get(position).CatagoryCode);
                //						MyUIApplication.StateMachine.add("115");
                //					}

                ((Home) mContext)
                    .OpenHtmlPage(
                        ScreenNumberr,
                        MyUIApplication.PictureGaleryCategoryList.get(position).CatagoryName);
                MyUIApplication.StateMachine.add(ScreenNumberr);

                int i = MyUIApplication.StateMachine.size();
                System.out.println("State Machine Size >>>" + i);
                //					}

                break;
              case MotionEvent.ACTION_CANCEL:
                //					holder.THImage.getBackground().setAlpha(255);
                try {
                  holder.THImage.setAlpha(255);
                } catch (Exception e) {
                  // TODO: handle exception
                }
                break;
            }

            return false;
          }
        });
    try {

      int buttonwidth = (int) (.48f * deviceWidth);
      int imagewidth = (int) (.48f * deviceWidth);
      //			int imagewidth=(int)(deviceWidth* .25f);
      int imageHeight = (int) (deviceWidth * .48f * .65f);

      try {

        String root = Environment.getExternalStorageDirectory().toString();
        String imagepath =
            MyUIApplication.mainDirectoryName
                + "/"
                + MyUIApplication.ClientCode
                + "/"
                + MyUIApplication.EventCode
                + "/PictureGalleryCategory/"
                + MyUIApplication.PictureGaleryCategoryList.get(position).Image;
        File myDir = new File(root + "/" + imagepath);
        if (myDir.exists()) {
          Bitmap bmp =
              ImageUtil.setBgFromSDCardForOtherDirectoy(
                  holder.THImage,
                  (Home) mContext,
                  imagepath,
                  (int) (imageHeight),
                  (int) (imagewidth));
          if (bmp != null) {
            holder.THImage.setImageBitmap(bmp);
            holder.THImage.setBackgroundDrawable(null);
          }
        }
      } catch (Exception e) {
        // TODO: handle exception
        String filePath = "images/folder.png";
        ImageUtil.setBackgroundBgFromAssetsNotCache(
            holder.ButtonGV,
            (Home) mContext,
            filePath,
            (int) (buttonwidth * .6f),
            (int) (buttonwidth));
      }

      String s = MyUIApplication.PictureGaleryCategoryList.get(position).ImageCount.trim();
      holder.GridButtonTV.setText(
          MyUIApplication.PictureGaleryCategoryList.get(position).CatagoryName.trim()
              + " ("
              + s
              + ")");

    } catch (Exception e) {

    }

    try {
      Typeface tf = MyUIApplication.fontmap.get(_objElement.fontStyle);
      holder.GridButtonTV.setTypeface(tf);
    } catch (Exception e) {
      // TODO: handle exception
    }

    try {
      holder.GridButtonTV.setTextColor(Color.parseColor(_objElement.fontColor));
      int i = Integer.parseInt(_objElement.fontSize);
      float testsizepercent = i / 960f;
      holder.GridButtonTV.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          MyUIApplication.determineTextSize(
              holder.GridButtonTV.getTypeface(), (testsizepercent * deviceHeight)));
    } catch (Exception e) {
      // TODO: handle exception
      holder.GridButtonTV.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          MyUIApplication.determineTextSize(
              holder.GridButtonTV.getTypeface(), (0.1f) * (.4f * deviceHeight)));
    }

    try {
      if (_objElement.TitleGravity.equalsIgnoreCase("center"))
        holder.GridButtonTV.setGravity(Gravity.CENTER);
      if (_objElement.TitleGravity.equalsIgnoreCase("right"))
        holder.GridButtonTV.setGravity(Gravity.RIGHT);
      if (_objElement.TitleGravity.equalsIgnoreCase("left"))
        holder.GridButtonTV.setGravity(Gravity.LEFT);
    } catch (Exception e) {
      // TODO: handle exception
      holder.GridButtonTV.setGravity(Gravity.CENTER);
    }

    try {
      holder.ButtonGV.setBackgroundColor(Color.parseColor(_objElement.bgcolor));
    } catch (Exception e) {
      // TODO: handle exception
      holder.ButtonGV.setBackgroundColor(Color.WHITE);
    }

    // Display planet data
    holder.id = position;
    return convertView;
  }
  @SuppressWarnings("deprecation")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_show_my_projects);

    ActionBar bar = getActionBar();
    bar.setDisplayHomeAsUpEnabled(true);
    bar.setBackgroundDrawable(new ColorDrawable(Color.WHITE));

    ProjectsUserService pservice = new ProjectsUserService();
    try {
      pservice.execute().get();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ExecutionException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    gv = (GridView) findViewById(R.id.gridViewMyProjects);
    gv.setAdapter(new MyAdapter(this, 4));
    dialog = new AlertDialog.Builder(this);

    gv.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
            final int aux = pos;
            dialog.setTitle("Projeto?");
            dialog.setPositiveButton(
                R.string.ver,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                    Intent goProject =
                        new Intent(ShowMyProjectsActivity.this, VerProjetoActivity.class);
                    goProject.putExtra("ID_PROJETO", aux);
                    startActivity(goProject);
                  }
                });
            dialog.setNegativeButton(
                R.string.finalizar,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                    Toast.makeText(
                            getApplicationContext(), "Projeto Finalizado", Toast.LENGTH_SHORT)
                        .show();
                  }
                });

            AlertDialog xpto = dialog.create();
            xpto.show();
          }
        });

    findViewById(R.id.button_perfil)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                startActivity(new Intent(getApplicationContext(), PerfilActivity.class));
              }
            });

    findViewById(R.id.button_eventos)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                startActivity(new Intent(getApplicationContext(), EventsActivity.class));
              }
            });

    findViewById(R.id.button_mapa)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                startActivity(new Intent(getApplicationContext(), MapActivity.class));
              }
            });

    findViewById(R.id.button_projetos)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                startActivity(new Intent(getApplicationContext(), VerProjetoActivity.class));
              }
            });

    findViewById(R.id.button_credits)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                startActivity(new Intent(getApplicationContext(), CreditsActivity.class));
              }
            });

    findViewById(R.id.button_projetos)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                startActivity(new Intent(getApplicationContext(), ShowMyProjectsActivity.class));
              }
            });

    gestureDetector = new GestureDetector(new MyGestureDetector());
    // Initialize
    metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    panelWidth = (int) ((metrics.widthPixels) * 0.75);

    slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel);
    slidingPanelParameters = (FrameLayout.LayoutParams) slidingPanel.getLayoutParams();
    slidingPanelParameters.width = metrics.widthPixels;
    slidingPanel.setLayoutParams(slidingPanelParameters);

    View mainview = (View) findViewById(R.id.slidingPanel);

    // Set the touch listener for the main view to be our custom gesture
    // listener
    mainview.setOnTouchListener(
        new View.OnTouchListener() {
          public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
              return true;
            }
            return false;
          }
        });

    // Slide the Panel
    View itemid = findViewById(android.R.id.home);
    itemid.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            if (!isExpanded) {
              flag = 1;
              isExpanded = true;

              // Expand
              new ExpandAnimation(
                  slidingPanel,
                  panelWidth,
                  Animation.RELATIVE_TO_SELF,
                  0.0f,
                  Animation.RELATIVE_TO_SELF,
                  0.75f,
                  0,
                  0.0f,
                  0,
                  0.0f);
            } else {
              isExpanded = false;
              flag = 0;
              // Collapse
              new CollapseAnimation(
                  slidingPanel,
                  panelWidth,
                  TranslateAnimation.RELATIVE_TO_SELF,
                  0.75f,
                  TranslateAnimation.RELATIVE_TO_SELF,
                  0.0f,
                  0,
                  0.0f,
                  0,
                  0.0f);
            }
          }
        });
  }
  @Override
  public View createView(Context context, LayoutInflater inflater) {
    searching = false;
    searchWas = false;

    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("Language", R.string.Language));

    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              finishFragment();
            }
          }
        });

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

                  @Override
                  public void onSearchCollapse() {
                    search(null);
                    searching = false;
                    searchWas = false;
                    if (listView != null) {
                      emptyTextView.setVisibility(View.GONE);
                      listView.setAdapter(listAdapter);
                    }
                  }

                  @Override
                  public void onTextChanged(EditText editText) {
                    String text = editText.getText().toString();
                    search(text);
                    if (text.length() != 0) {
                      searchWas = true;
                      if (listView != null) {
                        listView.setAdapter(searchListViewAdapter);
                      }
                    }
                  }
                });
    item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));

    listAdapter = new ListAdapter(context);
    searchListViewAdapter = new SearchAdapter(context);

    fragmentView = new FrameLayout(context);

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

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

    FrameLayout frameLayout = new FrameLayout(context);
    emptyTextLayout.addView(frameLayout);
    layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
    layoutParams1.width = LayoutHelper.MATCH_PARENT;
    layoutParams1.height = LayoutHelper.MATCH_PARENT;
    layoutParams1.weight = 0.5f;
    frameLayout.setLayoutParams(layoutParams1);

    listView = new ListView(context);
    listView.setEmptyView(emptyTextLayout);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setAdapter(listAdapter);
    ((FrameLayout) fragmentView).addView(listView);
    layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    listView.setLayoutParams(layoutParams);

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            LocaleController.LocaleInfo localeInfo = null;
            if (searching && searchWas) {
              if (i >= 0 && i < searchResult.size()) {
                localeInfo = searchResult.get(i);
              }
            } else {
              if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
                localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
              }
            }
            if (localeInfo != null) {
              LocaleController.getInstance().applyLanguage(localeInfo, true);
              parentLayout.rebuildAllFragmentViews(false);
            }
            finishFragment();
          }
        });

    listView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            LocaleController.LocaleInfo localeInfo = null;
            if (searching && searchWas) {
              if (i >= 0 && i < searchResult.size()) {
                localeInfo = searchResult.get(i);
              }
            } else {
              if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
                localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
              }
            }
            if (localeInfo == null
                || localeInfo.pathToFile == null
                || getParentActivity() == null) {
              return false;
            }
            final LocaleController.LocaleInfo finalLocaleInfo = localeInfo;
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setMessage(
                LocaleController.getString("DeleteLocalization", R.string.DeleteLocalization));
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setPositiveButton(
                LocaleController.getString("Delete", R.string.Delete),
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                    if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo)) {
                      if (searchResult != null) {
                        searchResult.remove(finalLocaleInfo);
                      }
                      if (listAdapter != null) {
                        listAdapter.notifyDataSetChanged();
                      }
                      if (searchListViewAdapter != null) {
                        searchListViewAdapter.notifyDataSetChanged();
                      }
                    }
                  }
                });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
            return true;
          }
        });

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

          @Override
          public void onScroll(
              AbsListView absListView,
              int firstVisibleItem,
              int visibleItemCount,
              int totalItemCount) {}
        });

    return fragmentView;
  }
  @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;
  }
  void initLayout() {
    DisplayMetrics dm = new DisplayMetrics();
    // 取得窗口属性
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);
    backgoundWidth = dm.widthPixels * 5;
    ViewGroup.LayoutParams layoutParams;

    ImageView back_image_one = (ImageView) findViewById(R.id.back_image_one);
    layoutParams = back_image_one.getLayoutParams();
    layoutParams.height = dm.heightPixels;
    layoutParams.width = dm.widthPixels;
    back_image_one.setLayoutParams(layoutParams);

    ImageView back_image_two = (ImageView) findViewById(R.id.back_image_two);
    layoutParams = back_image_two.getLayoutParams();
    layoutParams.height = dm.heightPixels;
    layoutParams.width = dm.widthPixels;
    back_image_two.setLayoutParams(layoutParams);

    ImageView back_image_three = (ImageView) findViewById(R.id.back_image_three);
    layoutParams = back_image_three.getLayoutParams();
    layoutParams.height = dm.heightPixels;
    layoutParams.width = dm.widthPixels;
    back_image_three.setLayoutParams(layoutParams);

    ImageView back_image_four = (ImageView) findViewById(R.id.back_image_four);
    layoutParams = back_image_four.getLayoutParams();
    layoutParams.height = dm.heightPixels;
    layoutParams.width = dm.widthPixels;
    back_image_four.setLayoutParams(layoutParams);

    ImageView back_image_five = (ImageView) findViewById(R.id.back_image_five);
    layoutParams = back_image_five.getLayoutParams();
    layoutParams.height = dm.heightPixels;
    layoutParams.width = dm.widthPixels;
    back_image_five.setLayoutParams(layoutParams);

    FrameLayout.LayoutParams frameLayoutParams;
    ImageView layer_image_one = (ImageView) findViewById(R.id.layer_image_one);
    frameLayoutParams = (FrameLayout.LayoutParams) layer_image_one.getLayoutParams();
    frameLayoutParams.height = dm.heightPixels;
    frameLayoutParams.width = dm.widthPixels;
    layer_image_one.setLayoutParams(frameLayoutParams);

    ImageView layer_image_two = (ImageView) findViewById(R.id.layer_image_two);
    frameLayoutParams = (FrameLayout.LayoutParams) layer_image_two.getLayoutParams();
    frameLayoutParams.height = dm.heightPixels;
    frameLayoutParams.width = dm.widthPixels;
    layer_image_two.setLayoutParams(frameLayoutParams);

    ImageView layer_image_three = (ImageView) findViewById(R.id.layer_image_three);
    frameLayoutParams = (FrameLayout.LayoutParams) layer_image_three.getLayoutParams();
    frameLayoutParams.height = dm.heightPixels;
    frameLayoutParams.width = dm.widthPixels;
    layer_image_three.setLayoutParams(frameLayoutParams);

    ImageView layer_image_four = (ImageView) findViewById(R.id.layer_image_four);
    frameLayoutParams = (FrameLayout.LayoutParams) layer_image_four.getLayoutParams();
    frameLayoutParams.height = dm.heightPixels;
    frameLayoutParams.width = dm.widthPixels;
    layer_image_four.setLayoutParams(frameLayoutParams);

    ImageView layer_image_five = (ImageView) findViewById(R.id.layer_image_five);
    frameLayoutParams = (FrameLayout.LayoutParams) layer_image_five.getLayoutParams();
    frameLayoutParams.height = dm.heightPixels;
    frameLayoutParams.width = dm.widthPixels;
    layer_image_five.setLayoutParams(frameLayoutParams);
  }
  @SuppressLint("InlinedApi")
  private void applyRules(View view, BoxElement elm) {
    int alignmentInBox = elm.getAlignmentInBox();
    int elmW = elm.getWidthCell();
    boolean bOverlapTB = false;
    boolean bOverlapLR = false;
    FrameLayout.LayoutParams lp = (LayoutParams) view.getLayoutParams();

    switch (alignmentInBox) {
      case DEFINE_BOX_ELEMENT_RULES_RIGHT_TOP:
        if (UIUtils.hasICS()) {
          lp.gravity = Gravity.END;
        } else {
          lp.gravity = Gravity.RIGHT | Gravity.TOP;
        }
        break;
      case DEFINE_BOX_ELEMENT_RULES_LEFT_BOTTOM:
        if (UIUtils.hasICS()) {
          lp.gravity = Gravity.START;
        } else {
          lp.gravity = Gravity.LEFT | Gravity.BOTTOM;
        }
        break;
      case DEFINE_BOX_ELEMENT_RULES_RIGHT_BOTTOM:
        if (UIUtils.hasICS()) {
          lp.gravity = Gravity.END;
        } else {
          lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;
        }
        break;
      case DEFINE_BOX_ELEMENT_RULES_OVERLAP_TOP:
        bOverlapTB = true;
        lp.gravity = Gravity.TOP;
        break;
      case DEFINE_BOX_ELEMENT_RULES_OVERLAP_BOTTOM:
        bOverlapTB = true;
        lp.gravity = Gravity.BOTTOM;
        if (view instanceof TextView) {
          ((TextView) view).setGravity(Gravity.BOTTOM);
        }
        break;
      case DEFINE_BOX_ELEMENT_RULES_OVERLAP_LEFT:
        bOverlapLR = true;
        if (UIUtils.hasICS()) {
          lp.gravity = Gravity.START;
        }
        break;
      case DEFINE_BOX_ELEMENT_RULES_OVERLAP_RIGHT:
        bOverlapLR = true;
        if (UIUtils.hasICS()) {
          lp.gravity = Gravity.END;
        } else {
          lp.gravity = Gravity.RIGHT | Gravity.TOP;
        }
        break;
      case DEFINE_BOX_ELEMENT_RULES_STRETCH:
        lp.width = getBoxSupposeWidth();
        lp.height = getBoxSupposeHeight();
        break;
      case DEFINE_BOX_ELEMENT_RULES_LEFT_TOP:
      default:
        lp.gravity = Gravity.LEFT | Gravity.TOP;
        break;
    }

    if (bOverlapTB) {
      lp.width =
          mBoxCellSize * mNumberOfColumn + mMultiPaddingNum * (mNumberOfColumn - 1) * mGapWidth;
      if (mBoxLayoutIndex == 0) {
        lp.height =
            (mBoxCellSize * mNumberOfRow + mMultiPaddingNum * (mNumberOfRow - 1) * getPaddingTop())
                / 4;
      } else {
        lp.height =
            (int)
                ((2
                        * (mBoxCellSize * mNumberOfRow
                            + mMultiPaddingNum * (mNumberOfRow - 1) * getPaddingTop()))
                    / 5.5f);
      }
      // lp.height = (mBoxCellSize * mNumberOfRow + mMultiPaddingNum
      // * (mNumberOfRow - 1) * getPaddingTop()) / 3;
    } else if (bOverlapLR) {
      lp.width = mBoxCellSize * elmW + mMultiPaddingNum * (elmW - 1) * mGapWidth;
      lp.height =
          (mBoxCellSize * mNumberOfRow + mMultiPaddingNum * (mNumberOfRow - 1) * getPaddingTop());
    } else if (alignmentInBox != DEFINE_BOX_ELEMENT_RULES_STRETCH) {
      lp.width = mBoxCellSize * elmW + mMultiPaddingNum * (elmW - 1) * mGapWidth;
      lp.height = mBoxCellSize;
    }

    if ((view instanceof ImageView) && alignmentInBox != DEFINE_BOX_ELEMENT_RULES_STRETCH) {
      ((ImageView) view).setScaleType(ScaleType.FIT_XY);
      if (mNumberOfColumn > 1) {
        mNeedBackground = true;
      }
      // NOTE: image could be able to "eat" the padding in box.
      lp.width = mBoxCellSize * elmW + mMultiPaddingNum * (elmW) * mGapWidth;
    } else if (view instanceof TextView) {
      TextView tv = (TextView) view;
      if (TNPreferenceManager.isIgnoreTextGravity()) {
        tv.setGravity(Gravity.LEFT | Gravity.TOP);
      } else {
        tv.setGravity(lp.gravity);
      }
      // mWidthText = lp.width;
      // mHeightText = lp.height;
      tv.setPadding(mGapWidth, mGapWidth / 2, mGapWidth, mGapWidth);
    }

    view.setLayoutParams(lp);
    view.setVisibility(VISIBLE);
  }
  void GenerateUI() {
    int boxHeight = 0;
    int boxWidth = 0;
    FrameLayout frm = new FrameLayout(CollageEditorActivity.this);
    FrameLayout.LayoutParams frmParams;
    LinearLayout.LayoutParams params1;
    FrameLayout.LayoutParams params2;

    switch (typeId) {

        // region thumb1
      case R.drawable.thumb1:
        boxHeight = imgBackgroundHeight / 2 - ConvertDotToPixel(80);
        boxWidth = imgBackgroundWidth - ConvertDotToPixel(80);

        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(40));
        frm.setY(ConvertDotToPixel(40));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage1 = new CustomImageView(CollageEditorActivity.this);
        mImage1.setScaleType(ImageView.ScaleType.MATRIX);
        mImage1.setLayoutParams(params1);
        frm.addView(mImage1);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd1 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd1.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd1.setLayoutParams(params2);
        frm.addView(imgAdd1);

        collageEditorRelativeLayout.addView(frm);

        frm = new FrameLayout(CollageEditorActivity.this);
        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(40));
        frm.setY(boxHeight + ConvertDotToPixel(120));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage2 = new CustomImageView(CollageEditorActivity.this);
        mImage2.setScaleType(ImageView.ScaleType.MATRIX);
        mImage2.setLayoutParams(params1);
        frm.addView(mImage2);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd2 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd2.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd2.setLayoutParams(params2);
        frm.addView(imgAdd2);

        collageEditorRelativeLayout.addView(frm);

        break;
        // endregion

        // region thumb2
      case R.drawable.thumb2:
        boxHeight = imgBackgroundHeight - ConvertDotToPixel(120);
        boxWidth = imgBackgroundWidth / 2 - ConvertDotToPixel(60);

        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(30));
        frm.setY(ConvertDotToPixel(60));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage1 = new CustomImageView(CollageEditorActivity.this);
        mImage1.setScaleType(ImageView.ScaleType.MATRIX);
        mImage1.setLayoutParams(params1);
        frm.addView(mImage1);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd1 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd1.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd1.setLayoutParams(params2);
        frm.addView(imgAdd1);

        collageEditorRelativeLayout.addView(frm);

        frm = new FrameLayout(CollageEditorActivity.this);
        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(boxWidth + ConvertDotToPixel(90));
        frm.setY(ConvertDotToPixel(60));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage2 = new CustomImageView(CollageEditorActivity.this);
        mImage2.setScaleType(ImageView.ScaleType.MATRIX);
        mImage2.setLayoutParams(params1);
        frm.addView(mImage2);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd2 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd2.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd2.setLayoutParams(params2);
        frm.addView(imgAdd2);

        collageEditorRelativeLayout.addView(frm);

        break;
        // endregion

        // region thumb3
      case R.drawable.thumb3:
        boxHeight = imgBackgroundHeight / 2 - ConvertDotToPixel(50);
        boxWidth = imgBackgroundWidth / 2 - ConvertDotToPixel(50);

        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(30));
        frm.setY(ConvertDotToPixel(30));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage1 = new CustomImageView(CollageEditorActivity.this);
        mImage1.setScaleType(ImageView.ScaleType.MATRIX);
        mImage1.setLayoutParams(params1);
        frm.addView(mImage1);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd1 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd1.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd1.setLayoutParams(params2);
        frm.addView(imgAdd1);

        collageEditorRelativeLayout.addView(frm);

        frm = new FrameLayout(CollageEditorActivity.this);
        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(boxWidth + ConvertDotToPixel(70));
        frm.setY(boxHeight + ConvertDotToPixel(70));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage2 = new CustomImageView(CollageEditorActivity.this);
        mImage2.setScaleType(ImageView.ScaleType.MATRIX);
        mImage2.setLayoutParams(params1);
        frm.addView(mImage2);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd2 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd2.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd2.setLayoutParams(params2);
        frm.addView(imgAdd2);

        collageEditorRelativeLayout.addView(frm);

        break;
        // endregion

        // region thumb4
      case R.drawable.thumb4:
        boxHeight = imgBackgroundHeight / 2 - ConvertDotToPixel(50);
        boxWidth = imgBackgroundWidth / 2 - ConvertDotToPixel(50);

        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(30));
        frm.setY(boxHeight + ConvertDotToPixel(70));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage1 = new CustomImageView(CollageEditorActivity.this);
        mImage1.setScaleType(ImageView.ScaleType.MATRIX);
        mImage1.setLayoutParams(params1);
        frm.addView(mImage1);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd1 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd1.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd1.setLayoutParams(params2);
        frm.addView(imgAdd1);

        collageEditorRelativeLayout.addView(frm);

        frm = new FrameLayout(CollageEditorActivity.this);
        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(boxWidth + ConvertDotToPixel(70));
        frm.setY(ConvertDotToPixel(30));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage2 = new CustomImageView(CollageEditorActivity.this);
        mImage2.setScaleType(ImageView.ScaleType.MATRIX);
        mImage2.setLayoutParams(params1);
        frm.addView(mImage2);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd2 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd2.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd2.setLayoutParams(params2);
        frm.addView(imgAdd2);

        collageEditorRelativeLayout.addView(frm);

        break;
        // endregion

        // region thumb5
      case R.drawable.thumb5:
        boxHeight = imgBackgroundWidth / 2 + ConvertDotToPixel(10);
        boxWidth = imgBackgroundWidth / 2 + ConvertDotToPixel(10);

        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(30));
        frm.setY(boxHeight + ConvertDotToPixel(140));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage1 = new CustomImageView(CollageEditorActivity.this);
        mImage1.setScaleType(ImageView.ScaleType.MATRIX);
        mImage1.setLayoutParams(params1);
        frm.addView(mImage1);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd1 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd1.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd1.setLayoutParams(params2);
        frm.addView(imgAdd1);

        collageEditorRelativeLayout.addView(frm);

        frm = new FrameLayout(CollageEditorActivity.this);
        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(boxWidth - ConvertDotToPixel(50));
        frm.setY(ConvertDotToPixel(30));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage2 = new CustomImageView(CollageEditorActivity.this);
        mImage2.setScaleType(ImageView.ScaleType.MATRIX);
        mImage2.setLayoutParams(params1);
        frm.addView(mImage2);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd2 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd2.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd2.setLayoutParams(params2);
        frm.addView(imgAdd2);

        collageEditorRelativeLayout.addView(frm);

        break;
        // endregion

        // region thumb6
      case R.drawable.thumb6:
        boxHeight = imgBackgroundWidth / 2 - ConvertDotToPixel(10);
        boxWidth = imgBackgroundWidth / 2 + ConvertDotToPixel(10);

        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(30));
        frm.setY(ConvertDotToPixel(30));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage1 = new CustomImageView(CollageEditorActivity.this);
        mImage1.setScaleType(ImageView.ScaleType.MATRIX);
        mImage1.setLayoutParams(params1);
        frm.addView(mImage1);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd1 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd1.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd1.setLayoutParams(params2);
        frm.addView(imgAdd1);

        collageEditorRelativeLayout.addView(frm);

        frm = new FrameLayout(CollageEditorActivity.this);
        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(boxWidth - ConvertDotToPixel(50));
        frm.setY(boxHeight + ConvertDotToPixel(140));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage2 = new CustomImageView(CollageEditorActivity.this);
        mImage2.setScaleType(ImageView.ScaleType.MATRIX);
        mImage2.setLayoutParams(params1);
        frm.addView(mImage2);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd2 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd2.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd2.setLayoutParams(params2);
        frm.addView(imgAdd2);

        collageEditorRelativeLayout.addView(frm);

        break;
        // endregion

        // region thumb7
      case R.drawable.thumb7:
        boxHeight = imgBackgroundHeight / 2 - ConvertDotToPixel(120);
        boxWidth = imgBackgroundWidth - ConvertDotToPixel(60);

        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(30));
        frm.setY(ConvertDotToPixel(30));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage1 = new CustomImageView(CollageEditorActivity.this);
        mImage1.setScaleType(ImageView.ScaleType.MATRIX);
        mImage1.setLayoutParams(params1);
        frm.addView(mImage1);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd1 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd1.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd1.setLayoutParams(params2);
        frm.addView(imgAdd1);

        collageEditorRelativeLayout.addView(frm);

        frm = new FrameLayout(CollageEditorActivity.this);
        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(30));
        frm.setY(boxHeight + ConvertDotToPixel(100));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage2 = new CustomImageView(CollageEditorActivity.this);
        mImage2.setScaleType(ImageView.ScaleType.MATRIX);
        mImage2.setLayoutParams(params1);
        frm.addView(mImage2);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd2 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd2.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd2.setLayoutParams(params2);
        frm.addView(imgAdd2);

        collageEditorRelativeLayout.addView(frm);

        break;
        // endregion

        // region thumb8
      case R.drawable.thumb8:
        boxHeight = imgBackgroundHeight / 2 - ConvertDotToPixel(120);
        boxWidth = imgBackgroundWidth - ConvertDotToPixel(60);

        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(30));
        frm.setY(boxHeight - ConvertDotToPixel(10));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage1 = new CustomImageView(CollageEditorActivity.this);
        mImage1.setScaleType(ImageView.ScaleType.MATRIX);
        mImage1.setLayoutParams(params1);
        frm.addView(mImage1);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd1 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd1.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd1.setLayoutParams(params2);
        frm.addView(imgAdd1);

        collageEditorRelativeLayout.addView(frm);

        frm = new FrameLayout(CollageEditorActivity.this);
        frmParams = new FrameLayout.LayoutParams(boxWidth, boxHeight);
        frmParams.gravity = Gravity.CENTER;

        frm.setLayoutParams(frmParams);
        frm.setBackgroundColor(Color.WHITE);
        frm.setForegroundGravity(Gravity.CENTER);
        frm.setX(ConvertDotToPixel(30));
        frm.setY(boxHeight + ConvertDotToPixel(200));

        params1 =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        params1.gravity = Gravity.CENTER;

        mImage2 = new CustomImageView(CollageEditorActivity.this);
        mImage2.setScaleType(ImageView.ScaleType.MATRIX);
        mImage2.setLayoutParams(params1);
        frm.addView(mImage2);

        params2 =
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER;
        imgAdd2 = new ImageView(CollageEditorActivity.this);
        params2.width = ConvertDotToPixel(30);
        params2.height = ConvertDotToPixel(30);

        imgAdd2.setImageDrawable(getResources().getDrawable(R.drawable.add));
        imgAdd2.setLayoutParams(params2);
        frm.addView(imgAdd2);

        collageEditorRelativeLayout.addView(frm);

        break;
        // endregion

    }

    // save = (ImageView) findViewById(R.id.iv_btn_save);

    //        mImage1.setOnClickListener(new View.OnClickListener() {
    //
    //			@Override
    //			public void onClick(View v) {
    //				Intent i = new Intent(
    //						Intent.ACTION_PICK,
    //						android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    //				startActivityForResult(i, 0);
    //			}
    //		});

    imgAdd1.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            currentSelectedImage = 1;
            chooseImage();

            //                if (Build.VERSION.SDK_INT < 19){
            //                    Intent intent = new Intent();
            //                    intent.setType("image/*");
            //                    intent.setAction(Intent.ACTION_GET_CONTENT);
            //                    // Always show the chooser (if there are multiple options
            // available)
            //                    startActivityForResult(Intent.createChooser(intent,
            // getString(R.string.choose_photo)), PICK_FROM_GALLERY);
            //                }
            //                else
            //                {
            //                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            //                    intent.setType("image/*");
            //                    startActivityForResult(intent, PICK_FROM_GALLERY);
            //                }

          }
        });

    imgAdd2.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            currentSelectedImage = 2;
            chooseImage();
            //                Intent intent = new Intent();
            //                // Show only images, no videos or anything else
            //                intent.setType("image/*");
            //                intent.setAction(Intent.ACTION_GET_CONTENT);
            //                // Always show the chooser (if there are multiple options available)
            //                startActivityForResult(Intent.createChooser(intent,
            // getString(R.string.choose_photo)), 1);
          }
        });

    //        save.setOnClickListener(new View.OnClickListener() {
    //
    //            @Override
    //            public void onClick(View v) {
    //                String filename = captureImage();
    //            }
    //        });
  }
Beispiel #27
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    bgLayout = (FrameLayout) inflater.inflate(R.layout.popover_layout, container, false);

    containerLayout = (FrameLayout) bgLayout.findViewById(R.id.popover_container);
    bgView = bgLayout.findViewById(R.id.popover_background);

    bgView.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            loader.cancelSubViews();
          }
        });

    FrameLayout.LayoutParams frameLayoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    frameLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
    float density = getResources().getDisplayMetrics().density;
    frameLayoutParams.width = (int) (width * density);
    frameLayoutParams.height = (int) (height * density);

    /*// set size
    LayoutParams params = containerLayout.getLayoutParams();
    float density = getResources().getDisplayMetrics().density;
    params.width = (int)(width * density);
    params.height = (int)(height * density);*/

    containerLayout.setLayoutParams(frameLayoutParams);

    /*
    webView = new SmartWebView(this);

    containerLayout.addView(webView, new FrameLayout.LayoutParams(
    		FrameLayout.LayoutParams.MATCH_PARENT,
    		FrameLayout.LayoutParams.MATCH_PARENT));
    webView.loadUrl(url);*/

    FrameLayout.LayoutParams webViewLayoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams
                .MATCH_PARENT); // (android.widget.RelativeLayout.LayoutParams)
                                // containerLayout.getLayoutParams();
    int margin = (int) (10 * density);
    webViewLayoutParams.setMargins(margin, margin, margin, margin);
    // webView.setLayoutParams(webViewLayoutParams);
    webView = new SmartWebViewClassic(this);
    containerLayout.addView(webView, webViewLayoutParams);
    webView.loadUrl(url);

    /*RoundRectShape rs = new RoundRectShape(new float[] { 10, 10, 10, 10, 10, 10, 10, 10 }, null, null);
    ShapeDrawable sd = new CustomShapeDrawable(rs, Color.RED, Color.WHITE, 20);
    webView.setBackground(sd);*/

    return bgLayout;
  }
  @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;
  }
  @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;
  }