这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions app/src/main/java/com/termux/window/FloatingBubbleManager.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.termux.window;

import android.graphics.Outline;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.WindowManager;

import com.termux.shared.view.ViewUtils;
import com.termux.view.TerminalView;

/**
* Handles displaying our TermuxFloatView as a collapsed bubble and restoring back
* to its original display.
*/
public class FloatingBubbleManager {
private static final int BUBBLE_SIZE = 200;
private static final int DEFAULT_BUBBLE_SIZE_DP = 56;

private TermuxFloatView mTermuxFloatView;
private final int BUBBLE_SIZE_PX;

private boolean mIsMinimized;

Expand All @@ -26,9 +30,9 @@ public class FloatingBubbleManager {
private Drawable mOriginalTerminalViewBackground;
private Drawable mOriginalFloatViewBackground;


public FloatingBubbleManager(TermuxFloatView termuxFloatView) {
mTermuxFloatView = termuxFloatView;
BUBBLE_SIZE_PX = ViewUtils.dpToPx(mTermuxFloatView.getContext(), DEFAULT_BUBBLE_SIZE_DP);
}

public void toggleBubble() {
Expand All @@ -50,11 +54,20 @@ public void displayAsFloatingBubble() {
captureOriginalLayoutValues();

WindowManager.LayoutParams layoutParams = getLayoutParams();
layoutParams.width = BUBBLE_SIZE;
layoutParams.height = BUBBLE_SIZE;

layoutParams.width = BUBBLE_SIZE_PX;
layoutParams.height = BUBBLE_SIZE_PX;

TerminalView terminalView = getTerminalView();
terminalView.setBackgroundResource(R.drawable.round_button);
final int strokeWidth = (int) terminalView.getResources().getDimension(R.dimen.bubble_outline_stroke_width);
terminalView.setOutlineProvider(new ViewOutlineProvider() {
@SuppressWarnings("SuspiciousNameCombination")
@Override
public void getOutline(View view, Outline outline) {
// shrink TerminalView clipping a bit so it doesn't cut off our bubble outline
outline.setOval(strokeWidth, strokeWidth, view.getWidth() - strokeWidth, view.getHeight() - strokeWidth);
}
});
terminalView.setClipToOutline(true);

TermuxFloatView termuxFloatView = getTermuxFloatView();
Expand All @@ -79,6 +92,7 @@ public void displayAsFloatingWindow() {

TerminalView terminalView = getTerminalView();
terminalView.setBackground(mOriginalTerminalViewBackground);
terminalView.setOutlineProvider(null);
terminalView.setClipToOutline(false);

TermuxFloatView termuxFloatView = getTermuxFloatView();
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/res/drawable/round_button.xml

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/res/drawable/round_button_with_outline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<shape android:shape="oval">
<solid android:color="@android:color/black" />
<stroke android:color="@android:color/white"
android:width="1dp" />
android:width="@dimen/bubble_outline_stroke_width" />
</shape>
</item>
</selector>
4 changes: 4 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="bubble_outline_stroke_width">1dp</dimen>
</resources>