Skip to content

Commit 906ca2d

Browse files
committed
Android 8.0 compatibility with overlay type
Also check for custom font in ~/.termux/font.ttf
1 parent 11fb650 commit 906ca2d

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import android.content.Context;
55
import android.graphics.PixelFormat;
66
import android.graphics.Point;
7+
import android.graphics.Typeface;
8+
import android.os.Build;
79
import android.util.AttributeSet;
10+
import android.util.Log;
811
import android.view.Gravity;
912
import android.view.MotionEvent;
1013
import android.view.ScaleGestureDetector;
@@ -14,8 +17,11 @@
1417
import android.widget.LinearLayout;
1518
import android.widget.Toast;
1619

20+
import com.termux.terminal.EmulatorDebug;
1721
import com.termux.view.TerminalView;
1822

23+
import java.io.File;
24+
1925
public class TermuxFloatView extends LinearLayout {
2026

2127
public static final float ALPHA_FOCUS = 0.9f;
@@ -94,7 +100,17 @@ protected void onAttachedToWindow() {
94100
DISPLAY_WIDTH = displaySize.x;
95101
DISPLAY_HEIGHT = displaySize.y;
96102

97-
// mTerminalView.checkForFontAndColors();
103+
checkForFont();
104+
}
105+
106+
void checkForFont() {
107+
try {
108+
@SuppressLint("SdCardPath") File fontFile = new File("/data/data/com.termux/files/home/.termux/font.ttf");
109+
final Typeface newTypeface = (fontFile.exists() && fontFile.length() > 0) ? Typeface.createFromFile(fontFile) : Typeface.MONOSPACE;
110+
mTerminalView.setTypeface(newTypeface);
111+
} catch (Exception e) {
112+
Log.e(EmulatorDebug.LOG_TAG, "Error in checkForFont()", e);
113+
}
98114
}
99115

100116
@SuppressLint("RtlHardcoded")
@@ -103,7 +119,11 @@ public void launchFloatingWindow() {
103119
layoutParams.flags = computeLayoutFlags(true);
104120
layoutParams.width = widthAndHeight;
105121
layoutParams.height = widthAndHeight;
106-
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
122+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
123+
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
124+
} else {
125+
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
126+
}
107127
layoutParams.format = PixelFormat.RGBA_8888;
108128

109129
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;

0 commit comments

Comments
 (0)