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, icon, appType, null,
61                 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, icon, appType, uci,
68                 uciPrefix);
69     }
70 
getAccountId()71     public long getAccountId() {
72         if (mId != null) {
73             return Long.parseLong(mId);
74         }
75         return -1;
76     }
77 
getUci()78     public String getUci() {
79         return mUci;
80     }
81 
getUciPrefix()82     public String getUciPrefix() {
83         return mUciPrefix;
84     }
85 
getUciFull()86     public String getUciFull() {
87         if (mUci == null) {
88             return null;
89         }
90         if (mUciPrefix == null) {
91             return null;
92         }
93         return new StringBuilder(mUciPrefix).append(":").append(mUci).toString();
94     }
95 
96     @Override
compareTo(BluetoothMapAccountItem other)97     public int compareTo(BluetoothMapAccountItem other) {
98 
99         if (!other.mId.equals(this.mId)) {
100             if (V) {
101                 Log.d(TAG, "Wrong id : " + this.mId + " vs " + other.mId);
102             }
103             return -1;
104         }
105         if (!other.mName.equals(this.mName)) {
106             if (V) {
107                 Log.d(TAG, "Wrong name : " + this.mName + " vs " + other.mName);
108             }
109             return -1;
110         }
111         if (!other.mPackageName.equals(this.mPackageName)) {
112             if (V) {
113                 Log.d(TAG,
114                         "Wrong packageName : " + this.mPackageName + " vs " + other.mPackageName);
115             }
116             return -1;
117         }
118         if (!other.mProviderAuthority.equals(this.mProviderAuthority)) {
119             if (V) {
120                 Log.d(TAG, "Wrong providerName : " + this.mProviderAuthority + " vs "
121                         + other.mProviderAuthority);
122             }
123             return -1;
124         }
125         if (other.mIsChecked != this.mIsChecked) {
126             if (V) {
127                 Log.d(TAG, "Wrong isChecked : " + this.mIsChecked + " vs " + other.mIsChecked);
128             }
129             return -1;
130         }
131         if (!other.mType.equals(this.mType)) {
132             if (V) {
133                 Log.d(TAG, "Wrong appType : " + this.mType + " vs " + other.mType);
134             }
135             return -1;
136         }
137         return 0;
138     }
139 
140     @Override
hashCode()141     public int hashCode() {
142         final int prime = 31;
143         int result = 1;
144         result = prime * result + ((mId == null) ? 0 : mId.hashCode());
145         result = prime * result + ((mName == null) ? 0 : mName.hashCode());
146         result = prime * result + ((mPackageName == null) ? 0 : mPackageName.hashCode());
147         result =
148                 prime * result + ((mProviderAuthority == null) ? 0 : mProviderAuthority.hashCode());
149         return result;
150     }
151 
152     @Override
equals(Object obj)153     public boolean equals(Object obj) {
154         if (this == obj) {
155             return true;
156         }
157         if (obj == null) {
158             return false;
159         }
160         if (getClass() != obj.getClass()) {
161             return false;
162         }
163         BluetoothMapAccountItem other = (BluetoothMapAccountItem) obj;
164         if (mId == null) {
165             if (other.mId != null) {
166                 return false;
167             }
168         } else if (!mId.equals(other.mId)) {
169             return false;
170         }
171         if (mName == null) {
172             if (other.mName != null) {
173                 return false;
174             }
175         } else if (!mName.equals(other.mName)) {
176             return false;
177         }
178         if (mPackageName == null) {
179             if (other.mPackageName != null) {
180                 return false;
181             }
182         } else if (!mPackageName.equals(other.mPackageName)) {
183             return false;
184         }
185         if (mProviderAuthority == null) {
186             if (other.mProviderAuthority != null) {
187                 return false;
188             }
189         } else if (!mProviderAuthority.equals(other.mProviderAuthority)) {
190             return false;
191         }
192         if (mType == null) {
193             if (other.mType != null) {
194                 return false;
195             }
196         } else if (!mType.equals(other.mType)) {
197             return false;
198         }
199         return true;
200     }
201 
202     @Override
toString()203     public String toString() {
204         return mName + " (" + mBase_uri + ")";
205     }
206 
getIcon()207     public Drawable getIcon() {
208         return mIcon;
209     }
210 
getName()211     public String getName() {
212         return mName;
213     }
214 
getId()215     public String getId() {
216         return mId;
217     }
218 
getPackageName()219     public String getPackageName() {
220         return mPackageName;
221     }
222 
getProviderAuthority()223     public String getProviderAuthority() {
224         return mProviderAuthority;
225     }
226 
getType()227     public BluetoothMapUtils.TYPE getType() {
228         return mType;
229     }
230 
231 }
232