11package com .termux .window ;
22
3+ import android .graphics .Outline ;
34import android .graphics .drawable .Drawable ;
45import android .view .View ;
56import android .view .ViewGroup ;
7+ import android .view .ViewOutlineProvider ;
68import android .view .WindowManager ;
79
10+ import com .termux .shared .view .ViewUtils ;
811import com .termux .view .TerminalView ;
912
1013/**
1114 * Handles displaying our TermuxFloatView as a collapsed bubble and restoring back
1215 * to its original display.
1316 */
1417public class FloatingBubbleManager {
15- private static final int BUBBLE_SIZE = 200 ;
18+ private static final int DEFAULT_BUBBLE_SIZE_DP = 56 ;
1619
1720 private TermuxFloatView mTermuxFloatView ;
21+ private final int BUBBLE_SIZE_PX ;
1822
1923 private boolean mIsMinimized ;
2024
@@ -26,9 +30,9 @@ public class FloatingBubbleManager {
2630 private Drawable mOriginalTerminalViewBackground ;
2731 private Drawable mOriginalFloatViewBackground ;
2832
29-
3033 public FloatingBubbleManager (TermuxFloatView termuxFloatView ) {
3134 mTermuxFloatView = termuxFloatView ;
35+ BUBBLE_SIZE_PX = ViewUtils .dpToPx (mTermuxFloatView .getContext (), DEFAULT_BUBBLE_SIZE_DP );
3236 }
3337
3438 public void toggleBubble () {
@@ -50,11 +54,20 @@ public void displayAsFloatingBubble() {
5054 captureOriginalLayoutValues ();
5155
5256 WindowManager .LayoutParams layoutParams = getLayoutParams ();
53- layoutParams .width = BUBBLE_SIZE ;
54- layoutParams .height = BUBBLE_SIZE ;
57+
58+ layoutParams .width = BUBBLE_SIZE_PX ;
59+ layoutParams .height = BUBBLE_SIZE_PX ;
5560
5661 TerminalView terminalView = getTerminalView ();
57- terminalView .setBackgroundResource (R .drawable .round_button );
62+ final int strokeWidth = (int ) terminalView .getResources ().getDimension (R .dimen .bubble_outline_stroke_width );
63+ terminalView .setOutlineProvider (new ViewOutlineProvider () {
64+ @ SuppressWarnings ("SuspiciousNameCombination" )
65+ @ Override
66+ public void getOutline (View view , Outline outline ) {
67+ // shrink TerminalView clipping a bit so it doesn't cut off our bubble outline
68+ outline .setOval (strokeWidth , strokeWidth , view .getWidth () - strokeWidth , view .getHeight () - strokeWidth );
69+ }
70+ });
5871 terminalView .setClipToOutline (true );
5972
6073 TermuxFloatView termuxFloatView = getTermuxFloatView ();
@@ -79,6 +92,7 @@ public void displayAsFloatingWindow() {
7992
8093 TerminalView terminalView = getTerminalView ();
8194 terminalView .setBackground (mOriginalTerminalViewBackground );
95+ terminalView .setOutlineProvider (null );
8296 terminalView .setClipToOutline (false );
8397
8498 TermuxFloatView termuxFloatView = getTermuxFloatView ();
0 commit comments