Skip to content

Commit

Permalink
Merge pull request #38 from dkramer95/float-bubble-fixes
Browse files Browse the repository at this point in the history
Fixed: Fix float button default size and outline
  • Loading branch information
agnostic-apollo authored Sep 3, 2021
2 parents 90f908d + f7c212a commit 648dbff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
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>

0 comments on commit 648dbff

Please sign in to comment.