mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Fix bubble desired height calculation.
This commit is contained in:
committed by
Cody Henthorne
parent
7428e1e2ea
commit
bd121e47c8
@@ -4,8 +4,10 @@ import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -14,6 +16,7 @@ import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.DimensionUnit;
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||
@@ -35,6 +38,8 @@ public final class BubbleUtil {
|
||||
private static final String TAG = Log.tag(BubbleUtil.class);
|
||||
private static String currentState = "";
|
||||
|
||||
private static final float MIN_BUBBLE_HEIGHT_DP = 600f;
|
||||
private static final float BUBBLE_HEIGHT_SCREEN_FRACTION = 0.9f;
|
||||
private BubbleUtil() {
|
||||
}
|
||||
|
||||
@@ -134,4 +139,26 @@ public final class BubbleUtil {
|
||||
SHOWN,
|
||||
HIDDEN
|
||||
}
|
||||
|
||||
public static int getDesiredBubbleHeightPx(@NonNull Context context) {
|
||||
int minHeightPx = (int) DimensionUnit.DP.toPixels(MIN_BUBBLE_HEIGHT_DP);
|
||||
int screenHeightPx = context.getResources().getDisplayMetrics().heightPixels;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
WindowManager wm = context.getSystemService(WindowManager.class);
|
||||
if (wm != null) {
|
||||
Rect bounds = wm.getCurrentWindowMetrics().getBounds();
|
||||
screenHeightPx = bounds.height();
|
||||
}
|
||||
}
|
||||
|
||||
if (screenHeightPx <= 0) {
|
||||
return minHeightPx;
|
||||
}
|
||||
|
||||
int targetPx = (int) (screenHeightPx * BUBBLE_HEIGHT_SCREEN_FRACTION);
|
||||
int desiredPx = Math.max(minHeightPx, targetPx);
|
||||
|
||||
return Math.min(desiredPx, screenHeightPx);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user