use of androidx.recyclerview.widget.RecyclerView in project Douya by DreaminginCodeZH.
the class DividerItemDecoration method drawHorizontal.
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
canvas.save();
int top;
int bottom;
if (parent.getClipToPadding()) {
top = parent.getPaddingTop();
bottom = parent.getHeight() - parent.getPaddingBottom();
canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom);
} else {
top = 0;
bottom = parent.getHeight();
}
for (int i = 0, count = parent.getChildCount(); i < count; ++i) {
View child = parent.getChildAt(i);
if (parent.getChildAdapterPosition(child) == 0) {
continue;
}
parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
int left = mBounds.left + Math.round(child.getTranslationX());
int right = left + mDivider.getIntrinsicWidth();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(canvas);
}
canvas.restore();
}
use of androidx.recyclerview.widget.RecyclerView in project Weather by Sparker0i.
the class WeatherFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_weather, container, false);
ButterKnife.bind(this, rootView);
MaterialDialog.Builder builder = new MaterialDialog.Builder(this.activity()).title(getString(R.string.please_wait)).content(getString(R.string.loading)).cancelable(false).progress(true, 0);
pd = builder.build();
setHasOptionsMenu(true);
preferences = new Prefs(context());
weatherFont = Typeface.createFromAsset(activity().getAssets(), "fonts/weather-icons-v2.0.10.ttf");
fab = ((WeatherActivity) activity()).findViewById(R.id.fab);
Bundle bundle = getArguments();
fabProgressCircle = ((WeatherActivity) activity()).findViewById(R.id.fabProgressCircle);
int mode;
if (bundle != null)
mode = bundle.getInt(Constants.MODE, 0);
else
mode = 0;
if (mode == 0)
updateWeatherData(preferences.getCity(), null, null);
else
updateWeatherData(null, Float.toString(preferences.getLatitude()), Float.toString(preferences.getLongitude()));
gps = new GPSTracker(context());
cityField.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
updatedField.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
humidityView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
sunriseIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
sunriseIcon.setTypeface(weatherFont);
sunriseIcon.setText(activity().getString(R.string.sunrise_icon));
sunsetIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
sunsetIcon.setTypeface(weatherFont);
sunsetIcon.setText(activity().getString(R.string.sunset_icon));
humidityIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
humidityIcon.setTypeface(weatherFont);
humidityIcon.setText(activity().getString(R.string.humidity_icon));
windView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
swipeView.setColorSchemeResources(R.color.red, R.color.green, R.color.blue, R.color.yellow, R.color.orange);
swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
handler.post(new Runnable() {
@Override
public void run() {
changeCity(preferences.getCity());
swipeView.setRefreshing(false);
}
});
}
});
horizontalLayoutManager = new LinearLayoutManager(context(), LinearLayoutManager.HORIZONTAL, false);
horizontalRecyclerView.setLayoutManager(horizontalLayoutManager);
horizontalRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (horizontalLayoutManager.findLastVisibleItemPosition() == 9 || citys != null)
fab.hide();
else
fab.show();
}
});
directionView.setTypeface(weatherFont);
directionView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
dailyView.setText(getString(R.string.daily));
dailyView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
sunriseView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
sunsetView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
button.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
pd.show();
horizontalRecyclerView.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
weatherIcon.setTypeface(weatherFont);
weatherIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
if (citys == null)
((WeatherActivity) activity()).showFab();
else
((WeatherActivity) activity()).hideFab();
return rootView;
}
use of androidx.recyclerview.widget.RecyclerView in project Conversations by siacs.
the class ShareWithActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share_with);
setSupportActionBar(findViewById(R.id.toolbar));
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
}
setTitle(getString(R.string.title_activity_sharewith));
RecyclerView mListView = findViewById(R.id.choose_conversation_list);
mAdapter = new ConversationAdapter(this, this.mConversations);
mListView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
mListView.setAdapter(mAdapter);
mAdapter.setConversationClickListener((view, conversation) -> share(conversation));
this.share = new Share();
}
use of androidx.recyclerview.widget.RecyclerView in project BlurView by Dimezis.
the class ListFragment method init.
private void init() {
RecyclerView recyclerView = getView().findViewById(R.id.recyclerView);
recyclerView.setAdapter(new ExampleListAdapter(getContext()));
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
use of androidx.recyclerview.widget.RecyclerView in project flexbox-layout by google.
the class FlexboxLayoutManager method updateLayoutState.
/**
* Update the layout state as part of the scrolling. This method also update the flex lines
* enough to display the view port including the delta of the scroll.
*
* @param layoutDirection the layout direction value. Either of {@link LayoutState#LAYOUT_END}
* or {@link LayoutState#LAYOUT_START}
* @param absDelta the absolute value of the delta that is about to be scrolled.
*/
private void updateLayoutState(int layoutDirection, int absDelta) {
assert mFlexboxHelper.mIndexToFlexLine != null;
mLayoutState.mLayoutDirection = layoutDirection;
boolean mainAxisHorizontal = isMainAxisDirectionHorizontal();
// noinspection ResourceType
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(getWidth(), getWidthMode());
// noinspection ResourceType
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(getHeight(), getHeightMode());
boolean columnAndRtl = !mainAxisHorizontal && mIsRtl;
if (layoutDirection == LayoutState.LAYOUT_END) {
View lastVisible = getChildAt(getChildCount() - 1);
if (lastVisible == null) {
return;
}
mLayoutState.mOffset = mOrientationHelper.getDecoratedEnd(lastVisible);
int lastVisiblePosition = getPosition(lastVisible);
int lastVisibleLinePosition = mFlexboxHelper.mIndexToFlexLine[lastVisiblePosition];
FlexLine lastVisibleLine = mFlexLines.get(lastVisibleLinePosition);
// The reference view which has the maximum end (or minimum if the layout is RTL and
// the main axis direction is horizontal) coordinate in the last visible flex line.
View referenceView = findLastReferenceViewInLine(lastVisible, lastVisibleLine);
mLayoutState.mItemDirection = LayoutState.ITEM_DIRECTION_TAIL;
mLayoutState.mPosition = lastVisiblePosition + mLayoutState.mItemDirection;
if (mFlexboxHelper.mIndexToFlexLine.length <= mLayoutState.mPosition) {
mLayoutState.mFlexLinePosition = NO_POSITION;
} else {
mLayoutState.mFlexLinePosition = mFlexboxHelper.mIndexToFlexLine[mLayoutState.mPosition];
}
if (columnAndRtl) {
mLayoutState.mOffset = mOrientationHelper.getDecoratedStart(referenceView);
mLayoutState.mScrollingOffset = -mOrientationHelper.getDecoratedStart(referenceView) + mOrientationHelper.getStartAfterPadding();
mLayoutState.mScrollingOffset = Math.max(mLayoutState.mScrollingOffset, 0);
} else {
mLayoutState.mOffset = mOrientationHelper.getDecoratedEnd(referenceView);
mLayoutState.mScrollingOffset = mOrientationHelper.getDecoratedEnd(referenceView) - mOrientationHelper.getEndAfterPadding();
}
if ((mLayoutState.mFlexLinePosition == NO_POSITION || mLayoutState.mFlexLinePosition > mFlexLines.size() - 1) && mLayoutState.mPosition <= getFlexItemCount()) {
// If the RecyclerView tries to scroll beyond the already calculated
// flex container, need to calculate beyond the amount that needs to be filled
int needsToFill = absDelta - mLayoutState.mScrollingOffset;
mFlexLinesResult.reset();
if (needsToFill > 0) {
if (mainAxisHorizontal) {
mFlexboxHelper.calculateHorizontalFlexLines(mFlexLinesResult, widthMeasureSpec, heightMeasureSpec, needsToFill, mLayoutState.mPosition, mFlexLines);
} else {
mFlexboxHelper.calculateVerticalFlexLines(mFlexLinesResult, widthMeasureSpec, heightMeasureSpec, needsToFill, mLayoutState.mPosition, mFlexLines);
}
mFlexboxHelper.determineMainSize(widthMeasureSpec, heightMeasureSpec, mLayoutState.mPosition);
mFlexboxHelper.stretchViews(mLayoutState.mPosition);
}
}
} else {
View firstVisible = getChildAt(0);
if (firstVisible == null) {
return;
}
mLayoutState.mOffset = mOrientationHelper.getDecoratedStart(firstVisible);
int firstVisiblePosition = getPosition(firstVisible);
int firstVisibleLinePosition = mFlexboxHelper.mIndexToFlexLine[firstVisiblePosition];
FlexLine firstVisibleLine = mFlexLines.get(firstVisibleLinePosition);
// The reference view which has the minimum start (or maximum if the layout is RTL and
// the main axis direction is horizontal) coordinate in the first visible flex line
View referenceView = findFirstReferenceViewInLine(firstVisible, firstVisibleLine);
mLayoutState.mItemDirection = LayoutState.ITEM_DIRECTION_TAIL;
int flexLinePosition = mFlexboxHelper.mIndexToFlexLine[firstVisiblePosition];
if (flexLinePosition == NO_POSITION) {
flexLinePosition = 0;
}
if (flexLinePosition > 0) {
FlexLine previousLine = mFlexLines.get(flexLinePosition - 1);
// The position of the next item toward start should be on the next flex line,
// shifting the position by the number of the items in the previous line.
mLayoutState.mPosition = firstVisiblePosition - previousLine.getItemCount();
} else {
mLayoutState.mPosition = NO_POSITION;
}
mLayoutState.mFlexLinePosition = flexLinePosition > 0 ? flexLinePosition - 1 : 0;
if (columnAndRtl) {
mLayoutState.mOffset = mOrientationHelper.getDecoratedEnd(referenceView);
mLayoutState.mScrollingOffset = mOrientationHelper.getDecoratedEnd(referenceView) - mOrientationHelper.getEndAfterPadding();
mLayoutState.mScrollingOffset = Math.max(mLayoutState.mScrollingOffset, 0);
} else {
mLayoutState.mOffset = mOrientationHelper.getDecoratedStart(referenceView);
mLayoutState.mScrollingOffset = -mOrientationHelper.getDecoratedStart(referenceView) + mOrientationHelper.getStartAfterPadding();
}
}
mLayoutState.mAvailable = absDelta - mLayoutState.mScrollingOffset;
}
Aggregations