11package Ninja .coder .Ghostemane .code .terminal ;
22
3+ import Ninja .coder .Ghostemane .code .ApplicationLoader ;
34import Ninja .coder .Ghostemane .code .R ;
45import Ninja .coder .Ghostemane .code .activities .BaseCompat ;
56import Ninja .coder .Ghostemane .code .terminal .key .VirtualKeysView ;
89import Ninja .coder .Ghostemane .code .terminal .key .VirtualKeysConstants ;
910import Ninja .coder .Ghostemane .code .terminal .key .SpecialButton ;
1011import Ninja .coder .Ghostemane .code .config .CommandCompat ;
11- import Ninja .coder .Ghostemane .code .utils .AssetsSoft ;
12- import Ninja .coder .Ghostemane .code .utils .FileUtil ;
1312import android .app .Activity ;
1413import android .content .SharedPreferences ;
1514import android .graphics .Color ;
1615import android .os .Build ;
16+ import android .util .TypedValue ;
1717import android .view .KeyEvent ;
1818import android .view .MotionEvent ;
1919import android .view .View ;
3030import com .termux .terminal .TerminalSessionClient ;
3131import java .io .File ;
3232import java .io .FileInputStream ;
33- import java .io .IOException ;
3433import java .util .HashMap ;
3534import com .termux .view .TerminalView ;
3635import 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