Example #1
0
  @Override
  public void onStateChange(View view, HideablePartBehavior.State state) {
    switch (state) {
      case COLLAPSED:
        if (collapsed) return;
        if (getView() == null) return;
        collapsed = true;
        ((RelativeLayout.LayoutParams) send.getLayoutParams())
                .getRules()[RelativeLayout.ALIGN_BOTTOM] =
            R.id.text;
        ((RelativeLayout.LayoutParams) target.getLayoutParams())
                .getRules()[RelativeLayout.ALIGN_BOTTOM] =
            0;
        ((RelativeLayout.LayoutParams) text.getLayoutParams()).getRules()[RelativeLayout.LEFT_OF] =
            R.id.send;

        ((CoordinatorLayout.LayoutParams) commentFrame.getLayoutParams()).rightMargin =
            (int) (getView().getResources().getDisplayMetrics().density * 59);

        root.invalidate();
        text.clearFocus();
        text.setSingleLine(true);
        text.setVerticalScrollBarEnabled(false);

      case HIDDEN:
        hideKeyboard();
        break;

      case EXPANDED:
        if (!collapsed) return;
        if (getView() == null) return;
        collapsed = false;
        ((RelativeLayout.LayoutParams) send.getLayoutParams())
                .getRules()[RelativeLayout.ALIGN_BOTTOM] =
            0;
        ((RelativeLayout.LayoutParams) target.getLayoutParams())
                .getRules()[RelativeLayout.ALIGN_BOTTOM] =
            R.id.send;
        ((RelativeLayout.LayoutParams) text.getLayoutParams()).getRules()[RelativeLayout.LEFT_OF] =
            0;

        ((CoordinatorLayout.LayoutParams) commentFrame.getLayoutParams()).rightMargin = 0;
        root.invalidate();
        text.setVerticalScrollBarEnabled(true);
        text.setSingleLine(false);
        text.setMaxLines(9);

        showKeyboard();
        break;
    }
  }
Example #2
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ButterKnife.bind(this, view);

    final CoordinatorLayout.LayoutParams layoutParams =
        (CoordinatorLayout.LayoutParams) commentFrame.getLayoutParams();

    commentFrame.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    behavior = (HideablePartBehavior) layoutParams.getBehavior();
    behavior.setChangeCallback(this);

    root.setResizeCallback(
        new IgnorantCoordinatorLayout.ResizeCallback() {
          @Override
          public void onSizeChanged(int w, int h, int oldw, int oldh) {
            commentFrame.post(
                new Runnable() {
                  @Override
                  public void run() {
                    behavior.sync(commentFrame);
                  }
                });
          }
        });

    instrumentsLayout.removeAllViews();

    LayoutInflater inflater = getLayoutInflater(savedInstanceState);
    for (final TextChanger changer : instruments) {
      View button = inflater.inflate(R.layout.include_instrument_button, instrumentsLayout, false);
      ((ImageView) button.findViewById(R.id.icon)).setImageResource(changer.getImageResource());
      button.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              changer.onSelect(CommentEditFragment.this, text);
              selectedInstrument = instruments.indexOf(changer);
            }
          });
      instrumentsLayout.addView(button);
    }
  }