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 #4
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 possiblyResizeChildOfContent() {
   int usableHeightNow = computeUsableHeight();
   if (usableHeightNow != usableHeightPrevious) {
     int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
     int heightDifference = usableHeightSansKeyboard - usableHeightNow;
     if (heightDifference > (usableHeightSansKeyboard / 4)) {
       // keyboard probably just became visible
       frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
     } else {
       // keyboard probably just became hidden
       frameLayoutParams.height = usableHeightSansKeyboard;
     }
     mChildOfContent.requestLayout();
     usableHeightPrevious = usableHeightNow;
   }
 }
  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);
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    characters = new ArrayList<CharTextView>();
    mainLayout = new LinearLayout(this);
    setContentView(mainLayout);
    mainLayout.setOrientation(LinearLayout.VERTICAL);
    mainLayout.setId(442);
    grid = new GridLayout(this);
    GridLayout.LayoutParams gridParams =
        new GridLayout.LayoutParams(GridLayout.spec(3), GridLayout.spec(7));
    grid.setId(444);
    int counter = 0;
    for (int i = 0; i < 7; ++i) {
      for (int j = 0; j < 2; ++j) {
        CharTextView iv = new CharTextView(this);
        Bitmap joeAvatar = BitmapFactory.decodeResource(getResources(), R.drawable.joe);
        Character joe = new Character(joeAvatar, "Joe Nash", 24, "United Kingdom");
        iv.setCharacterCell(joe);
        iv.setId(50 + counter);
        GridLayout.LayoutParams buttonparams =
            new GridLayout.LayoutParams(GridLayout.spec(j), GridLayout.spec(i));
        buttonparams.height = 200;
        buttonparams.width = 150;
        iv.setOnClickListener(this);
        grid.addView(iv, buttonparams);
        characters.add(iv);
        counter++;
      }
    }

    heroLayout = new FrameLayout(this);
    heroLayout.setId(443);
    FrameLayout.LayoutParams frameParams =
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    frameParams.height = 600;
    ImageView portrait = new ImageView(this);
    portrait.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.joenash));
    heroLayout.addView(portrait);

    Button fightButton = new Button(this);
    fightButton.setText(R.string.fight);
    ViewGroup.LayoutParams buttonParams =
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    buttonParams.height = 150;
    buttonParams.width = 650;

    mainLayout.addView(heroLayout, frameParams);
    mainLayout.addView(grid, gridParams);
    mainLayout.addView(fightButton, buttonParams);
    // znameto
    //        heroLayout.setBackground();
    // String variable = "variable"
    // int Button = getResources().getIdentifier(variable, "drawable", getPackageName());
  }
Beispiel #8
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 #9
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 #10
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;
  }
    public ViewHolder(View view) {
      super(view);
      ButterKnife.bind(this, view);
      this.view = (FrameLayout) view;

      // optimization to preset the correct height for our device
      int screenWidth = view.getContext().getResources().getDisplayMetrics().widthPixels;
      int finalHeight = (int) (screenWidth / 1.5) / 2;
      imageView.setMinimumHeight(finalHeight);
      imageView.setMaxHeight(finalHeight);
      imageView.setAdjustViewBounds(false);
      // set height as layoutParameter too
      FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) imageView.getLayoutParams();
      lp.height = finalHeight;
      imageView.setLayoutParams(lp);
    }
  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());
  }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   ViewHolder holder;
   if (convertView == null) {
     holder = new ViewHolder();
     convertView = mLayoutInflater.inflate(R.layout.item_restoration, null);
     holder.textView = (TextView) convertView.findViewById(R.id.item_restoration_tv);
     FrameLayout.LayoutParams params =
         (FrameLayout.LayoutParams) holder.textView.getLayoutParams();
     params.height = DensityUtil.dp2px(mContext, mItemHeight);
     holder.textView.setLayoutParams(params);
     convertView.setTag(holder);
   } else {
     holder = (ViewHolder) convertView.getTag();
   }
   holder.textView.setText(mData.get(position));
   return convertView;
 }
  /** Toggle the Logs View visibility with a nice animation. */
  public void toggleLogsView(boolean showView) {
    final View logsView = findViewById(R.id.logs_layout);
    final View bodyView = findViewById(R.id.container);
    final FrameLayout.LayoutParams logsLayoutParams =
        (FrameLayout.LayoutParams) logsView.getLayoutParams();
    final int startLogsY, endLogsY, startBodyY, endBodyY;

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

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

      // Prepare the value for the Show animation.
      startLogsY = logsLayoutParams.bottomMargin;
      endLogsY = 0;
      startBodyY = 0;
      endBodyY = logsLayoutParams.height;
    } else {
      // Prepare the value for the Hide animation.
      startLogsY = 0;
      endLogsY = -logsLayoutParams.height;
      startBodyY = logsLayoutParams.height;
      endBodyY = 0;
    }
    final int deltaLogsY = endLogsY - startLogsY;
    final int deltaBodyY = endBodyY - startBodyY;
    Animation a =
        new Animation() {
          @Override
          protected void applyTransformation(float interpolatedTime, Transformation t) {
            logsLayoutParams.bottomMargin = (int) (startLogsY + deltaLogsY * interpolatedTime);
            logsView.setLayoutParams(logsLayoutParams);
            bodyView.setPadding(0, 0, 0, (int) (startBodyY + deltaBodyY * interpolatedTime));
          }
        };
    a.setDuration(500);
    logsView.startAnimation(a);
  }
Beispiel #18
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);
      }
    }
  }
 private void possiblyResizeChildOfContent() {
   int usableHeightNow = computeUsableHeight();
   if (usableHeightNow != usableHeightPrevious) {
     int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
     int heightDifference = usableHeightSansKeyboard - usableHeightNow;
     if (heightDifference > (usableHeightSansKeyboard / 4)) {
       // keyboard probably just became visible
       isKeybordShow = true;
       //                mChildOfContent.setPadding(0,0,0,bottomPadding);
     } else {
       // keyboard probably just became
       isKeybordShow = false;
       //                mChildOfContent.setPadding(0,0,0,bottomPadding +
       // (ApiCompatibleUtil.hasLollipop() ? navigationBarHeight : 0));
     }
     frameLayoutParams.height = usableHeightNow;
     mChildOfContent.requestLayout();
     usableHeightPrevious = usableHeightNow;
   }
 }
  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;
  }
  public BaseRcvAdapterHelper setHeightRatio(int viewId, float width, float ratio) {
    View view = retrieveView(viewId);
    if (view.getParent() instanceof FrameLayout) {

      FrameLayout.LayoutParams frameParams = (FrameLayout.LayoutParams) view.getLayoutParams();
      frameParams.height = (int) (width * ratio);
      view.setLayoutParams(frameParams);

    } else if (view.getParent() instanceof LinearLayout) {

      LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) view.getLayoutParams();
      linearParams.height = (int) (width * ratio);
      view.setLayoutParams(linearParams);

    } else if (view.getParent() instanceof RelativeLayout) {

      RelativeLayout.LayoutParams relativeParams =
          (RelativeLayout.LayoutParams) view.getLayoutParams();
      relativeParams.height = (int) (width * ratio);
      view.setLayoutParams(relativeParams);
    }
    return this;
  }
  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;
  }
  @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;
  }
  @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;
  }
  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;
  }
  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);
  }
Beispiel #29
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;
  }
  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;
  }