Home | History | Annotate | Download | only in map
      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 BluetoothMapEmailSettingsItem implements Comparable<BluetoothMapEmailSettingsItem>{
     27     private static final String TAG = "BluetoothMapEmailSettingsItem";
     28 
     29     private static final boolean D = BluetoothMapService.DEBUG;
     30     private static final boolean V = BluetoothMapService.VERBOSE;
     31 
     32     protected boolean mIsChecked;
     33     private String mName;
     34     private String mPackageName;
     35     private String mId;
     36     private String mProviderAuthority;
     37     private Drawable mIcon;
     38     public String mBase_uri;
     39     public String mBase_uri_no_account;
     40     public BluetoothMapEmailSettingsItem(String id, String name, String packageName, String authority, Drawable icon) {
     41         this.mName = name;
     42         this.mIcon = icon;
     43         this.mPackageName = packageName;
     44         this.mId = id;
     45         this.mProviderAuthority = authority;
     46         this.mBase_uri_no_account = "content://" + authority;
     47         this.mBase_uri = mBase_uri_no_account + "/"+id;
     48     }
     49 
     50     public long getAccountId() {
     51         if(mId != null) {
     52             return Long.parseLong(mId);
     53         }
     54         return -1;
     55     }
     56 
     57     @Override
     58     public int compareTo(BluetoothMapEmailSettingsItem other) {
     59 
     60         if(!other.mId.equals(this.mId)){
     61             if(V) Log.d(TAG, "Wrong id : " + this.mId + " vs " + other.mId);
     62             return -1;
     63         }
     64         if(!other.mName.equals(this.mName)){
     65             if(V) Log.d(TAG, "Wrong name : " + this.mName + " vs " + other.mName);
     66             return -1;
     67         }
     68         if(!other.mPackageName.equals(this.mPackageName)){
     69             if(V) Log.d(TAG, "Wrong packageName : " + this.mPackageName + " vs " + other.mPackageName);
     70              return -1;
     71         }
     72         if(!other.mProviderAuthority.equals(this.mProviderAuthority)){
     73             if(V) Log.d(TAG, "Wrong providerName : " + this.mProviderAuthority + " vs " + other.mProviderAuthority);
     74             return -1;
     75         }
     76         if(other.mIsChecked != this.mIsChecked){
     77             if(V) Log.d(TAG, "Wrong isChecked : " + this.mIsChecked + " vs " + other.mIsChecked);
     78             return -1;
     79         }
     80         return 0;
     81     }
     82 
     83     @Override
     84     public int hashCode() {
     85         final int prime = 31;
     86         int result = 1;
     87         result = prime * result + ((mId == null) ? 0 : mId.hashCode());
     88         result = prime * result + ((mName == null) ? 0 : mName.hashCode());
     89         result = prime * result
     90                 + ((mPackageName == null) ? 0 : mPackageName.hashCode());
     91         result = prime * result
     92                 + ((mProviderAuthority == null) ? 0 : mProviderAuthority.hashCode());
     93         return result;
     94     }
     95 
     96     @Override
     97     public boolean equals(Object obj) {
     98         if (this == obj)
     99             return true;
    100         if (obj == null)
    101             return false;
    102         if (getClass() != obj.getClass())
    103             return false;
    104         BluetoothMapEmailSettingsItem other = (BluetoothMapEmailSettingsItem) obj;
    105         if (mId == null) {
    106             if (other.mId != null)
    107                 return false;
    108         } else if (!mId.equals(other.mId))
    109             return false;
    110         if (mName == null) {
    111             if (other.mName != null)
    112                 return false;
    113         } else if (!mName.equals(other.mName))
    114             return false;
    115         if (mPackageName == null) {
    116             if (other.mPackageName != null)
    117                 return false;
    118         } else if (!mPackageName.equals(other.mPackageName))
    119             return false;
    120         if (mProviderAuthority == null) {
    121             if (other.mProviderAuthority != null)
    122                 return false;
    123         } else if (!mProviderAuthority.equals(other.mProviderAuthority))
    124             return false;
    125         return true;
    126     }
    127 
    128     @Override
    129     public String toString() {
    130         return mName + " (" + mBase_uri + ")";
    131     }
    132 
    133     public Drawable getIcon() {
    134         return mIcon;
    135     }
    136 
    137     public void setIcon(Drawable icon) {
    138         this.mIcon = icon;
    139     }
    140 
    141     public String getName() {
    142         return mName;
    143     }
    144 
    145     public void setName(String name) {
    146         this.mName = name;
    147     }
    148 
    149     public String getId() {
    150         return mId;
    151     }
    152 
    153     public void setId(String id) {
    154         this.mId = id;
    155     }
    156 
    157     public String getPackageName() {
    158         return mPackageName;
    159     }
    160 
    161     public void setPackageName(String packageName) {
    162         this.mPackageName = packageName;
    163     }
    164 
    165     public String getProviderAuthority() {
    166         return mProviderAuthority;
    167     }
    168 
    169     public void setProviderAuthority(String providerAuthority) {
    170         this.mProviderAuthority = providerAuthority;
    171     }
    172 }