/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.gnd.ui;

import static com.google.android.gnd.ui.OnBottomSheetSlideBehavior.SheetSlideMetrics.scale;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gnd.R;

public class BottomSheetChromeBehavior extends OnBottomSheetSlideBehavior<ViewGroup> {
  // TODO: Refactor transitions into "TransitionEffect" classes.
  private static final float HIDE_SCRIM_THRESHOLD = 0.0f;
  private static final float SHOW_SCRIM_THRESHOLD = 0.1f;
  private static final float HIDE_ADD_BUTTON_THRESHOLD = 0.3f;
  private static final float SHOW_ADD_BUTTON_THRESHOLD = 0.5f;

  public BottomSheetChromeBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  @Override
  protected void onSheetScrolled(
    CoordinatorLayout parent, ViewGroup layout, SheetSlideMetrics metrics) {
    View scrim = layout.findViewById(R.id.bottom_sheet_bottom_inset_scrim);
    View addRecordButton = layout.findViewById(R.id.add_record_btn);
    ViewGroup toolbarWrapper = layout.findViewById(R.id.toolbar_wrapper);
    ViewGroup toolbar = toolbarWrapper.findViewById(R.id.toolbar);
    ViewGroup toolbarTitles = toolbarWrapper.findViewById(R.id.toolbar_titles_layout);
    metrics.showWithSheet(scrim, HIDE_SCRIM_THRESHOLD, SHOW_SCRIM_THRESHOLD);
    metrics.showWithSheet(addRecordButton, HIDE_ADD_BUTTON_THRESHOLD, SHOW_ADD_BUTTON_THRESHOLD);
    toolbarWrapper.setBackgroundColor(layout.getResources().getColor(R.color.colorPrimary));
    toolbarWrapper.setTranslationY(
      scale(metrics.getVisibleRatio(), 0.3f, 0.5f, -toolbarWrapper.getHeight(), 0));
    metrics.showWithSheet(toolbarWrapper.getBackground(), 0.9f, 1);
    // Fade in toolbar text labels with sheet expansion.
    float alpha = scale(metrics.getTop(), 0, toolbarWrapper.getHeight(), 1f, 0f);
    toolbarTitles.setAlpha(alpha);
    Log.e("!!!", "" + alpha + " h: " + toolbarWrapper.getHeight() + " t: " + metrics.getTop());
  }
}

/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.gnd.ui;

import static com.google.android.gnd.ui.OnBottomSheetSlideBehavior.SheetSlideMetrics.scale;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gnd.R;

public class BottomSheetChromeBehavior extends OnBottomSheetSlideBehavior<ViewGroup> {
  // TODO: Refactor transitions into "TransitionEffect" classes.
  private static final float HIDE_SCRIM_THRESHOLD = 0.0f;
  private static final float SHOW_SCRIM_THRESHOLD = 0.1f;
  private static final float HIDE_ADD_BUTTON_THRESHOLD = 0.3f;
  private static final float SHOW_ADD_BUTTON_THRESHOLD = 0.5f;

  public BottomSheetChromeBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  @Override
  protected void onSheetScrolled(
    CoordinatorLayout parent, ViewGroup layout, SheetSlideMetrics metrics) {
    View scrim = layout.findViewById(R.id.bottom_sheet_bottom_inset_scrim);
    View addRecordButton = layout.findViewById(R.id.add_record_btn);
    ViewGroup toolbarWrapper = layout.findViewById(R.id.toolbar_wrapper);
    ViewGroup toolbar = toolbarWrapper.findViewById(R.id.toolbar);
    ViewGroup toolbarTitles = toolbarWrapper.findViewById(R.id.toolbar_titles_layout);
    metrics.showWithSheet(scrim, HIDE_SCRIM_THRESHOLD, SHOW_SCRIM_THRESHOLD);
    metrics.showWithSheet(addRecordButton, HIDE_ADD_BUTTON_THRESHOLD, SHOW_ADD_BUTTON_THRESHOLD);
    toolbarWrapper.setBackgroundColor(layout.getResources().getColor(R.color.colorPrimary));
    toolbarWrapper.setTranslationY(
      scale(metrics.getVisibleRatio(), 0.3f, 0.5f, -toolbarWrapper.getHeight(), 0));
    metrics.showWithSheet(toolbarWrapper.getBackground(), 0.9f, 1);
    // Fade in toolbar text labels with sheet expansion.
    float alpha = scale(metrics.getTop(), 0, toolbarWrapper.getHeight(), 1f, 0f);
    toolbarTitles.setAlpha(alpha);
  }
}

Remove debug log statement.