Skip to content
This repository has been archived by the owner on Oct 23, 2020. It is now read-only.

Fix saveButtonOriginalPosition #261

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
Expand Down Expand Up @@ -98,6 +99,8 @@ public class FloatingActionButton extends ImageButton {
private int mProgressMax = 100;
private boolean mShowProgressBackground;

private boolean isLayoutInit = false;

public FloatingActionButton(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -165,6 +168,21 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {

// updateBackground();
setClickable(true);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
this.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
isLayoutInit = true;
saveButtonOriginalPosition();
getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
} else {
isLayoutInit = true;
}
}

private void initShowAnimation(TypedArray attr) {
Expand Down Expand Up @@ -439,7 +457,7 @@ private void setBackgroundCompat(Drawable drawable) {
}

private void saveButtonOriginalPosition() {
if (!mButtonPositionSaved) {
if (!mButtonPositionSaved && isLayoutInit) {
if (mOriginalX == -1) {
mOriginalX = getX();
}
Expand All @@ -448,6 +466,11 @@ private void saveButtonOriginalPosition() {
mOriginalY = getY();
}

if (mProgressBarEnabled) {
mOriginalX = mOriginalX + mProgressWidth;
mOriginalY = mOriginalY + mProgressWidth;
}

mButtonPositionSaved = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
}

final FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
// fab.setIndeterminate(true); // To reproduce the bug
fab.setMax(mMaxProgress);

RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view);
Expand Down