Salut à tous,
Je viens de changer une bonne partie de mon code et y ai ajouter des hashmap, le problème c'est que c'est aps du tout optimisé et ca se sent
Voici un bout de code :
Et la les gens qui ont plus l'habitude que moi de faire du Java sur Android sautent certainement au plafond
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public static enum datas{ALLAPPS, SMS, CONTACTS, BROWSER, PHONE, WPP}; private static HashMap<Object, Bitmap> DicoDataBmp = new HashMap<Object, Bitmap>(){{ put(datas.ALLAPPS, null); put(datas.SMS, null); put(datas.CONTACTS, null); put(datas.BROWSER, null); put(datas.PHONE, null); put(datas.WPP, null); }}; private static HashMap<Object, String> DicoDataFilename = new HashMap<Object, String>(){{ put(datas.ALLAPPS, "file_allapps.jpg"); put(datas.SMS, "file_sms.jpg"); put(datas.CONTACTS, "file_contacts.jpg"); put(datas.BROWSER, "file_browser.jpg"); put(datas.PHONE, "file_phone.jpg"); put(datas.WPP, "file_wpp.jpg"); }}; private static HashMap<Object, Integer> DicoDataDefaultDrawable = new HashMap<Object, Integer>(){{ put(datas.ALLAPPS, R.drawable.ic_allapps); put(datas.SMS, R.drawable.sms); put(datas.CONTACTS, R.drawable.contacts); put(datas.BROWSER, R.drawable.web); put(datas.PHONE, R.drawable.phone); put(datas.WPP, R.drawable.wallpaper_01); }}; public static void blabla(Context context){ // Load images from sdcard File sdcard = Environment.getExternalStorageDirectory(); String file; Bitmap bmp; Object key; for(Entry<Object, String> dico : DicoDataFilename.entrySet()){ key = dico.getKey(); file = new File(sdcard + File.separator + dico.getValue()).getAbsolutePath(); bmp = BitmapFactory.decodeFile(file); if(bmp == null){ DicoDataBmp.put(key, BitmapFactory.decodeResource(context.getResources(), DicoDataDefaultDrawable.get(key))); }else{ DicoDataBmp.put(key, bmp); } } }
Déjà je comprend pas bien pourquoi je ne peut pas faire passer mes "datas" pour des int comme en C++ ... ca me parmettrait d'utiliser des ParseArray.
Bref, auriez vous une idée de comment je pourrais optimiser ca ?
Merci d'avance.
Edit :
J'ai changer un peu le code, mais ca reste lent :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 private static final int ALLAPPS = 0; private static final int SMS = 1; private static final int CONTACTS = 2; private static final int BROWSER = 3; private static final int PHONE = 4; private static final int WPP = 5; private static SparseArray<Bitmap> DicoDataBmp = new SparseArray<Bitmap>(){{ append(ALLAPPS, null); append(SMS, null); append(CONTACTS, null); append(BROWSER, null); append(PHONE, null); append(WPP, null); }}; private static SparseArray<String> DicoDataFilename = new SparseArray<String>(){{ append(ALLAPPS, "file_allapps.jpg"); append(SMS, "file_sms.jpg"); append(CONTACTS, "file_contacts.jpg"); append(BROWSER, "file_browser.jpg"); append(PHONE, "file_phone.jpg"); append(WPP, "file_wpp.jpg"); }}; private static SparseIntArray DicoDataDefaultDrawable = new SparseIntArray(){{ append(ALLAPPS, R.drawable.ic_allapps); append(SMS, R.drawable.sms); append(CONTACTS, R.drawable.contacts); append(BROWSER, R.drawable.web); append(PHONE, R.drawable.phone); append(WPP, R.drawable.wallpaper_01); }};
Partager