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.class.getSimpleName(); 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 mUciPrefix + ":" + mUci; 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 instanceof BluetoothMapAccountItem other)) { 163 return false; 164 } 165 if (mId == null) { 166 if (other.mId != null) { 167 return false; 168 } 169 } else if (!mId.equals(other.mId)) { 170 return false; 171 } 172 if (mName == null) { 173 if (other.mName != null) { 174 return false; 175 } 176 } else if (!mName.equals(other.mName)) { 177 return false; 178 } 179 if (mPackageName == null) { 180 if (other.mPackageName != null) { 181 return false; 182 } 183 } else if (!mPackageName.equals(other.mPackageName)) { 184 return false; 185 } 186 if (mProviderAuthority == null) { 187 if (other.mProviderAuthority != null) { 188 return false; 189 } 190 } else if (!mProviderAuthority.equals(other.mProviderAuthority)) { 191 return false; 192 } 193 if (mType == null) { 194 if (other.mType != null) { 195 return false; 196 } 197 } else if (!mType.equals(other.mType)) { 198 return false; 199 } 200 return true; 201 } 202 203 @Override toString()204 public String toString() { 205 return mName + " (" + mBase_uri + ")"; 206 } 207 getIcon()208 public Drawable getIcon() { 209 return mIcon; 210 } 211 getName()212 public String getName() { 213 return mName; 214 } 215 getId()216 public String getId() { 217 return mId; 218 } 219 getPackageName()220 public String getPackageName() { 221 return mPackageName; 222 } 223 getProviderAuthority()224 public String getProviderAuthority() { 225 return mProviderAuthority; 226 } 227 getType()228 public BluetoothMapUtils.TYPE getType() { 229 return mType; 230 } 231 } 232