-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathUIManager.java
More file actions
executable file
·1803 lines (1428 loc) · 81 KB
/
Copy pathUIManager.java
File metadata and controls
executable file
·1803 lines (1428 loc) · 81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package ohi.andre.consolelauncher;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.GestureDetectorCompat;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.DisplayMetrics;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import ohi.andre.consolelauncher.commands.main.MainPack;
import ohi.andre.consolelauncher.commands.main.specific.RedirectCommand;
import ohi.andre.consolelauncher.managers.HTMLExtractManager;
import ohi.andre.consolelauncher.managers.NotesManager;
import ohi.andre.consolelauncher.managers.TerminalManager;
import ohi.andre.consolelauncher.managers.TimeManager;
import ohi.andre.consolelauncher.managers.TuiLocationManager;
import ohi.andre.consolelauncher.managers.suggestions.SuggestionTextWatcher;
import ohi.andre.consolelauncher.managers.suggestions.SuggestionsManager;
import ohi.andre.consolelauncher.managers.xml.XMLPrefsManager;
import ohi.andre.consolelauncher.managers.xml.options.Behavior;
import ohi.andre.consolelauncher.managers.xml.options.Suggestions;
import ohi.andre.consolelauncher.managers.xml.options.Theme;
import ohi.andre.consolelauncher.managers.xml.options.Toolbar;
import ohi.andre.consolelauncher.managers.xml.options.Ui;
import ohi.andre.consolelauncher.tuils.AllowEqualsSequence;
import ohi.andre.consolelauncher.tuils.NetworkUtils;
import ohi.andre.consolelauncher.tuils.OutlineEditText;
import ohi.andre.consolelauncher.tuils.OutlineTextView;
import ohi.andre.consolelauncher.tuils.Tuils;
import ohi.andre.consolelauncher.tuils.interfaces.CommandExecuter;
import ohi.andre.consolelauncher.tuils.interfaces.OnBatteryUpdate;
import ohi.andre.consolelauncher.tuils.interfaces.OnRedirectionListener;
import ohi.andre.consolelauncher.tuils.interfaces.OnTextChanged;
import ohi.andre.consolelauncher.tuils.stuff.PolicyReceiver;
public class UIManager implements OnTouchListener {
public static String ACTION_UPDATE_SUGGESTIONS = BuildConfig.APPLICATION_ID + ".ui_update_suggestions";
public static String ACTION_UPDATE_HINT = BuildConfig.APPLICATION_ID + ".ui_update_hint";
public static String ACTION_ROOT = BuildConfig.APPLICATION_ID + ".ui_root";
public static String ACTION_NOROOT = BuildConfig.APPLICATION_ID + ".ui_noroot";
public static String ACTION_LOGTOFILE = BuildConfig.APPLICATION_ID + ".ui_log";
public static String ACTION_CLEAR = BuildConfig.APPLICATION_ID + "ui_clear";
public static String ACTION_WEATHER = BuildConfig.APPLICATION_ID + "ui_weather";
public static String ACTION_WEATHER_GOT_LOCATION = BuildConfig.APPLICATION_ID + "ui_weather_location";
public static String ACTION_WEATHER_DELAY = BuildConfig.APPLICATION_ID + "ui_weather_delay";
public static String ACTION_WEATHER_MANUAL_UPDATE = BuildConfig.APPLICATION_ID + "ui_weather_update";
public static String FILE_NAME = "fileName";
public static String PREFS_NAME = "ui";
private enum Label {
ram,
device,
time,
battery,
storage,
network,
notes,
weather,
unlock
}
private final int RAM_DELAY = 3000;
private final int TIME_DELAY = 1000;
private final int STORAGE_DELAY = 60 * 1000;
protected Context mContext;
private Handler handler;
private DevicePolicyManager policy;
private ComponentName component;
private GestureDetectorCompat gestureDetector;
SharedPreferences preferences;
private InputMethodManager imm;
private TerminalManager mTerminalAdapter;
int mediumPercentage, lowPercentage;
String batteryFormat;
boolean hideToolbarNoInput;
View toolbarView;
// never access this directly, use getLabelView
private TextView[] labelViews = new TextView[Label.values().length];
private float[] labelIndexes = new float[labelViews.length];
private int[] labelSizes = new int[labelViews.length];
private CharSequence[] labelTexts = new CharSequence[labelViews.length];
private TextView getLabelView(Label l) {
return labelViews[(int) labelIndexes[l.ordinal()]];
}
private int notesMaxLines;
private NotesManager notesManager;
private NotesRunnable notesRunnable;
private class NotesRunnable implements Runnable {
int updateTime = 2000;
@Override
public void run() {
if(notesManager != null) {
if(notesManager.hasChanged) {
UIManager.this.updateText(Label.notes, Tuils.span(mContext, labelSizes[Label.notes.ordinal()], notesManager.getNotes()));
}
handler.postDelayed(this, updateTime);
}
}
};
private BatteryUpdate batteryUpdate;
private class BatteryUpdate implements OnBatteryUpdate {
// %(charging:not charging)
// final Pattern optionalCharging = Pattern.compile("%\\(([^\\/]*)\\/([^)]*)\\)", Pattern.CASE_INSENSITIVE);
Pattern optionalCharging;
final Pattern value = Pattern.compile("%v", Pattern.LITERAL | Pattern.CASE_INSENSITIVE);
boolean manyStatus, loaded;
int colorHigh, colorMedium, colorLow;
boolean charging;
float last = -1;
@Override
public void update(float p) {
if(batteryFormat == null) {
batteryFormat = XMLPrefsManager.get(Behavior.battery_format);
Intent intent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if(intent == null) charging = false;
else {
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
charging = plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
}
String optionalSeparator = "\\" + XMLPrefsManager.get(Behavior.optional_values_separator);
String optional = "%\\(([^" + optionalSeparator + "]*)" + optionalSeparator + "([^)]*)\\)";
optionalCharging = Pattern.compile(optional, Pattern.CASE_INSENSITIVE);
}
if(p == -1) p = last;
last = p;
if(!loaded) {
loaded = true;
manyStatus = XMLPrefsManager.getBoolean(Ui.enable_battery_status);
colorHigh = XMLPrefsManager.getColor(Theme.battery_color_high);
colorMedium = XMLPrefsManager.getColor(Theme.battery_color_medium);
colorLow = XMLPrefsManager.getColor(Theme.battery_color_low);
}
int percentage = (int) p;
int color;
if(manyStatus) {
if(percentage > mediumPercentage) color = colorHigh;
else if(percentage > lowPercentage) color = colorMedium;
else color = colorLow;
} else {
color = colorHigh;
}
String cp = batteryFormat;
Matcher m = optionalCharging.matcher(cp);
while (m.find()) {
cp = cp.replace(m.group(0), m.groupCount() == 2 ? m.group(charging ? 1 : 2) : Tuils.EMPTYSTRING);
}
cp = value.matcher(cp).replaceAll(String.valueOf(percentage));
cp = Tuils.patternNewline.matcher(cp).replaceAll(Tuils.NEWLINE);
UIManager.this.updateText(Label.battery, Tuils.span(mContext, cp, color, labelSizes[Label.battery.ordinal()]));
}
@Override
public void onCharging() {
charging = true;
update(-1);
}
@Override
public void onNotCharging() {
charging = false;
update(-1);
}
};
private StorageRunnable storageRunnable;
private class StorageRunnable implements Runnable {
private final String INT_AV = "%iav";
private final String INT_TOT = "%itot";
private final String EXT_AV = "%eav";
private final String EXT_TOT = "%etot";
private List<Pattern> storagePatterns;
private String storageFormat;
int color;
@Override
public void run() {
if(storageFormat == null) {
storageFormat = XMLPrefsManager.get(Behavior.storage_format);
color = XMLPrefsManager.getColor(Theme.storage_color);
}
if(storagePatterns == null) {
storagePatterns = new ArrayList<>();
storagePatterns.add(Pattern.compile(INT_AV + "tb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_AV + "gb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_AV + "mb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_AV + "kb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_AV + "b", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_AV + "%", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_TOT + "tb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_TOT + "gb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_TOT + "mb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_TOT + "kb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_TOT + "b", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_AV + "tb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_AV + "gb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_AV + "mb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_AV + "kb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_AV + "b", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_AV + "%", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_TOT + "tb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_TOT + "gb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_TOT + "mb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_TOT + "kb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_TOT + "b", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Tuils.patternNewline);
storagePatterns.add(Pattern.compile(INT_AV, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(INT_TOT, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_AV, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
storagePatterns.add(Pattern.compile(EXT_TOT, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
}
double iav = Tuils.getAvailableInternalMemorySize(Tuils.BYTE);
double itot = Tuils.getTotalInternalMemorySize(Tuils.BYTE);
double eav = Tuils.getAvailableExternalMemorySize(Tuils.BYTE);
double etot = Tuils.getTotalExternalMemorySize(Tuils.BYTE);
String copy = storageFormat;
copy = storagePatterns.get(0).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) iav, Tuils.TERA))));
copy = storagePatterns.get(1).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) iav, Tuils.GIGA))));
copy = storagePatterns.get(2).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) iav, Tuils.MEGA))));
copy = storagePatterns.get(3).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) iav, Tuils.KILO))));
copy = storagePatterns.get(4).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) iav, Tuils.BYTE))));
copy = storagePatterns.get(5).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.percentage(iav, itot))));
copy = storagePatterns.get(6).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) itot, Tuils.TERA))));
copy = storagePatterns.get(7).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) itot, Tuils.GIGA))));
copy = storagePatterns.get(8).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) itot, Tuils.MEGA))));
copy = storagePatterns.get(9).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) itot, Tuils.KILO))));
copy = storagePatterns.get(10).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) itot, Tuils.BYTE))));
copy = storagePatterns.get(11).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) eav, Tuils.TERA))));
copy = storagePatterns.get(12).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) eav, Tuils.GIGA))));
copy = storagePatterns.get(13).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) eav, Tuils.MEGA))));
copy = storagePatterns.get(14).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) eav, Tuils.KILO))));
copy = storagePatterns.get(15).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) eav, Tuils.BYTE))));
copy = storagePatterns.get(16).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.percentage(eav, etot))));
copy = storagePatterns.get(17).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) etot, Tuils.TERA))));
copy = storagePatterns.get(18).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) etot, Tuils.GIGA))));
copy = storagePatterns.get(19).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) etot, Tuils.MEGA))));
copy = storagePatterns.get(20).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) etot, Tuils.KILO))));
copy = storagePatterns.get(21).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) etot, Tuils.BYTE))));
copy = storagePatterns.get(22).matcher(copy).replaceAll(Matcher.quoteReplacement(Tuils.NEWLINE));
copy = storagePatterns.get(23).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) iav, Tuils.GIGA))));
copy = storagePatterns.get(24).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) itot, Tuils.GIGA))));
copy = storagePatterns.get(25).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) eav, Tuils.GIGA))));
copy = storagePatterns.get(26).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) etot, Tuils.GIGA))));
updateText(Label.storage, Tuils.span(mContext, copy, color, labelSizes[Label.storage.ordinal()]));
handler.postDelayed(this, STORAGE_DELAY);
}
};
private TimeRunnable timeRunnable;
private class TimeRunnable implements Runnable {
boolean active;
@Override
public void run() {
if(!active) {
active = true;
}
updateText(Label.time, TimeManager.instance.getCharSequence(mContext, labelSizes[Label.time.ordinal()], "%t0"));
handler.postDelayed(this, TIME_DELAY);
}
};
private ActivityManager.MemoryInfo memory;
private ActivityManager activityManager;
private RamRunnable ramRunnable;
private class RamRunnable implements Runnable {
private final String AV = "%av";
private final String TOT = "%tot";
List<Pattern> ramPatterns;
String ramFormat;
int color;
@Override
public void run() {
if(ramFormat == null) {
ramFormat = XMLPrefsManager.get(Behavior.ram_format);
color = XMLPrefsManager.getColor(Theme.ram_color);
}
if(ramPatterns == null) {
ramPatterns = new ArrayList<>();
ramPatterns.add(Pattern.compile(AV + "tb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(AV + "gb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(AV + "mb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(AV + "kb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(AV + "b", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(AV + "%", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(TOT + "tb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(TOT + "gb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(TOT + "mb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(TOT + "kb", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Pattern.compile(TOT + "b", Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
ramPatterns.add(Tuils.patternNewline);
}
String copy = ramFormat;
double av = Tuils.freeRam(activityManager, memory);
double tot = Tuils.totalRam() * 1024L;
copy = ramPatterns.get(0).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) av, Tuils.TERA))));
copy = ramPatterns.get(1).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) av, Tuils.GIGA))));
copy = ramPatterns.get(2).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) av, Tuils.MEGA))));
copy = ramPatterns.get(3).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) av, Tuils.KILO))));
copy = ramPatterns.get(4).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) av, Tuils.BYTE))));
copy = ramPatterns.get(5).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.percentage(av, tot))));
copy = ramPatterns.get(6).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) tot, Tuils.TERA))));
copy = ramPatterns.get(7).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) tot, Tuils.GIGA))));
copy = ramPatterns.get(8).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) tot, Tuils.MEGA))));
copy = ramPatterns.get(9).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) tot, Tuils.KILO))));
copy = ramPatterns.get(10).matcher(copy).replaceAll(Matcher.quoteReplacement(String.valueOf(Tuils.formatSize((long) tot, Tuils.BYTE))));
copy = ramPatterns.get(11).matcher(copy).replaceAll(Matcher.quoteReplacement(Tuils.NEWLINE));
updateText(Label.ram, Tuils.span(mContext, copy, color, labelSizes[Label.ram.ordinal()]));
handler.postDelayed(this, RAM_DELAY);
}
};
private NetworkRunnable networkRunnable;
private class NetworkRunnable implements Runnable {
// %() -> wifi
// %[] -> data
// %{} -> bluetooth
final String zero = "0";
final String one = "1";
final String on = "on";
final String off = "off";
final String ON = on.toUpperCase();
final String OFF = off.toUpperCase();
final String _true = "true";
final String _false = "false";
final String TRUE = _true.toUpperCase();
final String FALSE = _false.toUpperCase();
final Pattern w0 = Pattern.compile("%w0", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern w1 = Pattern.compile("%w1", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern w2 = Pattern.compile("%w2", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern w3 = Pattern.compile("%w3", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern w4 = Pattern.compile("%w4", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern wn = Pattern.compile("%wn", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern d0 = Pattern.compile("%d0", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern d1 = Pattern.compile("%d1", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern d2 = Pattern.compile("%d2", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern d3 = Pattern.compile("%d3", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern d4 = Pattern.compile("%d4", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern b0 = Pattern.compile("%b0", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern b1 = Pattern.compile("%b1", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern b2 = Pattern.compile("%b2", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern b3 = Pattern.compile("%b3", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern b4 = Pattern.compile("%b4", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern ip4 = Pattern.compile("%ip4", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern ip6 = Pattern.compile("%ip6", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
final Pattern dt = Pattern.compile("%dt", Pattern.CASE_INSENSITIVE | Pattern.LITERAL);
// final Pattern optionalWifi = Pattern.compile("%\\(([^/]*)/([^)]*)\\)", Pattern.CASE_INSENSITIVE);
// final Pattern optionalData = Pattern.compile("%\\[([^/]*)/([^\\]]*)\\]", Pattern.CASE_INSENSITIVE);
// final Pattern optionalBluetooth = Pattern.compile("%\\{([^/]*)/([^}]*)\\}", Pattern.CASE_INSENSITIVE);
Pattern optionalWifi, optionalData, optionalBluetooth;
String format, optionalValueSeparator;
int color;
WifiManager wifiManager;
BluetoothAdapter mBluetoothAdapter;
ConnectivityManager connectivityManager;
Class cmClass;
Method method;
int maxDepth;
int updateTime;
@Override
public void run() {
if (format == null) {
format = XMLPrefsManager.get(Behavior.network_info_format);
color = XMLPrefsManager.getColor(Theme.network_info_color);
maxDepth = XMLPrefsManager.getInt(Behavior.max_optional_depth);
updateTime = XMLPrefsManager.getInt(Behavior.network_info_update_ms);
if (updateTime < 1000)
updateTime = Integer.parseInt(Behavior.network_info_update_ms.defaultValue());
connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
wifiManager = (WifiManager) mContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
optionalValueSeparator = "\\" + XMLPrefsManager.get(Behavior.optional_values_separator);
String wifiRegex = "%\\(([^" + optionalValueSeparator + "]*)" + optionalValueSeparator + "([^)]*)\\)";
String dataRegex = "%\\[([^" + optionalValueSeparator + "]*)" + optionalValueSeparator + "([^\\]]*)\\]";
String bluetoothRegex = "%\\{([^" + optionalValueSeparator + "]*)" + optionalValueSeparator + "([^}]*)\\}";
optionalWifi = Pattern.compile(wifiRegex, Pattern.CASE_INSENSITIVE);
optionalBluetooth = Pattern.compile(bluetoothRegex, Pattern.CASE_INSENSITIVE);
optionalData = Pattern.compile(dataRegex, Pattern.CASE_INSENSITIVE);
try {
cmClass = Class.forName(connectivityManager.getClass().getName());
method = cmClass.getDeclaredMethod("getMobileDataEnabled");
method.setAccessible(true);
} catch (Exception e) {
cmClass = null;
method = null;
}
}
// wifi
boolean wifiOn = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
String wifiName = null;
if (wifiOn) {
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo != null) {
wifiName = connectionInfo.getSSID();
}
}
// mobile data
boolean mobileOn = false;
try {
mobileOn = method != null && connectivityManager != null && (Boolean) method.invoke(connectivityManager);
} catch (Exception e) {
}
String mobileType = null;
if (mobileOn) {
mobileType = Tuils.getNetworkType(mContext);
} else {
mobileType = "unknown";
}
// bluetooth
boolean bluetoothOn = mBluetoothAdapter != null && mBluetoothAdapter.isEnabled();
String copy = format;
if (maxDepth > 0) {
copy = apply(1, copy, new boolean[]{wifiOn, mobileOn, bluetoothOn}, optionalWifi, optionalData, optionalBluetooth);
copy = apply(1, copy, new boolean[]{mobileOn, wifiOn, bluetoothOn}, optionalData, optionalWifi, optionalBluetooth);
copy = apply(1, copy, new boolean[]{bluetoothOn, wifiOn, mobileOn}, optionalBluetooth, optionalWifi, optionalData);
}
copy = w0.matcher(copy).replaceAll(wifiOn ? one : zero);
copy = w1.matcher(copy).replaceAll(wifiOn ? on : off);
copy = w2.matcher(copy).replaceAll(wifiOn ? ON : OFF);
copy = w3.matcher(copy).replaceAll(wifiOn ? _true : _false);
copy = w4.matcher(copy).replaceAll(wifiOn ? TRUE : FALSE);
copy = wn.matcher(copy).replaceAll(wifiName != null ? wifiName.replaceAll("\"", Tuils.EMPTYSTRING) : "null");
copy = d0.matcher(copy).replaceAll(mobileOn ? one : zero);
copy = d1.matcher(copy).replaceAll(mobileOn ? on : off);
copy = d2.matcher(copy).replaceAll(mobileOn ? ON : OFF);
copy = d3.matcher(copy).replaceAll(mobileOn ? _true : _false);
copy = d4.matcher(copy).replaceAll(mobileOn ? TRUE : FALSE);
copy = b0.matcher(copy).replaceAll(bluetoothOn ? one : zero);
copy = b1.matcher(copy).replaceAll(bluetoothOn ? on : off);
copy = b2.matcher(copy).replaceAll(bluetoothOn ? ON : OFF);
copy = b3.matcher(copy).replaceAll(bluetoothOn ? _true : _false);
copy = b4.matcher(copy).replaceAll(bluetoothOn ? TRUE : FALSE);
copy = ip4.matcher(copy).replaceAll(NetworkUtils.getIPAddress(true));
copy = ip6.matcher(copy).replaceAll(NetworkUtils.getIPAddress(false));
copy = dt.matcher(copy).replaceAll(mobileType);
copy = Tuils.patternNewline.matcher(copy).replaceAll(Tuils.NEWLINE);
updateText(Label.network, Tuils.span(mContext, copy, color, labelSizes[Label.network.ordinal()]));
handler.postDelayed(this, updateTime);
}
private String apply(int depth, String s, boolean[] on, Pattern... ps) {
if(ps.length == 0) return s;
Matcher m = ps[0].matcher(s);
while (m.find()) {
if(m.groupCount() < 2) {
s = s.replace(m.group(0), Tuils.EMPTYSTRING);
continue;
}
String g1 = m.group(1);
String g2 = m.group(2);
if(depth < maxDepth) {
for(int c = 0; c < ps.length - 1; c++) {
boolean[] subOn = new boolean[on.length - 1];
subOn[0] = on[c+1];
Pattern[] subPs = new Pattern[ps.length - 1];
subPs[0] = ps[c+1];
for(int j = 1, k = 1; j < subOn.length; j++, k++) {
if(k == c+1) {
j--;
continue;
}
subOn[j] = on[k];
subPs[j] = ps[k];
}
g1 = apply(depth + 1, g1, subOn, subPs);
g2 = apply(depth + 1, g2, subOn, subPs);
}
}
s = s.replace(m.group(0), on[0] ? g1 : g2);
}
return s;
}
}
private int weatherDelay;
private double lastLatitude, lastLongitude;
private String location;
private boolean fixedLocation = false;
private boolean weatherPerformedStartupRun = false;
private WeatherRunnable weatherRunnable;
private int weatherColor;
boolean showWeatherUpdate;
private class WeatherRunnable implements Runnable {
String key;
String url;
public WeatherRunnable() {
if(XMLPrefsManager.wasChanged(Behavior.weather_key, false)) {
weatherDelay = XMLPrefsManager.getInt(Behavior.weather_update_time);
key = XMLPrefsManager.get(Behavior.weather_key);
} else {
key = Behavior.weather_key.defaultValue();
weatherDelay = 60 * 60;
}
weatherDelay *= 1000;
String where = XMLPrefsManager.get(Behavior.weather_location);
if(where == null || where.length() == 0 || (!Tuils.isNumber(where) && !where.contains(","))) {
// Tuils.location(mContext, new Tuils.ArgsRunnable() {
// @Override
// public void run() {
// setUrl(
// "lat=" + get(int.class, 0) + "&lon=" + get(int.class, 1),
// finalKey,
// XMLPrefsManager.get(Behavior.weather_temperature_measure));
// WeatherRunnable.this.run();
// }
// }, new Runnable() {
// @Override
// public void run() {
// updateText(Label.weather, Tuils.span(mContext, mContext.getString(R.string.location_error), XMLPrefsManager.getColor(Theme.weather_color), labelSizes[Label.weather.ordinal()]));
// }
// }, handler);
// Location l = Tuils.getLocation(mContext);
// if(l != null) {
// setUrl(
// "lat=" + l.getLatitude() + "&lon=" + l.getLongitude(),
// finalKey,
// XMLPrefsManager.get(Behavior.weather_temperature_measure));
// WeatherRunnable.this.run();
// } else {
// updateText(Label.weather, Tuils.span(mContext, mContext.getString(R.string.location_error), XMLPrefsManager.getColor(Theme.weather_color), labelSizes[Label.weather.ordinal()]));
// }
TuiLocationManager l = TuiLocationManager.instance(mContext);
l.add(ACTION_WEATHER_GOT_LOCATION);
} else {
fixedLocation = true;
if(where.contains(",")) {
String[] split = where.split(",");
where = "lat=" + split[0] + "&lon=" + split[1];
} else {
where = "id=" + where;
}
setUrl(where);
}
}
@Override
public void run() {
weatherPerformedStartupRun = true;
if(!fixedLocation) setUrl(lastLatitude, lastLongitude);
send();
if(handler != null) handler.postDelayed(this, weatherDelay);
}
private void send() {
if(url == null) return;
Intent i = new Intent(HTMLExtractManager.ACTION_WEATHER);
i.putExtra(XMLPrefsManager.VALUE_ATTRIBUTE, url);
i.putExtra(HTMLExtractManager.BROADCAST_COUNT, HTMLExtractManager.broadcastCount);
LocalBroadcastManager.getInstance(mContext.getApplicationContext()).sendBroadcast(i);
}
private void setUrl(String where) {
url = "http://api.openweathermap.org/data/2.5/weather?" + where + "&appid=" + key + "&units=" + XMLPrefsManager.get(Behavior.weather_temperature_measure);
}
private void setUrl(double latitude, double longitude) {
url = "http://api.openweathermap.org/data/2.5/weather?" + "lat=" + latitude + "&lon=" + longitude + "&appid=" + key + "&units=" + XMLPrefsManager.get(Behavior.weather_temperature_measure);
}
}
// you need to use labelIndexes[i]
private void updateText(Label l, CharSequence s) {
labelTexts[l.ordinal()] = s;
int base = (int) labelIndexes[l.ordinal()];
List<Float> indexs = new ArrayList<>();
for(int count = 0; count < Label.values().length; count++) {
if((int) labelIndexes[count] == base && labelTexts[count] != null) indexs.add(labelIndexes[count]);
}
// now I'm sorting the labels on the same line for decimals (2.1, 2.0, ...)
Collections.sort(indexs);
CharSequence sequence = Tuils.EMPTYSTRING;
for(int c = 0; c < indexs.size(); c++) {
float i = indexs.get(c);
for(int a = 0; a < Label.values().length; a++) {
if(i == labelIndexes[a] && labelTexts[a] != null) sequence = TextUtils.concat(sequence, labelTexts[a]);
}
}
if(sequence.length() == 0) labelViews[base].setVisibility(View.GONE);
else {
labelViews[base].setVisibility(View.VISIBLE);
labelViews[base].setText(sequence);
}
}
private boolean is_simons_sexy_view_enabled = true;
private SuggestionsManager suggestionsManager;
private TextView terminalView;
private String doubleTapCmd;
private boolean lockOnDbTap;
private BroadcastReceiver receiver;
public MainPack pack;
private boolean clearOnLock;
protected UIManager(final Context context, final ViewGroup rootView, MainPack mainPack, boolean canApplyTheme, CommandExecuter executer) {
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_UPDATE_SUGGESTIONS);
filter.addAction(ACTION_UPDATE_HINT);
filter.addAction(ACTION_ROOT);
filter.addAction(ACTION_NOROOT);
// filter.addAction(ACTION_CLEAR_SUGGESTIONS);
filter.addAction(ACTION_LOGTOFILE);
filter.addAction(ACTION_CLEAR);
filter.addAction(ACTION_WEATHER);
filter.addAction(ACTION_WEATHER_GOT_LOCATION);
filter.addAction(ACTION_WEATHER_DELAY);
filter.addAction(ACTION_WEATHER_MANUAL_UPDATE);
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(ACTION_UPDATE_SUGGESTIONS)) {
if(suggestionsManager != null) suggestionsManager.requestSuggestion(Tuils.EMPTYSTRING);
} else if(action.equals(ACTION_UPDATE_HINT)) {
mTerminalAdapter.setDefaultHint();
} else if(action.equals(ACTION_ROOT)) {
mTerminalAdapter.onRoot();
} else if(action.equals(ACTION_NOROOT)) {
mTerminalAdapter.onStandard();
// } else if(action.equals(ACTION_CLEAR_SUGGESTIONS)) {
// if(suggestionsManager != null) suggestionsManager.clear();
} else if(action.equals(ACTION_LOGTOFILE)) {
String fileName = intent.getStringExtra(FILE_NAME);
if(fileName == null || fileName.contains(File.separator)) return;
File file = new File(Tuils.getFolder(), fileName);
if(file.exists()) file.delete();
try {
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(mTerminalAdapter.getTerminalText().getBytes());
Tuils.sendOutput(context, "Logged to " + file.getAbsolutePath());
} catch (Exception e) {
Tuils.sendOutput(Color.RED, context, e.toString());
}
} else if(action.equals(ACTION_CLEAR)) {
mTerminalAdapter.clear();
if (suggestionsManager != null)
suggestionsManager.requestSuggestion(Tuils.EMPTYSTRING);
} else if(action.equals(ACTION_WEATHER)) {
Calendar c = Calendar.getInstance();
CharSequence s = intent.getCharSequenceExtra(XMLPrefsManager.VALUE_ATTRIBUTE);
if(s == null) s = intent.getStringExtra(XMLPrefsManager.VALUE_ATTRIBUTE);
if(s == null) return;
s = Tuils.span(context, s, weatherColor, labelSizes[Label.weather.ordinal()]);
updateText(Label.weather, s);
if(showWeatherUpdate) {
String message = context.getString(R.string.weather_updated) + Tuils.SPACE + c.get(Calendar.HOUR_OF_DAY) + "." + c.get(Calendar.MINUTE) + Tuils.SPACE + "(" + lastLatitude + ", " + lastLongitude + ")";
Tuils.sendOutput(context, message, TerminalManager.CATEGORY_OUTPUT);
}
} else if(action.equals(ACTION_WEATHER_GOT_LOCATION)) {
// int result = intent.getIntExtra(XMLPrefsManager.VALUE_ATTRIBUTE, 0);
// if(result == PackageManager.PERMISSION_DENIED) {
// updateText(Label.weather, Tuils.span(context, context.getString(R.string.location_error), weatherColor, labelSizes[Label.weather.ordinal()]));
// } else handler.post(weatherRunnable);
if(intent.getBooleanExtra(TuiLocationManager.FAIL, false)) {
handler.removeCallbacks(weatherRunnable);
weatherRunnable = null;
CharSequence s = Tuils.span(context, context.getString(R.string.location_error), weatherColor, labelSizes[Label.weather.ordinal()]);
updateText(Label.weather, s);
} else {
lastLatitude = intent.getDoubleExtra(TuiLocationManager.LATITUDE, 0);
lastLongitude = intent.getDoubleExtra(TuiLocationManager.LONGITUDE, 0);
location = Tuils.locationName(context, lastLatitude, lastLongitude);
if(!weatherPerformedStartupRun || XMLPrefsManager.wasChanged(Behavior.weather_key, false)) {
handler.removeCallbacks(weatherRunnable);
handler.post(weatherRunnable);
}
}
} else if(action.equals(ACTION_WEATHER_DELAY)) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis() + 1000 * 10);
if(showWeatherUpdate) {
String message = context.getString(R.string.weather_error) + Tuils.SPACE + c.get(Calendar.HOUR_OF_DAY) + "." + c.get(Calendar.MINUTE);
Tuils.sendOutput(context, message, TerminalManager.CATEGORY_OUTPUT);
}
handler.removeCallbacks(weatherRunnable);
handler.postDelayed(weatherRunnable, 1000 * 60);
} else if(action.equals(ACTION_WEATHER_MANUAL_UPDATE)) {
handler.removeCallbacks(weatherRunnable);
handler.post(weatherRunnable);
}
}
};
LocalBroadcastManager.getInstance(context.getApplicationContext()).registerReceiver(receiver, filter);
policy = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
component = new ComponentName(context, PolicyReceiver.class);
mContext = context;
preferences = mContext.getSharedPreferences(PREFS_NAME, 0);
handler = new Handler();
imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if (!XMLPrefsManager.getBoolean(Ui.system_wallpaper) || !canApplyTheme) {
rootView.setBackgroundColor(XMLPrefsManager.getColor(Theme.bg_color));
} else {
rootView.setBackgroundColor(XMLPrefsManager.getColor(Theme.overlay_color));
}
// scrolllllll
if(XMLPrefsManager.getBoolean(Behavior.auto_scroll)) {
rootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
int heightDiff = rootView.getRootView().getHeight() - rootView.getHeight();
if (heightDiff > Tuils.dpToPx(context, 200)) { // if more than 200 dp, it's probably a keyboard...
if(mTerminalAdapter != null) mTerminalAdapter.scrollToEnd();
}
});
}
clearOnLock = XMLPrefsManager.getBoolean(Behavior.clear_on_lock);
lockOnDbTap = XMLPrefsManager.getBoolean(Behavior.double_tap_lock);
doubleTapCmd = XMLPrefsManager.get(Behavior.double_tap_cmd);
if(!lockOnDbTap && doubleTapCmd == null) {
policy = null;
component = null;
gestureDetector = null;
} else {
gestureDetector = new GestureDetectorCompat(mContext, new GestureDetector.OnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
});
gestureDetector.setOnDoubleTapListener(new OnDoubleTapListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
if(doubleTapCmd != null && doubleTapCmd.length() > 0) {
String input = mTerminalAdapter.getInput();
mTerminalAdapter.setInput(doubleTapCmd);
mTerminalAdapter.simulateEnter();
mTerminalAdapter.setInput(input);
}
if(lockOnDbTap) {
boolean admin = policy.isAdminActive(component);
if (!admin) {
Intent i = Tuils.requestAdmin(component, mContext.getString(R.string.admin_permission));
mContext.startActivity(i);
} else {
policy.lockNow();
}
}
return true;
}
});
}
int[] displayMargins = getListOfIntValues(XMLPrefsManager.get(Ui.display_margin_mm), 4, 0);
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
rootView.setPadding(Tuils.mmToPx(metrics, displayMargins[0]), Tuils.mmToPx(metrics, displayMargins[1]), Tuils.mmToPx(metrics, displayMargins[2]), Tuils.mmToPx(metrics, displayMargins[3]));
labelSizes[Label.time.ordinal()] = XMLPrefsManager.getInt(Ui.time_size);
labelSizes[Label.ram.ordinal()] = XMLPrefsManager.getInt(Ui.ram_size);
labelSizes[Label.battery.ordinal()] = XMLPrefsManager.getInt(Ui.battery_size);
labelSizes[Label.storage.ordinal()] = XMLPrefsManager.getInt(Ui.storage_size);
labelSizes[Label.network.ordinal()] = XMLPrefsManager.getInt(Ui.network_size);
labelSizes[Label.notes.ordinal()] = XMLPrefsManager.getInt(Ui.notes_size);
labelSizes[Label.device.ordinal()] = XMLPrefsManager.getInt(Ui.device_size);
labelSizes[Label.weather.ordinal()] = XMLPrefsManager.getInt(Ui.weather_size);