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();
     }
   }
 }
Ejemplo n.º 2
0
  private void applyTo(View target) {

    LayoutParams lp = target.getLayoutParams();
    ViewParent parent = target.getParent();
    FrameLayout container = new FrameLayout(context);

    if (target instanceof TabWidget) {

      // set target to the relevant tab child container
      target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
      this.target = target;

      ((ViewGroup) target)
          .addView(container, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

      this.setVisibility(View.GONE);
      container.addView(this);

    } else {

      // TODO verify that parent is indeed a ViewGroup
      ViewGroup group = (ViewGroup) parent;
      int index = group.indexOfChild(target);

      group.removeView(target);
      group.addView(container, index, lp);

      container.addView(target);

      this.setVisibility(View.GONE);
      container.addView(this);

      group.invalidate();
    }
  }
 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();
 }
Ejemplo n.º 4
0
 public void refresh() {
   recipes.removeAllViews();
   for (Suggestion s : recipe.getSuggestedWith()) {
     recipes.addView(createRecipeEntry(s));
   }
   recipes.invalidate();
 }
Ejemplo n.º 5
0
        @Override
        public void onLocationChanged(Location location) {

          if (counterEnter == 0) {
            counterEnter++;
            checkLocation(location);
            vg.invalidate();
          }
        }
 private void bringViewToFront(View view) {
   ViewGroup group = (ViewGroup) view.getParent();
   int index = group.indexOfChild(view);
   if (index != group.getChildCount() - 1) {
     view.bringToFront();
     if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
       view.requestLayout();
       group.invalidate();
     }
   }
 }
Ejemplo n.º 7
0
 /** @param floatView */
 private void applyToNormal(View floatView) {
   ViewGroup group = (ViewGroup) this.getParent();
   LinearLayout.LayoutParams lp =
       (LinearLayout.LayoutParams)
           ((ViewGroup) this.getChildAt(0)).getChildAt(originIndex).getLayoutParams();
   ((ViewGroup) group).removeView(floatView);
   ((ViewGroup) this.getChildAt(0)).removeViewAt(originIndex);
   ((ViewGroup) this.getChildAt(0)).addView(floatView, originIndex, lp);
   mInsteadView = floatView;
   group.invalidate();
 }
Ejemplo n.º 8
0
  /** @param floatView */
  private void applyToFloat(View floatView) {

    originIndex = ((ViewGroup) this.getChildAt(0)).indexOfChild(floatView);
    LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) floatView.getLayoutParams();
    View v = new View(context);
    v.setTag("view");
    ((ViewGroup) this.getChildAt(0)).removeView(floatView);
    ((ViewGroup) this.getChildAt(0)).addView(v, originIndex, lp);
    ViewGroup group = (ViewGroup) this.getParent();
    ((ViewGroup) group).addView(floatView);
    mInsteadView = v;
    group.invalidate();
  }
Ejemplo n.º 9
0
  /** @param floatView */
  private void initFloatView(View floatView) {
    //        ((ViewGroup)this.getChildAt(0)).removeView(floatView);
    LayoutParams lp = (LayoutParams) this.getLayoutParams();
    ViewGroup group = (ViewGroup) this.getParent();
    FrameLayout container = new FrameLayout(context);

    int index = group.indexOfChild(this);
    group.removeView(this);
    group.addView(container, index, lp);
    container.removeAllViews();
    container.addView(this);
    group.invalidate();
  }
Ejemplo n.º 10
0
  @Override
  public boolean onTouch(View view, MotionEvent event) {
    TouchPoint touchPoint = new TouchPoint(event);
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        sendAnimation.onSwipeStart(touchPoint);

        break;
      case MotionEvent.ACTION_UP:
        sendAnimation.onSwipeEnd(touchPoint);

        break;
      case MotionEvent.ACTION_POINTER_DOWN:
        break;
      case MotionEvent.ACTION_POINTER_UP:
        break;
      case MotionEvent.ACTION_MOVE:
        sendAnimation.onSwiping(touchPoint);

        break;
    }
    mRrootLayout.invalidate();
    return true;
  }
Ejemplo n.º 11
0
  public boolean onTouch(View view, MotionEvent event) {
    float scale;
    final int X = (int) event.getRawX();
    final int Y = (int) event.getRawY();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        view.setBackgroundResource(R.drawable.border);
        garbage.setVisibility(View.VISIBLE);
        RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
        _xDelta = X - lParams.leftMargin;
        _yDelta = Y - lParams.topMargin;

        start.set(event.getX(), event.getY());
        mode = DRAG;
        break;
      case MotionEvent.ACTION_UP:
        Iterator<View> iterator;
        mode = NONE;
        garbage.setVisibility(View.INVISIBLE);
        view.setBackgroundResource(R.color.none);
        if (event.getRawY() > 1530) {
          if (position_status == FRONT) {
            iterator = ViewList.iterator();
          } else {
            iterator = ViewListBack.iterator();
          }
          view.setVisibility(View.GONE);

          while (iterator.hasNext()) {
            View i = iterator.next();
            if (i == view) {
              iterator.remove();
            }
          }
        }
        break;
      case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        if (oldDist > 8f) {
          RelativeLayout.LayoutParams zParams =
              (RelativeLayout.LayoutParams) view.getLayoutParams();
          midPoint(mid, event);
          _xDelta = (int) mid.x - zParams.leftMargin;
          _yDelta = (int) mid.y - zParams.topMargin;
          mode = ZOOM;
        }
        break;
      case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
      case MotionEvent.ACTION_MOVE:
        RelativeLayout.LayoutParams layoutParams =
            (RelativeLayout.LayoutParams) view.getLayoutParams();
        if (mode == DRAG) {
          layoutParams.leftMargin = X - _xDelta;
          layoutParams.topMargin = Y - _yDelta;
          layoutParams.rightMargin = -250;
          layoutParams.bottomMargin = -250;
          view.setLayoutParams(layoutParams);
          rectView = new Rect();
          view.getDrawingRect(rectView);
          if (event.getRawY() > 1530) {
            view.setBackgroundResource(R.color.deletecolor);
          } else view.setBackgroundResource(R.drawable.border);

        } else if (mode == ZOOM) {
          // pinch zooming
          float newDist = spacing(event);
          if (newDist > 8f) {
            // setting the scaling of the
            scale = newDist / oldDist;

            if (view instanceof ImageView) {
              int imgSizeH = view.getHeight();
              int imgSizeW = view.getWidth();
              imgSizeH = (int) (imgSizeH * scale);
              imgSizeW = (int) (imgSizeW * scale);
              layoutParams.width = imgSizeW;
              layoutParams.height = imgSizeH;
              layoutParams.leftMargin = (int) mid.x - _xDelta;
              layoutParams.topMargin = (int) mid.y - _yDelta;
              layoutParams.rightMargin = -250;
              layoutParams.bottomMargin = -250;
              view.setLayoutParams(layoutParams);

            } else if (view instanceof TextView) {
              // textSize = ((TextView) view).getTextSize();
              textSize = textSize * scale;
              ((TextView) view).setTextSize(textSize);
            }
            oldDist = newDist;
          }
        }
        break;
    }
    mRrootLayout.invalidate();
    return true;
  }
  @Override
  public boolean onTouch(View view, MotionEvent event) {
    final int X = (int) event.getRawX();
    final int Y = (int) event.getRawY();

    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        {
          RelativeLayout.LayoutParams layoutParams =
              new RelativeLayout.LayoutParams(button.getLayoutParams());
          layoutParams.leftMargin = startX;
          layoutParams.topMargin = startY;
          view.setLayoutParams(layoutParams);
          xDelta = X - layoutParams.leftMargin;
          yDelta = Y - layoutParams.topMargin;
          initX = X;
          initY = Y;
          break;
        }
      case MotionEvent.ACTION_UP:
        {
          centerButtonWithAnimation();
          dragValue = 0;

          if (mListener != null) {
            if ((xAxisLocked || yAxisLocked)) {
              if (xAxisLocked) mListener.onDragEnded(true);
              else mListener.onDragEnded(false);
            } else mListener.onClicked();
          }
          setDragAxis(mDragAxis);
          break;
        }
      case MotionEvent.ACTION_OUTSIDE:
      case MotionEvent.ACTION_CANCEL:
        {
          centerButtonWithAnimation();
          dragValue = 0;
          if (mListener != null) {
            if (xAxisLocked) mListener.onDragEnded(true);
            else mListener.onDragEnded(false);
          }
          setDragAxis(mDragAxis);
        }
        break;
      case MotionEvent.ACTION_MOVE:
        {
          int diffY = Y - initY;
          int diffX = X - initX;

          if (diffX > 0) {

            if (diffX > THRESHOLD && !yAxisLocked) {
              // move right
              if (!xAxisLocked) {
                xAxisLocked = true;
                if (mListener != null) {
                  mListener.onDragStarted(true);
                }
              }
              RelativeLayout.LayoutParams layoutParams =
                  (RelativeLayout.LayoutParams) view.getLayoutParams();
              if (layoutParams.leftMargin < parentWidth - view.getWidth()) {
                layoutParams.leftMargin = X - xDelta;
                view.setLayoutParams(layoutParams);

                int value = (X - initX) / (view.getWidth() / 2);
                if (value > dragValue && mListener != null) {
                  mListener.onDragRight(value);
                  Log.d("Drag control", "Right------");
                  dragValue++;
                }
              }
              break;
            }
          } else {
            if (diffX < -THRESHOLD && !yAxisLocked) {
              // move left

              if (!xAxisLocked) {
                xAxisLocked = true;
                if (mListener != null) {
                  mListener.onDragStarted(true);
                }
              }
              RelativeLayout.LayoutParams layoutParams =
                  (RelativeLayout.LayoutParams) view.getLayoutParams();
              if (layoutParams.leftMargin > 0) {
                layoutParams.leftMargin = X - xDelta;
                view.setLayoutParams(layoutParams);

                int value = (initX - X) / (view.getWidth() / 2);
                if (value > dragValue && mListener != null) {
                  mListener.onDragLeft(value);
                  Log.d("Drag control", "Left------");
                  dragValue++;
                }
              }
              break;
            }
          }

          if (diffY > 0) {

            if (diffY > THRESHOLD && !xAxisLocked) {
              // move down
              if (!yAxisLocked) {
                yAxisLocked = true;
                if (mListener != null) {
                  mListener.onDragStarted(false);
                }
              }
              RelativeLayout.LayoutParams layoutParams =
                  (RelativeLayout.LayoutParams) view.getLayoutParams();

              if (layoutParams.topMargin < parentHeight - view.getHeight()) {
                layoutParams.topMargin = Y - yDelta;
                view.setLayoutParams(layoutParams);

                int value = (Y - initY) / (view.getHeight() / 2);
                if (value > dragValue && mListener != null) {
                  mListener.onDragDown(1);
                  Log.d("Drag control", "Down------");
                  dragValue++;
                }
              }
              break;
            }
          } else {
            if (diffY < -THRESHOLD && !xAxisLocked) {
              // move up
              if (!yAxisLocked) {
                yAxisLocked = true;
                if (mListener != null) {
                  mListener.onDragStarted(false);
                }
              }
              RelativeLayout.LayoutParams layoutParams =
                  (RelativeLayout.LayoutParams) view.getLayoutParams();
              if (layoutParams.topMargin > 0) {
                layoutParams.topMargin = Y - yDelta;
                view.setLayoutParams(layoutParams);
                int value = (initY - Y) / (view.getHeight() / 2);
                if (value > dragValue && mListener != null) {
                  mListener.onDragUp(1);
                  Log.d("Drag control", "Up------");
                  dragValue++;
                }
              }
              break;
            }
          }
          break;
        }
    }
    root.invalidate();
    return true;
  }
  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;
  }