MyApplication.java
6.59 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
package com.sw.laryngoscope;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.provider.MediaStore;
import android.provider.Settings;
import android.view.Gravity;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import com.sw.laryngoscope.manager.AccountManager;
import com.sw.laryngoscope.manager.CameraCheck;
import com.sw.laryngoscope.manager.CameraInfoMg;
import com.sw.laryngoscope.manager.SpManager;
import com.sw.laryngoscope.manager.StorageStateManager;
import com.sw.laryngoscope.utils.LogcatHelper;
import com.sw.laryngoscope.utils.ShellUtils;
import com.sw.laryngoscope.utils.TimeUtil;
import com.sw.laryngoscope.utils.ZoneGetter;
import com.sw.laryngoscope.widget.SimplexToast;
import org.litepal.LitePal;
import org.litepal.LitePalApplication;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.TimeZone;
public class MyApplication extends LitePalApplication {
private final String TAG = "MyApplication";
private static MyApplication instance;
static Context _context;
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onCreate() {
super.onCreate();
CameraInfoMg.getInstance(this);
LogcatHelper.getInstance(this).start();
//Logger.d(" onCreate " + (0x1<<2));
TimeUtil.init(this);
/*int b = 0 | (0x03 << 24);
Logger.d(" onCreate " + (b >>> 24));*/
Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
ShellUtils.execCommand("wm density 160", true);
_context = getApplicationContext();
instance = this;
SpManager.init(getApplicationContext());
LitePal.initialize(this);
CameraCheck.getInstance(this);
AccountManager.getInstance().initList();
/*final List<Map<String, Object>> sortedList = ZoneGetter.getZonesList(this);
for(Map<String, Object> a:sortedList){
Logger.d(" sortedList " + a.values());
}*/
ZoneGetter mZoneGetter = new ZoneGetter();
mZoneGetter.getZones(getContext());
String[] zoneList = TimeZone.getAvailableIDs();
ArrayList<String> TZ1 = new ArrayList<String>();
for(String a:zoneList){
TimeZone d = TimeZone.getTimeZone(a);
// Logger.d(" getID " + d.getID());
// Logger.d(" getDisplayName " + d.getDisplayName());
// Logger.d(" showZonePop " + d.getDSTSavings());
//Logger.d(" showZonePop " + d.getRawOffset());
if ( !a.matches(".*/.*") ) {
continue;
}
/*for ( HashMap item:InitParam.zoneList ) {
if ( d.getID().equals(item.get(InitParam.ZONE_ID)) ) {
item.replace(InitParam.ZONE_COUNTRYNAME, d.getDisplayName(Locale.CHINA));
//item.replace()
//Logger.d(" getID " + d.getDisplayName(Locale.CHINA) + "" + d.get);
}
}*/
//if (TimeZone.getTimeZone(a).getRawOffset() / 3600 / 1000 == -5) {
//InitParam.zoneList.add(d.getDisplayName(false, TimeZone.LONG, Locale.CHINA));
//}
if(!(TZ1.contains(TimeZone.getTimeZone(a).getDisplayName(false, TimeZone.LONG, Locale.CHINA)))) {
TZ1.add(TimeZone.getTimeZone(a).getDisplayName(false, TimeZone.LONG, Locale.CHINA));
//InitParam.zoneList.add(d.getDisplayName(false, TimeZone.LONG, Locale.CHINA));
}
String region = a.replaceAll(".*/","").replaceAll("_"," ");
int hours = Math.abs(d.getRawOffset()) / 3600000;
int minutes = Math.abs(d.getRawOffset() / 60000) % 60;
String sign = d.getRawOffset() >= 0 ? "+" : "-";
String timeZonePretty = String.format("(UTC %s %02d:%02d) %s",sign,hours,minutes,region);
}
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
}
@Override
public void onTerminate() {
super.onTerminate();
}
public Context get_context() {
return _context;
}
public static MyApplication getInstance() {
return instance;
}
public static void showToastShort(String message) {
showToast(message, Toast.LENGTH_SHORT, 0, Gravity.BOTTOM);
}
public static void showToastLong(String message) {
showToast(message, Toast.LENGTH_LONG, 0, Gravity.BOTTOM);
}
public static void showToastLong1(String message) {
showToast1(message, Toast.LENGTH_LONG, 0, Gravity.BOTTOM);
}
public static void showToast(String message, int duration, int icon, int gravity) {
Context context = _context;
if (context != null)
SimplexToast.show(context, message, gravity, duration);
}
public static void showToast1(String message, int duration, int icon, int gravity) {
Context context = _context;
if (context != null)
SimplexToast.show1(context, message, gravity, duration);
}
public static Bitmap getVideoThumbnail(ContentResolver cr, String fileName) {
Bitmap bitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
//select condition.
String whereClause = MediaStore.Video.Media.DATA + " = '" + fileName + "'";
//colection of results.
Cursor cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Video.Media._ID }, whereClause,
null, null);
if (cursor == null || cursor.getCount() == 0) {
return null;
}
cursor.moveToFirst();
//image id in image table.
String videoId = cursor.getString(cursor
.getColumnIndex(MediaStore.Video.Media._ID));
if (videoId == null) {
return null;
}
cursor.close();
long videoIdLong = Long.parseLong(videoId);
//via imageid get the bimap type thumbnail in thumbnail table.
bitmap = MediaStore.Video.Thumbnails.getThumbnail(cr, videoIdLong,
MediaStore.Images.Thumbnails.MICRO_KIND, options);
return bitmap;
}
}