-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathNextApplication.java
More file actions
331 lines (288 loc) · 14 KB
/
NextApplication.java
File metadata and controls
331 lines (288 loc) · 14 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
package com.lingtuan.firefly;
import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.net.wifi.WifiManager;
import android.support.multidex.MultiDex;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.Log;
import android.widget.ImageView;
import com.lingtuan.firefly.custom.BitmapFillet;
import com.lingtuan.firefly.custom.RoundBitmapDisplayer;
import com.lingtuan.firefly.db.user.FinalUserDataBase;
import com.lingtuan.firefly.listener.RequestListener;
import com.lingtuan.firefly.raiden.API;
import com.lingtuan.firefly.raiden.RaidenNet;
import com.lingtuan.firefly.raiden.RaidenUrl;
import com.lingtuan.firefly.util.CrashHandler;
import com.lingtuan.firefly.util.MySharedPrefs;
import com.lingtuan.firefly.util.SDCardCtrl;
import com.lingtuan.firefly.util.SmileyParser;
import com.lingtuan.firefly.util.Utils;
import com.lingtuan.firefly.util.netutil.NetRequestImpl;
import com.lingtuan.firefly.util.netutil.NetRequestUtils;
import com.lingtuan.firefly.vo.UserInfoVo;
import com.lingtuan.firefly.wallet.util.WalletStorage;
import com.lingtuan.firefly.wallet.vo.StorableWallet;
import com.lingtuan.firefly.wallet.vo.TokenVo;
import com.lingtuan.firefly.xmpp.XmppUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.ImageSize;
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import org.jivesoftware.smackx.pubsub.Subscription;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Created on 2017/8/18.
*/
public class NextApplication extends Application {
public static Context mContext;
public static UserInfoVo myInfo;
public static API api;
public static String mRaidenStatus;
public static Subscription mRaidenSubscribe;
public static ExecutorService mRaidenThreadPool;
public static boolean raidenSwitch = false;
public static ImageLoader mImageLoader = null;
private static DisplayImageOptions mOptionsNull;
private static DisplayImageOptions mOptionsCircle;
private static DisplayImageOptions mOptionsCircleToken;
/*expression*/
public static SmileyParser mSmileyParser;
public static Object lock;
@Override
public void onCreate() {
super.onCreate();
/** Initialize the folder*/
SDCardCtrl.initPath(this);
lock = new Object();
XmppUtils.isLogining = false;
mContext = this;
try {
myInfo = new UserInfoVo().readMyUserInfo(this);
Resources res = getResources();
Configuration config = new Configuration();
config.setToDefaults();
config.fontScale = 1;
res.updateConfiguration(config, res.getDisplayMetrics());
} catch (Exception e) {
e.printStackTrace();
}
NetRequestUtils.getInstance().getServerTime(this);
initImageLoaderConfig();
/**Initialize the expression*/
SmileyParser.init(this);
mSmileyParser = SmileyParser.getInstance();
/**Initialization error log collection*/
CrashHandler crashHandler = CrashHandler.getInstance();
crashHandler.init(getApplicationContext());
getWalletChange();
initKeystore();
// initKeyData();
raidenMobileStart();
}
private void initKeystore() {
try {
File file = new File(getFilesDir(), SDCardCtrl.WALLERPATH);
file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (!name.startsWith(RaidenUrl.keystorePath)) {
String okFilePth = dir.getAbsolutePath() + "/" + RaidenUrl.keystorePath + "0x" + name;
File oldFile = new File(dir.getAbsolutePath() + "/" + name);
oldFile.renameTo(new File(okFilePth));
} else {
String tempName;
tempName = name.substring(RaidenUrl.keystorePath.length());
if (!tempName.startsWith("0x")) {
tempName = "0x" + tempName;
}
String okFilePth = dir.getAbsolutePath() + "/" + RaidenUrl.keystorePath + tempName;
File oldFile = new File(dir.getAbsolutePath() + "/" + name);
oldFile.renameTo(new File(okFilePth));
}
return true;
}
});
} catch (Exception e) {
Log.i("xxxxxxxx异常", e.toString());
}
}
private void initKeyData(){
try {
File file = new File(getFilesDir(), SDCardCtrl.RAIDEN_DATA);
file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
File oldFile = new File(dir.getAbsolutePath() + "/" + name);
oldFile.delete();
return true;
}
});
} catch (Exception e) {
Log.i("xxxxxxxx异常", e.toString());
}
}
/**
* change wallet
*/
private void getWalletChange() {
if (myInfo != null && myInfo.getLocalId() != null) {
int version = MySharedPrefs.readInt(mContext, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_WALLET_CHANGE_VERSION + myInfo.getLocalId());
NetRequestImpl.getInstance().getChange(version, new RequestListener() {
@Override
public void start() {
}
@Override
public void success(JSONObject response) {
int version = response.optInt("version");
MySharedPrefs.writeInt(mContext, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_WALLET_CHANGE_VERSION + myInfo.getLocalId(), version);
JSONArray listArray = response.optJSONArray("data");
if (listArray == null || listArray.length() <= 0) {
return;
}
FinalUserDataBase.getInstance().beginTransaction();
for (int i = 0; i < listArray.length(); i++) {
TokenVo token = new TokenVo().parse(listArray.optJSONObject(i));
FinalUserDataBase.getInstance().updateAllAddressToken(token);
}
FinalUserDataBase.getInstance().endTransactionSuccessful();
}
@Override
public void error(int errorCode, String errorMsg) {
}
});
}
}
private void raidenMobileStart() {
// try {
mRaidenThreadPool = Executors.newFixedThreadPool(6);
// ArrayList<StorableWallet> storableWallets = WalletStorage.getInstance(getApplicationContext()).get();
// if (storableWallets != null && storableWallets.size() > 0) {
// String selectAddress = "";
// for (int i = 0; i < storableWallets.size(); i++) {
// if (storableWallets.get(i).isSelect()) {
// selectAddress = storableWallets.get(i).getPublicKey();
// }
// }
// if (TextUtils.isEmpty(selectAddress)) {
// selectAddress = storableWallets.get(0).getPublicKey();
// }
// if (!selectAddress.startsWith("0x")) {
// selectAddress = "0x" + selectAddress;
// }
// final String TempAddress = selectAddress;
// new Thread(new Runnable() {
//
// @Override
// public void run() {
// try {
// WifiManager wm = (WifiManager) mContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
// String clientIP = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
//// "ws://192.168.0.152:18546",
//// "ws://182.254.155.208:37171",
// api = SmartRaiden.startUp(
// TempAddress,
// getFilesDir().getAbsolutePath() + SDCardCtrl.WALLERPATH,
// "ws://192.168.0.152:18546",
// getFilesDir().getAbsolutePath() + SDCardCtrl.RAIDEN_DATA,
// "111111",
// "127.0.0.1:5001",
// clientIP + ":40001",
// "",
// null);
//
// mRaidenSubscribe = api.subscribe(new NotifyHandler() {
// @Override
// public void onError(long l, String s) {
// Log.i("xxxxxxxxxx==onError", "===" + l + "====" + s);
// }
//
// @Override
// public void onReceivedTransfer(String s) {
// Log.i("xxxxxx==onRTransfer", "===" + s);
// }
//
// @Override
// public void onSentTransfer(String s) {
// Log.i("xxxxxx==onSTransfer", "===" + s);
// }
//
// @Override
// public void onStatusChange(String s) {
// Log.i("xxxxxx==onStatusChange", "===" + s);
// mRaidenStatus = s;
// }
// });
//
// } catch (Exception e) {
// Log.i("ddddddddddddd异常", "====" + e.toString());
// mRaidenSubscribe.unsubscribe();
// RaidenNet.getInatance().stopRaiden();
// }
// }
// }).start();
// }
//
// } catch (Exception e) {
// Log.i("dddddddddd", e.toString());
// mRaidenSubscribe.unsubscribe();
// RaidenNet.getInatance().stopRaiden();
// }
}
private void initImageLoaderConfig() {
int width = getResources().getDisplayMetrics().widthPixels;
int height = getResources().getDisplayMetrics().heightPixels;
/** Use the default configuration*/
ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(getApplicationContext()).memoryCacheExtraOptions(width, height).threadPoolSize(3).build();
mImageLoader = ImageLoader.getInstance();
mImageLoader.init(configuration);
mOptionsCircle = new DisplayImageOptions.Builder().bitmapConfig(Bitmap.Config.RGB_565).showImageForEmptyUri(R.drawable.nothing).showImageOnFail(R.drawable.nothing).showImageOnLoading(R.drawable.nothing).cacheOnDisc(true).cacheInMemory(true).displayer(new RoundBitmapDisplayer(BitmapFillet.ROUND, 0)).imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).build();
mOptionsCircleToken = new DisplayImageOptions.Builder().bitmapConfig(Bitmap.Config.RGB_565).showImageForEmptyUri(R.drawable.icon_default_token).showImageOnFail(R.drawable.icon_default_token).showImageOnLoading(R.drawable.icon_default_token).cacheOnDisc(true).cacheInMemory(true).displayer(new RoundBitmapDisplayer(BitmapFillet.ROUND, 0)).imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).build();
mOptionsNull = new DisplayImageOptions.Builder().bitmapConfig(Bitmap.Config.RGB_565).showImageForEmptyUri(R.drawable.nothing).showImageOnFail(R.drawable.nothing).showImageOnLoading(R.drawable.nothing).cacheOnDisc(true).cacheInMemory(true).imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).build();
}
/*According to circular head*/
public static void displayCircleImage(ImageView avatarView, String avatarUrl) {
display(avatarView, avatarUrl, mOptionsCircle, null, null);
}
/*According to circular head*/
public static void displayCircleToken(ImageView avatarView, String avatarUrl) {
display(avatarView, avatarUrl, mOptionsCircleToken, null, null);
}
public static void displayNothing(ImageView avatarView, String avatarUrl, ImageLoadingListener listener) {
display(avatarView, avatarUrl, mOptionsNull, listener, null);
}
private static void display(ImageView avatarView, String avatarUrl, DisplayImageOptions options, ImageLoadingListener listener, ImageSize size) {
if (avatarUrl == null) {
avatarUrl = "";
}
if (size == null) {
mImageLoader.displayImage(avatarUrl, avatarView, options, listener);
} else {
mImageLoader.displayImage(avatarUrl, new ImageViewAware(avatarView), options, size, null, null);
}
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
/**Set the language*/
Utils.settingLanguage(NextApplication.this);
}
}