use of android.support.v4.view.WindowInsetsCompat in project material-components-android by material-components.
the class SnackbarWithTranslucentNavBarTest method testDrawsAboveNavigationBar.
@Test
@MediumTest
public void testDrawsAboveNavigationBar() {
// Show a simple Snackbar and wait for it to be shown
final Snackbar snackbar = Snackbar.make(mCoordinatorLayout, MESSAGE_TEXT, Snackbar.LENGTH_SHORT);
SnackbarUtils.showTransientBottomBarAndWaitUntilFullyShown(snackbar);
final WindowInsetsCompat colLastInsets = mCoordinatorLayout.getLastWindowInsets();
assertNotNull(colLastInsets);
// Check that the Snackbar view has padding set to display above the nav bar
final View view = snackbar.getView();
assertNotNull(view);
assertEquals(colLastInsets.getSystemWindowInsetBottom(), view.getPaddingBottom());
}
use of android.support.v4.view.WindowInsetsCompat in project muzei by romannurik.
the class GallerySettingsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_activity);
Toolbar appBar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(appBar);
getSupportLoaderManager().initLoader(0, null, this);
bindService(new Intent(this, GalleryArtSource.class).setAction(GalleryArtSource.ACTION_BIND_GALLERY), mServiceConnection, BIND_AUTO_CREATE);
mPlaceholderDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.gallery_chosen_photo_placeholder));
mPlaceholderSmallDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.gallery_chosen_photo_placeholder));
mPhotoGridView = (RecyclerView) findViewById(R.id.photo_grid);
DefaultItemAnimator itemAnimator = new DefaultItemAnimator();
itemAnimator.setSupportsChangeAnimations(false);
mPhotoGridView.setItemAnimator(itemAnimator);
setupMultiSelect();
final GridLayoutManager gridLayoutManager = new GridLayoutManager(GallerySettingsActivity.this, 1);
mPhotoGridView.setLayoutManager(gridLayoutManager);
final ViewTreeObserver vto = mPhotoGridView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int width = mPhotoGridView.getWidth() - mPhotoGridView.getPaddingStart() - mPhotoGridView.getPaddingEnd();
if (width <= 0) {
return;
}
// Compute number of columns
int maxItemWidth = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_max_item_size);
int numColumns = 1;
while (true) {
if (width / numColumns > maxItemWidth) {
++numColumns;
} else {
break;
}
}
int spacing = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_spacing);
mItemSize = (width - spacing * (numColumns - 1)) / numColumns;
// Complete setup
gridLayoutManager.setSpanCount(numColumns);
mChosenPhotosAdapter.setHasStableIds(true);
mPhotoGridView.setAdapter(mChosenPhotosAdapter);
mPhotoGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
tryUpdateSelection(false);
}
});
ViewCompat.setOnApplyWindowInsetsListener(mPhotoGridView, new OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat insets) {
int gridSpacing = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_spacing);
ViewCompat.onApplyWindowInsets(v, insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft() + gridSpacing, gridSpacing, insets.getSystemWindowInsetRight() + gridSpacing, insets.getSystemWindowInsetBottom() + insets.getSystemWindowInsetTop() + gridSpacing + getResources().getDimensionPixelSize(R.dimen.gallery_fab_space)));
return insets;
}
});
Button enableRandomImages = (Button) findViewById(R.id.gallery_enable_random);
enableRandomImages.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
ActivityCompat.requestPermissions(GallerySettingsActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_STORAGE_PERMISSION);
}
});
Button permissionSettings = (Button) findViewById(R.id.gallery_edit_permission_settings);
permissionSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getPackageName(), null));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
mAddButton = findViewById(R.id.add_fab);
mAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// On Lollipop and higher, we show the add toolbar to allow users to add either
// individual photos or a whole directory
showAddToolbar();
} else {
requestPhotos();
}
}
});
mAddToolbar = findViewById(R.id.add_toolbar);
findViewById(R.id.add_photos).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
requestPhotos();
}
});
findViewById(R.id.add_folder).setOnClickListener(new View.OnClickListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(final View v) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
try {
startActivityForResult(intent, REQUEST_CHOOSE_FOLDER);
SharedPreferences preferences = getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
if (preferences.getBoolean(SHOW_INTERNAL_STORAGE_MESSAGE, true)) {
Toast.makeText(GallerySettingsActivity.this, R.string.gallery_internal_storage_message, Toast.LENGTH_LONG).show();
}
} catch (ActivityNotFoundException e) {
Snackbar.make(mPhotoGridView, R.string.gallery_add_folder_error, Snackbar.LENGTH_LONG).show();
hideAddToolbar(true);
}
}
});
}
use of android.support.v4.view.WindowInsetsCompat in project material-components-android by material-components.
the class HeaderScrollingViewBehavior method layoutChild.
@Override
protected void layoutChild(final CoordinatorLayout parent, final View child, final int layoutDirection) {
final List<View> dependencies = parent.getDependencies(child);
final View header = findFirstDependency(dependencies);
if (header != null) {
final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
final Rect available = mTempRect1;
available.set(parent.getPaddingLeft() + lp.leftMargin, header.getBottom() + lp.topMargin, parent.getWidth() - parent.getPaddingRight() - lp.rightMargin, parent.getHeight() + header.getBottom() - parent.getPaddingBottom() - lp.bottomMargin);
final WindowInsetsCompat parentInsets = parent.getLastWindowInsets();
if (parentInsets != null && ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) {
// If we're set to handle insets but this child isn't, then it has been measured as
// if there are no insets. We need to lay it out to match horizontally.
// Top and bottom and already handled in the logic above
available.left += parentInsets.getSystemWindowInsetLeft();
available.right -= parentInsets.getSystemWindowInsetRight();
}
final Rect out = mTempRect2;
GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), available, out, layoutDirection);
final int overlap = getOverlapPixelsForOffset(header);
child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
mVerticalLayoutGap = out.top - header.getBottom();
} else {
// If we don't have a dependency, let super handle it
super.layoutChild(parent, child, layoutDirection);
mVerticalLayoutGap = 0;
}
}
use of android.support.v4.view.WindowInsetsCompat in project BlogSource by TeachCourse.
the class ViewPagerCompat method initViewPager.
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);
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);
}
});
}
use of android.support.v4.view.WindowInsetsCompat in project iosched by google.
the class CollapsingToolbarLayout method onWindowInsetChanged.
WindowInsetsCompat onWindowInsetChanged(final WindowInsetsCompat insets) {
WindowInsetsCompat newInsets = null;
if (ViewCompat.getFitsSystemWindows(this)) {
// If we're set to fit system windows, keep the insets
newInsets = insets;
}
// If our insets have changed, keep them and invalidate the scroll ranges...
if (!objectEquals(mLastInsets, newInsets)) {
mLastInsets = newInsets;
requestLayout();
}
// get the default padding functionality from View
return insets.consumeSystemWindowInsets();
}
Aggregations