Merge "Add FLAG_PARTIAL. Partial files can't be copied." into nyc-dev
This commit is contained in:
@@ -379,8 +379,18 @@ public final class DocumentsContract {
|
||||
* @see DocumentsProvider#queryChildDocuments(String, String[], String)
|
||||
* @hide
|
||||
*/
|
||||
|
||||
public static final int FLAG_ARCHIVE = 1 << 15;
|
||||
|
||||
/**
|
||||
* Flag indicating that a document is not complete, likely its
|
||||
* contents are being downloaded. Partial files cannot be opened,
|
||||
* copied, moved in the UI. But they can be deleted and retried
|
||||
* if they represent a failed download.
|
||||
*
|
||||
* @see #COLUMN_FLAGS
|
||||
* @hide
|
||||
*/
|
||||
public static final int FLAG_PARTIAL = 1 << 16;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -440,6 +440,7 @@ public class DirectoryFragment extends Fragment
|
||||
|
||||
private Selection mSelected = new Selection();
|
||||
private ActionMode mActionMode;
|
||||
private int mNoCopyCount = 0;
|
||||
private int mNoDeleteCount = 0;
|
||||
private int mNoRenameCount = -1;
|
||||
private Menu mMenu;
|
||||
@@ -471,6 +472,9 @@ public class DirectoryFragment extends Fragment
|
||||
// triggered on "silent" selection updates (i.e. we might be reacting to unfinalized
|
||||
// selection changes here)
|
||||
final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
|
||||
if ((docFlags & Document.FLAG_PARTIAL) != 0) {
|
||||
mNoCopyCount += selected ? 1 : -1;
|
||||
}
|
||||
if ((docFlags & Document.FLAG_SUPPORTS_DELETE) == 0
|
||||
&& (docFlags & Document.FLAG_SUPPORTS_DELETE) == 0) {
|
||||
mNoDeleteCount += selected ? 1 : -1;
|
||||
@@ -537,19 +541,24 @@ public class DirectoryFragment extends Fragment
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean canRenameSelection() {
|
||||
return mNoRenameCount == 0 && mSelectionManager.getSelection().size() == 1;
|
||||
boolean canCopySelection() {
|
||||
return mNoCopyCount == 0;
|
||||
}
|
||||
|
||||
boolean canDeleteSelection() {
|
||||
return mNoDeleteCount == 0;
|
||||
}
|
||||
|
||||
boolean canRenameSelection() {
|
||||
return mNoRenameCount == 0 && mSelectionManager.getSelection().size() == 1;
|
||||
}
|
||||
|
||||
private void updateActionMenu() {
|
||||
assert(mMenu != null);
|
||||
|
||||
// Delegate update logic to our owning action, since specialized logic is desired.
|
||||
mTuner.updateActionMenu(mMenu, mType, canDeleteSelection(), canRenameSelection());
|
||||
mTuner.updateActionMenu(
|
||||
mMenu, mType, canCopySelection(), canDeleteSelection(), canRenameSelection());
|
||||
Menus.disableHiddenItems(mMenu);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,9 +58,9 @@ public abstract class FragmentTuner {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public abstract void updateActionMenu(
|
||||
Menu menu, @ResultType int dirType, boolean canDelete, boolean canRename);
|
||||
Menu menu, @ResultType int dirType,
|
||||
boolean canCopy, boolean canDelete, boolean canRename);
|
||||
|
||||
// Subtly different from isDocumentEnabled. The reason may be illuminated as follows.
|
||||
// A folder is enabled such that it may be double clicked, even in settings
|
||||
@@ -140,7 +140,8 @@ public abstract class FragmentTuner {
|
||||
|
||||
@Override
|
||||
public void updateActionMenu(
|
||||
Menu menu, @ResultType int dirType, boolean canDelete, boolean canRename) {
|
||||
Menu menu, @ResultType int dirType,
|
||||
boolean canCopy, boolean canDelete, boolean canRename) {
|
||||
|
||||
MenuItem open = menu.findItem(R.id.menu_open);
|
||||
MenuItem share = menu.findItem(R.id.menu_share);
|
||||
@@ -198,22 +199,28 @@ public abstract class FragmentTuner {
|
||||
|
||||
@Override
|
||||
public void updateActionMenu(
|
||||
Menu menu, @ResultType int dirType, boolean canDelete, boolean canRename) {
|
||||
Menu menu, @ResultType int dirType,
|
||||
boolean canCopy, boolean canDelete, boolean canRename) {
|
||||
|
||||
MenuItem copy = menu.findItem(R.id.menu_copy_to_clipboard);
|
||||
MenuItem paste = menu.findItem(R.id.menu_paste_from_clipboard);
|
||||
copy.setEnabled(dirType != DirectoryFragment.TYPE_RECENT_OPEN);
|
||||
copy.setEnabled(canCopy);
|
||||
|
||||
MenuItem rename = menu.findItem(R.id.menu_rename);
|
||||
MenuItem moveTo = menu.findItem(R.id.menu_move_to);
|
||||
MenuItem copyTo = menu.findItem(R.id.menu_copy_to);
|
||||
|
||||
copyTo.setVisible(true);
|
||||
moveTo.setVisible(true);
|
||||
rename.setVisible(true);
|
||||
|
||||
copyTo.setEnabled(canCopy);
|
||||
moveTo.setEnabled(canCopy && canDelete);
|
||||
rename.setEnabled(canRename);
|
||||
|
||||
menu.findItem(R.id.menu_share).setVisible(true);
|
||||
menu.findItem(R.id.menu_delete).setVisible(canDelete);
|
||||
menu.findItem(R.id.menu_open).setVisible(false);
|
||||
menu.findItem(R.id.menu_copy_to).setVisible(true);
|
||||
menu.findItem(R.id.menu_move_to).setVisible(true);
|
||||
menu.findItem(R.id.menu_move_to).setEnabled(canDelete);
|
||||
|
||||
Menus.disableHiddenItems(menu, copy, paste);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,6 @@ public class DocumentInfo implements Durable, Parcelable {
|
||||
summary = null;
|
||||
size = -1;
|
||||
icon = 0;
|
||||
|
||||
derivedUri = null;
|
||||
}
|
||||
|
||||
@@ -210,6 +209,7 @@ public class DocumentInfo implements Durable, Parcelable {
|
||||
+ ", isContainer=" + isContainer()
|
||||
+ ", isDirectory=" + isDirectory()
|
||||
+ ", isArchive=" + isArchive()
|
||||
+ ", isPartial=" + isPartial()
|
||||
+ ", isVirtualDocument=" + isVirtualDocument()
|
||||
+ ", isDeleteSupported=" + isDeleteSupported()
|
||||
+ ", isCreateSupported=" + isCreateSupported()
|
||||
@@ -249,6 +249,10 @@ public class DocumentInfo implements Durable, Parcelable {
|
||||
return (flags & Document.FLAG_ARCHIVE) != 0;
|
||||
}
|
||||
|
||||
public boolean isPartial() {
|
||||
return (flags & Document.FLAG_PARTIAL) != 0;
|
||||
}
|
||||
|
||||
public boolean isContainer() {
|
||||
return isDirectory() || isArchive();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user