mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-09 03:54:17 +08:00
Added: Add support for ~/.termux/termux.float.properties
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.termux.shared.settings.properties;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.termux.shared.termux.TermuxConstants;
|
||||
import com.termux.shared.logger.Logger;
|
||||
@@ -12,7 +14,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/*
|
||||
* Version: v0.13.0
|
||||
* Version: v0.14.0
|
||||
*
|
||||
* Changelog
|
||||
*
|
||||
@@ -58,6 +60,9 @@ import java.util.Set;
|
||||
*
|
||||
* - 0.13.0 (2021-08-25)
|
||||
* - Add `*KEY_TERMINAL_MARGIN_HORIZONTAL*` and `*KEY_TERMINAL_MARGIN_VERTICAL*`.
|
||||
*
|
||||
* - 0.14.0 (2021-09-02)
|
||||
* - Add `getTermuxFloatPropertiesFile()`.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -390,11 +395,28 @@ public final class TermuxPropertyConstants {
|
||||
* @return Returns the {@link File} object for termux properties.
|
||||
*/
|
||||
public static File getTermuxPropertiesFile() {
|
||||
String[] possiblePropertiesFileLocations = {
|
||||
return getPropertiesFile(new String[]{
|
||||
TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH,
|
||||
TermuxConstants.TERMUX_PROPERTIES_SECONDARY_FILE_PATH
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** Returns the first {@link File} found at
|
||||
* {@link TermuxConstants#TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH} or
|
||||
* {@link TermuxConstants#TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH}
|
||||
* from which termux properties can be loaded.
|
||||
* If the {@link File} found is not a regular file or is not readable then null is returned.
|
||||
*
|
||||
* @return Returns the {@link File} object for termux properties.
|
||||
*/
|
||||
public static File getTermuxFloatPropertiesFile() {
|
||||
return getPropertiesFile(new String[]{
|
||||
TermuxConstants.TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH,
|
||||
TermuxConstants.TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH
|
||||
});
|
||||
}
|
||||
|
||||
public static File getPropertiesFile(@NonNull String[] possiblePropertiesFileLocations) {
|
||||
File propertiesFile = new File(possiblePropertiesFileLocations[0]);
|
||||
int i = 0;
|
||||
while (!propertiesFile.exists() && i < possiblePropertiesFileLocations.length) {
|
||||
@@ -405,7 +427,7 @@ public final class TermuxPropertyConstants {
|
||||
if (propertiesFile.isFile() && propertiesFile.canRead()) {
|
||||
return propertiesFile;
|
||||
} else {
|
||||
Logger.logDebug("No readable termux.properties file found");
|
||||
Logger.logDebug("No readable properties file found at: " + Arrays.toString(possiblePropertiesFileLocations));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@ package com.termux.shared.settings.properties;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.termux.shared.logger.Logger;
|
||||
import com.termux.shared.data.DataUtils;
|
||||
|
||||
@@ -10,21 +12,25 @@ import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class TermuxSharedProperties {
|
||||
public abstract class TermuxSharedProperties {
|
||||
|
||||
protected final Context mContext;
|
||||
protected final SharedProperties mSharedProperties;
|
||||
protected final String mLabel;
|
||||
protected final File mPropertiesFile;
|
||||
protected final SharedProperties mSharedProperties;
|
||||
|
||||
public static final String LOG_TAG = "TermuxSharedProperties";
|
||||
|
||||
public TermuxSharedProperties(@Nonnull Context context) {
|
||||
public TermuxSharedProperties(@Nonnull Context context, @NonNull String label, File propertiesFile,
|
||||
@NonNull Set<String> propertiesList, @NonNull SharedPropertiesParser sharedPropertiesParser) {
|
||||
mContext = context;
|
||||
mPropertiesFile = TermuxPropertyConstants.getTermuxPropertiesFile();
|
||||
mSharedProperties = new SharedProperties(context, mPropertiesFile, TermuxPropertyConstants.TERMUX_PROPERTIES_LIST, new SharedPropertiesParserClient());
|
||||
mLabel = label;
|
||||
mPropertiesFile = propertiesFile;
|
||||
mSharedProperties = new SharedProperties(context, mPropertiesFile, propertiesList, sharedPropertiesParser);
|
||||
loadTermuxPropertiesFromDisk();
|
||||
}
|
||||
|
||||
@@ -162,7 +168,7 @@ public class TermuxSharedProperties {
|
||||
|
||||
/**
|
||||
* Get the internal {@link Object} value for the key passed from the file returned by
|
||||
* {@link TermuxPropertyConstants#getTermuxPropertiesFile()}. The {@link Properties} object is
|
||||
* {@code propertiesFile}. The {@link Properties} object is
|
||||
* read directly from the file and internal value is returned for the property value against the key.
|
||||
*
|
||||
* @param context The context for operations.
|
||||
@@ -170,8 +176,9 @@ public class TermuxSharedProperties {
|
||||
* @return Returns the {@link Object} object. This will be {@code null} if key is not found or
|
||||
* the object stored against the key is {@code null}.
|
||||
*/
|
||||
public static Object getInternalPropertyValue(Context context, String key) {
|
||||
return SharedProperties.getInternalProperty(context, TermuxPropertyConstants.getTermuxPropertiesFile(), key, new SharedPropertiesParserClient());
|
||||
public static Object getInternalPropertyValue(Context context, File propertiesFile, String key,
|
||||
@NonNull SharedPropertiesParser sharedPropertiesParser) {
|
||||
return SharedProperties.getInternalProperty(context, propertiesFile, key, sharedPropertiesParser);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -588,7 +595,7 @@ public class TermuxSharedProperties {
|
||||
Properties properties = getProperties(true);
|
||||
StringBuilder propertiesDump = new StringBuilder();
|
||||
|
||||
propertiesDump.append("Termux Properties:");
|
||||
propertiesDump.append(mLabel).append(" Termux Properties:");
|
||||
if (properties != null) {
|
||||
for (String key : properties.stringPropertyNames()) {
|
||||
propertiesDump.append("\n").append(key).append(": `").append(properties.get(key)).append("`");
|
||||
@@ -604,7 +611,7 @@ public class TermuxSharedProperties {
|
||||
HashMap<String, Object> internalProperties = (HashMap<String, Object>) getInternalProperties();
|
||||
StringBuilder internalPropertiesDump = new StringBuilder();
|
||||
|
||||
internalPropertiesDump.append("Termux Internal Properties:");
|
||||
internalPropertiesDump.append(mLabel).append(" Internal Properties:");
|
||||
if (internalProperties != null) {
|
||||
for (String key : internalProperties.keySet()) {
|
||||
internalPropertiesDump.append("\n").append(key).append(": `").append(internalProperties.get(key)).append("`");
|
||||
|
Reference in New Issue
Block a user