1 package com.android.gallery3d.ingest.data; 2 3 import android.annotation.TargetApi; 4 import android.mtp.MtpDevice; 5 import android.mtp.MtpObjectInfo; 6 import android.os.Build; 7 8 /** 9 * Holds the info needed for the in-memory index of MTP objects. 10 */ 11 @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) 12 public class IngestObjectInfo implements Comparable<IngestObjectInfo> { 13 14 private int mHandle; 15 private long mDateCreated; 16 private int mFormat; 17 private int mCompressedSize; 18 19 public IngestObjectInfo(MtpObjectInfo mtpObjectInfo) { 20 mHandle = mtpObjectInfo.getObjectHandle(); 21 mDateCreated = mtpObjectInfo.getDateCreated(); 22 mFormat = mtpObjectInfo.getFormat(); 23 mCompressedSize = mtpObjectInfo.getCompressedSize(); 24 } 25 26 public IngestObjectInfo(int handle, long dateCreated, int format, int compressedSize) { 27 mHandle = handle; 28 mDateCreated = dateCreated; 29 mFormat = format; 30 mCompressedSize = compressedSize; 31 } 32 33 public int getCompressedSize() { 34 return mCompressedSize; 35 } 36 37 public int getFormat() { 38 return mFormat; 39 } 40 41 public long getDateCreated() { 42 return mDateCreated; 43 } 44 45 public int getObjectHandle() { 46 return mHandle; 47 } 48 49 public String getName(MtpDevice device) { 50 if (device != null) { 51 MtpObjectInfo info = device.getObjectInfo(mHandle); 52 if (info != null) { 53 return info.getName(); 54 } 55 } 56 return null; 57 } 58 59 @Override 60 public int compareTo(IngestObjectInfo another) { 61 long diff = getDateCreated() - another.getDateCreated(); 62 if (diff < 0) { 63 return -1; 64 } else if (diff == 0) { 65 return 0; 66 } else { 67 return 1; 68 } 69 } 70 71 @Override 72 public String toString() { 73 return "IngestObjectInfo [mHandle=" + mHandle + ", mDateCreated=" + mDateCreated 74 + ", mFormat=" + mFormat + ", mCompressedSize=" + mCompressedSize + "]"; 75 } 76 77 @Override 78 public int hashCode() { 79 final int prime = 31; 80 int result = 1; 81 result = prime * result + mCompressedSize; 82 result = prime * result + (int) (mDateCreated ^ (mDateCreated >>> 32)); 83 result = prime * result + mFormat; 84 result = prime * result + mHandle; 85 return result; 86 } 87 88 @Override 89 public boolean equals(Object obj) { 90 if (this == obj) { 91 return true; 92 } 93 if (obj == null) { 94 return false; 95 } 96 if (!(obj instanceof IngestObjectInfo)) { 97 return false; 98 } 99 IngestObjectInfo other = (IngestObjectInfo) obj; 100 if (mCompressedSize != other.mCompressedSize) { 101 return false; 102 } 103 if (mDateCreated != other.mDateCreated) { 104 return false; 105 } 106 if (mFormat != other.mFormat) { 107 return false; 108 } 109 if (mHandle != other.mHandle) { 110 return false; 111 } 112 return true; 113 } 114 } 115