Skip to content

Commit a025449

Browse files
author
appt2
committed
add zoom from terminal for test
1 parent e99e84b commit a025449

File tree

17 files changed

+4989
-3630
lines changed

17 files changed

+4989
-3630
lines changed

app/src/main/java/Ninja/coder/Ghostemane/code/ApplicationLoader.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
import android.util.Log;
1717
import android.widget.Toast;
1818
import androidx.appcompat.app.AppCompatDelegate;
19+
import androidx.preference.PreferenceManager;
1920
import com.google.android.material.color.DynamicColors;
2021
import de.larsgrefer.sass.embedded.SassCompiler;
2122
import de.larsgrefer.sass.embedded.android.AndroidSassCompilerFactory;
2223

2324
import java.util.Calendar;
2425

2526
public class ApplicationLoader extends Application {
26-
protected static SharedPreferences materialYou, getvb, setfont, ru, save_path,thememanagersoft;
27+
// from terminal
28+
29+
private static SharedPreferences prfns;
30+
protected static SharedPreferences materialYou, getvb, setfont, ru, save_path, thememanagersoft;
2731
private static Context mApplicationContext;
2832
private static Activity activity;
2933
private static IdeEditor editor;
@@ -59,8 +63,8 @@ public static SharedPreferences getRu() {
5963
public static SharedPreferences getPath() {
6064
return save_path;
6165
}
62-
63-
public static SharedPreferences getThememanagersoft(){
66+
67+
public static SharedPreferences getThememanagersoft() {
6468
return thememanagersoft;
6569
}
6670

@@ -75,7 +79,8 @@ public void onCreate() {
7579
setfont = getSharedPreferences("setfont", MODE_PRIVATE);
7680
save_path = getSharedPreferences("path", MODE_PRIVATE);
7781
ru = getSharedPreferences("ru", MODE_PRIVATE);
78-
thememanagersoft = getSharedPreferences("thememanagersoft",MODE_PRIVATE);
82+
thememanagersoft = getSharedPreferences("thememanagersoft", MODE_PRIVATE);
83+
prfns = PreferenceManager.getDefaultSharedPreferences(this);
7984
try (SassCompiler compiler = AndroidSassCompilerFactory.bundled(this)) {
8085
Toast.makeText(getApplicationContext(), compiler.getVersion().toString(), Toast.LENGTH_SHORT)
8186
.show();
@@ -156,4 +161,8 @@ public String getVersion() {
156161
return null;
157162
}
158163
}
164+
165+
public static SharedPreferences getPrefManager() {
166+
return prfns;
167+
}
159168
}

app/src/main/java/Ninja/coder/Ghostemane/code/terminal/TerminalActivity.java

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package Ninja.coder.Ghostemane.code.terminal;
22

3+
import Ninja.coder.Ghostemane.code.ApplicationLoader;
34
import Ninja.coder.Ghostemane.code.R;
45
import Ninja.coder.Ghostemane.code.activities.BaseCompat;
56
import Ninja.coder.Ghostemane.code.terminal.key.VirtualKeysView;
@@ -8,12 +9,11 @@
89
import Ninja.coder.Ghostemane.code.terminal.key.VirtualKeysConstants;
910
import Ninja.coder.Ghostemane.code.terminal.key.SpecialButton;
1011
import Ninja.coder.Ghostemane.code.config.CommandCompat;
11-
import Ninja.coder.Ghostemane.code.utils.AssetsSoft;
12-
import Ninja.coder.Ghostemane.code.utils.FileUtil;
1312
import android.app.Activity;
1413
import android.content.SharedPreferences;
1514
import android.graphics.Color;
1615
import android.os.Build;
16+
import android.util.TypedValue;
1717
import android.view.KeyEvent;
1818
import android.view.MotionEvent;
1919
import android.view.View;
@@ -30,7 +30,6 @@
3030
import com.termux.terminal.TerminalSessionClient;
3131
import java.io.File;
3232
import java.io.FileInputStream;
33-
import java.io.IOException;
3433
import java.util.HashMap;
3534
import com.termux.view.TerminalView;
3635
import android.os.Bundle;
@@ -47,7 +46,11 @@ public class TerminalActivity extends BaseCompat implements TerminalViewClient {
4746
private TerminalView terminals;
4847
protected VirtualKeysView keys;
4948
protected KeyListener listener;
49+
private static final String KEY_FONT_SIZE = "terminal_fontSize";
5050
protected TermuxActivityRootView layoutRoot;
51+
private int MIN_FONT_SIZE;
52+
private int MAX_FONT_SIZE;
53+
private int DEFAULT_FONT_SIZE;
5154

5255
@Override
5356
protected void onCreate(Bundle _savedInstanceState) {
@@ -64,7 +67,6 @@ private KeyListener getKeyListener() {
6467

6568
private void initialize(Bundle _savedInstanceState) {
6669
terminals = findViewById(R.id.term);
67-
getvb = getSharedPreferences("getvb", Activity.MODE_PRIVATE);
6870
keys = findViewById(R.id.keysterm);
6971
layoutRoot = findViewById(R.id.rootPos);
7072
layoutRoot.setActivity(this);
@@ -80,7 +82,7 @@ public View getTermuxActivityBottomSpaceView() {
8082
return keys;
8183
}
8284

83-
private void initializeLogic() {
85+
private void initializeLogic() {
8486

8587
String shell = "/bin/sh";
8688
if (!new File("/bin/sh").exists()) {
@@ -194,17 +196,17 @@ public void onCopyTextToClipboard(TerminalSession session, String text) {
194196
CommandCompat.INSTANCE.getInterpreterCommand(
195197
getApplicationContext(), getIntent().getStringExtra("path"));
196198
terminals.mTermSession.write(pys + '\r');
197-
199+
198200
} else if (getIntent().hasExtra("phpcode")) {
199201
String php =
200202
CommandCompat.INSTANCE.getRunPhpCommand(
201203
getApplicationContext(), new File(getIntent().getStringExtra("phpcode")));
202204
terminals.mTermSession.write(php + '\r');
203205
} else {
204-
var mypath = getFilesDir().getAbsolutePath() + "/" + "databins";
205-
var code = CommandCompat.INSTANCE.getInterpreterCommand(
206-
getApplicationContext(),mypath);
207-
terminals.mTermSession.write(code + '\r');
206+
var mypath = getFilesDir().getAbsolutePath() + "/" + "databins";
207+
var code =
208+
CommandCompat.INSTANCE.getInterpreterCommand(getApplicationContext(), mypath);
209+
terminals.mTermSession.write(code + '\r');
208210
}
209211
});
210212
try {
@@ -236,8 +238,79 @@ public void onCopyTextToClipboard(TerminalSession session, String text) {
236238

237239
@Override
238240
public float onScale(float scale) {
241+
///not work error
242+
// if (scale < 0.9f || scale > 1.1f) {
243+
// boolean increase = scale > 1.f;
244+
// //changeFontSize(increase);
245+
// return 1.0f;
246+
// }
247+
return 2f;
248+
}
249+
250+
private void changeFontSize(final boolean increase) {
251+
int fontSize = getFontSize();
252+
fontSize += (increase ? 1 : -1) * 2;
253+
fontSize = Math.max(MIN_FONT_SIZE, Math.min(fontSize, MAX_FONT_SIZE));
254+
setFontSize(fontSize, true);
255+
}
256+
257+
public void setFontSize(int value, boolean apply) {
258+
ApplicationLoader.getPrefManager().getString(KEY_FONT_SIZE,String.valueOf(value));
259+
if (apply) {
260+
terminals.setTextSize(getFontSize());
261+
}
262+
}
263+
264+
public int getFontSize() {
265+
int fontSize;
266+
267+
try {
268+
fontSize = Integer.parseInt(ApplicationLoader.getPrefManager().getString(KEY_FONT_SIZE,String.valueOf(DEFAULT_FONT_SIZE)));
269+
} catch(NumberFormatException err) {
270+
fontSize = DEFAULT_FONT_SIZE;
271+
}
272+
273+
274+
return Math.min(Math.max(fontSize, MIN_FONT_SIZE), MAX_FONT_SIZE);
275+
}
276+
277+
public void setFontVariables() {
278+
int[] sizes = getDefaultFontSizes();
279+
280+
DEFAULT_FONT_SIZE = sizes[0];
281+
MIN_FONT_SIZE = sizes[1];
282+
MAX_FONT_SIZE = sizes[2];
283+
}
284+
285+
// https://github.com/termux/termux-app/blob/82b15803126138eef8899e0c7b582713f872cd09/termux-shared/src/main/java/com/termux/shared/termux/settings/preferences/TermuxAppSharedPreferences.java
286+
private int[] getDefaultFontSizes() {
287+
float dipInPixels =
288+
TypedValue.applyDimension(
289+
TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics());
290+
291+
int[] sizes = new int[3];
292+
293+
// This is a bit arbitrary and sub-optimal. We want to give a sensible default for minimum font
294+
// size
295+
// to prevent invisible text due to zoom be mistake:
296+
sizes[1] = (int) (4f * dipInPixels); // min
297+
298+
// http://www.google.com/design/spec/style/typography.html#typography-line-height
299+
int defaultFontSize = Math.round(9 * dipInPixels);
300+
// Make it divisible by 2 since that is the minimal adjustment step:
301+
if (defaultFontSize % 2 == 1) defaultFontSize--;
302+
303+
sizes[0] = defaultFontSize; // default
304+
305+
sizes[2] = 256; // max
306+
307+
setFontSize(16, false);
308+
309+
if (ApplicationLoader.getPrefManager().getString(KEY_FONT_SIZE, "<not_available>").equals("<not_available>")) {
310+
setFontSize(defaultFontSize, false);
311+
}
239312

240-
return 18;
313+
return sizes;
241314
}
242315

243316
@Override

0 commit comments

Comments
 (0)