6
6
7
7
import androidx .annotation .NonNull ;
8
8
9
+ import com .termux .shared .data .DataUtils ;
9
10
import com .termux .shared .logger .Logger ;
10
11
import com .termux .shared .packages .PackageUtils ;
11
12
import com .termux .shared .settings .preferences .TermuxPreferenceConstants .TERMUX_FLOAT_APP ;
@@ -18,13 +19,20 @@ public class TermuxFloatAppSharedPreferences {
18
19
19
20
private final Context mContext ;
20
21
private final SharedPreferences mSharedPreferences ;
22
+ private final SharedPreferences mMultiProcessSharedPreferences ;
21
23
24
+ private int MIN_FONTSIZE ;
25
+ private int MAX_FONTSIZE ;
26
+ private int DEFAULT_FONTSIZE ;
22
27
23
28
private static final String LOG_TAG = "TermuxFloatAppSharedPreferences" ;
24
29
25
30
private TermuxFloatAppSharedPreferences (@ Nonnull Context context ) {
26
31
mContext = context ;
27
32
mSharedPreferences = getPrivateSharedPreferences (mContext );
33
+ mMultiProcessSharedPreferences = getPrivateAndMultiProcessSharedPreferences (mContext );
34
+
35
+ setFontVariables (context );
28
36
}
29
37
30
38
/**
@@ -36,11 +44,11 @@ private TermuxFloatAppSharedPreferences(@Nonnull Context context) {
36
44
*/
37
45
@ Nullable
38
46
public static TermuxFloatAppSharedPreferences build (@ NonNull final Context context ) {
39
- Context termuxTaskerPackageContext = PackageUtils .getContextForPackage (context , TermuxConstants .TERMUX_FLOAT_PACKAGE_NAME );
40
- if (termuxTaskerPackageContext == null )
47
+ Context termuxFloatPackageContext = PackageUtils .getContextForPackage (context , TermuxConstants .TERMUX_FLOAT_PACKAGE_NAME );
48
+ if (termuxFloatPackageContext == null )
41
49
return null ;
42
50
else
43
- return new TermuxFloatAppSharedPreferences (termuxTaskerPackageContext );
51
+ return new TermuxFloatAppSharedPreferences (termuxFloatPackageContext );
44
52
}
45
53
46
54
/**
@@ -53,27 +61,114 @@ public static TermuxFloatAppSharedPreferences build(@NonNull final Context conte
53
61
* @return Returns the {@link TermuxFloatAppSharedPreferences}. This will {@code null} if an exception is raised.
54
62
*/
55
63
public static TermuxFloatAppSharedPreferences build (@ NonNull final Context context , final boolean exitAppOnError ) {
56
- Context termuxTaskerPackageContext = PackageUtils .getContextForPackageOrExitApp (context , TermuxConstants .TERMUX_FLOAT_PACKAGE_NAME , exitAppOnError );
57
- if (termuxTaskerPackageContext == null )
64
+ Context termuxFloatPackageContext = PackageUtils .getContextForPackageOrExitApp (context , TermuxConstants .TERMUX_FLOAT_PACKAGE_NAME , exitAppOnError );
65
+ if (termuxFloatPackageContext == null )
58
66
return null ;
59
67
else
60
- return new TermuxFloatAppSharedPreferences (termuxTaskerPackageContext );
68
+ return new TermuxFloatAppSharedPreferences (termuxFloatPackageContext );
61
69
}
62
70
63
71
private static SharedPreferences getPrivateSharedPreferences (Context context ) {
64
72
if (context == null ) return null ;
65
73
return SharedPreferenceUtils .getPrivateSharedPreferences (context , TermuxConstants .TERMUX_FLOAT_DEFAULT_PREFERENCES_FILE_BASENAME_WITHOUT_EXTENSION );
66
74
}
67
75
76
+ private static SharedPreferences getPrivateAndMultiProcessSharedPreferences (Context context ) {
77
+ if (context == null ) return null ;
78
+ return SharedPreferenceUtils .getPrivateAndMultiProcessSharedPreferences (context , TermuxConstants .TERMUX_FLOAT_DEFAULT_PREFERENCES_FILE_BASENAME_WITHOUT_EXTENSION );
79
+ }
80
+
81
+
82
+
83
+ public int getWindowX () {
84
+ return SharedPreferenceUtils .getInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_WINDOW_X , 200 );
85
+
86
+ }
87
+
88
+ public void setWindowX (int value ) {
89
+ SharedPreferenceUtils .setInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_WINDOW_X , value , false );
90
+ }
91
+
92
+ public int getWindowY () {
93
+ return SharedPreferenceUtils .getInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_WINDOW_Y , 200 );
94
+
95
+ }
96
+
97
+ public void setWindowY (int value ) {
98
+ SharedPreferenceUtils .setInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_WINDOW_Y , value , false );
99
+ }
100
+
101
+
102
+
103
+ public int getWindowWidth () {
104
+ return SharedPreferenceUtils .getInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_WINDOW_WIDTH , 500 );
105
+
106
+ }
107
+
108
+ public void setWindowWidth (int value ) {
109
+ SharedPreferenceUtils .setInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_WINDOW_WIDTH , value , false );
110
+ }
111
+
112
+ public int getWindowHeight () {
113
+ return SharedPreferenceUtils .getInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_WINDOW_HEIGHT , 500 );
68
114
115
+ }
69
116
70
- public int getLogLevel ( ) {
71
- return SharedPreferenceUtils .getInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_LOG_LEVEL , Logger . DEFAULT_LOG_LEVEL );
117
+ public void setWindowHeight ( int value ) {
118
+ SharedPreferenceUtils .setInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_WINDOW_HEIGHT , value , false );
72
119
}
73
120
74
- public void setLogLevel (Context context , int logLevel ) {
121
+
122
+
123
+ public void setFontVariables (Context context ) {
124
+ int [] sizes = TermuxAppSharedPreferences .getDefaultFontSizes (context );
125
+
126
+ DEFAULT_FONTSIZE = sizes [0 ];
127
+ MIN_FONTSIZE = sizes [1 ];
128
+ MAX_FONTSIZE = sizes [2 ];
129
+ }
130
+
131
+ public int getFontSize () {
132
+ int fontSize = SharedPreferenceUtils .getIntStoredAsString (mSharedPreferences , TERMUX_FLOAT_APP .KEY_FONTSIZE , DEFAULT_FONTSIZE );
133
+ return DataUtils .clamp (fontSize , MIN_FONTSIZE , MAX_FONTSIZE );
134
+ }
135
+
136
+ public void setFontSize (int value ) {
137
+ SharedPreferenceUtils .setIntStoredAsString (mSharedPreferences , TERMUX_FLOAT_APP .KEY_FONTSIZE , value , false );
138
+ }
139
+
140
+ public void changeFontSize (boolean increase ) {
141
+ int fontSize = getFontSize ();
142
+
143
+ fontSize += (increase ? 1 : -1 ) * 2 ;
144
+ fontSize = Math .max (MIN_FONTSIZE , Math .min (fontSize , MAX_FONTSIZE ));
145
+
146
+ setFontSize (fontSize );
147
+ }
148
+
149
+
150
+ public int getLogLevel (boolean readFromFile ) {
151
+ if (readFromFile )
152
+ return SharedPreferenceUtils .getInt (mMultiProcessSharedPreferences , TERMUX_FLOAT_APP .KEY_LOG_LEVEL , Logger .DEFAULT_LOG_LEVEL );
153
+ else
154
+ return SharedPreferenceUtils .getInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_LOG_LEVEL , Logger .DEFAULT_LOG_LEVEL );
155
+ }
156
+
157
+ public void setLogLevel (Context context , int logLevel , boolean commitToFile ) {
75
158
logLevel = Logger .setLogLevel (context , logLevel );
76
- SharedPreferenceUtils .setInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_LOG_LEVEL , logLevel , false );
159
+ SharedPreferenceUtils .setInt (mSharedPreferences , TERMUX_FLOAT_APP .KEY_LOG_LEVEL , logLevel , commitToFile );
160
+ }
161
+
162
+
163
+ public boolean isTerminalViewKeyLoggingEnabled (boolean readFromFile ) {
164
+ if (readFromFile )
165
+ return SharedPreferenceUtils .getBoolean (mMultiProcessSharedPreferences , TERMUX_FLOAT_APP .KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED , TERMUX_FLOAT_APP .DEFAULT_VALUE_TERMINAL_VIEW_KEY_LOGGING_ENABLED );
166
+ else
167
+ return SharedPreferenceUtils .getBoolean (mSharedPreferences , TERMUX_FLOAT_APP .KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED , TERMUX_FLOAT_APP .DEFAULT_VALUE_TERMINAL_VIEW_KEY_LOGGING_ENABLED );
168
+ }
169
+
170
+ public void setTerminalViewKeyLoggingEnabled (boolean value , boolean commitToFile ) {
171
+ SharedPreferenceUtils .setBoolean (mSharedPreferences , TERMUX_FLOAT_APP .KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED , value , commitToFile );
77
172
}
78
173
79
174
}
0 commit comments