package com.android.documentsui;
import static com.android.documentsui.DocumentsActivity.TAG;
-import static com.android.documentsui.DocumentsActivity.DisplayState.ACTION_MANAGE;
-import static com.android.documentsui.DocumentsActivity.DisplayState.MODE_GRID;
-import static com.android.documentsui.DocumentsActivity.DisplayState.MODE_LIST;
+import static com.android.documentsui.DocumentsActivity.State.ACTION_MANAGE;
+import static com.android.documentsui.DocumentsActivity.State.MODE_GRID;
+import static com.android.documentsui.DocumentsActivity.State.MODE_LIST;
import static com.android.documentsui.model.DocumentInfo.getCursorInt;
import static com.android.documentsui.model.DocumentInfo.getCursorLong;
import static com.android.documentsui.model.DocumentInfo.getCursorString;
import android.widget.TextView;
import android.widget.Toast;
-import com.android.documentsui.DocumentsActivity.DisplayState;
+import com.android.documentsui.DocumentsActivity.State;
import com.android.documentsui.model.DocumentInfo;
import com.android.internal.util.Predicate;
import com.google.android.collect.Lists;
mCallbacks = new LoaderCallbacks<DirectoryResult>() {
@Override
public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
- final DisplayState state = getDisplayState(DirectoryFragment.this);
+ final State state = getDisplayState(DirectoryFragment.this);
Uri contentsUri;
if (mType == TYPE_NORMAL) {
}
public void updateDisplayState() {
- final DisplayState state = getDisplayState(this);
+ final State state = getDisplayState(this);
if (mLastSortOrder != state.sortOrder) {
getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- final DisplayState state = getDisplayState(DirectoryFragment.this);
+ final State state = getDisplayState(DirectoryFragment.this);
final MenuItem open = menu.findItem(R.id.menu_open);
final MenuItem share = menu.findItem(R.id.menu_share);
final int id = item.getItemId();
if (id == R.id.menu_open) {
DocumentsActivity.get(DirectoryFragment.this).onDocumentsPicked(docs);
+ mode.finish();
return true;
} else if (id == R.id.menu_share) {
onShareDocuments(docs);
+ mode.finish();
return true;
} else if (id == R.id.menu_delete) {
onDeleteDocuments(docs);
+ mode.finish();
return true;
} else {
};
private void onShareDocuments(List<DocumentInfo> docs) {
- final ArrayList<Uri> uris = Lists.newArrayList();
- for (DocumentInfo doc : docs) {
- uris.add(doc.uri);
- }
+ Intent intent;
+ if (docs.size() == 1) {
+ final DocumentInfo doc = docs.get(0);
+
+ intent = new Intent(Intent.ACTION_SEND);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ intent.addCategory(Intent.CATEGORY_DEFAULT);
+ intent.setType(doc.mimeType);
+ intent.putExtra(Intent.EXTRA_STREAM, doc.uri);
- final Intent intent;
- if (uris.size() > 1) {
+ } else if (docs.size() > 1) {
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addCategory(Intent.CATEGORY_DEFAULT);
- // TODO: find common mimetype
- intent.setType("*/*");
+
+ final ArrayList<String> mimeTypes = Lists.newArrayList();
+ final ArrayList<Uri> uris = Lists.newArrayList();
+ for (DocumentInfo doc : docs) {
+ mimeTypes.add(doc.mimeType);
+ uris.add(doc.uri);
+ }
+
+ intent.setType(findCommonMimeType(mimeTypes));
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
+
} else {
- intent = new Intent(Intent.ACTION_SEND);
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.addCategory(Intent.CATEGORY_DEFAULT);
- intent.setData(uris.get(0));
+ return;
}
+ intent = Intent.createChooser(intent, getActivity().getText(R.string.share_via));
startActivity(intent);
}
}
}
- private static DisplayState getDisplayState(Fragment fragment) {
+ private static State getDisplayState(Fragment fragment) {
return ((DocumentsActivity) fragment.getActivity()).getDisplayState();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Context context = parent.getContext();
- final DisplayState state = getDisplayState(DirectoryFragment.this);
+ final State state = getDisplayState(DirectoryFragment.this);
final RootsCache roots = DocumentsApplication.getRootsCache(context);
final ThumbnailCache thumbs = DocumentsApplication.getThumbnailsCache(
return DateUtils.formatDateTime(context, when, flags);
}
+
+ private String findCommonMimeType(List<String> mimeTypes) {
+ String[] commonType = mimeTypes.get(0).split("/");
+ if (commonType.length != 2) {
+ return "*/*";
+ }
+
+ for (int i = 1; i < mimeTypes.size(); i++) {
+ String[] type = mimeTypes.get(i).split("/");
+ if (type.length != 2) continue;
+
+ if (!commonType[1].equals(type[1])) {
+ commonType[1] = "*";
+ }
+
+ if (!commonType[0].equals(type[0])) {
+ commonType[0] = "*";
+ commonType[1] = "*";
+ break;
+ }
+ }
+
+ return commonType[0] + "/" + commonType[1];
+ }
}
package com.android.documentsui;
-import static com.android.documentsui.DocumentsActivity.DisplayState.ACTION_CREATE;
-import static com.android.documentsui.DocumentsActivity.DisplayState.ACTION_GET_CONTENT;
-import static com.android.documentsui.DocumentsActivity.DisplayState.ACTION_MANAGE;
-import static com.android.documentsui.DocumentsActivity.DisplayState.ACTION_OPEN;
-import static com.android.documentsui.DocumentsActivity.DisplayState.MODE_GRID;
-import static com.android.documentsui.DocumentsActivity.DisplayState.MODE_LIST;
-import static com.android.documentsui.DocumentsActivity.DisplayState.SORT_ORDER_LAST_MODIFIED;
+import static com.android.documentsui.DocumentsActivity.State.ACTION_CREATE;
+import static com.android.documentsui.DocumentsActivity.State.ACTION_GET_CONTENT;
+import static com.android.documentsui.DocumentsActivity.State.ACTION_MANAGE;
+import static com.android.documentsui.DocumentsActivity.State.ACTION_OPEN;
+import static com.android.documentsui.DocumentsActivity.State.MODE_GRID;
+import static com.android.documentsui.DocumentsActivity.State.MODE_LIST;
+import static com.android.documentsui.DocumentsActivity.State.SORT_ORDER_LAST_MODIFIED;
import android.app.ActionBar;
import android.app.ActionBar.OnNavigationListener;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Parcel;
import android.provider.DocumentsContract;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import com.android.documentsui.model.DocumentInfo;
import com.android.documentsui.model.DocumentStack;
+import com.android.documentsui.model.DurableUtils;
import com.android.documentsui.model.RootInfo;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class DocumentsActivity extends Activity {
public static final String TAG = "Documents";
- private int mAction;
-
private SearchView mSearchView;
private View mRootsContainer;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
- private final DisplayState mDisplayState = new DisplayState();
+ private static final String EXTRA_STATE = "state";
private RootsCache mRoots;
-
- /** Current user navigation stack; empty implies recents. */
- private DocumentStack mStack = new DocumentStack();
- /** Currently active search, overriding any stack. */
- private String mCurrentSearch;
+ private State mState;
@Override
public void onCreate(Bundle icicle) {
mRoots = DocumentsApplication.getRootsCache(this);
- final Intent intent = getIntent();
- final String action = intent.getAction();
- if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) {
- mAction = ACTION_OPEN;
- } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) {
- mAction = ACTION_CREATE;
- } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
- mAction = ACTION_GET_CONTENT;
- } else if (DocumentsContract.ACTION_MANAGE_DOCUMENTS.equals(action)) {
- mAction = ACTION_MANAGE;
- }
+ setResult(Activity.RESULT_CANCELED);
+ setContentView(R.layout.activity);
- // TODO: unify action in single place
- mDisplayState.action = mAction;
+ mRootsContainer = findViewById(R.id.container_roots);
- if (mAction == ACTION_OPEN || mAction == ACTION_GET_CONTENT) {
- mDisplayState.allowMultiple = intent.getBooleanExtra(
- Intent.EXTRA_ALLOW_MULTIPLE, false);
- }
+ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
- if (mAction == ACTION_MANAGE) {
- mDisplayState.acceptMimes = new String[] { "*/*" };
- mDisplayState.allowMultiple = true;
- } else if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) {
- mDisplayState.acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES);
+ mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
+ R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);
+
+ mDrawerLayout.setDrawerListener(mDrawerListener);
+ mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
+
+ if (icicle != null) {
+ mState = icicle.getParcelable(EXTRA_STATE);
} else {
- mDisplayState.acceptMimes = new String[] { intent.getType() };
+ buildDefaultState();
}
- mDisplayState.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false);
-
- setResult(Activity.RESULT_CANCELED);
- setContentView(R.layout.activity);
+ if (mState.action == ACTION_MANAGE) {
+ mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+ }
- if (mAction == ACTION_CREATE) {
+ if (mState.action == ACTION_CREATE) {
final String mimeType = getIntent().getType();
final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE);
SaveFragment.show(getFragmentManager(), mimeType, title);
}
- if (mAction == ACTION_GET_CONTENT) {
+ if (mState.action == ACTION_GET_CONTENT) {
final Intent moreApps = new Intent(getIntent());
moreApps.setComponent(null);
moreApps.setPackage(null);
RootsFragment.show(getFragmentManager(), moreApps);
- } else if (mAction == ACTION_OPEN || mAction == ACTION_CREATE) {
+ } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) {
RootsFragment.show(getFragmentManager(), null);
}
- if (mAction == ACTION_MANAGE) {
- mDisplayState.sortOrder = SORT_ORDER_LAST_MODIFIED;
- }
+ onCurrentDirectoryChanged();
+ }
- mRootsContainer = findViewById(R.id.container_roots);
+ private void buildDefaultState() {
+ mState = new State();
- mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
+ final Intent intent = getIntent();
+ final String action = intent.getAction();
+ if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) {
+ mState.action = ACTION_OPEN;
+ } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) {
+ mState.action = ACTION_CREATE;
+ } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
+ mState.action = ACTION_GET_CONTENT;
+ } else if (DocumentsContract.ACTION_MANAGE_DOCUMENTS.equals(action)) {
+ mState.action = ACTION_MANAGE;
+ }
- mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
- R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);
+ if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
+ mState.allowMultiple = intent.getBooleanExtra(
+ Intent.EXTRA_ALLOW_MULTIPLE, false);
+ }
- mDrawerLayout.setDrawerListener(mDrawerListener);
- mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
+ if (mState.action == ACTION_MANAGE) {
+ mState.acceptMimes = new String[] { "*/*" };
+ mState.allowMultiple = true;
+ } else if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) {
+ mState.acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES);
+ } else {
+ mState.acceptMimes = new String[] { intent.getType() };
+ }
- if (mAction == ACTION_MANAGE) {
- mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+ mState.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false);
+ if (mState.action == ACTION_MANAGE) {
+ mState.sortOrder = SORT_ORDER_LAST_MODIFIED;
+ }
+
+ if (mState.action == ACTION_MANAGE) {
final Uri rootUri = intent.getData();
final RootInfo root = mRoots.findRoot(rootUri);
if (root != null) {
}
} else {
- mDrawerLayout.openDrawer(mRootsContainer);
-
// Restore last stack for calling package
// TODO: move into async loader
final String packageName = getCallingPackage();
.query(RecentsProvider.buildResume(packageName), null, null, null, null);
try {
if (cursor.moveToFirst()) {
- final String raw = cursor.getString(
+ final byte[] rawStack = cursor.getBlob(
cursor.getColumnIndex(RecentsProvider.COL_PATH));
- mStack = DocumentStack.deserialize(getContentResolver(), raw);
+ DurableUtils.readFromArray(rawStack, mState.stack);
}
- } catch (FileNotFoundException e) {
+ } catch (IOException e) {
Log.w(TAG, "Failed to resume", e);
} finally {
cursor.close();
}
- onCurrentDirectoryChanged();
+ mDrawerLayout.openDrawer(mRootsContainer);
}
}
public void onStart() {
super.onStart();
- if (mAction == ACTION_MANAGE) {
- mDisplayState.showSize = true;
+ if (mState.action == ACTION_MANAGE) {
+ mState.showSize = true;
} else {
- mDisplayState.showSize = SettingsActivity.getDisplayFileSize(this);
+ mState.showSize = SettingsActivity.getDisplayFileSize(this);
}
}
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setIcon(new ColorDrawable());
- if (mAction == ACTION_OPEN || mAction == ACTION_GET_CONTENT) {
+ if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
actionBar.setTitle(R.string.title_open);
- } else if (mAction == ACTION_CREATE) {
+ } else if (mState.action == ACTION_CREATE) {
actionBar.setTitle(R.string.title_save);
}
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setTitle(null);
actionBar.setListNavigationCallbacks(mSortAdapter, mSortListener);
- actionBar.setSelectedNavigationItem(mDisplayState.sortOrder);
+ actionBar.setSelectedNavigationItem(mState.sortOrder);
}
- if (mStack.size() > 1) {
+ if (mState.stack.size() > 1) {
actionBar.setDisplayHomeAsUpEnabled(true);
mDrawerToggle.setDrawerIndicatorEnabled(false);
- } else if (mAction == ACTION_MANAGE) {
+ } else if (mState.action == ACTION_MANAGE) {
actionBar.setDisplayHomeAsUpEnabled(false);
mDrawerToggle.setDrawerIndicatorEnabled(false);
} else {
mSearchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
- mCurrentSearch = query;
+ mState.currentSearch = query;
onCurrentDirectoryChanged();
mSearchView.setIconified(true);
return true;
mSearchView.setOnCloseListener(new OnCloseListener() {
@Override
public boolean onClose() {
- mCurrentSearch = null;
+ mState.currentSearch = null;
onCurrentDirectoryChanged();
return false;
}
final MenuItem list = menu.findItem(R.id.menu_list);
final MenuItem settings = menu.findItem(R.id.menu_settings);
- grid.setVisible(mDisplayState.mode != MODE_GRID);
- list.setVisible(mDisplayState.mode != MODE_LIST);
+ grid.setVisible(mState.mode != MODE_GRID);
+ list.setVisible(mState.mode != MODE_LIST);
final boolean searchVisible;
- if (mAction == ACTION_CREATE) {
+ if (mState.action == ACTION_CREATE) {
createDir.setVisible(cwd != null && cwd.isCreateSupported());
searchVisible = false;
// TODO: close any search in-progress when hiding
search.setVisible(searchVisible);
- settings.setVisible(mAction != ACTION_MANAGE);
+ settings.setVisible(mState.action != ACTION_MANAGE);
return true;
}
return false;
} else if (id == R.id.menu_grid) {
// TODO: persist explicit user mode for cwd
- mDisplayState.mode = MODE_GRID;
+ mState.mode = MODE_GRID;
updateDisplayState();
invalidateOptionsMenu();
return true;
} else if (id == R.id.menu_list) {
// TODO: persist explicit user mode for cwd
- mDisplayState.mode = MODE_LIST;
+ mState.mode = MODE_LIST;
updateDisplayState();
invalidateOptionsMenu();
return true;
@Override
public void onBackPressed() {
- final int size = mStack.size();
+ final int size = mState.stack.size();
if (size > 1) {
- mStack.pop();
+ mState.stack.pop();
onCurrentDirectoryChanged();
} else if (size == 1 && !mDrawerLayout.isDrawerOpen(mRootsContainer)) {
// TODO: open root drawer once we can capture back key
}
}
+ @Override
+ protected void onSaveInstanceState(Bundle state) {
+ super.onSaveInstanceState(state);
+ state.putParcelable(EXTRA_STATE, mState);
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle state) {
+ super.onRestoreInstanceState(state);
+ updateActionBar();
+ }
+
// TODO: support additional sort orders
private BaseAdapter mSortAdapter = new BaseAdapter() {
@Override
public int getCount() {
- return mDisplayState.showSize ? 3 : 2;
+ return mState.showSize ? 3 : 2;
}
@Override
final TextView title = (TextView) convertView.findViewById(android.R.id.title);
final TextView summary = (TextView) convertView.findViewById(android.R.id.summary);
- if (mStack.size() > 0) {
- title.setText(mStack.getTitle(mRoots));
+ if (mState.stack.size() > 0) {
+ title.setText(mState.stack.getTitle(mRoots));
} else {
// No directory means recents
title.setText(R.string.root_recent);
private OnNavigationListener mSortListener = new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
- mDisplayState.sortOrder = itemPosition;
+ mState.sortOrder = itemPosition;
updateDisplayState();
return true;
}
};
public RootInfo getCurrentRoot() {
- if (mStack.size() > 0) {
- return mStack.getRoot(mRoots);
+ if (mState.stack.size() > 0) {
+ return mState.stack.getRoot(mRoots);
} else {
return mRoots.getRecentsRoot();
}
}
public DocumentInfo getCurrentDirectory() {
- return mStack.peek();
+ return mState.stack.peek();
}
- public DisplayState getDisplayState() {
- return mDisplayState;
+ public State getDisplayState() {
+ return mState;
}
private void onCurrentDirectoryChanged() {
if (cwd == null) {
// No directory means recents
- if (mAction == ACTION_CREATE) {
+ if (mState.action == ACTION_CREATE) {
RecentsCreateFragment.show(fm);
} else {
DirectoryFragment.showRecentsOpen(fm);
}
} else {
- if (mCurrentSearch != null) {
+ if (mState.currentSearch != null) {
// Ongoing search
- DirectoryFragment.showSearch(fm, cwd.uri, mCurrentSearch);
+ DirectoryFragment.showSearch(fm, cwd.uri, mState.currentSearch);
} else {
// Normal boring directory
DirectoryFragment.showNormal(fm, cwd.uri);
}
// Forget any replacement target
- if (mAction == ACTION_CREATE) {
+ if (mState.action == ACTION_CREATE) {
final SaveFragment save = SaveFragment.get(fm);
if (save != null) {
save.setReplaceTarget(null);
}
public void onStackPicked(DocumentStack stack) {
- mStack = stack;
+ mState.stack = stack;
onCurrentDirectoryChanged();
}
public void onRootPicked(RootInfo root, boolean closeDrawer) {
// Clear entire backstack and start in new root
- mStack.clear();
+ mState.stack.clear();
if (!mRoots.isRecentsRoot(root)) {
try {
if (doc.isDirectory()) {
// TODO: query display mode user preference for this dir
if (doc.isGridPreferred()) {
- mDisplayState.mode = MODE_GRID;
+ mState.mode = MODE_GRID;
} else {
- mDisplayState.mode = MODE_LIST;
+ mState.mode = MODE_LIST;
}
- mStack.push(doc);
+ mState.stack.push(doc);
onCurrentDirectoryChanged();
- } else if (mAction == ACTION_OPEN || mAction == ACTION_GET_CONTENT) {
+ } else if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
// Explicit file picked, return
onFinished(doc.uri);
- } else if (mAction == ACTION_CREATE) {
+ } else if (mState.action == ACTION_CREATE) {
// Replace selected file
SaveFragment.get(fm).setReplaceTarget(doc);
- } else if (mAction == ACTION_MANAGE) {
+ } else if (mState.action == ACTION_MANAGE) {
// Open the document
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
public void onDocumentsPicked(List<DocumentInfo> docs) {
- if (mAction == ACTION_OPEN || mAction == ACTION_GET_CONTENT) {
+ if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
final int size = docs.size();
final Uri[] uris = new Uri[size];
for (int i = 0; i < size; i++) {
final ContentResolver resolver = getContentResolver();
final ContentValues values = new ContentValues();
- final String rawStack = DocumentStack.serialize(mStack);
- if (mAction == ACTION_CREATE) {
+ final byte[] rawStack = DurableUtils.writeToArrayOrNull(mState.stack);
+ if (mState.action == ACTION_CREATE) {
// Remember stack for last create
values.clear();
values.put(RecentsProvider.COL_PATH, rawStack);
resolver.insert(RecentsProvider.buildRecentCreate(), values);
- } else if (mAction == ACTION_OPEN || mAction == ACTION_GET_CONTENT) {
+ } else if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
// Remember opened items
for (Uri uri : uris) {
values.clear();
intent.setData(uris[0]);
} else if (uris.length > 1) {
final ClipData clipData = new ClipData(
- null, mDisplayState.acceptMimes, new ClipData.Item(uris[0]));
+ null, mState.acceptMimes, new ClipData.Item(uris[0]));
for (int i = 1; i < uris.length; i++) {
clipData.addItem(new ClipData.Item(uris[i]));
}
intent.setClipData(clipData);
}
- if (mAction == ACTION_GET_CONTENT) {
+ if (mState.action == ACTION_GET_CONTENT) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
finish();
}
- public static class DisplayState {
+ public static class State implements android.os.Parcelable {
public int action;
public int mode = MODE_LIST;
public String[] acceptMimes;
public boolean showSize = false;
public boolean localOnly = false;
+ /** Current user navigation stack; empty implies recents. */
+ public DocumentStack stack = new DocumentStack();
+ /** Currently active search, overriding any stack. */
+ public String currentSearch;
+
public static final int ACTION_OPEN = 1;
public static final int ACTION_CREATE = 2;
public static final int ACTION_GET_CONTENT = 3;
public static final int SORT_ORDER_DISPLAY_NAME = 0;
public static final int SORT_ORDER_LAST_MODIFIED = 1;
public static final int SORT_ORDER_SIZE = 2;
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(action);
+ out.writeInt(mode);
+ out.writeStringArray(acceptMimes);
+ out.writeInt(sortOrder);
+ out.writeInt(allowMultiple ? 1 : 0);
+ out.writeInt(showSize ? 1 : 0);
+ out.writeInt(localOnly ? 1 : 0);
+ DurableUtils.writeToParcel(out, stack);
+ out.writeString(currentSearch);
+ }
+
+ public static final Creator<State> CREATOR = new Creator<State>() {
+ @Override
+ public State createFromParcel(Parcel in) {
+ final State state = new State();
+ state.action = in.readInt();
+ state.mode = in.readInt();
+ state.acceptMimes = in.readStringArray();
+ state.sortOrder = in.readInt();
+ state.allowMultiple = in.readInt() != 0;
+ state.showSize = in.readInt() != 0;
+ state.localOnly = in.readInt() != 0;
+ DurableUtils.readFromParcel(in, state.stack);
+ state.currentSearch = in.readString();
+ return state;
+ }
+
+ @Override
+ public State[] newArray(int size) {
+ return new State[size];
+ }
+ };
}
private void dumpStack() {
Log.d(TAG, "Current stack:");
- for (DocumentInfo doc : mStack) {
+ for (DocumentInfo doc : mState.stack) {
Log.d(TAG, "--> " + doc);
}
}