Merge "Add menu option to show/hide internal storage." into nyc-dev

This commit is contained in:
Aga Wronska
2016-03-31 01:39:11 +00:00
committed by Android (Google) Code Review
9 changed files with 53 additions and 23 deletions

View File

@@ -85,6 +85,10 @@
android:id="@+id/menu_file_size" android:id="@+id/menu_file_size"
android:showAsAction="never" android:showAsAction="never"
android:visible="false" /> android:visible="false" />
<item
android:id="@+id/menu_advanced"
android:showAsAction="never"
android:visible="false" />
<item <item
android:id="@+id/menu_settings" android:id="@+id/menu_settings"
android:title="@string/menu_settings" android:title="@string/menu_settings"

View File

@@ -24,8 +24,9 @@
<!-- Indicates if the home directory should be hidden in the roots list, that is presented <!-- Indicates if the home directory should be hidden in the roots list, that is presented
in the drawer/left side panel ) --> in the drawer/left side panel ) -->
<bool name="home_root_hidden">true</bool> <bool name="home_root_hidden">true</bool>
<!-- Indicates if the advanced roots like internal storage should be hidden in the roots list) --> <!-- Indicates if the advanced roots like internal storage should be shown in the roots list.
<bool name="advanced_roots_hidden">true</bool> When enabled there is no menu option to toggle internal storage visibility. -->
<bool name="advanced_roots_shown">false</bool>
<!-- Indicates if search view is taking the whole toolbar space --> <!-- Indicates if search view is taking the whole toolbar space -->
<bool name="full_bar_search_view">true</bool> <bool name="full_bar_search_view">true</bool>
</resources> </resources>

View File

@@ -18,6 +18,11 @@ package com.android.documentsui;
import static com.android.documentsui.Shared.DEBUG; import static com.android.documentsui.Shared.DEBUG;
import static com.android.documentsui.Shared.EXTRA_BENCHMARK; import static com.android.documentsui.Shared.EXTRA_BENCHMARK;
import static com.android.documentsui.State.ACTION_CREATE;
import static com.android.documentsui.State.ACTION_OPEN;
import static com.android.documentsui.State.ACTION_OPEN_TREE;
import static com.android.documentsui.State.ACTION_GET_CONTENT;
import static com.android.documentsui.State.ACTION_PICK_COPY_DESTINATION;
import static com.android.documentsui.State.MODE_GRID; import static com.android.documentsui.State.MODE_GRID;
import android.app.Activity; import android.app.Activity;
@@ -165,6 +170,7 @@ public abstract class BaseActivity extends Activity
final MenuItem sortSize = menu.findItem(R.id.menu_sort_size); final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
final MenuItem grid = menu.findItem(R.id.menu_grid); final MenuItem grid = menu.findItem(R.id.menu_grid);
final MenuItem list = menu.findItem(R.id.menu_list); final MenuItem list = menu.findItem(R.id.menu_list);
final MenuItem advanced = menu.findItem(R.id.menu_advanced);
final MenuItem fileSize = menu.findItem(R.id.menu_file_size); final MenuItem fileSize = menu.findItem(R.id.menu_file_size);
// Search uses backend ranking; no sorting, recents doesn't support sort. // Search uses backend ranking; no sorting, recents doesn't support sort.
@@ -176,6 +182,9 @@ public abstract class BaseActivity extends Activity
grid.setVisible(mState.derivedMode != State.MODE_GRID); grid.setVisible(mState.derivedMode != State.MODE_GRID);
list.setVisible(mState.derivedMode != State.MODE_LIST); list.setVisible(mState.derivedMode != State.MODE_LIST);
advanced.setVisible(mState.showAdvancedOption);
advanced.setTitle(mState.showAdvancedOption && mState.showAdvanced
? R.string.menu_advanced_hide : R.string.menu_advanced_show);
fileSize.setTitle(LocalPreferences.getDisplayFileSize(this) fileSize.setTitle(LocalPreferences.getDisplayFileSize(this)
? R.string.menu_file_size_hide : R.string.menu_file_size_show); ? R.string.menu_file_size_hide : R.string.menu_file_size_show);
@@ -195,25 +204,30 @@ public abstract class BaseActivity extends Activity
return state; return state;
} }
State state = createSharedState();
includeState(state);
if (DEBUG) Log.d(mTag, "Created new state object: " + state);
return state;
}
private State createSharedState() {
State state = new State(); State state = new State();
final Intent intent = getIntent(); final Intent intent = getIntent();
state.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false); state.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false);
state.forceSize = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_FILESIZE, false); state.forceSize = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_FILESIZE, false);
state.showSize = state.forceSize || LocalPreferences.getDisplayFileSize(this); state.showSize = state.forceSize || LocalPreferences.getDisplayFileSize(this);
state.initAcceptMimes(intent); state.initAcceptMimes(intent);
state.excludedAuthorities = getExcludedAuthorities(); state.excludedAuthorities = getExcludedAuthorities();
includeState(state);
// Advanced roots are shown by deafult without menu option if forced by config or intent.
state.showAdvanced = getResources().getBoolean(R.bool.advanced_roots_shown)
|| intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false);
// Menu option is shown for whitelisted intents if advanced roots are not shown by default.
state.showAdvancedOption = !state.showAdvanced &&
(state.action == ACTION_OPEN ||
state.action == ACTION_CREATE ||
state.action == ACTION_OPEN_TREE ||
state.action == ACTION_GET_CONTENT);
if (DEBUG) Log.d(mTag, "Created new state object: " + state);
return state; return state;
} }
@@ -287,6 +301,10 @@ public abstract class BaseActivity extends Activity
} }
return true; return true;
case R.id.menu_advanced:
setDisplayAdvancedDevices(!mState.showAdvanced);
return true;
case R.id.menu_file_size: case R.id.menu_file_size:
setDisplayFileSize(!LocalPreferences.getDisplayFileSize(this)); setDisplayFileSize(!LocalPreferences.getDisplayFileSize(this));
return true; return true;
@@ -452,6 +470,12 @@ public abstract class BaseActivity extends Activity
? DocumentsContract.buildRootUri("com.android.providers.downloads.documents", ? DocumentsContract.buildRootUri("com.android.providers.downloads.documents",
"downloads") "downloads")
: DocumentsContract.buildHomeUri(); : DocumentsContract.buildHomeUri();
}
void setDisplayAdvancedDevices(boolean display) {
mState.showAdvanced = display;
RootsFragment.get(getFragmentManager()).onDisplayStateChanged();
invalidateOptionsMenu();
} }
void setDisplayFileSize(boolean display) { void setDisplayFileSize(boolean display) {

View File

@@ -477,6 +477,11 @@ public class RootsCache {
continue; continue;
} }
if (!state.showAdvanced && root.isAdvanced()) {
if (DEBUG) Log.d(TAG, "Excluding root because: unwanted advanced device.");
continue;
}
if (state.localOnly && !root.isLocalOnly()) { if (state.localOnly && !root.isLocalOnly()) {
if (DEBUG) Log.d(TAG, "Excluding root because: unwanted non-local device."); if (DEBUG) Log.d(TAG, "Excluding root because: unwanted non-local device.");
continue; continue;

View File

@@ -321,9 +321,6 @@ public class RootsFragment extends Fragment {
if (root.isHome() && Shared.isHomeRootHidden(context)) { if (root.isHome() && Shared.isHomeRootHidden(context)) {
continue; continue;
} else if (root.isAdvanced()
&& Shared.areAdvancedRootsHidden(context, state)) {
continue;
} else if (root.isLibrary()) { } else if (root.isLibrary()) {
if (DEBUG) Log.d(TAG, "Adding " + root + " as library."); if (DEBUG) Log.d(TAG, "Adding " + root + " as library.");
libraries.add(item); libraries.add(item);

View File

@@ -181,12 +181,4 @@ public final class Shared {
return context.getResources().getBoolean(R.bool.home_root_hidden); return context.getResources().getBoolean(R.bool.home_root_hidden);
} }
/*
* Indicates if the advanced roots should be hidden.
*/
public static boolean areAdvancedRootsHidden(Context context, State state) {
return context.getResources().getBoolean(R.bool.advanced_roots_hidden)
&& state.action != ACTION_OPEN_TREE;
}
} }

View File

@@ -93,6 +93,8 @@ public class State implements android.os.Parcelable {
public boolean forceSize; public boolean forceSize;
public boolean showSize; public boolean showSize;
public boolean localOnly; public boolean localOnly;
public boolean showAdvancedOption;
public boolean showAdvanced;
public boolean restored; public boolean restored;
/* /*
* Indicates handler was an external app, like photos. * Indicates handler was an external app, like photos.
@@ -194,6 +196,8 @@ public class State implements android.os.Parcelable {
out.writeInt(forceSize ? 1 : 0); out.writeInt(forceSize ? 1 : 0);
out.writeInt(showSize ? 1 : 0); out.writeInt(showSize ? 1 : 0);
out.writeInt(localOnly ? 1 : 0); out.writeInt(localOnly ? 1 : 0);
out.writeInt(showAdvancedOption ? 1 : 0);
out.writeInt(showAdvanced ? 1 : 0);
out.writeInt(restored ? 1 : 0); out.writeInt(restored ? 1 : 0);
out.writeInt(external ? 1 : 0); out.writeInt(external ? 1 : 0);
DurableUtils.writeToParcel(out, stack); DurableUtils.writeToParcel(out, stack);
@@ -223,6 +227,8 @@ public class State implements android.os.Parcelable {
state.forceSize = in.readInt() != 0; state.forceSize = in.readInt() != 0;
state.showSize = in.readInt() != 0; state.showSize = in.readInt() != 0;
state.localOnly = in.readInt() != 0; state.localOnly = in.readInt() != 0;
state.showAdvancedOption = in.readInt() != 0;
state.showAdvanced = in.readInt() != 0;
state.restored = in.readInt() != 0; state.restored = in.readInt() != 0;
state.external = in.readInt() != 0; state.external = in.readInt() != 0;
DurableUtils.readFromParcel(in, state.stack); DurableUtils.readFromParcel(in, state.stack);

View File

@@ -55,6 +55,7 @@ public class RootsCacheTest extends AndroidTestCase {
mState = new State(); mState = new State();
mState.action = State.ACTION_OPEN; mState.action = State.ACTION_OPEN;
mState.showAdvanced = true;
mState.localOnly = false; mState.localOnly = false;
} }

View File

@@ -56,7 +56,7 @@ public class BugreportStorageProvider extends DocumentsProvider {
final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection)); final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
final RowBuilder row = result.newRow(); final RowBuilder row = result.newRow();
row.add(Root.COLUMN_ROOT_ID, DOC_ID_ROOT); row.add(Root.COLUMN_ROOT_ID, DOC_ID_ROOT);
row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY); row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED);
row.add(Root.COLUMN_ICON, android.R.mipmap.sym_def_app_icon); row.add(Root.COLUMN_ICON, android.R.mipmap.sym_def_app_icon);
row.add(Root.COLUMN_TITLE, getContext().getString(R.string.bugreport_storage_title)); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.bugreport_storage_title));
row.add(Root.COLUMN_DOCUMENT_ID, DOC_ID_ROOT); row.add(Root.COLUMN_DOCUMENT_ID, DOC_ID_ROOT);