1
1
package com .termux .window ;
2
2
3
+ import android .graphics .Outline ;
3
4
import android .graphics .drawable .Drawable ;
4
5
import android .view .View ;
5
6
import android .view .ViewGroup ;
7
+ import android .view .ViewOutlineProvider ;
6
8
import android .view .WindowManager ;
7
9
10
+ import com .termux .shared .view .ViewUtils ;
8
11
import com .termux .view .TerminalView ;
9
12
10
13
/**
11
14
* Handles displaying our TermuxFloatView as a collapsed bubble and restoring back
12
15
* to its original display.
13
16
*/
14
17
public class FloatingBubbleManager {
15
- private static final int BUBBLE_SIZE = 200 ;
18
+ private static final int DEFAULT_BUBBLE_SIZE_DP = 56 ;
16
19
17
20
private TermuxFloatView mTermuxFloatView ;
21
+ private final int BUBBLE_SIZE_PX ;
18
22
19
23
private boolean mIsMinimized ;
20
24
@@ -26,9 +30,9 @@ public class FloatingBubbleManager {
26
30
private Drawable mOriginalTerminalViewBackground ;
27
31
private Drawable mOriginalFloatViewBackground ;
28
32
29
-
30
33
public FloatingBubbleManager (TermuxFloatView termuxFloatView ) {
31
34
mTermuxFloatView = termuxFloatView ;
35
+ BUBBLE_SIZE_PX = ViewUtils .dpToPx (mTermuxFloatView .getContext (), DEFAULT_BUBBLE_SIZE_DP );
32
36
}
33
37
34
38
public void toggleBubble () {
@@ -50,11 +54,20 @@ public void displayAsFloatingBubble() {
50
54
captureOriginalLayoutValues ();
51
55
52
56
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 ;
55
60
56
61
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
+ });
58
71
terminalView .setClipToOutline (true );
59
72
60
73
TermuxFloatView termuxFloatView = getTermuxFloatView ();
@@ -79,6 +92,7 @@ public void displayAsFloatingWindow() {
79
92
80
93
TerminalView terminalView = getTerminalView ();
81
94
terminalView .setBackground (mOriginalTerminalViewBackground );
95
+ terminalView .setOutlineProvider (null );
82
96
terminalView .setClipToOutline (false );
83
97
84
98
TermuxFloatView termuxFloatView = getTermuxFloatView ();
0 commit comments