2 * Copyright (C) 2012 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.cyanogenmod.filemanager.model;
19 import android.content.ContentResolver;
20 import android.net.Uri;
21 import com.cyanogenmod.filemanager.R;
22 import com.cyanogenmod.filemanager.util.FileHelper;
25 import java.io.Serializable;
26 import java.util.Date;
29 * A class that represents an abstract file system object.
36 public abstract class FileSystemObject implements Serializable, Comparable<FileSystemObject> {
38 private static final long serialVersionUID = -571144166609728391L;
40 //Resource identifier for default icon
41 private static final int RESOURCE_ICON_DEFAULT = R.drawable.ic_fso_default;
43 private int mResourceIconId;
45 private String mParent;
48 private Permissions mPermissions;
50 private Date mLastAccessedTime;
51 private Date mLastModifiedTime;
52 private Date mLastChangedTime;
53 private boolean mIsSecure;
54 private boolean mIsRemote;
57 * Constructor of <code>FileSystemObject</code>.
59 * @param name The name of the object
60 * @param parent The parent folder of the object
61 * @param user The user proprietary of the object
62 * @param group The group proprietary of the object
63 * @param permissions The permissions of the object
64 * @param size The size in bytes of the object
65 * @param lastAccessedTime The last time that the object was accessed
66 * @param lastModifiedTime The last time that the object was modified
67 * @param lastChangedTime The last time that the object was changed
69 public FileSystemObject(String name, String parent, User user, Group group,
70 Permissions permissions, long size,
71 Date lastAccessedTime, Date lastModifiedTime, Date lastChangedTime) {
74 this.mParent = parent;
77 this.mPermissions = permissions;
79 this.mLastAccessedTime = lastAccessedTime;
80 this.mLastModifiedTime = lastModifiedTime;
81 this.mLastChangedTime = lastChangedTime;
82 this.mResourceIconId = RESOURCE_ICON_DEFAULT;
83 this.mIsSecure = false;
84 this.mIsRemote = false;
88 * Method that returns the character that identifies the object in unix.
90 * @return char The character that identifies the object in unix
92 public abstract char getUnixIdentifier();
95 * Method that returns the name of the object.
97 * @return String The name of the object
99 public String getName() {
104 * Method that sets the name of the object.
106 * @param name The name to set
108 public void setName(String name) {
113 * Method that returns the parent folder of the object.
115 * @return String The parent folder of the object
117 public String getParent() {
122 * Method that sets the parent folder of the object.
124 * @param parent The parent folder of the object
126 public void setParent(String parent) {
127 this.mParent = parent;
131 * Method that returns the user proprietary of the object.
133 * @return User The user proprietary of the object
135 public User getUser() {
140 * Method that sets the user proprietary of the object.
142 * @param user The user proprietary of the object
144 public void setUser(User user) {
149 * Method that returns the group proprietary of the object.
151 * @return Group The group proprietary of the object
153 public Group getGroup() {
158 * Method that sets the group proprietary of the object.
160 * @param group The group proprietary of the object
162 public void setGroup(Group group) {
167 * Method that returns the permissions of the object.
169 * @return Permissions The permissions of the object
171 public Permissions getPermissions() {
172 return this.mPermissions;
176 * Method that sets the permissions of the object.
178 * @param permissions The permissions of the object
180 public void setPermissions(Permissions permissions) {
181 this.mPermissions = permissions;
185 * Method that returns the size in bytes of the object.
187 * @return long The size in bytes of the object
189 public long getSize() {
194 * Method that sets the size in bytes of the object.
196 * @param size The size in bytes of the object
198 public void setSize(long size) {
203 * Method that returns the last time that the object was accessed.
205 * @return Date The last time that the object was accessed
207 public Date getLastAccessedTime() {
208 return this.mLastAccessedTime;
212 * Method that sets the last time that the object was accessed.
214 * @param lastAccessedTime The last time that the object was accessed
216 public void setLastAccessedTime(Date lastAccessedTime) {
217 this.mLastAccessedTime = lastAccessedTime;
221 * Method that returns the last time that the object was modified.
223 * @return Date The last time that the object was modified
225 public Date getLastModifiedTime() {
226 return this.mLastModifiedTime;
230 * Method that sets the last time that the object was modified.
232 * @param lastModifiedTime The last time that the object was modified
234 public void setLastModifiedTime(Date lastModifiedTime) {
235 this.mLastModifiedTime = lastModifiedTime;
239 * Method that returns the last time that the object was changed.
241 * @return Date The last time that the object was changed
243 public Date getLastChangedTime() {
244 return this.mLastChangedTime;
248 * Method that sets the last time that the object was changed.
250 * @param lastChangedTime The last time that the object was changed
252 public void setLastChangedTime(Date lastChangedTime) {
253 this.mLastChangedTime = lastChangedTime;
257 * Method that returns if the object is hidden object.
259 * @return boolean If the object is hidden object
261 public boolean isHidden() {
262 return this.mName.startsWith("."); //$NON-NLS-1$
266 * Method that returns if the object is secure
268 * @return boolean If the object is secure
270 public boolean isSecure() {
275 * Mehtod that sets if the object is secure
277 * @param secure if the object is secure
279 public void setSecure(boolean secure) {
284 * Method that returns if the object is remote
286 * @return boolean If the object is remote
288 public boolean isRemote() {
293 * Mehtod that sets if the object is remote
295 * @param remote if the object is remote
297 public void setRemote(boolean remote) {
302 * Method that returns the identifier of the drawable icon associated
305 * @return int The identifier of the drawable icon
308 public int getResourceIconId() {
309 return this.mResourceIconId;
313 * Method that sets the identifier of the drawable icon associated
316 * @param resourceIconId The identifier of the drawable icon
319 protected void setResourceIconId(int resourceIconId) {
320 this.mResourceIconId = resourceIconId;
324 * Method that returns the full path of the file system object.
326 * @return String The full path of the file system object
328 public String getFullPath() {
329 if (FileHelper.isRootDirectory(this)) {
330 return FileHelper.ROOT_DIRECTORY;
331 } else if (FileHelper.isParentRootDirectory(this)) {
332 if (this.mParent == null) {
333 return FileHelper.ROOT_DIRECTORY + this.mName;
335 return this.mParent + this.mName;
337 return this.mParent + File.separator + this.mName;
341 * creates a file uri that references this FileSystemObject
344 public Uri getFileUri() {
345 Uri uri = new Uri.Builder()
346 .scheme(ContentResolver.SCHEME_FILE)
357 public int compareTo(FileSystemObject another) {
358 String o1 = this.getFullPath();
359 String o2 = another.getFullPath();
360 return o1.compareTo(o2);
367 public int hashCode() {
368 final int prime = 31;
370 result = prime * result + ((this.mName == null) ? 0 : this.mName.hashCode());
371 result = prime * result + ((this.mParent == null) ? 0 : this.mParent.hashCode());
379 public boolean equals(Object obj) {
384 FileSystemObject other = (FileSystemObject) obj;
385 if (this.mName == null) {
386 if (other.mName != null)
388 } else if (!this.mName.equals(other.mName))
390 if (this.mParent == null) {
391 if (other.mParent != null)
393 } else if (!this.mParent.equals(other.mParent))
399 * Method that returns the unix string representation of the type and permissions of the
400 * file system object.
402 * @return String The string representation
404 public String toRawPermissionString() {
405 return Character.toString(getUnixIdentifier())
406 + getPermissions().toRawString();
413 public String toString() {
414 return "FileSystemObject [mResourceIconId=" + this.mResourceIconId //$NON-NLS-1$
415 + ", mName=" + this.mName + ", mParent=" + this.mParent //$NON-NLS-1$ //$NON-NLS-2$
416 + ", mUser=" + this.mUser + ", mGroup=" + this.mGroup //$NON-NLS-1$ //$NON-NLS-2$
417 + ", mPermissions=" + this.mPermissions //$NON-NLS-1$
418 + ", mSize=" + this.mSize //$NON-NLS-1$
419 + ", mLastAccessedTime=" + this.mLastAccessedTime //$NON-NLS-1$
420 + ", mLastModifiedTime=" + this.mLastModifiedTime //$NON-NLS-1$
421 + ", mLastChangedTime=" + this.mLastChangedTime //$NON-NLS-1$
422 + ", mIsSecure=" + mIsSecure //$NON-NLS-1$
423 + ", mIsRemote=" + mIsRemote //$NON-NLS-1$