<commit_before>// 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
//
//      http://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.firebase.inappmessaging.display.internal;

import android.app.Activity;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Build;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import com.google.firebase.inappmessaging.display.internal.bindingwrappers.BindingWrapper;
import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * Class encapsulating the popup window into which we inflate the in app message. The window manager
 * keeps state of the binding that is currently in view
 *
 * @hide
 */
@Singleton
public class FiamWindowManager {

  static final int DEFAULT_TYPE = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;

  private BindingWrapper bindingWrapper;

  @Inject
  FiamWindowManager() {}

  /** Inflate the container into a new popup window */
  public void show(@NonNull final BindingWrapper bindingWrapper, @NonNull Activity activity) {
    if (isFiamDisplayed()) {
      Logging.loge("Fiam already active. Cannot show new Fiam.");
      return;
    }

    InAppMessageLayoutConfig config = bindingWrapper.getConfig();
    final WindowManager.LayoutParams layoutParams = getLayoutParams(config, activity);

    final WindowManager windowManager = getWindowManager(activity);
    final View rootView = bindingWrapper.getRootView();
    windowManager.addView(rootView, layoutParams);

    // Set 'window' left and right padding from the inset, this prevents
    // anything from touching the navigation bar when in landscape.
    Rect insetDimensions = getInsetDimensions(activity);
    Logging.logdPair("Inset (top, bottom)", insetDimensions.top, insetDimensions.bottom);
    Logging.logdPair("Inset (left, right)", insetDimensions.left, insetDimensions.right);

    // TODO: Should use WindowInsetCompat to make sure we don't overlap with the status bar
    //       action bar or anything else. This will become more pressing as notches
    //       become more common on Android phones.

    if (bindingWrapper.canSwipeToDismiss()) {
      SwipeDismissTouchListener listener =
          getSwipeListener(config, bindingWrapper, windowManager, layoutParams);
      bindingWrapper.getDialogView().setOnTouchListener(listener);
    }

    this.bindingWrapper = bindingWrapper;
  }

  public boolean isFiamDisplayed() {
    return bindingWrapper != null;<commit_msg>Change FIAM window manager visibility check (#941)<commit_after>// 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
//
//      http://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.firebase.inappmessaging.display.internal;

import android.app.Activity;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Build;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import com.google.firebase.inappmessaging.display.internal.bindingwrappers.BindingWrapper;
import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * Class encapsulating the popup window into which we inflate the in app message. The window manager
 * keeps state of the binding that is currently in view
 *
 * @hide
 */
@Singleton
public class FiamWindowManager {

  static final int DEFAULT_TYPE = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;

  private BindingWrapper bindingWrapper;

  @Inject
  FiamWindowManager() {}

  /** Inflate the container into a new popup window */
  public void show(@NonNull final BindingWrapper bindingWrapper, @NonNull Activity activity) {
    if (isFiamDisplayed()) {
      Logging.loge("Fiam already active. Cannot show new Fiam.");
      return;
    }

    InAppMessageLayoutConfig config = bindingWrapper.getConfig();
    final WindowManager.LayoutParams layoutParams = getLayoutParams(config, activity);

    final WindowManager windowManager = getWindowManager(activity);
    final View rootView = bindingWrapper.getRootView();
    windowManager.addView(rootView, layoutParams);

    // Set 'window' left and right padding from the inset, this prevents
    // anything from touching the navigation bar when in landscape.
    Rect insetDimensions = getInsetDimensions(activity);
    Logging.logdPair("Inset (top, bottom)", insetDimensions.top, insetDimensions.bottom);
    Logging.logdPair("Inset (left, right)", insetDimensions.left, insetDimensions.right);

    // TODO: Should use WindowInsetCompat to make sure we don't overlap with the status bar
    //       action bar or anything else. This will become more pressing as notches
    //       become more common on Android phones.

    if (bindingWrapper.canSwipeToDismiss()) {
      SwipeDismissTouchListener listener =
          getSwipeListener(config, bindingWrapper, windowManager, layoutParams);
      bindingWrapper.getDialogView().setOnTouchListener(listener);
    }

    this.bindingWrapper = bindingWrapper;
  }

  public boolean isFiamDisplayed() {
    if (bindingWrapper == null) {
      return false;
    }
    return bindingWrapper.getRootView().isShown();
{'fraction_non_alphanumeric': 0.08383418092155956, 'fraction_numerical': 0.0029280320542456463, 'mean_word_length': 4.229653505237711, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4675895', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1666, 'n_words': 581}