@Override
  protected void initialize(Bundle savedInstanceState) {
    super.initialize(savedInstanceState);

    mOverlay = (ViewGroup) findViewById(R.id.overlay);
    mTray = findViewById(R.id.tray);
    mFab = (FloatingActionButton) findViewById(R.id.fab);

    mFab.getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                if (android.os.Build.VERSION.SDK_INT >= 16) {
                  mFab.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                } else {
                  mFab.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
                initializeLayout();
              }
            });
    mFab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            showTray();
            hideFab();
          }
        });
    setupTray(savedInstanceState);
    if (findViewById(R.id.pad_pager) == null) {
      showFab();
    }
  }
Ejemplo n.º 2
0
 private void updateFavoriteBtn() {
   fab.setImageDrawable(isFavorite ? mStarFilled : mStarOutline);
   if (fab.getScaleX() == 0) {
     // credits for onPreDraw technique:
     // http://frogermcs.github.io/Instagram-with-Material-Design-concept-part-2-Comments-transition/
     fab.getViewTreeObserver()
         .addOnPreDrawListener(
             new ViewTreeObserver.OnPreDrawListener() {
               @Override
               public boolean onPreDraw() {
                 fab.getViewTreeObserver().removeOnPreDrawListener(this);
                 fab.animate()
                     .withLayer()
                     .scaleX(1f)
                     .scaleY(1f)
                     .setInterpolator(new DecelerateInterpolator())
                     .setDuration(mAnimShortDuration)
                     .start();
                 return true;
               }
             });
   }
 }