这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit 648dbff

Browse files
Merge pull request #38 from dkramer95/float-bubble-fixes
Fixed: Fix float button default size and outline
2 parents 90f908d + f7c212a commit 648dbff

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

app/src/main/java/com/termux/window/FloatingBubbleManager.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package com.termux.window;
22

3+
import android.graphics.Outline;
34
import android.graphics.drawable.Drawable;
45
import android.view.View;
56
import android.view.ViewGroup;
7+
import android.view.ViewOutlineProvider;
68
import android.view.WindowManager;
79

10+
import com.termux.shared.view.ViewUtils;
811
import com.termux.view.TerminalView;
912

1013
/**
1114
* Handles displaying our TermuxFloatView as a collapsed bubble and restoring back
1215
* to its original display.
1316
*/
1417
public 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();

app/src/main/res/drawable/round_button.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

app/src/main/res/drawable/round_button_with_outline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<shape android:shape="oval">
55
<solid android:color="@android:color/black" />
66
<stroke android:color="@android:color/white"
7-
android:width="1dp" />
7+
android:width="@dimen/bubble_outline_stroke_width" />
88
</shape>
99
</item>
1010
</selector>

app/src/main/res/values/dimens.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<dimen name="bubble_outline_stroke_width">1dp</dimen>
4+
</resources>

0 commit comments

Comments
 (0)