/* Add the appropriate flags. */
- row.add (Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE);
+ row.add (Root.COLUMN_FLAGS, (Root.FLAG_SUPPORTS_CREATE
+ | Root.FLAG_SUPPORTS_IS_CHILD));
row.add (Root.FLAG_LOCAL_ONLY);
row.add (Root.COLUMN_TITLE, "Emacs");
row.add (Root.COLUMN_DOCUMENT_ID, baseDir.getAbsolutePath ());
return result;
}
+ private Uri
+ getNotificationUri (File file)
+ {
+ Uri updatedUri;
+ Context context;
+
+ context = getContext ();
+ updatedUri
+ = buildChildDocumentsUri ("org.gnu.emacs",
+ file.getAbsolutePath ());
+
+ return updatedUri;
+ }
+
+ /* Inform the system that FILE's contents (or FILE itself) has
+ changed. */
+
+ private void
+ notifyChange (File file)
+ {
+ Uri updatedUri;
+ Context context;
+
+ context = getContext ();
+ updatedUri
+ = buildChildDocumentsUri ("org.gnu.emacs",
+ file.getAbsolutePath ());
+ context.getContentResolver ().notifyChange (updatedUri, null);
+ }
+
/* Return the MIME type of a file FILE. */
private String
{
flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
flags |= Document.FLAG_SUPPORTS_DELETE;
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
+ flags |= Document.FLAG_SUPPORTS_RENAME;
}
}
else if (file.canWrite ())
flags |= Document.FLAG_SUPPORTS_WRITE;
flags |= Document.FLAG_SUPPORTS_DELETE;
- /* TODO: implement these
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
+ flags |= Document.FLAG_SUPPORTS_RENAME;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
- flags |= Document.FLAG_SUPPORTS_RENAME;
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
- flags |= Document.FLAG_SUPPORTS_REMOVE; */
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ flags |= Document.FLAG_SUPPORTS_REMOVE;
}
displayName = file.getName ();
throws FileNotFoundException
{
MatrixCursor result;
+ File file;
+ Context context;
+
+ file = new File (documentId);
+ context = getContext ();
if (projection == null)
projection = DEFAULT_DOCUMENT_PROJECTION;
result = new MatrixCursor (projection);
- queryDocument1 (result, new File (documentId));
+ queryDocument1 (result, file);
+
+ /* Now allow interested applications to detect changes. */
+ result.setNotificationUri (context.getContentResolver (),
+ getNotificationUri (file));
return result;
}
{
MatrixCursor result;
File directory;
+ Context context;
if (projection == null)
projection = DEFAULT_DOCUMENT_PROJECTION;
for (File child : directory.listFiles ())
queryDocument1 (result, child);
+ context = getContext ();
+
+ /* Now allow interested applications to detect changes. */
+ result.setNotificationUri (context.getContentResolver (),
+ getNotificationUri (directory));
+
return result;
}
createDocument (String documentId, String mimeType,
String displayName) throws FileNotFoundException
{
- File file;
+ File file, parentFile;
boolean rc;
- Uri updatedUri;
- Context context;
- context = getContext ();
file = new File (documentId, displayName);
try
throw new FileNotFoundException (e.toString ());
}
- updatedUri
- = buildChildDocumentsUri ("org.gnu.emacs", documentId);
- /* Tell the system about the change. */
- context.getContentResolver ().notifyChange (updatedUri, null);
+ parentFile = file.getParentFile ();
+
+ if (parentFile != null)
+ notifyChange (parentFile);
return file.getAbsolutePath ();
}
{
File file, parent;
File[] children;
- Uri updatedUri;
Context context;
/* Java makes recursively deleting a file hard. File name
throw new RuntimeException ("trying to delete file without"
+ " parent!");
- updatedUri
- = buildChildDocumentsUri ("org.gnu.emacs",
- parent.getAbsolutePath ());
-
if (file.delete ())
{
/* Tell the system about the change. */
- context.getContentResolver ().notifyChange (updatedUri, null);
+ notifyChange (parent);
return;
}
if (file.delete ())
/* Tell the system about the change. */
- context.getContentResolver ().notifyChange (updatedUri, null);
+ notifyChange (parent);
}
@Override
{
deleteDocument (documentId);
}
+
+ @Override
+ public String
+ getDocumentType (String documentId)
+ {
+ return getMimeType (new File (documentId));
+ }
+
+ @Override
+ public String
+ renameDocument (String documentId, String displayName)
+ throws FileNotFoundException
+ {
+ File file, newName;
+ File parent;
+
+ file = new File (documentId);
+ parent = file.getParentFile ();
+ newName = new File (parent, displayName);
+
+ if (parent == null)
+ throw new FileNotFoundException ("parent is null");
+
+ file = new File (documentId);
+
+ if (!file.renameTo (newName))
+ return null;
+
+ notifyChange (parent);
+ return newName.getAbsolutePath ();
+ }
+
+ @Override
+ public boolean
+ isChildDocument (String parentDocumentId, String documentId)
+ {
+ return documentId.startsWith (parentDocumentId);
+ }
}