summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ingest/data/IngestObjectInfo.java
blob: 25273838b7c3a5148620d821634c85cacf36d393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.android.gallery3d.ingest.data;

import android.annotation.TargetApi;
import android.mtp.MtpDevice;
import android.mtp.MtpObjectInfo;
import android.os.Build;

/**
 * Holds the info needed for the in-memory index of MTP objects.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public class IngestObjectInfo implements Comparable<IngestObjectInfo> {

  private int mHandle;
  private long mDateCreated;
  private int mFormat;
  private int mCompressedSize;

  public IngestObjectInfo(MtpObjectInfo mtpObjectInfo) {
    mHandle = mtpObjectInfo.getObjectHandle();
    mDateCreated = mtpObjectInfo.getDateCreated();
    mFormat = mtpObjectInfo.getFormat();
    mCompressedSize = mtpObjectInfo.getCompressedSize();
  }

  public IngestObjectInfo(int handle, long dateCreated, int format, int compressedSize) {
    mHandle = handle;
    mDateCreated = dateCreated;
    mFormat = format;
    mCompressedSize = compressedSize;
  }

  public int getCompressedSize() {
    return mCompressedSize;
  }

  public int getFormat() {
    return mFormat;
  }

  public long getDateCreated() {
    return mDateCreated;
  }

  public int getObjectHandle() {
    return mHandle;
  }

  public String getName(MtpDevice device) {
    if (device != null) {
      MtpObjectInfo info = device.getObjectInfo(mHandle);
      if (info != null) {
        return info.getName();
      }
    }
    return null;
  }

  @Override
  public int compareTo(IngestObjectInfo another) {
    long diff = getDateCreated() - another.getDateCreated();
    if (diff < 0) {
      return -1;
    } else if (diff == 0) {
      return 0;
    } else {
      return 1;
    }
  }

  @Override
  public String toString() {
    return "IngestObjectInfo [mHandle=" + mHandle + ", mDateCreated=" + mDateCreated
        + ", mFormat=" + mFormat + ", mCompressedSize=" + mCompressedSize + "]";
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + mCompressedSize;
    result = prime * result + (int) (mDateCreated ^ (mDateCreated >>> 32));
    result = prime * result + mFormat;
    result = prime * result + mHandle;
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof IngestObjectInfo)) {
      return false;
    }
    IngestObjectInfo other = (IngestObjectInfo) obj;
    if (mCompressedSize != other.mCompressedSize) {
      return false;
    }
    if (mDateCreated != other.mDateCreated) {
      return false;
    }
    if (mFormat != other.mFormat) {
      return false;
    }
    if (mHandle != other.mHandle) {
      return false;
    }
    return true;
  }
}