Skip to content

Commit

Permalink
restore stored position in CustomiseFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Aug 13, 2023
1 parent da6de63 commit d91e619
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
Expand Down Expand Up @@ -118,6 +119,23 @@ public void onViewCreated(
quoteTextView.setText(quote);
authorTextView.setText(author);

constraintLayout.post(
() -> {
Rect offsetViewBounds = new Rect();
cardView.getDrawingRect(offsetViewBounds);
constraintLayout.offsetDescendantRectToMyCoords(cardView, offsetViewBounds);

float cardX = sharedPreferenceHelper.getCardX();
float cardY = sharedPreferenceHelper.getCardY();

if (cardX != -1)
cardView.setX(
(constraintLayout.getWidth() - offsetViewBounds.left) / cardX);
if (cardY != -1)
cardView.setY(
(constraintLayout.getHeight() - offsetViewBounds.top) / cardY);
});

AtomicReference<Float> dX = new AtomicReference<>(cardView.getX());
AtomicReference<Float> dY = new AtomicReference<>(cardView.getY());

Expand Down

0 comments on commit d91e619

Please sign in to comment.