Skip to content

Commit

Permalink
card position MVP 🥳
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Aug 16, 2023
1 parent f2bc8ef commit ce0ca7f
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions app/src/main/java/phone/vishnu/quotes/helper/ExportHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.media.MediaScannerConnection;
Expand Down Expand Up @@ -153,6 +152,8 @@ private Bitmap getBitmap(Context context, Quote q) {
int widthPixels = 1080;
int heightPixels = 1920;

int DP_8 = Utils.Companion.DPtoPX(context, 8);

String cardColor = sharedPreferenceHelper.getCardColorPreference();
String fontColor = sharedPreferenceHelper.getFontColorPreference();
String fontPath = sharedPreferenceHelper.getFontPath();
Expand Down Expand Up @@ -209,19 +210,28 @@ private Bitmap getBitmap(Context context, Quote q) {
shareView.measure(
View.MeasureSpec.makeMeasureSpec(widthPixels, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(heightPixels, View.MeasureSpec.EXACTLY));
shareView.layout(0, 0, widthPixels, heightPixels);

Rect offsetViewBounds = new Rect();
cardView.getDrawingRect(offsetViewBounds);
relativeLayout.offsetDescendantRectToMyCoords(cardView, offsetViewBounds);
int cardViewWidth = cardView.getWidth();
int cardViewHeight = cardView.getHeight();

if (cardX != -1) cardView.setX((widthPixels - offsetViewBounds.left) / cardX);
if (cardY != -1) cardView.setY((heightPixels - offsetViewBounds.top) / cardY - 960);
float finalX = Math.max(0, widthPixels / cardX); // left bound
float finalY = Math.max(0, heightPixels / cardY); // top bound

Bitmap bitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888);
if (cardX != -1)
cardView.setX(
finalX + cardViewWidth > widthPixels
? widthPixels - cardViewWidth - DP_8
: finalX); // right bound

Canvas c = new Canvas(bitmap);
shareView.layout(0, 0, widthPixels, heightPixels);
shareView.draw(c);
if (cardY != -1)
cardView.setY(
finalY + cardViewHeight > heightPixels
? heightPixels - cardViewHeight - DP_8
: finalY); // bottom bound

Bitmap bitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888);
shareView.draw(new Canvas(bitmap));

return bitmap;
}
Expand Down

0 comments on commit ce0ca7f

Please sign in to comment.