use of android.support.v7.widget.RecyclerView.LayoutParams in project BaseRecyclerViewAdapterHelper by CymChad.
the class BaseQuickAdapter method addHeaderView.
/**
* @param header
* @param index
* @param orientation
*/
public int addHeaderView(View header, int index, int orientation) {
if (mHeaderLayout == null) {
mHeaderLayout = new LinearLayout(header.getContext());
if (orientation == LinearLayout.VERTICAL) {
mHeaderLayout.setOrientation(LinearLayout.VERTICAL);
mHeaderLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
} else {
mHeaderLayout.setOrientation(LinearLayout.HORIZONTAL);
mHeaderLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
}
}
final int childCount = mHeaderLayout.getChildCount();
if (index < 0 || index > childCount) {
index = childCount;
}
mHeaderLayout.addView(header, index);
if (mHeaderLayout.getChildCount() == 1) {
int position = getHeaderViewPosition();
if (position != -1) {
notifyItemInserted(position);
}
}
return index;
}
use of android.support.v7.widget.RecyclerView.LayoutParams in project BaseRecyclerViewAdapterHelper by CymChad.
the class BaseQuickAdapter method setEmptyView.
public void setEmptyView(View emptyView) {
boolean insert = false;
if (mEmptyLayout == null) {
mEmptyLayout = new FrameLayout(emptyView.getContext());
final LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
final ViewGroup.LayoutParams lp = emptyView.getLayoutParams();
if (lp != null) {
layoutParams.width = lp.width;
layoutParams.height = lp.height;
}
mEmptyLayout.setLayoutParams(layoutParams);
insert = true;
}
mEmptyLayout.removeAllViews();
mEmptyLayout.addView(emptyView);
mIsUseEmpty = true;
if (insert) {
if (getEmptyViewCount() == 1) {
int position = 0;
if (mHeadAndEmptyEnable && getHeaderLayoutCount() != 0) {
position++;
}
notifyItemInserted(position);
}
}
}
use of android.support.v7.widget.RecyclerView.LayoutParams in project android-flowlayout by ApmeM.
the class FlowLayoutManager method onLayoutChildren.
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
detachAndScrapAttachedViews(recycler);
final int count = this.getItemCount();
views.clear();
lines.clear();
for (int i = 0; i < count; i++) {
View child = recycler.getViewForPosition(i);
attachView(child);
measureChildWithMargins(child, 0, 0);
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
ViewDefinition view = new ViewDefinition(this.config, child);
view.setWidth(child.getMeasuredWidth());
view.setHeight(child.getMeasuredHeight());
view.setNewLine(lp.isNewLine());
view.setGravity(lp.getGravity());
view.setWeight(lp.getWeight());
view.setMargins(lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin);
views.add(view);
}
this.config.setMaxWidth(this.getWidth() - this.getPaddingRight() - this.getPaddingLeft());
this.config.setMaxHeight(this.getHeight() - this.getPaddingTop() - this.getPaddingBottom());
this.config.setWidthMode(View.MeasureSpec.EXACTLY);
this.config.setHeightMode(View.MeasureSpec.EXACTLY);
this.config.setCheckCanFit(true);
CommonLogic.fillLines(views, lines, config);
CommonLogic.calculateLinesAndChildPosition(lines);
int contentLength = 0;
final int linesCount = lines.size();
for (int i = 0; i < linesCount; i++) {
LineDefinition l = lines.get(i);
contentLength = Math.max(contentLength, l.getLineLength());
}
LineDefinition currentLine = lines.get(lines.size() - 1);
int contentThickness = currentLine.getLineStartThickness() + currentLine.getLineThickness();
int realControlLength = CommonLogic.findSize(this.config.getLengthMode(), this.config.getMaxLength(), contentLength);
int realControlThickness = CommonLogic.findSize(this.config.getThicknessMode(), this.config.getMaxThickness(), contentThickness);
CommonLogic.applyGravityToLines(lines, realControlLength, realControlThickness, config);
for (int i = 0; i < linesCount; i++) {
LineDefinition line = lines.get(i);
applyPositionsToViews(line);
}
}
use of android.support.v7.widget.RecyclerView.LayoutParams in project AndroidChromium by JackyAndroid.
the class NewTabPageView method initialize.
/**
* Initializes the NTP. This must be called immediately after inflation, before this object is
* used in any other way.
*
* @param manager NewTabPageManager used to perform various actions when the user interacts
* with the page.
* @param searchProviderHasLogo Whether the search provider has a logo.
* @param scrollPosition The adapter scroll position to initialize to.
*/
public void initialize(NewTabPageManager manager, boolean searchProviderHasLogo, int scrollPosition) {
mManager = manager;
mUiConfig = new UiConfig(this);
ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub);
mUseCardsUi = manager.getSuggestionsSource() != null;
if (mUseCardsUi) {
stub.setLayoutResource(R.layout.new_tab_page_recycler_view);
mRecyclerView = (NewTabPageRecyclerView) stub.inflate();
// Don't attach now, the recyclerView itself will determine when to do it.
mNewTabPageLayout = (NewTabPageLayout) LayoutInflater.from(getContext()).inflate(R.layout.new_tab_page_layout, mRecyclerView, false);
mNewTabPageLayout.setUseCardsUiEnabled(mUseCardsUi);
mRecyclerView.setAboveTheFoldView(mNewTabPageLayout);
// Tailor the LayoutParams for the snippets UI, as the configuration in the XML is
// made for the ScrollView UI.
ViewGroup.LayoutParams params = mNewTabPageLayout.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
mRecyclerView.setItemAnimator(new DefaultItemAnimator() {
@Override
public void onAnimationFinished(ViewHolder viewHolder) {
super.onAnimationFinished(viewHolder);
// When removing sections, because the animations are all translations, the
// scroll events don't fire and we can get in the situation where the toolbar
// buttons disappear.
updateSearchBoxOnScroll();
}
});
} else {
stub.setLayoutResource(R.layout.new_tab_page_scroll_view);
mScrollView = (NewTabPageScrollView) stub.inflate();
mScrollView.setBackgroundColor(NtpStyleUtils.getBackgroundColorResource(getResources(), false));
mScrollView.enableBottomShadow(SHADOW_COLOR);
mNewTabPageLayout = (NewTabPageLayout) findViewById(R.id.ntp_content);
}
mMostVisitedDesign = new MostVisitedDesign(getContext());
mMostVisitedLayout = (MostVisitedLayout) mNewTabPageLayout.findViewById(R.id.most_visited_layout);
mMostVisitedDesign.initMostVisitedLayout(searchProviderHasLogo);
mSearchProviderLogoView = (LogoView) mNewTabPageLayout.findViewById(R.id.search_provider_logo);
mSearchBoxView = (ViewGroup) mNewTabPageLayout.findViewById(R.id.search_box);
mNoSearchLogoSpacer = mNewTabPageLayout.findViewById(R.id.no_search_logo_spacer);
initializeSearchBoxTextView();
initializeVoiceSearchButton();
initializeBottomToolbar();
mNewTabPageLayout.addOnLayoutChangeListener(this);
setSearchProviderHasLogo(searchProviderHasLogo);
mPendingLoadTasks++;
mManager.setMostVisitedURLsObserver(this, mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo));
// Set up snippets
if (mUseCardsUi) {
mNewTabPageAdapter = NewTabPageAdapter.create(mManager, mNewTabPageLayout, mUiConfig);
mRecyclerView.setAdapter(mNewTabPageAdapter);
mRecyclerView.scrollToPosition(scrollPosition);
if (CardsVariationParameters.isScrollBelowTheFoldEnabled()) {
int searchBoxHeight = NtpStyleUtils.getSearchBoxHeight(getResources());
mRecyclerView.getLinearLayoutManager().scrollToPositionWithOffset(mNewTabPageAdapter.getFirstHeaderPosition(), searchBoxHeight);
}
// Set up swipe-to-dismiss
ItemTouchHelper helper = new ItemTouchHelper(mNewTabPageAdapter.getItemTouchCallbacks());
helper.attachToRecyclerView(mRecyclerView);
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
private boolean mScrolledOnce = false;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState != RecyclerView.SCROLL_STATE_DRAGGING)
return;
RecordUserAction.record("MobileNTP.Snippets.Scrolled");
if (mScrolledOnce)
return;
mScrolledOnce = true;
NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_SCROLLED);
}
});
initializeSearchBoxRecyclerViewScrollHandling();
} else {
initializeSearchBoxScrollHandling();
}
}
use of android.support.v7.widget.RecyclerView.LayoutParams in project LeafPic by HoraApps.
the class AlertDialogsHelper method getInsertTextDialog.
public static AlertDialog getInsertTextDialog(final ThemedActivity activity, AlertDialog.Builder dialogBuilder, EditText editText, @StringRes int title) {
View dialogLayout = activity.getLayoutInflater().inflate(org.horaapps.leafpic.R.layout.dialog_insert_text, null);
TextView textViewTitle = (TextView) dialogLayout.findViewById(org.horaapps.leafpic.R.id.rename_title);
((CardView) dialogLayout.findViewById(org.horaapps.leafpic.R.id.dialog_chose_provider_title)).setCardBackgroundColor(activity.getCardBackgroundColor());
textViewTitle.setBackgroundColor(activity.getPrimaryColor());
textViewTitle.setText(title);
ThemeHelper.setCursorDrawableColor(editText, activity.getTextColor());
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
editText.setLayoutParams(layoutParams);
editText.setSingleLine(true);
editText.getBackground().mutate().setColorFilter(activity.getTextColor(), PorterDuff.Mode.SRC_IN);
editText.setTextColor(activity.getTextColor());
try {
Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
f.setAccessible(true);
f.set(editText, null);
} catch (Exception ignored) {
}
((RelativeLayout) dialogLayout.findViewById(org.horaapps.leafpic.R.id.container_edit_text)).addView(editText);
dialogBuilder.setView(dialogLayout);
return dialogBuilder.create();
}
Aggregations