use of android.view.WindowInsets in project platform_frameworks_base by android.
the class ActionBarOverlayLayout method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
pullChildren();
int maxHeight = 0;
int maxWidth = 0;
int childState = 0;
int topInset = 0;
int bottomInset = 0;
measureChildWithMargins(mActionBarTop, widthMeasureSpec, 0, heightMeasureSpec, 0);
LayoutParams lp = (LayoutParams) mActionBarTop.getLayoutParams();
maxWidth = Math.max(maxWidth, mActionBarTop.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
maxHeight = Math.max(maxHeight, mActionBarTop.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
childState = combineMeasuredStates(childState, mActionBarTop.getMeasuredState());
// xlarge screen layout doesn't have bottom action bar.
if (mActionBarBottom != null) {
measureChildWithMargins(mActionBarBottom, widthMeasureSpec, 0, heightMeasureSpec, 0);
lp = (LayoutParams) mActionBarBottom.getLayoutParams();
maxWidth = Math.max(maxWidth, mActionBarBottom.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
maxHeight = Math.max(maxHeight, mActionBarBottom.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
childState = combineMeasuredStates(childState, mActionBarBottom.getMeasuredState());
}
final int vis = getWindowSystemUiVisibility();
final boolean stable = (vis & SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0;
if (stable) {
// This is the standard space needed for the action bar. For stable measurement,
// we can't depend on the size currently reported by it -- this must remain constant.
topInset = mActionBarHeight;
if (mHasNonEmbeddedTabs) {
final View tabs = mActionBarTop.getTabContainer();
if (tabs != null) {
// If tabs are not embedded, increase space on top to account for them.
topInset += mActionBarHeight;
}
}
} else if (mActionBarTop.getVisibility() != GONE) {
// This is the space needed on top of the window for all of the action bar
// and tabs.
topInset = mActionBarTop.getMeasuredHeight();
}
if (mDecorToolbar.isSplit()) {
// If action bar is split, adjust bottom insets for it.
if (mActionBarBottom != null) {
if (stable) {
bottomInset = mActionBarHeight;
} else {
bottomInset = mActionBarBottom.getMeasuredHeight();
}
}
}
// If the window has not requested system UI layout flags, we need to
// make sure its content is not being covered by system UI... though it
// will still be covered by the action bar if they have requested it to
// overlay.
mContentInsets.set(mBaseContentInsets);
mInnerInsets.set(mBaseInnerInsets);
if (!mOverlayMode && !stable) {
mContentInsets.top += topInset;
mContentInsets.bottom += bottomInset;
} else {
mInnerInsets.top += topInset;
mInnerInsets.bottom += bottomInset;
}
applyInsets(mContent, mContentInsets, true, true, true, true);
if (!mLastInnerInsets.equals(mInnerInsets)) {
// If the inner insets have changed, we need to dispatch this down to
// the app's fitSystemWindows(). We do this before measuring the content
// view to keep the same semantics as the normal fitSystemWindows() call.
mLastInnerInsets.set(mInnerInsets);
mContent.dispatchApplyWindowInsets(new WindowInsets(mInnerInsets));
}
measureChildWithMargins(mContent, widthMeasureSpec, 0, heightMeasureSpec, 0);
lp = (LayoutParams) mContent.getLayoutParams();
maxWidth = Math.max(maxWidth, mContent.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
maxHeight = Math.max(maxHeight, mContent.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
childState = combineMeasuredStates(childState, mContent.getMeasuredState());
// Account for padding too
maxWidth += getPaddingLeft() + getPaddingRight();
maxHeight += getPaddingTop() + getPaddingBottom();
// Check against our minimum height and width
maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT));
}
use of android.view.WindowInsets in project plaid by nickbutcher.
the class HomeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ButterKnife.bind(this);
drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
setActionBar(toolbar);
if (savedInstanceState == null) {
animateToolbar();
}
setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this));
dribbblePrefs = DribbblePrefs.get(this);
designerNewsPrefs = DesignerNewsPrefs.get(this);
filtersAdapter = new FilterAdapter(this, SourceManager.getSources(this), new FilterAdapter.FilterAuthoriser() {
@Override
public void requestDribbbleAuthorisation(View sharedElement, Source forSource) {
Intent login = new Intent(HomeActivity.this, DribbbleLogin.class);
MorphTransform.addExtras(login, ContextCompat.getColor(HomeActivity.this, R.color.background_dark), sharedElement.getHeight() / 2);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(HomeActivity.this, sharedElement, getString(R.string.transition_dribbble_login));
startActivityForResult(login, getAuthSourceRequestCode(forSource), options.toBundle());
}
});
dataManager = new DataManager(this, filtersAdapter) {
@Override
public void onDataLoaded(List<? extends PlaidItem> data) {
adapter.addAndResort(data);
checkEmptyState();
}
};
adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
grid.setAdapter(adapter);
layoutManager = new GridLayoutManager(this, columns);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return adapter.getItemColumnSpan(position);
}
});
grid.setLayoutManager(layoutManager);
grid.addOnScrollListener(toolbarElevation);
grid.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
@Override
public void onLoadMore() {
dataManager.loadAllDataSources();
}
});
grid.setHasFixedSize(true);
grid.addItemDecoration(new GridItemDividerDecoration(adapter.getDividedViewHolderClasses(), this, R.dimen.divider_height, R.color.divider));
grid.setItemAnimator(new HomeGridItemAnimator());
// drawer layout treats fitsSystemWindows specially so we have to handle insets ourselves
drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
// inset the toolbar down by the status bar height
ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
lpToolbar.topMargin += insets.getSystemWindowInsetTop();
lpToolbar.leftMargin += insets.getSystemWindowInsetLeft();
lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(lpToolbar);
// inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
grid.setPadding(// landscape
grid.getPaddingLeft() + insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(HomeActivity.this), // landscape
grid.getPaddingRight() + insets.getSystemWindowInsetRight(), grid.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// inset the fab for the navbar
ViewGroup.MarginLayoutParams lpFab = (ViewGroup.MarginLayoutParams) fab.getLayoutParams();
// portrait
lpFab.bottomMargin += insets.getSystemWindowInsetBottom();
// landscape
lpFab.rightMargin += insets.getSystemWindowInsetRight();
fab.setLayoutParams(lpFab);
View postingStub = findViewById(R.id.stub_posting_progress);
ViewGroup.MarginLayoutParams lpPosting = (ViewGroup.MarginLayoutParams) postingStub.getLayoutParams();
// portrait
lpPosting.bottomMargin += insets.getSystemWindowInsetBottom();
// landscape
lpPosting.rightMargin += insets.getSystemWindowInsetRight();
postingStub.setLayoutParams(lpPosting);
// we place a background behind the status bar to combine with it's semi-transparent
// color to get the desired appearance. Set it's height to the status bar height
View statusBarBackground = findViewById(R.id.status_bar_background);
FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
lpStatus.height = insets.getSystemWindowInsetTop();
statusBarBackground.setLayoutParams(lpStatus);
// inset the filters list for the status bar / navbar
// need to set the padding end for landscape case
final boolean ltr = filtersList.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
filtersList.setPaddingRelative(filtersList.getPaddingStart(), filtersList.getPaddingTop() + insets.getSystemWindowInsetTop(), filtersList.getPaddingEnd() + (ltr ? insets.getSystemWindowInsetRight() : 0), filtersList.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// clear this listener so insets aren't re-applied
drawer.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
setupTaskDescription();
filtersList.setAdapter(filtersAdapter);
filtersList.setItemAnimator(new FilterAdapter.FilterAnimator());
filtersAdapter.registerFilterChangedCallback(filtersChangedCallbacks);
dataManager.loadAllDataSources();
ItemTouchHelper.Callback callback = new FilterTouchHelperCallback(filtersAdapter);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(filtersList);
checkEmptyState();
}
use of android.view.WindowInsets in project plaid by nickbutcher.
the class PlayerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dribbble_player);
ButterKnife.bind(this);
circleTransform = new CircleTransform(this);
chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this);
final Intent intent = getIntent();
if (intent.hasExtra(EXTRA_PLAYER)) {
player = intent.getParcelableExtra(EXTRA_PLAYER);
bindPlayer();
} else if (intent.hasExtra(EXTRA_PLAYER_NAME)) {
String name = intent.getStringExtra(EXTRA_PLAYER_NAME);
playerName.setText(name);
if (intent.hasExtra(EXTRA_PLAYER_ID)) {
long userId = intent.getLongExtra(EXTRA_PLAYER_ID, 0L);
loadPlayer(userId);
} else if (intent.hasExtra(EXTRA_PLAYER_USERNAME)) {
String username = intent.getStringExtra(EXTRA_PLAYER_USERNAME);
loadPlayer(username);
}
} else if (intent.getData() != null) {
// todo support url intents
}
// setup immersive mode i.e. draw behind the system chrome & adjust insets
draggableFrame.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
draggableFrame.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
final ViewGroup.MarginLayoutParams lpFrame = (ViewGroup.MarginLayoutParams) draggableFrame.getLayoutParams();
// landscape
lpFrame.leftMargin += insets.getSystemWindowInsetLeft();
// landscape
lpFrame.rightMargin += insets.getSystemWindowInsetRight();
((ViewGroup.MarginLayoutParams) avatar.getLayoutParams()).topMargin += insets.getSystemWindowInsetTop();
ViewUtils.setPaddingTop(container, insets.getSystemWindowInsetTop());
ViewUtils.setPaddingBottom(shots, insets.getSystemWindowInsetBottom());
// clear this listener so insets aren't re-applied
draggableFrame.setOnApplyWindowInsetsListener(null);
return insets;
}
});
setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this));
}
use of android.view.WindowInsets in project Douya by DreaminginCodeZH.
the class DispatchInsetsHelper method dispatchInsetsToChild.
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
private void dispatchInsetsToChild(int layoutDirection, View child, ViewGroup.LayoutParams childLayoutParams) {
int childGravity = GravityCompat.getAbsoluteGravity(mDelegate.getGravityFromLayoutParams(childLayoutParams), layoutDirection);
// In fact equivalent to the algorithm in Gravity.apply().
int childInsetLeft = mInsets.getSystemWindowInsetLeft();
int childInsetRight = mInsets.getSystemWindowInsetRight();
if (childLayoutParams.width != FrameLayout.LayoutParams.MATCH_PARENT) {
if ((childGravity & (Gravity.AXIS_PULL_BEFORE << Gravity.AXIS_X_SHIFT)) == 0) {
childInsetLeft = 0;
}
if ((childGravity & (Gravity.AXIS_PULL_AFTER << Gravity.AXIS_X_SHIFT)) == 0) {
childInsetRight = 0;
}
}
int childInsetTop = mInsets.getSystemWindowInsetTop();
int childInsetBottom = mInsets.getSystemWindowInsetBottom();
if (childLayoutParams.height != FrameLayout.LayoutParams.MATCH_PARENT) {
if ((childGravity & (Gravity.AXIS_PULL_BEFORE << Gravity.AXIS_Y_SHIFT)) == 0) {
childInsetTop = 0;
}
if ((childGravity & (Gravity.AXIS_PULL_AFTER << Gravity.AXIS_Y_SHIFT)) == 0) {
childInsetBottom = 0;
}
}
WindowInsets childInsets = mInsets.replaceSystemWindowInsets(childInsetLeft, childInsetTop, childInsetRight, childInsetBottom);
child.dispatchApplyWindowInsets(childInsets);
}
use of android.view.WindowInsets in project LookLook by xinghongfei.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
IMainPresenter = new MainPresenterImpl(this, this);
IMainPresenter.getBackground();
toolbar.setOnMenuItemClickListener(onMenuItemClick);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
animateToolbar();
}
addfragmentsAndTitle();
// setStatusColor();
drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
if (savedInstanceState == null) {
nevigationId = SharePreferenceUtil.getNevigationItem(this);
if (nevigationId != -1) {
currentMenuItem = navView.getMenu().findItem(nevigationId);
}
if (currentMenuItem == null) {
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
}
if (currentMenuItem != null) {
currentMenuItem.setChecked(true);
// TODO: 16/8/17 add a fragment and set toolbar title
Fragment fragment = getFragmentById(currentMenuItem.getItemId());
String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
if (fragment != null) {
switchFragment(fragment, title);
}
}
} else {
if (currentMenuItem != null) {
Fragment fragment = getFragmentById(currentMenuItem.getItemId());
String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
if (fragment != null) {
switchFragment(fragment, title);
}
} else {
switchFragment(new ZhihuFragment(), " ");
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
}
}
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
if (currentMenuItem != item && currentMenuItem != null) {
currentMenuItem.setChecked(false);
int id = item.getItemId();
SharePreferenceUtil.putNevigationItem(MainActivity.this, id);
currentMenuItem = item;
currentMenuItem.setChecked(true);
switchFragment(getFragmentById(currentMenuItem.getItemId()), mTitleArryMap.get(currentMenuItem.getItemId()));
}
drawer.closeDrawer(GravityCompat.END, true);
return true;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
// inset the toolbar down by the status bar height
ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
lpToolbar.topMargin += insets.getSystemWindowInsetTop();
lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(lpToolbar);
// inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
mFragmentContainer.setPadding(mFragmentContainer.getPaddingLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(MainActivity.this), // landscape
mFragmentContainer.getPaddingRight() + insets.getSystemWindowInsetRight(), mFragmentContainer.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// we place a background behind the status bar to combine with it's semi-transparent
// color to get the desired appearance. Set it's height to the status bar height
View statusBarBackground = findViewById(R.id.status_bar_background);
FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
lpStatus.height = insets.getSystemWindowInsetTop();
statusBarBackground.setLayoutParams(lpStatus);
// inset the filters list for the status bar / navbar
// need to set the padding end for landscape case
// clear this listener so insets aren't re-applied
drawer.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
}
int[][] state = new int[][] { // unchecked
new int[] { -android.R.attr.state_checked }, // pressed
new int[] { android.R.attr.state_checked } };
int[] color = new int[] { Color.BLACK, Color.BLACK };
int[] iconcolor = new int[] { Color.GRAY, Color.BLACK };
navView.setItemTextColor(new ColorStateList(state, color));
navView.setItemIconTintList(new ColorStateList(state, iconcolor));
//主题变色
MenuItem item = navView.getMenu().findItem(R.id.nav_theme);
mThemeSwitch = (SwitchCompat) MenuItemCompat.getActionView(item).findViewById(R.id.view_switch);
mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mThemeSwitch.setChecked(isChecked);
if (isChecked) {
setThemeColor(Color.GREEN);
} else {
setThemeColor(getResources().getColor(R.color.colorPrimaryDark));
}
}
});
}
Aggregations