mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 18:55:31 +08:00
Fix problem with font and color loading at startup
Using View#post() does not work in onCreate().
This commit is contained in:
@@ -136,9 +136,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
if (ensureStoragePermissionGranted()) TermuxInstaller.setupStorageSymlinks(TermuxActivity.this);
|
if (ensureStoragePermissionGranted()) TermuxInstaller.setupStorageSymlinks(TermuxActivity.this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (whatToReload == null || "colors".equals(whatToReload)) mTerminalView.checkForColors();
|
mTerminalView.checkForFontAndColors();
|
||||||
if (whatToReload == null || "font".equals(whatToReload)) mTerminalView.checkForTypeface();
|
mSettings.reloadFromProperties(TermuxActivity.this);
|
||||||
if (whatToReload == null || "settings".equals(whatToReload)) mSettings.reloadFromProperties(TermuxActivity.this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -281,14 +280,16 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
findViewById(R.id.new_session_button).setOnClickListener(new OnClickListener() {
|
View newSessionButton = findViewById(R.id.new_session_button);
|
||||||
|
|
||||||
|
newSessionButton.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
addNewSession(false, null);
|
addNewSession(false, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
findViewById(R.id.new_session_button).setOnLongClickListener(new OnLongClickListener() {
|
newSessionButton.setOnLongClickListener(new OnLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
Resources res = getResources();
|
Resources res = getResources();
|
||||||
@@ -336,8 +337,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
startService(serviceIntent);
|
startService(serviceIntent);
|
||||||
if (!bindService(serviceIntent, this, 0)) throw new RuntimeException("bindService() failed");
|
if (!bindService(serviceIntent, this, 0)) throw new RuntimeException("bindService() failed");
|
||||||
|
|
||||||
mTerminalView.checkForTypeface();
|
mTerminalView.checkForFontAndColors();
|
||||||
mTerminalView.checkForColors();
|
|
||||||
|
|
||||||
mBellSoundId = mBellSoundPool.load(this, R.raw.bell, 1);
|
mBellSoundId = mBellSoundPool.load(this, R.raw.bell, 1);
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,5 @@
|
|||||||
package com.termux.view;
|
package com.termux.view;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import com.termux.terminal.EmulatorDebug;
|
|
||||||
import com.termux.terminal.KeyHandler;
|
|
||||||
import com.termux.terminal.TerminalColors;
|
|
||||||
import com.termux.terminal.TerminalEmulator;
|
|
||||||
import com.termux.terminal.TerminalSession;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@@ -30,6 +19,17 @@ import android.view.inputmethod.EditorInfo;
|
|||||||
import android.view.inputmethod.InputConnection;
|
import android.view.inputmethod.InputConnection;
|
||||||
import android.widget.Scroller;
|
import android.widget.Scroller;
|
||||||
|
|
||||||
|
import com.termux.terminal.EmulatorDebug;
|
||||||
|
import com.termux.terminal.KeyHandler;
|
||||||
|
import com.termux.terminal.TerminalColors;
|
||||||
|
import com.termux.terminal.TerminalEmulator;
|
||||||
|
import com.termux.terminal.TerminalSession;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/** View displaying and interacting with a {@link TerminalSession}. */
|
/** View displaying and interacting with a {@link TerminalSession}. */
|
||||||
public final class TerminalView extends View {
|
public final class TerminalView extends View {
|
||||||
|
|
||||||
@@ -710,68 +710,29 @@ public final class TerminalView extends View {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkForTypeface() {
|
public void checkForFontAndColors() {
|
||||||
new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
File fontFile = new File("/data/data/com.termux/files/home/.termux/font.ttf");
|
File fontFile = new File("/data/data/com.termux/files/home/.termux/font.ttf");
|
||||||
final Typeface newTypeface = fontFile.exists() ? Typeface.createFromFile(fontFile) : Typeface.MONOSPACE;
|
|
||||||
if (newTypeface != mRenderer.mTypeface) {
|
|
||||||
post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
mRenderer = new TerminalRenderer(mRenderer.mTextSize, newTypeface);
|
|
||||||
updateSize();
|
|
||||||
invalidate();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(EmulatorDebug.LOG_TAG, "Error loading font", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(EmulatorDebug.LOG_TAG, "Error loading font", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkForColors() {
|
|
||||||
new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
File colorsFile = new File("/data/data/com.termux/files/home/.termux/colors.properties");
|
File colorsFile = new File("/data/data/com.termux/files/home/.termux/colors.properties");
|
||||||
final Properties props = colorsFile.isFile() ? new Properties() : null;
|
|
||||||
if (props != null) {
|
final Properties props = new Properties();
|
||||||
|
if (colorsFile.isFile()) {
|
||||||
try (InputStream in = new FileInputStream(colorsFile)) {
|
try (InputStream in = new FileInputStream(colorsFile)) {
|
||||||
props.load(in);
|
props.load(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
if (props == null) {
|
|
||||||
TerminalColors.COLOR_SCHEME.reset();
|
|
||||||
} else {
|
|
||||||
TerminalColors.COLOR_SCHEME.updateWith(props);
|
TerminalColors.COLOR_SCHEME.updateWith(props);
|
||||||
}
|
|
||||||
if (mEmulator != null) mEmulator.mColors.reset();
|
if (mEmulator != null) mEmulator.mColors.reset();
|
||||||
|
|
||||||
|
final Typeface newTypeface = fontFile.exists() ? Typeface.createFromFile(fontFile) : Typeface.MONOSPACE;
|
||||||
|
mRenderer = new TerminalRenderer(mRenderer.mTextSize, newTypeface);
|
||||||
|
updateSize();
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(EmulatorDebug.LOG_TAG, "Setting colors failed: " + e.getMessage());
|
Log.e(EmulatorDebug.LOG_TAG, "Error loading font", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(EmulatorDebug.LOG_TAG, "Failed colors handling", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called during layout when the size of this view has changed. If you were just added to the view
|
* This is called during layout when the size of this view has changed. If you were just added to the view
|
||||||
|
Reference in New Issue
Block a user