use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project FABsMenu by jahirfiquitiva.
the class FABsMenu method onLayout.
@SuppressLint("DrawAllocation")
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
switch(expandDirection) {
case EXPAND_UP:
case EXPAND_DOWN:
boolean expandUp = expandDirection == EXPAND_UP;
touchDelegateGroup.clearTouchDelegates();
int addButtonY = expandUp ? b - t - menuButton.getMeasuredHeight() : 0;
if (expandUp)
addButtonY -= menuBottomMargin;
else
addButtonY += menuTopMargin;
// Ensure menuButton is centered on the line where the buttons should be
int buttonsHorizontalCenter = labelsPosition == LABELS_ON_LEFT_SIDE ? r - l - maxButtonWidth / 2 : maxButtonWidth / 2;
buttonsHorizontalCenter -= labelsPosition == LABELS_ON_LEFT_SIDE ? menuRightMargin : -menuLeftMargin;
int addButtonLeft = buttonsHorizontalCenter - menuButton.getMeasuredWidth() / 2;
menuButton.layout(addButtonLeft, addButtonY, addButtonLeft + menuButton.getMeasuredWidth(), addButtonY + menuButton.getMeasuredHeight());
int labelsOffset = maxButtonWidth / 2 + labelsMargin;
int labelsXNearButton = labelsPosition == LABELS_ON_LEFT_SIDE ? buttonsHorizontalCenter - labelsOffset : buttonsHorizontalCenter + labelsOffset;
int nextY = expandUp ? addButtonY - buttonSpacing : addButtonY + menuButton.getMeasuredHeight() + buttonSpacing;
for (int i = buttonsCount - 1; i >= 0; i--) {
final View child = getChildAt(i);
if (child.equals(menuButton) || child.getVisibility() == GONE)
continue;
int childX = buttonsHorizontalCenter - child.getMeasuredWidth() / 2;
int childY = expandUp ? nextY - child.getMeasuredHeight() : nextY;
child.layout(childX, childY, childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight());
float collapsedTranslation = addButtonY - childY;
float expandedTranslation = 0f;
child.setTranslationY(expanded ? expandedTranslation : collapsedTranslation);
child.setAlpha(expanded ? 1f : 0f);
LayoutParams params = (LayoutParams) child.getLayoutParams();
params.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
params.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
params.setAnimationsTarget(child);
View label = (View) child.getTag(R.id.fab_label);
if (label != null) {
int labelXAwayFromButton = labelsPosition == LABELS_ON_LEFT_SIDE ? labelsXNearButton - label.getMeasuredWidth() : labelsXNearButton + label.getMeasuredWidth();
int labelLeft = labelsPosition == LABELS_ON_LEFT_SIDE ? labelXAwayFromButton : labelsXNearButton;
int labelRight = labelsPosition == LABELS_ON_LEFT_SIDE ? labelsXNearButton : labelXAwayFromButton;
int labelTop = childY - labelsVerticalOffset + (child.getMeasuredHeight() - label.getMeasuredHeight()) / 2;
label.layout(labelLeft, labelTop, labelRight, labelTop + label.getMeasuredHeight());
Rect touchArea = new Rect(Math.min(childX, labelLeft), childY - buttonSpacing / 2, Math.max(childX + child.getMeasuredWidth(), labelRight), childY + child.getMeasuredHeight() + buttonSpacing / 2);
touchDelegateGroup.addTouchDelegate(new TouchDelegate(touchArea, child));
label.setTranslationY(expanded ? expandedTranslation : collapsedTranslation);
label.setAlpha(expanded ? 1f : 0f);
LayoutParams labelParams = (LayoutParams) label.getLayoutParams();
labelParams.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
labelParams.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
labelParams.setAnimationsTarget(label);
}
nextY = expandUp ? childY - buttonSpacing : childY + child.getMeasuredHeight() + buttonSpacing;
}
break;
case EXPAND_LEFT:
case EXPAND_RIGHT:
boolean expandLeft = expandDirection == EXPAND_LEFT;
int addButtonX = expandLeft ? r - l - menuButton.getMeasuredWidth() : 0;
if (expandLeft)
addButtonX -= menuRightMargin;
else
addButtonX += menuLeftMargin;
// Ensure menuButton is centered on the line where the buttons should be
int addButtonTop = b - t - maxButtonHeight + (maxButtonHeight - menuButton.getMeasuredHeight()) / 2;
addButtonTop -= menuBottomMargin;
menuButton.layout(addButtonX, addButtonTop, addButtonX + menuButton.getMeasuredWidth(), addButtonTop + menuButton.getMeasuredHeight());
int nextX = expandLeft ? addButtonX - buttonSpacing : addButtonX + menuButton.getMeasuredWidth() + buttonSpacing;
for (int i = buttonsCount - 1; i >= 0; i--) {
final View child = getChildAt(i);
if (child.equals(menuButton) || child.getVisibility() == GONE)
continue;
int childX = expandLeft ? nextX - child.getMeasuredWidth() : nextX;
int childY = addButtonTop + (menuButton.getMeasuredHeight() - child.getMeasuredHeight()) / 2;
child.layout(childX, childY, childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight());
float collapsedTranslation = addButtonX - childX;
float expandedTranslation = 0f;
child.setTranslationX(expanded ? expandedTranslation : collapsedTranslation);
child.setAlpha(expanded ? 1f : 0f);
LayoutParams params = (LayoutParams) child.getLayoutParams();
params.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
params.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
params.setAnimationsTarget(child);
nextX = expandLeft ? childX - buttonSpacing : childX + child.getMeasuredWidth() + buttonSpacing;
}
break;
default:
// Do Nothing
break;
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project Osmand by osmandapp.
the class POIMapLayer method showText.
private static void showText(final Context ctx, final OsmandApplication app, final String text, String title) {
final Dialog dialog = new Dialog(ctx, app.getSettings().isLightContent() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
LinearLayout ll = new LinearLayout(ctx);
ll.setOrientation(LinearLayout.VERTICAL);
final Toolbar topBar = new Toolbar(ctx);
topBar.setClickable(true);
Drawable back = app.getIconsCache().getIcon(R.drawable.ic_arrow_back);
topBar.setNavigationIcon(back);
topBar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
topBar.setTitle(title);
topBar.setBackgroundColor(ContextCompat.getColor(ctx, getResIdFromAttribute(ctx, R.attr.pstsTabBackground)));
topBar.setTitleTextColor(ContextCompat.getColor(ctx, getResIdFromAttribute(ctx, R.attr.pstsTextColor)));
topBar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
dialog.dismiss();
}
});
final TextView textView = new TextView(ctx);
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int textMargin = dpToPx(app, 10f);
boolean light = app.getSettings().isLightContent();
textView.setLayoutParams(llTextParams);
textView.setPadding(textMargin, textMargin, textMargin, textMargin);
textView.setTextSize(16);
textView.setTextColor(ContextCompat.getColor(app, light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
textView.setAutoLinkMask(Linkify.ALL);
textView.setLinksClickable(true);
textView.setText(text);
ScrollView scrollView = new ScrollView(ctx);
ll.addView(topBar);
LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
lp.weight = 1;
ll.addView(scrollView, lp);
scrollView.addView(textView);
dialog.setContentView(ll);
dialog.setCancelable(true);
dialog.show();
}
use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project ttdj by soonphe.
the class RecycleViewDivider method drawVertical.
// 绘制纵向 item 分割线
private void drawVertical(Canvas canvas, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom();
final int childSize = parent.getChildCount();
for (int i = 0; i < childSize; i++) {
final View child = parent.getChildAt(i);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
final int left = child.getRight() + layoutParams.rightMargin;
final int right = left + mDividerHeight;
if (mDivider != null) {
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(canvas);
}
if (mPaint != null) {
canvas.drawRect(left, top, right, bottom, mPaint);
}
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project TicktockMusic by Lauzy.
the class HorizontalPagerScrollListener method onScrollStateChanged.
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState != RecyclerView.SCROLL_STATE_IDLE) {
return;
}
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (mOrientationHelper == null) {
mOrientationHelper = OrientationHelper.createHorizontalHelper(layoutManager);
}
final int rvCenter;
if (recyclerView.getClipToPadding()) {
rvCenter = mOrientationHelper.getStartAfterPadding() + mOrientationHelper.getTotalSpace() / 2;
} else {
rvCenter = mOrientationHelper.getTotalSpace() / 2;
}
int minSpace = Integer.MAX_VALUE;
View minCloseView = null;
final int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View childView = recyclerView.getChildAt(i);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) childView.getLayoutParams();
final int childStart = mOrientationHelper.getDecoratedStart(childView) + layoutParams.leftMargin;
final int childWidth = mOrientationHelper.getDecoratedMeasurement(childView) - layoutParams.leftMargin - layoutParams.rightMargin;
final int childCenter = childStart + childWidth / 2;
final int space = Math.abs(childCenter - rvCenter);
if (minSpace > space) {
minSpace = space;
minCloseView = childView;
}
}
if (minCloseView != null) {
int position = recyclerView.getChildViewHolder(minCloseView).getAdapterPosition();
if (position == RecyclerView.NO_POSITION) {
return;
}
if (mLastPosition != position) {
onPageChange(position);
mLastPosition = position;
}
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams in project focus-android by mozilla-mobile.
the class SearchEngineListPreference method refreshSearchEngineViews.
private void refreshSearchEngineViews(Context context, SearchEngineManager sem) {
if (searchEngineGroup == null) {
// so searchEngineGroup is not set yet.
return;
}
final String defaultSearchEngine = sem.getDefaultSearchEngine(context).getIdentifier();
searchEngineGroup.removeAllViews();
final LayoutInflater layoutInflater = LayoutInflater.from(context);
final RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
for (int i = 0; i < searchEngines.size(); i++) {
final SearchEngine engine = searchEngines.get(i);
final String engineId = engine.getIdentifier();
final CompoundButton engineItem = makeButtonFromSearchEngine(engine, layoutInflater, context.getResources());
engineItem.setId(i);
engineItem.setTag(engineId);
if (engineId.equals(defaultSearchEngine)) {
updateDefaultItem(engineItem);
}
searchEngineGroup.addView(engineItem, layoutParams);
}
}
Aggregations