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. It can be used for 23 * both Email Apps (group Parent item) and Accounts (Group child Item). 24 */ 25 public class BluetoothMapAccountItem implements Comparable<BluetoothMapAccountItem> { 26 private static final String TAG = "BluetoothMapAccountItem"; 27 28 protected boolean mIsChecked; 29 private final String mName; 30 private final String mPackageName; 31 private final String mId; 32 private final String mProviderAuthority; 33 private final Drawable mIcon; 34 private final BluetoothMapUtils.TYPE mType; 35 public final String mBase_uri; 36 public final String mBase_uri_no_account; 37 private final String mUci; 38 private final String mUciPrefix; 39 BluetoothMapAccountItem( String id, String name, String packageName, String authority, Drawable icon, BluetoothMapUtils.TYPE appType, String uci, String uciPrefix)40 private BluetoothMapAccountItem( 41 String id, 42 String name, 43 String packageName, 44 String authority, 45 Drawable icon, 46 BluetoothMapUtils.TYPE appType, 47 String uci, 48 String uciPrefix) { 49 this.mName = name; 50 this.mIcon = icon; 51 this.mPackageName = packageName; 52 this.mId = id; 53 this.mProviderAuthority = authority; 54 this.mType = appType; 55 this.mBase_uri_no_account = "content://" + authority; 56 this.mBase_uri = mBase_uri_no_account + "/" + id; 57 this.mUci = uci; 58 this.mUciPrefix = uciPrefix; 59 } 60 create( String id, String name, String packageName, String authority, Drawable icon, BluetoothMapUtils.TYPE appType)61 public static BluetoothMapAccountItem create( 62 String id, 63 String name, 64 String packageName, 65 String authority, 66 Drawable icon, 67 BluetoothMapUtils.TYPE appType) { 68 return new BluetoothMapAccountItem( 69 id, name, packageName, authority, icon, appType, null, null); 70 } 71 create( String id, String name, String packageName, String authority, Drawable icon, BluetoothMapUtils.TYPE appType, String uci, String uciPrefix)72 public static BluetoothMapAccountItem create( 73 String id, 74 String name, 75 String packageName, 76 String authority, 77 Drawable icon, 78 BluetoothMapUtils.TYPE appType, 79 String uci, 80 String uciPrefix) { 81 return new BluetoothMapAccountItem( 82 id, name, packageName, authority, icon, appType, uci, uciPrefix); 83 } 84 getAccountId()85 public long getAccountId() { 86 if (mId != null) { 87 return Long.parseLong(mId); 88 } 89 return -1; 90 } 91 getUci()92 public String getUci() { 93 return mUci; 94 } 95 getUciPrefix()96 public String getUciPrefix() { 97 return mUciPrefix; 98 } 99 getUciFull()100 public String getUciFull() { 101 if (mUci == null) { 102 return null; 103 } 104 if (mUciPrefix == null) { 105 return null; 106 } 107 return new StringBuilder(mUciPrefix).append(":").append(mUci).toString(); 108 } 109 110 @Override compareTo(BluetoothMapAccountItem other)111 public int compareTo(BluetoothMapAccountItem other) { 112 113 if (!other.mId.equals(this.mId)) { 114 Log.v(TAG, "Wrong id : " + this.mId + " vs " + other.mId); 115 return -1; 116 } 117 if (!other.mName.equals(this.mName)) { 118 Log.v(TAG, "Wrong name : " + this.mName + " vs " + other.mName); 119 return -1; 120 } 121 if (!other.mPackageName.equals(this.mPackageName)) { 122 Log.v(TAG, "Wrong packageName : " + this.mPackageName + " vs " + other.mPackageName); 123 return -1; 124 } 125 if (!other.mProviderAuthority.equals(this.mProviderAuthority)) { 126 Log.v( 127 TAG, 128 "Wrong providerName : " 129 + this.mProviderAuthority 130 + " vs " 131 + other.mProviderAuthority); 132 return -1; 133 } 134 if (other.mIsChecked != this.mIsChecked) { 135 Log.v(TAG, "Wrong isChecked : " + this.mIsChecked + " vs " + other.mIsChecked); 136 return -1; 137 } 138 if (!other.mType.equals(this.mType)) { 139 Log.v(TAG, "Wrong appType : " + this.mType + " vs " + other.mType); 140 return -1; 141 } 142 return 0; 143 } 144 145 @Override hashCode()146 public int hashCode() { 147 final int prime = 31; 148 int result = 1; 149 result = prime * result + ((mId == null) ? 0 : mId.hashCode()); 150 result = prime * result + ((mName == null) ? 0 : mName.hashCode()); 151 result = prime * result + ((mPackageName == null) ? 0 : mPackageName.hashCode()); 152 result = 153 prime * result + ((mProviderAuthority == null) ? 0 : mProviderAuthority.hashCode()); 154 return result; 155 } 156 157 @Override equals(Object obj)158 public boolean equals(Object obj) { 159 if (this == obj) { 160 return true; 161 } 162 if (obj == null) { 163 return false; 164 } 165 if (getClass() != obj.getClass()) { 166 return false; 167 } 168 BluetoothMapAccountItem other = (BluetoothMapAccountItem) obj; 169 if (mId == null) { 170 if (other.mId != null) { 171 return false; 172 } 173 } else if (!mId.equals(other.mId)) { 174 return false; 175 } 176 if (mName == null) { 177 if (other.mName != null) { 178 return false; 179 } 180 } else if (!mName.equals(other.mName)) { 181 return false; 182 } 183 if (mPackageName == null) { 184 if (other.mPackageName != null) { 185 return false; 186 } 187 } else if (!mPackageName.equals(other.mPackageName)) { 188 return false; 189 } 190 if (mProviderAuthority == null) { 191 if (other.mProviderAuthority != null) { 192 return false; 193 } 194 } else if (!mProviderAuthority.equals(other.mProviderAuthority)) { 195 return false; 196 } 197 if (mType == null) { 198 if (other.mType != null) { 199 return false; 200 } 201 } else if (!mType.equals(other.mType)) { 202 return false; 203 } 204 return true; 205 } 206 207 @Override toString()208 public String toString() { 209 return mName + " (" + mBase_uri + ")"; 210 } 211 getIcon()212 public Drawable getIcon() { 213 return mIcon; 214 } 215 getName()216 public String getName() { 217 return mName; 218 } 219 getId()220 public String getId() { 221 return mId; 222 } 223 getPackageName()224 public String getPackageName() { 225 return mPackageName; 226 } 227 getProviderAuthority()228 public String getProviderAuthority() { 229 return mProviderAuthority; 230 } 231 getType()232 public BluetoothMapUtils.TYPE getType() { 233 return mType; 234 } 235 } 236