1 /*
2 * Copyright (C) 2014 Samsung System LSI
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *      http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 
16 package com.android.bluetooth.map;
17 
18 import android.graphics.drawable.Drawable;
19 import android.util.Log;
20 
21 /**
22  * Class to contain all the info about the items of the Map Email Settings Menu.
23  * It can be used for both Email Apps (group Parent item) and Accounts (Group child Item).
24  *
25  */
26 public class BluetoothMapAccountItem implements Comparable<BluetoothMapAccountItem>{
27     private static final String TAG = "BluetoothMapAccountItem";
28 
29     private static final boolean D = BluetoothMapService.DEBUG;
30     private static final boolean V = BluetoothMapService.VERBOSE;
31 
32     protected boolean mIsChecked;
33     private final String mName;
34     private final String mPackageName;
35     private final String mId;
36     private final String mProviderAuthority;
37     private final Drawable mIcon;
38     private final BluetoothMapUtils.TYPE mType;
39     public final String mBase_uri;
40     public final String mBase_uri_no_account;
41     private final String mUci;
42     private final String mUciPrefix;
43 
BluetoothMapAccountItem(String id, String name, String packageName, String authority, Drawable icon, BluetoothMapUtils.TYPE appType, String uci, String uciPrefix)44     public BluetoothMapAccountItem(String id, String name, String packageName, String authority,
45             Drawable icon, BluetoothMapUtils.TYPE appType, String uci, String uciPrefix) {
46         this.mName = name;
47         this.mIcon = icon;
48         this.mPackageName = packageName;
49         this.mId = id;
50         this.mProviderAuthority = authority;
51         this.mType = appType;
52         this.mBase_uri_no_account = "content://" + authority;
53         this.mBase_uri = mBase_uri_no_account + "/"+id;
54         this.mUci = uci;
55         this.mUciPrefix = uciPrefix;
56     }
57 
create(String id, String name, String packageName, String authority, Drawable icon, BluetoothMapUtils.TYPE appType)58     public static BluetoothMapAccountItem create(String id, String name, String packageName,
59             String authority, Drawable icon, BluetoothMapUtils.TYPE appType) {
60         return new BluetoothMapAccountItem(id, name, packageName, authority,
61                 icon, appType, null, null);
62     }
63 
create(String id, String name, String packageName, String authority, Drawable icon, BluetoothMapUtils.TYPE appType, String uci, String uciPrefix)64     public static BluetoothMapAccountItem create(String id, String name, String packageName,
65             String authority, Drawable icon, BluetoothMapUtils.TYPE appType, String uci,
66             String uciPrefix) {
67         return new BluetoothMapAccountItem(id, name, packageName, authority,
68                 icon, appType, uci, uciPrefix);
69     }
getAccountId()70     public long getAccountId() {
71         if(mId != null) {
72             return Long.parseLong(mId);
73         }
74         return -1;
75     }
76 
getUci()77     public String getUci() {
78         return mUci;
79     }
80 
getUciPrefix()81     public String getUciPrefix(){
82         return mUciPrefix;
83     }
84 
getUciFull()85     public String getUciFull(){
86         if(mUci == null)
87             return null;
88         if(mUciPrefix == null)
89             return null;
90         return new StringBuilder(mUciPrefix).append(":").append(mUci).toString();
91     }
92 
93     @Override
compareTo(BluetoothMapAccountItem other)94     public int compareTo(BluetoothMapAccountItem other) {
95 
96         if(!other.mId.equals(this.mId)){
97             if(V) Log.d(TAG, "Wrong id : " + this.mId + " vs " + other.mId);
98             return -1;
99         }
100         if(!other.mName.equals(this.mName)){
101             if(V) Log.d(TAG, "Wrong name : " + this.mName + " vs " + other.mName);
102             return -1;
103         }
104         if(!other.mPackageName.equals(this.mPackageName)){
105             if(V) Log.d(TAG, "Wrong packageName : " + this.mPackageName + " vs "
106                     + other.mPackageName);
107              return -1;
108         }
109         if(!other.mProviderAuthority.equals(this.mProviderAuthority)){
110             if(V) Log.d(TAG, "Wrong providerName : " + this.mProviderAuthority + " vs "
111                     + other.mProviderAuthority);
112             return -1;
113         }
114         if(other.mIsChecked != this.mIsChecked){
115             if(V) Log.d(TAG, "Wrong isChecked : " + this.mIsChecked + " vs " + other.mIsChecked);
116             return -1;
117         }
118         if(!other.mType.equals(this.mType)){
119             if(V) Log.d(TAG, "Wrong appType : " + this.mType + " vs " + other.mType);
120              return -1;
121         }
122         return 0;
123     }
124 
125     @Override
hashCode()126     public int hashCode() {
127         final int prime = 31;
128         int result = 1;
129         result = prime * result + ((mId == null) ? 0 : mId.hashCode());
130         result = prime * result + ((mName == null) ? 0 : mName.hashCode());
131         result = prime * result
132                 + ((mPackageName == null) ? 0 : mPackageName.hashCode());
133         result = prime * result
134                 + ((mProviderAuthority == null) ? 0 : mProviderAuthority.hashCode());
135         return result;
136     }
137 
138     @Override
equals(Object obj)139     public boolean equals(Object obj) {
140         if (this == obj)
141             return true;
142         if (obj == null)
143             return false;
144         if (getClass() != obj.getClass())
145             return false;
146         BluetoothMapAccountItem other = (BluetoothMapAccountItem) obj;
147         if (mId == null) {
148             if (other.mId != null)
149                 return false;
150         } else if (!mId.equals(other.mId))
151             return false;
152         if (mName == null) {
153             if (other.mName != null)
154                 return false;
155         } else if (!mName.equals(other.mName))
156             return false;
157         if (mPackageName == null) {
158             if (other.mPackageName != null)
159                 return false;
160         } else if (!mPackageName.equals(other.mPackageName))
161             return false;
162         if (mProviderAuthority == null) {
163             if (other.mProviderAuthority != null)
164                 return false;
165         } else if (!mProviderAuthority.equals(other.mProviderAuthority))
166             return false;
167         if (mType == null) {
168             if (other.mType != null)
169                 return false;
170         } else if (!mType.equals(other.mType))
171             return false;
172         return true;
173     }
174 
175     @Override
toString()176     public String toString() {
177         return mName + " (" + mBase_uri + ")";
178     }
179 
getIcon()180     public Drawable getIcon() {
181         return mIcon;
182     }
183 
getName()184     public String getName() {
185         return mName;
186     }
187 
getId()188     public String getId() {
189         return mId;
190     }
191 
getPackageName()192     public String getPackageName() {
193         return mPackageName;
194     }
195 
getProviderAuthority()196     public String getProviderAuthority() {
197         return mProviderAuthority;
198     }
199 
getType()200     public BluetoothMapUtils.TYPE getType() {
201         return mType;
202     }
203 
204 }
205