@Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // получаем плавающую кнопку из активити
    FloatingActionButton fab = ButterKnife.findById(getActivity(), R.id.fab);
    // получаем параметры Layout fab приведенные к родителю
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
    // выставляем привязку якоря к appBarLayout
    params.setAnchorId(R.id.appbar_layout);
    // выставляем anchorGravity
    params.anchorGravity = Gravity.BOTTOM | Gravity.RIGHT;
    fab.setLayoutParams(params);
    // меняем иконку плавающей кнопки
    fab.setImageResource(R.drawable.ic_mode_edit_24dp);
    /*        fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) { //создаем и вешаем новый обработчик на fab
            //выбираем действие для fab в зависимости от текущего режима
            if (sCurrentFunctionality.equals(FUNCTIONALITY_PROFILE_VIEW)) {
                setupFuncionality(FUNCTIONALITY_PROFILE_EDIT);
            } else {
                setupFuncionality(FUNCTIONALITY_PROFILE_VIEW);
            }
        }
    });*/
  }
示例#2
0
 private void showFab() {
   final CoordinatorLayout.LayoutParams layoutParams =
       (CoordinatorLayout.LayoutParams) fabPhoto.getLayoutParams();
   layoutParams.setAnchorId(R.id.layout_app_bar);
   layoutParams.anchorGravity = Gravity.RIGHT | Gravity.END | Gravity.BOTTOM;
   fabPhoto.requestLayout();
   fabPhoto.show();
 }
示例#3
0
 /** To hide fab, you need to remove its anchor */
 private void hideFab() {
   // Ugly bug makes the view go to bottom|center of screen before hiding, seems like you need to
   // implement your own fab behavior...
   fabPhoto.setVisibility(View.GONE);
   final CoordinatorLayout.LayoutParams layoutParams =
       (CoordinatorLayout.LayoutParams) fabPhoto.getLayoutParams();
   layoutParams.setAnchorId(View.NO_ID);
   fabPhoto.requestLayout();
   fabPhoto.hide();
 }
示例#4
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);
    }
  }
  @Override
  public boolean onDependentViewChanged(
      CoordinatorLayout parent, CircleImageView child, View dependency) {

    // Called once
    if (mStartYPosition == 0) mStartYPosition = (int) (child.getY() + (child.getHeight() / 2));

    if (mFinalYPosition == 0) mFinalYPosition = (dependency.getHeight() / 2);

    if (mStartHeight == 0) mStartHeight = child.getHeight();

    if (finalHeight == 0)
      finalHeight = mContext.getResources().getDimensionPixelOffset(R.dimen.image_final_width);

    if (mStartXPosition == 0) mStartXPosition = (int) (child.getX() + (child.getWidth() / 2));

    if (mFinalXPosition == 0)
      mFinalXPosition =
          mContext
                  .getResources()
                  .getDimensionPixelOffset(R.dimen.abc_action_bar_content_inset_material)
              + (finalHeight / 2);

    if (mStartToolbarPosition == 0)
      mStartToolbarPosition = dependency.getY() + (dependency.getHeight() / 2);

    final int maxScrollDistance = (int) (mStartToolbarPosition - getStatusBarHeight());
    float expandedPercentageFactor = dependency.getY() / maxScrollDistance;

    float distanceYToSubtract =
        ((mStartYPosition - mFinalYPosition) * (1f - expandedPercentageFactor))
            + (child.getHeight() / 2);

    float distanceXToSubtract =
        ((mStartXPosition - mFinalXPosition) * (1f - expandedPercentageFactor))
            + (child.getWidth() / 2);

    float heightToSubtract = ((mStartHeight - finalHeight) * (1f - expandedPercentageFactor));

    child.setY(mStartYPosition - distanceYToSubtract);
    child.setX(mStartXPosition - distanceXToSubtract);

    int proportionalAvatarSize = (int) (mAvatarMaxSize * (expandedPercentageFactor));

    CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
    lp.width = (int) (mStartHeight - heightToSubtract);
    lp.height = (int) (mStartHeight - heightToSubtract);
    child.setLayoutParams(lp);
    return true;
  }
 public static void setDrag(boolean isDrag, AppBarLayout appBar) {
   final boolean drag = isDrag;
   ((CoordinatorLayout.LayoutParams) appBar.getLayoutParams())
       .setBehavior(new AppBarLayout.Behavior() {});
   CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) appBar.getLayoutParams();
   AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) lp.getBehavior();
   behavior.setDragCallback(
       new AppBarLayout.Behavior.DragCallback() {
         @Override
         public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
           return drag;
         }
       });
 }
  public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) {
    ViewParent p = this.getParent().getParent();

    if (p instanceof CoordinatorLayout) {
      CoordinatorLayout cl = ((CoordinatorLayout) p);
      AppBarLayout apl = (AppBarLayout) cl.findViewById(R.id.app_bar_layout);
      CoordinatorLayout.LayoutParams lp = (LayoutParams) apl.getLayoutParams();
      final Behavior viewBehavior = lp.getBehavior();
      if (viewBehavior != null) {
        viewBehavior.onNestedFling(this, apl, target, velocityX, velocityY, consumed);
      }
    }

    return super.onNestedFling(target, velocityX, velocityY, consumed);
  }
示例#8
0
 private void disableAppBarDrag() {
   // see
   // http://stackoverflow.com/questions/34108501/how-to-disable-scrolling-of-appbarlayout-in-coordinatorlayout
   CoordinatorLayout.LayoutParams params =
       (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
   AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
   params.setBehavior(behavior);
   behavior.setDragCallback(
       new AppBarLayout.Behavior.DragCallback() {
         @Override
         public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
           return false;
         }
       });
 }
示例#9
0
  @Override
  public void onClick(View view) {
    PreferencesManager mPreferencesManager = new PreferencesManager(MainActivity.this);
    DisplayMetrics displaymetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int screenWidth = displaymetrics.widthPixels;
    int screenHeight = displaymetrics.heightPixels;

    switch (view.getId()) {
      case R.id.switchAnimation:
        if (isRevealEnabled) {
          switchAnimation.setText("Switch to Reveal");
          isRevealEnabled = false;
        } else {
          switchAnimation.setText("Switch to Fadein");
          isRevealEnabled = true;
        }
        mPreferencesManager.resetAll();
        break;

      case R.id.reset:
        mPreferencesManager.resetAll();
        break;
      case R.id.resetAndPlay:
        mPreferencesManager.resetAll();
        new Handler(Looper.getMainLooper())
            .postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    showIntro(fab, INTRO_CARD);
                  }
                },
                400);
        break;
      case R.id.changePosAndPlay:
        mPreferencesManager.resetAll();
        Random r = new Random();
        int right = r.nextInt((screenWidth - Utils.dpToPx(16)) - 16) + 16;
        int bottom = r.nextInt((screenHeight - Utils.dpToPx(16)) - 16) + 16;
        CoordinatorLayout.LayoutParams params =
            (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
        params.setMargins(Utils.dpToPx(16), Utils.dpToPx(16), right, bottom);
        fab.setLayoutParams(params);
        break;
    }
  }
  private void handleToolbarVisibility(final boolean show) {

    final AppBarLayout appBarLayout = (AppBarLayout) mToolbar.getParent();
    final CoordinatorLayout rootLayout = (CoordinatorLayout) appBarLayout.getParent();

    final CoordinatorLayout.LayoutParams params =
        (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
    final AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();

    if (show) {
      // Show appBar
      behavior.setTopAndBottomOffset(0);
      behavior.onNestedPreScroll(rootLayout, appBarLayout, null, 0, 1, new int[2]);

    } else {
      // Hide appBar
      behavior.onNestedFling(rootLayout, appBarLayout, null, 0, 10000, true);
    }
  }
示例#11
0
 @Override
 public void onAttachedToLayoutParams(@NonNull CoordinatorLayout.LayoutParams params) {
   params.dodgeInsetEdges |= Gravity.BOTTOM;
 }