Java – Use Stick Headers in Reversed RecyclerView in Chat Room

Excuse my English 🙂
I use recyclerview in my chatroom and with this code


make it down the top
Now I use stickHeader as an article decoration

recyclerView.addItemDecoration(new StickHeaderItemDecoration(_1_ChatRoom_Activity.this));


public class StickHeaderItemDecoration extends RecyclerView.ItemDecoration {

private StickyHeaderInterface mListener;
private int mStickyHeaderHeight;
private int layout;

public StickHeaderItemDecoration(@NonNull StickyHeaderInterface listener) {
    this.layout = R.layout.item_chat_date;
    this.mListener = listener;

public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
    super.onDrawOver(c, parent, state);
    View topChild = parent.getChildAt(0);
    if (topChild == null) return;

    int topChildPosition = parent.getChildAdapterPosition(topChild);
    if (topChildPosition == RecyclerView.NO_POSITION) {

    int headerPos = mListener.getHeaderPositionForItem(topChildPosition);
    final View currentHeader = getHeaderViewForItem(headerPos, parent);

    fixLayoutSize(parent, currentHeader);
    int contactPoint = currentHeader.getBottom();
    View childInContact = getChildInContact(parent, contactPoint, headerPos);
    if (childInContact != null && mListener.isHeader(parent.getChildAdapterPosition(childInContact))) {
        moveHeader(c, currentHeader, childInContact);

    drawHeader(c, currentHeader);

private View getHeaderViewForItem(int headerPosition, RecyclerView parent) {
    View header = LayoutInflater.from(parent.getContext()).inflate(layout, parent, false);
    mListener.bindHeaderData(header, headerPosition);
    return header;

private void drawHeader(final Canvas c, final View header) {;
    c.translate(0, 0);

private void moveHeader(final Canvas c, final View currentHeader, final View nextHeader) {;
    c.translate(0, nextHeader.getTop() - currentHeader.getHeight());

private View getChildInContact(RecyclerView parent, int contactPoint, int currentHeaderPos) {
    View childInContact = null;
    for (int i = 0; i < parent.getChildCount(); i++) {
        int heightTolerance = 0;
        View child = parent.getChildAt(i);
        if (currentHeaderPos != i) {
            boolean isChildHeader = mListener.isHeader(parent.getChildAdapterPosition(child));
            if (isChildHeader) {
                heightTolerance = mStickyHeaderHeight - child.getHeight();

        //add heightTolerance if child top be in display area
        int childBottomPosition;
        if (child.getTop() > 0) {
            childBottomPosition = child.getBottom() + heightTolerance;
        } else {
            childBottomPosition = child.getBottom();

        if (childBottomPosition > contactPoint) {
            if (child.getTop() <= contactPoint) {
                // This child overlaps the contactPoint
                childInContact = child;
    return childInContact;

private void fixLayoutSize(ViewGroup parent, View view) {
    int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED);
    // Specs for children (headers)
    int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), view.getLayoutParams().width);
    int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), view.getLayoutParams().height);

    view.measure(childWidthSpec, childHeightSpec);
    view.layout(0, 0, view.getMeasuredWidth(), mStickyHeaderHeight = view.getMeasuredHeight());


I have a UI that is implemented in chatroom activities:

public boolean isHeader(int itemPosition) {
    return models.get(itemPosition).getType() .equals("header");

public int getHeaderPositionForItem(int itemPosition) {
    int headerPosition = 0;
    do {
        if (this.isHeader(itemPosition)) {
            headerPosition = itemPosition;
        itemPosition ++;
    while (itemPosition 

and the problem is: my first header at the end of the list is repeated when scrolling the list.
means: other headers are in the right position, but between each header my first header is displayed !!!
again sorry for mistakes :))))
Thank you .

Equipment Recommendation – Looking for a cheap prime-wide lens (28mm) that can be reversed on a Canon 6D

I'm interested in experimenting with the lens for macro shooting, but since this is all an experiment, I do not want to spend so much money on it. I looked at this Youtube video and they said you could buy a 28mm wide-angle lens for about $ 50. This was a first class lens with a manual aperture ring.

I searched online, but so far the cheapest I could find was at least a few hundred dollars missing a bezel ring.

Does anyone know a cheap 28 mm Prime lens with a diaphragm ring, which I can mount on a Canon 6D?

Layout – Is there a reason why the discussion in e-mail threads is reversed?

In all e-mail clients I know, the answer is written at the top of the e-mail when someone responds to an e-mail.

I do not understand the reason for this decision. It appears that:

  • For each email that is long enough to require a vertical scroll bar, I need to scroll up before answering.

  • It is very cumbersome to read a discussion with several e-mails. I have to read a piece of text from top to bottom, then jump up and find the beginning of the next message.

  • It's just counterintuitive. Books, scientific articles and websites are written from top to bottom. The first chapter is not at the end of the book and the last chapter is at the beginning.

What would explain this original decision? I mean, since somebody around 1985 had the idea of ​​doing this in that way rather than using a common paradigm for existing content like books, there was probably a good reason for that. Or was it purely technical?

Mixer – Material slot is reversed when importing the .blend file into Unity?

I import the .blend file into the unit. The file contains 9 separate objects. Now all objects have been assigned the same 2 materials. When importing into Unity, the material slot of an object is reversed. But in the mixer, I set the slots correctly.

Plug in the blender
Blender img

Slot in the unit
Unit img

This only happens for one object (Kurve.076).
This is important to me as I assign the material from the code to each slot.
Here is the .blend file if you want to look at it. download

Unit 2018.3.4f1

Mixer 2.79b

Why are the controls reversed when flying in a game or vice versa?

In an actual plane, the steering column is not really pulled up or down. Instead, the pilot pushes the steering wheel or joystick away to dive and pulls it towards him to pull up. The same applies to games that you control with a joystick. You push it away to go forward and back to go backwards.

This forward and backward movement is most likely the reason why inverted controls are intuitive for flying in a game. If you lean forward, your body turns to the floor as you lean backwards to look up. This corresponds to the mental model of flying a plane and the associated inclination of the plane itself.

Why were the up and down keys inverted? Up Arrow indicates forward movement of the Joystick / Yoke corresponding to a dive in an aircraft. The arrow pointing down indicates a backward movement of the joystick / yoke, which refers to pulling up.

The answer has been edited to include some of the comments from GalacticCowboy and Austin French

Why are the forward / backward keyboard shortcuts in Google Calendar reversed?

The j/k The keys come from the text editor Vi and the computer terminals ADM3A for which they were originally used vertical Navigation – they mean "cursor down" or "cursor up". The complete set can be found under HJKL buttons.

(These hidden hotkeys are also found in various other webapps today, such as Twitter timelines or Ars Technica comment threads.)

because j If you move the mouse pointer down in this keymap, it makes sense to scroll down to the next element. In previous versions of the Google Calendar interface, this was an obvious choice using vertical scrolling for the month view. (If I remember correctly, that's it.)

The only problem is that the redesign of "Material 2" for Google Calendar has been switched to page scrolling for months, which is no longer the hotkey selection. (And, IMHO, is generally uninteresting for a calendar – even if I wipe left / right in the Android app.)

Algorithms – For a bit sequence, you generate all bit sequences with n reversed bits

For an algorithm, I have to be able to go through all the bit strings where $ k $ Bits are reversed when a bit string of length is specified $ n $ and $ n geq k $, For example, suppose I have the bit string $ 1001 and I want to have all the bit strings with me $ 2 $ Bits turned around. This should result in the following bit sequences:


So a small length $ n $ and where $ k $ Bits are reversed and the result is displayed $ binom {n} {k} $ Cords. Is there an efficient way to generate all? The bitstrings I have as input are only unsigned integers, so I can use some twiddling!

Will most of these decisions that judges now take against Trump not be reversed by the Supreme Court?

If the judges based their decisions on the Constitution as it should, then they are highly unlikely to be overturned. I think you'll see a slight left turn by Roberts, as he does not want a split court, and though I disagree with some political leanings, I think at his core, he wants to do the right thing.