Пример #1
0
 public void onAnimationEnd(View view) {
   if (ae.a(a) && ae.b(a) != null) {
     ViewCompat.setTranslationY(ae.b(a), 0.0F);
     ViewCompat.setTranslationY(ae.c(a), 0.0F);
   }
   if (ae.d(a) != null && ae.e(a) == 1) {
     ae.d(a).setVisibility(8);
   }
   ae.c(a).setVisibility(8);
   ae.c(a).setTransitioning(false);
   ae.a(a, null);
   a.e();
   if (ae.f(a) != null) {
     ViewCompat.requestApplyInsets(ae.f(a));
   }
 }
  /**
   * change to full screen mode
   *
   * @param hideStatusBarBackground hide status bar Background when SDK > 21, true if hide it
   */
  public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) {
    Window window = activity.getWindow();
    ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);

    // set child View not fill the system window
    View mChildView = mContentView.getChildAt(0);
    if (mChildView != null) {
      ViewCompat.setFitsSystemWindows(mChildView, false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      int statusBarHeight = getStatusBarHeight(activity);

      // First translucent status bar.
      window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // After LOLLIPOP just set LayoutParams.
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        if (hideStatusBarBackground) {
          window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
          window.setStatusBarColor(Color.parseColor("#00000000"));
        } else {
          window.setStatusBarColor(Color.parseColor("#55000000"));
        }
        // must call requestLayout, otherwise it will have space in screen bottom
        if (mChildView != null) {
          ViewCompat.requestApplyInsets(mChildView);
        }
      } else {
        if (mChildView != null
            && mChildView.getLayoutParams() != null
            && mChildView.getLayoutParams().height == statusBarHeight) {
          // Before LOLLIPOP need remove fake status bar view.
          mContentView.removeView(mChildView);
          mChildView = mContentView.getChildAt(0);
        }
        if (mChildView != null) {
          FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams();
          // cancel the margin top
          if (lp != null && lp.topMargin >= statusBarHeight) {
            lp.topMargin -= statusBarHeight;
            mChildView.setLayoutParams(lp);
          }
        }
      }
    }
  }
 @Override
 public void onDestroyActionMode(ActionMode mode) {
   mWrapped.onDestroyActionMode(mode);
   if (mActionModePopup != null) {
     mWindow.getDecorView().removeCallbacks(mShowActionModePopup);
     mActionModePopup.dismiss();
   } else if (mActionModeView != null) {
     mActionModeView.setVisibility(View.GONE);
     if (mActionModeView.getParent() != null) {
       ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
     }
   }
   if (mActionModeView != null) {
     mActionModeView.removeAllViews();
   }
   if (mAppCompatCallback != null) {
     mAppCompatCallback.onSupportActionModeFinished(mActionMode);
   }
   mActionMode = null;
 }
Пример #4
0
  protected void applyInsetsToViewMargin(View view) {
    ViewCompat.setOnApplyWindowInsetsListener(
        view,
        new OnApplyWindowInsetsListener() {
          private int mInitialBottom = -1;

          @Override
          public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            synchronized (LOCK) {
              ViewGroup.MarginLayoutParams layoutParams =
                  (ViewGroup.MarginLayoutParams) v.getLayoutParams();
              if (mInitialBottom == -1) mInitialBottom = layoutParams.bottomMargin;
              layoutParams.bottomMargin = mInitialBottom + insets.getSystemWindowInsetBottom();
              v.setLayoutParams(layoutParams);
              return insets;
            }
          }
        });
    ViewCompat.requestApplyInsets(view);
  }
Пример #5
0
  /**
   * Applies any window insets apart from the top inset to the view.
   *
   * <p>Must be called in/after onViewCreated
   */
  protected void applyInsetsToView(View view) {
    ViewCompat.setOnApplyWindowInsetsListener(
        view,
        new OnApplyWindowInsetsListener() {
          private int mInitialBottom = -1;

          @Override
          public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            synchronized (LOCK) {
              if (mInitialBottom == -1) mInitialBottom = v.getPaddingBottom();
              v.setPaddingRelative(
                  v.getPaddingStart(),
                  v.getPaddingTop(),
                  v.getPaddingEnd(),
                  mInitialBottom + insets.getSystemWindowInsetBottom());
              return insets;
            }
          }
        });
    ViewCompat.requestApplyInsets(view);
  }
  ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) {
    if (mActionMode != null) {
      mActionMode.finish();
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);

    if (mActionModeView == null) {
      // Use the action bar theme.
      final Context actionBarContext;
      actionBarContext =
          ThemeUtils.getActionBarThemedContext(
              mActivity, mThemed.getCurrentThemeResourceId(), mThemed.getCurrentThemeColor());

      mActionModeView = new ActionBarContextView(actionBarContext);
      mActionModePopup =
          new PopupWindow(
              actionBarContext,
              null,
              android.support.v7.appcompat.R.attr.actionModePopupWindowStyle);
      mActionModePopup.setContentView(mActionModeView);

      final TypedValue outValue = new TypedValue();
      actionBarContext
          .getTheme()
          .resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, outValue, true);
      final int height =
          TypedValue.complexToDimensionPixelSize(
              outValue.data, actionBarContext.getResources().getDisplayMetrics());
      mActionModeView.setContentHeight(height);
      ThemeUtils.setActionBarContextViewBackground(
          mActionModeView,
          mThemed.getCurrentThemeResourceId(),
          mThemed.getCurrentThemeColor(),
          mThemed.getCurrentThemeBackgroundOption(),
          false);
      mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
      final Rect actionModeBounds = getActionModeBounds();
      if (actionModeBounds != null) {
        mActionModePopup.setWidth(actionModeBounds.width());
      } else {
        mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
      }
      mShowActionModePopup =
          new Runnable() {
            @Override
            public void run() {
              if (actionModeBounds != null) {
                mActionModePopup.showAtLocation(
                    mWindow.getDecorView(),
                    Gravity.TOP | Gravity.LEFT,
                    actionModeBounds.left,
                    actionModeBounds.top);
              } else {
                mActionModePopup.showAtLocation(
                    mWindow.getDecorView(), Gravity.TOP | Gravity.LEFT, 0, 0);
              }
            }
          };
    }

    if (mActionModeView != null) {
      mActionModeView.killMode();
      ActionMode mode =
          new StandaloneActionMode(
              mActionModeView.getContext(),
              mActionModeView,
              wrappedCallback,
              mActionModePopup == null);
      if (callback.onCreateActionMode(mode, mode.getMenu())) {
        mode.invalidate();
        mActionModeView.initForMode(mode);
        mActionModeView.setVisibility(View.VISIBLE);
        mActionMode = mode;
        if (mActionModePopup != null) {
          mWindow.getDecorView().post(mShowActionModePopup);
        }
        mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);

        if (mActionModeView.getParent() != null) {
          ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
        }
      } else {
        mActionMode = null;
      }
    }
    if (mActionMode != null && mAppCompatCallback != null) {
      mAppCompatCallback.onSupportActionModeStarted(mActionMode);
    }
    return mActionMode;
  }