Skip to content

Commit bc779d2

Browse files
Added: Add support for ~/.termux/termux.float.properties
1 parent 9f1203f commit bc779d2

File tree

8 files changed

+66
-20
lines changed

8 files changed

+66
-20
lines changed

app/src/main/java/com/termux/app/settings/properties/TermuxAppSharedProperties.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.termux.shared.logger.Logger;
1010
import com.termux.shared.settings.properties.TermuxPropertyConstants;
1111
import com.termux.shared.settings.properties.TermuxSharedProperties;
12+
import com.termux.shared.termux.TermuxConstants;
1213

1314
import org.json.JSONException;
1415

@@ -26,7 +27,8 @@ public class TermuxAppSharedProperties extends TermuxSharedProperties {
2627
private static final String LOG_TAG = "TermuxAppSharedProperties";
2728

2829
public TermuxAppSharedProperties(@Nonnull Context context) {
29-
super(context);
30+
super(context, TermuxConstants.TERMUX_APP_NAME, TermuxPropertyConstants.getTermuxPropertiesFile(),
31+
TermuxPropertyConstants.TERMUX_PROPERTIES_LIST, new SharedPropertiesParserClient());
3032
}
3133

3234
/**
@@ -110,7 +112,8 @@ public ExtraKeysInfo getExtraKeysInfo() {
110112
* Load the {@link TermuxPropertyConstants#KEY_TERMINAL_TRANSCRIPT_ROWS} value from termux properties file on disk.
111113
*/
112114
public static int getTerminalTranscriptRows(Context context) {
113-
return (int) TermuxSharedProperties.getInternalPropertyValue(context, TermuxPropertyConstants.KEY_TERMINAL_TRANSCRIPT_ROWS);
115+
return (int) TermuxSharedProperties.getInternalPropertyValue(context, TermuxPropertyConstants.getTermuxPropertiesFile(),
116+
TermuxPropertyConstants.KEY_TERMINAL_TRANSCRIPT_ROWS, new SharedPropertiesParserClient());
114117
}
115118

116119
}

app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.termux.shared.termux.TermuxConstants;
2121
import com.termux.app.TermuxService;
2222
import com.termux.shared.settings.properties.TermuxPropertyConstants;
23-
import com.termux.app.terminal.io.BellHandler;
23+
import com.termux.shared.terminal.io.BellHandler;
2424
import com.termux.shared.logger.Logger;
2525
import com.termux.terminal.TerminalColors;
2626
import com.termux.terminal.TerminalSession;

app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void onReload() {
140140
}
141141

142142
/**
143-
* Should be called when {@link com.termux.view.TerminalView#mEmulator}
143+
* Should be called when {@link com.termux.view.TerminalView#mEmulator} is set
144144
*/
145145
@Override
146146
public void onEmulatorSet() {

termux-shared/src/main/java/com/termux/shared/settings/properties/TermuxPropertyConstants.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.termux.shared.settings.properties;
22

3+
import androidx.annotation.NonNull;
4+
35
import com.google.common.collect.ImmutableBiMap;
46
import com.termux.shared.termux.TermuxConstants;
57
import com.termux.shared.logger.Logger;
@@ -12,7 +14,7 @@
1214
import java.util.Set;
1315

1416
/*
15-
* Version: v0.13.0
17+
* Version: v0.14.0
1618
*
1719
* Changelog
1820
*
@@ -58,6 +60,9 @@
5860
*
5961
* - 0.13.0 (2021-08-25)
6062
* - Add `*KEY_TERMINAL_MARGIN_HORIZONTAL*` and `*KEY_TERMINAL_MARGIN_VERTICAL*`.
63+
*
64+
* - 0.14.0 (2021-09-02)
65+
* - Add `getTermuxFloatPropertiesFile()`.
6166
*/
6267

6368
/**
@@ -390,11 +395,28 @@ public final class TermuxPropertyConstants {
390395
* @return Returns the {@link File} object for termux properties.
391396
*/
392397
public static File getTermuxPropertiesFile() {
393-
String[] possiblePropertiesFileLocations = {
398+
return getPropertiesFile(new String[]{
394399
TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH,
395400
TermuxConstants.TERMUX_PROPERTIES_SECONDARY_FILE_PATH
396-
};
401+
});
402+
}
403+
404+
/** Returns the first {@link File} found at
405+
* {@link TermuxConstants#TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH} or
406+
* {@link TermuxConstants#TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH}
407+
* from which termux properties can be loaded.
408+
* If the {@link File} found is not a regular file or is not readable then null is returned.
409+
*
410+
* @return Returns the {@link File} object for termux properties.
411+
*/
412+
public static File getTermuxFloatPropertiesFile() {
413+
return getPropertiesFile(new String[]{
414+
TermuxConstants.TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH,
415+
TermuxConstants.TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH
416+
});
417+
}
397418

419+
public static File getPropertiesFile(@NonNull String[] possiblePropertiesFileLocations) {
398420
File propertiesFile = new File(possiblePropertiesFileLocations[0]);
399421
int i = 0;
400422
while (!propertiesFile.exists() && i < possiblePropertiesFileLocations.length) {
@@ -405,7 +427,7 @@ public static File getTermuxPropertiesFile() {
405427
if (propertiesFile.isFile() && propertiesFile.canRead()) {
406428
return propertiesFile;
407429
} else {
408-
Logger.logDebug("No readable termux.properties file found");
430+
Logger.logDebug("No readable properties file found at: " + Arrays.toString(possiblePropertiesFileLocations));
409431
return null;
410432
}
411433
}

termux-shared/src/main/java/com/termux/shared/settings/properties/TermuxSharedProperties.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,34 @@
33
import android.content.Context;
44
import android.content.res.Configuration;
55

6+
import androidx.annotation.NonNull;
7+
68
import com.termux.shared.logger.Logger;
79
import com.termux.shared.data.DataUtils;
810

911
import java.io.File;
1012
import java.util.HashMap;
1113
import java.util.Map;
1214
import java.util.Properties;
15+
import java.util.Set;
1316

1417
import javax.annotation.Nonnull;
1518

16-
public class TermuxSharedProperties {
19+
public abstract class TermuxSharedProperties {
1720

1821
protected final Context mContext;
19-
protected final SharedProperties mSharedProperties;
22+
protected final String mLabel;
2023
protected final File mPropertiesFile;
24+
protected final SharedProperties mSharedProperties;
2125

2226
public static final String LOG_TAG = "TermuxSharedProperties";
2327

24-
public TermuxSharedProperties(@Nonnull Context context) {
28+
public TermuxSharedProperties(@Nonnull Context context, @NonNull String label, File propertiesFile,
29+
@NonNull Set<String> propertiesList, @NonNull SharedPropertiesParser sharedPropertiesParser) {
2530
mContext = context;
26-
mPropertiesFile = TermuxPropertyConstants.getTermuxPropertiesFile();
27-
mSharedProperties = new SharedProperties(context, mPropertiesFile, TermuxPropertyConstants.TERMUX_PROPERTIES_LIST, new SharedPropertiesParserClient());
31+
mLabel = label;
32+
mPropertiesFile = propertiesFile;
33+
mSharedProperties = new SharedProperties(context, mPropertiesFile, propertiesList, sharedPropertiesParser);
2834
loadTermuxPropertiesFromDisk();
2935
}
3036

@@ -162,16 +168,17 @@ public Object getInternalPropertyValue(String key, boolean cached) {
162168

163169
/**
164170
* Get the internal {@link Object} value for the key passed from the file returned by
165-
* {@link TermuxPropertyConstants#getTermuxPropertiesFile()}. The {@link Properties} object is
171+
* {@code propertiesFile}. The {@link Properties} object is
166172
* read directly from the file and internal value is returned for the property value against the key.
167173
*
168174
* @param context The context for operations.
169175
* @param key The key for which the internal object is required.
170176
* @return Returns the {@link Object} object. This will be {@code null} if key is not found or
171177
* the object stored against the key is {@code null}.
172178
*/
173-
public static Object getInternalPropertyValue(Context context, String key) {
174-
return SharedProperties.getInternalProperty(context, TermuxPropertyConstants.getTermuxPropertiesFile(), key, new SharedPropertiesParserClient());
179+
public static Object getInternalPropertyValue(Context context, File propertiesFile, String key,
180+
@NonNull SharedPropertiesParser sharedPropertiesParser) {
181+
return SharedProperties.getInternalProperty(context, propertiesFile, key, sharedPropertiesParser);
175182
}
176183

177184
/**
@@ -588,7 +595,7 @@ public void dumpPropertiesToLog() {
588595
Properties properties = getProperties(true);
589596
StringBuilder propertiesDump = new StringBuilder();
590597

591-
propertiesDump.append("Termux Properties:");
598+
propertiesDump.append(mLabel).append(" Termux Properties:");
592599
if (properties != null) {
593600
for (String key : properties.stringPropertyNames()) {
594601
propertiesDump.append("\n").append(key).append(": `").append(properties.get(key)).append("`");
@@ -604,7 +611,7 @@ public void dumpInternalPropertiesToLog() {
604611
HashMap<String, Object> internalProperties = (HashMap<String, Object>) getInternalProperties();
605612
StringBuilder internalPropertiesDump = new StringBuilder();
606613

607-
internalPropertiesDump.append("Termux Internal Properties:");
614+
internalPropertiesDump.append(mLabel).append(" Internal Properties:");
608615
if (internalProperties != null) {
609616
for (String key : internalProperties.keySet()) {
610617
internalPropertiesDump.append("\n").append(key).append(": `").append(internalProperties.get(key)).append("`");

app/src/main/java/com/termux/app/terminal/io/BellHandler.java renamed to termux-shared/src/main/java/com/termux/shared/terminal/io/BellHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.termux.app.terminal.io;
1+
package com.termux.shared.terminal.io;
22

33
import android.content.Context;
44
import android.os.Build;

termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.List;
1313

1414
/*
15-
* Version: v0.27.0
15+
* Version: v0.28.0
1616
*
1717
* Changelog
1818
*
@@ -187,6 +187,9 @@
187187
* `TERMUX_FLOAT_APP.TERMUX_FLOAT_SERVICE_NAME`.
188188
* - Added following to `TERMUX_FLOAT_APP.TERMUX_FLOAT_SERVICE`:
189189
* `ACTION_STOP_SERVICE`, `ACTION_SHOW`, `ACTION_HIDE`.
190+
*
191+
* - 0.28.0 (2021-09-02)
192+
* - Added `TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE*` and `TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE*`.
190193
*/
191194

192195
/**
@@ -640,6 +643,17 @@ public final class TermuxConstants {
640643
public static final File TERMUX_PROPERTIES_SECONDARY_FILE = new File(TERMUX_PROPERTIES_SECONDARY_FILE_PATH);
641644

642645

646+
/** Termux Float app termux.properties primary file path */
647+
public static final String TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH = TERMUX_DATA_HOME_DIR_PATH + "/termux.float.properties"; // Default: "/data/data/com.termux/files/home/.termux/termux.float.properties"
648+
/** Termux Float app termux.properties primary file */
649+
public static final File TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE = new File(TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH);
650+
651+
/** Termux Float app termux.properties secondary file path */
652+
public static final String TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH = TERMUX_CONFIG_HOME_DIR_PATH + "/termux.float.properties"; // Default: "/data/data/com.termux/files/home/.config/termux/termux.float.properties"
653+
/** Termux Float app termux.properties secondary file */
654+
public static final File TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE = new File(TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH);
655+
656+
643657
/** Termux app and Termux:Styling colors.properties file path */
644658
public static final String TERMUX_COLOR_PROPERTIES_FILE_PATH = TERMUX_DATA_HOME_DIR_PATH + "/colors.properties"; // Default: "/data/data/com.termux/files/home/.termux/colors.properties"
645659
/** Termux app and Termux:Styling colors.properties file */

0 commit comments

Comments
 (0)