|
1 | | -package com.zeromake.onscripter; |
2 | | - |
3 | | -import android.app.Activity; |
4 | | -import android.content.SharedPreferences; |
5 | | -import android.os.Environment; |
6 | | - |
7 | | -import com.nostra13.universalimageloader.core.DisplayImageOptions; |
8 | | - |
9 | | -import java.io.File; |
10 | | -import java.util.ArrayList; |
11 | | -import java.util.TreeSet; |
12 | | - |
13 | | -public class Settings { |
14 | | - |
15 | | - private static boolean globalsSettingsLoaded = false; |
16 | | - |
17 | | - private Settings() { |
18 | | - } |
19 | | - |
20 | | - public static void LoadGlobals(Activity activity, boolean reload) { |
21 | | - if (globalsSettingsLoaded && !reload) { |
22 | | - return; |
23 | | - } |
24 | | - SharedPreferences sharedPreferences = activity.getSharedPreferences("pref", 0); |
25 | | - Globals.CurrentDirectoryPathForLauncher = sharedPreferences.getString("CurrentDirectoryPathForLauncher", Globals.CurrentDirectoryPathForLauncher); |
26 | | - setupCurrentDirectory(); |
27 | | - globalsSettingsLoaded = true; |
28 | | - } |
29 | | - |
30 | | - public static void SaveGlobals(Activity activity) { |
31 | | - SharedPreferences.Editor edit = activity.getSharedPreferences("pref", 0).edit(); |
32 | | - edit.clear(); |
33 | | - if (Globals.CurrentDirectoryPathForLauncher != null) { |
34 | | - edit.putString("CurrentDirectoryPathForLauncher", Globals.CurrentDirectoryPathForLauncher); |
35 | | - } |
36 | | - edit.apply(); |
37 | | - } |
38 | | - |
39 | | - private static void setupCurrentDirectory() { |
40 | | - if (Globals.CurrentDirectoryPathForLauncher != null) { |
41 | | - if (Globals.CurrentDirectoryPathForLauncher.equals("")) { |
42 | | - Globals.CurrentDirectoryPathForLauncher = null; |
43 | | - } else { |
44 | | - File file = new File(Globals.CurrentDirectoryPathForLauncher); |
45 | | - if (!file.exists() || !file.isDirectory() || !file.canRead()) { |
46 | | - Globals.CurrentDirectoryPathForLauncher = null; |
47 | | - } |
48 | | - } |
49 | | - } |
50 | | - Globals.CurrentDirectoryPath = null; |
51 | | - ArrayList<String> arrayList = new ArrayList<>(); |
52 | | - TreeSet<String> treeSet = new TreeSet<>(); |
53 | | - for (String str : Globals.CURRENT_DIRECTORY_PATH_TEMPLATE_ARRAY) { |
54 | | - if (!str.contains("${SDCARD}")) { |
55 | | - treeSet.add(str); |
56 | | - } else { |
57 | | - treeSet.add(str.replace("${SDCARD}", Environment.getExternalStorageDirectory().getAbsolutePath())); |
58 | | - treeSet.add(str.replace("${SDCARD}", "/mnt/ext_card")); |
59 | | - treeSet.add(str.replace("${SDCARD}", "/mnt/flash")); |
60 | | - treeSet.add(str.replace("${SDCARD}", "/mnt/sdcard")); |
61 | | - treeSet.add(str.replace("${SDCARD}", "/mnt/sdcard/external_sd")); |
62 | | - treeSet.add(str.replace("${SDCARD}", "/mnt/sdcard-ext")); |
63 | | - treeSet.add(str.replace("${SDCARD}", "/mnt/storage/sdcard")); |
64 | | - treeSet.add(str.replace("${SDCARD}", "/mnt/udisk")); |
65 | | - treeSet.add(str.replace("${SDCARD}", "/mnt/usbdisk")); |
66 | | - treeSet.add(str.replace("${SDCARD}", "/sdcard")); |
67 | | - treeSet.add(str.replace("${SDCARD}", "/sdcard/sd")); |
68 | | - String str2 = System.getenv("EXTERNAL_STORAGE"); |
69 | | - if (str2 != null) { |
70 | | - treeSet.add(str.replace("${SDCARD}", str2)); |
71 | | - } |
72 | | - String str3 = System.getenv("EXTERNAL_STORAGE2"); |
73 | | - if (str3 != null) { |
74 | | - treeSet.add(str.replace("${SDCARD}", str3)); |
75 | | - } |
76 | | - String str4 = System.getenv("EXTERNAL_ALT_STORAGE"); |
77 | | - if (str4 != null) { |
78 | | - treeSet.add(str.replace("${SDCARD}", str4)); |
79 | | - } |
80 | | - String str5 = System.getenv("SECOND_VOLUME_STORAGE"); |
81 | | - if (str5 != null) { |
82 | | - treeSet.add(str.replace("${SDCARD}", str5)); |
83 | | - } |
84 | | - String str6 = System.getenv("THIRD_VOLUME_STORAGE"); |
85 | | - if (str6 != null) { |
86 | | - treeSet.add(str.replace("${SDCARD}", str6)); |
87 | | - } |
88 | | - String str7 = System.getenv("SECONDARY_STORAGE"); |
89 | | - if (str7 != null) { |
90 | | - treeSet.add(str.replace("${SDCARD}", str7)); |
91 | | - } |
92 | | - String str8 = System.getenv("EXTERNAL_STORAGE_ALL"); |
93 | | - if (str8 != null) { |
94 | | - for (String str9 : str8.split(";")) { |
95 | | - treeSet.add(str.replace("${SDCARD}", str9)); |
96 | | - } |
97 | | - } |
98 | | - } |
99 | | - for (String s : treeSet) { |
100 | | - File file2 = new File(s); |
101 | | - if (file2.exists() && file2.isDirectory() && file2.canRead() && file2.canWrite()) { |
102 | | - String absolutePath = file2.getAbsolutePath(); |
103 | | - if (Globals.CurrentDirectoryPathForLauncher == null || Globals.CurrentDirectoryPathForLauncher.equals("")) { |
104 | | - Globals.CurrentDirectoryPathForLauncher = absolutePath; |
105 | | - } |
106 | | - if (Globals.CurrentDirectoryPath == null || Globals.CurrentDirectoryPath.equals("")) { |
107 | | - Globals.CurrentDirectoryPath = absolutePath; |
108 | | - } |
109 | | - arrayList.add(absolutePath); |
110 | | - } |
111 | | - } |
112 | | - } |
113 | | - Globals.CurrentDirectoryPathArray = (String[]) treeSet.toArray(new String[0]); |
114 | | - Globals.CurrentDirectoryValidPathArray = (String[]) arrayList.toArray(new String[0]); |
115 | | - } |
116 | | - |
117 | | - public static DisplayImageOptions getDisplayImageOptions() { |
118 | | - return new DisplayImageOptions.Builder() |
119 | | - .cacheInMemory(true)//是否进行内存缓存 |
120 | | - .build(); |
121 | | - } |
122 | | -} |
| 1 | +package com.zeromake.onscripter; |
| 2 | + |
| 3 | +import android.app.Activity; |
| 4 | +import android.content.SharedPreferences; |
| 5 | +import android.os.Environment; |
| 6 | + |
| 7 | +import com.nostra13.universalimageloader.core.DisplayImageOptions; |
| 8 | + |
| 9 | +import java.io.File; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.TreeSet; |
| 12 | + |
| 13 | +public class Settings { |
| 14 | + |
| 15 | + private static boolean globalsSettingsLoaded = false; |
| 16 | + |
| 17 | + private Settings() { |
| 18 | + } |
| 19 | + |
| 20 | + public static void LoadGlobals(Activity activity, boolean reload) { |
| 21 | + if (globalsSettingsLoaded && !reload) { |
| 22 | + return; |
| 23 | + } |
| 24 | + SharedPreferences sharedPreferences = activity.getSharedPreferences("pref", 0); |
| 25 | + Globals.CurrentDirectoryPathForLauncher = sharedPreferences.getString("CurrentDirectoryPathForLauncher", Globals.CurrentDirectoryPathForLauncher); |
| 26 | + setupCurrentDirectory(); |
| 27 | + globalsSettingsLoaded = true; |
| 28 | + } |
| 29 | + |
| 30 | + public static void SaveGlobals(Activity activity) { |
| 31 | + SharedPreferences.Editor edit = activity.getSharedPreferences("pref", 0).edit(); |
| 32 | + edit.clear(); |
| 33 | + if (Globals.CurrentDirectoryPathForLauncher != null) { |
| 34 | + edit.putString("CurrentDirectoryPathForLauncher", Globals.CurrentDirectoryPathForLauncher); |
| 35 | + } |
| 36 | + edit.apply(); |
| 37 | + } |
| 38 | + |
| 39 | + private static void setupCurrentDirectory() { |
| 40 | + if (Globals.CurrentDirectoryPathForLauncher != null) { |
| 41 | + if (Globals.CurrentDirectoryPathForLauncher.equals("")) { |
| 42 | + Globals.CurrentDirectoryPathForLauncher = null; |
| 43 | + } else { |
| 44 | + File file = new File(Globals.CurrentDirectoryPathForLauncher); |
| 45 | + if (!file.exists() || !file.isDirectory() || !file.canRead()) { |
| 46 | + Globals.CurrentDirectoryPathForLauncher = null; |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + Globals.CurrentDirectoryPath = null; |
| 51 | + ArrayList<String> arrayList = new ArrayList<>(); |
| 52 | + TreeSet<String> treeSet = new TreeSet<>(); |
| 53 | + for (String str : Globals.CURRENT_DIRECTORY_PATH_TEMPLATE_ARRAY) { |
| 54 | + if (!str.contains("${SDCARD}")) { |
| 55 | + treeSet.add(str); |
| 56 | + } else { |
| 57 | + treeSet.add(str.replace("${SDCARD}", Environment.getExternalStorageDirectory().getAbsolutePath())); |
| 58 | + treeSet.add(str.replace("${SDCARD}", "/mnt/ext_card")); |
| 59 | + treeSet.add(str.replace("${SDCARD}", "/mnt/flash")); |
| 60 | + treeSet.add(str.replace("${SDCARD}", "/mnt/sdcard")); |
| 61 | + treeSet.add(str.replace("${SDCARD}", "/mnt/sdcard/external_sd")); |
| 62 | + treeSet.add(str.replace("${SDCARD}", "/mnt/sdcard-ext")); |
| 63 | + treeSet.add(str.replace("${SDCARD}", "/mnt/storage/sdcard")); |
| 64 | + treeSet.add(str.replace("${SDCARD}", "/mnt/udisk")); |
| 65 | + treeSet.add(str.replace("${SDCARD}", "/mnt/usbdisk")); |
| 66 | + treeSet.add(str.replace("${SDCARD}", "/sdcard")); |
| 67 | + treeSet.add(str.replace("${SDCARD}", "/sdcard/sd")); |
| 68 | + treeSet.add(str.replace("${SDCARD}", "/storage/sdcard")); |
| 69 | + treeSet.add(str.replace("${SDCARD}", "/storage/emulated/0")); |
| 70 | + String str2 = System.getenv("EXTERNAL_STORAGE"); |
| 71 | + if (str2 != null) { |
| 72 | + treeSet.add(str.replace("${SDCARD}", str2)); |
| 73 | + } |
| 74 | + String str3 = System.getenv("EXTERNAL_STORAGE2"); |
| 75 | + if (str3 != null) { |
| 76 | + treeSet.add(str.replace("${SDCARD}", str3)); |
| 77 | + } |
| 78 | + String str4 = System.getenv("EXTERNAL_ALT_STORAGE"); |
| 79 | + if (str4 != null) { |
| 80 | + treeSet.add(str.replace("${SDCARD}", str4)); |
| 81 | + } |
| 82 | + String str5 = System.getenv("SECOND_VOLUME_STORAGE"); |
| 83 | + if (str5 != null) { |
| 84 | + treeSet.add(str.replace("${SDCARD}", str5)); |
| 85 | + } |
| 86 | + String str6 = System.getenv("THIRD_VOLUME_STORAGE"); |
| 87 | + if (str6 != null) { |
| 88 | + treeSet.add(str.replace("${SDCARD}", str6)); |
| 89 | + } |
| 90 | + String str7 = System.getenv("SECONDARY_STORAGE"); |
| 91 | + if (str7 != null) { |
| 92 | + treeSet.add(str.replace("${SDCARD}", str7)); |
| 93 | + } |
| 94 | + String str8 = System.getenv("EXTERNAL_STORAGE_ALL"); |
| 95 | + if (str8 != null) { |
| 96 | + for (String str9 : str8.split(";")) { |
| 97 | + treeSet.add(str.replace("${SDCARD}", str9)); |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + for (String s : treeSet) { |
| 102 | + File file2 = new File(s); |
| 103 | + if (file2.exists() && file2.isDirectory() && file2.canRead() && file2.canWrite()) { |
| 104 | + String absolutePath = file2.getAbsolutePath(); |
| 105 | + if (Globals.CurrentDirectoryPathForLauncher == null || Globals.CurrentDirectoryPathForLauncher.equals("")) { |
| 106 | + Globals.CurrentDirectoryPathForLauncher = absolutePath; |
| 107 | + } |
| 108 | + if (Globals.CurrentDirectoryPath == null || Globals.CurrentDirectoryPath.equals("")) { |
| 109 | + Globals.CurrentDirectoryPath = absolutePath; |
| 110 | + } |
| 111 | + arrayList.add(absolutePath); |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + Globals.CurrentDirectoryPathArray = (String[]) treeSet.toArray(new String[0]); |
| 116 | + Globals.CurrentDirectoryValidPathArray = (String[]) arrayList.toArray(new String[0]); |
| 117 | + } |
| 118 | + |
| 119 | + public static DisplayImageOptions getDisplayImageOptions() { |
| 120 | + return new DisplayImageOptions.Builder() |
| 121 | + .cacheInMemory(true)//是否进行内存缓存 |
| 122 | + .build(); |
| 123 | + } |
| 124 | +} |
0 commit comments