当前位置: 首页>>代码示例>>Java>>正文


Java ViewCompat.setOnApplyWindowInsetsListener方法代码示例

本文整理汇总了Java中android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener方法的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat.setOnApplyWindowInsetsListener方法的具体用法?Java ViewCompat.setOnApplyWindowInsetsListener怎么用?Java ViewCompat.setOnApplyWindowInsetsListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.view.ViewCompat的用法示例。


在下文中一共展示了ViewCompat.setOnApplyWindowInsetsListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ScrimInsetsFrameLayout

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.mTempRect = new Rect();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrimInsetsFrameLayout, defStyleAttr, R.style.Widget_Design_ScrimInsetsFrameLayout);
    this.mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsFrameLayout_insetForeground);
    a.recycle();
    setWillNotDraw(true);
    ViewCompat.setOnApplyWindowInsetsListener(this, new OnApplyWindowInsetsListener() {
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            if (ScrimInsetsFrameLayout.this.mInsets == null) {
                ScrimInsetsFrameLayout.this.mInsets = new Rect();
            }
            ScrimInsetsFrameLayout.this.mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
            ScrimInsetsFrameLayout.this.onInsetsChanged(ScrimInsetsFrameLayout.this.mInsets);
            ScrimInsetsFrameLayout scrimInsetsFrameLayout = ScrimInsetsFrameLayout.this;
            boolean z = ScrimInsetsFrameLayout.this.mInsets.isEmpty() || ScrimInsetsFrameLayout.this.mInsetForeground == null;
            scrimInsetsFrameLayout.setWillNotDraw(z);
            ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this);
            return insets.consumeSystemWindowInsets();
        }
    });
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:ScrimInsetsFrameLayout.java

示例2: AppBarLayout

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public AppBarLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.mTotalScrollRange = -1;
    this.mDownPreScrollRange = -1;
    this.mDownScrollRange = -1;
    this.mPendingAction = 0;
    setOrientation(1);
    ThemeUtils.checkAppCompatTheme(context);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppBarLayout, 0, R.style.Widget_Design_AppBarLayout);
    this.mTargetElevation = (float) a.getDimensionPixelSize(R.styleable.AppBarLayout_elevation, 0);
    setBackgroundDrawable(a.getDrawable(R.styleable.AppBarLayout_android_background));
    if (a.hasValue(R.styleable.AppBarLayout_expanded)) {
        setExpanded(a.getBoolean(R.styleable.AppBarLayout_expanded, false));
    }
    a.recycle();
    ViewUtils.setBoundsViewOutlineProvider(this);
    this.mListeners = new ArrayList();
    ViewCompat.setElevation(this, this.mTargetElevation);
    ViewCompat.setOnApplyWindowInsetsListener(this, new OnApplyWindowInsetsListener() {
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            return AppBarLayout.this.onWindowInsetChanged(insets);
        }
    });
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:AppBarLayout.java

示例3: setStatusBarColor

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
 * set StatusBarColor
 */
public static void setStatusBarColor(Activity activity, int statusColor) {
    Window window = activity.getWindow();

    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(statusColor);
    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

    ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
    View mChildView = mContentView.getChildAt(0);
    if (mChildView != null) {
        ViewCompat.setOnApplyWindowInsetsListener(mChildView, new OnApplyWindowInsetsListener() {
            @Override
            public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                return insets;
            }
        });
        ViewCompat.setFitsSystemWindows(mChildView, true);
        ViewCompat.requestApplyInsets(mChildView);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:StatusBarCompatLollipop.java

示例4: setupForInsets

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void setupForInsets() {
  if (Build.VERSION.SDK_INT < 21) {
    return;
  }

  if (ViewCompat.getFitsSystemWindows(this)) {
    if (mApplyWindowInsetsListener == null) {
      mApplyWindowInsetsListener =
          new android.support.v4.view.OnApplyWindowInsetsListener() {
            @Override
                          public WindowInsetsCompat onApplyWindowInsets(View v,
                                  WindowInsetsCompat insets) {
              return setWindowInsets(insets);
            }
          };
    }
    // First apply the insets listener
    ViewCompat.setOnApplyWindowInsetsListener(this, mApplyWindowInsetsListener);

    // Now set the sys ui flags to enable us to lay out in the window insets
          setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                  | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
  } else {
    ViewCompat.setOnApplyWindowInsetsListener(this, null);
  }
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:27,代码来源:CoordinatorLayout.java

示例5: onCreate

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
protected final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tabSwitcher = findViewById(R.id.tab_switcher);
    ViewCompat.setOnApplyWindowInsetsListener(tabSwitcher, createWindowInsetsListener());
    tabSwitcher.setDecorator(new Decorator());
    tabSwitcher.addListener(this);
    tabSwitcher.showToolbars(true);

    for (int i = 0; i < TAB_COUNT; i++) {
        tabSwitcher.addTab(createTab(i));
    }

    tabSwitcher.showAddTabButton(createAddTabButtonListener());
    tabSwitcher
            .setToolbarNavigationIcon(R.drawable.ic_add_box_white_24dp, createAddTabListener());
    TabSwitcher.setupWithMenu(tabSwitcher, createTabSwitcherButtonListener());
    inflateMenu();
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:21,代码来源:MainActivity.java

示例6: translucentStatusBar

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
 * translucentStatusBar(full-screen)
 * @param hideStatusBarBackground hide statusBar's shadow
 */
public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) {
    Window window = activity.getWindow();

    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    if (hideStatusBarBackground) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    } else {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
    }

    ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
    View mChildView = mContentView.getChildAt(0);
    if (mChildView != null) {
        ViewCompat.setOnApplyWindowInsetsListener(mChildView, new OnApplyWindowInsetsListener() {
            @Override
            public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                return insets;
            }
        });
        ViewCompat.setFitsSystemWindows(mChildView, false);
        ViewCompat.requestApplyInsets(mChildView);

    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:StatusBarCompatLollipop.java

示例7: setStatusBarColorForCollapsingToolbar

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
 * compat for CollapsingToolbarLayout
 */
public static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, CollapsingToolbarLayout collapsingToolbarLayout,
                                                         Toolbar toolbar, int statusColor) {
    Window window = activity.getWindow();

    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.TRANSPARENT);
    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

    ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
    View mChildView = mContentView.getChildAt(0);
    if (mChildView != null) {
        ViewCompat.setOnApplyWindowInsetsListener(mChildView, new OnApplyWindowInsetsListener() {
            @Override
            public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                return insets;
            }
        });
        ViewCompat.setFitsSystemWindows(mChildView, true);
        ViewCompat.requestApplyInsets(mChildView);
    }

    ((View) appBarLayout.getParent()).setFitsSystemWindows(true);
    appBarLayout.setFitsSystemWindows(true);
    collapsingToolbarLayout.setFitsSystemWindows(true);
    collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(true);
    toolbar.setFitsSystemWindows(false);

    collapsingToolbarLayout.setStatusBarScrimColor(statusColor);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:StatusBarCompatLollipop.java

示例8: QMUIWindowInsetHelper

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public QMUIWindowInsetHelper(ViewGroup viewGroup, IWindowInsetLayout windowInsetLayout) {
    mWindowInsetLayoutWR = new WeakReference<>(windowInsetLayout);
    KEYBOARD_HEIGHT_BOUNDARY = QMUIDisplayHelper.dp2px(viewGroup.getContext(), 100);
    ViewCompat.setOnApplyWindowInsetsListener(viewGroup,
            new android.support.v4.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v,
                                                              WindowInsetsCompat insets) {
                    return setWindowInsets(insets);
                }
            });
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:13,代码来源:QMUIWindowInsetHelper.java

示例9: initViewPager

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;

    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);

    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());

    if (ViewCompat.getImportantForAccessibility(this)
            == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this,
                ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4.view.OnApplyWindowInsetsListener() {
                private final Rect mTempRect = new Rect();

                @Override
                public WindowInsetsCompat onApplyWindowInsets(final View v,
                                                              final WindowInsetsCompat originalInsets) {
                    // First let the ViewPager itself try and consume them...
                    final WindowInsetsCompat applied =
                            ViewCompat.onApplyWindowInsets(v, originalInsets);
                    if (applied.isConsumed()) {
                        // If the ViewPager consumed all insets, return now
                        return applied;
                    }

                    // Now we'll manually dispatch the insets to our children. Since ViewPager
                    // children are always full-height, we do not want to use the standard
                    // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them,
                    // the rest of the children will not receive any insets. To workaround this
                    // we manually dispatch the applied insets, not allowing children to
                    // consume them from each other. We do however keep track of any insets
                    // which are consumed, returning the union of our children's consumption
                    final Rect res = mTempRect;
                    res.left = applied.getSystemWindowInsetLeft();
                    res.top = applied.getSystemWindowInsetTop();
                    res.right = applied.getSystemWindowInsetRight();
                    res.bottom = applied.getSystemWindowInsetBottom();

                    for (int i = 0, count = getChildCount(); i < count; i++) {
                        final WindowInsetsCompat childInsets = ViewCompat
                                .dispatchApplyWindowInsets(getChildAt(i), applied);
                        // Now keep track of any consumed by tracking each dimension's min
                        // value
                        res.left = Math.min(childInsets.getSystemWindowInsetLeft(),
                                res.left);
                        res.top = Math.min(childInsets.getSystemWindowInsetTop(),
                                res.top);
                        res.right = Math.min(childInsets.getSystemWindowInsetRight(),
                                res.right);
                        res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(),
                                res.bottom);
                    }

                    // Now return a new WindowInsets, using the consumed window insets
                    return applied.replaceSystemWindowInsets(
                            res.left, res.top, res.right, res.bottom);
                }
            });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:79,代码来源:DirectionalViewpager.java

示例10: onCreate

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_view_pager);

	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	setSupportActionBar(toolbar);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);

	HeaderView headerView = (HeaderView) findViewById(R.id.toolbar_header_view);
	headerView.bindTo(getString(R.string.app_name), getString(R.string.viewpager));

	// Create the adapter that will return a fragment for each of the three
	// primary sections of the activity.
	mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

	// Set up the ViewPager with the sections adapter.
	mViewPager = (ViewPager) findViewById(R.id.view_pager);
	mViewPager.setAdapter(mSectionsPagerAdapter);

	TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
	tabLayout.setupWithViewPager(mViewPager);

	//Coordinatorlayout Status Bar Padding Disappears From Viewpager 2nd-page
	//http://stackoverflow.com/questions/31368781/coordinatorlayout-status-bar-padding-disappears-from-viewpager-2nd-page
	ViewCompat.setOnApplyWindowInsetsListener(mViewPager, new OnApplyWindowInsetsListener() {
		@Override
		public WindowInsetsCompat onApplyWindowInsets(View v,
													  WindowInsetsCompat insets) {
			insets = ViewCompat.onApplyWindowInsets(v, insets);
			if (insets.isConsumed()) {
				return insets;
			}

			boolean consumed = false;
			for (int i = 0, count = mViewPager.getChildCount(); i < count; i++) {
				ViewCompat.dispatchApplyWindowInsets(mViewPager.getChildAt(i), insets);
				if (insets.isConsumed()) {
					consumed = true;
				}
			}
			return consumed ? insets.consumeSystemWindowInsets() : insets;
		}
	});
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:46,代码来源:ViewPagerActivity.java

示例11: initViewPager

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;

    mTouchSlop = configuration.getScaledPagingTouchSlop();
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);

    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());

    if (ViewCompat.getImportantForAccessibility(this)
            == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this,
                ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4.view.OnApplyWindowInsetsListener() {
                private final Rect mTempRect = new Rect();

                @Override
                public WindowInsetsCompat onApplyWindowInsets(final View v,
                                                              final WindowInsetsCompat originalInsets) {
                    // First let the ViewPager itself try and consume them...
                    final WindowInsetsCompat applied =
                            ViewCompat.onApplyWindowInsets(v, originalInsets);
                    if (applied.isConsumed()) {
                        // If the ViewPager consumed all insets, return now
                        return applied;
                    }

                    // Now we'll manually dispatch the insets to our children. Since ViewPager
                    // children are always full-height, we do not want to use the standard
                    // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them,
                    // the rest of the children will not receive any insets. To workaround this
                    // we manually dispatch the applied insets, not allowing children to
                    // consume them from each other. We do however keep track of any insets
                    // which are consumed, returning the union of our children's consumption
                    final Rect res = mTempRect;
                    res.left = applied.getSystemWindowInsetLeft();
                    res.top = applied.getSystemWindowInsetTop();
                    res.right = applied.getSystemWindowInsetRight();
                    res.bottom = applied.getSystemWindowInsetBottom();

                    for (int i = 0, count = getChildCount(); i < count; i++) {
                        final WindowInsetsCompat childInsets = ViewCompat
                                .dispatchApplyWindowInsets(getChildAt(i), applied);
                        // Now keep track of any consumed by tracking each dimension's min
                        // value
                        res.left = Math.min(childInsets.getSystemWindowInsetLeft(),
                                res.left);
                        res.top = Math.min(childInsets.getSystemWindowInsetTop(),
                                res.top);
                        res.right = Math.min(childInsets.getSystemWindowInsetRight(),
                                res.right);
                        res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(),
                                res.bottom);
                    }

                    // Now return a new WindowInsets, using the consumed window insets
                    return applied.replaceSystemWindowInsets(
                            res.left, res.top, res.right, res.bottom);
                }
            });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:79,代码来源:BaseViewPager.java

示例12: QMUICollapsingTopBarLayout

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public QMUICollapsingTopBarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mCollapsingTextHelper = new QMUICollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(QMUIInterpolatorStaticHolder.DECELERATE_INTERPOLATOR);

    QMUIViewHelper.checkAppCompatTheme(context);

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.QMUICollapsingTopBarLayout, defStyleAttr, 0);

    mCollapsingTextHelper.setExpandedTextGravity(
            a.getInt(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleGravity,
                    Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));
    mCollapsingTextHelper.setCollapsedTextGravity(
            a.getInt(R.styleable.QMUICollapsingTopBarLayout_qmui_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));


    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom =
            a.getDimensionPixelSize(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginStart)) {
        mExpandedMarginStart = a.getDimensionPixelSize(
                R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(
                R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginEnd, 0);
    }
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(
                R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginTop, 0);
    }
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(
                R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.QMUICollapsingTopBarLayout_qmui_titleEnabled, true);
    setTitle(a.getText(R.styleable.QMUICollapsingTopBarLayout_qmui_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.QMUI_CollapsingTopBarLayoutExpanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(R.style.QMUI_CollapsingTopBarLayoutCollapsed);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.QMUICollapsingTopBarLayout_qmui_collapsedTitleTextAppearance, 0));
    }

    mScrimVisibleHeightTrigger = a.getDimensionPixelSize(
            R.styleable.QMUICollapsingTopBarLayout_qmui_scrimVisibleHeightTrigger, -1);

    mScrimAnimationDuration = a.getInt(
            R.styleable.QMUICollapsingTopBarLayout_qmui_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    setContentScrim(a.getDrawable(R.styleable.QMUICollapsingTopBarLayout_qmui_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.QMUICollapsingTopBarLayout_qmui_statusBarScrim));

    mTopBarId = a.getResourceId(R.styleable.QMUICollapsingTopBarLayout_qmui_topBarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    return setWindowInsets(insets);
                }
            });
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:81,代码来源:QMUICollapsingTopBarLayout.java

示例13: QMUICollapsingTopBarLayout

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public QMUICollapsingTopBarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mCollapsingTextHelper = new QMUICollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(QMUIInterpolatorStaticHolder.DECELERATE_INTERPOLATOR);

    QMUIViewHelper.checkAppCompatTheme(context);

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.QMUICollapsingTopBarLayout, defStyleAttr, 0);

    mCollapsingTextHelper.setExpandedTextGravity(
            a.getInt(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleGravity,
                    Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));
    mCollapsingTextHelper.setCollapsedTextGravity(
            a.getInt(R.styleable.QMUICollapsingTopBarLayout_qmui_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));


    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom =
            a.getDimensionPixelSize(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginStart)) {
        mExpandedMarginStart = a.getDimensionPixelSize(
                R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(
                R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginEnd, 0);
    }
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(
                R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginTop, 0);
    }
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(
                R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.QMUICollapsingTopBarLayout_qmui_titleEnabled, true);
    setTitle(a.getText(R.styleable.QMUICollapsingTopBarLayout_qmui_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.QMUI_CollapsingTopBarLayoutExpanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(R.style.QMUI_CollapsingTopBarLayoutCollapsed);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.QMUICollapsingTopBarLayout_qmui_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.QMUICollapsingTopBarLayout_qmui_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.QMUICollapsingTopBarLayout_qmui_collapsedTitleTextAppearance, 0));
    }

    mScrimVisibleHeightTrigger = a.getDimensionPixelSize(
            R.styleable.QMUICollapsingTopBarLayout_qmui_scrimVisibleHeightTrigger, -1);

    mScrimAnimationDuration = a.getInt(
            R.styleable.QMUICollapsingTopBarLayout_qmui_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    setContentScrim(a.getDrawable(R.styleable.QMUICollapsingTopBarLayout_qmui_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.QMUICollapsingTopBarLayout_qmui_statusBarScrim));

    mTopBarId = a.getResourceId(R.styleable.QMUICollapsingTopBarLayout_qmui_topBarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v,
                                                              WindowInsetsCompat insets) {
                    return onWindowInsetChanged(insets);
                }
            });
}
 
开发者ID:coopese,项目名称:qmui,代码行数:82,代码来源:QMUICollapsingTopBarLayout.java

示例14: initViewPager

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;

    mTouchSlop = configuration.getScaledPagingTouchSlop();
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);

    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new YViewPager.MyAccessibilityDelegate());

    if (ViewCompat.getImportantForAccessibility(this)
            == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this,
                ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4.view.OnApplyWindowInsetsListener() {
                private final Rect mTempRect = new Rect();

                @Override
                public WindowInsetsCompat onApplyWindowInsets(final View v,
                                                              final WindowInsetsCompat originalInsets) {
                    // First let the ViewPager itself try and consume them...
                    final WindowInsetsCompat applied =
                            ViewCompat.onApplyWindowInsets(v, originalInsets);
                    if (applied.isConsumed()) {
                        // If the ViewPager consumed all insets, return now
                        return applied;
                    }

                    // Now we'll manually dispatch the insets to our children. Since ViewPager
                    // children are always full-height, we do not want to use the standard
                    // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them,
                    // the rest of the children will not receive any insets. To workaround this
                    // we manually dispatch the applied insets, not allowing children to
                    // consume them from each other. We do however keep track of any insets
                    // which are consumed, returning the union of our children's consumption
                    final Rect res = mTempRect;
                    res.left = applied.getSystemWindowInsetLeft();
                    res.top = applied.getSystemWindowInsetTop();
                    res.right = applied.getSystemWindowInsetRight();
                    res.bottom = applied.getSystemWindowInsetBottom();

                    for (int i = 0, count = getChildCount(); i < count; i++) {
                        final WindowInsetsCompat childInsets = ViewCompat
                                .dispatchApplyWindowInsets(getChildAt(i), applied);
                        // Now keep track of any consumed by tracking each dimension's min
                        // value
                        res.left = Math.min(childInsets.getSystemWindowInsetLeft(),
                                res.left);
                        res.top = Math.min(childInsets.getSystemWindowInsetTop(),
                                res.top);
                        res.right = Math.min(childInsets.getSystemWindowInsetRight(),
                                res.right);
                        res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(),
                                res.bottom);
                    }

                    // Now return a new WindowInsets, using the consumed window insets
                    return applied.replaceSystemWindowInsets(
                            res.left, res.top, res.right, res.bottom);
                }
            });
}
 
开发者ID:youngkaaa,项目名称:YViewPagerDemo,代码行数:79,代码来源:YViewPager.java

示例15: initViewPager

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;

    mTouchSlop = configuration.getScaledPagingTouchSlop();
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);

    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new YViewPagerNew.MyAccessibilityDelegate());

    if (ViewCompat.getImportantForAccessibility(this)
            == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this,
                ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4.view.OnApplyWindowInsetsListener() {
                private final Rect mTempRect = new Rect();

                @Override
                public WindowInsetsCompat onApplyWindowInsets(final View v,
                                                              final WindowInsetsCompat originalInsets) {
                    // First let the ViewPager itself try and consume them...
                    final WindowInsetsCompat applied =
                            ViewCompat.onApplyWindowInsets(v, originalInsets);
                    if (applied.isConsumed()) {
                        // If the ViewPager consumed all insets, return now
                        return applied;
                    }

                    // Now we'll manually dispatch the insets to our children. Since ViewPager
                    // children are always full-height, we do not want to use the standard
                    // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them,
                    // the rest of the children will not receive any insets. To workaround this
                    // we manually dispatch the applied insets, not allowing children to
                    // consume them from each other. We do however keep track of any insets
                    // which are consumed, returning the union of our children's consumption
                    final Rect res = mTempRect;
                    res.left = applied.getSystemWindowInsetLeft();
                    res.top = applied.getSystemWindowInsetTop();
                    res.right = applied.getSystemWindowInsetRight();
                    res.bottom = applied.getSystemWindowInsetBottom();

                    for (int i = 0, count = getChildCount(); i < count; i++) {
                        final WindowInsetsCompat childInsets = ViewCompat
                                .dispatchApplyWindowInsets(getChildAt(i), applied);
                        // Now keep track of any consumed by tracking each dimension's min
                        // value
                        res.left = Math.min(childInsets.getSystemWindowInsetLeft(),
                                res.left);
                        res.top = Math.min(childInsets.getSystemWindowInsetTop(),
                                res.top);
                        res.right = Math.min(childInsets.getSystemWindowInsetRight(),
                                res.right);
                        res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(),
                                res.bottom);
                    }

                    // Now return a new WindowInsets, using the consumed window insets
                    return applied.replaceSystemWindowInsets(
                            res.left, res.top, res.right, res.bottom);
                }
            });
}
 
开发者ID:youngkaaa,项目名称:YViewPagerDemo,代码行数:79,代码来源:YViewPagerNew.java


注:本文中的android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。