Initial commit.
[mobilnebezpieczenstwo.git] / src / com / samsung / srpol / data / Subcategory.java
1 /*
2    Copyright (C) 2014  Samsung Electronics Polska Sp. z o.o.
3
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU AFFERO General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8     You may obtain a copy of the License at
9
10                 http://www.gnu.org/licenses/agpl-3.0.txt
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 package com.samsung.srpol.data;
22
23 import java.util.ArrayList;
24
25 import android.content.Context;
26 import android.content.res.Resources.NotFoundException;
27 import android.graphics.drawable.Drawable;
28
29 public class Subcategory {
30
31     public static final int CAN_SEND_DATA_SUB_CATEGORY_ID = 1;
32     public static final String CAN_SEND_DATA_SUB_CATEGORY_HEADER = "uprawnienia do przesyƂu danych";
33     private static final String DARK_SUFIX = "_dark";
34     private static final String DISABLE_SUFIX = "_disable";
35     private static int mIdGenerator = 2;
36
37     private int mSubcatId;
38     private String mHeader;
39     private String mDescription;
40     private int mIconRes;
41     private Drawable mIconDrawable;
42     private Drawable mIconDarkDrawable;
43     private Drawable mIconDisabledDrawable;
44     private ArrayList<String> mPermissions;
45
46     public Subcategory(Context context, String header, String description,
47             String icon, ArrayList<String> permissions) {
48         mHeader = header;
49         mDescription = description;
50         if (mHeader.equals(CAN_SEND_DATA_SUB_CATEGORY_HEADER)) {
51             mSubcatId = CAN_SEND_DATA_SUB_CATEGORY_ID;
52         } else {
53             mSubcatId = mIdGenerator;
54             mIdGenerator = mIdGenerator << 1;
55         }
56
57         String packageName = context.getPackageName();
58         mIconRes = context.getResources().getIdentifier(icon, "drawable",
59                 packageName);
60         mIconDrawable = context.getResources().getDrawable(mIconRes);
61
62         int iconDarkRes = context.getResources().getIdentifier(
63                 icon.concat(DARK_SUFIX), "drawable", packageName);
64         try {
65             mIconDarkDrawable = context.getResources().getDrawable(iconDarkRes);
66         } catch (NotFoundException ex) {
67             mIconDarkDrawable = mIconDrawable;
68         }
69         
70         int iconDisableRes = context.getResources().getIdentifier(icon.concat(DISABLE_SUFIX), "drawable", packageName);
71         try {
72             mIconDisabledDrawable = context.getResources().getDrawable(iconDisableRes);
73         } catch (NotFoundException ex) {
74             mIconDisabledDrawable = mIconDrawable;
75         }
76         
77         mPermissions = permissions;
78     }
79
80     public ArrayList<String> getPermissions() {
81         return mPermissions;
82     }
83
84     public int getId() {
85         return mSubcatId;
86     }
87
88     public String getHeader() {
89         return mHeader;
90     }
91
92     public Drawable getIconDrawable() {
93         return mIconDrawable;
94     }
95
96     public Drawable getDarkIcon() {
97         return mIconDarkDrawable;
98     }
99     
100     public Drawable getDisabledIcon() {
101         return mIconDisabledDrawable;
102     }
103
104     public String getDescription() {
105         return mDescription;
106     }
107
108     public static void resetGenerator() {
109         mIdGenerator = 2;
110     }
111
112 }